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

Random/Random/RandGauss.h
Go to the documentation of this file.
1 // $Id: RandGauss.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- RandGauss ---
7 // class header file
8 // -----------------------------------------------------------------------
9 // This file is part of Geant4 (simulation toolkit for HEP).
10 
11 // Class defining methods for shooting gaussian distributed random values,
12 // given a mean (default=0) or specifying also a deviation (default=1).
13 // Gaussian random numbers are generated two at the time, so every
14 // other time shoot is called the number returned is the one generated the
15 // time before.
16 // Default values are used for operator()().
17 
18 // =======================================================================
19 // Gabriele Cosmo - Created: 5th September 1995
20 // - Minor corrections: 31st October 1996
21 // - Added methods to shoot arrays: 28th July 1997
22 // J.Marraffino - Added default arguments as attributes and
23 // operator() with arguments. Introduced method normal()
24 // for computation in fire(): 16th Feb 1998
25 // Gabriele Cosmo - Relocated static data from HepRandom: 5th Jan 1999
26 // M Fischler - put and get to/from streams 12/8/04
27 // =======================================================================
28 
29 #ifndef RandGauss_h
30 #define RandGauss_h 1
31 
32 #include "CLHEP/Random/defs.h"
33 #include "CLHEP/Random/Random.h"
34 #include "CLHEP/Utility/memory.h"
35 
36 namespace CLHEP {
37 
42 class RandGauss : public HepRandom {
43 
44 public:
45 
46  inline RandGauss ( HepRandomEngine& anEngine, double mean=0.0,
47  double stdDev=1.0 );
48  inline RandGauss ( HepRandomEngine* anEngine, double mean=0.0,
49  double stdDev=1.0 );
50  // These constructors should be used to instantiate a RandGauss
51  // distribution object defining a local engine for it.
52  // The static generator will be skipped using the non-static methods
53  // defined below.
54  // If the engine is passed by pointer the corresponding engine object
55  // will be deleted by the RandGauss destructor.
56  // If the engine is passed by reference the corresponding engine object
57  // will not be deleted by the RandGauss destructor.
58 
59  virtual ~RandGauss();
60  // Destructor
61 
62  // Static methods to shoot random values using the static generator
63 
64  static double shoot();
65 
66  static inline double shoot( double mean, double stdDev );
67 
68  static void shootArray ( const int size, double* vect,
69  double mean=0.0, double stdDev=1.0 );
70 
71  // Static methods to shoot random values using a given engine
72  // by-passing the static generator.
73 
74  static double shoot( HepRandomEngine* anEngine );
75 
76  static inline double shoot( HepRandomEngine* anEngine,
77  double mean, double stdDev );
78 
79  static void shootArray ( HepRandomEngine* anEngine, const int size,
80  double* vect, double mean=0.0,
81  double stdDev=1.0 );
82 
83  // Methods using the localEngine to shoot random values, by-passing
84  // the static generator.
85 
86  double fire();
87 
88  inline double fire( double mean, double stdDev );
89 
90  void fireArray ( const int size, double* vect);
91  void fireArray ( const int size, double* vect,
92  double mean, double stdDev );
93 
94  virtual double operator()();
95  virtual double operator()( double mean, double stdDev );
96 
97  std::string name() const;
98  HepRandomEngine & engine();
99 
100  static std::string distributionName() {return "RandGauss";}
101  // Provides the name of this distribution class
102 
103  // Save and restore to/from streams
104 
105  std::ostream & put ( std::ostream & os ) const;
106  std::istream & get ( std::istream & is );
107 
108  // Methods setFlag(false) and setF(false) if invoked in the client
109  // code before shoot/fire will force generation of a new couple of
110  // values.
111 
112  static bool getFlag() {return set_st;}
113 
114  static void setFlag( bool val ) {set_st = val;}
115 
116  bool getF() const {return set;}
117 
118  void setF( bool val ) {set = val;}
119 
120  // Methods overriding the base class static saveEngineStatus ones,
121  // by adding extra data so that save in one program, then further gaussians,
122  // will produce the identical sequence to restore in another program, then
123  // generating gaussian randoms there
124 
125  static void saveEngineStatus( const char filename[] = "Config.conf" );
126  // Saves to file the current status of the current engine.
127 
128  static void restoreEngineStatus( const char filename[] = "Config.conf" );
129  // Restores a saved status (if any) for the current engine.
130 
131  static std::ostream& saveFullState ( std::ostream & os );
132  // Saves to stream the state of the engine and cached data.
133 
134  static std::istream& restoreFullState ( std::istream & is );
135  // Restores from stream the state of the engine and cached data.
136 
137  static std::ostream& saveDistState ( std::ostream & os );
138  // Saves to stream the state of the cached data.
139 
140  static std::istream& restoreDistState ( std::istream & is );
141  // Restores from stream the state of the cached data.
142 
143 
144 protected:
145 
146  static double getVal() {return nextGauss_st;}
147 
148  static void setVal( double nextVal ) {nextGauss_st = nextVal;}
149 
150  double normal();
151 
152  double defaultMean;
153  double defaultStdDev;
154 
156 
157 private:
158 
159  bool set;
160  double nextGauss;
161 
162  // static data
163  static bool set_st;
164  static double nextGauss_st;
165 
166 };
167 
168 } // namespace CLHEP
169 
170 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
171 // backwards compatibility will be enabled ONLY in CLHEP 1.9
172 using namespace CLHEP;
173 #endif
174 
175 #include "CLHEP/Random/RandGauss.icc"
176 
177 #endif
CLHEP::shared_ptr
Definition: Matrix/CLHEP/Utility/memory.h:66
CLHEP::RandGauss::engine
HepRandomEngine & engine()
Definition: RandGauss.cc:44
CLHEP::RandGauss::restoreDistState
static std::istream & restoreDistState(std::istream &is)
Definition: RandGauss.cc:338
CLHEP::RandGauss::RandGauss
RandGauss(HepRandomEngine &anEngine, double mean=0.0, double stdDev=1.0)
CLHEP::RandGauss::setF
void setF(bool val)
Definition: Random/Random/RandGauss.h:118
RandGauss
How the various random distributions are validated The distributions in for example RandGauss
Definition: validation.doc:4
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::RandGauss::restoreFullState
static std::istream & restoreFullState(std::istream &is)
Definition: RandGauss.cc:388
CLHEP::RandGauss::normal
double normal()
Definition: RandGauss.cc:131
CLHEP::RandGauss::getVal
static double getVal()
Definition: Random/Random/RandGauss.h:146
CLHEP::RandGauss::operator()
virtual double operator()()
Definition: RandGauss.cc:53
CLHEP::RandGauss::getFlag
static bool getFlag()
Definition: Random/Random/RandGauss.h:112
CLHEP::RandGauss::setFlag
static void setFlag(bool val)
Definition: Random/Random/RandGauss.h:114
CLHEP::RandGauss::get
std::istream & get(std::istream &is)
Definition: RandGauss.cc:262
CLHEP::RandGauss::~RandGauss
virtual ~RandGauss()
Definition: RandGauss.cc:50
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::RandGauss::shoot
static double shoot()
Definition: RandGauss.cc:61
CLHEP::RandGauss::getF
bool getF() const
Definition: Random/Random/RandGauss.h:116
CLHEP::RandGauss::defaultStdDev
double defaultStdDev
Definition: Matrix/CLHEP/Random/RandGauss.h:153
CLHEP::RandGauss::saveDistState
static std::ostream & saveDistState(std::ostream &os)
Definition: RandGauss.cc:323
CLHEP::RandGauss::fireArray
void fireArray(const int size, double *vect)
Definition: RandGauss.cc:157
CLHEP
Definition: ClhepVersion.h:13
CLHEP::RandGauss::restoreEngineStatus
static void restoreEngineStatus(const char filename[]="Config.conf")
Definition: RandGauss.cc:190
CLHEP::RandGauss::defaultMean
double defaultMean
Definition: Matrix/CLHEP/Random/RandGauss.h:152
CLHEP::RandGauss::distributionName
static std::string distributionName()
Definition: Random/Random/RandGauss.h:100
CLHEP::RandGauss::name
std::string name() const
Definition: RandGauss.cc:43
CLHEP::RandGauss::saveEngineStatus
static void saveEngineStatus(const char filename[]="Config.conf")
Definition: RandGauss.cc:170
CLHEP::RandGauss::put
std::ostream & put(std::ostream &os) const
Definition: RandGauss.cc:237
CLHEP::RandGauss::saveFullState
static std::ostream & saveFullState(std::ostream &os)
Definition: RandGauss.cc:382
CLHEP::RandGauss::localEngine
shared_ptr< HepRandomEngine > localEngine
Definition: Matrix/CLHEP/Random/RandGauss.h:155
CLHEP::RandGauss::shootArray
static void shootArray(const int size, double *vect, double mean=0.0, double stdDev=1.0)
Definition: RandGauss.cc:90
CLHEP::RandGauss::setVal
static void setVal(double nextVal)
Definition: Random/Random/RandGauss.h:148
CLHEP::RandGauss::fire
double fire()