Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RanecuEngine.h
Go to the documentation of this file.
1 // $Id:$
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- RanecuEngine ---
7 // class header file
8 // -----------------------------------------------------------------------
9 // This file is part of Geant4 (simulation toolkit for HEP).
10 //
11 // RANECU Random Engine - algorithm originally written in FORTRAN77
12 // as part of the MATHLIB HEP library.
13 // The initialisation is carried out using a Multiplicative Congruential
14 // generator using formula constants of L'Ecuyer as described in "F.James,
15 // Comp. Phys. Comm. 60 (1990) 329-344".
16 // Seeds are taken from a seed table given an index, the getSeed() method
17 // returns the current index in the seed table, the getSeeds() method
18 // returns a pointer to the couple of seeds stored in the local table of
19 // seeds at the current index.
20 
21 // =======================================================================
22 // Gabriele Cosmo - Created: 2nd February 1996
23 // - Minor corrections: 31st October 1996
24 // - Added methods for engine status: 19th November 1996
25 // - setSeed() now has default dummy argument
26 // set to zero: 11th July 1997
27 // - Added default index to setSeeds(): 16th Oct 1997
28 // J.Marraffino - Added stream operators and related constructor.
29 // Added automatic seed selection from seed table and
30 // engine counter: 16th Feb 1998
31 // Ken Smith - Added conversion operators: 6th Aug 1998
32 // Mark Fischler Methods for distrib. instance save/restore 12/8/04
33 // Mark Fischler methods for anonymous save/restore 12/27/04
34 // =======================================================================
35 
36 #ifndef RanecuEngine_h
37 #define RanecuEngine_h 1
38 
40 
41 namespace CLHEP {
42 
47 class RanecuEngine : public HepRandomEngine {
48 
49 public:
50 
51  RanecuEngine(std::istream& is);
52  RanecuEngine();
53  RanecuEngine(int index);
54  virtual ~RanecuEngine();
55  // Constructors and destructor.
56 
57  double flat();
58  // Returns a pseudo random number between 0 and 1
59  // (excluding the end points)
60 
61  void flatArray (const int size, double* vect);
62  // Fills an array "vect" of specified size with flat random values.
63 
64  void setIndex (long index);
65  // Sets the state of the algorithm according to "index", the position
66  // in the local table of seeds.
67 
68  void setSeed (long index, int dum=0);
69  // Resets the state of the algorithm according to "index", the position
70  // in the static table of seeds stored in HepRandom.
71 
72  void setSeeds (const long* seeds, int index=-1);
73  // Sets the state of the algorithm according to the array of seeds
74  // "seeds" containing two seed values to be stored in the local table at
75  // "index" position.
76 
77  void saveStatus( const char filename[] = "Ranecu.conf" ) const;
78  // Saves on file Ranecu.conf the current engine status.
79 
80  void restoreStatus( const char filename[] = "Ranecu.conf" );
81  // Reads from file Ranecu.conf the last saved engine status
82  // and restores it.
83 
84  void showStatus() const;
85  // Dumps the engine status on the screen.
86 
87  operator unsigned int();
88  // 32-bit int flat, faster in this case
89 
90  virtual std::ostream & put (std::ostream & os) const;
91  virtual std::istream & get (std::istream & is);
92  static std::string beginTag ( );
93  virtual std::istream & getState ( std::istream & is );
94 
95  std::string name() const;
96  static std::string engineName() {return "RanecuEngine";}
97 
98  std::vector<unsigned long> put () const;
99  bool get (const std::vector<unsigned long> & v);
100  bool getState (const std::vector<unsigned long> & v);
101 
102 protected:
103 
104  // Suggested L'ecuyer coefficients for portable 32 bits generators.
105 
106  static const int ecuyer_a = 40014;
107  static const int ecuyer_b = 53668;
108  static const int ecuyer_c = 12211;
109  static const int ecuyer_d = 40692;
110  static const int ecuyer_e = 52774;
111  static const int ecuyer_f = 3791;
112  static const int shift1 = 2147483563;
113  static const int shift2 = 2147483399;
114 
115  static const unsigned int VECTOR_STATE_SIZE = 4;
116 
117 private:
118 
119  // private method used to mitigate the effects of using a lookup table
120  void further_randomize (int seq, int col, int index, int modulus);
121 
122  // Members defining the current state of the generator.
123 
124  static const int maxSeq = 215;
125  long table[215][2];
126  int seq;
127 
128 };
129 
130 } // namespace CLHEP
131 
132 #endif
void setSeeds(const long *seeds, int index=-1)
static const int shift1
Definition: RanecuEngine.h:112
static const int ecuyer_b
Definition: RanecuEngine.h:107
static const int ecuyer_f
Definition: RanecuEngine.h:111
static std::string engineName()
Definition: RanecuEngine.h:96
static const unsigned int VECTOR_STATE_SIZE
Definition: RanecuEngine.h:115
void restoreStatus(const char filename[]="Ranecu.conf")
std::string name() const
Definition: RanecuEngine.cc:60
virtual std::istream & getState(std::istream &is)
void setIndex(long index)
static const int ecuyer_a
Definition: RanecuEngine.h:106
void flatArray(const int size, double *vect)
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const int shift2
Definition: RanecuEngine.h:113
static const int ecuyer_e
Definition: RanecuEngine.h:110
void saveStatus(const char filename[]="Ranecu.conf") const
static const int ecuyer_d
Definition: RanecuEngine.h:109
static std::string beginTag()
void showStatus() const
void setSeed(long index, int dum=0)
static const int ecuyer_c
Definition: RanecuEngine.h:108
std::vector< unsigned long > put() const