Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:03:30

0001 // $Id: RanluxEngine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                             HEP Random
0006 //                        --- RanluxEngine ---
0007 //                          class header file
0008 // -----------------------------------------------------------------------
0009 // This file is part of Geant4 (simulation toolkit for HEP).
0010 //
0011 // The algorithm for this random engine has been taken from the original
0012 // implementation in FORTRAN by Fred James as part of the MATHLIB HEP
0013 // library.
0014 // The initialisation is carried out using a Multiplicative Congruential
0015 // generator using formula constants of L'Ecuyer as described in "F.James,
0016 // Comp. Phys. Comm. 60 (1990) 329-344".
0017 
0018 // =======================================================================
0019 // Adeyemi Adesanya - Created: 6th November 1995
0020 // Gabriele Cosmo - Adapted & Revised: 22nd November 1995
0021 // Adeyemi Adesanya - Added setSeeds() method: 2nd February 1996
0022 // Gabriele Cosmo - Added flatArray() method: 8th February 1996
0023 //                - Added methods for engine status: 19th November 1996
0024 //                - Added default luxury value for setSeed()
0025 //                  and setSeeds(): 21st July 1997
0026 // J.Marraffino   - Added stream operators and related constructor.
0027 //                  Added automatic seed selection from seed table and
0028 //                  engine counter: 14th Feb 1998
0029 // Ken Smith      - Added conversion operators:  6th Aug 1998
0030 // Mark Fischler    Methods put, get for instance save/restore 12/8/04    
0031 // Mark Fischler    methods for anonymous save/restore 12/27/04    
0032 // =======================================================================
0033 
0034 #ifndef RanluxEngine_h
0035 #define RanluxEngine_h 1
0036 
0037 #include "CLHEP/Random/defs.h"
0038 #include "CLHEP/Random/RandomEngine.h"
0039 
0040 namespace CLHEP {
0041 
0042 /**
0043  * @author
0044  * @ingroup random
0045  */
0046 class RanluxEngine : public HepRandomEngine {
0047 
0048 public:
0049 
0050   RanluxEngine( std::istream& is );
0051   RanluxEngine();
0052   RanluxEngine( long seed, int lxr = 3 );
0053   RanluxEngine( int rowIndex, int colIndex, int lxr );
0054   virtual ~RanluxEngine();
0055   // Constructors and destructor
0056 
0057 // Luxury level is set in the same way as the original FORTRAN routine.
0058 //  level 0  (p=24): equivalent to the original RCARRY of Marsaglia
0059 //           and Zaman, very long period, but fails many tests.
0060 //  level 1  (p=48): considerable improvement in quality over level 0,
0061 //           now passes the gap test, but still fails spectral test.
0062 //  level 2  (p=97): passes all known tests, but theoretically still
0063 //           defective.
0064 //  level 3  (p=223): DEFAULT VALUE.  Any theoretically possible
0065 //           correlations have very small chance of being observed.
0066 //  level 4  (p=389): highest possible luxury, all 24 bits chaotic.
0067 
0068   double flat();
0069   // It returns a pseudo random number between 0 and 1,
0070   // excluding the end points.
0071 
0072   void flatArray (const int size, double* vect);
0073   // Fills the array "vect" of specified size with flat random values.
0074 
0075   void setSeed(long seed, int lxr=3);
0076   // Sets the state of the algorithm according to seed.
0077 
0078   void setSeeds(const long * seeds, int lxr=3);
0079   // Sets the state of the algorithm according to the zero terminated
0080   // array of seeds. Only the first seed is used.
0081 
0082   void saveStatus( const char filename[] = "Ranlux.conf" ) const;
0083   // Saves on file Ranlux.conf the current engine status.
0084 
0085   void restoreStatus( const char filename[] = "Ranlux.conf" );
0086   // Reads from file Ranlux.conf the last saved engine status
0087   // and restores it.
0088 
0089   void showStatus() const;
0090   // Dumps the engine status on the screen.
0091 
0092   int getLuxury() const { return luxury; }
0093   // Gets the luxury level.
0094 
0095   operator double();       // Returns same as flat()
0096   operator float();        // less precise flat, faster if possible
0097   operator unsigned int(); // 32-bit flat, but slower than double or float
0098 
0099   virtual std::ostream & put (std::ostream & os) const;
0100   virtual std::istream & get (std::istream & is);
0101   static  std::string beginTag ( );
0102   virtual std::istream & getState ( std::istream & is );
0103 
0104   std::string name() const;
0105   static std::string engineName() {return "RanluxEngine";}
0106 
0107   std::vector<unsigned long> put () const;
0108   bool get (const std::vector<unsigned long> & v);
0109   bool getState (const std::vector<unsigned long> & v);
0110   
0111   static const unsigned int VECTOR_STATE_SIZE = 31;
0112   
0113 private:
0114 
0115   int nskip, luxury;
0116   float float_seed_table[24];
0117   int i_lag,j_lag;  
0118   float carry;
0119   int count24;
0120   static const int int_modulus = 0x1000000;
0121 };
0122 
0123 }  // namespace CLHEP
0124 
0125 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0126 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0127 using namespace CLHEP;
0128 #endif
0129 
0130 #endif