Geant4  10.02.p03
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
 

Private Member Functions

void update ()
 
void advance (int dozens)
 

Private Attributes

int pDiscard
 
int pDozens
 
int endIters
 
int luxury
 
int index
 
double randoms [12]
 
double carry
 

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

◆ Ranlux64Engine() [1/4]

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

Definition at line 149 of file Ranlux64Engine.cc.

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

◆ Ranlux64Engine() [2/4]

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)
void advance(int dozens)
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:152
Here is the call graph for this function:

◆ Ranlux64Engine() [3/4]

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)
static const double lux
void advance(int dozens)
Here is the call graph for this function:

◆ Ranlux64Engine() [4/4]

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 const double lux
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:152
Here is the call graph for this function:

◆ ~Ranlux64Engine()

CLHEP::Ranlux64Engine::~Ranlux64Engine ( )
virtual

Definition at line 155 of file Ranlux64Engine.cc.

155 {}

Member Function Documentation

◆ advance()

void CLHEP::Ranlux64Engine::advance ( int  dozens)
private

Definition at line 257 of file Ranlux64Engine.cc.

257  {
258 
259  double y1, y2, y3;
260  double cValue = twoToMinus_48();
261  double zero = 0.0;
262  double one = 1.0;
263 
264  // Technical note: We use Luscher's trick to only do the
265  // carry subtraction when we really have to. Like him, we use
266  // three registers instead of two so that we avoid sequences
267  // like storing y1 then immediately replacing its value:
268  // some architectures lose time when this is done.
269 
270  // Luscher's ranlxd.c fills the stash going
271  // upward. We fill it downward to save a bit of time in the
272  // flat() routine at no cost later. This means that while
273  // Luscher's ir is jr+5, our n-r is (n-s)-5. (Note that
274  // though ranlxd.c initializes ir and jr to 11 and 7, ir as
275  // used is 5 more than jr because update is entered after
276  // incrementing ir.)
277  //
278 
279  // I have CAREFULLY checked that the algorithms do match
280  // in all details.
281 
282  int k;
283  for ( k = dozens; k > 0; --k ) {
284 
285  y1 = randoms[ 4] - randoms[11] - carry;
286 
287  y2 = randoms[ 3] - randoms[10];
288  if ( y1 < zero ) {
289  y1 += one;
290  y2 -= cValue;
291  }
292  randoms[11] = y1;
293 
294  y3 = randoms[ 2] - randoms[ 9];
295  if ( y2 < zero ) {
296  y2 += one;
297  y3 -= cValue;
298  }
299  randoms[10] = y2;
300 
301  y1 = randoms[ 1] - randoms[ 8];
302  if ( y3 < zero ) {
303  y3 += one;
304  y1 -= cValue;
305  }
306  randoms[ 9] = y3;
307 
308  y2 = randoms[ 0] - randoms[ 7];
309  if ( y1 < zero ) {
310  y1 += one;
311  y2 -= cValue;
312  }
313  randoms[ 8] = y1;
314 
315  y3 = randoms[11] - randoms[ 6];
316  if ( y2 < zero ) {
317  y2 += one;
318  y3 -= cValue;
319  }
320  randoms[ 7] = y2;
321 
322  y1 = randoms[10] - randoms[ 5];
323  if ( y3 < zero ) {
324  y3 += one;
325  y1 -= cValue;
326  }
327  randoms[ 6] = y3;
328 
329  y2 = randoms[ 9] - randoms[ 4];
330  if ( y1 < zero ) {
331  y1 += one;
332  y2 -= cValue;
333  }
334  randoms[ 5] = y1;
335 
336  y3 = randoms[ 8] - randoms[ 3];
337  if ( y2 < zero ) {
338  y2 += one;
339  y3 -= cValue;
340  }
341  randoms[ 4] = y2;
342 
343  y1 = randoms[ 7] - randoms[ 2];
344  if ( y3 < zero ) {
345  y3 += one;
346  y1 -= cValue;
347  }
348  randoms[ 3] = y3;
349 
350  y2 = randoms[ 6] - randoms[ 1];
351  if ( y1 < zero ) {
352  y1 += one;
353  y2 -= cValue;
354  }
355  randoms[ 2] = y1;
356 
357  y3 = randoms[ 5] - randoms[ 0];
358  if ( y2 < zero ) {
359  y2 += one;
360  y3 -= cValue;
361  }
362  randoms[ 1] = y2;
363 
364  if ( y3 < zero ) {
365  y3 += one;
366  carry = cValue;
367  }
368  randoms[ 0] = y3;
369 
370  } // End of major k loop doing 12 numbers at each cycle
371 
372 } // advance(dozens)
Double_t y2[nxs]
Double_t y1[nxs]
static double twoToMinus_48()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginTag()

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

Definition at line 638 of file Ranlux64Engine.cc.

638  {
639  return "Ranlux64Engine-begin";
640 }
Here is the caller graph for this function:

◆ engineName()

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

Definition at line 92 of file Ranlux64Engine.h.

92 {return "Ranlux64Engine";}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flat()

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:

◆ flatArray()

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:

◆ get() [1/2]

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:

◆ get() [2/2]

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 }
virtual std::istream & getState(std::istream &is)
Here is the call graph for this function:

◆ getLuxury()

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

Definition at line 83 of file Ranlux64Engine.h.

83 { return luxury; }
Here is the call graph for this function:

◆ getState() [1/2]

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
virtual std::istream & getState(std::istream &is)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getState() [2/2]

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];
703  }
704  t[0] = v[25]; t[1] = v[26];
706  index = v[27];
707  luxury = v[28];
708  pDiscard = v[29];
709  return true;
710 }
static const unsigned int VECTOR_STATE_SIZE
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:114
Here is the call graph for this function:

◆ name()

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

Implements CLHEP::HepRandomEngine.

Definition at line 103 of file Ranlux64Engine.cc.

103 {return "Ranlux64Engine";}
Here is the caller graph for this function:

◆ put() [1/2]

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
Here is the call graph for this function:

◆ put() [2/2]

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) {
610  v.push_back(t[0]); v.push_back(t[1]);
611  }
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 }
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:

◆ restoreStatus()

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 }
ifstream in
Definition: comparison.C:7
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
virtual std::istream & getState(std::istream &is)
Here is the call graph for this function:

◆ saveStatus()

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
Here is the call graph for this function:

◆ setSeed()

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()
static const double lux
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSeeds()

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 const double lux
Here is the call graph for this function:
Here is the caller graph for this function:

◆ showStatus()

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 }

◆ update()

void CLHEP::Ranlux64Engine::update ( )
private

Definition at line 167 of file Ranlux64Engine.cc.

167  {
168  // Update the stash of twelve random numbers.
169  // When this routione is entered, index is always 0. The randoms
170  // contains the last 12 numbers in the sequents: s[0] is x[a+11],
171  // s[1] is x[a+10] ... and s[11] is x[a] for some a. Carry contains
172  // the last carry value (c[a+11]).
173  //
174  // The recursion relation (3) in Luscher's note says
175  // delta[n] = x[n-s] = x[n-r] -c[n-1] or for n=a+12,
176  // delta[a+12] = x[a+7] - x[a] -c[a+11] where we use r=12, s=5 per eqn. (7)
177  // This reduces to
178  // s[11] = s[4] - s[11] - carry.
179  // The next number similarly will be given by s[10] = s[3] - s[10] - carry,
180  // and so forth until s[0] is filled.
181  //
182  // However, we need to skip 397, 202 or 109 numbers - these are not divisible
183  // by 12 - to "fare well in the spectral test".
184 
185  advance(pDozens);
186 
187  // Since we wish at the end to have the 12 last numbers in the order of
188  // s[11] first, till s[0] last, we will have to do 1, 10, or 1 iterations
189  // and then re-arrange to place to get the oldest one in s[11].
190  // Generically, this will imply re-arranging the s array at the end,
191  // but we can treat the special case of endIters = 1 separately for superior
192  // efficiency in the cases of levels 0 and 2.
193 
194  double y1;
195 
196  if ( endIters == 1 ) { // Luxury levels 0 and 2 will go here
197  y1 = randoms[ 4] - randoms[11] - carry;
198  if ( y1 < 0.0 ) {
199  y1 += 1.0;
200  carry = twoToMinus_48();
201  } else {
202  carry = 0.0;
203  }
204  randoms[11] = randoms[10];
205  randoms[10] = randoms[ 9];
206  randoms[ 9] = randoms[ 8];
207  randoms[ 8] = randoms[ 7];
208  randoms[ 7] = randoms[ 6];
209  randoms[ 6] = randoms[ 5];
210  randoms[ 5] = randoms[ 4];
211  randoms[ 4] = randoms[ 3];
212  randoms[ 3] = randoms[ 2];
213  randoms[ 2] = randoms[ 1];
214  randoms[ 1] = randoms[ 0];
215  randoms[ 0] = y1;
216 
217  } else {
218 
219  int m, nr, ns;
220  for ( m = 0, nr = 11, ns = 4; m < endIters; ++m, --nr ) {
221  y1 = randoms [ns] - randoms[nr] - carry;
222  if ( y1 < 0.0 ) {
223  y1 += 1.0;
224  carry = twoToMinus_48();
225  } else {
226  carry = 0.0;
227  }
228  randoms[nr] = y1;
229  --ns;
230  if ( ns < 0 ) {
231  ns = 11;
232  }
233  } // loop on m
234 
235  double temp[12];
236  for (m=0; m<12; m++) {
237  temp[m]=randoms[m];
238  }
239 
240  ns = 11 - endIters;
241  for (m=11; m>=0; --m) {
242  randoms[m] = temp[ns];
243  --ns;
244  if ( ns < 0 ) {
245  ns = 11;
246  }
247  }
248 
249  }
250 
251  // Now when we return, there are 12 fresh usable numbers in s[11] ... s[0]
252 
253  index = 11;
254 
255 } // update()
static const double m
Double_t y1[nxs]
static double twoToMinus_48()
void advance(int dozens)
static const double ns
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ carry

double CLHEP::Ranlux64Engine::carry
private

Definition at line 112 of file Ranlux64Engine.h.

◆ endIters

int CLHEP::Ranlux64Engine::endIters
private

Definition at line 107 of file Ranlux64Engine.h.

◆ index

int CLHEP::Ranlux64Engine::index
private

Definition at line 110 of file Ranlux64Engine.h.

◆ luxury

int CLHEP::Ranlux64Engine::luxury
private

Definition at line 108 of file Ranlux64Engine.h.

◆ pDiscard

int CLHEP::Ranlux64Engine::pDiscard
private

Definition at line 105 of file Ranlux64Engine.h.

◆ pDozens

int CLHEP::Ranlux64Engine::pDozens
private

Definition at line 106 of file Ranlux64Engine.h.

◆ randoms

double CLHEP::Ranlux64Engine::randoms[12]
private

Definition at line 111 of file Ranlux64Engine.h.

◆ VECTOR_STATE_SIZE

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: