Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CLHEP::RanluxEngine Class Reference

#include <RanluxEngine.h>

Inheritance diagram for CLHEP::RanluxEngine:
Collaboration diagram for CLHEP::RanluxEngine:

Public Member Functions

 RanluxEngine (std::istream &is)
 
 RanluxEngine ()
 
 RanluxEngine (long seed, int lux=3)
 
 RanluxEngine (int rowIndex, int colIndex, int lux)
 
virtual ~RanluxEngine ()
 
double flat ()
 
void flatArray (const int size, double *vect)
 
void setSeed (long seed, int lux=3)
 
void setSeeds (const long *seeds, int lux=3)
 
void saveStatus (const char filename[]="Ranlux.conf") const
 
void restoreStatus (const char filename[]="Ranlux.conf")
 
void showStatus () const
 
int getLuxury () const
 
 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
 
virtual operator double ()
 
virtual operator float ()
 

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 = 31
 

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 45 of file RanluxEngine.h.

Constructor & Destructor Documentation

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

Definition at line 119 of file RanluxEngine.cc.

120 : HepRandomEngine()
121 {
122  is >> *this;
123 }
CLHEP::RanluxEngine::RanluxEngine ( )

Definition at line 76 of file RanluxEngine.cc.

78 {
79  long seed;
80  long seedlist[2]={0,0};
81 
82  luxury = 3;
83  int numEngines = numberOfEngines++;
84  int cycle = std::abs(int(numEngines/maxIndex));
85  int curIndex = std::abs(int(numEngines%maxIndex));
86 
87  long mask = ((cycle & 0x007fffff) << 8);
88  HepRandom::getTheTableSeeds( seedlist, curIndex );
89  seed = seedlist[0]^mask;
90  setSeed(seed, luxury);
91 
92  // setSeeds() wants a zero terminated array!
93  seedlist[0]=theSeed;
94  seedlist[1]=0;
95  setSeeds(seedlist, luxury);
96 }
static ush mask[]
Definition: csz_inflate.cc:317
void setSeeds(const long *seeds, int lux=3)
void setSeed(long seed, int lux=3)
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:251

Here is the call graph for this function:

CLHEP::RanluxEngine::RanluxEngine ( long  seed,
int  lux = 3 
)

Definition at line 62 of file RanluxEngine.cc.

64 {
65  long seedlist[2]={0,0};
66 
67  luxury = lux;
68  setSeed(seed, luxury);
69 
70  // setSeeds() wants a zero terminated array!
71  seedlist[0]=theSeed;
72  seedlist[1]=0;
73  setSeeds(seedlist, luxury);
74 }
void setSeeds(const long *seeds, int lux=3)
void setSeed(long seed, int lux=3)
static constexpr double lux

Here is the call graph for this function:

CLHEP::RanluxEngine::RanluxEngine ( int  rowIndex,
int  colIndex,
int  lux 
)

Definition at line 98 of file RanluxEngine.cc.

100 {
101  long seed;
102  long seedlist[2]={0,0};
103 
104  luxury = lux;
105  int cycle = std::abs(int(rowIndex/maxIndex));
106  int row = std::abs(int(rowIndex%maxIndex));
107  int col = std::abs(int(colIndex%2));
108  long mask = (( cycle & 0x000007ff ) << 20 );
109  HepRandom::getTheTableSeeds( seedlist, row );
110  seed = ( seedlist[col] )^mask;
111  setSeed(seed, luxury);
112 
113  // setSeeds() wants a zero terminated array!
114  seedlist[0]=theSeed;
115  seedlist[1]=0;
116  setSeeds(seedlist, luxury);
117 }
static ush mask[]
Definition: csz_inflate.cc:317
void setSeeds(const long *seeds, int lux=3)
void setSeed(long seed, int lux=3)
static constexpr double lux
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:251

Here is the call graph for this function:

CLHEP::RanluxEngine::~RanluxEngine ( )
virtual

Definition at line 125 of file RanluxEngine.cc.

125 {}

Member Function Documentation

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

Definition at line 466 of file RanluxEngine.cc.

466  {
467  return "RanluxEngine-begin";
468 }
static std::string CLHEP::RanluxEngine::engineName ( )
inlinestatic

Definition at line 102 of file RanluxEngine.h.

102 {return "RanluxEngine";}

Here is the caller graph for this function:

double CLHEP::RanluxEngine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 311 of file RanluxEngine.cc.

311  {
312 
313  float next_random;
314  float uni;
315  int i;
316 
317  uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
318  if(uni < 0. ){
319  uni += 1.0;
320  carry = mantissa_bit_24();
321  }else{
322  carry = 0.;
323  }
324 
325  float_seed_table[i_lag] = uni;
326  i_lag --;
327  j_lag --;
328  if(i_lag < 0) i_lag = 23;
329  if(j_lag < 0) j_lag = 23;
330 
331  if( uni < mantissa_bit_12() ){
332  uni += mantissa_bit_24() * float_seed_table[j_lag];
333  if( uni == 0) uni = mantissa_bit_24() * mantissa_bit_24();
334  }
335  next_random = uni;
336  count24 ++;
337 
338 // every 24th number generation, several random numbers are generated
339 // and wasted depending upon the luxury level.
340 
341  if(count24 == 24 ){
342  count24 = 0;
343  for( i = 0; i != nskip ; i++){
344  uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
345  if(uni < 0. ){
346  uni += 1.0;
347  carry = mantissa_bit_24();
348  }else{
349  carry = 0.;
350  }
351  float_seed_table[i_lag] = uni;
352  i_lag --;
353  j_lag --;
354  if(i_lag < 0)i_lag = 23;
355  if(j_lag < 0) j_lag = 23;
356  }
357  }
358  return (double) next_random;
359 }
static double mantissa_bit_24()
static double mantissa_bit_12()

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 361 of file RanluxEngine.cc.

362 {
363  float next_random;
364  float uni;
365  int i;
366  int index;
367 
368  for (index=0; index<size; ++index) {
369  uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
370  if(uni < 0. ){
371  uni += 1.0;
372  carry = mantissa_bit_24();
373  }else{
374  carry = 0.;
375  }
376 
377  float_seed_table[i_lag] = uni;
378  i_lag --;
379  j_lag --;
380  if(i_lag < 0) i_lag = 23;
381  if(j_lag < 0) j_lag = 23;
382 
383  if( uni < mantissa_bit_12() ){
384  uni += mantissa_bit_24() * float_seed_table[j_lag];
385  if( uni == 0) uni = mantissa_bit_24() * mantissa_bit_24();
386  }
387  next_random = uni;
388  vect[index] = (double)next_random;
389  count24 ++;
390 
391 // every 24th number generation, several random numbers are generated
392 // and wasted depending upon the luxury level.
393 
394  if(count24 == 24 ){
395  count24 = 0;
396  for( i = 0; i != nskip ; i++){
397  uni = float_seed_table[j_lag] - float_seed_table[i_lag] - carry;
398  if(uni < 0. ){
399  uni += 1.0;
400  carry = mantissa_bit_24();
401  }else{
402  carry = 0.;
403  }
404  float_seed_table[i_lag] = uni;
405  i_lag --;
406  j_lag --;
407  if(i_lag < 0)i_lag = 23;
408  if(j_lag < 0) j_lag = 23;
409  }
410  }
411  }
412 }
static double mantissa_bit_24()
static double mantissa_bit_12()

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 448 of file RanluxEngine.cc.

449 {
450  char beginMarker [MarkerLen];
451  is >> std::ws;
452  is.width(MarkerLen); // causes the next read to the char* to be <=
453  // that many bytes, INCLUDING A TERMINATION \0
454  // (Stroustrup, section 21.3.2)
455  is >> beginMarker;
456  if (strcmp(beginMarker,"RanluxEngine-begin")) {
457  is.clear(std::ios::badbit | is.rdstate());
458  std::cerr << "\nInput stream mispositioned or"
459  << "\nRanluxEngine state description missing or"
460  << "\nwrong engine type found." << std::endl;
461  return is;
462  }
463  return getState(is);
464 }
static const int MarkerLen
Definition: DualRand.cc:67
virtual std::istream & getState(std::istream &is)

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 511 of file RanluxEngine.cc.

511  {
512  if ((v[0] & 0xffffffffUL) != engineIDulong<RanluxEngine>()) {
513  std::cerr <<
514  "\nRanluxEngine get:state vector has wrong ID word - state unchanged\n";
515  return false;
516  }
517  return getState(v);
518 }
virtual std::istream & getState(std::istream &is)

Here is the call graph for this function:

int CLHEP::RanluxEngine::getLuxury ( ) const
inline

Definition at line 91 of file RanluxEngine.h.

91 { return luxury; }
std::istream & CLHEP::RanluxEngine::getState ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 470 of file RanluxEngine.cc.

471 {
472  if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
473  std::vector<unsigned long> v;
474  unsigned long uu;
475  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
476  is >> uu;
477  if (!is) {
478  is.clear(std::ios::badbit | is.rdstate());
479  std::cerr << "\nRanluxEngine state (vector) description improper."
480  << "\ngetState() has failed."
481  << "\nInput stream is probably mispositioned now." << std::endl;
482  return is;
483  }
484  v.push_back(uu);
485  }
486  getState(v);
487  return (is);
488  }
489 
490 // is >> theSeed; Removed, encompassed by possibleKeywordInput()
491 
492  char endMarker [MarkerLen];
493  for (int i=0; i<24; ++i) {
494  is >> float_seed_table[i];
495  }
496  is >> i_lag; is >> j_lag;
497  is >> carry; is >> count24;
498  is >> luxury; is >> nskip;
499  is >> std::ws;
500  is.width(MarkerLen);
501  is >> endMarker;
502  if (strcmp(endMarker,"RanluxEngine-end")) {
503  is.clear(std::ios::badbit | is.rdstate());
504  std::cerr << "\nRanluxEngine state description incomplete."
505  << "\nInput stream is probably mispositioned now." << std::endl;
506  return is;
507  }
508  return is;
509 }
static const int MarkerLen
Definition: DualRand.cc:67
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
virtual std::istream & getState(std::istream &is)
static const unsigned int VECTOR_STATE_SIZE
Definition: RanluxEngine.h:108

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 520 of file RanluxEngine.cc.

520  {
521  if (v.size() != VECTOR_STATE_SIZE ) {
522  std::cerr <<
523  "\nRanluxEngine get:state vector has wrong length - state unchanged\n";
524  return false;
525  }
526  for (int i=0; i<24; ++i) {
527  float_seed_table[i] = v[i+1]*mantissa_bit_24();
528  }
529  i_lag = v[25];
530  j_lag = v[26];
531  carry = v[27]*mantissa_bit_24();
532  count24 = v[28];
533  luxury = v[29];
534  nskip = v[30];
535  return true;
536 }
static double mantissa_bit_24()
static const unsigned int VECTOR_STATE_SIZE
Definition: RanluxEngine.h:108

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 60 of file RanluxEngine.cc.

60 {return "RanluxEngine";}
CLHEP::RanluxEngine::operator unsigned int ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 414 of file RanluxEngine.cc.

414  {
415  return ((unsigned int)(flat() * exponent_bit_32()) & 0xffffffff) |
416  (((unsigned int)(float_seed_table[i_lag]*exponent_bit_32())>>16) & 0xff);
417  // needed because Ranlux doesn't fill all bits of the double
418  // which therefore doesn't fill all bits of the integer.
419 }
static double exponent_bit_32()
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 421 of file RanluxEngine.cc.

422 {
423  char beginMarker[] = "RanluxEngine-begin";
424  os << beginMarker << "\nUvec\n";
425  std::vector<unsigned long> v = put();
426  for (unsigned int i=0; i<v.size(); ++i) {
427  os << v[i] << "\n";
428  }
429  return os;
430 }
std::vector< unsigned long > put() const

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 432 of file RanluxEngine.cc.

432  {
433  std::vector<unsigned long> v;
434  v.push_back (engineIDulong<RanluxEngine>());
435  for (int i=0; i<24; ++i) {
436  v.push_back
437  (static_cast<unsigned long>(float_seed_table[i]/mantissa_bit_24()));
438  }
439  v.push_back(static_cast<unsigned long>(i_lag));
440  v.push_back(static_cast<unsigned long>(j_lag));
441  v.push_back(static_cast<unsigned long>(carry/mantissa_bit_24()));
442  v.push_back(static_cast<unsigned long>(count24));
443  v.push_back(static_cast<unsigned long>(luxury));
444  v.push_back(static_cast<unsigned long>(nskip));
445  return v;
446 }
static double mantissa_bit_24()

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 261 of file RanluxEngine.cc.

262 {
263  std::ifstream inFile( filename, std::ios::in);
264  if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
265  std::cerr << " -- Engine state remains unchanged\n";
266  return;
267  }
268  if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
269  std::vector<unsigned long> v;
270  unsigned long xin;
271  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
272  inFile >> xin;
273  if (!inFile) {
274  inFile.clear(std::ios::badbit | inFile.rdstate());
275  std::cerr << "\nRanluxEngine state (vector) description improper."
276  << "\nrestoreStatus has failed."
277  << "\nInput stream is probably mispositioned now." << std::endl;
278  return;
279  }
280  v.push_back(xin);
281  }
282  getState(v);
283  return;
284  }
285 
286  if (!inFile.bad() && !inFile.eof()) {
287 // inFile >> theSeed; removed -- encompased by possibleKeywordInput
288  for (int i=0; i<24; ++i)
289  inFile >> float_seed_table[i];
290  inFile >> i_lag; inFile >> j_lag;
291  inFile >> carry; inFile >> count24;
292  inFile >> luxury; inFile >> nskip;
293  }
294 }
static std::string engineName()
Definition: RanluxEngine.h:102
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
Definition: RandomEngine.cc:45
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
virtual std::istream & getState(std::istream &is)
static const unsigned int VECTOR_STATE_SIZE
Definition: RanluxEngine.h:108

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 249 of file RanluxEngine.cc.

250 {
251  std::ofstream outFile( filename, std::ios::out ) ;
252  if (!outFile.bad()) {
253  outFile << "Uvec\n";
254  std::vector<unsigned long> v = put();
255  for (unsigned int i=0; i<v.size(); ++i) {
256  outFile << v[i] << "\n";
257  }
258  }
259 }
std::vector< unsigned long > put() const

Here is the call graph for this function:

void CLHEP::RanluxEngine::setSeed ( long  seed,
int  lux = 3 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 127 of file RanluxEngine.cc.

127  {
128 
129 // The initialisation is carried out using a Multiplicative
130 // Congruential generator using formula constants of L'Ecuyer
131 // as described in "A review of pseudorandom number generators"
132 // (Fred James) published in Computer Physics Communications 60 (1990)
133 // pages 329-344
134 
135  const int ecuyer_a = 53668;
136  const int ecuyer_b = 40014;
137  const int ecuyer_c = 12211;
138  const int ecuyer_d = 2147483563;
139 
140  const int lux_levels[5] = {0,24,73,199,365};
141 
142  long int_seed_table[24];
143  long next_seed = seed;
144  long k_multiple;
145  int i;
146 
147 // number of additional random numbers that need to be 'thrown away'
148 // every 24 numbers is set using luxury level variable.
149 
150  theSeed = seed;
151  if( (lux > 4)||(lux < 0) ){
152  if(lux >= 24){
153  nskip = lux - 24;
154  }else{
155  nskip = lux_levels[3]; // corresponds to default luxury level
156  }
157  }else{
158  luxury = lux;
159  nskip = lux_levels[luxury];
160  }
161 
162 
163  for(i = 0;i != 24;i++){
164  k_multiple = next_seed / ecuyer_a;
165  next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
166  - k_multiple * ecuyer_c ;
167  if(next_seed < 0)next_seed += ecuyer_d;
168  int_seed_table[i] = next_seed % int_modulus;
169  }
170 
171  for(i = 0;i != 24;i++)
172  float_seed_table[i] = int_seed_table[i] * mantissa_bit_24();
173 
174  i_lag = 23;
175  j_lag = 9;
176  carry = 0. ;
177 
178  if( float_seed_table[23] == 0. ) carry = mantissa_bit_24();
179 
180  count24 = 0;
181 }
static double mantissa_bit_24()
static constexpr double lux

Here is the call graph for this function:

Here is the caller graph for this function:

void CLHEP::RanluxEngine::setSeeds ( const long *  seeds,
int  lux = 3 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 183 of file RanluxEngine.cc.

183  {
184 
185  const int ecuyer_a = 53668;
186  const int ecuyer_b = 40014;
187  const int ecuyer_c = 12211;
188  const int ecuyer_d = 2147483563;
189 
190  const int lux_levels[5] = {0,24,73,199,365};
191  int i;
192  long int_seed_table[24];
193  long k_multiple,next_seed;
194  const long *seedptr;
195 
196  theSeeds = seeds;
197  seedptr = seeds;
198 
199  if(seeds == 0){
201  theSeeds = &theSeed;
202  return;
203  }
204 
205  theSeed = *seeds;
206 
207 // number of additional random numbers that need to be 'thrown away'
208 // every 24 numbers is set using luxury level variable.
209 
210  if( (lux > 4)||(lux < 0) ){
211  if(lux >= 24){
212  nskip = lux - 24;
213  }else{
214  nskip = lux_levels[3]; // corresponds to default luxury level
215  }
216  }else{
217  luxury = lux;
218  nskip = lux_levels[luxury];
219  }
220 
221  for( i = 0;(i != 24)&&(*seedptr != 0);i++){
222  int_seed_table[i] = *seedptr % int_modulus;
223  seedptr++;
224  }
225 
226  if(i != 24){
227  next_seed = int_seed_table[i-1];
228  for(;i != 24;i++){
229  k_multiple = next_seed / ecuyer_a;
230  next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
231  - k_multiple * ecuyer_c ;
232  if(next_seed < 0)next_seed += ecuyer_d;
233  int_seed_table[i] = next_seed % int_modulus;
234  }
235  }
236 
237  for(i = 0;i != 24;i++)
238  float_seed_table[i] = int_seed_table[i] * mantissa_bit_24();
239 
240  i_lag = 23;
241  j_lag = 9;
242  carry = 0. ;
243 
244  if( float_seed_table[23] == 0. ) carry = mantissa_bit_24();
245 
246  count24 = 0;
247 }
static double mantissa_bit_24()
void setSeed(long seed, int lux=3)
static constexpr double lux

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 296 of file RanluxEngine.cc.

297 {
298  std::cout << std::endl;
299  std::cout << "--------- Ranlux engine status ---------" << std::endl;
300  std::cout << " Initial seed = " << theSeed << std::endl;
301  std::cout << " float_seed_table[] = ";
302  for (int i=0; i<24; ++i)
303  std::cout << float_seed_table[i] << " ";
304  std::cout << std::endl;
305  std::cout << " i_lag = " << i_lag << ", j_lag = " << j_lag << std::endl;
306  std::cout << " carry = " << carry << ", count24 = " << count24 << std::endl;
307  std::cout << " luxury = " << luxury << " nskip = " << nskip << std::endl;
308  std::cout << "----------------------------------------" << std::endl;
309 }

Member Data Documentation

const unsigned int CLHEP::RanluxEngine::VECTOR_STATE_SIZE = 31
static

Definition at line 108 of file RanluxEngine.h.


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