CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
TripleRand.h
Go to the documentation of this file.
1// $Id: TripleRand.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2// -*- C++ -*-
3//
4// -----------------------------------------------------------------------
5// Hep Random
6// --- TripleRand ---
7// class header file
8// -----------------------------------------------------------------------
9// A canopy pseudo-random number generator. Using the Tausworthe
10// exclusive-or shift register, a simple Integer Coungruence generator, and
11// the Hurd 288 total bit shift register, all XOR'd with each other, we
12// provide an engine that should be a fairly good "mother" generator.
13//
14// This is similar to DualRand, with the addition of the Hurd288Engine.
15// From DualRand, we have the following:
16// Exclusive or of a feedback shift register and integer congruence
17// random number generator. The feedback shift register uses offsets
18// 127 and 97. The integer congruence generator uses a different
19// multiplier for each stream. The multipliers are chosen to give
20// full period and maximum "potency" for modulo 2^32. The period of
21// the combined random number generator is 2^159 - 2^32, and the
22// sequences are different for each stream (not just started in a
23// different place).
24// The above is then amended to also add in the exclusive or of the
25// 288-total bit Hurd engine which in this case is a series of 32
26// interconnected 9-bit shift registers, with the newest bit of each register
27// formed by the XOR of the previous bit and some bit b-d from a previous
28// register where d is chosen to create a primitive polynomial to maximize
29// the period.
30// =======================================================================
31// Ken Smith - Initial draft started: 23rd Jul 1998
32// - Added conversion operators: 6th Aug 1998
33// M Fischler - Big merge with CLHEP 13 May 1999
34// - Elimination of unused Taus() and Cong() accessors
35// Mark Fischler Methods put, get for instance save/restore 12/8/04
36// Mark Fischler methods for anonymous save/restore 12/27/04
37// =======================================================================
38
39#ifndef TripleRand_h
40#define TripleRand_h
41
42#include "CLHEP/Random/defs.h"
43#include "CLHEP/Random/RandomEngine.h"
44#include "CLHEP/Random/Hurd288Engine.h"
45
46namespace CLHEP {
47
48/**
49 * @author
50 * @ingroup random
51 */
53
54public:
55
56 TripleRand();
57 TripleRand( long seed );
58 TripleRand( std::istream & is );
59 TripleRand( int rowIndex, int colIndex );
60 virtual ~TripleRand();
61 // Constructors and destructor
62
63 double flat();
64 // Returns a pseudo random number between 0 and 1
65 // (excluding the end points)
66
67 void flatArray( const int size, double * vect );
68 // Fills an 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[] = "TripleRand.conf" ) const;
78 // Saves on named file the current engine status.
79
80 void restoreStatus( const char filename[] = "TripleRand.conf" );
81 // Reads from named file the last saved engine status and restores it.
82
83 void showStatus() const;
84 // Dumps the current 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 "TripleRand";}
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 static const unsigned int VECTOR_STATE_SIZE = 20;
103
104private:
105
106/**
107 * @author
108 * @ingroup random
109 */
110class Tausworthe {
111public:
112
113 Tausworthe();
114 Tausworthe(unsigned int seed);
115
116 operator unsigned int();
117
118 void put( std::ostream & os ) const;
119 void put(std::vector<unsigned long> & v) const;
120 void get( std::istream & is );
121 bool get(std::vector<unsigned long>::const_iterator & iv);
122
123private:
124
125 int wordIndex;
126 unsigned int words[4];
127}; // Tausworthe
128
129/**
130 * @author
131 * @ingroup random
132 */
133class IntegerCong {
134public:
135
136 IntegerCong();
137 IntegerCong(unsigned int seed, int streamNumber);
138
139 operator unsigned int();
140
141 void put( std::ostream & os ) const;
142 void put(std::vector<unsigned long> & v) const;
143 void get( std::istream & is );
144 bool get(std::vector<unsigned long>::const_iterator & iv);
145
146private:
147
148 unsigned int state, multiplier, addend;
149}; // IntegerCong
150
151 Hurd288Engine & Hurd(); // retrieve the constituent engine for input
152
153 const Tausworthe & ConstTaus() const; // Same as above
154 const IntegerCong & ConstCong() const; // necessary for
155 const Hurd288Engine & ConstHurd() const; // output
156
157 int numEngines;
158 Tausworthe tausworthe; // Instances of each of the
159 IntegerCong integerCong; // three engines that combine to make
160 Hurd288Engine hurd; // one TripleRand instance
161
162}; // TripleRand
163
164} // namespace CLHEP
165
166#ifdef ENABLE_BACKWARDS_COMPATIBILITY
167// backwards compatibility will be enabled ONLY in CLHEP 1.9
168using namespace CLHEP;
169#endif
170
171#endif // TripleRand_h
virtual std::istream & get(std::istream &is)
Definition: TripleRand.cc:264
static const unsigned int VECTOR_STATE_SIZE
Definition: TripleRand.h:102
virtual std::istream & getState(std::istream &is)
Definition: TripleRand.cc:285
std::vector< unsigned long > put() const
Definition: TripleRand.cc:252
void flatArray(const int size, double *vect)
Definition: TripleRand.cc:115
virtual ~TripleRand()
Definition: TripleRand.cc:103
std::string name() const
Definition: TripleRand.cc:64
void saveStatus(const char filename[]="TripleRand.conf") const
Definition: TripleRand.cc:133
void setSeed(long seed, int)
Definition: TripleRand.cc:121
void showStatus() const
Definition: TripleRand.cc:196
void restoreStatus(const char filename[]="TripleRand.conf")
Definition: TripleRand.cc:160
void setSeeds(const long *seeds, int)
Definition: TripleRand.cc:128
static std::string engineName()
Definition: TripleRand.h:96
static std::string beginTag()
Definition: TripleRand.cc:281
#define double(obj)
Definition: excDblThrow.cc:32