Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 09:06:15

0001 // $Id: RandPoissonQ.h,v 1.5 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                             HEP Random
0006 //                         --- RandPoissonQ ---
0007 //                          class header file
0008 // -----------------------------------------------------------------------
0009 
0010 // Class defining RandPoissonQ, which is derived from RandPoison.
0011 // The user interface is identical; but RandGaussQ is much faster in all cases
0012 // and a bit less accurate when mu > 100.
0013 
0014 // =======================================================================
0015 // M. Fischler - Created: 4th Feb 2000
0016 // M Fischler      - put and get to/from streams 12/10/04
0017 //
0018 // =======================================================================
0019 
0020 #ifndef RandPoissonQ_h
0021 #define RandPoissonQ_h 1
0022 
0023 #include "CLHEP/Random/defs.h"
0024 #include "CLHEP/Random/Random.h"
0025 #include "CLHEP/Random/RandPoisson.h"
0026 
0027 namespace CLHEP {
0028 
0029 /**
0030  * @author
0031  * @ingroup random
0032  */
0033 class RandPoissonQ : public RandPoisson {
0034 
0035 public:
0036 
0037   inline RandPoissonQ ( HepRandomEngine& anEngine, double b1=1.0 );
0038   inline RandPoissonQ ( HepRandomEngine* anEngine, double b1=1.0 );
0039   // These constructors should be used to instantiate a RandPoissonQ
0040   // distribution object defining a local engine for it.
0041   // The static generator will be skipped using the non-static methods
0042   // defined below.
0043   // If the engine is passed by pointer the corresponding engine object
0044   // will be deleted by the RandPoissonQ destructor.
0045   // If the engine is passed by reference the corresponding engine object
0046   // will not be deleted by the RandPoissonQ destructor.
0047 
0048   virtual ~RandPoissonQ();
0049   // Destructor
0050 
0051   // Save and restore to/from streams
0052   
0053   std::ostream & put ( std::ostream & os ) const;
0054   std::istream & get ( std::istream & is );
0055 
0056   // Methods to generate Poisson-distributed random deviates.
0057 
0058   //   The method used for mu <= 100 is exact, and 3-7 times faster than
0059   //   that used by RandPoisson.  
0060   //   For mu > 100 then we use a corrected version of a 
0061   //   (quick) Gaussian approximation.  Naively that would be:
0062   //
0063   //    Poisson(mu) ~ floor( mu + .5 + Gaussian(sqrt(mu)) )
0064   //
0065   //   but actually, that would give a slightly incorrect sigma and a 
0066   //   very different skew than a true Poisson.  Instead we return 
0067   // 
0068   //    Poisson(mu) ~ floor( a0*mu + a1*g + a2*g*g ) )
0069   //                        (with g a gaussian normal)
0070   //
0071   //   where a0, a1, a2 are chosen to give the exctly correct mean, sigma,
0072   //   and skew for the Poisson distribution.
0073 
0074   // Static methods to shoot random values using the static generator
0075 
0076   static  long shoot( double mean=1.0 );
0077 
0078   static  void shootArray ( const int size, long* vect, double mean=1.0 );
0079 
0080   //  Static methods to shoot random values using a given engine
0081   //  by-passing the static generator.
0082 
0083   static  long shoot( HepRandomEngine* anEngine, double mean=1.0 );
0084 
0085   static  void shootArray ( HepRandomEngine* anEngine,
0086                             const int size, long* vect, double mean=1.0 );
0087 
0088   //  Methods using the localEngine to shoot random values, by-passing
0089   //  the static generator.
0090 
0091   long  fire();
0092   long  fire( double mean );
0093 
0094   void fireArray ( const int size, long* vect );
0095   void fireArray ( const int size, long* vect, double mean);
0096 
0097   double operator()();
0098   double operator()( double mean );
0099 
0100   std::string name() const;
0101   HepRandomEngine & engine();
0102 
0103   static std::string distributionName() {return "RandPoissonQ";}  
0104   // Provides the name of this distribution class
0105 
0106   
0107   // static constants of possible interest to users:
0108 
0109   // RandPoisson will never return a deviate greater than this value:
0110   static const double MAXIMUM_POISSON_DEVIATE; // Will be 2.0E9
0111 
0112   static inline int tableBoundary();
0113 
0114 private:
0115 
0116   // constructor helper
0117   void setupForDefaultMu();
0118 
0119   // algorithm helper methods - all static since the shoot methods mayneed them
0120   static long poissonDeviateSmall ( HepRandomEngine * e, double mean );
0121   static long poissonDeviateQuick ( HepRandomEngine * e, double mean );
0122   static long poissonDeviateQuick ( HepRandomEngine * e, 
0123         double A0, double A1, double A2, double sig );
0124 
0125   // All the engine info, and the default mean, are in the 
0126   // RandPoisson base class.
0127 
0128   // quantities for approximate Poisson by corrected Gaussian
0129   double a0;      
0130   double a1;            
0131   double a2;    
0132   double sigma;  
0133 
0134   // static data - constants only, so that saveEngineStatus works properly!
0135 
0136   // The following MUST MATCH the corresponding values used (in 
0137   // poissonTables.cc) when poissonTables.cdat was created.  
0138   // poissonTables.cc gets these values by including this header, 
0139   // but we must be careful not to change these values,
0140   // and rebuild RandPoissonQ before re-generating poissonTables.cdat.
0141 
0142   // (These statics are given values near the start of the .cc file) 
0143 
0144   static const double FIRST_MU;  // lowest mu value in table
0145   static const double LAST_MU;   // highest mu value
0146   static const double S;         // Spacing between mu values
0147   static const int BELOW;        // Starting point for N is at mu - BELOW
0148   static const int ENTRIES;      // Number of entries in each mu row
0149 
0150 };
0151 
0152 }  // namespace CLHEP
0153 
0154 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0155 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0156 using namespace CLHEP;
0157 #endif
0158 
0159 #include "CLHEP/Random/RandPoissonQ.icc"
0160 
0161 #endif