CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: RandGauss.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- RandGauss --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 // This file is part of Geant4 (simulation toolkit for HEP). 00010 00011 // Class defining methods for shooting gaussian distributed random values, 00012 // given a mean (default=0) or specifying also a deviation (default=1). 00013 // Gaussian random numbers are generated two at the time, so every 00014 // other time shoot is called the number returned is the one generated the 00015 // time before. 00016 // Default values are used for operator()(). 00017 00018 // ======================================================================= 00019 // Gabriele Cosmo - Created: 5th September 1995 00020 // - Minor corrections: 31st October 1996 00021 // - Added methods to shoot arrays: 28th July 1997 00022 // J.Marraffino - Added default arguments as attributes and 00023 // operator() with arguments. Introduced method normal() 00024 // for computation in fire(): 16th Feb 1998 00025 // Gabriele Cosmo - Relocated static data from HepRandom: 5th Jan 1999 00026 // M Fischler - put and get to/from streams 12/8/04 00027 // ======================================================================= 00028 00029 #ifndef RandGauss_h 00030 #define RandGauss_h 1 00031 00032 #include "CLHEP/Random/defs.h" 00033 #include "CLHEP/Random/Random.h" 00034 00035 namespace CLHEP { 00036 00041 class RandGauss : public HepRandom { 00042 00043 public: 00044 00045 inline RandGauss ( HepRandomEngine& anEngine, double mean=0.0, 00046 double stdDev=1.0 ); 00047 inline RandGauss ( HepRandomEngine* anEngine, double mean=0.0, 00048 double stdDev=1.0 ); 00049 // These constructors should be used to instantiate a RandGauss 00050 // distribution object defining a local engine for it. 00051 // The static generator will be skipped using the non-static methods 00052 // defined below. 00053 // If the engine is passed by pointer the corresponding engine object 00054 // will be deleted by the RandGauss destructor. 00055 // If the engine is passed by reference the corresponding engine object 00056 // will not be deleted by the RandGauss destructor. 00057 00058 virtual ~RandGauss(); 00059 // Destructor 00060 00061 // Static methods to shoot random values using the static generator 00062 00063 static double shoot(); 00064 00065 static inline double shoot( double mean, double stdDev ); 00066 00067 static void shootArray ( const int size, double* vect, 00068 double mean=0.0, double stdDev=1.0 ); 00069 00070 // Static methods to shoot random values using a given engine 00071 // by-passing the static generator. 00072 00073 static double shoot( HepRandomEngine* anEngine ); 00074 00075 static inline double shoot( HepRandomEngine* anEngine, 00076 double mean, double stdDev ); 00077 00078 static void shootArray ( HepRandomEngine* anEngine, const int size, 00079 double* vect, double mean=0.0, 00080 double stdDev=1.0 ); 00081 00082 // Methods using the localEngine to shoot random values, by-passing 00083 // the static generator. 00084 00085 double fire(); 00086 00087 inline double fire( double mean, double stdDev ); 00088 00089 void fireArray ( const int size, double* vect); 00090 void fireArray ( const int size, double* vect, 00091 double mean, double stdDev ); 00092 00093 virtual double operator()(); 00094 virtual double operator()( double mean, double stdDev ); 00095 00096 std::string name() const; 00097 HepRandomEngine & engine(); 00098 00099 static std::string distributionName() {return "RandGauss";} 00100 // Provides the name of this distribution class 00101 00102 // Save and restore to/from streams 00103 00104 std::ostream & put ( std::ostream & os ) const; 00105 std::istream & get ( std::istream & is ); 00106 00107 // Methods setFlag(false) and setF(false) if invoked in the client 00108 // code before shoot/fire will force generation of a new couple of 00109 // values. 00110 00111 static bool getFlag() {return set_st;} 00112 00113 static void setFlag( bool val ) {set_st = val;} 00114 00115 bool getF() const {return set;} 00116 00117 void setF( bool val ) {set = val;} 00118 00119 // Methods overriding the base class static saveEngineStatus ones, 00120 // by adding extra data so that save in one program, then further gaussians, 00121 // will produce the identical sequence to restore in another program, then 00122 // generating gaussian randoms there 00123 00124 static void saveEngineStatus( const char filename[] = "Config.conf" ); 00125 // Saves to file the current status of the current engine. 00126 00127 static void restoreEngineStatus( const char filename[] = "Config.conf" ); 00128 // Restores a saved status (if any) for the current engine. 00129 00130 static std::ostream& saveFullState ( std::ostream & os ); 00131 // Saves to stream the state of the engine and cached data. 00132 00133 static std::istream& restoreFullState ( std::istream & is ); 00134 // Restores from stream the state of the engine and cached data. 00135 00136 static std::ostream& saveDistState ( std::ostream & os ); 00137 // Saves to stream the state of the cached data. 00138 00139 static std::istream& restoreDistState ( std::istream & is ); 00140 // Restores from stream the state of the cached data. 00141 00142 00143 protected: 00144 00145 // Protected copy constructor. Defining it here disallows user use. 00146 RandGauss(const RandGauss& d); 00147 00148 static double getVal() {return nextGauss_st;} 00149 00150 static void setVal( double nextVal ) {nextGauss_st = nextVal;} 00151 00152 double normal(); 00153 00154 double defaultMean; 00155 double defaultStdDev; 00156 00157 HepRandomEngine* localEngine; 00158 00159 private: 00160 00161 bool deleteEngine, set; 00162 double nextGauss; 00163 00164 // static data 00165 static bool set_st; 00166 static double nextGauss_st; 00167 00168 }; 00169 00170 } // namespace CLHEP 00171 00172 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00173 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00174 using namespace CLHEP; 00175 #endif 00176 00177 #include "CLHEP/Random/RandGauss.icc" 00178 00179 #endif