|
||||
File indexing completed on 2025-01-30 10:03:30
0001 // $Id: RanecuEngine.h,v 1.6 2010/07/20 18:06:02 garren Exp $ 0002 // -*- C++ -*- 0003 // 0004 // ----------------------------------------------------------------------- 0005 // HEP Random 0006 // --- RanecuEngine --- 0007 // class header file 0008 // ----------------------------------------------------------------------- 0009 // This file is part of Geant4 (simulation toolkit for HEP). 0010 // 0011 // RANECU Random Engine - algorithm originally written in FORTRAN77 0012 // as part of the MATHLIB HEP library. 0013 // The initialisation is carried out using a Multiplicative Congruential 0014 // generator using formula constants of L'Ecuyer as described in "F.James, 0015 // Comp. Phys. Comm. 60 (1990) 329-344". 0016 // Seeds are taken from a seed table given an index, the getSeed() method 0017 // returns the current index in the seed table, the getSeeds() method 0018 // returns a pointer to the couple of seeds stored in the local table of 0019 // seeds at the current index. 0020 0021 // ======================================================================= 0022 // Gabriele Cosmo - Created: 2nd February 1996 0023 // - Minor corrections: 31st October 1996 0024 // - Added methods for engine status: 19th November 1996 0025 // - setSeed() now has default dummy argument 0026 // set to zero: 11th July 1997 0027 // - Added default index to setSeeds(): 16th Oct 1997 0028 // J.Marraffino - Added stream operators and related constructor. 0029 // Added automatic seed selection from seed table and 0030 // engine counter: 16th Feb 1998 0031 // Ken Smith - Added conversion operators: 6th Aug 1998 0032 // Mark Fischler Methods for distrib. instance save/restore 12/8/04 0033 // Mark Fischler methods for anonymous save/restore 12/27/04 0034 // ======================================================================= 0035 0036 #ifndef RanecuEngine_h 0037 #define RanecuEngine_h 1 0038 0039 #include "CLHEP/Random/defs.h" 0040 #include "CLHEP/Random/RandomEngine.h" 0041 0042 namespace CLHEP { 0043 0044 /** 0045 * @author <Gabriele.Cosmo@cern.ch> 0046 * @ingroup random 0047 */ 0048 class RanecuEngine : public HepRandomEngine { 0049 0050 public: 0051 0052 RanecuEngine(std::istream& is); 0053 RanecuEngine(); 0054 RanecuEngine(int index); 0055 virtual ~RanecuEngine(); 0056 // Constructors and destructor. 0057 0058 double flat(); 0059 // Returns a pseudo random number between 0 and 1 0060 // (excluding the end points) 0061 0062 void flatArray (const int size, double* vect); 0063 // Fills an array "vect" of specified size with flat random values. 0064 0065 void setIndex (long index); 0066 // Sets the state of the algorithm according to "index", the position 0067 // in the local table of seeds. 0068 0069 void setSeed (long index, int dum=0); 0070 // Resets the state of the algorithm according to "index", the position 0071 // in the static table of seeds stored in HepRandom. 0072 0073 void setSeeds (const long* seeds, int index=-1); 0074 // Sets the state of the algorithm according to the array of seeds 0075 // "seeds" containing two seed values to be stored in the local table at 0076 // "index" position. 0077 0078 void saveStatus( const char filename[] = "Ranecu.conf" ) const; 0079 // Saves on file Ranecu.conf the current engine status. 0080 0081 void restoreStatus( const char filename[] = "Ranecu.conf" ); 0082 // Reads from file Ranecu.conf the last saved engine status 0083 // and restores it. 0084 0085 void showStatus() const; 0086 // Dumps the engine status on the screen. 0087 0088 operator double(); 0089 // Returns same as flat() 0090 operator float(); 0091 // less precise flat, faster if possible 0092 operator unsigned int(); 0093 // 32-bit int flat, faster in this case 0094 0095 virtual std::ostream & put (std::ostream & os) const; 0096 virtual std::istream & get (std::istream & is); 0097 static std::string beginTag ( ); 0098 virtual std::istream & getState ( std::istream & is ); 0099 0100 std::string name() const; 0101 static std::string engineName() {return "RanecuEngine";} 0102 0103 std::vector<unsigned long> put () const; 0104 bool get (const std::vector<unsigned long> & v); 0105 bool getState (const std::vector<unsigned long> & v); 0106 0107 protected: 0108 0109 // Suggested L'ecuyer coefficients for portable 32 bits generators. 0110 0111 static const int ecuyer_a = 40014; 0112 static const int ecuyer_b = 53668; 0113 static const int ecuyer_c = 12211; 0114 static const int ecuyer_d = 40692; 0115 static const int ecuyer_e = 52774; 0116 static const int ecuyer_f = 3791; 0117 static const int shift1 = 2147483563; 0118 static const int shift2 = 2147483399; 0119 0120 static const unsigned int VECTOR_STATE_SIZE = 4; 0121 0122 private: 0123 0124 // private method used to mitigate the effects of using a lookup table 0125 void further_randomize (int seq, int col, int index, int modulus); 0126 0127 // Members defining the current state of the generator. 0128 0129 static const int maxSeq = 215; 0130 long table[215][2]; 0131 int seq; 0132 0133 }; 0134 0135 } // namespace CLHEP 0136 0137 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 0138 // backwards compatibility will be enabled ONLY in CLHEP 1.9 0139 using namespace CLHEP; 0140 #endif 0141 0142 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |