CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: RandGauss.h,v 1.5 2010/06/16 17:24:53 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 #include "CLHEP/Utility/memory.h" 00035 00036 namespace CLHEP { 00037 00042 class RandGauss : public HepRandom { 00043 00044 public: 00045 00046 inline RandGauss ( HepRandomEngine& anEngine, double mean=0.0, 00047 double stdDev=1.0 ); 00048 inline RandGauss ( HepRandomEngine* anEngine, double mean=0.0, 00049 double stdDev=1.0 ); 00050 // These constructors should be used to instantiate a RandGauss 00051 // distribution object defining a local engine for it. 00052 // The static generator will be skipped using the non-static methods 00053 // defined below. 00054 // If the engine is passed by pointer the corresponding engine object 00055 // will be deleted by the RandGauss destructor. 00056 // If the engine is passed by reference the corresponding engine object 00057 // will not be deleted by the RandGauss destructor. 00058 00059 virtual ~RandGauss(); 00060 // Destructor 00061 00062 // Static methods to shoot random values using the static generator 00063 00064 static double shoot(); 00065 00066 static inline double shoot( double mean, double stdDev ); 00067 00068 static void shootArray ( const int size, double* vect, 00069 double mean=0.0, double stdDev=1.0 ); 00070 00071 // Static methods to shoot random values using a given engine 00072 // by-passing the static generator. 00073 00074 static double shoot( HepRandomEngine* anEngine ); 00075 00076 static inline double shoot( HepRandomEngine* anEngine, 00077 double mean, double stdDev ); 00078 00079 static void shootArray ( HepRandomEngine* anEngine, const int size, 00080 double* vect, double mean=0.0, 00081 double stdDev=1.0 ); 00082 00083 // Methods using the localEngine to shoot random values, by-passing 00084 // the static generator. 00085 00086 double fire(); 00087 00088 inline double fire( double mean, double stdDev ); 00089 00090 void fireArray ( const int size, double* vect); 00091 void fireArray ( const int size, double* vect, 00092 double mean, double stdDev ); 00093 00094 virtual double operator()(); 00095 virtual double operator()( double mean, double stdDev ); 00096 00097 std::string name() const; 00098 HepRandomEngine & engine(); 00099 00100 static std::string distributionName() {return "RandGauss";} 00101 // Provides the name of this distribution class 00102 00103 // Save and restore to/from streams 00104 00105 std::ostream & put ( std::ostream & os ) const; 00106 std::istream & get ( std::istream & is ); 00107 00108 // Methods setFlag(false) and setF(false) if invoked in the client 00109 // code before shoot/fire will force generation of a new couple of 00110 // values. 00111 00112 static bool getFlag() {return set_st;} 00113 00114 static void setFlag( bool val ) {set_st = val;} 00115 00116 bool getF() const {return set;} 00117 00118 void setF( bool val ) {set = val;} 00119 00120 // Methods overriding the base class static saveEngineStatus ones, 00121 // by adding extra data so that save in one program, then further gaussians, 00122 // will produce the identical sequence to restore in another program, then 00123 // generating gaussian randoms there 00124 00125 static void saveEngineStatus( const char filename[] = "Config.conf" ); 00126 // Saves to file the current status of the current engine. 00127 00128 static void restoreEngineStatus( const char filename[] = "Config.conf" ); 00129 // Restores a saved status (if any) for the current engine. 00130 00131 static std::ostream& saveFullState ( std::ostream & os ); 00132 // Saves to stream the state of the engine and cached data. 00133 00134 static std::istream& restoreFullState ( std::istream & is ); 00135 // Restores from stream the state of the engine and cached data. 00136 00137 static std::ostream& saveDistState ( std::ostream & os ); 00138 // Saves to stream the state of the cached data. 00139 00140 static std::istream& restoreDistState ( std::istream & is ); 00141 // Restores from stream the state of the cached data. 00142 00143 00144 protected: 00145 00146 static double getVal() {return nextGauss_st;} 00147 00148 static void setVal( double nextVal ) {nextGauss_st = nextVal;} 00149 00150 double normal(); 00151 00152 double defaultMean; 00153 double defaultStdDev; 00154 00155 shared_ptr<HepRandomEngine> localEngine; 00156 00157 private: 00158 00159 bool set; 00160 double nextGauss; 00161 00162 // static data 00163 static bool set_st; 00164 static double nextGauss_st; 00165 00166 }; 00167 00168 } // namespace CLHEP 00169 00170 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00171 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00172 using namespace CLHEP; 00173 #endif 00174 00175 #include "CLHEP/Random/RandGauss.icc" 00176 00177 #endif