Geant4 Cross Reference |
1 // -*- C++ -*- 1 // -*- C++ -*- 2 // 2 // 3 // ------------------------------------------- 3 // ----------------------------------------------------------------------- 4 // HEP Random 4 // HEP Random 5 // --- RanecuEngine -- 5 // --- RanecuEngine --- 6 // class header file 6 // class header file 7 // ------------------------------------------- 7 // ----------------------------------------------------------------------- 8 // This file is part of Geant4 (simulation too 8 // This file is part of Geant4 (simulation toolkit for HEP). 9 // 9 // 10 // RANECU Random Engine - algorithm originally 10 // RANECU Random Engine - algorithm originally written in FORTRAN77 11 // as part of the MATHL 11 // as part of the MATHLIB HEP library. 12 // The initialisation is carried out using a M 12 // The initialisation is carried out using a Multiplicative Congruential 13 // generator using formula constants of L'Ecuy 13 // generator using formula constants of L'Ecuyer as described in "F.James, 14 // Comp. Phys. Comm. 60 (1990) 329-344". 14 // Comp. Phys. Comm. 60 (1990) 329-344". 15 // Seeds are taken from a seed table given an 15 // Seeds are taken from a seed table given an index, the getSeed() method 16 // returns the current index in the seed table 16 // returns the current index in the seed table, the getSeeds() method 17 // returns a pointer to the couple of seeds st 17 // returns a pointer to the couple of seeds stored in the local table of 18 // seeds at the current index. 18 // seeds at the current index. 19 19 20 // =========================================== 20 // ======================================================================= 21 // Gabriele Cosmo - Created: 2nd February 1996 21 // Gabriele Cosmo - Created: 2nd February 1996 22 // - Minor corrections: 31st Oc 22 // - Minor corrections: 31st October 1996 23 // - Added methods for engine s 23 // - Added methods for engine status: 19th November 1996 24 // - setSeed() now has default 24 // - setSeed() now has default dummy argument 25 // set to zero: 11th July 199 25 // set to zero: 11th July 1997 26 // - Added default index to set 26 // - Added default index to setSeeds(): 16th Oct 1997 27 // J.Marraffino - Added stream operators and 27 // J.Marraffino - Added stream operators and related constructor. 28 // Added automatic seed selec 28 // Added automatic seed selection from seed table and 29 // engine counter: 16th Feb 1 29 // engine counter: 16th Feb 1998 30 // Ken Smith - Added conversion operators 30 // Ken Smith - Added conversion operators: 6th Aug 1998 31 // Mark Fischler Methods for distrib. insta 31 // Mark Fischler Methods for distrib. instance save/restore 12/8/04 32 // Mark Fischler methods for anonymous save 32 // Mark Fischler methods for anonymous save/restore 12/27/04 33 // =========================================== 33 // ======================================================================= 34 34 35 #ifndef RanecuEngine_h 35 #ifndef RanecuEngine_h 36 #define RanecuEngine_h 1 36 #define RanecuEngine_h 1 37 37 38 #include "CLHEP/Random/RandomEngine.h" 38 #include "CLHEP/Random/RandomEngine.h" 39 39 40 namespace CLHEP { 40 namespace CLHEP { 41 41 42 /** 42 /** 43 * @author <Gabriele.Cosmo@cern.ch> 43 * @author <Gabriele.Cosmo@cern.ch> 44 * @ingroup random 44 * @ingroup random 45 */ 45 */ 46 class RanecuEngine : public HepRandomEngine { 46 class RanecuEngine : public HepRandomEngine { 47 47 48 public: 48 public: 49 49 50 RanecuEngine(std::istream& is); 50 RanecuEngine(std::istream& is); 51 RanecuEngine(); 51 RanecuEngine(); 52 RanecuEngine(int index); 52 RanecuEngine(int index); 53 virtual ~RanecuEngine(); 53 virtual ~RanecuEngine(); 54 // Constructors and destructor. 54 // Constructors and destructor. 55 55 56 double flat(); 56 double flat(); 57 // Returns a pseudo random number between 0 57 // Returns a pseudo random number between 0 and 1 58 // (excluding the end points) 58 // (excluding the end points) 59 59 60 void flatArray (const int size, double* vect 60 void flatArray (const int size, double* vect); 61 // Fills an array "vect" of specified size w 61 // Fills an array "vect" of specified size with flat random values. 62 62 63 void setIndex (long index); 63 void setIndex (long index); 64 // Sets the state of the algorithm according 64 // Sets the state of the algorithm according to "index", the position 65 // in the local table of seeds. 65 // in the local table of seeds. 66 66 67 void setSeed (long index, int dum=0); 67 void setSeed (long index, int dum=0); 68 // Resets the state of the algorithm accordi 68 // Resets the state of the algorithm according to "index", the position 69 // in the static table of seeds stored in He 69 // in the static table of seeds stored in HepRandom. 70 70 71 void setSeeds (const long* seeds, int index= 71 void setSeeds (const long* seeds, int index=-1); 72 // Sets the state of the algorithm according 72 // Sets the state of the algorithm according to the array of seeds 73 // "seeds" containing two seed values to be 73 // "seeds" containing two seed values to be stored in the local table at 74 // "index" position. 74 // "index" position. 75 75 76 void saveStatus( const char filename[] = "Ra 76 void saveStatus( const char filename[] = "Ranecu.conf" ) const; 77 // Saves on file Ranecu.conf the current eng 77 // Saves on file Ranecu.conf the current engine status. 78 78 79 void restoreStatus( const char filename[] = 79 void restoreStatus( const char filename[] = "Ranecu.conf" ); 80 // Reads from file Ranecu.conf the last save 80 // Reads from file Ranecu.conf the last saved engine status 81 // and restores it. 81 // and restores it. 82 82 83 void showStatus() const; 83 void showStatus() const; 84 // Dumps the engine status on the screen. 84 // Dumps the engine status on the screen. 85 85 86 operator double(); 86 operator double(); 87 // Returns same as flat() 87 // Returns same as flat() 88 operator float(); 88 operator float(); 89 // less precise flat, faster if possible 89 // less precise flat, faster if possible 90 operator unsigned int(); 90 operator unsigned int(); 91 // 32-bit int flat, faster in this case 91 // 32-bit int flat, faster in this case 92 92 93 virtual std::ostream & put (std::ostream & o 93 virtual std::ostream & put (std::ostream & os) const; 94 virtual std::istream & get (std::istream & i 94 virtual std::istream & get (std::istream & is); 95 static std::string beginTag ( ); 95 static std::string beginTag ( ); 96 virtual std::istream & getState ( std::istre 96 virtual std::istream & getState ( std::istream & is ); 97 97 98 std::string name() const; 98 std::string name() const; 99 static std::string engineName() {return "Ran 99 static std::string engineName() {return "RanecuEngine";} 100 100 101 std::vector<unsigned long> put () const; 101 std::vector<unsigned long> put () const; 102 bool get (const std::vector<unsigned long> & 102 bool get (const std::vector<unsigned long> & v); 103 bool getState (const std::vector<unsigned lo 103 bool getState (const std::vector<unsigned long> & v); 104 104 105 protected: 105 protected: 106 106 107 // Suggested L'ecuyer coefficients for porta 107 // Suggested L'ecuyer coefficients for portable 32 bits generators. 108 108 109 static const int ecuyer_a = 40014; 109 static const int ecuyer_a = 40014; 110 static const int ecuyer_b = 53668; 110 static const int ecuyer_b = 53668; 111 static const int ecuyer_c = 12211; 111 static const int ecuyer_c = 12211; 112 static const int ecuyer_d = 40692; 112 static const int ecuyer_d = 40692; 113 static const int ecuyer_e = 52774; 113 static const int ecuyer_e = 52774; 114 static const int ecuyer_f = 3791; 114 static const int ecuyer_f = 3791; 115 static const int shift1 = 2147483563; 115 static const int shift1 = 2147483563; 116 static const int shift2 = 2147483399; 116 static const int shift2 = 2147483399; 117 117 118 static const unsigned int VECTOR_STATE_SIZE 118 static const unsigned int VECTOR_STATE_SIZE = 4; 119 119 120 private: 120 private: 121 121 122 // private method used to mitigate the effec 122 // private method used to mitigate the effects of using a lookup table 123 void further_randomize (int seq, int col, in 123 void further_randomize (int seq, int col, int index, int modulus); 124 124 125 // Members defining the current state of the 125 // Members defining the current state of the generator. 126 126 127 static const int maxSeq = 215; 127 static const int maxSeq = 215; 128 long table[215][2]; 128 long table[215][2]; 129 int seq; 129 int seq; 130 130 131 }; 131 }; 132 132 133 } // namespace CLHEP 133 } // namespace CLHEP 134 134 135 #endif 135 #endif 136 136