Geant4 Cross Reference |
>> 1 // $Id:$ 1 // -*- C++ -*- 2 // -*- C++ -*- 2 // 3 // 3 // ------------------------------------------- 4 // ----------------------------------------------------------------------- 4 // HEP Random 5 // HEP Random 5 // --- Ranlux64Engine - 6 // --- Ranlux64Engine --- 6 // class header file 7 // class header file 7 // ------------------------------------------- 8 // ----------------------------------------------------------------------- 8 // The algorithm for this random engine has be 9 // The algorithm for this random engine has been taken from the notes of 9 // a double-precision ranlux implementation by 10 // a double-precision ranlux implementation by Martin Luscher, dated 10 // November 1997. 11 // November 1997. 11 // 12 // 12 // Like the previous ranlux generator, this on 13 // Like the previous ranlux generator, this one also has "luxury" levels, 13 // determining how many pseudo-random numbers 14 // determining how many pseudo-random numbers are discarded for every 14 // twelve values used. Three levels are given, 15 // twelve values used. Three levels are given, with the note that Luscher 15 // himself advocates only the highest two leve 16 // himself advocates only the highest two levels for this engine. 16 // level 0 (p=109): Throw away 17 // level 0 (p=109): Throw away 109 values for every 12 used 17 // level 1 (p=202): (default) Throw away 18 // level 1 (p=202): (default) Throw away 202 values for every 12 used 18 // level 2 (p=397): Throw away 19 // level 2 (p=397): Throw away 397 values for every 12 used 19 // 20 // 20 // The initialization is carried out using a M 21 // The initialization is carried out using a Multiplicative Congruential 21 // generator using formula constants of L'Ecuy 22 // generator using formula constants of L'Ecuyer as described in "F.James, 22 // Comp. Phys. Comm. 60 (1990) 329-344". 23 // Comp. Phys. Comm. 60 (1990) 329-344". 23 // =========================================== 24 // ======================================================================= 24 // Ken Smith - Created Initial draft: 14t 25 // Ken Smith - Created Initial draft: 14th Jul 1998 25 // - Added conversion operators 26 // - Added conversion operators: 6th Aug 1998 26 // Mark Fischler 27 // Mark Fischler 27 // 9/9/98 - Added update() routine to allow 28 // 9/9/98 - Added update() routine to allow computation of many at once 28 // - Replaced algorithm with jone exactly 29 // - Replaced algorithm with jone exactly matching Luscher: 29 // 48-bits generated 30 // 48-bits generated 30 // skip n-12 instead of n numbers 31 // skip n-12 instead of n numbers 31 // - Corrected protection agains overflow 32 // - Corrected protection agains overflow 32 // 12/8/04 - Methods for instance save/ 33 // 12/8/04 - Methods for instance save/restore 33 // 12/27/04 - methods for anonymous save 34 // 12/27/04 - methods for anonymous save/restore 12/27/04 34 // 35 // 35 // =========================================== 36 // ======================================================================= 36 37 37 #ifndef Ranlux64Engine_h 38 #ifndef Ranlux64Engine_h 38 #define Ranlux64Engine_h 39 #define Ranlux64Engine_h 39 40 40 #include "CLHEP/Random/RandomEngine.h" 41 #include "CLHEP/Random/RandomEngine.h" 41 42 42 namespace CLHEP { 43 namespace CLHEP { 43 44 44 /** 45 /** 45 * @author 46 * @author 46 * @ingroup random 47 * @ingroup random 47 */ 48 */ 48 class Ranlux64Engine : public HepRandomEngine 49 class Ranlux64Engine : public HepRandomEngine { 49 50 50 public: 51 public: 51 52 52 Ranlux64Engine( std::istream& is ); 53 Ranlux64Engine( std::istream& is ); 53 Ranlux64Engine(); 54 Ranlux64Engine(); 54 Ranlux64Engine( long seed, int lxr = 1 ); << 55 Ranlux64Engine( long seed, int lux = 1 ); 55 Ranlux64Engine( int rowIndex, int colIndex, << 56 Ranlux64Engine( int rowIndex, int colIndex, int lux ); 56 virtual ~Ranlux64Engine(); 57 virtual ~Ranlux64Engine(); 57 // Constructors and destructor 58 // Constructors and destructor 58 59 59 double flat(); 60 double flat(); 60 // It returns a pseudo random number between 61 // It returns a pseudo random number between 0 and 1, 61 // excluding the end points. 62 // excluding the end points. 62 63 63 void flatArray (const int size, double* vect 64 void flatArray (const int size, double* vect); 64 // Fills the array "vect" of specified size 65 // Fills the array "vect" of specified size with flat random values. 65 66 66 void setSeed(long seed, int lxr=1); << 67 void setSeed(long seed, int lux=1); 67 // Sets the state of the algorithm according 68 // Sets the state of the algorithm according to seed. 68 69 69 void setSeeds(const long * seeds, int lxr=1) << 70 void setSeeds(const long * seeds, int lux=1); 70 // Sets the state of the algorithm according 71 // Sets the state of the algorithm according to the zero terminated 71 // array of seeds. Only the first seed is u 72 // array of seeds. Only the first seed is used. 72 73 73 void saveStatus( const char filename[] = "Ra 74 void saveStatus( const char filename[] = "Ranlux64.conf" ) const; 74 // Saves in named file the current engine st 75 // Saves in named file the current engine status. 75 76 76 void restoreStatus( const char filename[] = 77 void restoreStatus( const char filename[] = "Ranlux64.conf" ); 77 // Reads from named file the last saved engi 78 // Reads from named file the last saved engine status and restores it. 78 79 79 void showStatus() const; 80 void showStatus() const; 80 // Dumps the engine status on the screen. 81 // Dumps the engine status on the screen. 81 82 82 int getLuxury() const { return luxury; } 83 int getLuxury() const { return luxury; } 83 // Gets the luxury level. 84 // Gets the luxury level. 84 85 85 virtual std::ostream & put (std::ostream & o 86 virtual std::ostream & put (std::ostream & os) const; 86 virtual std::istream & get (std::istream & i 87 virtual std::istream & get (std::istream & is); 87 static std::string beginTag ( ); 88 static std::string beginTag ( ); 88 virtual std::istream & getState ( std::istre 89 virtual std::istream & getState ( std::istream & is ); 89 90 90 std::string name() const; 91 std::string name() const; 91 static std::string engineName() {return "Ran 92 static std::string engineName() {return "Ranlux64Engine";} 92 93 93 std::vector<unsigned long> put () const; 94 std::vector<unsigned long> put () const; 94 bool get (const std::vector<unsigned long> & 95 bool get (const std::vector<unsigned long> & v); 95 bool getState (const std::vector<unsigned lo 96 bool getState (const std::vector<unsigned long> & v); 96 97 97 static const unsigned int VECTOR_STATE_SIZE 98 static const unsigned int VECTOR_STATE_SIZE = 30; 98 99 99 private: 100 private: 100 101 101 void update(); 102 void update(); 102 void advance(int dozens); 103 void advance(int dozens); 103 104 104 int pDiscard; // separate sequence by p- 105 int pDiscard; // separate sequence by p-r = p-12 discarded elements 105 int pDozens; // pDiscard / 12; 106 int pDozens; // pDiscard / 12; 106 int endIters; // pDiscard % 12; 107 int endIters; // pDiscard % 12; 107 int luxury; 108 int luxury; 108 109 109 int index; 110 int index; 110 double randoms[12]; // randoms [i] is the x[ 111 double randoms[12]; // randoms [i] is the x[n-i] of Luscher's note 111 double carry; 112 double carry; >> 113 >> 114 static int numEngines; >> 115 static int maxIndex; 112 116 113 }; // Ranlux64Engine 117 }; // Ranlux64Engine 114 118 115 } // namespace CLHEP 119 } // namespace CLHEP 116 120 117 #endif // Ranlux64Engine_h 121 #endif // Ranlux64Engine_h 118 122