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

#include <RanecuEngine.h>

+ Inheritance diagram for CLHEP::RanecuEngine:

Public Member Functions

 RanecuEngine (std::istream &is)
 
 RanecuEngine ()
 
 RanecuEngine (int index)
 
virtual ~RanecuEngine ()
 
double flat ()
 
void flatArray (const int size, double *vect)
 
void setIndex (long index)
 
void setSeed (long index, int dum=0)
 
void setSeeds (const long *seeds, int index=-1)
 
void saveStatus (const char filename[]="Ranecu.conf") const
 
void restoreStatus (const char filename[]="Ranecu.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)
 
long getSeed () const
 
const long * getSeeds () const
 

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 Protected Attributes

static const int ecuyer_a = 40014
 
static const int ecuyer_b = 53668
 
static const int ecuyer_c = 12211
 
static const int ecuyer_d = 40692
 
static const int ecuyer_e = 52774
 
static const int ecuyer_f = 3791
 
static const int shift1 = 2147483563
 
static const int shift2 = 2147483399
 
static const unsigned int VECTOR_STATE_SIZE = 4
 

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

Constructor & Destructor Documentation

◆ RanecuEngine() [1/3]

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

Definition at line 105 of file RanecuEngine.cc.

107{
108 is >> *this;
109}

◆ RanecuEngine() [2/3]

CLHEP::RanecuEngine::RanecuEngine ( )

Definition at line 71 of file RanecuEngine.cc.

73{
74 int numEngines = numberOfEngines++;
75 int cycle = std::abs(int(numEngines/maxSeq));
76 seq = std::abs(int(numEngines%maxSeq));
77
78 theSeed = seq;
79 long mask = ((cycle & 0x007fffff) << 8);
80 for (int i=0; i<2; ++i) {
81 for (int j=0; j<maxSeq; ++j) {
83 table[j][i] ^= mask;
84 }
85 }
86 theSeeds = &table[seq][0];
87}
static void getTheTableSeeds(long *seeds, int index)
Definition Random.cc:254

◆ RanecuEngine() [3/3]

CLHEP::RanecuEngine::RanecuEngine ( int index)

Definition at line 89 of file RanecuEngine.cc.

91{
92 int cycle = std::abs(int(index/maxSeq));
93 seq = std::abs(int(index%maxSeq));
94 theSeed = seq;
95 long mask = ((cycle & 0x000007ff) << 20);
96 for (int j=0; j<maxSeq; ++j) {
98 table[j][0] ^= mask;
99 table[j][1] ^= mask;
100 }
101 theSeeds = &table[seq][0];
102 further_randomize (seq, 0, index, shift1); // mf 6/22/10
103}
static const int shift1

◆ ~RanecuEngine()

CLHEP::RanecuEngine::~RanecuEngine ( )
virtual

Definition at line 111 of file RanecuEngine.cc.

111{}

Member Function Documentation

◆ beginTag()

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

Definition at line 317 of file RanecuEngine.cc.

317 {
318 return "RanecuEngine-begin";
319}

◆ engineName()

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

Definition at line 99 of file RanecuEngine.h.

99{return "RanecuEngine";}

Referenced by restoreStatus().

◆ flat()

double CLHEP::RanecuEngine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 199 of file RanecuEngine.cc.

200{
201 const int index = seq;
202 long seed1 = table[index][0];
203 long seed2 = table[index][1];
204
205 int k1 = (int)(seed1/ecuyer_b);
206 int k2 = (int)(seed2/ecuyer_e);
207
208 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
209 if (seed1 < 0) seed1 += shift1;
210 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
211 if (seed2 < 0) seed2 += shift2;
212
213 table[index][0] = seed1;
214 table[index][1] = seed2;
215
216 long diff = seed1-seed2;
217
218 if (diff <= 0) diff += (shift1-1);
219 return (double)(diff*prec);
220}
static const int ecuyer_b
static const int ecuyer_e
static const int ecuyer_f
static const int ecuyer_d
static const int ecuyer_a
static const int shift2
static const int ecuyer_c

◆ flatArray()

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

Implements CLHEP::HepRandomEngine.

Definition at line 222 of file RanecuEngine.cc.

223{
224 const int index = seq;
225 long seed1 = table[index][0];
226 long seed2 = table[index][1];
227 int k1, k2;
228 int i;
229
230 for (i=0; i<size; ++i)
231 {
232 k1 = (int)(seed1/ecuyer_b);
233 k2 = (int)(seed2/ecuyer_e);
234
235 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
236 if (seed1 < 0) seed1 += shift1;
237 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
238 if (seed2 < 0) seed2 += shift2;
239
240 long diff = seed1-seed2;
241 if (diff <= 0) diff += (shift1-1);
242
243 vect[i] = (double)(diff*prec);
244 }
245 table[index][0] = seed1;
246 table[index][1] = seed2;
247}

◆ get() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 360 of file RanecuEngine.cc.

360 {
361 if ((v[0] & 0xffffffffUL) != engineIDulong<RanecuEngine>()) {
362 std::cerr <<
363 "\nRanecuEngine get:state vector has wrong ID word - state unchanged\n";
364 return false;
365 }
366 return getState(v);
367}
virtual std::istream & getState(std::istream &is)
unsigned long engineIDulong()

◆ get() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 298 of file RanecuEngine.cc.

299{
300 char beginMarker [MarkerLen];
301
302 is >> std::ws;
303 is.width(MarkerLen); // causes the next read to the char* to be <=
304 // that many bytes, INCLUDING A TERMINATION \0
305 // (Stroustrup, section 21.3.2)
306 is >> beginMarker;
307 if (strcmp(beginMarker,"RanecuEngine-begin")) {
308 is.clear(std::ios::badbit | is.rdstate());
309 std::cerr << "\nInput stream mispositioned or"
310 << "\nRanecuEngine state description missing or"
311 << "\nwrong engine type found." << std::endl;
312 return is;
313 }
314 return getState(is);
315}

◆ getState() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 369 of file RanecuEngine.cc.

369 {
370 if (v.size() != VECTOR_STATE_SIZE ) {
371 std::cerr <<
372 "\nRanecuEngine get:state vector has wrong length - state unchanged\n";
373 return false;
374 }
375 theSeed = v[1];
376 table[theSeed][0] = v[2];
377 table[theSeed][1] = v[3];
378 seq = int(theSeed);
379 return true;
380}
static const unsigned int VECTOR_STATE_SIZE

◆ getState() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 321 of file RanecuEngine.cc.

322{
323 if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
324 std::vector<unsigned long> v;
325 unsigned long uu;
326 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
327 is >> uu;
328 if (!is) {
329 is.clear(std::ios::badbit | is.rdstate());
330 std::cerr << "\nRanecuEngine state (vector) description improper."
331 << "\ngetState() has failed."
332 << "\nInput stream is probably mispositioned now." << std::endl;
333 return is;
334 }
335 v.push_back(uu);
336 }
337 getState(v);
338 return (is);
339 }
340
341// is >> theSeed; Removed, encompassed by possibleKeywordInput()
342 char endMarker [MarkerLen];
343 for (int i=0; i<2; ++i) {
344 is >> table[theSeed][i];
345 }
346 is >> std::ws;
347 is.width(MarkerLen);
348 is >> endMarker;
349 if (strcmp(endMarker,"RanecuEngine-end")) {
350 is.clear(std::ios::badbit | is.rdstate());
351 std::cerr << "\nRanecuEngine state description incomplete."
352 << "\nInput stream is probably mispositioned now." << std::endl;
353 return is;
354 }
355
356 seq = int(theSeed);
357 return is;
358}
bool possibleKeywordInput(IS &is, const std::string &key, T &t)

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

◆ name()

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

Implements CLHEP::HepRandomEngine.

Definition at line 63 of file RanecuEngine.cc.

63{return "RanecuEngine";}

◆ operator double()

CLHEP::RanecuEngine::operator double ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 249 of file RanecuEngine.cc.

249 {
250 return flat();
251}

◆ operator float()

CLHEP::RanecuEngine::operator float ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 253 of file RanecuEngine.cc.

253 {
254 return float( flat() );
255}

◆ operator unsigned int()

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 257 of file RanecuEngine.cc.

257 {
258 const int index = seq;
259 long seed1 = table[index][0];
260 long seed2 = table[index][1];
261
262 int k1 = (int)(seed1/ecuyer_b);
263 int k2 = (int)(seed2/ecuyer_e);
264
265 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
266 if (seed1 < 0) seed1 += shift1;
267 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
268 if (seed2 < 0) seed2 += shift2;
269
270 table[index][0] = seed1;
271 table[index][1] = seed2;
272 long diff = seed1-seed2;
273 if( diff <= 0 ) diff += (shift1-1);
274
275 return ((diff << 1) | (seed1&1))& 0xffffffff;
276}

◆ put() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 289 of file RanecuEngine.cc.

289 {
290 std::vector<unsigned long> v;
291 v.push_back (engineIDulong<RanecuEngine>());
292 v.push_back(static_cast<unsigned long>(theSeed));
293 v.push_back(static_cast<unsigned long>(table[theSeed][0]));
294 v.push_back(static_cast<unsigned long>(table[theSeed][1]));
295 return v;
296}

Referenced by put(), and saveStatus().

◆ put() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 278 of file RanecuEngine.cc.

279{
280 char beginMarker[] = "RanecuEngine-begin";
281 os << beginMarker << "\nUvec\n";
282 std::vector<unsigned long> v = put();
283 for (unsigned int i=0; i<v.size(); ++i) {
284 os << v[i] << "\n";
285 }
286 return os;
287}
std::vector< unsigned long > put() const

◆ restoreStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 155 of file RanecuEngine.cc.

156{
157 std::ifstream inFile( filename, std::ios::in);
158 if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
159 std::cerr << " -- Engine state remains unchanged\n";
160 return;
161 }
162 if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
163 std::vector<unsigned long> v;
164 unsigned long xin;
165 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
166 inFile >> xin;
167 if (!inFile) {
168 inFile.clear(std::ios::badbit | inFile.rdstate());
169 std::cerr << "\nJamesRandom state (vector) description improper."
170 << "\nrestoreStatus has failed."
171 << "\nInput stream is probably mispositioned now." << std::endl;
172 return;
173 }
174 v.push_back(xin);
175 }
176 getState(v);
177 return;
178 }
179
180 if (!inFile.bad() && !inFile.eof()) {
181// inFile >> theSeed; removed -- encompased by possibleKeywordInput
182 for (int i=0; i<2; ++i)
183 inFile >> table[theSeed][i];
184 seq = int(theSeed);
185 }
186}
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
static std::string engineName()

◆ saveStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 142 of file RanecuEngine.cc.

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

◆ setIndex()

void CLHEP::RanecuEngine::setIndex ( long index)

Definition at line 135 of file RanecuEngine.cc.

136{
137 seq = std::abs(int(index%maxSeq));
138 theSeed = seq;
139 theSeeds = &table[seq][0];
140}

◆ setSeed()

void CLHEP::RanecuEngine::setSeed ( long index,
int dum = 0 )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 113 of file RanecuEngine.cc.

114{
115 seq = std::abs(int(index%maxSeq));
116 theSeed = seq;
117 HepRandom::getTheTableSeeds(table[seq],seq);
118 theSeeds = &table[seq][0];
119 further_randomize (seq, 0, (int)index, shift1); // mf 6/22/10
120 further_randomize (seq, 1, dum, shift2); // mf 6/22/10
121}

◆ setSeeds()

void CLHEP::RanecuEngine::setSeeds ( const long * seeds,
int index = -1 )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 123 of file RanecuEngine.cc.

124{
125 if (pos != -1) {
126 seq = std::abs(int(pos%maxSeq));
127 theSeed = seq;
128 }
129 // only positive seeds are allowed
130 table[seq][0] = std::abs(seeds[0])%shift1;
131 table[seq][1] = std::abs(seeds[1])%shift2;
132 theSeeds = &table[seq][0];
133}

◆ showStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 188 of file RanecuEngine.cc.

189{
190 std::cout << std::endl;
191 std::cout << "--------- Ranecu engine status ---------" << std::endl;
192 std::cout << " Initial seed (index) = " << theSeed << std::endl;
193 std::cout << " Current couple of seeds = "
194 << table[theSeed][0] << ", "
195 << table[theSeed][1] << std::endl;
196 std::cout << "----------------------------------------" << std::endl;
197}

Member Data Documentation

◆ ecuyer_a

const int CLHEP::RanecuEngine::ecuyer_a = 40014
staticprotected

Definition at line 109 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ ecuyer_b

const int CLHEP::RanecuEngine::ecuyer_b = 53668
staticprotected

Definition at line 110 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ ecuyer_c

const int CLHEP::RanecuEngine::ecuyer_c = 12211
staticprotected

Definition at line 111 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ ecuyer_d

const int CLHEP::RanecuEngine::ecuyer_d = 40692
staticprotected

Definition at line 112 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ ecuyer_e

const int CLHEP::RanecuEngine::ecuyer_e = 52774
staticprotected

Definition at line 113 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ ecuyer_f

const int CLHEP::RanecuEngine::ecuyer_f = 3791
staticprotected

Definition at line 114 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ shift1

const int CLHEP::RanecuEngine::shift1 = 2147483563
staticprotected

Definition at line 115 of file RanecuEngine.h.

Referenced by flat(), flatArray(), RanecuEngine(), setSeed(), and setSeeds().

◆ shift2

const int CLHEP::RanecuEngine::shift2 = 2147483399
staticprotected

Definition at line 116 of file RanecuEngine.h.

Referenced by flat(), flatArray(), setSeed(), and setSeeds().

◆ VECTOR_STATE_SIZE

const unsigned int CLHEP::RanecuEngine::VECTOR_STATE_SIZE = 4
staticprotected

Definition at line 118 of file RanecuEngine.h.

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


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