CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Matrix/CLHEP/Random/RanluxEngine.h
Go to the documentation of this file.
1 // $Id: RanluxEngine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- RanluxEngine ---
7 // class header file
8 // -----------------------------------------------------------------------
9 // This file is part of Geant4 (simulation toolkit for HEP).
10 //
11 // The algorithm for this random engine has been taken from the original
12 // implementation in FORTRAN by Fred James as part of the MATHLIB HEP
13 // library.
14 // The initialisation is carried out using a Multiplicative Congruential
15 // generator using formula constants of L'Ecuyer as described in "F.James,
16 // Comp. Phys. Comm. 60 (1990) 329-344".
17 
18 // =======================================================================
19 // Adeyemi Adesanya - Created: 6th November 1995
20 // Gabriele Cosmo - Adapted & Revised: 22nd November 1995
21 // Adeyemi Adesanya - Added setSeeds() method: 2nd February 1996
22 // Gabriele Cosmo - Added flatArray() method: 8th February 1996
23 // - Added methods for engine status: 19th November 1996
24 // - Added default luxury value for setSeed()
25 // and setSeeds(): 21st July 1997
26 // J.Marraffino - Added stream operators and related constructor.
27 // Added automatic seed selection from seed table and
28 // engine counter: 14th Feb 1998
29 // Ken Smith - Added conversion operators: 6th Aug 1998
30 // Mark Fischler Methods put, get for instance save/restore 12/8/04
31 // Mark Fischler methods for anonymous save/restore 12/27/04
32 // =======================================================================
33 
34 #ifndef RanluxEngine_h
35 #define RanluxEngine_h 1
36 
37 #include "CLHEP/Random/defs.h"
38 #include "CLHEP/Random/RandomEngine.h"
39 
40 namespace CLHEP {
41 
46 class RanluxEngine : public HepRandomEngine {
47 
48 public:
49 
50  RanluxEngine( std::istream& is );
51  RanluxEngine();
52  RanluxEngine( long seed, int lux = 3 );
53  RanluxEngine( int rowIndex, int colIndex, int lux );
54  virtual ~RanluxEngine();
55  // Constructors and destructor
56 
57 // Luxury level is set in the same way as the original FORTRAN routine.
58 // level 0 (p=24): equivalent to the original RCARRY of Marsaglia
59 // and Zaman, very long period, but fails many tests.
60 // level 1 (p=48): considerable improvement in quality over level 0,
61 // now passes the gap test, but still fails spectral test.
62 // level 2 (p=97): passes all known tests, but theoretically still
63 // defective.
64 // level 3 (p=223): DEFAULT VALUE. Any theoretically possible
65 // correlations have very small chance of being observed.
66 // level 4 (p=389): highest possible luxury, all 24 bits chaotic.
67 
68  double flat();
69  // It returns a pseudo random number between 0 and 1,
70  // excluding the end points.
71 
72  void flatArray (const int size, double* vect);
73  // Fills the array "vect" of specified size with flat random values.
74 
75  void setSeed(long seed, int lux=3);
76  // Sets the state of the algorithm according to seed.
77 
78  void setSeeds(const long * seeds, int lux=3);
79  // Sets the state of the algorithm according to the zero terminated
80  // array of seeds. Only the first seed is used.
81 
82  void saveStatus( const char filename[] = "Ranlux.conf" ) const;
83  // Saves on file Ranlux.conf the current engine status.
84 
85  void restoreStatus( const char filename[] = "Ranlux.conf" );
86  // Reads from file Ranlux.conf the last saved engine status
87  // and restores it.
88 
89  void showStatus() const;
90  // Dumps the engine status on the screen.
91 
92  int getLuxury() const { return luxury; }
93  // Gets the luxury level.
94 
95  operator unsigned int(); // 32-bit flat, but slower than double or float
96 
97  virtual std::ostream & put (std::ostream & os) const;
98  virtual std::istream & get (std::istream & is);
99  static std::string beginTag ( );
100  virtual std::istream & getState ( std::istream & is );
101 
102  std::string name() const;
103  static std::string engineName() {return "RanluxEngine";}
104 
105  std::vector<unsigned long> put () const;
106  bool get (const std::vector<unsigned long> & v);
107  bool getState (const std::vector<unsigned long> & v);
108 
109  static const unsigned int VECTOR_STATE_SIZE = 31;
110 
111 private:
112 
113  int nskip, luxury;
114  float float_seed_table[24];
115  int i_lag,j_lag;
116  float carry;
117  int count24;
118  static const int int_modulus = 0x1000000;
119  static int numEngines;
120  static int maxIndex;
121 };
122 
123 } // namespace CLHEP
124 
125 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
126 // backwards compatibility will be enabled ONLY in CLHEP 1.9
127 using namespace CLHEP;
128 #endif
129 
130 #endif