CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

RandPoissonQ.h

Go to the documentation of this file.
00001 // $Id: RandPoissonQ.h,v 1.3.4.1 2005/03/18 22:26:48 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 m=1.0 );
00038   inline RandPoissonQ ( HepRandomEngine* anEngine, double m=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 protected:
00115 
00116 private:
00117 
00118   // Private copy constructor. Defining it here disallows use.
00119   RandPoissonQ(const RandPoissonQ& d);
00120 
00121   // constructor helper
00122   void setupForDefaultMu();
00123 
00124   // algorithm helper methods - all static since the shoot methods mayneed them
00125   static long poissonDeviateSmall ( HepRandomEngine * e, double mean );
00126   static long poissonDeviateQuick ( HepRandomEngine * e, double mean );
00127   static long poissonDeviateQuick ( HepRandomEngine * e, 
00128                 double A0, double A1, double A2, double sig );
00129 
00130   // All the engine info, and the default mean, are in the 
00131   // RandPoisson base class.
00132 
00133   // quantities for approximate Poisson by corrected Gaussian
00134   double a0;      
00135   double a1;            
00136   double a2;    
00137   double sigma;  
00138 
00139   // static data - constants only, so that saveEngineStatus works properly!
00140 
00141   // The following MUST MATCH the corresponding values used (in 
00142   // poissonTables.cc) when poissonTables.cdat was created.  
00143   // poissonTables.cc gets these values by including this header, 
00144   // but we must be careful not to change these values,
00145   // and rebuild RandPoissonQ before re-generating poissonTables.cdat.
00146 
00147   // (These statics are given values near the start of the .cc file) 
00148 
00149   static const double FIRST_MU;  // lowest mu value in table
00150   static const double LAST_MU;   // highest mu value
00151   static const double S;         // Spacing between mu values
00152   static const int BELOW;        // Starting point for N is at mu - BELOW
00153   static const int ENTRIES;      // Number of entries in each mu row
00154 
00155 };
00156 
00157 }  // namespace CLHEP
00158 
00159 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00160 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00161 using namespace CLHEP;
00162 #endif
00163 
00164 #include "CLHEP/Random/RandPoissonQ.icc"
00165 
00166 #endif

Generated on Thu Jul 1 22:02:30 2010 for CLHEP by  doxygen 1.4.7