RandomGen.h
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \class genie::RandomGen
5 
6 \brief A singleton holding random number generator classes. All random
7  number generation in GENIE should take place through this class.
8  Ensures that the random number generator seed is set consistently
9  to all GENIE modules and that all modules use the preferred rndm
10  number generator.
11 
12 \author Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
13  University of Liverpool & STFC Rutherford Appleton Lab
14 
15 \created September 22, 2004
16 
17 \cpright Copyright (c) 2003-2019, The GENIE Collaboration
18  For the full text of the license visit http://copyright.genie-mc.org
19  or see $GENIE/LICENSE
20 */
21 //____________________________________________________________________________
22 
23 #ifndef _RANDOM_GEN_H_
24 #define _RANDOM_GEN_H_
25 
26 #include <TRandom3.h>
27 
28 namespace genie {
29 
30 class RandomGen {
31 
32 public:
33 
34  //! Access instance
35  static RandomGen * Instance();
36 
37  //! Random number generators used by various GENIE modules.
38  //! (See note at http://root.cern.ch/root/html//TRandom.html
39  //! on using several TRandom objects each with each own
40  //! "independent" run sequence).
41 
42  //! At this point, since the actual random number generator
43  //! periodicity is very high, all the generators are in fact one!
44  //! However, the option to use many generators is reserved.
45 
46  //! Currently, the preferred generator is the "Mersenne Twister"
47  //! with a periodicity of 10**6000
48  //! See: http://root.cern.ch/root/html/TRandom3.html
49 
50  //! rnd number generator used by kinematics generators
51  TRandom3 & RndKine (void) const { return *fRandom3; }
52 
53  //! rnd number generator used by hadronization models
54  TRandom3 & RndHadro (void) const { return *fRandom3; }
55 
56  //! rnd number generator used by decay models
57  TRandom3 & RndDec (void) const { return *fRandom3; }
58 
59  //! rnd number generator used by intranuclear cascade monte carlos
60  TRandom3 & RndFsi (void) const { return *fRandom3; }
61 
62  //! rnd number generator used by final state primary lepton generators
63  TRandom3 & RndLep (void) const { return *fRandom3; }
64 
65  //! rnd number generator used by interaction selectors
66  TRandom3 & RndISel (void) const { return *fRandom3; }
67 
68  //! rnd number generator used by geometry drivers
69  TRandom3 & RndGeom (void) const { return *fRandom3; }
70 
71  //! rnd number generator used by flux drivers
72  TRandom3 & RndFlux (void) const { return *fRandom3; }
73 
74  //! rnd number generator used by the event generation drivers
75  TRandom3 & RndEvg (void) const { return *fRandom3; }
76 
77  //! rnd number generator used by MC integrators & other numerical methods
78  TRandom3 & RndNum (void) const { return *fRandom3; }
79 
80  //! rnd number generator for generic usage
81  TRandom3 & RndGen (void) const { return *fRandom3; }
82 
83  long int GetSeed (void) const { return fCurrSeed; }
84  void SetSeed (long int seed);
85 
86 private:
87 
88  RandomGen();
89  RandomGen(const RandomGen & rgen);
90  virtual ~RandomGen();
91 
92  static RandomGen * fInstance;
93 
94  TRandom3 * fRandom3; ///< Mersenne Twistor
95  long int fCurrSeed; ///< random number generator seed number
96  bool fInitalized; ///< done initializing singleton?
97 
98  void InitRandomGenerators(long int seed);
99 
100  struct Cleaner {
103  if (RandomGen::fInstance !=0) {
104  delete RandomGen::fInstance;
106  }
107  }
108  };
109 
110  friend struct Cleaner;
111 };
112 
113 } // genie namespace
114 
115 #endif // _RANDOM_GEN_H_
bool fInitalized
done initializing singleton?
Definition: RandomGen.h:96
TRandom3 & RndFsi(void) const
rnd number generator used by intranuclear cascade monte carlos
Definition: RandomGen.h:60
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
TRandom3 & RndLep(void) const
rnd number generator used by final state primary lepton generators
Definition: RandomGen.h:63
static RandomGen * Instance()
Access instance.
Definition: RandomGen.cxx:79
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:30
long int fCurrSeed
random number generator seed number
Definition: RandomGen.h:95
TRandom3 * fRandom3
Mersenne Twistor.
Definition: RandomGen.h:94
unsigned int seed
Definition: runWimpSim.h:102
static RandomGen * fInstance
Definition: RandomGen.h:92
long int GetSeed(void) const
Definition: RandomGen.h:83
TRandom3 & RndEvg(void) const
rnd number generator used by the event generation drivers
Definition: RandomGen.h:75
TRandom3 & RndGeom(void) const
rnd number generator used by geometry drivers
Definition: RandomGen.h:69
TRandom3 & RndKine(void) const
rnd number generator used by kinematics generators
Definition: RandomGen.h:51
TRandom3 & RndNum(void) const
rnd number generator used by MC integrators & other numerical methods
Definition: RandomGen.h:78
TRandom3 & RndHadro(void) const
rnd number generator used by hadronization models
Definition: RandomGen.h:54
void InitRandomGenerators(long int seed)
Definition: RandomGen.cxx:134
void DummyMethodAndSilentCompiler()
Definition: RandomGen.h:101
TRandom3 & RndGen(void) const
rnd number generator for generic usage
Definition: RandomGen.h:81
virtual ~RandomGen()
Definition: RandomGen.cxx:73
TRandom3 & RndISel(void) const
rnd number generator used by interaction selectors
Definition: RandomGen.h:66
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
Definition: RandomGen.h:72
TRandom3 & RndDec(void) const
rnd number generator used by decay models
Definition: RandomGen.h:57
void SetSeed(long int seed)
Definition: RandomGen.cxx:90