Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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"
34
35namespace CLHEP {
36
37/**
38 * @author
39 * @ingroup random
40 */
41class RandGauss : public HepRandom {
42
43public:
44
45 inline RandGauss ( HepRandomEngine& anEngine, double mean=0.0,
46 double stdDev=1.0 );
47 inline RandGauss ( HepRandomEngine* anEngine, double mean=0.0,
48 double stdDev=1.0 );
49 // These constructors should be used to instantiate a RandGauss
50 // distribution object defining a local engine for it.
51 // The static generator will be skipped using the non-static methods
52 // defined below.
53 // If the engine is passed by pointer the corresponding engine object
54 // will be deleted by the RandGauss destructor.
55 // If the engine is passed by reference the corresponding engine object
56 // will not be deleted by the RandGauss destructor.
57
58 virtual ~RandGauss();
59 // Destructor
60
61 // Static methods to shoot random values using the static generator
62
63 static double shoot();
64
65 static inline double shoot( double mean, double stdDev );
66
67 static void shootArray ( const int size, double* vect,
68 double mean=0.0, double stdDev=1.0 );
69
70 // Static methods to shoot random values using a given engine
71 // by-passing the static generator.
72
73 static double shoot( HepRandomEngine* anEngine );
74
75 static inline double shoot( HepRandomEngine* anEngine,
76 double mean, double stdDev );
77
78 static void shootArray ( HepRandomEngine* anEngine, const int size,
79 double* vect, double mean=0.0,
80 double stdDev=1.0 );
81
82 // Methods using the localEngine to shoot random values, by-passing
83 // the static generator.
84
85 double fire();
86
87 inline double fire( double mean, double stdDev );
88
89 void fireArray ( const int size, double* vect);
90 void fireArray ( const int size, double* vect,
91 double mean, double stdDev );
92
93 virtual double operator()();
94 virtual double operator()( double mean, double stdDev );
95
96 std::string name() const;
98
99 static std::string distributionName() {return "RandGauss";}
100 // Provides the name of this distribution class
101
102 // Save and restore to/from streams
103
104 std::ostream & put ( std::ostream & os ) const;
105 std::istream & get ( std::istream & is );
106
107 // Methods setFlag(false) and setF(false) if invoked in the client
108 // code before shoot/fire will force generation of a new couple of
109 // values.
110
111 static bool getFlag() {return set_st;}
112
113 static void setFlag( bool val ) {set_st = val;}
114
115 bool getF() const {return set;}
116
117 void setF( bool val ) {set = val;}
118
119 // Methods overriding the base class static saveEngineStatus ones,
120 // by adding extra data so that save in one program, then further gaussians,
121 // will produce the identical sequence to restore in another program, then
122 // generating gaussian randoms there
123
124 static void saveEngineStatus( const char filename[] = "Config.conf" );
125 // Saves to file the current status of the current engine.
126
127 static void restoreEngineStatus( const char filename[] = "Config.conf" );
128 // Restores a saved status (if any) for the current engine.
129
130 static std::ostream& saveFullState ( std::ostream & os );
131 // Saves to stream the state of the engine and cached data.
132
133 static std::istream& restoreFullState ( std::istream & is );
134 // Restores from stream the state of the engine and cached data.
135
136 static std::ostream& saveDistState ( std::ostream & os );
137 // Saves to stream the state of the cached data.
138
139 static std::istream& restoreDistState ( std::istream & is );
140 // Restores from stream the state of the cached data.
141
142
143protected:
144
145 static double getVal() {return nextGauss_st;}
146
147 static void setVal( double nextVal ) {nextGauss_st = nextVal;}
148
149 double normal();
150
153
155
156private:
157
158 bool set;
159 double nextGauss;
160
161 // static data
162 static bool set_st;
163 static double nextGauss_st;
164
165};
166
167} // namespace CLHEP
168
169#include "CLHEP/Random/RandGauss.icc"
170
171#endif
static std::ostream & saveDistState(std::ostream &os)
Definition: RandGauss.cc:309
std::string name() const
Definition: RandGauss.cc:42
static std::istream & restoreFullState(std::istream &is)
Definition: RandGauss.cc:374
static void restoreEngineStatus(const char filename[]="Config.conf")
Definition: RandGauss.cc:189
static double shoot()
Definition: RandGauss.cc:60
std::istream & get(std::istream &is)
Definition: RandGauss.cc:255
double defaultStdDev
Definition: RandGauss.h:152
std::ostream & put(std::ostream &os) const
Definition: RandGauss.cc:236
RandGauss(HepRandomEngine *anEngine, double mean=0.0, double stdDev=1.0)
void fireArray(const int size, double *vect)
Definition: RandGauss.cc:156
RandGauss(HepRandomEngine &anEngine, double mean=0.0, double stdDev=1.0)
double fire(double mean, double stdDev)
void setF(bool val)
Definition: RandGauss.h:117
static void shootArray(const int size, double *vect, double mean=0.0, double stdDev=1.0)
Definition: RandGauss.cc:89
HepRandomEngine & engine()
Definition: RandGauss.cc:43
static std::ostream & saveFullState(std::ostream &os)
Definition: RandGauss.cc:368
double normal()
Definition: RandGauss.cc:130
shared_ptr< HepRandomEngine > localEngine
Definition: RandGauss.h:154
double defaultMean
Definition: RandGauss.h:151
bool getF() const
Definition: RandGauss.h:115
static double shoot(double mean, double stdDev)
static std::string distributionName()
Definition: RandGauss.h:99
static double getVal()
Definition: RandGauss.h:145
static bool getFlag()
Definition: RandGauss.h:111
static void setVal(double nextVal)
Definition: RandGauss.h:147
static double shoot(HepRandomEngine *anEngine, double mean, double stdDev)
static void setFlag(bool val)
Definition: RandGauss.h:113
virtual ~RandGauss()
Definition: RandGauss.cc:49
static std::istream & restoreDistState(std::istream &is)
Definition: RandGauss.cc:324
virtual double operator()()
Definition: RandGauss.cc:52
static void saveEngineStatus(const char filename[]="Config.conf")
Definition: RandGauss.cc:169
Definition: DoubConv.h:17