CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: Ranlux64Engine.h,v 1.5 2010/06/16 17:24:53 garren Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- Ranlux64Engine --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 // The algorithm for this random engine has been taken from the notes of 00010 // a double-precision ranlux implementation by Martin Luscher, dated 00011 // November 1997. 00012 // 00013 // Like the previous ranlux generator, this one also has "luxury" levels, 00014 // determining how many pseudo-random numbers are discarded for every 00015 // twelve values used. Three levels are given, with the note that Luscher 00016 // himself advocates only the highest two levels for this engine. 00017 // level 0 (p=109): Throw away 109 values for every 12 used 00018 // level 1 (p=202): (default) Throw away 202 values for every 12 used 00019 // level 2 (p=397): Throw away 397 values for every 12 used 00020 // 00021 // The initialization is carried out using a Multiplicative Congruential 00022 // generator using formula constants of L'Ecuyer as described in "F.James, 00023 // Comp. Phys. Comm. 60 (1990) 329-344". 00024 // ======================================================================= 00025 // Ken Smith - Created Initial draft: 14th Jul 1998 00026 // - Added conversion operators: 6th Aug 1998 00027 // Mark Fischler 00028 // 9/9/98 - Added update() routine to allow computation of many at once 00029 // - Replaced algorithm with jone exactly matching Luscher: 00030 // 48-bits generated 00031 // skip n-12 instead of n numbers 00032 // - Corrected protection agains overflow 00033 // 12/8/04 - Methods for instance save/restore 00034 // 12/27/04 - methods for anonymous save/restore 12/27/04 00035 // 00036 // ======================================================================= 00037 00038 #ifndef Ranlux64Engine_h 00039 #define Ranlux64Engine_h 00040 00041 #include "CLHEP/Random/defs.h" 00042 #include "CLHEP/Random/RandomEngine.h" 00043 00044 namespace CLHEP { 00045 00050 class Ranlux64Engine : public HepRandomEngine { 00051 00052 public: 00053 00054 Ranlux64Engine( std::istream& is ); 00055 Ranlux64Engine(); 00056 Ranlux64Engine( long seed, int lux = 1 ); 00057 Ranlux64Engine( int rowIndex, int colIndex, int lux ); 00058 virtual ~Ranlux64Engine(); 00059 // Constructors and destructor 00060 00061 double flat(); 00062 // It returns a pseudo random number between 0 and 1, 00063 // excluding the end points. 00064 00065 void flatArray (const int size, double* vect); 00066 // Fills the array "vect" of specified size with flat random values. 00067 00068 void setSeed(long seed, int lux=1); 00069 // Sets the state of the algorithm according to seed. 00070 00071 void setSeeds(const long * seeds, int lux=1); 00072 // Sets the state of the algorithm according to the zero terminated 00073 // array of seeds. Only the first seed is used. 00074 00075 void saveStatus( const char filename[] = "Ranlux64.conf" ) const; 00076 // Saves in named file the current engine status. 00077 00078 void restoreStatus( const char filename[] = "Ranlux64.conf" ); 00079 // Reads from named file the last saved engine status and restores it. 00080 00081 void showStatus() const; 00082 // Dumps the engine status on the screen. 00083 00084 int getLuxury() const { return luxury; } 00085 // Gets the luxury level. 00086 00087 virtual std::ostream & put (std::ostream & os) const; 00088 virtual std::istream & get (std::istream & is); 00089 static std::string beginTag ( ); 00090 virtual std::istream & getState ( std::istream & is ); 00091 00092 std::string name() const; 00093 static std::string engineName() {return "Ranlux64Engine";} 00094 00095 std::vector<unsigned long> put () const; 00096 bool get (const std::vector<unsigned long> & v); 00097 bool getState (const std::vector<unsigned long> & v); 00098 00099 static const unsigned int VECTOR_STATE_SIZE = 30; 00100 00101 private: 00102 00103 void update(); 00104 void advance(int dozens); 00105 00106 int pDiscard; // separate sequence by p-r = p-12 discarded elements 00107 int pDozens; // pDiscard / 12; 00108 int endIters; // pDiscard % 12; 00109 int luxury; 00110 00111 int index; 00112 double randoms[12]; // randoms [i] is the x[n-i] of Luscher's note 00113 double carry; 00114 00115 static int numEngines; 00116 static int maxIndex; 00117 00118 }; // Ranlux64Engine 00119 00120 } // namespace CLHEP 00121 00122 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00123 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00124 using namespace CLHEP; 00125 #endif 00126 00127 #endif // Ranlux64Engine_h