Geant4 10.7.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 double ()
 
 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 49 of file DualRand.h.

Constructor & Destructor Documentation

◆ DualRand() [1/4]

CLHEP::DualRand::DualRand ( )

Definition at line 80 of file DualRand.cc.

82 numEngines(numberOfEngines++),
83 tausworthe (1234567 + numEngines + 175321),
84 integerCong(69607 * tausworthe + 54329, numEngines)
85{
86 theSeed = 1234567;
87}

◆ DualRand() [2/4]

CLHEP::DualRand::DualRand ( long  seed)

Definition at line 89 of file DualRand.cc.

91 numEngines(0),
92 tausworthe ((unsigned int)seed + 175321),
93 integerCong(69607 * tausworthe + 54329, 8043) // MF - not numEngines
94{
95 theSeed = seed;
96}

◆ DualRand() [3/4]

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

Definition at line 98 of file DualRand.cc.

100 numEngines(0)
101{
102 is >> *this;
103}

◆ DualRand() [4/4]

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

Definition at line 105 of file DualRand.cc.

107 numEngines(0),
108 tausworthe (rowIndex + 1000 * colIndex + 85329),
109 integerCong(69607 * tausworthe + 54329, 1123) // MF - not numengines
110{
111 theSeed = rowIndex;
112}

◆ ~DualRand()

CLHEP::DualRand::~DualRand ( )
virtual

Definition at line 114 of file DualRand.cc.

114{ }

Member Function Documentation

◆ beginTag()

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

Definition at line 248 of file DualRand.cc.

248 {
249 return "DualRand-begin";
250}

◆ 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 116 of file DualRand.cc.

116 {
117 unsigned int ic ( integerCong );
118 unsigned int t ( tausworthe );
119 return ( (t ^ ic) * twoToMinus_32() + // most significant part
120 (t >> 11) * twoToMinus_53() + // fill in remaining bits
121 nearlyTwoToMinus_54() // make sure non-zero
122 );
123}
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 125 of file DualRand.cc.

125 {
126 for (int i = 0; i < size; ++i) {
127 vect[i] = flat();
128 }
129}
double flat()
Definition: DualRand.cc:116

◆ get() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 288 of file DualRand.cc.

288 {
289 if ((v[0] & 0xffffffffUL) != engineIDulong<DualRand>()) {
290 std::cerr <<
291 "\nDualRand get:state vector has wrong ID word - state unchanged\n";
292 return false;
293 }
294 if (v.size() != VECTOR_STATE_SIZE) {
295 std::cerr << "\nDualRand get:state vector has wrong size: "
296 << v.size() << " - state unchanged\n";
297 return false;
298 }
299 return getState(v);
300}
static const unsigned int VECTOR_STATE_SIZE
Definition: DualRand.h:102
virtual std::istream & getState(std::istream &is)
Definition: DualRand.cc:252

◆ get() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 231 of file DualRand.cc.

231 {
232 char beginMarker [MarkerLen];
233 is >> std::ws;
234 is.width(MarkerLen); // causes the next read to the char* to be <=
235 // that many bytes, INCLUDING A TERMINATION \0
236 // (Stroustrup, section 21.3.2)
237 is >> beginMarker;
238 if (strcmp(beginMarker,"DualRand-begin")) {
239 is.clear(std::ios::badbit | is.rdstate());
240 std::cerr << "\nInput mispositioned or"
241 << "\nDualRand state description missing or"
242 << "\nwrong engine type found." << std::endl;
243 return is;
244 }
245 return getState(is);
246}

◆ getState() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 302 of file DualRand.cc.

302 {
303 std::vector<unsigned long>::const_iterator iv = v.begin()+1;
304 if (!tausworthe.get(iv)) return false;
305 if (!integerCong.get(iv)) return false;
306 if (iv != v.end()) {
307 std::cerr <<
308 "\nDualRand get:state vector has wrong size: " << v.size()
309 << "\n Apparently " << iv-v.begin() << " words were consumed\n";
310 return false;
311 }
312 return true;
313}

◆ getState() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 252 of file DualRand.cc.

252 {
253 if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
254 std::vector<unsigned long> v;
255 unsigned long uu;
256 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
257 is >> uu;
258 if (!is) {
259 is.clear(std::ios::badbit | is.rdstate());
260 std::cerr << "\nDualRand state (vector) description improper."
261 << "\ngetState() has failed."
262 << "\nInput stream is probably mispositioned now." << std::endl;
263 return is;
264 }
265 v.push_back(uu);
266 }
267 getState(v);
268 return (is);
269 }
270
271// is >> theSeed; Removed, encompassed by possibleKeywordInput()
272
273 char endMarker [MarkerLen];
274 tausworthe.get(is);
275 integerCong.get(is);
276 is >> std::ws;
277 is.width(MarkerLen);
278 is >> endMarker;
279 if (strcmp(endMarker,"DualRand-end")) {
280 is.clear(std::ios::badbit | is.rdstate());
281 std::cerr << "DualRand state description incomplete."
282 << "\nInput stream is probably mispositioned now." << std::endl;
283 return is;
284 }
285 return is;
286}
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:166

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

◆ name()

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

Implements CLHEP::HepRandomEngine.

Definition at line 72 of file DualRand.cc.

72{return "DualRand";}

◆ operator double()

CLHEP::DualRand::operator double ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 199 of file DualRand.cc.

199 {
200 return flat();
201}

◆ operator float()

CLHEP::DualRand::operator float ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 203 of file DualRand.cc.

203 {
204 return (float) ( (integerCong ^ tausworthe) * twoToMinus_32()
205 + nearlyTwoToMinus_54() );
206 // add this so that zero never happens
207}

◆ operator unsigned int()

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 209 of file DualRand.cc.

209 {
210 return (integerCong ^ tausworthe) & 0xffffffff;
211}

◆ put() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 223 of file DualRand.cc.

223 {
224 std::vector<unsigned long> v;
225 v.push_back (engineIDulong<DualRand>());
226 tausworthe.put(v);
227 integerCong.put(v);
228 return v;
229}

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 213 of file DualRand.cc.

213 {
214 char beginMarker[] = "DualRand-begin";
215 os << beginMarker << "\nUvec\n";
216 std::vector<unsigned long> v = put();
217 for (unsigned int i=0; i<v.size(); ++i) {
218 os << v[i] << "\n";
219 }
220 return os;
221}
std::vector< unsigned long > put() const
Definition: DualRand.cc:223

◆ restoreStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 153 of file DualRand.cc.

153 {
154 std::ifstream inFile(filename, std::ios::in);
155 if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
156 std::cerr << " -- Engine state remains unchanged\n";
157 return;
158 }
159 if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
160 std::vector<unsigned long> v;
161 unsigned long xin;
162 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
163 inFile >> xin;
164 if (!inFile) {
165 inFile.clear(std::ios::badbit | inFile.rdstate());
166 std::cerr << "\nDualRand state (vector) description improper."
167 << "\nrestoreStatus has failed."
168 << "\nInput stream is probably mispositioned now." << std::endl;
169 return;
170 }
171 v.push_back(xin);
172 }
173 getState(v);
174 return;
175 }
176
177 if (!inFile.bad()) {
178// inFile >> theSeed; removed -- encompased by possibleKeywordInput
179 tausworthe.get(inFile);
180 integerCong.get(inFile);
181 }
182}
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:47

◆ saveStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 142 of file DualRand.cc.

142 {
143 std::ofstream outFile(filename, std::ios::out);
144 if (!outFile.bad()) {
145 outFile << "Uvec\n";
146 std::vector<unsigned long> v = put();
147 for (unsigned int i=0; i<v.size(); ++i) {
148 outFile << v[i] << "\n";
149 }
150 }
151}

◆ setSeed()

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

Implements CLHEP::HepRandomEngine.

Definition at line 131 of file DualRand.cc.

131 {
132 theSeed = seed;
133 tausworthe = Tausworthe((unsigned int)seed + 175321);
134 integerCong = IntegerCong(69607 * tausworthe + 54329, 8043);
135}

Referenced by setSeeds().

◆ setSeeds()

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

Implements CLHEP::HepRandomEngine.

Definition at line 137 of file DualRand.cc.

137 {
138 setSeed(seeds ? *seeds : 1234567, 0);
139 theSeeds = seeds;
140}
void setSeed(long seed, int)
Definition: DualRand.cc:131

◆ showStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 184 of file DualRand.cc.

184 {
185 int pr=std::cout.precision(20);
186 std::cout << std::endl;
187 std::cout << "-------- DualRand engine status ---------"
188 << std::endl;
189 std::cout << "Initial seed = " << theSeed << std::endl;
190 std::cout << "Tausworthe generator = " << std::endl;
191 tausworthe.put(std::cout);
192 std::cout << "\nIntegerCong generator = " << std::endl;
193 integerCong.put(std::cout);
194 std::cout << std::endl << "-----------------------------------------"
195 << std::endl;
196 std::cout.precision(pr);
197}

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: