Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
RanshiEngine.h
이 파일의 문서화 페이지로 가기
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 double(); // Returns same as flat()
87  operator float(); // flat value, without worrying about filling bits
88  operator unsigned int(); // 32-bit flat value, quickest of all
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 "RanshiEngine";}
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 private:
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
void setSeeds(const long *seeds, int)
static const unsigned int VECTOR_STATE_SIZE
Definition: RanshiEngine.h:109
static std::string engineName()
Definition: RanshiEngine.h:96
void showStatus() const
static std::string beginTag()
void saveStatus(const char filename[]="RanshiEngine.conf") const
unsigned int halfBuff
Definition: RanshiEngine.h:105
unsigned int numFlats
Definition: RanshiEngine.h:105
long seed
Definition: chem4.cc:68
void setSeed(long seed, int)
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
unsigned int redSpin
Definition: RanshiEngine.h:107
void flatArray(const int size, double *vect)
virtual std::istream & getState(std::istream &is)
std::vector< unsigned long > put() const
std::string name() const
Definition: RanshiEngine.cc:61
void restoreStatus(const char filename[]="RanshiEngine.conf")
unsigned int buffer[numBuff]
Definition: RanshiEngine.h:106