Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RandGauss.h
Go to the documentation of this file.
1 // $Id:$
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/Random.h"
33 #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;
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();
113 
114  static void setFlag( bool 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();
147 
148  static void setVal( double nextVal );
149 
150  double normal();
151 
152  double defaultMean;
154 
155  std::shared_ptr<HepRandomEngine> localEngine;
156 
157 private:
158 
159  bool set;
160  double nextGauss;
161 
162  // static data
163  static CLHEP_THREAD_LOCAL bool set_st;
164  static CLHEP_THREAD_LOCAL double nextGauss_st;
165 
166 };
167 
168 } // namespace CLHEP
169 
170 #include "CLHEP/Random/RandGauss.icc"
171 
172 #endif
static std::istream & restoreFullState(std::istream &is)
Definition: RandGauss.cc:394
static void saveEngineStatus(const char filename[]="Config.conf")
Definition: RandGauss.cc:189
virtual ~RandGauss()
Definition: RandGauss.cc:49
double defaultStdDev
Definition: RandGauss.h:153
static std::istream & restoreDistState(std::istream &is)
Definition: RandGauss.cc:344
HepRandomEngine & engine()
Definition: RandGauss.cc:43
static bool getFlag()
Definition: RandGauss.cc:169
static std::ostream & saveDistState(std::ostream &os)
Definition: RandGauss.cc:329
void fireArray(const int size, double *vect)
Definition: RandGauss.cc:156
std::shared_ptr< HepRandomEngine > localEngine
Definition: RandGauss.h:155
static double getVal()
Definition: RandGauss.cc:179
RandGauss(HepRandomEngine &anEngine, double mean=0.0, double stdDev=1.0)
void setF(bool val)
Definition: RandGauss.h:118
double normal()
Definition: RandGauss.cc:130
static void shootArray(const int size, double *vect, double mean=0.0, double stdDev=1.0)
Definition: RandGauss.cc:89
static double shoot()
Definition: RandGauss.cc:60
double defaultMean
Definition: RandGauss.h:152
static std::string distributionName()
Definition: RandGauss.h:100
bool getF() const
Definition: RandGauss.h:116
#define CLHEP_THREAD_LOCAL
Definition: thread_local.h:25
virtual double operator()()
Definition: RandGauss.cc:52
static void setVal(double nextVal)
Definition: RandGauss.cc:184
static void restoreEngineStatus(const char filename[]="Config.conf")
Definition: RandGauss.cc:209
static std::ostream & saveFullState(std::ostream &os)
Definition: RandGauss.cc:388
static void setFlag(bool val)
Definition: RandGauss.cc:174
std::ostream & put(std::ostream &os) const
Definition: RandGauss.cc:256
std::string name() const
Definition: RandGauss.cc:42