CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: RanecuEngine.h,v 1.3.4.2.2.2 2010/06/23 20:49:50 garren Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- RanecuEngine --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 // This file is part of Geant4 (simulation toolkit for HEP). 00010 // 00011 // RANECU Random Engine - algorithm originally written in FORTRAN77 00012 // as part of the MATHLIB HEP library. 00013 // The initialisation is carried out using a Multiplicative Congruential 00014 // generator using formula constants of L'Ecuyer as described in "F.James, 00015 // Comp. Phys. Comm. 60 (1990) 329-344". 00016 // Seeds are taken from a seed table given an index, the getSeed() method 00017 // returns the current index in the seed table, the getSeeds() method 00018 // returns a pointer to the couple of seeds stored in the local table of 00019 // seeds at the current index. 00020 00021 // ======================================================================= 00022 // Gabriele Cosmo - Created: 2nd February 1996 00023 // - Minor corrections: 31st October 1996 00024 // - Added methods for engine status: 19th November 1996 00025 // - setSeed() now has default dummy argument 00026 // set to zero: 11th July 1997 00027 // - Added default index to setSeeds(): 16th Oct 1997 00028 // J.Marraffino - Added stream operators and related constructor. 00029 // Added automatic seed selection from seed table and 00030 // engine counter: 16th Feb 1998 00031 // Ken Smith - Added conversion operators: 6th Aug 1998 00032 // Mark Fischler Methods for distrib. instance save/restore 12/8/04 00033 // Mark Fischler methods for anonymous save/restore 12/27/04 00034 // ======================================================================= 00035 00036 #ifndef RanecuEngine_h 00037 #define RanecuEngine_h 1 00038 00039 #include "CLHEP/Random/defs.h" 00040 #include "CLHEP/Random/RandomEngine.h" 00041 00042 namespace CLHEP { 00043 00048 class RanecuEngine : public HepRandomEngine { 00049 00050 public: 00051 00052 RanecuEngine(std::istream& is); 00053 RanecuEngine(); 00054 RanecuEngine(int index); 00055 virtual ~RanecuEngine(); 00056 // Constructors and destructor. 00057 00058 RanecuEngine(const RanecuEngine &p); 00059 // Copy constructor 00060 00061 RanecuEngine & operator = (const RanecuEngine &p); 00062 // Overloaded assignment operator, to retrieve the engine status. 00063 00064 double flat(); 00065 // Returns a pseudo random number between 0 and 1 00066 // (excluding the end points) 00067 00068 void flatArray (const int size, double* vect); 00069 // Fills an array "vect" of specified size with flat random values. 00070 00071 void setIndex (long index); 00072 // Sets the state of the algorithm according to "index", the position 00073 // in the local table of seeds. 00074 00075 void setSeed (long index, int dum=0); 00076 // Resets the state of the algorithm according to "index", the position 00077 // in the static table of seeds stored in HepRandom. 00078 00079 void setSeeds (const long* seeds, int index=-1); 00080 // Sets the state of the algorithm according to the array of seeds 00081 // "seeds" containing two seed values to be stored in the local table at 00082 // "index" position. 00083 00084 void saveStatus( const char filename[] = "Ranecu.conf" ) const; 00085 // Saves on file Ranecu.conf the current engine status. 00086 00087 void restoreStatus( const char filename[] = "Ranecu.conf" ); 00088 // Reads from file Ranecu.conf the last saved engine status 00089 // and restores it. 00090 00091 void showStatus() const; 00092 // Dumps the engine status on the screen. 00093 00094 operator unsigned int(); 00095 // 32-bit int flat, faster in this case 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 "RanecuEngine";} 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 protected: 00110 00111 // Suggested L'ecuyer coefficients for portable 32 bits generators. 00112 00113 const int ecuyer_a, ecuyer_b, ecuyer_c, ecuyer_d, ecuyer_e, ecuyer_f; 00114 const int shift1, shift2; 00115 const double prec; 00116 00117 static const unsigned int VECTOR_STATE_SIZE = 4; 00118 00119 private: 00120 00121 // private method used to mitigate the effects of using a lookup table 00122 void further_randomize (int seq, int col, int index, int modulus); 00123 00124 // Members defining the current state of the generator. 00125 00126 static const int maxSeq = 215; 00127 long table[215][2]; 00128 int seq; 00129 static int numEngines; 00130 00131 }; 00132 00133 } // namespace CLHEP 00134 00135 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00136 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00137 using namespace CLHEP; 00138 #endif 00139 00140 #endif