|
||||
File indexing completed on 2025-01-18 09:55:24
0001 //========================================================================== 0002 // AIDA Detector description implementation 0003 //-------------------------------------------------------------------------- 0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) 0005 // All rights reserved. 0006 // 0007 // For the licensing terms see $DD4hepINSTALL/LICENSE. 0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS. 0009 // 0010 // Author : M.Frank 0011 // 0012 //========================================================================== 0013 #ifndef DDG4_GEANT4RANDOM_H 0014 #define DDG4_GEANT4RANDOM_H 0015 0016 // Framework include files 0017 #include <DDG4/Geant4Action.h> 0018 0019 // C/C++ include files 0020 #include <string> 0021 0022 // Forward declarations 0023 class TRandom; 0024 0025 /// CLHEP namespace 0026 namespace CLHEP { class HepRandomEngine; } 0027 0028 /// Namespace for the AIDA detector description toolkit 0029 namespace dd4hep { 0030 0031 /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit 0032 namespace sim { 0033 0034 // Forward declarations 0035 class Geant4Exec; 0036 0037 /// Mini interface to THE random generator of the application 0038 /** 0039 * Mini interface to THE random generator of the application. 0040 * Necessary, that on every object creates its own instance, but accesses 0041 * the main instance avaible throu the Geant4Context. 0042 * 0043 * This is mandatory to ensure reproducability of the event generation 0044 * process. Particular objects may use a dependent generator from 0045 * an experiment framework like GAUDI. 0046 * 0047 * This main interface is supposed to be stable. Unclear however is 0048 * if the generation functions will have to become virtual.... 0049 * Future will tell us. 0050 * 0051 * The first instance of the random action is automatically set 0052 * to be the Geant4 instance. If another instance should be used by 0053 * Geant4, use setMainInstance(Geant4Random* ptr). 0054 * 0055 * \author M.Frank 0056 * \version 1.0 0057 * \ingroup DD4HEP_SIMULATION 0058 */ 0059 class Geant4Random : public Geant4Action { 0060 friend class Geant4Exec; 0061 0062 protected: 0063 /// Property: File name if initialized from file. If set, engine name and seeds are ignored 0064 std::string m_file; 0065 /// Property: Engine type. default: "HepJamesRandom" 0066 std::string m_engineType; 0067 /// Property: Initial random seed. Default: 123456789 0068 long m_seed, m_luxury; 0069 /// Property: Indicator to replace the ROOT gRandom instance 0070 bool m_replace; 0071 0072 /// Reference to the CLHEP random number engine (valid only after initialization) 0073 CLHEP::HepRandomEngine* m_engine; 0074 0075 /// Reference to ROOT random instance 0076 TRandom *m_rootRandom, *m_rootOLD; 0077 /// Flag to remember initialization 0078 bool m_inited; 0079 0080 public: 0081 /// Standard constructor 0082 /** Please Note: 0083 * Should be used only for initialization of the main instance. 0084 * Subsequent usage should be invoked using the class member 0085 * Geant4Random::instance(). 0086 * 0087 * @param context Geant4 context for this action. 0088 * @param name Name of the action object 0089 */ 0090 Geant4Random(Geant4Context* context, const std::string& name); 0091 /// Default destructor 0092 virtual ~Geant4Random(); 0093 0094 /// Access the main Geant4 random generator instance. Must be created before used! 0095 static Geant4Random* instance(bool throw_exception=true); 0096 /// Make this random generator instance the one used by Geant4. 0097 /** Returns reference to previous instance. It is up to the user 0098 * to manage the reference. 0099 * Caveat: other code may hold references to this instance. 0100 * 0101 * @param ptr Reference to main random number generator 0102 * @return Reference to previous random number generator instance 0103 */ 0104 static Geant4Random* setMainInstance(Geant4Random* ptr); 0105 0106 /// Initialize the instance. 0107 /** Called either by user or on request of the first random number. 0108 * To propagate the engine to Geant4, initialize MUST be called by 0109 * the user. 0110 */ 0111 void initialize(); 0112 0113 /** Access to the CLHEP random number engine. For further doc see CLHEP/Random/RandomEngine.h */ 0114 0115 /// CLHEP random number engine (valid after initialization only) 0116 CLHEP::HepRandomEngine* engine() { return m_engine; } 0117 0118 /// Should initialise the status of the algorithm according to seed. 0119 virtual void setSeed(long seed); 0120 /// Should initialise the status of the algorithm 0121 /** Initialization according to the zero terminated 0122 * array of seeds. It is allowed to ignore one or 0123 * many seeds in this array. 0124 */ 0125 virtual void setSeeds(const long * seeds, int size); 0126 /// Should save on a file specific to the instantiated engine in use the current status. 0127 virtual void saveStatus( const char filename[] = "Config.conf") const; 0128 /// Should read from a file and restore the last saved engine configuration. 0129 virtual void restoreStatus( const char filename[] = "Config.conf" ); 0130 /// Should dump the current engine status on the screen. 0131 virtual void showStatus() const; 0132 0133 /** Basic random generator functions */ 0134 0135 /// Create flat distributed random numbers in the interval ]0,1] calling CLHEP 0136 /** This is more or less a test function, since the result should be 0137 * identical to calling rndm. 0138 */ 0139 double rndm_clhep(); 0140 0141 /// Create flat distributed random numbers in the interval ]0,1] 0142 double rndm(int i=0); 0143 /// Create a float array of flat distributed random numbers in the interval ]0,1] 0144 void rndmArray(int n, float *array); 0145 /// Create a double array of flat distributed random numbers in the interval ]0,1] 0146 void rndmArray(int n, double *array); 0147 /// Create uniformly disributed random numbers in the interval ]0,x1] 0148 double uniform(double x1=1); 0149 /// Create uniformly disributed random numbers in the interval ]x1,x2] 0150 double uniform(double x1, double x2); 0151 0152 /// Create exponentially distributed random numbers 0153 double exp(double tau); 0154 /// Create gaussian distributed random numbers 0155 double gauss(double mean=0, double sigma=1); 0156 /// Create gamma distributed random numbers 0157 double gamma(double k, double lambda); 0158 /// Create landau distributed random numbers 0159 double landau(double mean=0, double sigma=1); 0160 /// Create tuple of randum number around a circle with radius r 0161 void circle(double &x, double &y, double r); 0162 /// Create tuple of randum number on a sphere with radius r 0163 void sphere(double &x, double &y, double &z, double r); 0164 /// Create poisson distributed random numbers 0165 double poisson(double mean=1e0 ); 0166 /// Create breit wigner distributed random numbers 0167 double breit_wigner(double mean=0e0, double gamma=1e0); 0168 }; 0169 0170 } // End namespace sim 0171 } // End namespace dd4hep 0172 #endif // DDG4_GEANT4RANDOM_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |