CLHEP/Random/RandGauss.h

00001 // $Id: RandGauss.h,v 1.16 2002/04/12 15:02:44 evc 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 // =======================================================================
00027 
00028 #ifndef RandGauss_h
00029 #define RandGauss_h 1
00030 
00031 #include "CLHEP/Random/Random.h"
00032 
00037 class RandGauss : public HepRandom {
00038 
00039 public:
00040 
00041   inline RandGauss ( HepRandomEngine& anEngine, double mean=0.0,
00042                                                 double stdDev=1.0 );
00043   inline RandGauss ( HepRandomEngine* anEngine, double mean=0.0,
00044                                                 double stdDev=1.0 );
00045   // These constructors should be used to instantiate a RandGauss
00046   // distribution object defining a local engine for it.
00047   // The static generator will be skipped using the non-static methods
00048   // defined below.
00049   // If the engine is passed by pointer the corresponding engine object
00050   // will be deleted by the RandGauss destructor.
00051   // If the engine is passed by reference the corresponding engine object
00052   // will not be deleted by the RandGauss destructor.
00053 
00054   virtual ~RandGauss();
00055   // Destructor
00056 
00057   // Static methods to shoot random values using the static generator
00058 
00059   static  double shoot();
00060 
00061   static  inline double shoot( double mean, double stdDev );
00062 
00063   static  void shootArray ( const int size, double* vect,
00064                             double mean=0.0, double stdDev=1.0 );
00065 
00066   //  Static methods to shoot random values using a given engine
00067   //  by-passing the static generator.
00068 
00069   static  double shoot( HepRandomEngine* anEngine );
00070 
00071   static  inline double shoot( HepRandomEngine* anEngine, 
00072                                   double mean, double stdDev );
00073 
00074   static  void shootArray ( HepRandomEngine* anEngine, const int size,
00075                             double* vect, double mean=0.0,
00076                             double stdDev=1.0 );
00077 
00078   //  Methods using the localEngine to shoot random values, by-passing
00079   //  the static generator.
00080 
00081   double fire();
00082 
00083   inline double fire( double mean, double stdDev );
00084   
00085   void fireArray ( const int size, double* vect);
00086   void fireArray ( const int size, double* vect,
00087                    double mean, double stdDev );
00088 
00089   virtual double operator()();
00090   virtual double operator()( double mean, double stdDev );
00091 
00092   //  Methods setFlag(false) and setF(false) if invoked in the client
00093   //  code before shoot/fire will force generation of a new couple of
00094   //  values.
00095 
00096   static  bool getFlag() {return set_st;}
00097 
00098   static  void setFlag( bool val ) {set_st = val;}
00099 
00100   bool getF() const {return set;}
00101   
00102   void setF( bool val ) {set = val;}
00103 
00104   // Methods overriding the base class static saveEngineStatus ones,
00105   // by adding extra data so that save in one program, then further gaussians,
00106   // will produce the identical sequence to restore in another program, then 
00107   // generating gaussian randoms there 
00108 
00109   static void saveEngineStatus( const char filename[] = "Config.conf" );
00110   // Saves to file the current status of the current engine.
00111 
00112   static void restoreEngineStatus( const char filename[] = "Config.conf" );
00113   // Restores a saved status (if any) for the current engine.
00114 
00115 
00116 protected:
00117 
00118   // Protected copy constructor. Defining it here disallows user use.
00119   RandGauss(const RandGauss& d);
00120 
00121   static  double getVal() {return nextGauss_st;}
00122 
00123   static  void setVal( double nextVal ) {nextGauss_st = nextVal;}
00124 
00125   double normal();
00126 
00127   const double defaultMean;
00128   const double defaultStdDev;
00129 
00130 private:
00131 
00132   HepRandomEngine* localEngine;
00133   bool deleteEngine, set;
00134   double nextGauss;
00135 
00136   // static data
00137   static bool set_st;
00138   static double nextGauss_st;
00139 
00140 };
00141 
00142 #include "CLHEP/Random/RandGauss.icc"
00143 
00144 #endif

Class Library for High Energy Physics (version 1.8)