Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CLHEP::Ranlux64Engine Class Reference

#include <Ranlux64Engine.h>

Inheritance diagram for CLHEP::Ranlux64Engine:
Collaboration diagram for CLHEP::Ranlux64Engine:

Public Member Functions

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

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 Ranlux64Engine.h.

Constructor & Destructor Documentation

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

Definition at line 149 of file Ranlux64Engine.cc.

150 : HepRandomEngine()
151 {
152  is >> *this;
153 }
CLHEP::Ranlux64Engine::Ranlux64Engine ( )

Definition at line 105 of file Ranlux64Engine.cc.

106 : HepRandomEngine()
107 {
108  luxury = 1;
109  int numEngines = numberOfEngines++;
110  int cycle = std::abs(int(numEngines/maxIndex));
111  int curIndex = std::abs(int(numEngines%maxIndex));
112 
113  long mask = ((cycle & 0x007fffff) << 8);
114  long seedlist[2];
115  HepRandom::getTheTableSeeds( seedlist, curIndex );
116  seedlist[0] ^= mask;
117  seedlist[1] = 0;
118 
119  setSeeds(seedlist, luxury);
120  advance ( 8 ); // Discard some iterations and ensure that
121  // this sequence won't match one where seeds
122  // were provided.
123 }
static ush mask[]
Definition: csz_inflate.cc:317
void setSeeds(const long *seeds, int lux=1)
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:251

Here is the call graph for this function:

CLHEP::Ranlux64Engine::Ranlux64Engine ( long  seed,
int  lux = 1 
)

Definition at line 125 of file Ranlux64Engine.cc.

126 : HepRandomEngine()
127 {
128  luxury = lux;
129  long seedlist[2]={seed,0};
130  setSeeds(seedlist, lux);
131  advance ( 2*lux + 1 ); // Discard some iterations to use a different
132  // point in the sequence.
133 }
void setSeeds(const long *seeds, int lux=1)
long seed
Definition: chem4.cc:68
static constexpr double lux

Here is the call graph for this function:

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

Definition at line 135 of file Ranlux64Engine.cc.

136 : HepRandomEngine()
137 {
138  luxury = lux;
139  int cycle = std::abs(int(rowIndex/maxIndex));
140  int row = std::abs(int(rowIndex%maxIndex));
141  long mask = (( cycle & 0x000007ff ) << 20 );
142  long seedlist[2];
143  HepRandom::getTheTableSeeds( seedlist, row );
144  seedlist[0] ^= mask;
145  seedlist[1]= 0;
146  setSeeds(seedlist, lux);
147 }
static ush mask[]
Definition: csz_inflate.cc:317
void setSeeds(const long *seeds, int lux=1)
static constexpr double lux
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:251

Here is the call graph for this function:

CLHEP::Ranlux64Engine::~Ranlux64Engine ( )
virtual

Definition at line 155 of file Ranlux64Engine.cc.

155 {}

Member Function Documentation

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

Definition at line 638 of file Ranlux64Engine.cc.

638  {
639  return "Ranlux64Engine-begin";
640 }
static std::string CLHEP::Ranlux64Engine::engineName ( )
inlinestatic

Definition at line 92 of file Ranlux64Engine.h.

92 {return "Ranlux64Engine";}

Here is the caller graph for this function:

double CLHEP::Ranlux64Engine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 157 of file Ranlux64Engine.cc.

157  {
158  // Luscher improves the speed by computing several numbers in a shot,
159  // in a manner similar to that of the Tausworth in DualRand or the Hurd
160  // engines. Thus, the real work is done in update(). Here we merely ensure
161  // that zero, which the algorithm can produce, is never returned by flat().
162 
163  if (index <= 0) update();
164  return randoms[--index] + twoToMinus_49();
165 }
static double twoToMinus_49()

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 374 of file Ranlux64Engine.cc.

374  {
375  for( int i=0; i < size; ++i ) {
376  vect[i] = flat();
377  }
378 }

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 620 of file Ranlux64Engine.cc.

621 {
622  char beginMarker [MarkerLen];
623  is >> std::ws;
624  is.width(MarkerLen); // causes the next read to the char* to be <=
625  // that many bytes, INCLUDING A TERMINATION \0
626  // (Stroustrup, section 21.3.2)
627  is >> beginMarker;
628  if (strcmp(beginMarker,"Ranlux64Engine-begin")) {
629  is.clear(std::ios::badbit | is.rdstate());
630  std::cerr << "\nInput stream mispositioned or"
631  << "\nRanlux64Engine state description missing or"
632  << "\nwrong engine type found." << std::endl;
633  return is;
634  }
635  return getState(is);
636 }
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::Ranlux64Engine::get ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 684 of file Ranlux64Engine.cc.

684  {
685  if ((v[0] & 0xffffffffUL) != engineIDulong<Ranlux64Engine>()) {
686  std::cerr <<
687  "\nRanlux64Engine get:state vector has wrong ID word - state unchanged\n";
688  return false;
689  }
690  return getState(v);
691 }
tuple v
Definition: test.py:18
virtual std::istream & getState(std::istream &is)

Here is the call graph for this function:

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

Definition at line 83 of file Ranlux64Engine.h.

83 { return luxury; }
std::istream & CLHEP::Ranlux64Engine::getState ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 642 of file Ranlux64Engine.cc.

643 {
644  if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
645  std::vector<unsigned long> v;
646  unsigned long uu;
647  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
648  is >> uu;
649  if (!is) {
650  is.clear(std::ios::badbit | is.rdstate());
651  std::cerr << "\nRanlux64Engine state (vector) description improper."
652  << "\ngetState() has failed."
653  << "\nInput stream is probably mispositioned now." << std::endl;
654  return is;
655  }
656  v.push_back(uu);
657  }
658  getState(v);
659  return (is);
660  }
661 
662 // is >> theSeed; Removed, encompassed by possibleKeywordInput()
663 
664  char endMarker [MarkerLen];
665  for (int i=0; i<12; ++i) {
666  is >> randoms[i];
667  }
668  is >> carry; is >> index;
669  is >> luxury; is >> pDiscard;
670  pDozens = pDiscard / 12;
671  endIters = pDiscard % 12;
672  is >> std::ws;
673  is.width(MarkerLen);
674  is >> endMarker;
675  if (strcmp(endMarker,"Ranlux64Engine-end")) {
676  is.clear(std::ios::badbit | is.rdstate());
677  std::cerr << "\nRanlux64Engine state description incomplete."
678  << "\nInput stream is probably mispositioned now." << std::endl;
679  return is;
680  }
681  return is;
682 }
static const int MarkerLen
Definition: DualRand.cc:67
static const unsigned int VECTOR_STATE_SIZE
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
tuple v
Definition: test.py:18
virtual std::istream & getState(std::istream &is)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 693 of file Ranlux64Engine.cc.

693  {
694  if (v.size() != VECTOR_STATE_SIZE ) {
695  std::cerr <<
696  "\nRanlux64Engine get:state vector has wrong length - state unchanged\n";
697  return false;
698  }
699  std::vector<unsigned long> t(2);
700  for (int i=0; i<12; ++i) {
701  t[0] = v[2*i+1]; t[1] = v[2*i+2];
702  randoms[i] = DoubConv::longs2double(t);
703  }
704  t[0] = v[25]; t[1] = v[26];
705  carry = DoubConv::longs2double(t);
706  index = v[27];
707  luxury = v[28];
708  pDiscard = v[29];
709  return true;
710 }
static const unsigned int VECTOR_STATE_SIZE
tuple v
Definition: test.py:18
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:114

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 103 of file Ranlux64Engine.cc.

103 {return "Ranlux64Engine";}
std::ostream & CLHEP::Ranlux64Engine::put ( std::ostream &  os) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 593 of file Ranlux64Engine.cc.

594 {
595  char beginMarker[] = "Ranlux64Engine-begin";
596  os << beginMarker << "\nUvec\n";
597  std::vector<unsigned long> v = put();
598  for (unsigned int i=0; i<v.size(); ++i) {
599  os << v[i] << "\n";
600  }
601  return os;
602 }
std::vector< unsigned long > put() const
tuple v
Definition: test.py:18

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 604 of file Ranlux64Engine.cc.

604  {
605  std::vector<unsigned long> v;
606  v.push_back (engineIDulong<Ranlux64Engine>());
607  std::vector<unsigned long> t;
608  for (int i=0; i<12; ++i) {
609  t = DoubConv::dto2longs(randoms[i]);
610  v.push_back(t[0]); v.push_back(t[1]);
611  }
612  t = DoubConv::dto2longs(carry);
613  v.push_back(t[0]); v.push_back(t[1]);
614  v.push_back(static_cast<unsigned long>(index));
615  v.push_back(static_cast<unsigned long>(luxury));
616  v.push_back(static_cast<unsigned long>(pDiscard));
617  return v;
618 }
tuple v
Definition: test.py:18
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:98

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 540 of file Ranlux64Engine.cc.

541 {
542  std::ifstream inFile( filename, std::ios::in);
543  if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
544  std::cerr << " -- Engine state remains unchanged\n";
545  return;
546  }
547  if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
548  std::vector<unsigned long> v;
549  unsigned long xin;
550  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
551  inFile >> xin;
552  if (!inFile) {
553  inFile.clear(std::ios::badbit | inFile.rdstate());
554  std::cerr << "\nJamesRandom state (vector) description improper."
555  << "\nrestoreStatus has failed."
556  << "\nInput stream is probably mispositioned now." << std::endl;
557  return;
558  }
559  v.push_back(xin);
560  }
561  getState(v);
562  return;
563  }
564 
565  if (!inFile.bad() && !inFile.eof()) {
566 // inFile >> theSeed; removed -- encompased by possibleKeywordInput
567  for (int i=0; i<12; ++i) {
568  inFile >> randoms[i];
569  }
570  inFile >> carry; inFile >> index;
571  inFile >> luxury; inFile >> pDiscard;
572  pDozens = pDiscard / 12;
573  endIters = pDiscard % 12;
574  }
575 }
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
Definition: RandomEngine.cc:45
static std::string engineName()
static const unsigned int VECTOR_STATE_SIZE
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
tuple v
Definition: test.py:18
virtual std::istream & getState(std::istream &is)

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 528 of file Ranlux64Engine.cc.

529 {
530  std::ofstream outFile( filename, std::ios::out ) ;
531  if (!outFile.bad()) {
532  outFile << "Uvec\n";
533  std::vector<unsigned long> v = put();
534  for (unsigned int i=0; i<v.size(); ++i) {
535  outFile << v[i] << "\n";
536  }
537  }
538 }
std::vector< unsigned long > put() const
tuple v
Definition: test.py:18

Here is the call graph for this function:

void CLHEP::Ranlux64Engine::setSeed ( long  seed,
int  lux = 1 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 380 of file Ranlux64Engine.cc.

380  {
381 
382 // The initialization is carried out using a Multiplicative
383 // Congruential generator using formula constants of L'Ecuyer
384 // as described in "A review of pseudorandom number generators"
385 // (Fred James) published in Computer Physics Communications 60 (1990)
386 // pages 329-344
387 
388  const int ecuyer_a(53668);
389  const int ecuyer_b(40014);
390  const int ecuyer_c(12211);
391  const int ecuyer_d(2147483563);
392 
393  const int lux_levels[3] = {109, 202, 397};
394  theSeed = seed;
395 
396  if( (lux > 2)||(lux < 0) ){
397  pDiscard = (lux >= 12) ? (lux-12) : lux_levels[1];
398  }else{
399  pDiscard = lux_levels[luxury];
400  }
401  pDozens = pDiscard / 12;
402  endIters = pDiscard % 12;
403 
404  long init_table[24];
405  long next_seed = seed;
406  long k_multiple;
407  int i;
408  next_seed &= 0xffffffff;
409  while( next_seed >= ecuyer_d ) {
410  next_seed -= ecuyer_d;
411  }
412 
413  for(i = 0;i != 24;i++){
414  k_multiple = next_seed / ecuyer_a;
415  next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
416  - k_multiple * ecuyer_c;
417  if(next_seed < 0) {
418  next_seed += ecuyer_d;
419  }
420  next_seed &= 0xffffffff;
421  init_table[i] = next_seed;
422  }
423  // are we on a 64bit machine?
424  if( sizeof(long) >= 8 ) {
425  long topbits1, topbits2;
426 #ifdef WIN32
427  topbits1 = ( seed >> 32) & 0xffff ;
428  topbits2 = ( seed >> 48) & 0xffff ;
429 #else
430  topbits1 = detail::rshift<32>(seed) & 0xffff ;
431  topbits2 = detail::rshift<48>(seed) & 0xffff ;
432 #endif
433  init_table[0] ^= topbits1;
434  init_table[2] ^= topbits2;
435  //std::cout << " init_table[0] " << init_table[0] << " from " << topbits1 << std::endl;
436  //std::cout << " init_table[2] " << init_table[2] << " from " << topbits2 << std::endl;
437  }
438 
439  for(i = 0;i < 12; i++){
440  randoms[i] = (init_table[2*i ] ) * 2.0 * twoToMinus_32() +
441  (init_table[2*i+1] >> 15) * twoToMinus_48();
442  //if( randoms[i] < 0. || randoms[i] > 1. ) {
443  //std::cout << "setSeed: init_table " << init_table[2*i ] << std::endl;
444  //std::cout << "setSeed: init_table " << init_table[2*i+1] << std::endl;
445  //std::cout << "setSeed: random " << i << " is " << randoms[i] << std::endl;
446  //}
447  }
448 
449  carry = 0.0;
450  if ( randoms[11] == 0. ) carry = twoToMinus_48();
451  index = 11;
452 
453 } // setSeed()
static double twoToMinus_48()
static double twoToMinus_32()
long seed
Definition: chem4.cc:68
static constexpr double lux

Here is the call graph for this function:

Here is the caller graph for this function:

void CLHEP::Ranlux64Engine::setSeeds ( const long *  seeds,
int  lux = 1 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 455 of file Ranlux64Engine.cc.

455  {
456 // old code only uses the first long in seeds
457 // setSeed( *seeds ? *seeds : 32767, lux );
458 // theSeeds = seeds;
459 
460 // using code from Ranlux - even those are 32bit seeds,
461 // that is good enough to completely differentiate the sequences
462 
463  const int ecuyer_a = 53668;
464  const int ecuyer_b = 40014;
465  const int ecuyer_c = 12211;
466  const int ecuyer_d = 2147483563;
467 
468  const int lux_levels[3] = {109, 202, 397};
469  const long *seedptr;
470 
471  theSeeds = seeds;
472  seedptr = seeds;
473 
474  if(seeds == 0){
476  theSeeds = &theSeed;
477  return;
478  }
479 
480  theSeed = *seeds;
481 
482 // number of additional random numbers that need to be 'thrown away'
483 // every 24 numbers is set using luxury level variable.
484 
485  if( (lux > 2)||(lux < 0) ){
486  pDiscard = (lux >= 12) ? (lux-12) : lux_levels[1];
487  }else{
488  pDiscard = lux_levels[luxury];
489  }
490  pDozens = pDiscard / 12;
491  endIters = pDiscard % 12;
492 
493  long init_table[24];
494  long next_seed = *seeds;
495  long k_multiple;
496  int i;
497 
498  for( i = 0;(i != 24)&&(*seedptr != 0);i++){
499  init_table[i] = *seedptr & 0xffffffff;
500  seedptr++;
501  }
502 
503  if(i != 24){
504  next_seed = init_table[i-1];
505  for(;i != 24;i++){
506  k_multiple = next_seed / ecuyer_a;
507  next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
508  - k_multiple * ecuyer_c;
509  if(next_seed < 0) {
510  next_seed += ecuyer_d;
511  }
512  next_seed &= 0xffffffff;
513  init_table[i] = next_seed;
514  }
515  }
516 
517  for(i = 0;i < 12; i++){
518  randoms[i] = (init_table[2*i ] ) * 2.0 * twoToMinus_32() +
519  (init_table[2*i+1] >> 15) * twoToMinus_48();
520  }
521 
522  carry = 0.0;
523  if ( randoms[11] == 0. ) carry = twoToMinus_48();
524  index = 11;
525 
526 }
static double twoToMinus_48()
static double twoToMinus_32()
void setSeed(long seed, int lux=1)
static constexpr double lux

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 577 of file Ranlux64Engine.cc.

578 {
579  std::cout << std::endl;
580  std::cout << "--------- Ranlux engine status ---------" << std::endl;
581  std::cout << " Initial seed = " << theSeed << std::endl;
582  std::cout << " randoms[] = ";
583  for (int i=0; i<12; ++i) {
584  std::cout << randoms[i] << std::endl;
585  }
586  std::cout << std::endl;
587  std::cout << " carry = " << carry << ", index = " << index << std::endl;
588  std::cout << " luxury = " << luxury << " pDiscard = "
589  << pDiscard << std::endl;
590  std::cout << "----------------------------------------" << std::endl;
591 }

Member Data Documentation

const unsigned int CLHEP::Ranlux64Engine::VECTOR_STATE_SIZE = 30
static

Definition at line 98 of file Ranlux64Engine.h.


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