Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
RanluxEngine.h
이 파일의 문서화 페이지로 가기
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 double(); // Returns same as flat()
95  operator float(); // less precise flat, faster if possible
96  operator unsigned int(); // 32-bit flat, but slower than double or float
97 
98  virtual std::ostream & put (std::ostream & os) const;
99  virtual std::istream & get (std::istream & is);
100  static std::string beginTag ( );
101  virtual std::istream & getState ( std::istream & is );
102 
103  std::string name() const;
104  static std::string engineName() {return "RanluxEngine";}
105 
106  std::vector<unsigned long> put () const;
107  bool get (const std::vector<unsigned long> & v);
108  bool getState (const std::vector<unsigned long> & v);
109 
110  static const unsigned int VECTOR_STATE_SIZE = 31;
111 
112 private:
113 
114  int nskip, luxury;
115  float float_seed_table[24];
116  int i_lag,j_lag;
117  float carry;
118  int count24;
119  static const int int_modulus = 0x1000000;
120 };
121 
122 } // namespace CLHEP
123 
124 #endif
static std::string engineName()
Definition: RanluxEngine.h:104
void setSeed(long seed, int lux=3)
static const unsigned int VECTOR_STATE_SIZE
Definition: RanluxEngine.h:110
void showStatus() const
virtual std::istream & getState(std::istream &is)
void flatArray(const int size, double *vect)
float float_seed_table[24]
Definition: RanluxEngine.h:115
long seed
Definition: chem4.cc:68
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const int int_modulus
Definition: RanluxEngine.h:119
void setSeeds(const long *seeds, int lux=3)
std::string name() const
Definition: RanluxEngine.cc:60
static constexpr double lux
int getLuxury() const
Definition: RanluxEngine.h:91
std::vector< unsigned long > put() const
void saveStatus(const char filename[]="Ranlux.conf") const
static std::string beginTag()
void restoreStatus(const char filename[]="Ranlux.conf")