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