RandomGen.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Author: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab
9 
10  For the class documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13  @ Jan 24, 2013 - CA
14  No longer uses the $GSEED variable for setting the random number seed.
15 
16 */
17 //____________________________________________________________________________
18 
19 #include <cstdlib>
20 
21 #include <TSystem.h>
22 #include <TPythia6.h>
23 
27 
28 using namespace genie::controls;
29 
30 namespace genie {
31 
32 //____________________________________________________________________________
33 RandomGen * RandomGen::fInstance = 0;
34 //____________________________________________________________________________
36 {
37  LOG("Rndm", pINFO) << "RandomGen late initialization";
38 
39  fInitalized = false;
40  fInstance = 0;
41 /*
42  // try to get this job's random number seed from the environment
43  const char * seed = gSystem->Getenv("GSEED");
44  if(seed) {
45  LOG("Rndm", pDEBUG) << "Reading RandomNumGenerator seed env. var $GSEED";
46  fCurrSeed = atoi(seed);
47  } else {
48  LOG("Rndm", pINFO) << "Env. var. $GSEED is not set. Using default seed";
49  fCurrSeed = kDefaultRandSeed; // default seed number
50  }
51  this->InitRandomGenerators(fCurrSeed);
52 */
53 
54  if ( gSystem->Getenv("GSEED") ) {
55  LOG("Rndm", pFATAL)
56  << "\n\n"
57  << "************************************************************************************** \n"
58  << "The random number seed is no longer set via the $GSEED variable.\n"
59  << "Please use the --seed option implemented in all GENIE apps or, if you access RandomGen \n"
60  << "directly in your user code, use RandomGen::SetSeed(long int seed).\n"
61  << "Unset $GSEED to continue running GENIE. \n"
62  << "************************************************************************************** \n";
63  gAbortingInErr = true;
64  exit(1);
65  }
66 
67  fCurrSeed = kDefaultRandSeed; // a default seed number is set a init
68  this->InitRandomGenerators(fCurrSeed);
69 
70  fInitalized = true;
71 }
72 //____________________________________________________________________________
74 {
75  fInstance = 0;
76  if(fRandom3) delete fRandom3;
77 }
78 //____________________________________________________________________________
80 {
81  if(fInstance == 0) {
82  static RandomGen::Cleaner cleaner;
84 
85  fInstance = new RandomGen;
86  }
87  return fInstance;
88 }
89 //____________________________________________________________________________
90 void RandomGen::SetSeed(long int seed)
91 {
92  LOG("Rndm", pNOTICE)
93  << "Setting"
94  << ((fInitalized) ? " " : " default ")
95  << "random number seed"
96  << ((fInitalized) ? ": " : " at random number generator initialization: ")
97  << seed;
98 
99  // Set the seed number for all internal GENIE random number generators
100  this->RndKine ().SetSeed(seed);
101  this->RndHadro().SetSeed(seed);
102  this->RndDec ().SetSeed(seed);
103  this->RndFsi ().SetSeed(seed);
104  this->RndLep ().SetSeed(seed);
105  this->RndISel ().SetSeed(seed);
106  this->RndGeom ().SetSeed(seed);
107  this->RndFlux ().SetSeed(seed);
108  this->RndEvg ().SetSeed(seed);
109  this->RndNum ().SetSeed(seed);
110  this->RndGen ().SetSeed(seed);
111 
112  // Set the seed number for ROOT's gRandom
113  gRandom ->SetSeed (seed);
114 
115  // Set the PYTHIA6 seed number
116  TPythia6 * pythia6 = TPythia6::Instance();
117  pythia6->SetMRPY(1, seed);
118 
119  LOG("Rndm", pINFO) << "RndKine seed = " << this->RndKine ().GetSeed();
120  LOG("Rndm", pINFO) << "RndHadro seed = " << this->RndHadro().GetSeed();
121  LOG("Rndm", pINFO) << "RndDec seed = " << this->RndDec ().GetSeed();
122  LOG("Rndm", pINFO) << "RndFsi seed = " << this->RndFsi ().GetSeed();
123  LOG("Rndm", pINFO) << "RndLep seed = " << this->RndLep ().GetSeed();
124  LOG("Rndm", pINFO) << "RndISel seed = " << this->RndISel ().GetSeed();
125  LOG("Rndm", pINFO) << "RndGeom seed = " << this->RndGeom ().GetSeed();
126  LOG("Rndm", pINFO) << "RndFlux seed = " << this->RndFlux ().GetSeed();
127  LOG("Rndm", pINFO) << "RndEvg seed = " << this->RndEvg ().GetSeed();
128  LOG("Rndm", pINFO) << "RndNum seed = " << this->RndNum ().GetSeed();
129  LOG("Rndm", pINFO) << "RndGen seed = " << this->RndGen ().GetSeed();
130  LOG("Rndm", pINFO) << "gRandom seed = " << gRandom->GetSeed();
131  LOG("Rndm", pINFO) << "PYTHIA6 seed = " << pythia6->GetMRPY(1);
132 }
133 //____________________________________________________________________________
135 {
136  fRandom3 = new TRandom3();
137  this->SetSeed(seed);
138 }
139 //____________________________________________________________________________
140 } // genie namespace
static const unsigned int kDefaultRandSeed
Definition: Controls.h:38
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:79
#define pFATAL
Definition: Messenger.h:57
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:30
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
unsigned int seed
Definition: runWimpSim.h:102
static RandomGen * fInstance
Definition: RandomGen.h:92
#define pINFO
Definition: Messenger.h:63
Misc GENIE control constants.
void InitRandomGenerators(long int seed)
Definition: RandomGen.cxx:134
void DummyMethodAndSilentCompiler()
Definition: RandomGen.h:101
exit(0)
virtual ~RandomGen()
Definition: RandomGen.cxx:73
#define pNOTICE
Definition: Messenger.h:62
bool gAbortingInErr
Definition: Messenger.cxx:56
void SetSeed(long int seed)
Definition: RandomGen.cxx:90