GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RandomGen.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <c.andreopoulos \at cern.ch>
7  University of Liverpool
8 */
9 //____________________________________________________________________________
10 
11 #include <cstdlib>
12 
13 #include <TSystem.h>
14 #include <TPythia6.h>
15 
19 
20 using namespace genie::controls;
21 
22 namespace genie {
23 
24 //____________________________________________________________________________
25 RandomGen * RandomGen::fInstance = 0;
26 //____________________________________________________________________________
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
60  this->InitRandomGenerators(fCurrSeed);
61 
62  fInitalized = true;
63 }
64 //____________________________________________________________________________
66 {
67  fInstance = 0;
68  if(fRandom3) delete fRandom3;
69 }
70 //____________________________________________________________________________
72 {
73  if(fInstance == 0) {
74  static RandomGen::Cleaner cleaner;
76 
77  fInstance = new RandomGen;
78  }
79  return fInstance;
80 }
81 //____________________________________________________________________________
82 void RandomGen::SetSeed(long int seed)
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 }
125 //____________________________________________________________________________
127 {
128  fRandom3 = new TRandom3();
129  this->SetSeed(seed);
130 }
131 //____________________________________________________________________________
132 } // genie namespace
static const unsigned int kDefaultRandSeed
Definition: Controls.h:37
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:71
#define pFATAL
Definition: Messenger.h:56
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
#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
void DummyMethodAndSilentCompiler()
Definition: RandomGen.h:100
virtual ~RandomGen()
Definition: RandomGen.cxx:65
#define pNOTICE
Definition: Messenger.h:61
bool gAbortingInErr
Definition: Messenger.cxx:34
void SetSeed(long int seed)
Definition: RandomGen.cxx:82