CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: RandBinomial.h,v 1.5 2010/06/16 17:24:53 garren Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- RandBinomial --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 00010 // Class defining methods for shooting binomial distributed random values, 00011 // given a sample size n (default=1) and a probability p (default=0.5). 00012 // Default values are used for operator()(). 00013 // 00014 // Valid input values satisfy the relation n*min(p,1-p) > 0. When invalid 00015 // values are presented, the code silently returns -1.0. 00016 00017 // ======================================================================= 00018 // John Marraffino - Created: 12th May 1998 Based on the C-Rand package 00019 // by Ernst Stadlober and Franz Niederl of the Technical 00020 // University of Graz, Austria. 00021 // Gabriele Cosmo - Removed useless methods and data: 5th Jan 1999 00022 // M Fischler - put and get to/from streams 12/10/04 00023 // ======================================================================= 00024 00025 #ifndef RandBinomial_h 00026 #define RandBinomial_h 1 00027 00028 #include "CLHEP/Random/Random.h" 00029 #include "CLHEP/Utility/memory.h" 00030 00031 namespace CLHEP { 00032 00037 class RandBinomial : public HepRandom { 00038 00039 public: 00040 00041 inline RandBinomial ( HepRandomEngine& anEngine, long n=1, 00042 double p=0.5 ); 00043 inline RandBinomial ( HepRandomEngine* anEngine, long n=1, 00044 double p=0.5 ); 00045 // These constructors should be used to instantiate a RandBinomial 00046 // distribution object defining a local engine for it. 00047 // The static generator will be skipped using the non-static methods 00048 // defined below. 00049 // If the engine is passed by pointer the corresponding engine object 00050 // will be deleted by the RandBinomial destructor. 00051 // If the engine is passed by reference the corresponding engine object 00052 // will not be deleted by the RandBinomial destructor. 00053 00054 virtual ~RandBinomial(); 00055 // Destructor 00056 00057 // Static methods to shoot random values using the static generator 00058 00059 static inline double shoot(); 00060 00061 static double shoot( long n, double p ); 00062 00063 static void shootArray ( const int size, double* vect, 00064 long n=1, double p=0.5 ); 00065 00066 // Static methods to shoot random values using a given engine 00067 // by-passing the static generator. 00068 00069 static inline double shoot( HepRandomEngine* anEngine ); 00070 00071 static double shoot( HepRandomEngine* anEngine, 00072 long n, double p ); 00073 00074 static void shootArray ( HepRandomEngine* anEngine, const int size, 00075 double* vect, long n=1, 00076 double p=0.5 ); 00077 00078 // Methods using the localEngine to shoot random values, by-passing 00079 // the static generator. 00080 00081 inline double fire(); 00082 00083 double fire( long n, double p ); 00084 00085 void fireArray ( const int size, double* vect); 00086 void fireArray ( const int size, double* vect, 00087 long n, double p ); 00088 inline double operator()(); 00089 inline double operator()( long n, double p ); 00090 00091 // Save and restore to/from streams 00092 00093 std::ostream & put ( std::ostream & os ) const; 00094 std::istream & get ( std::istream & is ); 00095 00096 std::string name() const; 00097 HepRandomEngine & engine(); 00098 00099 static std::string distributionName() {return "RandBinomial";} 00100 // Provides the name of this distribution class 00101 00102 private: 00103 00104 static double genBinomial( HepRandomEngine *anEngine, long n, double p ); 00105 00106 shared_ptr<HepRandomEngine> localEngine; 00107 long defaultN; 00108 double defaultP; 00109 00110 }; 00111 00112 } // namespace CLHEP 00113 00114 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00115 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00116 using namespace CLHEP; 00117 #endif 00118 00119 #include "CLHEP/Random/RandBinomial.icc" 00120 00121 #endif