Geant4 Cross Reference |
1 // -*- C++ -*- 1 // -*- C++ -*- 2 // 2 // 3 // ------------------------------------------- 3 // ----------------------------------------------------------------------- 4 // HEP Random 4 // HEP Random 5 // --- RanluxEngine --- 5 // --- RanluxEngine --- 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 // The algorithm for this random engine has be 10 // The algorithm for this random engine has been taken from the original 11 // implementation in FORTRAN by Fred James as 11 // implementation in FORTRAN by Fred James as part of the MATHLIB HEP 12 // library. 12 // library. 13 // The initialisation is carried out using a M 13 // The initialisation is carried out using a Multiplicative Congruential 14 // generator using formula constants of L'Ecuy 14 // generator using formula constants of L'Ecuyer as described in "F.James, 15 // Comp. Phys. Comm. 60 (1990) 329-344". 15 // Comp. Phys. Comm. 60 (1990) 329-344". 16 16 17 // =========================================== 17 // ======================================================================= 18 // Adeyemi Adesanya - Created: 6th November 19 18 // Adeyemi Adesanya - Created: 6th November 1995 19 // Gabriele Cosmo - Adapted & Revised: 22nd No 19 // Gabriele Cosmo - Adapted & Revised: 22nd November 1995 20 // Adeyemi Adesanya - Added setSeeds() method: 20 // Adeyemi Adesanya - Added setSeeds() method: 2nd February 1996 21 // Gabriele Cosmo - Added flatArray() method: 21 // Gabriele Cosmo - Added flatArray() method: 8th February 1996 22 // - Added methods for engine s 22 // - Added methods for engine status: 19th November 1996 23 // - Added default luxury value 23 // - Added default luxury value for setSeed() 24 // and setSeeds(): 21st July 24 // and setSeeds(): 21st July 1997 25 // J.Marraffino - Added stream operators and 25 // J.Marraffino - Added stream operators and related constructor. 26 // Added automatic seed selec 26 // Added automatic seed selection from seed table and 27 // engine counter: 14th Feb 1 27 // engine counter: 14th Feb 1998 28 // Ken Smith - Added conversion operators 28 // Ken Smith - Added conversion operators: 6th Aug 1998 29 // Mark Fischler Methods put, get for insta 29 // Mark Fischler Methods put, get for instance save/restore 12/8/04 30 // Mark Fischler methods for anonymous save 30 // Mark Fischler methods for anonymous save/restore 12/27/04 31 // =========================================== 31 // ======================================================================= 32 32 33 #ifndef RanluxEngine_h 33 #ifndef RanluxEngine_h 34 #define RanluxEngine_h 1 34 #define RanluxEngine_h 1 35 35 36 #include "CLHEP/Random/RandomEngine.h" 36 #include "CLHEP/Random/RandomEngine.h" 37 37 38 namespace CLHEP { 38 namespace CLHEP { 39 39 40 /** 40 /** 41 * @author 41 * @author 42 * @ingroup random 42 * @ingroup random 43 */ 43 */ 44 class RanluxEngine : public HepRandomEngine { 44 class RanluxEngine : public HepRandomEngine { 45 45 46 public: 46 public: 47 47 48 RanluxEngine( std::istream& is ); 48 RanluxEngine( std::istream& is ); 49 RanluxEngine(); 49 RanluxEngine(); 50 RanluxEngine( long seed, int lxr = 3 ); << 50 RanluxEngine( long seed, int lux = 3 ); 51 RanluxEngine( int rowIndex, int colIndex, in << 51 RanluxEngine( int rowIndex, int colIndex, int lux ); 52 virtual ~RanluxEngine(); 52 virtual ~RanluxEngine(); 53 // Constructors and destructor 53 // Constructors and destructor 54 54 55 // Luxury level is set in the same way as the 55 // Luxury level is set in the same way as the original FORTRAN routine. 56 // level 0 (p=24): equivalent to the origina 56 // level 0 (p=24): equivalent to the original RCARRY of Marsaglia 57 // and Zaman, very long period, but 57 // and Zaman, very long period, but fails many tests. 58 // level 1 (p=48): considerable improvement 58 // level 1 (p=48): considerable improvement in quality over level 0, 59 // now passes the gap test, but stil 59 // now passes the gap test, but still fails spectral test. 60 // level 2 (p=97): passes all known tests, b 60 // level 2 (p=97): passes all known tests, but theoretically still 61 // defective. 61 // defective. 62 // level 3 (p=223): DEFAULT VALUE. Any theo 62 // level 3 (p=223): DEFAULT VALUE. Any theoretically possible 63 // correlations have very small chan 63 // correlations have very small chance of being observed. 64 // level 4 (p=389): highest possible luxury, 64 // level 4 (p=389): highest possible luxury, all 24 bits chaotic. 65 65 66 double flat(); 66 double flat(); 67 // It returns a pseudo random number between 67 // It returns a pseudo random number between 0 and 1, 68 // excluding the end points. 68 // excluding the end points. 69 69 70 void flatArray (const int size, double* vect 70 void flatArray (const int size, double* vect); 71 // Fills the array "vect" of specified size 71 // Fills the array "vect" of specified size with flat random values. 72 72 73 void setSeed(long seed, int lxr=3); << 73 void setSeed(long seed, int lux=3); 74 // Sets the state of the algorithm according 74 // Sets the state of the algorithm according to seed. 75 75 76 void setSeeds(const long * seeds, int lxr=3) << 76 void setSeeds(const long * seeds, int lux=3); 77 // Sets the state of the algorithm according 77 // Sets the state of the algorithm according to the zero terminated 78 // array of seeds. Only the first seed is us 78 // array of seeds. Only the first seed is used. 79 79 80 void saveStatus( const char filename[] = "Ra 80 void saveStatus( const char filename[] = "Ranlux.conf" ) const; 81 // Saves on file Ranlux.conf the current eng 81 // Saves on file Ranlux.conf the current engine status. 82 82 83 void restoreStatus( const char filename[] = 83 void restoreStatus( const char filename[] = "Ranlux.conf" ); 84 // Reads from file Ranlux.conf the last save 84 // Reads from file Ranlux.conf the last saved engine status 85 // and restores it. 85 // and restores it. 86 86 87 void showStatus() const; 87 void showStatus() const; 88 // Dumps the engine status on the screen. 88 // Dumps the engine status on the screen. 89 89 90 int getLuxury() const { return luxury; } 90 int getLuxury() const { return luxury; } 91 // Gets the luxury level. 91 // Gets the luxury level. 92 92 93 operator double(); // Returns same as 93 operator double(); // Returns same as flat() 94 operator float(); // less precise fla 94 operator float(); // less precise flat, faster if possible 95 operator unsigned int(); // 32-bit flat, but 95 operator unsigned int(); // 32-bit flat, but slower than double or float 96 96 97 virtual std::ostream & put (std::ostream & o 97 virtual std::ostream & put (std::ostream & os) const; 98 virtual std::istream & get (std::istream & i 98 virtual std::istream & get (std::istream & is); 99 static std::string beginTag ( ); 99 static std::string beginTag ( ); 100 virtual std::istream & getState ( std::istre 100 virtual std::istream & getState ( std::istream & is ); 101 101 102 std::string name() const; 102 std::string name() const; 103 static std::string engineName() {return "Ran 103 static std::string engineName() {return "RanluxEngine";} 104 104 105 std::vector<unsigned long> put () const; 105 std::vector<unsigned long> put () const; 106 bool get (const std::vector<unsigned long> & 106 bool get (const std::vector<unsigned long> & v); 107 bool getState (const std::vector<unsigned lo 107 bool getState (const std::vector<unsigned long> & v); 108 108 109 static const unsigned int VECTOR_STATE_SIZE 109 static const unsigned int VECTOR_STATE_SIZE = 31; 110 110 111 private: 111 private: 112 112 113 int nskip, luxury; 113 int nskip, luxury; 114 float float_seed_table[24]; 114 float float_seed_table[24]; 115 int i_lag,j_lag; 115 int i_lag,j_lag; 116 float carry; 116 float carry; 117 int count24; 117 int count24; 118 static const int int_modulus = 0x1000000; 118 static const int int_modulus = 0x1000000; 119 }; 119 }; 120 120 121 } // namespace CLHEP 121 } // namespace CLHEP 122 122 123 #endif 123 #endif 124 124