CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Matrix/CLHEP/Random/RandGeneral.h
Go to the documentation of this file.
1 // $Id: RandGeneral.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- RandGeneral ---
7 // class header file
8 // -----------------------------------------------------------------------
9 
10 // Class defining methods for shooting generally distributed random values,
11 // given a user-defined probability distribution function.
12 
13 // =======================================================================
14 // S.Magni & G.Pieri - Created: 29 April 1998
15 // G.Cosmo - Added constructor using default engine from the
16 // static generator: 20 Aug 1998
17 // S.Magni & G.Pieri - Added linear interpolation: 24 March 1999
18 // M. Fischler - Added private methods that simplify the implementaion
19 // prepareTables(), useFlatDistribution(), mapRandom()
20 // - Added private variable oneOverNbins.
21 // - Made the warning about shoot() not being static a tad
22 // more prominent. 14 May 1999
23 // M Fischler - put and get to/from streams 12/15/04
24 // =======================================================================
25 
26 #ifndef RandGeneral_h
27 #define RandGeneral_h 1
28 
29 #include "CLHEP/Random/defs.h"
30 #include "CLHEP/Random/Random.h"
31 #include "CLHEP/Utility/memory.h"
32 #include <vector>
33 
34 namespace CLHEP {
35 
40 class RandGeneral : public HepRandom {
41 
42 public:
43 
44  RandGeneral ( const double* aProbFunc,
45  int theProbSize,
46  int IntType=0 );
47  RandGeneral ( HepRandomEngine& anEngine,
48  const double* aProbFunc,
49  int theProbSize,
50  int IntType=0 );
51  RandGeneral ( HepRandomEngine* anEngine,
52  const double* aProbFunc,
53  int theProbSize,
54  int IntType=0 );
55  // These constructors should be used to instantiate a RandGeneral
56  // distribution object defining a local engine for it.
57  // The static generator will be skipped by using the non-static methods
58  // defined below. In case no engine is specified in the constructor, the
59  // default engine used by the static generator is applied.
60  // If the engine is passed by pointer the corresponding engine object
61  // will be deleted by the RandGeneral destructor.
62  // If the engine is passed by reference the corresponding engine object
63  // will not be deleted by the RandGeneral destructor.
64  // The probability distribution function (Pdf) must be provided by the user
65  // as an array of positive real number. The array size must also be
66  // provided. The Pdf doesn't need to be normalized to 1.
67  // if IntType = 0 ( default value ) a uniform random number is
68  // generated using the engine. The uniform number is then transformed
69  // to the user's distribution using the cumulative probability
70  // distribution constructed from his histogram. The cumulative
71  // distribution is inverted using a binary search for the nearest
72  // bin boundary and a linear interpolation within the
73  // bin. RandGeneral therefore generates a constant density within
74  // each bin.
75  // if IntType = 1 no interpolation is performed and the result is a
76  // discrete distribution.
77 
78  virtual ~RandGeneral();
79  // Destructor
80 
81  // Methods to shoot random values using the static generator
82  // N.B.: The methods are NOT static since they use nonstatic members
83  // theIntegralPdf & nBins
84 
86  // //
87  // BIG RED WARNING //
88  // //
90  //
91  // The above N.B. is telling users that the shoot() methods in this
92  // class are NOT STATIC. You cannot do
93  // double x = RandGeneral::shoot();
94  // It would not make sense to provide a static shoot -- what would
95  // the default probability function look like?
96 
97  inline double shoot();
98 
99  inline void shootArray ( const int size, double* vect);
100 
101  // Methods to shoot random values using a given engine
102  // by-passing the static generator.
103 
104  double shoot( HepRandomEngine* anEngine );
105 
106  void shootArray ( HepRandomEngine* anEngine, const int size,
107  double* vect );
108 
109  // Methods using the localEngine to shoot random values, by-passing
110  // the static generator.
111 
112  double fire();
113 
114  void fireArray ( const int size, double* vect);
115 
116  double operator()();
117 
118  // Save and restore to/from streams
119 
120  std::ostream & put ( std::ostream & os ) const;
121  std::istream & get ( std::istream & is );
122 
123  std::string name() const;
125 
126  static std::string distributionName() {return "RandGeneral";}
127  // Provides the name of this distribution class
128 
129 
130 private:
131 
132  shared_ptr<HepRandomEngine> localEngine;
133  std::vector<double> theIntegralPdf;
134  int nBins;
135  double oneOverNbins;
136  int InterpolationType;
137 
138  // Private methods to factor out replicated implementation sections
139  void prepareTable(const double* aProbFunc);
140  void useFlatDistribution();
141  double mapRandom(double rand) const;
142 
143 };
144 
145 } // namespace CLHEP
146 
147 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
148 // backwards compatibility will be enabled ONLY in CLHEP 1.9
149 using namespace CLHEP;
150 #endif
151 
152 #include "CLHEP/Random/RandGeneral.icc"
153 
154 #endif
CLHEP::shared_ptr
Definition: Matrix/CLHEP/Utility/memory.h:66
CLHEP::HepRandomEngine
Definition: Matrix/CLHEP/Random/RandomEngine.h:55
CLHEP::RandGeneral::fireArray
void fireArray(const int size, double *vect)
Definition: RandGeneral.cc:241
CLHEP::RandGeneral::~RandGeneral
virtual ~RandGeneral()
Definition: RandGeneral.cc:173
is
HepRotation and so forth isNear() norm2() rectify() static Rotation row1 row4(To avoid bloat in the code pulled in for programs which don 't use all these features, we split the implementation .cc files. Only isNear() goes into the original Rotation.cc) --------------------------------------- HepAxisAngle and HepEulerAngles classes --------------------------------------- These classes are very useful and simple structures for holding the result of a nice intuituve decomposition of a rotation there is no longer much content in the distinct ZOOM PhysicsVectors library The only content left in the library is the object files representing the various Exception objects When we build the CLHEP classes for the ZOOM we will set up so as to use ZOOM SpaceVector is(but we can disable namespace usage and most of our users do so at this point). What I do is leave Hep3Vector in the global namespace
CLHEP::RandGeneral
Definition: Matrix/CLHEP/Random/RandGeneral.h:40
CLHEP::RandGeneral::RandGeneral
RandGeneral(const double *aProbFunc, int theProbSize, int IntType=0)
Definition: RandGeneral.cc:65
size
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno size() Return the(integer) number of ZMthrow 'n exceptions currently recorded. 5) ZMerrno.clear() Set an internal counter to zero. This counter is available(see next function) to user code to track ZMthrow 'n exceptions that have occurred during any arbitrary time interval. 6) ZMerrno.countSinceCleared() Return the(integer) number of ZMthrow 'n exceptions that have been recorded via ZMerrno.write()
CLHEP::RandGeneral::shoot
double shoot()
CLHEP
Definition: ClhepVersion.h:13
CLHEP::RandGeneral::engine
HepRandomEngine & engine()
Definition: RandGeneral.cc:58
CLHEP::RandGeneral::get
std::istream & get(std::istream &is)
Definition: RandGeneral.cc:277
CLHEP::RandGeneral::distributionName
static std::string distributionName()
Definition: Matrix/CLHEP/Random/RandGeneral.h:126
CLHEP::RandGeneral::operator()
double operator()()
CLHEP::RandGeneral::name
std::string name() const
Definition: RandGeneral.cc:57
CLHEP::RandGeneral::fire
double fire()
CLHEP::RandGeneral::shootArray
void shootArray(const int size, double *vect)
CLHEP::HepRandom
Definition: Matrix/CLHEP/Random/Random.h:50
CLHEP::RandGeneral::put
std::ostream & put(std::ostream &os) const
Definition: RandGeneral.cc:250