CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: JamesRandom.h,v 1.5 2010/06/16 17:24:53 garren Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- HepJamesRandom --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 // This file is part of Geant4 (simulation toolkit for HEP). 00010 // 00011 // HepJamesRandom implements the algorithm by Marsaglia-Zaman RANMAR 00012 // described in "F.James, Comp. Phys. Comm. 60 (1990) 329" and implemented 00013 // in FORTRAN77 as part of the MATHLIB HEP library for pseudo-random 00014 // numbers generation. 00015 // This is the default random engine invoked by each distribution unless 00016 // the user sets a different one. 00017 00018 // ======================================================================= 00019 // Gabriele Cosmo - Created: 5th September 1995 00020 // - Minor corrections: 31st October 1996 00021 // - Added methods for engine status: 19th November 1996 00022 // - setSeed(), setSeeds() now have default dummy argument 00023 // set to zero: 11th July 1997 00024 // J.Marraffino - Added stream operators and related constructor. 00025 // Added automatic seed selection from seed table and 00026 // engine counter: 16th Feb 1998 00027 // Ken Smith - Added conversion operators: 6th Aug 1998 00028 // V. Innocente - changed pointers to indices 3 may 2000 00029 // Mark Fischler - Methods for distrib. instance save/restore 12/8/04 00030 // Mark Fischler methods for anonymous save/restore 12/27/04 00031 // ======================================================================= 00032 00033 #ifndef HepJamesRandom_h 00034 #define HepJamesRandom_h 1 00035 00036 #include "CLHEP/Random/defs.h" 00037 #include "CLHEP/Random/RandomEngine.h" 00038 00039 namespace CLHEP { 00040 00045 class HepJamesRandom: public HepRandomEngine { 00046 00047 public: 00048 00049 HepJamesRandom(std::istream& is); 00050 HepJamesRandom(); 00051 HepJamesRandom(long seed); 00052 HepJamesRandom(int rowIndex, int colIndex); 00053 virtual ~HepJamesRandom(); 00054 // Constructor and destructor. 00055 00056 double flat(); 00057 // Returns a pseudo random number between 0 and 1 00058 // (excluding the end points) 00059 00060 void flatArray (const int size, double* vect); 00061 // Fills the array "vect" of specified size with flat random values. 00062 00063 void setSeed(long seed, int dum=0); 00064 // Sets the state of the algorithm according to seed. 00065 00066 void setSeeds(const long * seeds, int dum=0); 00067 // Sets the state of the algorithm according to the zero terminated 00068 // array of seeds. Only the first seed is used. 00069 00070 void saveStatus( const char filename[] = "JamesRand.conf" ) const; 00071 // Saves on file JamesRand.conf the current engine status. 00072 00073 void restoreStatus( const char filename[] = "JamesRand.conf" ); 00074 // Reads from file JamesRand.conf the last saved engine status 00075 // and restores it. 00076 00077 void showStatus() const; 00078 // Dumps the engine status on the screen. 00079 00080 operator unsigned int(); 00081 // 32-bit flat, but slower than double or float. 00082 00083 virtual std::ostream & put (std::ostream & os) const; 00084 virtual std::istream & get (std::istream & is); 00085 static std::string beginTag ( ); 00086 virtual std::istream & getState ( std::istream & is ); 00087 00088 std::string name() const; 00089 static std::string engineName() {return "HepJamesRandom";} 00090 00091 std::vector<unsigned long> put () const; 00092 bool get (const std::vector<unsigned long> & v); 00093 bool getState (const std::vector<unsigned long> & v); 00094 00095 static const unsigned int VECTOR_STATE_SIZE = 202; 00096 00097 private: 00098 00099 // Members defining the current status of the generator. 00100 double u[97]; 00101 double c, cd, cm; 00102 int i97, j97; 00103 static int numEngines; 00104 static int maxIndex; 00105 }; 00106 00107 } // namespace CLHEP 00108 00109 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00110 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00111 using namespace CLHEP; 00112 #endif 00113 00114 #endif