CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Random/Random/RanecuEngine.h
Go to the documentation of this file.
1 // $Id: RanecuEngine.h,v 1.6 2010/07/20 18:06:02 garren Exp $
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 
39 #include "CLHEP/Random/defs.h"
40 #include "CLHEP/Random/RandomEngine.h"
41 
42 namespace CLHEP {
43 
48 class RanecuEngine : public HepRandomEngine {
49 
50 public:
51 
52  RanecuEngine(std::istream& is);
54  RanecuEngine(int index);
55  virtual ~RanecuEngine();
56  // Constructors and destructor.
57 
58  double flat();
59  // Returns a pseudo random number between 0 and 1
60  // (excluding the end points)
61 
62  void flatArray (const int size, double* vect);
63  // Fills an array "vect" of specified size with flat random values.
64 
65  void setIndex (long index);
66  // Sets the state of the algorithm according to "index", the position
67  // in the local table of seeds.
68 
69  void setSeed (long index, int dum=0);
70  // Resets the state of the algorithm according to "index", the position
71  // in the static table of seeds stored in HepRandom.
72 
73  void setSeeds (const long* seeds, int index=-1);
74  // Sets the state of the algorithm according to the array of seeds
75  // "seeds" containing two seed values to be stored in the local table at
76  // "index" position.
77 
78  void saveStatus( const char filename[] = "Ranecu.conf" ) const;
79  // Saves on file Ranecu.conf the current engine status.
80 
81  void restoreStatus( const char filename[] = "Ranecu.conf" );
82  // Reads from file Ranecu.conf the last saved engine status
83  // and restores it.
84 
85  void showStatus() const;
86  // Dumps the engine status on the screen.
87 
88  operator unsigned int();
89  // 32-bit int flat, faster in this case
90 
91  virtual std::ostream & put (std::ostream & os) const;
92  virtual std::istream & get (std::istream & is);
93  static std::string beginTag ( );
94  virtual std::istream & getState ( std::istream & is );
95 
96  std::string name() const;
97  static std::string engineName() {return "RanecuEngine";}
98 
99  std::vector<unsigned long> put () const;
100  bool get (const std::vector<unsigned long> & v);
101  bool getState (const std::vector<unsigned long> & v);
102 
103 protected:
104 
105  // Suggested L'ecuyer coefficients for portable 32 bits generators.
106 
107  static const int ecuyer_a = 40014;
108  static const int ecuyer_b = 53668;
109  static const int ecuyer_c = 12211;
110  static const int ecuyer_d = 40692;
111  static const int ecuyer_e = 52774;
112  static const int ecuyer_f = 3791;
113  static const int shift1 = 2147483563;
114  static const int shift2 = 2147483399;
115 
116  static const unsigned int VECTOR_STATE_SIZE = 4;
117 
118 private:
119 
120  // private method used to mitigate the effects of using a lookup table
121  void further_randomize (int seq, int col, int index, int modulus);
122 
123  // Members defining the current state of the generator.
124 
125  static const int maxSeq = 215;
126  long table[215][2];
127  int seq;
128  static int numEngines;
129 
130 };
131 
132 } // namespace CLHEP
133 
134 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
135 // backwards compatibility will be enabled ONLY in CLHEP 1.9
136 using namespace CLHEP;
137 #endif
138 
139 #endif
void restoreStatus(const char filename[]="Ranecu.conf")
virtual std::istream & getState(std::istream &is)
void saveStatus(const char filename[]="Ranecu.conf") const
virtual std::istream & get(std::istream &is)
static std::string engineName()
void showStatus() const
void setSeed(long index, int dum=0)
std::string name() const
virtual std::ostream & put(std::ostream &os) const
void flatArray(const int size, double *vect)
void setIndex(long index)
RanecuEngine(int index)
bool getState(const std::vector< unsigned long > &v)
RanecuEngine(std::istream &is)
std::vector< unsigned long > put() const
void setSeeds(const long *seeds, int index=-1)
bool get(const std::vector< unsigned long > &v)
static std::string beginTag()
static const unsigned int VECTOR_STATE_SIZE
virtual ~RanecuEngine()