Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
genie::RandomGen Class Reference

A singleton holding random number generator classes. All random number generation in GENIE should take place through this class. Ensures that the random number generator seed is set consistently to all GENIE modules and that all modules use the preferred rndm number generator. More...

#include <RandomGen.h>

Classes

struct  Cleaner
 

Public Member Functions

TRandom3 & RndKine (void) const
 rnd number generator used by kinematics generators More...
 
TRandom3 & RndHadro (void) const
 rnd number generator used by hadronization models More...
 
TRandom3 & RndDec (void) const
 rnd number generator used by decay models More...
 
TRandom3 & RndFsi (void) const
 rnd number generator used by intranuclear cascade monte carlos More...
 
TRandom3 & RndLep (void) const
 rnd number generator used by final state primary lepton generators More...
 
TRandom3 & RndISel (void) const
 rnd number generator used by interaction selectors More...
 
TRandom3 & RndGeom (void) const
 rnd number generator used by geometry drivers More...
 
TRandom3 & RndFlux (void) const
 rnd number generator used by flux drivers More...
 
TRandom3 & RndEvg (void) const
 rnd number generator used by the event generation drivers More...
 
TRandom3 & RndNum (void) const
 rnd number generator used by MC integrators & other numerical methods More...
 
TRandom3 & RndGen (void) const
 rnd number generator for generic usage More...
 
long int GetSeed (void) const
 
void SetSeed (long int seed)
 

Static Public Member Functions

static RandomGenInstance ()
 Access instance. More...
 

Private Member Functions

 RandomGen ()
 
 RandomGen (const RandomGen &rgen)
 
virtual ~RandomGen ()
 
void InitRandomGenerators (long int seed)
 

Private Attributes

TRandom3 * fRandom3
 Mersenne Twistor. More...
 
long int fCurrSeed
 random number generator seed number More...
 
bool fInitalized
 done initializing singleton? More...
 

Static Private Attributes

static RandomGenfInstance = 0
 

Friends

struct Cleaner
 

Detailed Description

A singleton holding random number generator classes. All random number generation in GENIE should take place through this class. Ensures that the random number generator seed is set consistently to all GENIE modules and that all modules use the preferred rndm number generator.

Author
Costas Andreopoulos <constantinos.andreopoulos cern.ch> University of Liverpool & STFC Rutherford Appleton Laboratory

September 22, 2004

Copyright (c) 2003-2020, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 29 of file RandomGen.h.

Constructor & Destructor Documentation

genie::RandomGen::RandomGen ( )
private

Definition at line 27 of file RandomGen.cxx.

28 {
29  LOG("Rndm", pINFO) << "RandomGen late initialization";
30 
31  fInitalized = false;
32  fInstance = 0;
33 /*
34  // try to get this job's random number seed from the environment
35  const char * seed = gSystem->Getenv("GSEED");
36  if(seed) {
37  LOG("Rndm", pDEBUG) << "Reading RandomNumGenerator seed env. var $GSEED";
38  fCurrSeed = atoi(seed);
39  } else {
40  LOG("Rndm", pINFO) << "Env. var. $GSEED is not set. Using default seed";
41  fCurrSeed = kDefaultRandSeed; // default seed number
42  }
43  this->InitRandomGenerators(fCurrSeed);
44 */
45 
46  if ( gSystem->Getenv("GSEED") ) {
47  LOG("Rndm", pFATAL)
48  << "\n\n"
49  << "************************************************************************************** \n"
50  << "The random number seed is no longer set via the $GSEED variable.\n"
51  << "Please use the --seed option implemented in all GENIE apps or, if you access RandomGen \n"
52  << "directly in your user code, use RandomGen::SetSeed(long int seed).\n"
53  << "Unset $GSEED to continue running GENIE. \n"
54  << "************************************************************************************** \n";
55  gAbortingInErr = true;
56  exit(1);
57  }
58 
59  fCurrSeed = kDefaultRandSeed; // a default seed number is set a init
61 
62  fInitalized = true;
63 }
bool fInitalized
done initializing singleton?
Definition: RandomGen.h:95
static const unsigned int kDefaultRandSeed
Definition: Controls.h:37
#define pFATAL
Definition: Messenger.h:56
long int fCurrSeed
random number generator seed number
Definition: RandomGen.h:94
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static RandomGen * fInstance
Definition: RandomGen.h:91
#define pINFO
Definition: Messenger.h:62
void InitRandomGenerators(long int seed)
Definition: RandomGen.cxx:126
bool gAbortingInErr
Definition: Messenger.cxx:34
genie::RandomGen::RandomGen ( const RandomGen rgen)
private
genie::RandomGen::~RandomGen ( )
privatevirtual

Definition at line 65 of file RandomGen.cxx.

66 {
67  fInstance = 0;
68  if(fRandom3) delete fRandom3;
69 }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
static RandomGen * fInstance
Definition: RandomGen.h:91

Member Function Documentation

long int genie::RandomGen::GetSeed ( void  ) const
inline

Definition at line 82 of file RandomGen.h.

82 { return fCurrSeed; }
long int fCurrSeed
random number generator seed number
Definition: RandomGen.h:94
void genie::RandomGen::InitRandomGenerators ( long int  seed)
private

Definition at line 126 of file RandomGen.cxx.

127 {
128  fRandom3 = new TRandom3();
129  this->SetSeed(seed);
130 }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
void SetSeed(long int seed)
Definition: RandomGen.cxx:82
RandomGen * genie::RandomGen::Instance ( void  )
static

Access instance.

Definition at line 71 of file RandomGen.cxx.

72 {
73  if(fInstance == 0) {
74  static RandomGen::Cleaner cleaner;
75  cleaner.DummyMethodAndSilentCompiler();
76 
77  fInstance = new RandomGen;
78  }
79  return fInstance;
80 }
friend struct Cleaner
Definition: RandomGen.h:109
static RandomGen * fInstance
Definition: RandomGen.h:91
TRandom3& genie::RandomGen::RndDec ( void  ) const
inline

rnd number generator used by decay models

Definition at line 56 of file RandomGen.h.

56 { return *fRandom3; }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
TRandom3& genie::RandomGen::RndEvg ( void  ) const
inline

rnd number generator used by the event generation drivers

Definition at line 74 of file RandomGen.h.

74 { return *fRandom3; }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
TRandom3& genie::RandomGen::RndFlux ( void  ) const
inline

rnd number generator used by flux drivers

Definition at line 71 of file RandomGen.h.

71 { return *fRandom3; }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
TRandom3& genie::RandomGen::RndFsi ( void  ) const
inline

rnd number generator used by intranuclear cascade monte carlos

Definition at line 59 of file RandomGen.h.

59 { return *fRandom3; }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
TRandom3& genie::RandomGen::RndGen ( void  ) const
inline

rnd number generator for generic usage

Definition at line 80 of file RandomGen.h.

80 { return *fRandom3; }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
TRandom3& genie::RandomGen::RndGeom ( void  ) const
inline

rnd number generator used by geometry drivers

Definition at line 68 of file RandomGen.h.

68 { return *fRandom3; }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
TRandom3& genie::RandomGen::RndHadro ( void  ) const
inline

rnd number generator used by hadronization models

Definition at line 53 of file RandomGen.h.

53 { return *fRandom3; }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
TRandom3& genie::RandomGen::RndISel ( void  ) const
inline

rnd number generator used by interaction selectors

Definition at line 65 of file RandomGen.h.

65 { return *fRandom3; }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
TRandom3& genie::RandomGen::RndKine ( void  ) const
inline

rnd number generator used by kinematics generators

Random number generators used by various GENIE modules. (See note at http://root.cern.ch/root/html//TRandom.html on using several TRandom objects each with each own "independent" run sequence). At this point, since the actual random number generator periodicity is very high, all the generators are in fact one! However, the option to use many generators is reserved. Currently, the preferred generator is the "Mersenne Twister" with a periodicity of 10**6000 See: http://root.cern.ch/root/html/TRandom3.html

Definition at line 50 of file RandomGen.h.

50 { return *fRandom3; }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
TRandom3& genie::RandomGen::RndLep ( void  ) const
inline

rnd number generator used by final state primary lepton generators

Definition at line 62 of file RandomGen.h.

62 { return *fRandom3; }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
TRandom3& genie::RandomGen::RndNum ( void  ) const
inline

rnd number generator used by MC integrators & other numerical methods

Definition at line 77 of file RandomGen.h.

77 { return *fRandom3; }
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:93
void genie::RandomGen::SetSeed ( long int  seed)

Definition at line 82 of file RandomGen.cxx.

83 {
84  LOG("Rndm", pNOTICE)
85  << "Setting"
86  << ((fInitalized) ? " " : " default ")
87  << "random number seed"
88  << ((fInitalized) ? ": " : " at random number generator initialization: ")
89  << seed;
90 
91  // Set the seed number for all internal GENIE random number generators
92  this->RndKine ().SetSeed(seed);
93  this->RndHadro().SetSeed(seed);
94  this->RndDec ().SetSeed(seed);
95  this->RndFsi ().SetSeed(seed);
96  this->RndLep ().SetSeed(seed);
97  this->RndISel ().SetSeed(seed);
98  this->RndGeom ().SetSeed(seed);
99  this->RndFlux ().SetSeed(seed);
100  this->RndEvg ().SetSeed(seed);
101  this->RndNum ().SetSeed(seed);
102  this->RndGen ().SetSeed(seed);
103 
104  // Set the seed number for ROOT's gRandom
105  gRandom ->SetSeed (seed);
106 
107  // Set the PYTHIA6 seed number
108  TPythia6 * pythia6 = TPythia6::Instance();
109  pythia6->SetMRPY(1, seed);
110 
111  LOG("Rndm", pINFO) << "RndKine seed = " << this->RndKine ().GetSeed();
112  LOG("Rndm", pINFO) << "RndHadro seed = " << this->RndHadro().GetSeed();
113  LOG("Rndm", pINFO) << "RndDec seed = " << this->RndDec ().GetSeed();
114  LOG("Rndm", pINFO) << "RndFsi seed = " << this->RndFsi ().GetSeed();
115  LOG("Rndm", pINFO) << "RndLep seed = " << this->RndLep ().GetSeed();
116  LOG("Rndm", pINFO) << "RndISel seed = " << this->RndISel ().GetSeed();
117  LOG("Rndm", pINFO) << "RndGeom seed = " << this->RndGeom ().GetSeed();
118  LOG("Rndm", pINFO) << "RndFlux seed = " << this->RndFlux ().GetSeed();
119  LOG("Rndm", pINFO) << "RndEvg seed = " << this->RndEvg ().GetSeed();
120  LOG("Rndm", pINFO) << "RndNum seed = " << this->RndNum ().GetSeed();
121  LOG("Rndm", pINFO) << "RndGen seed = " << this->RndGen ().GetSeed();
122  LOG("Rndm", pINFO) << "gRandom seed = " << gRandom->GetSeed();
123  LOG("Rndm", pINFO) << "PYTHIA6 seed = " << pythia6->GetMRPY(1);
124 }
bool fInitalized
done initializing singleton?
Definition: RandomGen.h:95
TRandom3 & RndFsi(void) const
rnd number generator used by intranuclear cascade monte carlos
Definition: RandomGen.h:59
TRandom3 & RndLep(void) const
rnd number generator used by final state primary lepton generators
Definition: RandomGen.h:62
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
TRandom3 & RndEvg(void) const
rnd number generator used by the event generation drivers
Definition: RandomGen.h:74
#define pINFO
Definition: Messenger.h:62
TRandom3 & RndGeom(void) const
rnd number generator used by geometry drivers
Definition: RandomGen.h:68
TRandom3 & RndKine(void) const
rnd number generator used by kinematics generators
Definition: RandomGen.h:50
TRandom3 & RndNum(void) const
rnd number generator used by MC integrators & other numerical methods
Definition: RandomGen.h:77
TRandom3 & RndHadro(void) const
rnd number generator used by hadronization models
Definition: RandomGen.h:53
TRandom3 & RndGen(void) const
rnd number generator for generic usage
Definition: RandomGen.h:80
TRandom3 & RndISel(void) const
rnd number generator used by interaction selectors
Definition: RandomGen.h:65
#define pNOTICE
Definition: Messenger.h:61
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition: RandomGen.h:71
TRandom3 & RndDec(void) const
rnd number generator used by decay models
Definition: RandomGen.h:56

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 109 of file RandomGen.h.

Member Data Documentation

long int genie::RandomGen::fCurrSeed
private

random number generator seed number

Definition at line 94 of file RandomGen.h.

bool genie::RandomGen::fInitalized
private

done initializing singleton?

Definition at line 95 of file RandomGen.h.

RandomGen * genie::RandomGen::fInstance = 0
staticprivate

Definition at line 91 of file RandomGen.h.

TRandom3* genie::RandomGen::fRandom3
private

Mersenne Twistor.

Definition at line 93 of file RandomGen.h.


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