CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
RanshiEngine.h
Go to the documentation of this file.
1// $Id: RanshiEngine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
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
44#include "CLHEP/Random/defs.h"
45#include "CLHEP/Random/RandomEngine.h"
46
47namespace CLHEP {
48
49/**
50 * @author
51 * @ingroup random
52 */
54
55public:
56
58 RanshiEngine(std::istream &is);
59 RanshiEngine(long seed);
60 RanshiEngine(int rowIndex, int colIndex);
61 virtual ~RanshiEngine();
62 // Constructors and destructor
63
64 double flat();
65 // Returns a pseudo random number between 0 and 1
66
67 void flatArray(const int size, double* vect);
68 // Fills the array "vect" of specified size with flat random values
69
70 void setSeed(long seed, int);
71 // Sets the state of the algorithm according to seed.
72
73 void setSeeds(const long* seeds, int);
74 // Sets the state of the algorithm according to the zero-terminated
75 // array of seeds.
76
77 void saveStatus(const char filename[] = "RanshiEngine.conf") const;
78 // Saves on named file the current engine status
79
80 void restoreStatus(const char filename[] = "RanshiEngine.conf");
81 // Reads from named file 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 double(); // Returns same as flat()
88 operator float(); // flat value, without worrying about filling bits
89 operator unsigned int(); // 32-bit flat value, quickest of all
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 "RanshiEngine";}
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
103private:
104 enum {numBuff = 512};
105
106 unsigned int halfBuff, numFlats;
107 unsigned int buffer[numBuff];
108 unsigned int redSpin;
109
110 static const unsigned int VECTOR_STATE_SIZE = numBuff + 4;
111
112}; // RanshiEngine
113
114} // namespace CLHEP
115
116#ifdef ENABLE_BACKWARDS_COMPATIBILITY
117// backwards compatibility will be enabled ONLY in CLHEP 1.9
118using namespace CLHEP;
119#endif
120
121#endif // HepRanshiEngine_h
std::string name() const
Definition: RanshiEngine.cc:65
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:97
void restoreStatus(const char filename[]="RanshiEngine.conf")
void setSeeds(const long *seeds, int)
void setSeed(long seed, int)
void showStatus() const
#define double(obj)
Definition: excDblThrow.cc:32