CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: RandBinomial.h,v 1.3.4.1 2005/03/18 22:26:48 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 00030 namespace CLHEP { 00031 00036 class RandBinomial : public HepRandom { 00037 00038 public: 00039 00040 inline RandBinomial ( HepRandomEngine& anEngine, long n=1, 00041 double p=0.5 ); 00042 inline RandBinomial ( HepRandomEngine* anEngine, long n=1, 00043 double p=0.5 ); 00044 // These constructors should be used to instantiate a RandBinomial 00045 // distribution object defining a local engine for it. 00046 // The static generator will be skipped using the non-static methods 00047 // defined below. 00048 // If the engine is passed by pointer the corresponding engine object 00049 // will be deleted by the RandBinomial destructor. 00050 // If the engine is passed by reference the corresponding engine object 00051 // will not be deleted by the RandBinomial destructor. 00052 00053 virtual ~RandBinomial(); 00054 // Destructor 00055 00056 // Static methods to shoot random values using the static generator 00057 00058 static inline double shoot(); 00059 00060 static double shoot( long n, double p ); 00061 00062 static void shootArray ( const int size, double* vect, 00063 long n=1, double p=0.5 ); 00064 00065 // Static methods to shoot random values using a given engine 00066 // by-passing the static generator. 00067 00068 static inline double shoot( HepRandomEngine* anEngine ); 00069 00070 static double shoot( HepRandomEngine* anEngine, 00071 long n, double p ); 00072 00073 static void shootArray ( HepRandomEngine* anEngine, const int size, 00074 double* vect, long n=1, 00075 double p=0.5 ); 00076 00077 // Methods using the localEngine to shoot random values, by-passing 00078 // the static generator. 00079 00080 inline double fire(); 00081 00082 double fire( long n, double p ); 00083 00084 void fireArray ( const int size, double* vect); 00085 void fireArray ( const int size, double* vect, 00086 long n, double p ); 00087 inline double operator()(); 00088 inline double operator()( long n, double p ); 00089 00090 // Save and restore to/from streams 00091 00092 std::ostream & put ( std::ostream & os ) const; 00093 std::istream & get ( std::istream & is ); 00094 00095 std::string name() const; 00096 HepRandomEngine & engine(); 00097 00098 static std::string distributionName() {return "RandBinomial";} 00099 // Provides the name of this distribution class 00100 00101 private: 00102 00103 // Private copy constructor. Defining it here disallows use. 00104 RandBinomial(const RandBinomial& d); 00105 00106 static double genBinomial( HepRandomEngine *anEngine, long n, double p ); 00107 00108 HepRandomEngine* localEngine; 00109 bool deleteEngine; 00110 long defaultN; 00111 double defaultP; 00112 00113 }; 00114 00115 } // namespace CLHEP 00116 00117 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00118 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00119 using namespace CLHEP; 00120 #endif 00121 00122 #include "CLHEP/Random/RandBinomial.icc" 00123 00124 #endif