CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: RanluxEngine.h,v 1.5 2010/06/16 17:24:53 garren Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- RanluxEngine --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 // This file is part of Geant4 (simulation toolkit for HEP). 00010 // 00011 // The algorithm for this random engine has been taken from the original 00012 // implementation in FORTRAN by Fred James as part of the MATHLIB HEP 00013 // library. 00014 // The initialisation is carried out using a Multiplicative Congruential 00015 // generator using formula constants of L'Ecuyer as described in "F.James, 00016 // Comp. Phys. Comm. 60 (1990) 329-344". 00017 00018 // ======================================================================= 00019 // Adeyemi Adesanya - Created: 6th November 1995 00020 // Gabriele Cosmo - Adapted & Revised: 22nd November 1995 00021 // Adeyemi Adesanya - Added setSeeds() method: 2nd February 1996 00022 // Gabriele Cosmo - Added flatArray() method: 8th February 1996 00023 // - Added methods for engine status: 19th November 1996 00024 // - Added default luxury value for setSeed() 00025 // and setSeeds(): 21st July 1997 00026 // J.Marraffino - Added stream operators and related constructor. 00027 // Added automatic seed selection from seed table and 00028 // engine counter: 14th Feb 1998 00029 // Ken Smith - Added conversion operators: 6th Aug 1998 00030 // Mark Fischler Methods put, get for instance save/restore 12/8/04 00031 // Mark Fischler methods for anonymous save/restore 12/27/04 00032 // ======================================================================= 00033 00034 #ifndef RanluxEngine_h 00035 #define RanluxEngine_h 1 00036 00037 #include "CLHEP/Random/defs.h" 00038 #include "CLHEP/Random/RandomEngine.h" 00039 00040 namespace CLHEP { 00041 00046 class RanluxEngine : public HepRandomEngine { 00047 00048 public: 00049 00050 RanluxEngine( std::istream& is ); 00051 RanluxEngine(); 00052 RanluxEngine( long seed, int lux = 3 ); 00053 RanluxEngine( int rowIndex, int colIndex, int lux ); 00054 virtual ~RanluxEngine(); 00055 // Constructors and destructor 00056 00057 // Luxury level is set in the same way as the original FORTRAN routine. 00058 // level 0 (p=24): equivalent to the original RCARRY of Marsaglia 00059 // and Zaman, very long period, but fails many tests. 00060 // level 1 (p=48): considerable improvement in quality over level 0, 00061 // now passes the gap test, but still fails spectral test. 00062 // level 2 (p=97): passes all known tests, but theoretically still 00063 // defective. 00064 // level 3 (p=223): DEFAULT VALUE. Any theoretically possible 00065 // correlations have very small chance of being observed. 00066 // level 4 (p=389): highest possible luxury, all 24 bits chaotic. 00067 00068 double flat(); 00069 // It returns a pseudo random number between 0 and 1, 00070 // excluding the end points. 00071 00072 void flatArray (const int size, double* vect); 00073 // Fills the array "vect" of specified size with flat random values. 00074 00075 void setSeed(long seed, int lux=3); 00076 // Sets the state of the algorithm according to seed. 00077 00078 void setSeeds(const long * seeds, int lux=3); 00079 // Sets the state of the algorithm according to the zero terminated 00080 // array of seeds. Only the first seed is used. 00081 00082 void saveStatus( const char filename[] = "Ranlux.conf" ) const; 00083 // Saves on file Ranlux.conf the current engine status. 00084 00085 void restoreStatus( const char filename[] = "Ranlux.conf" ); 00086 // Reads from file Ranlux.conf the last saved engine status 00087 // and restores it. 00088 00089 void showStatus() const; 00090 // Dumps the engine status on the screen. 00091 00092 int getLuxury() const { return luxury; } 00093 // Gets the luxury level. 00094 00095 operator unsigned int(); // 32-bit flat, but slower than double or float 00096 00097 virtual std::ostream & put (std::ostream & os) const; 00098 virtual std::istream & get (std::istream & is); 00099 static std::string beginTag ( ); 00100 virtual std::istream & getState ( std::istream & is ); 00101 00102 std::string name() const; 00103 static std::string engineName() {return "RanluxEngine";} 00104 00105 std::vector<unsigned long> put () const; 00106 bool get (const std::vector<unsigned long> & v); 00107 bool getState (const std::vector<unsigned long> & v); 00108 00109 static const unsigned int VECTOR_STATE_SIZE = 31; 00110 00111 private: 00112 00113 int nskip, luxury; 00114 float float_seed_table[24]; 00115 int i_lag,j_lag; 00116 float carry; 00117 int count24; 00118 static const int int_modulus = 0x1000000; 00119 static int numEngines; 00120 static int maxIndex; 00121 }; 00122 00123 } // namespace CLHEP 00124 00125 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00126 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00127 using namespace CLHEP; 00128 #endif 00129 00130 #endif