CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

RandomObjects/CLHEP/Random/Random.h
Go to the documentation of this file.
1 // $Id: Random.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- HepRandom ---
7 // class header file
8 // -----------------------------------------------------------------------
9 // This file is part of Geant4 (simulation toolkit for HEP).
10 //
11 // It's a singleton instantiated by default within the HEP Random module.
12 // It uses an instantiated HepJamesRandom engine as default algorithm
13 // for pseudo-random number generation. HepRandom defines a static private
14 // data member theGenerator and a set of static inlined methods to manipulate
15 // it. By means of theGenerator the user can change the underlying engine
16 // algorithm, get and set the seeds and use any kind of defined random
17 // distribution.
18 // Distribution classes inherit from HepRandom and define both static and
19 // not-static interfaces.
20 // A static table of uncorrelated seeds is available in this class.
21 // A static method "getTheTableSeeds()" is defined to access a couple of
22 // seeds at a given index in the table.
23 
24 // =======================================================================
25 // Gabriele Cosmo - Created: 5th Sep 1995
26 // - Minor update: 17th May 1996
27 // - Poisson now operates on doubles : 31st Oct 1996
28 // - Added methods for engine status: 19th Nov 1996
29 // - Fixed default values to setTheSeed() and
30 // setTheSeeds() static methods: 16th Oct 1997
31 // - Modified HepRandom to act as a singleton, constructors
32 // are kept public for backward compatibility. Added table
33 // of seeds from HepRandomEngine: 19th Mar 1998
34 // - Relocated Poisson and Gauss data and simplified
35 // initialisation of static generator: 5th Jan 1999
36 // =======================================================================
37 
38 #ifndef HepRandom_h
39 #define HepRandom_h 1
40 
41 #include "CLHEP/Random/defs.h"
42 #include "CLHEP/Random/RandomEngine.h"
43 
44 namespace CLHEP {
45 
50 class HepRandom {
51 
52 public:
53 
54  HepRandom();
55  HepRandom(long seed);
56  // Contructors with and without a seed using the default engine
57  // (JamesRandom).
58 
59  HepRandom(HepRandomEngine & algorithm);
60  HepRandom(HepRandomEngine * algorithm);
61  // Constructor taking an alternative engine as argument. If a pointer is
62  // given the corresponding object will be deleted by the HepRandom
63  // destructor.
64 
65  virtual ~HepRandom();
66  // Destructor
67 
68  // implicitly allow compiler-generated copy functions
69 
70  double flat();
71  // Returns the flat value ( interval ]0...1[ ).
72 
73  void flatArray(const int size, double* vect);
74  // Fills "vect" array of flat random values, given the size.
75 
76  inline double flat (HepRandomEngine* theNewEngine);
77  // Returns a flat value, given a defined Random Engine.
78 
79  inline void flatArray(HepRandomEngine* theNewEngine,
80  const int size, double* vect);
81  // Fills "vect" array of flat random values, given the size
82  // and a defined Random Engine.
83 
84  virtual double operator()();
85  // To get a flat random number using the operator ().
86 
87  virtual std::string name() const;
88  virtual HepRandomEngine & engine();
89 
90 
91  virtual std::ostream & put ( std::ostream & os ) const;
92  virtual std::istream & get ( std::istream & is );
93  // Save and restore to/from streams
94 
95  // --------------------------------------------------
96  // Static member functions using the static generator
97  // --------------------------------------------------
98 
99  static void setTheSeed(long seed, int lux=3);
100  // (Re)Initializes the generator with a seed.
101 
102  static long getTheSeed();
103  // Gets the current seed of the current generator.
104 
105  static void setTheSeeds(const long* seeds, int aux=-1);
106  // (Re)Initializes the generator with a zero terminated list of seeds.
107 
108  static const long* getTheSeeds();
109  // Gets the current array of seeds of the current generator.
110 
111  static void getTheTableSeeds (long* seeds, int index);
112  // Gets the array of seeds in the static seedTable at "index" position.
113 
114  static HepRandom * getTheGenerator();
115  // Return the current static generator.
116 
117  static void setTheEngine (HepRandomEngine* theNewEngine);
118  // To set the underlying algorithm object.
119 
120  static HepRandomEngine * getTheEngine();
121  // Returns a pointer to the underlying algorithm object.
122 
123  static void saveEngineStatus( const char filename[] = "Config.conf" );
124  // Saves to file the current status of the current engine.
125 
126  static void restoreEngineStatus( const char filename[] = "Config.conf" );
127  // Restores a saved status (if any) for the current engine.
128 
129  static std::ostream& saveFullState ( std::ostream & os );
130  // Saves to stream the state of the engine and cached data.
131 
132  static std::istream& restoreFullState ( std::istream & is );
133  // Restores from stream the state of the engine and cached data.
134 
135  static std::ostream& saveDistState ( std::ostream & os ) {return os;}
136  // Saves to stream the state of the cached data.
137 
138  static std::istream& restoreDistState ( std::istream & is ) {return is;}
139  // Restores from stream the state of the cached data.
140 
141  static std::ostream& saveStaticRandomStates ( std::ostream & os );
142  // Saves to stream the engine and cached data for all distributions.
143 
144  static std::istream& restoreStaticRandomStates ( std::istream & is );
145  // Restores from stream the engine and cached data for all distributions.
146 
147  static void showEngineStatus();
148  // Dumps the current engine status on screen.
149 
150  static int createInstance();
151  // used to initialise the default engine
152 
153  static std::string distributionName() {return "HepRandomEngine";}
154  // Provides the name of this distribution class
155 
156 protected: // -------- Data members ---------
157 
158  static const long seedTable[215][2];
159  // Table of seeds
160 
161 };
162 
163 std::ostream & operator<< (std::ostream & os, const HepRandom & dist);
164 std::istream & operator>> (std::istream & is, HepRandom & dist);
165 
166 } // namespace CLHEP
167 
168 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
169 // backwards compatibility will be enabled ONLY in CLHEP 1.9
170 using namespace CLHEP;
171 #endif
172 
173 #include "CLHEP/Random/Random.icc"
174 
175 #endif
CLHEP::HepRandom::seedTable
static const long seedTable[215][2]
Definition: Matrix/CLHEP/Random/Random.h:158
CLHEP::HepRandom::saveFullState
static std::ostream & saveFullState(std::ostream &os)
Definition: Random.cc:186
CLHEP::HepRandom::createInstance
static int createInstance()
Definition: Random.cc:209
CLHEP::HepRandom::restoreStaticRandomStates
static std::istream & restoreStaticRandomStates(std::istream &is)
Definition: Random.cc:200
CLHEP::HepRandom::getTheTableSeeds
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:152
is
HepRotation and so forth isNear() norm2() rectify() static Rotation row1 row4(To avoid bloat in the code pulled in for programs which don 't use all these features, we split the implementation .cc files. Only isNear() goes into the original Rotation.cc) --------------------------------------- HepAxisAngle and HepEulerAngles classes --------------------------------------- These classes are very useful and simple structures for holding the result of a nice intuituve decomposition of a rotation there is no longer much content in the distinct ZOOM PhysicsVectors library The only content left in the library is the object files representing the various Exception objects When we build the CLHEP classes for the ZOOM we will set up so as to use ZOOM SpaceVector is(but we can disable namespace usage and most of our users do so at this point). What I do is leave Hep3Vector in the global namespace
CLHEP::HepRandom::restoreFullState
static std::istream & restoreFullState(std::istream &is)
Definition: Random.cc:191
CLHEP::HepRandom::setTheEngine
static void setTheEngine(HepRandomEngine *theNewEngine)
Definition: Random.cc:171
CLHEP::HepRandom::restoreEngineStatus
static void restoreEngineStatus(const char filename[]="Config.conf")
Definition: Random.cc:181
CLHEP::HepRandom::getTheSeeds
static const long * getTheSeeds()
Definition: Random.cc:147
size
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno size() Return the(integer) number of ZMthrow 'n exceptions currently recorded. 5) ZMerrno.clear() Set an internal counter to zero. This counter is available(see next function) to user code to track ZMthrow 'n exceptions that have occurred during any arbitrary time interval. 6) ZMerrno.countSinceCleared() Return the(integer) number of ZMthrow 'n exceptions that have been recorded via ZMerrno.write()
CLHEP::HepRandom::operator()
virtual double operator()()
Definition: Random.cc:107
CLHEP::HepRandom::getTheGenerator
static HepRandom * getTheGenerator()
Definition: Random.cc:161
CLHEP::HepRandom::engine
virtual HepRandomEngine & engine()
Definition: Random.cc:112
CLHEP
Definition: ClhepVersion.h:13
CLHEP::HepRandom::name
virtual std::string name() const
Definition: Random.cc:111
CLHEP::HepRandom::get
virtual std::istream & get(std::istream &is)
Definition: Random.cc:126
CLHEP::HepRandom::getTheSeed
static long getTheSeed()
Definition: Random.cc:137
algorithm
I could not create a faster method completely accurate that does not require overly large tables and takes a major step up when we cross for several values of but we have applied this with much higher N We validated the main trials It showed no sign of approaching the rejectable p values or errors in mean and sigma the method matches the original algorithm
Definition: validation.doc:308
CLHEP::HepRandom::setTheSeeds
static void setTheSeeds(const long *seeds, int aux=-1)
Definition: Random.cc:142
CLHEP::operator>>
std::istream & operator>>(std::istream &is, HepAxisAngle &aa)
Definition: AxisAngle.cc:96
seeds
Technical Maintenance Note for CLHEP Random Consequences of seeding JamesRandom with positive seed values greater than In the source code JamesRandom The usual way of seeding a generator is via the default which makes use of the table of seeds(with some trickery to ensure that the values won 't repeat after the table rows are exhausted). The trickery preserves the fact that sees are never negative(because the table values are never negative
CLHEP::HepRandom::saveStaticRandomStates
static std::ostream & saveStaticRandomStates(std::ostream &os)
Definition: Random.cc:196
CLHEP::HepRandom::flatArray
void flatArray(const int size, double *vect)
Definition: Random.cc:102
CLHEP::HepRandom::saveEngineStatus
static void saveEngineStatus(const char filename[]="Config.conf")
Definition: Random.cc:176
CLHEP::HepRandom::restoreDistState
static std::istream & restoreDistState(std::istream &is)
Definition: RandomObjects/CLHEP/Random/Random.h:138
CLHEP::HepRandom::showEngineStatus
static void showEngineStatus()
Definition: Random.cc:204
CLHEP::HepRandom::distributionName
static std::string distributionName()
Definition: RandomObjects/CLHEP/Random/Random.h:153
CLHEP::HepRandom::setTheSeed
static void setTheSeed(long seed, int lux=3)
Definition: Random.cc:132
CLHEP::operator<<
std::ostream & operator<<(std::ostream &os, const HepAxisAngle &aa)
Definition: AxisAngle.cc:86
CLHEP::HepRandom::getTheEngine
static HepRandomEngine * getTheEngine()
Definition: Random.cc:166
CLHEP::HepRandom::flat
double flat()
Definition: Random.cc:97
CLHEP::HepRandom::put
virtual std::ostream & put(std::ostream &os) const
Definition: Random.cc:125
CLHEP::HepRandom::HepRandom
HepRandom()
Definition: Random.cc:76
CLHEP::HepRandom::~HepRandom
virtual ~HepRandom()
Definition: Random.cc:94
CLHEP::HepRandom::saveDistState
static std::ostream & saveDistState(std::ostream &os)
Definition: RandomObjects/CLHEP/Random/Random.h:135