1 // $Id: RanecuEngine.h,v 1.6 2010/07/20 18:06:02 garren Exp $ 2 // -*- C++ -*- 3 // 4 // ----------------------------------------------------------------------- 5 // HEP Random 6 // --- RanecuEngine --- 7 // class header file 8 // ----------------------------------------------------------------------- 9 // This file is part of Geant4 (simulation toolkit for HEP). 10 // 11 // RANECU Random Engine - algorithm originally written in FORTRAN77 12 // as part of the MATHLIB HEP library. 13 // The initialisation is carried out using a Multiplicative Congruential 14 // generator using formula constants of L'Ecuyer as described in "F.James, 15 // Comp. Phys. Comm. 60 (1990) 329-344". 16 // Seeds are taken from a seed table given an index, the getSeed() method 17 // returns the current index in the seed table, the getSeeds() method 18 // returns a pointer to the couple of seeds stored in the local table of 19 // seeds at the current index. 20 21 // ======================================================================= 22 // Gabriele Cosmo - Created: 2nd February 1996 23 // - Minor corrections: 31st October 1996 24 // - Added methods for engine status: 19th November 1996 25 // - setSeed() now has default dummy argument 26 // set to zero: 11th July 1997 27 // - Added default index to setSeeds(): 16th Oct 1997 28 // J.Marraffino - Added stream operators and related constructor. 29 // Added automatic seed selection from seed table and 30 // engine counter: 16th Feb 1998 31 // Ken Smith - Added conversion operators: 6th Aug 1998 32 // Mark Fischler Methods for distrib. instance save/restore 12/8/04 33 // Mark Fischler methods for anonymous save/restore 12/27/04 34 // ======================================================================= 35 36 #ifndef RanecuEngine_h 37 #define RanecuEngine_h 1 38 39 #include "CLHEP/Random/defs.h" 40 #include "CLHEP/Random/RandomEngine.h" 41 42 namespace CLHEP { 43 44 /** 45 * @author <Gabriele.Cosmo@cern.ch> 46 * @ingroup random 47 */ 48 class RanecuEngine : public HepRandomEngine { 49 50 public: 51 52 RanecuEngine(std::istream& is); 53 RanecuEngine(); 54 RanecuEngine(int index); 55 virtual ~RanecuEngine(); 56 // Constructors and destructor. 57 58 double flat(); 59 // Returns a pseudo random number between 0 and 1 60 // (excluding the end points) 61 62 void flatArray (const int size, double* vect); 63 // Fills an array "vect" of specified size with flat random values. 64 65 void setIndex (long index); 66 // Sets the state of the algorithm according to "index", the position 67 // in the local table of seeds. 68 69 void setSeed (long index, int dum=0); 70 // Resets the state of the algorithm according to "index", the position 71 // in the static table of seeds stored in HepRandom. 72 73 void setSeeds (const long* seeds, int index=-1); 74 // Sets the state of the algorithm according to the array of seeds 75 // "seeds" containing two seed values to be stored in the local table at 76 // "index" position. 77 78 void saveStatus( const char filename[] = "Ranecu.conf" ) const; 79 // Saves on file Ranecu.conf the current engine status. 80 81 void restoreStatus( const char filename[] = "Ranecu.conf" ); 82 // Reads from file Ranecu.conf the last saved engine status 83 // and restores it. 84 85 void showStatus() const; 86 // Dumps the engine status on the screen. 87 88 operator double(); 89 // Returns same as flat() 90 operator float(); 91 // less precise flat, faster if possible 92 operator unsigned int(); 93 // 32-bit int flat, faster in this case 94 95 virtual std::ostream & put (std::ostream & os) const; 96 virtual std::istream & get (std::istream & is); 97 static std::string beginTag ( ); 98 virtual std::istream & getState ( std::istream & is ); 99 100 std::string name() const; engineName()101 static std::string engineName() {return "RanecuEngine";} 102 103 std::vector<unsigned long> put () const; 104 bool get (const std::vector<unsigned long> & v); 105 bool getState (const std::vector<unsigned long> & v); 106 107 protected: 108 109 // Suggested L'ecuyer coefficients for portable 32 bits generators. 110 111 static const int ecuyer_a = 40014; 112 static const int ecuyer_b = 53668; 113 static const int ecuyer_c = 12211; 114 static const int ecuyer_d = 40692; 115 static const int ecuyer_e = 52774; 116 static const int ecuyer_f = 3791; 117 static const int shift1 = 2147483563; 118 static const int shift2 = 2147483399; 119 120 static const unsigned int VECTOR_STATE_SIZE = 4; 121 122 private: 123 124 // private method used to mitigate the effects of using a lookup table 125 void further_randomize (int seq, int col, int index, int modulus); 126 127 // Members defining the current state of the generator. 128 129 static const int maxSeq = 215; 130 long table[215][2]; 131 int seq; 132 133 }; 134 135 } // namespace CLHEP 136 137 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 138 // backwards compatibility will be enabled ONLY in CLHEP 1.9 139 using namespace CLHEP; 140 #endif 141 142 #endif 143