Geant4 Cross Reference |
>> 1 // $Id:$ 1 // -*- C++ -*- 2 // -*- C++ -*- 2 // 3 // 3 // ------------------------------------------- 4 // ----------------------------------------------------------------------- 4 // HEP Random 5 // HEP Random 5 // --- HepJamesRandom - 6 // --- HepJamesRandom --- 6 // class header file 7 // class header file 7 // ------------------------------------------- 8 // ----------------------------------------------------------------------- 8 // This file is part of Geant4 (simulation too 9 // This file is part of Geant4 (simulation toolkit for HEP). 9 // 10 // 10 // HepJamesRandom implements the algorithm by 11 // HepJamesRandom implements the algorithm by Marsaglia-Zaman RANMAR 11 // described in "F.James, Comp. Phys. Comm. 60 12 // described in "F.James, Comp. Phys. Comm. 60 (1990) 329" and implemented 12 // in FORTRAN77 as part of the MATHLIB HEP lib 13 // in FORTRAN77 as part of the MATHLIB HEP library for pseudo-random 13 // numbers generation. 14 // numbers generation. 14 // This is the default random engine invoked b 15 // This is the default random engine invoked by each distribution unless 15 // the user sets a different one. 16 // the user sets a different one. 16 17 17 // =========================================== 18 // ======================================================================= 18 // Gabriele Cosmo - Created: 5th September 199 19 // Gabriele Cosmo - Created: 5th September 1995 19 // - Minor corrections: 31st Oc 20 // - Minor corrections: 31st October 1996 20 // - Added methods for engine s 21 // - Added methods for engine status: 19th November 1996 21 // - setSeed(), setSeeds() now 22 // - setSeed(), setSeeds() now have default dummy argument 22 // set to zero: 11th July 199 23 // set to zero: 11th July 1997 23 // J.Marraffino - Added stream operators and 24 // J.Marraffino - Added stream operators and related constructor. 24 // Added automatic seed selec 25 // Added automatic seed selection from seed table and 25 // engine counter: 16th Feb 1 26 // engine counter: 16th Feb 1998 26 // Ken Smith - Added conversion operators 27 // Ken Smith - Added conversion operators: 6th Aug 1998 27 // V. Innocente - changed pointers to indice 28 // V. Innocente - changed pointers to indices 3 may 2000 28 // Mark Fischler - Methods for distrib. insta 29 // Mark Fischler - Methods for distrib. instance save/restore 12/8/04 29 // Mark Fischler methods for anonymous sav 30 // Mark Fischler methods for anonymous save/restore 12/27/04 30 // =========================================== 31 // ======================================================================= 31 32 32 #ifndef HepJamesRandom_h 33 #ifndef HepJamesRandom_h 33 #define HepJamesRandom_h 1 34 #define HepJamesRandom_h 1 34 35 35 #include "CLHEP/Random/RandomEngine.h" 36 #include "CLHEP/Random/RandomEngine.h" 36 37 37 namespace CLHEP { 38 namespace CLHEP { 38 39 39 /** 40 /** 40 * @author 41 * @author 41 * @ingroup random 42 * @ingroup random 42 */ 43 */ 43 class HepJamesRandom: public HepRandomEngine { 44 class HepJamesRandom: public HepRandomEngine { 44 45 45 public: 46 public: 46 47 47 HepJamesRandom(std::istream& is); 48 HepJamesRandom(std::istream& is); 48 HepJamesRandom(); 49 HepJamesRandom(); 49 HepJamesRandom(long seed); 50 HepJamesRandom(long seed); 50 HepJamesRandom(int rowIndex, int colIndex); 51 HepJamesRandom(int rowIndex, int colIndex); 51 virtual ~HepJamesRandom(); 52 virtual ~HepJamesRandom(); 52 // Constructor and destructor. 53 // Constructor and destructor. 53 54 54 double flat(); 55 double flat(); 55 // Returns a pseudo random number between 0 56 // Returns a pseudo random number between 0 and 1 56 // (excluding the end points) 57 // (excluding the end points) 57 58 58 void flatArray (const int size, double* vect 59 void flatArray (const int size, double* vect); 59 // Fills the array "vect" of specified size 60 // Fills the array "vect" of specified size with flat random values. 60 61 61 void setSeed(long seed, int dum=0); 62 void setSeed(long seed, int dum=0); 62 // Sets the state of the algorithm according 63 // Sets the state of the algorithm according to seed. 63 64 64 void setSeeds(const long * seeds, int dum=0) 65 void setSeeds(const long * seeds, int dum=0); 65 // Sets the state of the algorithm according 66 // Sets the state of the algorithm according to the zero terminated 66 // array of seeds. Only the first seed is us 67 // array of seeds. Only the first seed is used. 67 68 68 void saveStatus( const char filename[] = "Ja 69 void saveStatus( const char filename[] = "JamesRand.conf" ) const; 69 // Saves on file JamesRand.conf the current 70 // Saves on file JamesRand.conf the current engine status. 70 71 71 void restoreStatus( const char filename[] = 72 void restoreStatus( const char filename[] = "JamesRand.conf" ); 72 // Reads from file JamesRand.conf the last s 73 // Reads from file JamesRand.conf the last saved engine status 73 // and restores it. 74 // and restores it. 74 75 75 void showStatus() const; 76 void showStatus() const; 76 // Dumps the engine status on the screen. 77 // Dumps the engine status on the screen. 77 78 78 operator double(); << 79 // Returns same as flat() << 80 operator float(); << 81 // less precise flat, faster if possible << 82 operator unsigned int(); 79 operator unsigned int(); 83 // 32-bit flat, but slower than double or fl 80 // 32-bit flat, but slower than double or float. 84 81 85 virtual std::ostream & put (std::ostream & o 82 virtual std::ostream & put (std::ostream & os) const; 86 virtual std::istream & get (std::istream & i 83 virtual std::istream & get (std::istream & is); 87 static std::string beginTag ( ); 84 static std::string beginTag ( ); 88 virtual std::istream & getState ( std::istre 85 virtual std::istream & getState ( std::istream & is ); 89 86 90 std::string name() const; 87 std::string name() const; 91 static std::string engineName() {return "Hep 88 static std::string engineName() {return "HepJamesRandom";} 92 89 93 std::vector<unsigned long> put () const; 90 std::vector<unsigned long> put () const; 94 bool get (const std::vector<unsigned long> & 91 bool get (const std::vector<unsigned long> & v); 95 bool getState (const std::vector<unsigned lo 92 bool getState (const std::vector<unsigned long> & v); 96 93 97 static const unsigned int VECTOR_STATE_SIZE 94 static const unsigned int VECTOR_STATE_SIZE = 202; 98 95 99 private: 96 private: 100 97 101 // Members defining the current status of th 98 // Members defining the current status of the generator. 102 double u[97]; 99 double u[97]; 103 double c, cd, cm; 100 double c, cd, cm; 104 int i97, j97; 101 int i97, j97; 105 }; 102 }; 106 103 107 } // namespace CLHEP 104 } // namespace CLHEP 108 105 109 #endif 106 #endif 110 107