CLHEP/Random/RandPoisson.h

00001 // $Id: RandPoisson.h,v 1.14 2002/04/12 15:02:45 evc Exp $
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                             HEP Random
00006 //                         --- RandPoisson ---
00007 //                          class header file
00008 // -----------------------------------------------------------------------
00009 // This file is part of Geant4 (simulation toolkit for HEP).
00010 
00011 // Class defining methods for shooting numbers according to the Poisson
00012 // distribution, given a mean (Algorithm taken from "W.H.Press et al.,
00013 // Numerical Recipes in C, Second Edition".
00014 // Default mean value is set to 1, value used for operator()().
00015 
00016 // =======================================================================
00017 // Gabriele Cosmo - Created: 5th September 1995
00018 //                - Added not static Shoot() method: 17th May 1996
00019 //                - Algorithm now operates on doubles : 31st Oct 1996
00020 //                - Added methods to shoot arrays: 28th July 1997
00021 // J.Marraffino   - Added default mean as attribute and
00022 //                  operator() with mean: 16th Feb 1998
00023 // Gabriele Cosmo - Relocated static data from HepRandom: 5th Jan 1999
00024 // M. Fischler    - Moved meanMax and defaultMean from private to protected
00025 //                  to accomodate derived classes RandPoissonQ & RandPoissonT
00026 // =======================================================================
00027 
00028 #ifndef RandPoisson_h
00029 #define RandPoisson_h 1
00030 
00031 #include "CLHEP/Random/Random.h"
00032 
00037 class RandPoisson : public HepRandom {
00038 
00039 public:
00040 
00041   inline RandPoisson ( HepRandomEngine& anEngine, double m=1.0 );
00042   inline RandPoisson ( HepRandomEngine* anEngine, double m=1.0 );
00043   // These constructors should be used to instantiate a RandPoisson
00044   // distribution object defining a local engine for it.
00045   // The static generator will be skipped using the non-static methods
00046   // defined below.
00047   // If the engine is passed by pointer the corresponding engine object
00048   // will be deleted by the RandPoisson destructor.
00049   // If the engine is passed by reference the corresponding engine object
00050   // will not be deleted by the RandPoisson destructor.
00051 
00052   virtual ~RandPoisson();
00053   // Destructor
00054 
00055   // Static methods to shoot random values using the static generator
00056 
00057   static  long shoot( double m=1.0 );
00058 
00059   static  void shootArray ( const int size, long* vect, double m=1.0 );
00060 
00061   //  Static methods to shoot random values using a given engine
00062   //  by-passing the static generator.
00063 
00064   static  long shoot( HepRandomEngine* anEngine, double m=1.0 );
00065 
00066   static  void shootArray ( HepRandomEngine* anEngine,
00067                             const int size, long* vect, double m=1.0 );
00068 
00069   //  Methods using the localEngine to shoot random values, by-passing
00070   //  the static generator.
00071 
00072   long  fire();
00073   long  fire( double m );
00074 
00075   void fireArray ( const int size, long* vect );
00076   void fireArray ( const int size, long* vect, double m);
00077 
00078   double operator()();
00079   double operator()( double m );
00080   
00081 
00082 protected:
00083 
00084   // Protected copy constructor. Defining it here disallows user use.
00085   RandPoisson(const RandPoisson& d);
00086 
00087   const double meanMax;
00088   const double defaultMean;
00089 
00090   static  double getOldMean() {return oldm_st;}
00091 
00092   static  double getMaxMean() {return meanMax_st;}
00093 
00094   static  void setOldMean( double val ){oldm_st = val;}
00095 
00096   static  double* getPStatus() {return status_st;}
00097 
00098   static void setPStatus(double sq, double alxm, double g) {
00099     status_st[0] = sq; status_st[1] = alxm; status_st[2] = g;
00100   }
00101 
00102   inline HepRandomEngine* getLocalEngine();
00103   
00104 private:
00105 
00106   HepRandomEngine* localEngine;
00107   bool deleteEngine;
00108   double status[3], oldm;
00109 
00110   // static data
00111   static double status_st[3];
00112   static double oldm_st;
00113   static const double meanMax_st;
00114 
00115 };
00116 
00117 #include "CLHEP/Random/RandPoisson.icc"
00118 
00119 #endif

Class Library for High Energy Physics (version 1.8)