DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4Random.h
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 #ifndef DD4HEP_GEANT4RANDOM_H
15 #define DD4HEP_GEANT4RANDOM_H
16 
17 // Framework include files
18 #include "DDG4/Geant4Action.h"
19 
20 // C/C++ include files
21 #include <string>
22 
23 // Forward declarations
24 class TRandom;
25 
27 namespace CLHEP { class HepRandomEngine; }
28 
30 namespace DD4hep {
31 
33  namespace Simulation {
34 
35  // Forward declarations
36  class Geant4Exec;
37 
39 
60  class Geant4Random : public Geant4Action {
61  friend class Geant4Exec;
62 
63  protected:
65  std::string m_file;
67  std::string m_engineType;
71  bool m_replace;
72 
74  CLHEP::HepRandomEngine* m_engine;
75 
77  TRandom *m_rootRandom, *m_rootOLD;
79  bool m_inited;
80 
81  public:
83 
91  Geant4Random(Geant4Context* context, const std::string& name);
93  virtual ~Geant4Random();
94 
96  static Geant4Random* instance(bool throw_exception=true);
98 
106 
108 
112  void initialize();
113 
116  CLHEP::HepRandomEngine* engine() { return m_engine; }
118 
120  virtual void setSeed(long seed);
122 
126  virtual void setSeeds(const long * seeds, int size);
128  virtual void saveStatus( const char filename[] = "Config.conf") const;
130  virtual void restoreStatus( const char filename[] = "Config.conf" );
132  virtual void showStatus() const;
133 
136 
140  double rndm_clhep();
141 
143  double rndm(int i=0);
145  void rndmArray(int n, float *array);
147  void rndmArray(int n, double *array);
149  double uniform(double x1=1);
151  double uniform(double x1, double x2);
152 
154  double exp(double tau);
156  double gauss(double mean=0, double sigma=1);
158  double landau(double mean=0, double sigma=1);
160  void circle(double &x, double &y, double r);
162  void sphere(double &x, double &y, double &z, double r);
163  };
164 
165  } // End namespace Simulation
166 } // End namespace DD4hep
167 #endif // DD4HEP_GEANT4RANDOM_H
TRandom * m_rootRandom
Reference to ROOT random instance.
Definition: Geant4Random.h:77
virtual void setSeeds(const long *seeds, int size)
Should initialise the status of the algorithm.
double uniform(double x1=1)
Create uniformly disributed random numbers in the interval ]0,x1].
bool m_inited
Flag to remember initialization.
Definition: Geant4Random.h:79
double exp(double tau)
Create exponentially distributed random numbers.
double landau(double mean=0, double sigma=1)
Create landau distributed random numbers.
double rndm_clhep()
Create flat distributed random numbers in the interval ]0,1] calling CLHEP.
void sphere(double &x, double &y, double &z, double r)
Create tuple of randum number on a sphere with radius r.
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:261
void circle(double &x, double &y, double r)
Create tuple of randum number around a circle with radius r.
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:271
double rndm(int i=0)
Create flat distributed random numbers in the interval ]0,1].
long m_seed
Property: Initial random seed. Default: 123456789.
Definition: Geant4Random.h:69
Main executor steering the Geant4 execution.
Definition: Geant4Kernel.h:274
static Geant4Random * setMainInstance(Geant4Random *ptr)
Make this random generator instance the one used by Geant4.
virtual void saveStatus(const char filename[]="Config.conf") const
Should save on a file specific to the instantiated engine in use the current status.
void initialize()
Initialize the instance.
static Geant4Random * instance(bool throw_exception=true)
Access the main Geant4 random generator instance. Must be created before used!
bool m_replace
Property: Indicator to replace the ROOT gRandom instance.
Definition: Geant4Random.h:71
void rndmArray(int n, float *array)
Create a float array of flat distributed random numbers in the interval ]0,1].
CLHEP::HepRandomEngine * m_engine
Reference to the CLHEP random number engine (valid only after initialization)
Definition: Geant4Random.h:74
virtual void setSeed(long seed)
Should initialise the status of the algorithm according to seed.
virtual ~Geant4Random()
Default destructor.
double gauss(double mean=0, double sigma=1)
Create gaussian distributed random numbers.
CLHEP::HepRandomEngine * engine()
CLHEP random number engine (valid after initialization only)
Definition: Geant4Random.h:117
std::string m_engineType
Property: Engine type. default: "HepJamesRandom".
Definition: Geant4Random.h:67
virtual void restoreStatus(const char filename[]="Config.conf")
Should read from a file and restore the last saved engine configuration.
Geant4Random(Geant4Context *context, const std::string &name)
Standard constructor.
virtual void showStatus() const
Should dump the current engine status on the screen.
Generic context to extend user, run and event information.
Mini interface to THE random generator of the application.
Definition: Geant4Random.h:60
std::string m_file
Property: File name if initialized from file. If set, engine name and seeds are ignored.
Definition: Geant4Random.h:65
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:91