00001 // $Id: RanecuEngine.h,v 1.14 2002/04/12 15:02:45 evc 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 // ======================================================================= 00033 00034 #ifndef RanecuEngine_h 00035 #define RanecuEngine_h 1 00036 00037 #include "CLHEP/Random/RandomEngine.h" 00038 00043 class RanecuEngine : public HepRandomEngine { 00044 00045 public: 00046 00047 RanecuEngine(HepStd::istream& is); 00048 RanecuEngine(); 00049 RanecuEngine(int index); 00050 virtual ~RanecuEngine(); 00051 // Constructors and destructor. 00052 00053 RanecuEngine(const RanecuEngine &p); 00054 // Copy constructor 00055 00056 RanecuEngine & operator = (const RanecuEngine &p); 00057 // Overloaded assignment operator, to retrieve the engine status. 00058 00059 double flat(); 00060 // Returns a pseudo random number between 0 and 1 00061 // (excluding the end points) 00062 00063 void flatArray (const int size, double* vect); 00064 // Fills an array "vect" of specified size with flat random values. 00065 00066 void setIndex (long index); 00067 // Sets the state of the algorithm according to "index", the position 00068 // in the local table of seeds. 00069 00070 void setSeed (long index, int dum=0); 00071 // Resets the state of the algorithm according to "index", the position 00072 // in the static table of seeds stored in HepRandom. 00073 00074 void setSeeds (const long* seeds, int index=-1); 00075 // Sets the state of the algorithm according to the array of seeds 00076 // "seeds" containing two seed values to be stored in the local table at 00077 // "index" position. 00078 00079 void saveStatus( const char filename[] = "Ranecu.conf" ) const; 00080 // Saves on file Ranecu.conf the current engine status. 00081 00082 void restoreStatus( const char filename[] = "Ranecu.conf" ); 00083 // Reads from file Ranecu.conf the last saved engine status 00084 // and restores it. 00085 00086 void showStatus() const; 00087 // Dumps the engine status on the screen. 00088 00089 operator unsigned int(); 00090 // 32-bit int flat, faster in this case 00091 00092 friend HepStd::ostream& operator<< (HepStd::ostream& os, const RanecuEngine& e); 00093 friend HepStd::istream& operator>> (HepStd::istream& is, RanecuEngine& e); 00094 00095 protected: 00096 00097 // Suggested L'ecuyer coefficients for portable 32 bits generators. 00098 00099 const int ecuyer_a, ecuyer_b, ecuyer_c, ecuyer_d, ecuyer_e, ecuyer_f; 00100 const int shift1, shift2; 00101 const double prec; 00102 00103 private: 00104 00105 // Members defining the current state of the generator. 00106 00107 const int maxSeq; 00108 long table[215][2]; 00109 int seq; 00110 static int numEngines; 00111 00112 }; 00113 00114 #endif