CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: RandPoissonQ.h,v 1.5 2010/06/16 17:24:53 garren Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- RandPoissonQ --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 00010 // Class defining RandPoissonQ, which is derived from RandPoison. 00011 // The user interface is identical; but RandGaussQ is much faster in all cases 00012 // and a bit less accurate when mu > 100. 00013 00014 // ======================================================================= 00015 // M. Fischler - Created: 4th Feb 2000 00016 // M Fischler - put and get to/from streams 12/10/04 00017 // 00018 // ======================================================================= 00019 00020 #ifndef RandPoissonQ_h 00021 #define RandPoissonQ_h 1 00022 00023 #include "CLHEP/Random/defs.h" 00024 #include "CLHEP/Random/Random.h" 00025 #include "CLHEP/Random/RandPoisson.h" 00026 00027 namespace CLHEP { 00028 00033 class RandPoissonQ : public RandPoisson { 00034 00035 public: 00036 00037 inline RandPoissonQ ( HepRandomEngine& anEngine, double b1=1.0 ); 00038 inline RandPoissonQ ( HepRandomEngine* anEngine, double b1=1.0 ); 00039 // These constructors should be used to instantiate a RandPoissonQ 00040 // distribution object defining a local engine for it. 00041 // The static generator will be skipped using the non-static methods 00042 // defined below. 00043 // If the engine is passed by pointer the corresponding engine object 00044 // will be deleted by the RandPoissonQ destructor. 00045 // If the engine is passed by reference the corresponding engine object 00046 // will not be deleted by the RandPoissonQ destructor. 00047 00048 virtual ~RandPoissonQ(); 00049 // Destructor 00050 00051 // Save and restore to/from streams 00052 00053 std::ostream & put ( std::ostream & os ) const; 00054 std::istream & get ( std::istream & is ); 00055 00056 // Methods to generate Poisson-distributed random deviates. 00057 00058 // The method used for mu <= 100 is exact, and 3-7 times faster than 00059 // that used by RandPoisson. 00060 // For mu > 100 then we use a corrected version of a 00061 // (quick) Gaussian approximation. Naively that would be: 00062 // 00063 // Poisson(mu) ~ floor( mu + .5 + Gaussian(sqrt(mu)) ) 00064 // 00065 // but actually, that would give a slightly incorrect sigma and a 00066 // very different skew than a true Poisson. Instead we return 00067 // 00068 // Poisson(mu) ~ floor( a0*mu + a1*g + a2*g*g ) ) 00069 // (with g a gaussian normal) 00070 // 00071 // where a0, a1, a2 are chosen to give the exctly correct mean, sigma, 00072 // and skew for the Poisson distribution. 00073 00074 // Static methods to shoot random values using the static generator 00075 00076 static long shoot( double m=1.0 ); 00077 00078 static void shootArray ( const int size, long* vect, double m=1.0 ); 00079 00080 // Static methods to shoot random values using a given engine 00081 // by-passing the static generator. 00082 00083 static long shoot( HepRandomEngine* anEngine, double m=1.0 ); 00084 00085 static void shootArray ( HepRandomEngine* anEngine, 00086 const int size, long* vect, double m=1.0 ); 00087 00088 // Methods using the localEngine to shoot random values, by-passing 00089 // the static generator. 00090 00091 long fire(); 00092 long fire( double m ); 00093 00094 void fireArray ( const int size, long* vect ); 00095 void fireArray ( const int size, long* vect, double m); 00096 00097 double operator()(); 00098 double operator()( double m ); 00099 00100 std::string name() const; 00101 HepRandomEngine & engine(); 00102 00103 static std::string distributionName() {return "RandPoissonQ";} 00104 // Provides the name of this distribution class 00105 00106 00107 // static constants of possible interest to users: 00108 00109 // RandPoisson will never return a deviate greater than this value: 00110 static const double MAXIMUM_POISSON_DEVIATE; // Will be 2.0E9 00111 00112 static inline int tableBoundary(); 00113 00114 private: 00115 00116 // constructor helper 00117 void setupForDefaultMu(); 00118 00119 // algorithm helper methods - all static since the shoot methods mayneed them 00120 static long poissonDeviateSmall ( HepRandomEngine * e, double mean ); 00121 static long poissonDeviateQuick ( HepRandomEngine * e, double mean ); 00122 static long poissonDeviateQuick ( HepRandomEngine * e, 00123 double A0, double A1, double A2, double sig ); 00124 00125 // All the engine info, and the default mean, are in the 00126 // RandPoisson base class. 00127 00128 // quantities for approximate Poisson by corrected Gaussian 00129 double a0; 00130 double a1; 00131 double a2; 00132 double sigma; 00133 00134 // static data - constants only, so that saveEngineStatus works properly! 00135 00136 // The following MUST MATCH the corresponding values used (in 00137 // poissonTables.cc) when poissonTables.cdat was created. 00138 // poissonTables.cc gets these values by including this header, 00139 // but we must be careful not to change these values, 00140 // and rebuild RandPoissonQ before re-generating poissonTables.cdat. 00141 00142 // (These statics are given values near the start of the .cc file) 00143 00144 static const double FIRST_MU; // lowest mu value in table 00145 static const double LAST_MU; // highest mu value 00146 static const double S; // Spacing between mu values 00147 static const int BELOW; // Starting point for N is at mu - BELOW 00148 static const int ENTRIES; // Number of entries in each mu row 00149 00150 }; 00151 00152 } // namespace CLHEP 00153 00154 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00155 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00156 using namespace CLHEP; 00157 #endif 00158 00159 #include "CLHEP/Random/RandPoissonQ.icc" 00160 00161 #endif