Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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
46namespace CLHEP {
47
48/**
49 * @author
50 * @ingroup random
51 */
53
54public:
55
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
101private:
102 static int numEngines;
103 enum {numBuff = 512};
104
105 unsigned int halfBuff, numFlats;
106 unsigned int buffer[numBuff];
107 unsigned int redSpin;
108
109 static const unsigned int VECTOR_STATE_SIZE = numBuff + 4;
110
111}; // RanshiEngine
112
113} // namespace CLHEP
114
115#endif // HepRanshiEngine_h
virtual ~RanshiEngine()
Definition: RanshiEngine.cc:99
std::string name() const
Definition: RanshiEngine.cc:43
virtual std::istream & getState(std::istream &is)
static std::string beginTag()
void flatArray(const int size, double *vect)
virtual std::istream & get(std::istream &is)
void saveStatus(const char filename[]="RanshiEngine.conf") const
std::vector< unsigned long > put() const
static std::string engineName()
Definition: RanshiEngine.h:95
void restoreStatus(const char filename[]="RanshiEngine.conf")
void setSeeds(const long *seeds, int)
void setSeed(long seed, int)
void showStatus() const
Definition: DoubConv.h:17