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