CLHEP/Random/RanluxEngine.h

00001 // $Id: RanluxEngine.h,v 1.13 2002/04/12 15:02:45 evc 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 // =======================================================================
00031 
00032 #ifndef RanluxEngine_h
00033 #define RanluxEngine_h 1
00034 
00035 #include "CLHEP/Random/RandomEngine.h"
00036 
00041 class RanluxEngine : public HepRandomEngine {
00042 
00043 public:
00044 
00045   RanluxEngine( HepStd::istream& is );
00046   RanluxEngine();
00047   RanluxEngine( long seed, int lux = 3 );
00048   RanluxEngine( int rowIndex, int colIndex, int lux );
00049   virtual ~RanluxEngine();
00050   // Constructors and destructor
00051 
00052   RanluxEngine(const RanluxEngine &p);
00053   // Copy constructor
00054 
00055   RanluxEngine & operator = (const RanluxEngine &p);
00056   // Overloaded assignment operator, to retrieve the engine status.
00057 
00058 // Luxury level is set in the same way as the original FORTRAN routine.
00059 //  level 0  (p=24): equivalent to the original RCARRY of Marsaglia
00060 //           and Zaman, very long period, but fails many tests.
00061 //  level 1  (p=48): considerable improvement in quality over level 0,
00062 //           now passes the gap test, but still fails spectral test.
00063 //  level 2  (p=97): passes all known tests, but theoretically still
00064 //           defective.
00065 //  level 3  (p=223): DEFAULT VALUE.  Any theoretically possible
00066 //           correlations have very small chance of being observed.
00067 //  level 4  (p=389): highest possible luxury, all 24 bits chaotic.
00068 
00069   double flat();
00070   // It returns a pseudo random number between 0 and 1,
00071   // excluding the end points.
00072 
00073   void flatArray (const int size, double* vect);
00074   // Fills the array "vect" of specified size with flat random values.
00075 
00076   void setSeed(long seed, int lux=3);
00077   // Sets the state of the algorithm according to seed.
00078 
00079   void setSeeds(const long * seeds, int lux=3);
00080   // Sets the state of the algorithm according to the zero terminated
00081   // array of seeds. Only the first seed is used.
00082 
00083   void saveStatus( const char filename[] = "Ranlux.conf" ) const;
00084   // Saves on file Ranlux.conf the current engine status.
00085 
00086   void restoreStatus( const char filename[] = "Ranlux.conf" );
00087   // Reads from file Ranlux.conf the last saved engine status
00088   // and restores it.
00089 
00090   void showStatus() const;
00091   // Dumps the engine status on the screen.
00092 
00093   int getLuxury() const { return luxury; }
00094   // Gets the luxury level.
00095 
00096   operator unsigned int(); // 32-bit flat, but slower than double or float
00097 
00098   friend HepStd::ostream& operator<< (HepStd::ostream& os, const RanluxEngine& e);
00099   friend HepStd::istream& operator>> (HepStd::istream& is,       RanluxEngine& e);
00100 
00101 private:
00102 
00103   int nskip, luxury;
00104   float float_seed_table[24];
00105   int i_lag,j_lag;  
00106   float carry;
00107   int count24;
00108   const int int_modulus;
00109   const double mantissa_bit_24;
00110   const double mantissa_bit_12;
00111   static int numEngines;
00112   static int maxIndex;
00113 };
00114 
00115 #endif

Class Library for High Energy Physics (version 1.8)