Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:38

0001 // $Id: RandPoisson.h,v 1.5 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                             HEP Random
0006 //                         --- RandPoisson ---
0007 //                          class header file
0008 // -----------------------------------------------------------------------
0009 // This file is part of Geant4 (simulation toolkit for HEP).
0010 
0011 // Class defining methods for shooting numbers according to the Poisson
0012 // distribution, given a mean (Algorithm taken from "W.H.Press et al.,
0013 // Numerical Recipes in C, Second Edition".
0014 // Default mean value is set to 1, value used for operator()().
0015 
0016 // =======================================================================
0017 // Gabriele Cosmo - Created: 5th September 1995
0018 //                - Added not static Shoot() method: 17th May 1996
0019 //                - Algorithm now operates on doubles : 31st Oct 1996
0020 //                - Added methods to shoot arrays: 28th July 1997
0021 // J.Marraffino   - Added default mean as attribute and
0022 //                  operator() with mean: 16th Feb 1998
0023 // Gabriele Cosmo - Relocated static data from HepRandom: 5th Jan 1999
0024 // M. Fischler    - Moved meanMax and defaultMean from private to protected
0025 //          to accomodate derived classes RandPoissonQ & RandPoissonT
0026 // M Fischler      - put and get to/from streams 12/10/04
0027 // =======================================================================
0028 
0029 #ifndef RandPoisson_h
0030 #define RandPoisson_h 1
0031 
0032 #include "CLHEP/Random/defs.h"
0033 #include "CLHEP/Random/Random.h"
0034 #include "CLHEP/Utility/memory.h"
0035 #include "CLHEP/Utility/thread_local.h"
0036 
0037 namespace CLHEP {
0038 
0039 /**
0040  * @author
0041  * @ingroup random
0042  */
0043 class RandPoisson : public HepRandom {
0044 
0045 public:
0046 
0047   inline RandPoisson ( HepRandomEngine& anEngine, double a1=1.0 );
0048   inline RandPoisson ( HepRandomEngine* anEngine, double a1=1.0 );
0049   // These constructors should be used to instantiate a RandPoisson
0050   // distribution object defining a local engine for it.
0051   // The static generator will be skipped using the non-static methods
0052   // defined below.
0053   // If the engine is passed by pointer the corresponding engine object
0054   // will be deleted by the RandPoisson destructor.
0055   // If the engine is passed by reference the corresponding engine object
0056   // will not be deleted by the RandPoisson destructor.
0057 
0058   virtual ~RandPoisson();
0059   // Destructor
0060 
0061   // Save and restore to/from streams
0062   
0063   std::ostream & put ( std::ostream & os ) const;
0064   std::istream & get ( std::istream & is );
0065 
0066   // Static methods to shoot random values using the static generator
0067 
0068   static  long shoot( double mean=1.0 );
0069 
0070   static  void shootArray ( const int size, long* vect, double mean=1.0 );
0071 
0072   //  Static methods to shoot random values using a given engine
0073   //  by-passing the static generator.
0074 
0075   static  long shoot( HepRandomEngine* anEngine, double mean=1.0 );
0076 
0077   static  void shootArray ( HepRandomEngine* anEngine,
0078                             const int size, long* vect, double mean=1.0 );
0079 
0080   //  Methods using the localEngine to shoot random values, by-passing
0081   //  the static generator.
0082 
0083   long  fire();
0084   long  fire( double mean );
0085 
0086   void fireArray ( const int size, long* vect );
0087   void fireArray ( const int size, long* vect, double mean);
0088 
0089   double operator()();
0090   double operator()( double mean );
0091   
0092   std::string name() const;
0093   HepRandomEngine & engine();
0094 
0095   static std::string distributionName() {return "RandPoisson";}  
0096   // Provides the name of this distribution class
0097 
0098 protected:
0099 
0100   double meanMax;
0101   double defaultMean;
0102 
0103   static  double getOldMean() {return oldm_st;}
0104 
0105   static  double getMaxMean() {return meanMax_st;}
0106 
0107   static  void setOldMean( double val ){oldm_st = val;}
0108 
0109   static  double* getPStatus() {return status_st;}
0110 
0111   static void setPStatus(double sq, double alxm, double g1) {
0112     status_st[0] = sq; status_st[1] = alxm; status_st[2] = g1;
0113   }
0114 
0115   inline HepRandomEngine* getLocalEngine();
0116   
0117 private:
0118 
0119   std::shared_ptr<HepRandomEngine> localEngine;
0120   double status[3], oldm;
0121 
0122   // static data
0123   static CLHEP_THREAD_LOCAL double status_st[3];
0124   static CLHEP_THREAD_LOCAL double oldm_st;
0125   static const double meanMax_st;
0126 
0127 };
0128 
0129 }  // namespace CLHEP
0130 
0131 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0132 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0133 using namespace CLHEP;
0134 #endif
0135 
0136 #include "CLHEP/Random/RandPoisson.icc"
0137 
0138 #endif