Geant4 Cross Reference |
1 // -*- C++ -*- 1 // -*- C++ -*- 2 // 2 // 3 // ------------------------------------------- 3 // ----------------------------------------------------------------------- 4 // HEP Random 4 // HEP Random 5 // --- RandBinomial -- 5 // --- RandBinomial --- 6 // class header file 6 // class header file 7 // ------------------------------------------- 7 // ----------------------------------------------------------------------- 8 8 9 // Class defining methods for shooting binomia 9 // Class defining methods for shooting binomial distributed random values, 10 // given a sample size n (default=1) and a pro 10 // given a sample size n (default=1) and a probability p (default=0.5). 11 // Default values are used for operator()(). 11 // Default values are used for operator()(). 12 // 12 // 13 // Valid input values satisfy the relation n*m 13 // Valid input values satisfy the relation n*min(p,1-p) > 0. When invalid 14 // values are presented, the code silently ret 14 // values are presented, the code silently returns -1.0. 15 15 16 // =========================================== 16 // ======================================================================= 17 // John Marraffino - Created: 12th May 1998 B 17 // John Marraffino - Created: 12th May 1998 Based on the C-Rand package 18 // by Ernst Stadlober and Fr 18 // by Ernst Stadlober and Franz Niederl of the Technical 19 // University of Graz, Austr 19 // University of Graz, Austria. 20 // Gabriele Cosmo - Removed useless methods a 20 // Gabriele Cosmo - Removed useless methods and data: 5th Jan 1999 21 // M Fischler - put and get to/from strea 21 // M Fischler - put and get to/from streams 12/10/04 22 // =========================================== 22 // ======================================================================= 23 23 24 #ifndef RandBinomial_h 24 #ifndef RandBinomial_h 25 #define RandBinomial_h 1 25 #define RandBinomial_h 1 26 26 27 #include "CLHEP/Random/Random.h" 27 #include "CLHEP/Random/Random.h" 28 #include "CLHEP/Utility/memory.h" 28 #include "CLHEP/Utility/memory.h" 29 29 30 namespace CLHEP { 30 namespace CLHEP { 31 31 32 /** 32 /** 33 * @author 33 * @author 34 * @ingroup random 34 * @ingroup random 35 */ 35 */ 36 class RandBinomial : public HepRandom { 36 class RandBinomial : public HepRandom { 37 37 38 public: 38 public: 39 39 40 inline RandBinomial ( HepRandomEngine& anEng 40 inline RandBinomial ( HepRandomEngine& anEngine, long n=1, 41 41 double p=0.5 ); 42 inline RandBinomial ( HepRandomEngine* anEng 42 inline RandBinomial ( HepRandomEngine* anEngine, long n=1, 43 43 double p=0.5 ); 44 // These constructors should be used to inst 44 // These constructors should be used to instantiate a RandBinomial 45 // distribution object defining a local engi 45 // distribution object defining a local engine for it. 46 // The static generator will be skipped usin 46 // The static generator will be skipped using the non-static methods 47 // defined below. 47 // defined below. 48 // If the engine is passed by pointer the co 48 // If the engine is passed by pointer the corresponding engine object 49 // will be deleted by the RandBinomial destr 49 // will be deleted by the RandBinomial destructor. 50 // If the engine is passed by reference the 50 // If the engine is passed by reference the corresponding engine object 51 // will not be deleted by the RandBinomial d 51 // will not be deleted by the RandBinomial destructor. 52 52 53 virtual ~RandBinomial(); 53 virtual ~RandBinomial(); 54 // Destructor 54 // Destructor 55 55 56 // Static methods to shoot random values usi 56 // Static methods to shoot random values using the static generator 57 57 58 static inline double shoot(); 58 static inline double shoot(); 59 59 60 static double shoot( long n, double p ); 60 static double shoot( long n, double p ); 61 61 62 static void shootArray ( const int size, dou 62 static void shootArray ( const int size, double* vect, 63 long n=1, double p 63 long n=1, double p=0.5 ); 64 64 65 // Static methods to shoot random values us 65 // Static methods to shoot random values using a given engine 66 // by-passing the static generator. 66 // by-passing the static generator. 67 67 68 static inline double shoot( HepRandomEngine* 68 static inline double shoot( HepRandomEngine* anEngine ); 69 69 70 static double shoot( HepRandomEngine* anEngi 70 static double shoot( HepRandomEngine* anEngine, 71 long n, doub 71 long n, double p ); 72 72 73 static void shootArray ( HepRandomEngine* an 73 static void shootArray ( HepRandomEngine* anEngine, const int size, 74 double* vect, long 74 double* vect, long n=1, 75 double p=0.5 ); 75 double p=0.5 ); 76 76 77 // Methods using the localEngine to shoot r 77 // Methods using the localEngine to shoot random values, by-passing 78 // the static generator. 78 // the static generator. 79 79 80 inline double fire(); 80 inline double fire(); 81 81 82 double fire( long n, double p ); 82 double fire( long n, double p ); 83 83 84 void fireArray ( const int size, double* vec 84 void fireArray ( const int size, double* vect); 85 void fireArray ( const int size, double* vec 85 void fireArray ( const int size, double* vect, 86 long n, double p ); 86 long n, double p ); 87 inline double operator()(); 87 inline double operator()(); 88 inline double operator()( long n, double p ) 88 inline double operator()( long n, double p ); 89 89 90 // Save and restore to/from streams 90 // Save and restore to/from streams 91 91 92 std::ostream & put ( std::ostream & os ) con 92 std::ostream & put ( std::ostream & os ) const; 93 std::istream & get ( std::istream & is ); 93 std::istream & get ( std::istream & is ); 94 94 95 std::string name() const; 95 std::string name() const; 96 HepRandomEngine & engine(); 96 HepRandomEngine & engine(); 97 97 98 static std::string distributionName() {retur 98 static std::string distributionName() {return "RandBinomial";} 99 // Provides the name of this distribution cl 99 // Provides the name of this distribution class 100 100 101 private: 101 private: 102 102 103 static double genBinomial( HepRandomEngine * 103 static double genBinomial( HepRandomEngine *anEngine, long n, double p ); 104 104 105 std::shared_ptr<HepRandomEngine> localEngine 105 std::shared_ptr<HepRandomEngine> localEngine; 106 long defaultN; 106 long defaultN; 107 double defaultP; 107 double defaultP; 108 108 109 }; 109 }; 110 110 111 } // namespace CLHEP 111 } // namespace CLHEP 112 112 113 #include "CLHEP/Random/RandBinomial.icc" 113 #include "CLHEP/Random/RandBinomial.icc" 114 114 115 #endif 115 #endif 116 116