CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: Random.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- HepRandom --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 // This file is part of Geant4 (simulation toolkit for HEP). 00010 // 00011 // It's a singleton instantiated by default within the HEP Random module. 00012 // It uses an instantiated HepJamesRandom engine as default algorithm 00013 // for pseudo-random number generation. HepRandom defines a static private 00014 // data member theGenerator and a set of static inlined methods to manipulate 00015 // it. By means of theGenerator the user can change the underlying engine 00016 // algorithm, get and set the seeds and use any kind of defined random 00017 // distribution. 00018 // Distribution classes inherit from HepRandom and define both static and 00019 // not-static interfaces. 00020 // A static table of uncorrelated seeds is available in this class. 00021 // A static method "getTheTableSeeds()" is defined to access a couple of 00022 // seeds at a given index in the table. 00023 00024 // ======================================================================= 00025 // Gabriele Cosmo - Created: 5th Sep 1995 00026 // - Minor update: 17th May 1996 00027 // - Poisson now operates on doubles : 31st Oct 1996 00028 // - Added methods for engine status: 19th Nov 1996 00029 // - Fixed default values to setTheSeed() and 00030 // setTheSeeds() static methods: 16th Oct 1997 00031 // - Modified HepRandom to act as a singleton, constructors 00032 // are kept public for backward compatibility. Added table 00033 // of seeds from HepRandomEngine: 19th Mar 1998 00034 // - Relocated Poisson and Gauss data and simplified 00035 // initialisation of static generator: 5th Jan 1999 00036 // ======================================================================= 00037 00038 #ifndef HepRandom_h 00039 #define HepRandom_h 1 00040 00041 #include "CLHEP/Random/defs.h" 00042 #include "CLHEP/Random/RandomEngine.h" 00043 00044 namespace CLHEP { 00045 00050 class HepRandom { 00051 00052 public: 00053 00054 HepRandom(); 00055 HepRandom(long seed); 00056 // Contructors with and without a seed using the default engine 00057 // (JamesRandom). 00058 00059 HepRandom(HepRandomEngine & algorithm); 00060 HepRandom(HepRandomEngine * algorithm); 00061 // Constructor taking an alternative engine as argument. If a pointer is 00062 // given the corresponding object will be deleted by the HepRandom 00063 // destructor. 00064 00065 virtual ~HepRandom(); 00066 // Destructor 00067 00068 double flat(); 00069 // Returns the flat value ( interval ]0...1[ ). 00070 00071 void flatArray(const int size, double* vect); 00072 // Fills "vect" array of flat random values, given the size. 00073 00074 inline double flat (HepRandomEngine* theNewEngine); 00075 // Returns a flat value, given a defined Random Engine. 00076 00077 inline void flatArray(HepRandomEngine* theNewEngine, 00078 const int size, double* vect); 00079 // Fills "vect" array of flat random values, given the size 00080 // and a defined Random Engine. 00081 00082 virtual double operator()(); 00083 // To get a flat random number using the operator (). 00084 00085 virtual std::string name() const; 00086 virtual HepRandomEngine & engine(); 00087 00088 00089 virtual std::ostream & put ( std::ostream & os ) const; 00090 virtual std::istream & get ( std::istream & is ); 00091 // Save and restore to/from streams 00092 00093 // -------------------------------------------------- 00094 // Static member functions using the static generator 00095 // -------------------------------------------------- 00096 00097 static void setTheSeed(long seed, int lux=3); 00098 // (Re)Initializes the generator with a seed. 00099 00100 static long getTheSeed(); 00101 // Gets the current seed of the current generator. 00102 00103 static void setTheSeeds(const long* seeds, int aux=-1); 00104 // (Re)Initializes the generator with a zero terminated list of seeds. 00105 00106 static const long* getTheSeeds(); 00107 // Gets the current array of seeds of the current generator. 00108 00109 static void getTheTableSeeds (long* seeds, int index); 00110 // Gets the array of seeds in the static seedTable at "index" position. 00111 00112 static HepRandom * getTheGenerator(); 00113 // Return the current static generator. 00114 00115 static void setTheEngine (HepRandomEngine* theNewEngine); 00116 // To set the underlying algorithm object. 00117 00118 static HepRandomEngine * getTheEngine(); 00119 // Returns a pointer to the underlying algorithm object. 00120 00121 static void saveEngineStatus( const char filename[] = "Config.conf" ); 00122 // Saves to file the current status of the current engine. 00123 00124 static void restoreEngineStatus( const char filename[] = "Config.conf" ); 00125 // Restores a saved status (if any) for the current engine. 00126 00127 static std::ostream& saveFullState ( std::ostream & os ); 00128 // Saves to stream the state of the engine and cached data. 00129 00130 static std::istream& restoreFullState ( std::istream & is ); 00131 // Restores from stream the state of the engine and cached data. 00132 00133 static std::ostream& saveDistState ( std::ostream & os ) {return os;} 00134 // Saves to stream the state of the cached data. 00135 00136 static std::istream& restoreDistState ( std::istream & is ) {return is;} 00137 // Restores from stream the state of the cached data. 00138 00139 static std::ostream& saveStaticRandomStates ( std::ostream & os ); 00140 // Saves to stream the engine and cached data for all distributions. 00141 00142 static std::istream& restoreStaticRandomStates ( std::istream & is ); 00143 // Restores from stream the engine and cached data for all distributions. 00144 00145 static void showEngineStatus(); 00146 // Dumps the current engine status on screen. 00147 00148 static int createInstance(); 00149 // used to initialise HepRandom::isActive and instantiate singleton 00150 00151 static std::string distributionName() {return "HepRandomEngine";} 00152 // Provides the name of this distribution class 00153 00154 protected: // -------- Data members --------- 00155 00156 static const long seedTable[215][2]; 00157 // Table of seeds 00158 00159 private: // -------- Data members --------- 00160 00161 static HepRandomEngine * theEngine; 00162 // The corresponding algorithm. 00163 00164 static HepRandom * theGenerator; 00165 // The common shared static generator 00166 00167 static int isActive; 00168 // Flag notifying singleton instance 00169 00170 bool deleteEngine; 00171 // True if the engine should be deleted on destruction. 00172 00173 }; 00174 00175 std::ostream & operator<< (std::ostream & os, const HepRandom & dist); 00176 std::istream & operator>> (std::istream & is, HepRandom & dist); 00177 00178 } // namespace CLHEP 00179 00180 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00181 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00182 using namespace CLHEP; 00183 #endif 00184 00185 #include "CLHEP/Random/Random.icc" 00186 00187 #endif