Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Ranlux64Engine.h
Go to the documentation of this file.
1 // $Id:$
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- Ranlux64Engine ---
7 // class header file
8 // -----------------------------------------------------------------------
9 // The algorithm for this random engine has been taken from the notes of
10 // a double-precision ranlux implementation by Martin Luscher, dated
11 // November 1997.
12 //
13 // Like the previous ranlux generator, this one also has "luxury" levels,
14 // determining how many pseudo-random numbers are discarded for every
15 // twelve values used. Three levels are given, with the note that Luscher
16 // himself advocates only the highest two levels for this engine.
17 // level 0 (p=109): Throw away 109 values for every 12 used
18 // level 1 (p=202): (default) Throw away 202 values for every 12 used
19 // level 2 (p=397): Throw away 397 values for every 12 used
20 //
21 // The initialization is carried out using a Multiplicative Congruential
22 // generator using formula constants of L'Ecuyer as described in "F.James,
23 // Comp. Phys. Comm. 60 (1990) 329-344".
24 // =======================================================================
25 // Ken Smith - Created Initial draft: 14th Jul 1998
26 // - Added conversion operators: 6th Aug 1998
27 // Mark Fischler
28 // 9/9/98 - Added update() routine to allow computation of many at once
29 // - Replaced algorithm with jone exactly matching Luscher:
30 // 48-bits generated
31 // skip n-12 instead of n numbers
32 // - Corrected protection agains overflow
33 // 12/8/04 - Methods for instance save/restore
34 // 12/27/04 - methods for anonymous save/restore 12/27/04
35 //
36 // =======================================================================
37 
38 #ifndef Ranlux64Engine_h
39 #define Ranlux64Engine_h
40 
42 
43 namespace CLHEP {
44 
50 
51 public:
52 
53  Ranlux64Engine( std::istream& is );
55  Ranlux64Engine( long seed, int lux = 1 );
56  Ranlux64Engine( int rowIndex, int colIndex, int lux );
57  virtual ~Ranlux64Engine();
58  // Constructors and destructor
59 
60  double flat();
61  // It returns a pseudo random number between 0 and 1,
62  // excluding the end points.
63 
64  void flatArray (const int size, double* vect);
65  // Fills the array "vect" of specified size with flat random values.
66 
67  void setSeed(long seed, int lux=1);
68  // Sets the state of the algorithm according to seed.
69 
70  void setSeeds(const long * seeds, int lux=1);
71  // Sets the state of the algorithm according to the zero terminated
72  // array of seeds. Only the first seed is used.
73 
74  void saveStatus( const char filename[] = "Ranlux64.conf" ) const;
75  // Saves in named file the current engine status.
76 
77  void restoreStatus( const char filename[] = "Ranlux64.conf" );
78  // Reads from named file the last saved engine status and restores it.
79 
80  void showStatus() const;
81  // Dumps the engine status on the screen.
82 
83  int getLuxury() const { return luxury; }
84  // Gets the luxury level.
85 
86  virtual std::ostream & put (std::ostream & os) const;
87  virtual std::istream & get (std::istream & is);
88  static std::string beginTag ( );
89  virtual std::istream & getState ( std::istream & is );
90 
91  std::string name() const;
92  static std::string engineName() {return "Ranlux64Engine";}
93 
94  std::vector<unsigned long> put () const;
95  bool get (const std::vector<unsigned long> & v);
96  bool getState (const std::vector<unsigned long> & v);
97 
98  static const unsigned int VECTOR_STATE_SIZE = 30;
99 
100 private:
101 
102  void update();
103  void advance(int dozens);
104 
105  int pDiscard; // separate sequence by p-r = p-12 discarded elements
106  int pDozens; // pDiscard / 12;
107  int endIters; // pDiscard % 12;
108  int luxury;
109 
110  int index;
111  double randoms[12]; // randoms [i] is the x[n-i] of Luscher's note
112  double carry;
113 
114 }; // Ranlux64Engine
115 
116 } // namespace CLHEP
117 
118 #endif // Ranlux64Engine_h
std::string name() const
int getLuxury() const
static std::string engineName()
std::vector< unsigned long > put() const
void setSeeds(const long *seeds, int lux=1)
static const unsigned int VECTOR_STATE_SIZE
void setSeed(long seed, int lux=1)
void restoreStatus(const char filename[]="Ranlux64.conf")
static constexpr double lux
static std::string beginTag()
virtual std::istream & getState(std::istream &is)
void showStatus() const
void flatArray(const int size, double *vect)
void saveStatus(const char filename[]="Ranlux64.conf") const