Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RanluxEngine.h
Go to the documentation of this file.
1 // $Id:$
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 
38 
39 namespace CLHEP {
40 
45 class RanluxEngine : public HepRandomEngine {
46 
47 public:
48 
49  RanluxEngine( std::istream& is );
50  RanluxEngine();
51  RanluxEngine( long seed, int lux = 3 );
52  RanluxEngine( int rowIndex, int colIndex, int lux );
53  virtual ~RanluxEngine();
54  // Constructors and destructor
55 
56 // Luxury level is set in the same way as the original FORTRAN routine.
57 // level 0 (p=24): equivalent to the original RCARRY of Marsaglia
58 // and Zaman, very long period, but fails many tests.
59 // level 1 (p=48): considerable improvement in quality over level 0,
60 // now passes the gap test, but still fails spectral test.
61 // level 2 (p=97): passes all known tests, but theoretically still
62 // defective.
63 // level 3 (p=223): DEFAULT VALUE. Any theoretically possible
64 // correlations have very small chance of being observed.
65 // level 4 (p=389): highest possible luxury, all 24 bits chaotic.
66 
67  double flat();
68  // It returns a pseudo random number between 0 and 1,
69  // excluding the end points.
70 
71  void flatArray (const int size, double* vect);
72  // Fills the array "vect" of specified size with flat random values.
73 
74  void setSeed(long seed, int lux=3);
75  // Sets the state of the algorithm according to seed.
76 
77  void setSeeds(const long * seeds, int lux=3);
78  // Sets the state of the algorithm according to the zero terminated
79  // array of seeds. Only the first seed is used.
80 
81  void saveStatus( const char filename[] = "Ranlux.conf" ) const;
82  // Saves on file Ranlux.conf the current engine status.
83 
84  void restoreStatus( const char filename[] = "Ranlux.conf" );
85  // Reads from file Ranlux.conf the last saved engine status
86  // and restores it.
87 
88  void showStatus() const;
89  // Dumps the engine status on the screen.
90 
91  int getLuxury() const { return luxury; }
92  // Gets the luxury level.
93 
94  operator unsigned int(); // 32-bit flat, but slower than double or float
95 
96  virtual std::ostream & put (std::ostream & os) const;
97  virtual std::istream & get (std::istream & is);
98  static std::string beginTag ( );
99  virtual std::istream & getState ( std::istream & is );
100 
101  std::string name() const;
102  static std::string engineName() {return "RanluxEngine";}
103 
104  std::vector<unsigned long> put () const;
105  bool get (const std::vector<unsigned long> & v);
106  bool getState (const std::vector<unsigned long> & v);
107 
108  static const unsigned int VECTOR_STATE_SIZE = 31;
109 
110 private:
111 
112  int nskip, luxury;
113  float float_seed_table[24];
114  int i_lag,j_lag;
115  float carry;
116  int count24;
117  static const int int_modulus = 0x1000000;
118 };
119 
120 } // namespace CLHEP
121 
122 #endif
std::vector< unsigned long > put() const
static std::string engineName()
Definition: RanluxEngine.h:102
void setSeeds(const long *seeds, int lux=3)
long seed
Definition: chem4.cc:68
void saveStatus(const char filename[]="Ranlux.conf") const
int getLuxury() const
Definition: RanluxEngine.h:91
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void setSeed(long seed, int lux=3)
void restoreStatus(const char filename[]="Ranlux.conf")
tuple v
Definition: test.py:18
static constexpr double lux
virtual std::istream & getState(std::istream &is)
void showStatus() const
void flatArray(const int size, double *vect)
static std::string beginTag()
std::string name() const
Definition: RanluxEngine.cc:60
static const unsigned int VECTOR_STATE_SIZE
Definition: RanluxEngine.h:108