Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
CLHEP::DualRand Class Reference

#include <DualRand.h>

+ Inheritance diagram for CLHEP::DualRand:

Public Member Functions

 DualRand ()
 
 DualRand (long seed)
 
 DualRand (std::istream &is)
 
 DualRand (int rowIndex, int colIndex)
 
virtual ~DualRand ()
 
double flat ()
 
void flatArray (const int size, double *vect)
 
void setSeed (long seed, int)
 
void setSeeds (const long *seeds, int)
 
void saveStatus (const char filename[]="DualRand.conf") const
 
void restoreStatus (const char filename[]="DualRand.conf")
 
void showStatus () const
 
 operator float ()
 
 operator unsigned int ()
 
virtual std::ostream & put (std::ostream &os) const
 
virtual std::istream & get (std::istream &is)
 
virtual std::istream & getState (std::istream &is)
 
std::string name () const
 
std::vector< unsigned long > put () const
 
bool get (const std::vector< unsigned long > &v)
 
bool getState (const std::vector< unsigned long > &v)
 
- Public Member Functions inherited from CLHEP::HepRandomEngine
 HepRandomEngine ()
 
virtual ~HepRandomEngine ()
 
bool operator== (const HepRandomEngine &engine)
 
bool operator!= (const HepRandomEngine &engine)
 
virtual double flat ()=0
 
virtual void flatArray (const int size, double *vect)=0
 
virtual void setSeed (long seed, int)=0
 
virtual void setSeeds (const long *seeds, int)=0
 
virtual void saveStatus (const char filename[]="Config.conf") const =0
 
virtual void restoreStatus (const char filename[]="Config.conf")=0
 
virtual void showStatus () const =0
 
virtual std::string name () const =0
 
virtual std::ostream & put (std::ostream &os) const
 
virtual std::istream & get (std::istream &is)
 
virtual std::istream & getState (std::istream &is)
 
virtual std::vector< unsigned long > put () const
 
virtual bool get (const std::vector< unsigned long > &v)
 
virtual bool getState (const std::vector< unsigned long > &v)
 
long getSeed () const
 
const long * getSeeds () const
 
virtual operator double ()
 
virtual operator float ()
 
virtual operator unsigned int ()
 

Static Public Member Functions

static std::string beginTag ()
 
static std::string engineName ()
 
- Static Public Member Functions inherited from CLHEP::HepRandomEngine
static std::string beginTag ()
 
static HepRandomEnginenewEngine (std::istream &is)
 
static HepRandomEnginenewEngine (const std::vector< unsigned long > &v)
 

Static Public Attributes

static const unsigned int VECTOR_STATE_SIZE = 9
 

Additional Inherited Members

- Static Protected Member Functions inherited from CLHEP::HepRandomEngine
static double exponent_bit_32 ()
 
static double mantissa_bit_12 ()
 
static double mantissa_bit_24 ()
 
static double mantissa_bit_32 ()
 
static double twoToMinus_32 ()
 
static double twoToMinus_48 ()
 
static double twoToMinus_49 ()
 
static double twoToMinus_53 ()
 
static double nearlyTwoToMinus_54 ()
 
static bool checkFile (std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
 
- Protected Attributes inherited from CLHEP::HepRandomEngine
long theSeed
 
const long * theSeeds
 

Detailed Description

Author

Definition at line 50 of file DualRand.h.

Constructor & Destructor Documentation

◆ DualRand() [1/4]

CLHEP::DualRand::DualRand ( )

Definition at line 73 of file DualRand.cc.

75 tausworthe (1234567 + numEngines + 175321),
76 integerCong(69607 * tausworthe + 54329, numEngines)
77{
78 theSeed = 1234567;
79 ++numEngines;
80}

◆ DualRand() [2/4]

CLHEP::DualRand::DualRand ( long  seed)

Definition at line 82 of file DualRand.cc.

84 tausworthe ((unsigned int)seed + 175321),
85 integerCong(69607 * tausworthe + 54329, 8043) // MF - not numEngines
86{
87 theSeed = seed;
88}

◆ DualRand() [3/4]

CLHEP::DualRand::DualRand ( std::istream &  is)

Definition at line 90 of file DualRand.cc.

92{
93 is >> *this;
94}

◆ DualRand() [4/4]

CLHEP::DualRand::DualRand ( int  rowIndex,
int  colIndex 
)

Definition at line 96 of file DualRand.cc.

98 tausworthe (rowIndex + 1000 * colIndex + 85329),
99 integerCong(69607 * tausworthe + 54329, 1123) // MF - not numengines
100{
101 theSeed = rowIndex;
102}

◆ ~DualRand()

CLHEP::DualRand::~DualRand ( )
virtual

Definition at line 104 of file DualRand.cc.

104{ }

Member Function Documentation

◆ beginTag()

std::string CLHEP::DualRand::beginTag ( )
static

Definition at line 234 of file DualRand.cc.

234 {
235 return "DualRand-begin";
236}

◆ engineName()

static std::string CLHEP::DualRand::engineName ( )
inlinestatic

Definition at line 96 of file DualRand.h.

96{return "DualRand";}

Referenced by restoreStatus().

◆ flat()

double CLHEP::DualRand::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 106 of file DualRand.cc.

106 {
107 unsigned int ic ( integerCong );
108 unsigned int t ( tausworthe );
109 return ( (t ^ ic) * twoToMinus_32() + // most significant part
110 (t >> 11) * twoToMinus_53() + // fill in remaining bits
111 nearlyTwoToMinus_54() // make sure non-zero
112 );
113}
static double twoToMinus_32()
static double twoToMinus_53()
static double nearlyTwoToMinus_54()

Referenced by flatArray().

◆ flatArray()

void CLHEP::DualRand::flatArray ( const int  size,
double *  vect 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 115 of file DualRand.cc.

115 {
116 for (int i = 0; i < size; ++i) {
117 vect[i] = flat();
118 }
119}
double flat()
Definition: DualRand.cc:106

◆ get() [1/2]

bool CLHEP::DualRand::get ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 274 of file DualRand.cc.

274 {
275 if ((v[0] & 0xffffffffUL) != engineIDulong<DualRand>()) {
276 std::cerr <<
277 "\nDualRand get:state vector has wrong ID word - state unchanged\n";
278 return false;
279 }
280 if (v.size() != VECTOR_STATE_SIZE) {
281 std::cerr << "\nDualRand get:state vector has wrong size: "
282 << v.size() << " - state unchanged\n";
283 return false;
284 }
285 return getState(v);
286}
static const unsigned int VECTOR_STATE_SIZE
Definition: DualRand.h:102
virtual std::istream & getState(std::istream &is)
Definition: DualRand.cc:238

◆ get() [2/2]

std::istream & CLHEP::DualRand::get ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 217 of file DualRand.cc.

217 {
218 char beginMarker [MarkerLen];
219 is >> std::ws;
220 is.width(MarkerLen); // causes the next read to the char* to be <=
221 // that many bytes, INCLUDING A TERMINATION \0
222 // (Stroustrup, section 21.3.2)
223 is >> beginMarker;
224 if (strcmp(beginMarker,"DualRand-begin")) {
225 is.clear(std::ios::badbit | is.rdstate());
226 std::cerr << "\nInput mispositioned or"
227 << "\nDualRand state description missing or"
228 << "\nwrong engine type found." << std::endl;
229 return is;
230 }
231 return getState(is);
232}

◆ getState() [1/2]

bool CLHEP::DualRand::getState ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 288 of file DualRand.cc.

288 {
289 std::vector<unsigned long>::const_iterator iv = v.begin()+1;
290 if (!tausworthe.get(iv)) return false;
291 if (!integerCong.get(iv)) return false;
292 if (iv != v.end()) {
293 std::cerr <<
294 "\nDualRand get:state vector has wrong size: " << v.size()
295 << "\n Apparently " << iv-v.begin() << " words were consumed\n";
296 return false;
297 }
298 return true;
299}

◆ getState() [2/2]

std::istream & CLHEP::DualRand::getState ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 238 of file DualRand.cc.

238 {
239 if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
240 std::vector<unsigned long> v;
241 unsigned long uu;
242 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
243 is >> uu;
244 if (!is) {
245 is.clear(std::ios::badbit | is.rdstate());
246 std::cerr << "\nDualRand state (vector) description improper."
247 << "\ngetState() has failed."
248 << "\nInput stream is probably mispositioned now." << std::endl;
249 return is;
250 }
251 v.push_back(uu);
252 }
253 getState(v);
254 return (is);
255 }
256
257// is >> theSeed; Removed, encompassed by possibleKeywordInput()
258
259 char endMarker [MarkerLen];
260 tausworthe.get(is);
261 integerCong.get(is);
262 is >> std::ws;
263 is.width(MarkerLen);
264 is >> endMarker;
265 if (strcmp(endMarker,"DualRand-end")) {
266 is.clear(std::ios::badbit | is.rdstate());
267 std::cerr << "DualRand state description incomplete."
268 << "\nInput stream is probably mispositioned now." << std::endl;
269 return is;
270 }
271 return is;
272}
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167

Referenced by get(), getState(), and restoreStatus().

◆ name()

std::string CLHEP::DualRand::name ( ) const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 62 of file DualRand.cc.

62{return "DualRand";}

◆ operator float()

CLHEP::DualRand::operator float ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 189 of file DualRand.cc.

189 {
190 return (float) ( (integerCong ^ tausworthe) * twoToMinus_32()
191 + nearlyTwoToMinus_54() );
192 // add this so that zero never happens
193}

◆ operator unsigned int()

CLHEP::DualRand::operator unsigned int ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 195 of file DualRand.cc.

195 {
196 return (integerCong ^ tausworthe) & 0xffffffff;
197}

◆ put() [1/2]

std::vector< unsigned long > CLHEP::DualRand::put ( ) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 209 of file DualRand.cc.

209 {
210 std::vector<unsigned long> v;
211 v.push_back (engineIDulong<DualRand>());
212 tausworthe.put(v);
213 integerCong.put(v);
214 return v;
215}

Referenced by put(), and saveStatus().

◆ put() [2/2]

std::ostream & CLHEP::DualRand::put ( std::ostream &  os) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 199 of file DualRand.cc.

199 {
200 char beginMarker[] = "DualRand-begin";
201 os << beginMarker << "\nUvec\n";
202 std::vector<unsigned long> v = put();
203 for (unsigned int i=0; i<v.size(); ++i) {
204 os << v[i] << "\n";
205 }
206 return os;
207}
std::vector< unsigned long > put() const
Definition: DualRand.cc:209

◆ restoreStatus()

void CLHEP::DualRand::restoreStatus ( const char  filename[] = "DualRand.conf")
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 143 of file DualRand.cc.

143 {
144 std::ifstream inFile(filename, std::ios::in);
145 if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
146 std::cerr << " -- Engine state remains unchanged\n";
147 return;
148 }
149 if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
150 std::vector<unsigned long> v;
151 unsigned long xin;
152 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
153 inFile >> xin;
154 if (!inFile) {
155 inFile.clear(std::ios::badbit | inFile.rdstate());
156 std::cerr << "\nDualRand state (vector) description improper."
157 << "\nrestoreStatus has failed."
158 << "\nInput stream is probably mispositioned now." << std::endl;
159 return;
160 }
161 v.push_back(xin);
162 }
163 getState(v);
164 return;
165 }
166
167 if (!inFile.bad()) {
168// inFile >> theSeed; removed -- encompased by possibleKeywordInput
169 tausworthe.get(inFile);
170 integerCong.get(inFile);
171 }
172}
static std::string engineName()
Definition: DualRand.h:96
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
Definition: RandomEngine.cc:45

◆ saveStatus()

void CLHEP::DualRand::saveStatus ( const char  filename[] = "DualRand.conf") const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 132 of file DualRand.cc.

132 {
133 std::ofstream outFile(filename, std::ios::out);
134 if (!outFile.bad()) {
135 outFile << "Uvec\n";
136 std::vector<unsigned long> v = put();
137 for (unsigned int i=0; i<v.size(); ++i) {
138 outFile << v[i] << "\n";
139 }
140 }
141}

◆ setSeed()

void CLHEP::DualRand::setSeed ( long  seed,
int   
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 121 of file DualRand.cc.

121 {
122 theSeed = seed;
123 tausworthe = Tausworthe((unsigned int)seed + numEngines + 175321);
124 integerCong = IntegerCong(69607 * tausworthe + 54329, numEngines);
125}

Referenced by setSeeds().

◆ setSeeds()

void CLHEP::DualRand::setSeeds ( const long *  seeds,
int   
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 127 of file DualRand.cc.

127 {
128 setSeed(seeds ? *seeds : 1234567, 0);
129 theSeeds = seeds;
130}
void setSeed(long seed, int)
Definition: DualRand.cc:121

◆ showStatus()

void CLHEP::DualRand::showStatus ( ) const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 174 of file DualRand.cc.

174 {
175 int pr=std::cout.precision(20);
176 std::cout << std::endl;
177 std::cout << "-------- DualRand engine status ---------"
178 << std::endl;
179 std::cout << "Initial seed = " << theSeed << std::endl;
180 std::cout << "Tausworthe generator = " << std::endl;
181 tausworthe.put(std::cout);
182 std::cout << "\nIntegerCong generator = " << std::endl;
183 integerCong.put(std::cout);
184 std::cout << std::endl << "-----------------------------------------"
185 << std::endl;
186 std::cout.precision(pr);
187}

Member Data Documentation

◆ VECTOR_STATE_SIZE

const unsigned int CLHEP::DualRand::VECTOR_STATE_SIZE = 9
static

Definition at line 102 of file DualRand.h.

Referenced by get(), getState(), and restoreStatus().


The documentation for this class was generated from the following files: