DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4Random.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DDG4_GEANT4RANDOM_H
14 #define DDG4_GEANT4RANDOM_H
15 
16 // Framework include files
17 #include <DDG4/Geant4Action.h>
18 
19 // C/C++ include files
20 #include <string>
21 
22 // Forward declarations
23 class TRandom;
24 
26 namespace CLHEP { class HepRandomEngine; }
27 
29 namespace dd4hep {
30 
32  namespace sim {
33 
34  // Forward declarations
35  class Geant4Exec;
36 
38 
59  class Geant4Random : public Geant4Action {
60  friend class Geant4Exec;
61 
62  protected:
64  std::string m_file;
66  std::string m_engineType;
70  bool m_replace;
71 
73  CLHEP::HepRandomEngine* m_engine;
74 
76  TRandom *m_rootRandom, *m_rootOLD;
78  bool m_inited;
79 
80  public:
82 
90  Geant4Random(Geant4Context* context, const std::string& name);
92  virtual ~Geant4Random();
93 
95  static Geant4Random* instance(bool throw_exception=true);
97 
105 
107 
111  void initialize();
112 
115  CLHEP::HepRandomEngine* engine() { return m_engine; }
117 
119  virtual void setSeed(long seed);
121 
125  virtual void setSeeds(const long * seeds, int size);
127  virtual void saveStatus( const char filename[] = "Config.conf") const;
129  virtual void restoreStatus( const char filename[] = "Config.conf" );
131  virtual void showStatus() const;
132 
135 
139  double rndm_clhep();
140 
142  double rndm(int i=0);
144  void rndmArray(int n, float *array);
146  void rndmArray(int n, double *array);
148  double uniform(double x1=1);
150  double uniform(double x1, double x2);
151 
153  double exp(double tau);
155  double gauss(double mean=0, double sigma=1);
157  double gamma(double k, double lambda);
159  double landau(double mean=0, double sigma=1);
161  void circle(double &x, double &y, double r);
163  void sphere(double &x, double &y, double &z, double r);
165  double poisson(double mean=1e0 );
167  double breit_wigner(double mean=0e0, double gamma=1e0);
168  };
169 
170  } // End namespace sim
171 } // End namespace dd4hep
172 #endif // DDG4_GEANT4RANDOM_H
dd4hep::sim::Geant4Random::poisson
double poisson(double mean=1e0)
Create poisson distributed random numbers.
Definition: Geant4Random.cpp:328
dd4hep::sim::Geant4Random::m_replace
bool m_replace
Property: Indicator to replace the ROOT gRandom instance.
Definition: Geant4Random.h:70
dd4hep::sim::Geant4Random::rndm
double rndm(int i=0)
Create flat distributed random numbers in the interval ]0,1].
Definition: Geant4Random.cpp:268
dd4hep::sim::Geant4Random::instance
static Geant4Random * instance(bool throw_exception=true)
Access the main Geant4 random generator instance. Must be created before used!
Definition: Geant4Random.cpp:113
dd4hep::sim::Geant4Random::sphere
void sphere(double &x, double &y, double &z, double r)
Create tuple of randum number on a sphere with radius r.
Definition: Geant4Random.cpp:322
dd4hep::sim::Geant4Random::engine
CLHEP::HepRandomEngine * engine()
CLHEP random number engine (valid after initialization only)
Definition: Geant4Random.h:116
dd4hep::sim::Geant4Random::uniform
double uniform(double x1=1)
Create uniformly disributed random numbers in the interval ]0,x1].
Definition: Geant4Random.cpp:286
dd4hep::sim::Geant4Random::m_file
std::string m_file
Property: File name if initialized from file. If set, engine name and seeds are ignored.
Definition: Geant4Random.h:64
dd4hep::sim::Geant4Random::rndm_clhep
double rndm_clhep()
Create flat distributed random numbers in the interval ]0,1] calling CLHEP.
Definition: Geant4Random.cpp:262
dd4hep::sim::Geant4Random::setSeed
virtual void setSeed(long seed)
Should initialise the status of the algorithm according to seed.
Definition: Geant4Random.cpp:199
dd4hep::sim::Geant4Random::m_luxury
long m_luxury
Definition: Geant4Random.h:68
dd4hep::sim::Geant4Random::gamma
double gamma(double k, double lambda)
Create gamma distributed random numbers.
Definition: Geant4Random.cpp:340
dd4hep::sim::Geant4Random::showStatus
virtual void showStatus() const
Should dump the current engine status on the screen.
Definition: Geant4Random.cpp:230
dd4hep::sim::Geant4Random::~Geant4Random
virtual ~Geant4Random()
Default destructor.
Definition: Geant4Random.cpp:97
dd4hep::sim::Geant4Random::breit_wigner
double breit_wigner(double mean=0e0, double gamma=1e0)
Create breit wigner distributed random numbers.
Definition: Geant4Random.cpp:334
CLHEP
CLHEP namespace.
Definition: Geant4Random.h:26
dd4hep::sim::Geant4Random::setMainInstance
static Geant4Random * setMainInstance(Geant4Random *ptr)
Make this random generator instance the one used by Geant4.
Definition: Geant4Random.cpp:121
dd4hep::sim::Geant4Random::Geant4Random
Geant4Random(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4Random.cpp:82
dd4hep::sim::Geant4Random
Mini interface to THE random generator of the application.
Definition: Geant4Random.h:59
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4Random::rndmArray
void rndmArray(int n, float *array)
Create a float array of flat distributed random numbers in the interval ]0,1].
Definition: Geant4Random.cpp:274
dd4hep::sim::Geant4Random::saveStatus
virtual void saveStatus(const char filename[]="Config.conf") const
Should save on a file specific to the instantiated engine in use the current status.
Definition: Geant4Random.cpp:216
dd4hep::sim::Geant4Random::circle
void circle(double &x, double &y, double r)
Create tuple of randum number around a circle with radius r.
Definition: Geant4Random.cpp:316
dd4hep::sim::Geant4Random::gauss
double gauss(double mean=0, double sigma=1)
Create gaussian distributed random numbers.
Definition: Geant4Random.cpp:304
dd4hep::sim::Geant4Random::m_rootRandom
TRandom * m_rootRandom
Reference to ROOT random instance.
Definition: Geant4Random.h:76
dd4hep::sim::Geant4Exec
Main executor steering the Geant4 execution.
Definition: Geant4Kernel.h:367
dd4hep::sim::Geant4Random::m_engine
CLHEP::HepRandomEngine * m_engine
Reference to the CLHEP random number engine (valid only after initialization)
Definition: Geant4Random.h:73
dd4hep::sim::Geant4Random::setSeeds
virtual void setSeeds(const long *seeds, int size)
Should initialise the status of the algorithm.
Definition: Geant4Random.cpp:209
dd4hep::sim::Geant4Random::m_rootOLD
TRandom * m_rootOLD
Definition: Geant4Random.h:76
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4Random::m_engineType
std::string m_engineType
Property: Engine type. default: "HepJamesRandom".
Definition: Geant4Random.h:66
dd4hep::sim::Geant4Random::restoreStatus
virtual void restoreStatus(const char filename[]="Config.conf")
Should read from a file and restore the last saved engine configuration.
Definition: Geant4Random.cpp:224
dd4hep::sim::Geant4Random::m_seed
long m_seed
Property: Initial random seed. Default: 123456789.
Definition: Geant4Random.h:68
dd4hep::sim::Geant4Random::m_inited
bool m_inited
Flag to remember initialization.
Definition: Geant4Random.h:78
dd4hep::sim::Geant4Random::exp
double exp(double tau)
Create exponentially distributed random numbers.
Definition: Geant4Random.cpp:298
dd4hep::sim::Geant4Random::initialize
void initialize()
Initialize the instance.
Definition: Geant4Random.cpp:158
Geant4Action.h
dd4hep::sim::Geant4Random::landau
double landau(double mean=0, double sigma=1)
Create landau distributed random numbers.
Definition: Geant4Random.cpp:310
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270