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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 // -*- C++ -*-
  2 //
  3 // -----------------------------------------------------------------------
  4 //                             HEP Random
  5 //                         --- RandPoissonQ ---
  6 //                          class header file
  7 // -----------------------------------------------------------------------
  8 
  9 // Class defining RandPoissonQ, which is derived from RandPoison.
 10 // The user interface is identical; but RandGaussQ is much faster in all cases
 11 // and a bit less accurate when mu > 100.
 12 
 13 // =======================================================================
 14 // M. Fischler - Created: 4th Feb 2000
 15 // M Fischler      - put and get to/from streams 12/10/04
 16 //
 17 // =======================================================================
 18 
 19 #ifndef RandPoissonQ_h
 20 #define RandPoissonQ_h 1
 21 
 22 #include "CLHEP/Random/Random.h"
 23 #include "CLHEP/Random/RandPoisson.h"
 24 
 25 namespace CLHEP {
 26 
 27 /**
 28  * @author
 29  * @ingroup random
 30  */
 31 class RandPoissonQ : public RandPoisson {
 32 
 33 public:
 34 
 35   inline RandPoissonQ ( HepRandomEngine& anEngine, double b1=1.0 );
 36   inline RandPoissonQ ( HepRandomEngine* anEngine, double b1=1.0 );
 37   // These constructors should be used to instantiate a RandPoissonQ
 38   // distribution object defining a local engine for it.
 39   // The static generator will be skipped using the non-static methods
 40   // defined below.
 41   // If the engine is passed by pointer the corresponding engine object
 42   // will be deleted by the RandPoissonQ destructor.
 43   // If the engine is passed by reference the corresponding engine object
 44   // will not be deleted by the RandPoissonQ destructor.
 45 
 46   virtual ~RandPoissonQ();
 47   // Destructor
 48 
 49   // Save and restore to/from streams
 50   
 51   std::ostream & put ( std::ostream & os ) const;
 52   std::istream & get ( std::istream & is );
 53 
 54   // Methods to generate Poisson-distributed random deviates.
 55 
 56   //   The method used for mu <= 100 is exact, and 3-7 times faster than
 57   //   that used by RandPoisson.  
 58   //   For mu > 100 then we use a corrected version of a 
 59   //   (quick) Gaussian approximation.  Naively that would be:
 60   //
 61   //  Poisson(mu) ~ floor( mu + .5 + Gaussian(sqrt(mu)) )
 62   //
 63   //   but actually, that would give a slightly incorrect sigma and a 
 64   //   very different skew than a true Poisson.  Instead we return 
 65   // 
 66   //  Poisson(mu) ~ floor( a0*mu + a1*g + a2*g*g ) )
 67   //            (with g a gaussian normal)
 68   //
 69   //   where a0, a1, a2 are chosen to give the exctly correct mean, sigma,
 70   //   and skew for the Poisson distribution.
 71 
 72   // Static methods to shoot random values using the static generator
 73 
 74   static  long shoot( double mean=1.0 );
 75 
 76   static  void shootArray ( const int size, long* vect, double mean=1.0 );
 77 
 78   //  Static methods to shoot random values using a given engine
 79   //  by-passing the static generator.
 80 
 81   static  long shoot( HepRandomEngine* anEngine, double mean=1.0 );
 82 
 83   static  void shootArray ( HepRandomEngine* anEngine,
 84                             const int size, long* vect, double mean=1.0 );
 85 
 86   //  Methods using the localEngine to shoot random values, by-passing
 87   //  the static generator.
 88 
 89   long  fire();
 90   long  fire( double mean );
 91 
 92   void fireArray ( const int size, long* vect );
 93   void fireArray ( const int size, long* vect, double mean);
 94 
 95   double operator()();
 96   double operator()( double mean );
 97 
 98   std::string name() const;
 99   HepRandomEngine & engine();
100 
101   static std::string distributionName() {return "RandPoissonQ";}  
102   // Provides the name of this distribution class
103 
104   
105   // static constants of possible interest to users:
106 
107   // RandPoisson will never return a deviate greater than this value:
108   static const double MAXIMUM_POISSON_DEVIATE; // Will be 2.0E9
109 
110   static inline int tableBoundary();
111 
112 private:
113 
114   // constructor helper
115   void setupForDefaultMu();
116 
117   // algorithm helper methods - all static since the shoot methods mayneed them
118   static long poissonDeviateSmall ( HepRandomEngine * e, double mean );
119   static long poissonDeviateQuick ( HepRandomEngine * e, double mean );
120   static long poissonDeviateQuick ( HepRandomEngine * e, 
121     double A0, double A1, double A2, double sig );
122 
123   // All the engine info, and the default mean, are in the 
124   // RandPoisson base class.
125 
126   // quantities for approximate Poisson by corrected Gaussian
127   double a0;      
128   double a1;        
129   double a2;  
130   double sigma;  
131 
132   // static data - constants only, so that saveEngineStatus works properly!
133 
134   // The following MUST MATCH the corresponding values used (in 
135   // poissonTables.cc) when poissonTables.cdat was created.  
136   // poissonTables.cc gets these values by including this header, 
137   // but we must be careful not to change these values,
138   // and rebuild RandPoissonQ before re-generating poissonTables.cdat.
139 
140   // (These statics are given values near the start of the .cc file) 
141 
142   static const double FIRST_MU;  // lowest mu value in table
143   static const double LAST_MU;   // highest mu value
144   static const double S;         // Spacing between mu values
145   static const int BELOW;        // Starting point for N is at mu - BELOW
146   static const int ENTRIES;      // Number of entries in each mu row
147 
148 };
149 
150 }  // namespace CLHEP
151 
152 #include "CLHEP/Random/RandPoissonQ.icc"
153 
154 #endif
155