CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

RanluxEngine.h

Go to the documentation of this file.
00001 // $Id: RanluxEngine.h,v 1.3.4.2 2005/04/15 16:32:53 garren Exp $
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                             HEP Random
00006 //                        --- RanluxEngine ---
00007 //                          class header file
00008 // -----------------------------------------------------------------------
00009 // This file is part of Geant4 (simulation toolkit for HEP).
00010 //
00011 // The algorithm for this random engine has been taken from the original
00012 // implementation in FORTRAN by Fred James as part of the MATHLIB HEP
00013 // library.
00014 // The initialisation is carried out using a Multiplicative Congruential
00015 // generator using formula constants of L'Ecuyer as described in "F.James,
00016 // Comp. Phys. Comm. 60 (1990) 329-344".
00017 
00018 // =======================================================================
00019 // Adeyemi Adesanya - Created: 6th November 1995
00020 // Gabriele Cosmo - Adapted & Revised: 22nd November 1995
00021 // Adeyemi Adesanya - Added setSeeds() method: 2nd February 1996
00022 // Gabriele Cosmo - Added flatArray() method: 8th February 1996
00023 //                - Added methods for engine status: 19th November 1996
00024 //                - Added default luxury value for setSeed()
00025 //                  and setSeeds(): 21st July 1997
00026 // J.Marraffino   - Added stream operators and related constructor.
00027 //                  Added automatic seed selection from seed table and
00028 //                  engine counter: 14th Feb 1998
00029 // Ken Smith      - Added conversion operators:  6th Aug 1998
00030 // Mark Fischler    Methods put, get for instance save/restore 12/8/04    
00031 // Mark Fischler    methods for anonymous save/restore 12/27/04    
00032 // =======================================================================
00033 
00034 #ifndef RanluxEngine_h
00035 #define RanluxEngine_h 1
00036 
00037 #include "CLHEP/Random/defs.h"
00038 #include "CLHEP/Random/RandomEngine.h"
00039 
00040 namespace CLHEP {
00041 
00046 class RanluxEngine : public HepRandomEngine {
00047 
00048 public:
00049 
00050   RanluxEngine( std::istream& is );
00051   RanluxEngine();
00052   RanluxEngine( long seed, int lux = 3 );
00053   RanluxEngine( int rowIndex, int colIndex, int lux );
00054   virtual ~RanluxEngine();
00055   // Constructors and destructor
00056 
00057   RanluxEngine(const RanluxEngine &p);
00058   // Copy constructor
00059 
00060   RanluxEngine & operator = (const RanluxEngine &p);
00061   // Overloaded assignment operator, to retrieve the engine status.
00062 
00063 // Luxury level is set in the same way as the original FORTRAN routine.
00064 //  level 0  (p=24): equivalent to the original RCARRY of Marsaglia
00065 //           and Zaman, very long period, but fails many tests.
00066 //  level 1  (p=48): considerable improvement in quality over level 0,
00067 //           now passes the gap test, but still fails spectral test.
00068 //  level 2  (p=97): passes all known tests, but theoretically still
00069 //           defective.
00070 //  level 3  (p=223): DEFAULT VALUE.  Any theoretically possible
00071 //           correlations have very small chance of being observed.
00072 //  level 4  (p=389): highest possible luxury, all 24 bits chaotic.
00073 
00074   double flat();
00075   // It returns a pseudo random number between 0 and 1,
00076   // excluding the end points.
00077 
00078   void flatArray (const int size, double* vect);
00079   // Fills the array "vect" of specified size with flat random values.
00080 
00081   void setSeed(long seed, int lux=3);
00082   // Sets the state of the algorithm according to seed.
00083 
00084   void setSeeds(const long * seeds, int lux=3);
00085   // Sets the state of the algorithm according to the zero terminated
00086   // array of seeds. Only the first seed is used.
00087 
00088   void saveStatus( const char filename[] = "Ranlux.conf" ) const;
00089   // Saves on file Ranlux.conf the current engine status.
00090 
00091   void restoreStatus( const char filename[] = "Ranlux.conf" );
00092   // Reads from file Ranlux.conf the last saved engine status
00093   // and restores it.
00094 
00095   void showStatus() const;
00096   // Dumps the engine status on the screen.
00097 
00098   int getLuxury() const { return luxury; }
00099   // Gets the luxury level.
00100 
00101   operator unsigned int(); // 32-bit flat, but slower than double or float
00102 
00103   virtual std::ostream & put (std::ostream & os) const;
00104   virtual std::istream & get (std::istream & is);
00105   static  std::string beginTag ( );
00106   virtual std::istream & getState ( std::istream & is );
00107 
00108   std::string name() const;
00109   static std::string engineName() {return "RanluxEngine";}
00110 
00111   std::vector<unsigned long> put () const;
00112   bool get (const std::vector<unsigned long> & v);
00113   bool getState (const std::vector<unsigned long> & v);
00114   
00115   static const unsigned int VECTOR_STATE_SIZE = 31;
00116   
00117 private:
00118 
00119   int nskip, luxury;
00120   float float_seed_table[24];
00121   int i_lag,j_lag;  
00122   float carry;
00123   int count24;
00124   const int int_modulus;
00125   const double mantissa_bit_24;
00126   const double mantissa_bit_12;
00127   static int numEngines;
00128   static int maxIndex;
00129 };
00130 
00131 }  // namespace CLHEP
00132 
00133 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00134 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00135 using namespace CLHEP;
00136 #endif
00137 
00138 #endif

Generated on Thu Jul 1 22:02:30 2010 for CLHEP by  doxygen 1.4.7