Geant4-11
Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
CLHEP::Ranlux64Engine Class Reference

#include <Ranlux64Engine.h>

Inheritance diagram for CLHEP::Ranlux64Engine:
CLHEP::HepRandomEngine

Public Member Functions

double flat ()
 
void flatArray (const int size, double *vect)
 
bool get (const std::vector< unsigned long > &v)
 
virtual std::istream & get (std::istream &is)
 
int getLuxury () const
 
long getSeed () const
 
const long * getSeeds () const
 
bool getState (const std::vector< unsigned long > &v)
 
virtual std::istream & getState (std::istream &is)
 
std::string name () const
 
virtual operator double ()
 
virtual operator float ()
 
virtual operator unsigned int ()
 
bool operator!= (const HepRandomEngine &engine)
 
bool operator== (const HepRandomEngine &engine)
 
std::vector< unsigned long > put () const
 
virtual std::ostream & put (std::ostream &os) const
 
 Ranlux64Engine ()
 
 Ranlux64Engine (int rowIndex, int colIndex, int lxr)
 
 Ranlux64Engine (long seed, int lxr=1)
 
 Ranlux64Engine (std::istream &is)
 
void restoreStatus (const char filename[]="Ranlux64.conf")
 
void saveStatus (const char filename[]="Ranlux64.conf") const
 
void setSeed (long seed, int lxr=1)
 
void setSeeds (const long *seeds, int lxr=1)
 
void showStatus () const
 
virtual ~Ranlux64Engine ()
 

Static Public Member Functions

static std::string beginTag ()
 
static std::string engineName ()
 
static HepRandomEnginenewEngine (const std::vector< unsigned long > &v)
 
static HepRandomEnginenewEngine (std::istream &is)
 

Static Public Attributes

static const unsigned int VECTOR_STATE_SIZE = 30
 

Static Protected Member Functions

static bool checkFile (std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
 
static double exponent_bit_32 ()
 
static double mantissa_bit_12 ()
 
static double mantissa_bit_24 ()
 
static double mantissa_bit_32 ()
 
static double nearlyTwoToMinus_54 ()
 
static double twoToMinus_32 ()
 
static double twoToMinus_48 ()
 
static double twoToMinus_49 ()
 
static double twoToMinus_53 ()
 

Protected Attributes

long theSeed
 
const long * theSeeds
 

Private Member Functions

void advance (int dozens)
 
void update ()
 

Private Attributes

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

Detailed Description

Author

Definition at line 48 of file Ranlux64Engine.h.

Constructor & Destructor Documentation

◆ Ranlux64Engine() [1/4]

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

Definition at line 151 of file Ranlux64Engine.cc.

153{
154 is >> *this;
155}

◆ Ranlux64Engine() [2/4]

CLHEP::Ranlux64Engine::Ranlux64Engine ( )

Definition at line 107 of file Ranlux64Engine.cc.

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

References advance(), geant4_check_module_cycles::cycle, CLHEP::HepRandom::getTheTableSeeds(), luxury, CLHEP::anonymous_namespace{Ranlux64Engine.cc}::maxIndex, CLHEP::anonymous_namespace{Ranlux64Engine.cc}::numberOfEngines(), and setSeeds().

◆ Ranlux64Engine() [3/4]

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

Definition at line 127 of file Ranlux64Engine.cc.

129{
130 luxury = lux;
131 long seedlist[2]={seed,0};
132 setSeeds(seedlist, lux);
133 advance ( 2*lux + 1 ); // Discard some iterations to use a different
134 // point in the sequence.
135}
static constexpr double lux

References advance(), CLHEP::lux, luxury, and setSeeds().

◆ Ranlux64Engine() [4/4]

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

Definition at line 137 of file Ranlux64Engine.cc.

139{
140 luxury = lux;
141 int cycle = std::abs(int(rowIndex/maxIndex));
142 int row = std::abs(int(rowIndex%maxIndex));
143 long mask = (( cycle & 0x000007ff ) << 20 );
144 long seedlist[2];
145 HepRandom::getTheTableSeeds( seedlist, row );
146 seedlist[0] ^= mask;
147 seedlist[1]= 0;
148 setSeeds(seedlist, lux);
149}

References geant4_check_module_cycles::cycle, CLHEP::HepRandom::getTheTableSeeds(), CLHEP::lux, luxury, CLHEP::anonymous_namespace{Ranlux64Engine.cc}::maxIndex, and setSeeds().

◆ ~Ranlux64Engine()

CLHEP::Ranlux64Engine::~Ranlux64Engine ( )
virtual

Definition at line 157 of file Ranlux64Engine.cc.

157{}

Member Function Documentation

◆ advance()

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

Definition at line 259 of file Ranlux64Engine.cc.

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

References carry, randoms, CLHEP::HepRandomEngine::twoToMinus_48(), and anonymous_namespace{G4CascadeDeexciteBase.cc}::zero.

Referenced by Ranlux64Engine(), and update().

◆ beginTag()

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

Definition at line 642 of file Ranlux64Engine.cc.

642 {
643 return "Ranlux64Engine-begin";
644}

◆ checkFile()

bool CLHEP::HepRandomEngine::checkFile ( std::istream &  file,
const std::string &  filename,
const std::string &  classname,
const std::string &  methodname 
)
staticprotectedinherited

Definition at line 47 of file RandomEngine.cc.

50 {
51 if (!file) {
52 std::cerr << "Failure to find or open file " << filename <<
53 " in " << classname << "::" << methodname << "()\n";
54 return false;
55 }
56 return true;
57}

References geant4_check_module_cycles::file.

Referenced by CLHEP::DualRand::restoreStatus(), CLHEP::HepJamesRandom::restoreStatus(), CLHEP::MTwistEngine::restoreStatus(), CLHEP::RanecuEngine::restoreStatus(), CLHEP::RanluxEngine::restoreStatus(), restoreStatus(), and CLHEP::RanshiEngine::restoreStatus().

◆ engineName()

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

Definition at line 91 of file Ranlux64Engine.h.

91{return "Ranlux64Engine";}

Referenced by restoreStatus().

◆ exponent_bit_32()

static double CLHEP::HepRandomEngine::exponent_bit_32 ( )
inlinestaticprotectedinherited

◆ flat()

double CLHEP::Ranlux64Engine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 159 of file Ranlux64Engine.cc.

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

References index, randoms, CLHEP::HepRandomEngine::twoToMinus_49(), and update().

Referenced by flatArray().

◆ flatArray()

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

Implements CLHEP::HepRandomEngine.

Definition at line 376 of file Ranlux64Engine.cc.

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

References flat().

◆ get() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 688 of file Ranlux64Engine.cc.

688 {
689 if ((v[0] & 0xffffffffUL) != engineIDulong<Ranlux64Engine>()) {
690 std::cerr <<
691 "\nRanlux64Engine get:state vector has wrong ID word - state unchanged\n";
692 return false;
693 }
694 return getState(v);
695}
virtual std::istream & getState(std::istream &is)

References getState().

◆ get() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 624 of file Ranlux64Engine.cc.

625{
626 char beginMarker [MarkerLen];
627 is >> std::ws;
628 is.width(MarkerLen); // causes the next read to the char* to be <=
629 // that many bytes, INCLUDING A TERMINATION \0
630 // (Stroustrup, section 21.3.2)
631 is >> beginMarker;
632 if (strcmp(beginMarker,"Ranlux64Engine-begin")) {
633 is.clear(std::ios::badbit | is.rdstate());
634 std::cerr << "\nInput stream mispositioned or"
635 << "\nRanlux64Engine state description missing or"
636 << "\nwrong engine type found." << std::endl;
637 return is;
638 }
639 return getState(is);
640}
static const int MarkerLen
Definition: DualRand.cc:70

References getState(), and CLHEP::MarkerLen.

◆ getLuxury()

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

Definition at line 82 of file Ranlux64Engine.h.

82{ return luxury; }

References luxury.

Referenced by G4WorkerRunManager::G4WorkerRunManager(), and G4UserWorkerThreadInitialization::SetupRNGEngine().

◆ getSeed()

long CLHEP::HepRandomEngine::getSeed ( ) const
inlineinherited

Definition at line 112 of file RandomEngine.h.

112{ return theSeed; }

References CLHEP::HepRandomEngine::theSeed.

◆ getSeeds()

const long * CLHEP::HepRandomEngine::getSeeds ( ) const
inlineinherited

Definition at line 115 of file RandomEngine.h.

115{ return theSeeds; }

References CLHEP::HepRandomEngine::theSeeds.

◆ getState() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 697 of file Ranlux64Engine.cc.

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

References carry, index, CLHEP::DoubConv::longs2double(), luxury, pDiscard, randoms, and VECTOR_STATE_SIZE.

◆ getState() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 646 of file Ranlux64Engine.cc.

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

References carry, endIters, getState(), index, luxury, CLHEP::MarkerLen, pDiscard, pDozens, CLHEP::possibleKeywordInput(), randoms, CLHEP::HepRandomEngine::theSeed, and VECTOR_STATE_SIZE.

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

◆ mantissa_bit_12()

static double CLHEP::HepRandomEngine::mantissa_bit_12 ( )
inlinestaticprotectedinherited

◆ mantissa_bit_24()

static double CLHEP::HepRandomEngine::mantissa_bit_24 ( )
inlinestaticprotectedinherited

◆ mantissa_bit_32()

static double CLHEP::HepRandomEngine::mantissa_bit_32 ( )
inlinestaticprotectedinherited

◆ name()

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

◆ nearlyTwoToMinus_54()

static double CLHEP::HepRandomEngine::nearlyTwoToMinus_54 ( )
inlinestaticprotectedinherited

◆ newEngine() [1/2]

HepRandomEngine * CLHEP::HepRandomEngine::newEngine ( const std::vector< unsigned long > &  v)
staticinherited

Definition at line 96 of file RandomEngine.cc.

96 {
98}
static HepRandomEngine * newEngine(std::istream &is)

References CLHEP::EngineFactory::newEngine().

◆ newEngine() [2/2]

HepRandomEngine * CLHEP::HepRandomEngine::newEngine ( std::istream &  is)
staticinherited

Definition at line 91 of file RandomEngine.cc.

91 {
92 return EngineFactory::newEngine(is);
93}

References CLHEP::EngineFactory::newEngine().

Referenced by CLHEP::StaticRandomStates::restore().

◆ operator double()

CLHEP::HepRandomEngine::operator double ( )
virtualinherited

◆ operator float()

CLHEP::HepRandomEngine::operator float ( )
virtualinherited

◆ operator unsigned int()

CLHEP::HepRandomEngine::operator unsigned int ( )
virtualinherited

◆ operator!=()

bool CLHEP::HepRandomEngine::operator!= ( const HepRandomEngine engine)
inlineinherited

◆ operator==()

bool CLHEP::HepRandomEngine::operator== ( const HepRandomEngine engine)
inlineinherited

◆ put() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 608 of file Ranlux64Engine.cc.

608 {
609 std::vector<unsigned long> v;
610 v.push_back (engineIDulong<Ranlux64Engine>());
611 std::vector<unsigned long> t;
612 for (int i=0; i<12; ++i) {
614 v.push_back(t[0]); v.push_back(t[1]);
615 }
617 v.push_back(t[0]); v.push_back(t[1]);
618 v.push_back(static_cast<unsigned long>(index));
619 v.push_back(static_cast<unsigned long>(luxury));
620 v.push_back(static_cast<unsigned long>(pDiscard));
621 return v;
622}
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:94

References carry, CLHEP::DoubConv::dto2longs(), index, luxury, pDiscard, and randoms.

Referenced by put(), and saveStatus().

◆ put() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 597 of file Ranlux64Engine.cc.

598{
599 char beginMarker[] = "Ranlux64Engine-begin";
600 os << beginMarker << "\nUvec\n";
601 std::vector<unsigned long> v = put();
602 for (unsigned int i=0; i<v.size(); ++i) {
603 os << v[i] << "\n";
604 }
605 return os;
606}
std::vector< unsigned long > put() const

References put().

◆ restoreStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 544 of file Ranlux64Engine.cc.

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

References carry, CLHEP::HepRandomEngine::checkFile(), endIters, engineName(), getState(), index, luxury, pDiscard, pDozens, CLHEP::possibleKeywordInput(), randoms, CLHEP::HepRandomEngine::theSeed, and VECTOR_STATE_SIZE.

◆ saveStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 532 of file Ranlux64Engine.cc.

533{
534 std::ofstream outFile( filename, std::ios::out ) ;
535 if (!outFile.bad()) {
536 outFile << "Uvec\n";
537 std::vector<unsigned long> v = put();
538 for (unsigned int i=0; i<v.size(); ++i) {
539 outFile << v[i] << "\n";
540 }
541 }
542}

References put().

◆ setSeed()

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

Implements CLHEP::HepRandomEngine.

Definition at line 382 of file Ranlux64Engine.cc.

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

References carry, endIters, index, CLHEP::lux, luxury, pDiscard, pDozens, randoms, CLHEP::HepRandomEngine::theSeed, CLHEP::HepRandomEngine::twoToMinus_32(), and CLHEP::HepRandomEngine::twoToMinus_48().

Referenced by setSeeds().

◆ setSeeds()

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

Implements CLHEP::HepRandomEngine.

Definition at line 458 of file Ranlux64Engine.cc.

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

References carry, endIters, index, CLHEP::lux, luxury, pDiscard, pDozens, randoms, setSeed(), CLHEP::HepRandomEngine::theSeed, CLHEP::HepRandomEngine::theSeeds, CLHEP::HepRandomEngine::twoToMinus_32(), and CLHEP::HepRandomEngine::twoToMinus_48().

Referenced by Ranlux64Engine().

◆ showStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 581 of file Ranlux64Engine.cc.

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

References carry, index, luxury, pDiscard, randoms, and CLHEP::HepRandomEngine::theSeed.

◆ twoToMinus_32()

static double CLHEP::HepRandomEngine::twoToMinus_32 ( )
inlinestaticprotectedinherited

◆ twoToMinus_48()

static double CLHEP::HepRandomEngine::twoToMinus_48 ( )
inlinestaticprotectedinherited

Referenced by advance(), setSeed(), setSeeds(), and update().

◆ twoToMinus_49()

static double CLHEP::HepRandomEngine::twoToMinus_49 ( )
inlinestaticprotectedinherited

Referenced by flat().

◆ twoToMinus_53()

static double CLHEP::HepRandomEngine::twoToMinus_53 ( )
inlinestaticprotectedinherited

◆ update()

void CLHEP::Ranlux64Engine::update ( )
private

Definition at line 169 of file Ranlux64Engine.cc.

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

References advance(), carry, endIters, index, CLHEP::m, CLHEP::ns, pDozens, randoms, and CLHEP::HepRandomEngine::twoToMinus_48().

Referenced by flat().

Field Documentation

◆ carry

double CLHEP::Ranlux64Engine::carry
private

Definition at line 111 of file Ranlux64Engine.h.

Referenced by advance(), getState(), put(), restoreStatus(), setSeed(), setSeeds(), showStatus(), and update().

◆ endIters

int CLHEP::Ranlux64Engine::endIters
private

Definition at line 106 of file Ranlux64Engine.h.

Referenced by getState(), restoreStatus(), setSeed(), setSeeds(), and update().

◆ index

int CLHEP::Ranlux64Engine::index
private

Definition at line 109 of file Ranlux64Engine.h.

Referenced by flat(), getState(), put(), restoreStatus(), setSeed(), setSeeds(), showStatus(), and update().

◆ luxury

int CLHEP::Ranlux64Engine::luxury
private

◆ pDiscard

int CLHEP::Ranlux64Engine::pDiscard
private

Definition at line 104 of file Ranlux64Engine.h.

Referenced by getState(), put(), restoreStatus(), setSeed(), setSeeds(), and showStatus().

◆ pDozens

int CLHEP::Ranlux64Engine::pDozens
private

Definition at line 105 of file Ranlux64Engine.h.

Referenced by getState(), restoreStatus(), setSeed(), setSeeds(), and update().

◆ randoms

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

◆ theSeed

long CLHEP::HepRandomEngine::theSeed
protectedinherited

Definition at line 142 of file RandomEngine.h.

Referenced by CLHEP::DualRand::DualRand(), CLHEP::HepRandomEngine::getSeed(), CLHEP::DualRand::getState(), CLHEP::HepJamesRandom::getState(), CLHEP::MixMaxRng::getState(), CLHEP::MTwistEngine::getState(), CLHEP::RanecuEngine::getState(), getState(), CLHEP::RanluxEngine::getState(), CLHEP::RanshiEngine::getState(), CLHEP::HepJamesRandom::HepJamesRandom(), CLHEP::MixMaxRng::MixMaxRng(), CLHEP::RanecuEngine::put(), CLHEP::MixMaxRng::put(), CLHEP::MTwistEngine::put(), CLHEP::RanecuEngine::RanecuEngine(), CLHEP::RanluxEngine::RanluxEngine(), CLHEP::RanluxppEngine::RanluxppEngine(), CLHEP::RanshiEngine::RanshiEngine(), CLHEP::DualRand::restoreStatus(), CLHEP::HepJamesRandom::restoreStatus(), CLHEP::MTwistEngine::restoreStatus(), CLHEP::RanecuEngine::restoreStatus(), CLHEP::RanluxEngine::restoreStatus(), restoreStatus(), CLHEP::RanshiEngine::restoreStatus(), CLHEP::MTwistEngine::saveStatus(), CLHEP::RanecuEngine::setIndex(), CLHEP::RanecuEngine::setSeed(), CLHEP::HepJamesRandom::setSeed(), CLHEP::MixMaxRng::setSeed(), CLHEP::RanluxppEngine::setSeed(), setSeed(), CLHEP::RanluxEngine::setSeed(), CLHEP::DualRand::setSeed(), CLHEP::MTwistEngine::setSeed(), CLHEP::RanecuEngine::setSeeds(), setSeeds(), CLHEP::RanluxEngine::setSeeds(), CLHEP::MixMaxRng::setSeeds(), CLHEP::RanshiEngine::setSeeds(), CLHEP::DualRand::showStatus(), CLHEP::HepJamesRandom::showStatus(), CLHEP::MTwistEngine::showStatus(), CLHEP::RanecuEngine::showStatus(), showStatus(), CLHEP::RanluxEngine::showStatus(), and CLHEP::RanshiEngine::showStatus().

◆ theSeeds

const long* CLHEP::HepRandomEngine::theSeeds
protectedinherited

◆ VECTOR_STATE_SIZE

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

Definition at line 97 of file Ranlux64Engine.h.

Referenced by getState(), and restoreStatus().


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