Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RanshiEngine.h
Go to the documentation of this file.
1 // $Id:$
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- RanshiEngine ---
7 // class header file
8 // -----------------------------------------------------------------------
9 //
10 //
11 // The algorithm for this random engine was taken from "F.Gutbrod, Comp.
12 // Phys. Comm. 87 (1995) 291-306".
13 //
14 // The algorithm can be imagined as a physical system as follows: Imagine
15 // 512 "black balls" each with their own unique spin, and positions char-
16 // acterized by disrete angles, where the spin is a 32-bit unsigned integer.
17 // A "red ball" collides based upon the angle determined by the last 8 bits
18 // of its spin, and the spin of the colliding ball is taken as the output
19 // random number. The spin of the colliding ball is replaced then with the
20 // left circular shift of the black ball's spin XOR'd with the red ball's
21 // spin. The black ball's old spin becomes the red ball's.
22 //
23 // To avoid the traps presented, two measures are taken: first, the red
24 // ball will oscillate between hitting the lower half of the buffer on one
25 // turn and the upper half on another; second, the red ball's spin is
26 // incremented by a counter of the number of random numbers produced.
27 //
28 // The result is scaled to a double precision floating point number to which
29 // is added another random double further scaled 2^(53-32) places to the
30 // right in order to ensure that the remaining bits of the result are not
31 // left empty due to the mere 32 bits representation used internally.
32 
33 // =======================================================================
34 // Ken Smith - Created: 9th June 1998
35 // - Removed pow() from flat method: 21st Jul 1998
36 // - Added conversion operators: 6th Aug 1998
37 // Mark Fischler Methods put, get for instance save/restore 12/8/04
38 // Mark Fischler methods for anonymous save/restore 12/27/04
39 // =======================================================================
40 
41 #ifndef HepRanshiEngine_h
42 #define HepRanshiEngine_h
43 
45 
46 namespace CLHEP {
47 
53 
54 public:
55 
56  RanshiEngine();
57  RanshiEngine(std::istream &is);
58  RanshiEngine(long seed);
59  RanshiEngine(int rowIndex, int colIndex);
60  virtual ~RanshiEngine();
61  // Constructors and destructor
62 
63  double flat();
64  // Returns a pseudo random number between 0 and 1
65 
66  void flatArray(const int size, double* vect);
67  // Fills the array "vect" of specified size with flat random values
68 
69  void setSeed(long seed, int);
70  // Sets the state of the algorithm according to seed.
71 
72  void setSeeds(const long* seeds, int);
73  // Sets the state of the algorithm according to the zero-terminated
74  // array of seeds.
75 
76  void saveStatus(const char filename[] = "RanshiEngine.conf") const;
77  // Saves on named file the current engine status
78 
79  void restoreStatus(const char filename[] = "RanshiEngine.conf");
80  // Reads from named file the last saved engine status
81  // and restores it.
82 
83  void showStatus() const;
84  // Dumps the engine status on the screen
85 
86  operator float(); // flat value, without worrying about filling bits
87  operator unsigned int(); // 32-bit flat value, quickest of all
88 
89  virtual std::ostream & put (std::ostream & os) const;
90  virtual std::istream & get (std::istream & is);
91  static std::string beginTag ( );
92  virtual std::istream & getState ( std::istream & is );
93 
94  std::string name() const;
95  static std::string engineName() {return "RanshiEngine";}
96 
97  std::vector<unsigned long> put () const;
98  bool get (const std::vector<unsigned long> & v);
99  bool getState (const std::vector<unsigned long> & v);
100 
101 private:
102  enum {numBuff = 512};
103 
104  unsigned int halfBuff, numFlats;
105  unsigned int buffer[numBuff];
106  unsigned int redSpin;
107 
108  static const unsigned int VECTOR_STATE_SIZE = numBuff + 4;
109 
110 }; // RanshiEngine
111 
112 } // namespace CLHEP
113 
114 #endif // HepRanshiEngine_h
void restoreStatus(const char filename[]="RanshiEngine.conf")
void setSeeds(const long *seeds, int)
void setSeed(long seed, int)
void flatArray(const int size, double *vect)
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void saveStatus(const char filename[]="RanshiEngine.conf") const
virtual std::istream & getState(std::istream &is)
std::string name() const
Definition: RanshiEngine.cc:61
void showStatus() const
std::vector< unsigned long > put() const
static std::string engineName()
Definition: RanshiEngine.h:95
static std::string beginTag()