CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Random/Random/RandPoissonQ.h
Go to the documentation of this file.
1 // $Id: RandPoissonQ.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- RandPoissonQ ---
7 // class header file
8 // -----------------------------------------------------------------------
9 
10 // Class defining RandPoissonQ, which is derived from RandPoison.
11 // The user interface is identical; but RandGaussQ is much faster in all cases
12 // and a bit less accurate when mu > 100.
13 
14 // =======================================================================
15 // M. Fischler - Created: 4th Feb 2000
16 // M Fischler - put and get to/from streams 12/10/04
17 //
18 // =======================================================================
19 
20 #ifndef RandPoissonQ_h
21 #define RandPoissonQ_h 1
22 
23 #include "CLHEP/Random/defs.h"
24 #include "CLHEP/Random/Random.h"
25 #include "CLHEP/Random/RandPoisson.h"
26 
27 namespace CLHEP {
28 
33 class RandPoissonQ : public RandPoisson {
34 
35 public:
36 
37  inline RandPoissonQ ( HepRandomEngine& anEngine, double b1=1.0 );
38  inline RandPoissonQ ( HepRandomEngine* anEngine, double b1=1.0 );
39  // These constructors should be used to instantiate a RandPoissonQ
40  // distribution object defining a local engine for it.
41  // The static generator will be skipped using the non-static methods
42  // defined below.
43  // If the engine is passed by pointer the corresponding engine object
44  // will be deleted by the RandPoissonQ destructor.
45  // If the engine is passed by reference the corresponding engine object
46  // will not be deleted by the RandPoissonQ destructor.
47 
48  virtual ~RandPoissonQ();
49  // Destructor
50 
51  // Save and restore to/from streams
52 
53  std::ostream & put ( std::ostream & os ) const;
54  std::istream & get ( std::istream & is );
55 
56  // Methods to generate Poisson-distributed random deviates.
57 
58  // The method used for mu <= 100 is exact, and 3-7 times faster than
59  // that used by RandPoisson.
60  // For mu > 100 then we use a corrected version of a
61  // (quick) Gaussian approximation. Naively that would be:
62  //
63  // Poisson(mu) ~ floor( mu + .5 + Gaussian(sqrt(mu)) )
64  //
65  // but actually, that would give a slightly incorrect sigma and a
66  // very different skew than a true Poisson. Instead we return
67  //
68  // Poisson(mu) ~ floor( a0*mu + a1*g + a2*g*g ) )
69  // (with g a gaussian normal)
70  //
71  // where a0, a1, a2 are chosen to give the exctly correct mean, sigma,
72  // and skew for the Poisson distribution.
73 
74  // Static methods to shoot random values using the static generator
75 
76  static long shoot( double m=1.0 );
77 
78  static void shootArray ( const int size, long* vect, double m=1.0 );
79 
80  // Static methods to shoot random values using a given engine
81  // by-passing the static generator.
82 
83  static long shoot( HepRandomEngine* anEngine, double m=1.0 );
84 
85  static void shootArray ( HepRandomEngine* anEngine,
86  const int size, long* vect, double m=1.0 );
87 
88  // Methods using the localEngine to shoot random values, by-passing
89  // the static generator.
90 
91  long fire();
92  long fire( double m );
93 
94  void fireArray ( const int size, long* vect );
95  void fireArray ( const int size, long* vect, double m);
96 
97  double operator()();
98  double operator()( double m );
99 
100  std::string name() const;
101  HepRandomEngine & engine();
102 
103  static std::string distributionName() {return "RandPoissonQ";}
104  // Provides the name of this distribution class
105 
106 
107  // static constants of possible interest to users:
108 
109  // RandPoisson will never return a deviate greater than this value:
110  static const double MAXIMUM_POISSON_DEVIATE; // Will be 2.0E9
111 
112  static inline int tableBoundary();
113 
114 private:
115 
116  // constructor helper
117  void setupForDefaultMu();
118 
119  // algorithm helper methods - all static since the shoot methods mayneed them
120  static long poissonDeviateSmall ( HepRandomEngine * e, double mean );
121  static long poissonDeviateQuick ( HepRandomEngine * e, double mean );
122  static long poissonDeviateQuick ( HepRandomEngine * e,
123  double A0, double A1, double A2, double sig );
124 
125  // All the engine info, and the default mean, are in the
126  // RandPoisson base class.
127 
128  // quantities for approximate Poisson by corrected Gaussian
129  double a0;
130  double a1;
131  double a2;
132  double sigma;
133 
134  // static data - constants only, so that saveEngineStatus works properly!
135 
136  // The following MUST MATCH the corresponding values used (in
137  // poissonTables.cc) when poissonTables.cdat was created.
138  // poissonTables.cc gets these values by including this header,
139  // but we must be careful not to change these values,
140  // and rebuild RandPoissonQ before re-generating poissonTables.cdat.
141 
142  // (These statics are given values near the start of the .cc file)
143 
144  static const double FIRST_MU; // lowest mu value in table
145  static const double LAST_MU; // highest mu value
146  static const double S; // Spacing between mu values
147  static const int BELOW; // Starting point for N is at mu - BELOW
148  static const int ENTRIES; // Number of entries in each mu row
149 
150 };
151 
152 } // namespace CLHEP
153 
154 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
155 // backwards compatibility will be enabled ONLY in CLHEP 1.9
156 using namespace CLHEP;
157 #endif
158 
159 #include "CLHEP/Random/RandPoissonQ.icc"
160 
161 #endif
CLHEP::RandPoissonQ::~RandPoissonQ
virtual ~RandPoissonQ()
Definition: RandPoissonQ.cc:81
CLHEP::RandPoissonQ::shootArray
static void shootArray(const int size, long *vect, double m=1.0)
Definition: RandPoissonQ.cc:173
CLHEP::RandPoissonQ::fire
long fire()
Definition: RandPoissonQ.cc:134
CLHEP::HepRandomEngine
Definition: Matrix/CLHEP/Random/RandomEngine.h:55
is
HepRotation and so forth isNear() norm2() rectify() static Rotation row1 row4(To avoid bloat in the code pulled in for programs which don 't use all these features, we split the implementation .cc files. Only isNear() goes into the original Rotation.cc) --------------------------------------- HepAxisAngle and HepEulerAngles classes --------------------------------------- These classes are very useful and simple structures for holding the result of a nice intuituve decomposition of a rotation there is no longer much content in the distinct ZOOM PhysicsVectors library The only content left in the library is the object files representing the various Exception objects When we build the CLHEP classes for the ZOOM we will set up so as to use ZOOM SpaceVector is(but we can disable namespace usage and most of our users do so at this point). What I do is leave Hep3Vector in the global namespace
CLHEP::RandPoissonQ::fireArray
void fireArray(const int size, long *vect)
Definition: RandPoissonQ.cc:186
CLHEP::RandPoissonQ::shoot
static long shoot(double m=1.0)
Definition: RandPoissonQ.cc:118
CLHEP::RandPoissonQ::RandPoissonQ
RandPoissonQ(HepRandomEngine &anEngine, double b1=1.0)
size
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno size() Return the(integer) number of ZMthrow 'n exceptions currently recorded. 5) ZMerrno.clear() Set an internal counter to zero. This counter is available(see next function) to user code to track ZMthrow 'n exceptions that have occurred during any arbitrary time interval. 6) ZMerrno.countSinceCleared() Return the(integer) number of ZMthrow 'n exceptions that have been recorded via ZMerrno.write()
CLHEP::RandPoissonQ::engine
HepRandomEngine & engine()
Definition: RandPoissonQ.cc:50
CLHEP
Definition: ClhepVersion.h:13
CLHEP::RandPoissonQ::MAXIMUM_POISSON_DEVIATE
static const double MAXIMUM_POISSON_DEVIATE
Definition: Matrix/CLHEP/Random/RandPoissonQ.h:110
CLHEP::RandPoissonQ::tableBoundary
static int tableBoundary()
CLHEP::RandPoissonQ::name
std::string name() const
Definition: RandPoissonQ.cc:49
CLHEP::RandPoissonQ::put
std::ostream & put(std::ostream &os) const
Definition: RandPoissonQ.cc:546
CLHEP::RandPoissonQ::get
std::istream & get(std::istream &is)
Definition: RandPoissonQ.cc:573
CLHEP::RandPoissonQ::distributionName
static std::string distributionName()
Definition: Random/Random/RandPoissonQ.h:103
CLHEP::RandPoissonQ::operator()
double operator()()
Definition: RandPoissonQ.cc:122