|
||||
File indexing completed on 2025-01-18 09:54:37
0001 // $Id: RandBinomial.h,v 1.5 2010/06/16 17:24:53 garren Exp $ 0002 // -*- C++ -*- 0003 // 0004 // ----------------------------------------------------------------------- 0005 // HEP Random 0006 // --- RandBinomial --- 0007 // class header file 0008 // ----------------------------------------------------------------------- 0009 0010 // Class defining methods for shooting binomial distributed random values, 0011 // given a sample size n (default=1) and a probability p (default=0.5). 0012 // Default values are used for operator()(). 0013 // 0014 // Valid input values satisfy the relation n*min(p,1-p) > 0. When invalid 0015 // values are presented, the code silently returns -1.0. 0016 0017 // ======================================================================= 0018 // John Marraffino - Created: 12th May 1998 Based on the C-Rand package 0019 // by Ernst Stadlober and Franz Niederl of the Technical 0020 // University of Graz, Austria. 0021 // Gabriele Cosmo - Removed useless methods and data: 5th Jan 1999 0022 // M Fischler - put and get to/from streams 12/10/04 0023 // ======================================================================= 0024 0025 #ifndef RandBinomial_h 0026 #define RandBinomial_h 1 0027 0028 #include "CLHEP/Random/Random.h" 0029 #include "CLHEP/Utility/memory.h" 0030 0031 namespace CLHEP { 0032 0033 /** 0034 * @author 0035 * @ingroup random 0036 */ 0037 class RandBinomial : public HepRandom { 0038 0039 public: 0040 0041 inline RandBinomial ( HepRandomEngine& anEngine, long n=1, 0042 double p=0.5 ); 0043 inline RandBinomial ( HepRandomEngine* anEngine, long n=1, 0044 double p=0.5 ); 0045 // These constructors should be used to instantiate a RandBinomial 0046 // distribution object defining a local engine for it. 0047 // The static generator will be skipped using the non-static methods 0048 // defined below. 0049 // If the engine is passed by pointer the corresponding engine object 0050 // will be deleted by the RandBinomial destructor. 0051 // If the engine is passed by reference the corresponding engine object 0052 // will not be deleted by the RandBinomial destructor. 0053 0054 virtual ~RandBinomial(); 0055 // Destructor 0056 0057 // Static methods to shoot random values using the static generator 0058 0059 static inline double shoot(); 0060 0061 static double shoot( long n, double p ); 0062 0063 static void shootArray ( const int size, double* vect, 0064 long n=1, double p=0.5 ); 0065 0066 // Static methods to shoot random values using a given engine 0067 // by-passing the static generator. 0068 0069 static inline double shoot( HepRandomEngine* anEngine ); 0070 0071 static double shoot( HepRandomEngine* anEngine, 0072 long n, double p ); 0073 0074 static void shootArray ( HepRandomEngine* anEngine, const int size, 0075 double* vect, long n=1, 0076 double p=0.5 ); 0077 0078 // Methods using the localEngine to shoot random values, by-passing 0079 // the static generator. 0080 0081 inline double fire(); 0082 0083 double fire( long n, double p ); 0084 0085 void fireArray ( const int size, double* vect); 0086 void fireArray ( const int size, double* vect, 0087 long n, double p ); 0088 inline double operator()(); 0089 inline double operator()( long n, double p ); 0090 0091 // Save and restore to/from streams 0092 0093 std::ostream & put ( std::ostream & os ) const; 0094 std::istream & get ( std::istream & is ); 0095 0096 std::string name() const; 0097 HepRandomEngine & engine(); 0098 0099 static std::string distributionName() {return "RandBinomial";} 0100 // Provides the name of this distribution class 0101 0102 private: 0103 0104 static double genBinomial( HepRandomEngine *anEngine, long n, double p ); 0105 0106 std::shared_ptr<HepRandomEngine> localEngine; 0107 long defaultN; 0108 double defaultP; 0109 0110 }; 0111 0112 } // namespace CLHEP 0113 0114 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 0115 // backwards compatibility will be enabled ONLY in CLHEP 1.9 0116 using namespace CLHEP; 0117 #endif 0118 0119 #include "CLHEP/Random/RandBinomial.icc" 0120 0121 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |