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