ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Random.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Random.h
1 // -*- C++ -*-
2 //
3 // -----------------------------------------------------------------------
4 // HEP Random
5 // --- HepRandom ---
6 // class header file
7 // -----------------------------------------------------------------------
8 // This file is part of Geant4 (simulation toolkit for HEP).
9 //
10 // It's a singleton instantiated by default within the HEP Random module.
11 // It uses an instantiated HepJamesRandom engine as default algorithm
12 // for pseudo-random number generation. HepRandom defines a static private
13 // data member theGenerator and a set of static inlined methods to manipulate
14 // it. By means of theGenerator the user can change the underlying engine
15 // algorithm, get and set the seeds and use any kind of defined random
16 // distribution.
17 // Distribution classes inherit from HepRandom and define both static and
18 // not-static interfaces.
19 // A static table of uncorrelated seeds is available in this class.
20 // A static method "getTheTableSeeds()" is defined to access a couple of
21 // seeds at a given index in the table.
22 
23 // =======================================================================
24 // Gabriele Cosmo - Created: 5th Sep 1995
25 // - Minor update: 17th May 1996
26 // - Poisson now operates on doubles : 31st Oct 1996
27 // - Added methods for engine status: 19th Nov 1996
28 // - Fixed default values to setTheSeed() and
29 // setTheSeeds() static methods: 16th Oct 1997
30 // - Modified HepRandom to act as a singleton, constructors
31 // are kept public for backward compatibility. Added table
32 // of seeds from HepRandomEngine: 19th Mar 1998
33 // - Relocated Poisson and Gauss data and simplified
34 // initialisation of static generator: 5th Jan 1999
35 // =======================================================================
36 
37 #ifndef HepRandom_h
38 #define HepRandom_h 1
39 
41 
42 namespace CLHEP {
43 
48 class HepRandom {
49 
50 public:
51 
52  HepRandom();
53  HepRandom(long seed);
54  // Contructors with and without a seed using the default engine
55  // (MixMax).
56 
58  HepRandom(HepRandomEngine * algorithm);
59  // Constructor taking an alternative engine as argument. If a pointer is
60  // given the corresponding object will be deleted by the HepRandom
61  // destructor.
62 
63  virtual ~HepRandom();
64  // Destructor
65 
66  // implicitly allow compiler-generated copy functions
67 
68  double flat();
69  // Returns the flat value ( interval ]0...1[ ).
70 
71  void flatArray(const int size, double* vect);
72  // Fills "vect" array of flat random values, given the size.
73 
74  inline double flat (HepRandomEngine* theNewEngine);
75  // Returns a flat value, given a defined Random Engine.
76 
77  inline void flatArray(HepRandomEngine* theNewEngine,
78  const int size, double* vect);
79  // Fills "vect" array of flat random values, given the size
80  // and a defined Random Engine.
81 
82  virtual double operator()();
83  // To get a flat random number using the operator ().
84 
85  virtual std::string name() const;
86  virtual HepRandomEngine & engine();
87 
88 
89  virtual std::ostream & put ( std::ostream & os ) const;
90  virtual std::istream & get ( std::istream & is );
91  // Save and restore to/from streams
92 
93  // --------------------------------------------------
94  // Static member functions using the static generator
95  // --------------------------------------------------
96 
97  static void setTheSeed(long seed, int lux=3);
98  // (Re)Initializes the generator with a seed.
99 
100  static long getTheSeed();
101  // Gets the current seed of the current generator.
102 
103  static void setTheSeeds(const long* seeds, int aux=-1);
104  // (Re)Initializes the generator with a zero terminated list of seeds.
105 
106  static const long* getTheSeeds();
107  // Gets the current array of seeds of the current generator.
108 
109  static void getTheTableSeeds (long* seeds, int index);
110  // Gets the array of seeds in the static seedTable at "index" position.
111 
112  static HepRandom * getTheGenerator();
113  // Return the current static generator.
114 
115  static void setTheEngine (HepRandomEngine* theNewEngine);
116  // To set the underlying algorithm object.
117 
118  static HepRandomEngine * getTheEngine();
119  // Returns a pointer to the underlying algorithm object.
120 
121  static void saveEngineStatus( const char filename[] = "Config.conf" );
122  // Saves to file the current status of the current engine.
123 
124  static void restoreEngineStatus( const char filename[] = "Config.conf" );
125  // Restores a saved status (if any) for the current engine.
126 
127  static std::ostream& saveFullState ( std::ostream & os );
128  // Saves to stream the state of the engine and cached data.
129 
130  static std::istream& restoreFullState ( std::istream & is );
131  // Restores from stream the state of the engine and cached data.
132 
133  static std::ostream& saveDistState ( std::ostream & os ) {return os;}
134  // Saves to stream the state of the cached data.
135 
136  static std::istream& restoreDistState ( std::istream & is ) {return is;}
137  // Restores from stream the state of the cached data.
138 
139  static std::ostream& saveStaticRandomStates ( std::ostream & os );
140  // Saves to stream the engine and cached data for all distributions.
141 
142  static std::istream& restoreStaticRandomStates ( std::istream & is );
143  // Restores from stream the engine and cached data for all distributions.
144 
145  static void showEngineStatus();
146  // Dumps the current engine status on screen.
147 
148  static int createInstance();
149  // used to initialise the default engine
150 
151  static std::string distributionName() {return "HepRandomEngine";}
152  // Provides the name of this distribution class
153 
154 protected: // -------- Data members ---------
155 
156  static const long seedTable[215][2];
157  // Table of seeds
158 
159 };
160 
161 std::ostream & operator<< (std::ostream & os, const HepRandom & dist);
162 std::istream & operator>> (std::istream & is, HepRandom & dist);
163 
164 } // namespace CLHEP
165 
166 #include "CLHEP/Random/Random.icc"
167 
168 #endif