test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RandArrayFunction.h
Go to the documentation of this file.
1 #ifndef RANDARRAYFUNCTION_INCLUDED
2 #define RANDARRAYFUNCTION_INCLUDED
3 
4 #include <vector>
6 #include "CLHEP/Random/RandomEngine.h"
7 #include "CLHEP/Random/RandFlat.h"
8 extern CLHEP::HepRandomEngine* hjRandomEngine;
9 /*
10 
11 Nikolai Amelin, Ludmila Malinina, Timur Pocheptsov (C) JINR/Dubna
12 amelin@sunhe.jinr.ru, malinina@sunhe.jinr.ru, pocheptsov@sunhe.jinr.ru
13 November. 2, 2005
14 
15 */
16 //This class is taken from the GEANT4 tool kit and changed!!!!!
17 
18 //========================================================================================
19 //RandArrayFunction defines several methods for shooting generally distributed random values,
20 //given a user-defined probability distribution function.
21 
22 //The probability distribution function Pdf must be provided by the user as an array of
23 //positive real numbers. The array size must also be provided. Pdf doesn't need to be
24 //normalized to 1.
25 
26 // if IntType = 0 ( default value ) a uniform random number is
27 // generated using the StandardRand() engine. The uniform number is then transformed
28 // to the user's distribution using the cumulative probability
29 // distribution constructed from his histogram. The cumulative
30 // distribution is inverted using a binary search for the nearest
31 // bin boundary and a linear interpolation within the
32 // bin. RandArrayFunction therefore generates a constant density within
33 // each bin.
34 // if IntType = 1 no interpolation is performed and the result is a
35 // discrete distribution.
36 
37 //A speculate set of Shoot()/ShootArray() and Fire()/FireArray() methods is provided
38 //to Shoot random numbers via an instantiated RandArrayFunction object. These methods
39 //act directly on the flat distribution provided by a StandardRand() engine.
40 //An Operator () is also provided.
41 
42 // example.
43 // ...
44 // double* Pdf;
45 // int fNBins;
46 // ...
47 // RandArrayFunction FunctDist(Pdf,fNBins);
48 // ...
49 // double num = FunctDist.Shoot();//Shoot() provides the same functionality as Fire()
50 
51 // example.
52 // ...
53 // double* Pdf;
54 // int fNBins;
55 // ...
56 // RandArrayFunction FunctDist(Pdf,fNBins);
57 // ...
58 // double num = FunctDist();
59 
60 // example.
61 // ...
62 // double* Pdf;
63 // int fNBins;
64 // ...
65 // RandArrayFunction FunctDist(Pdf,fNBins);
66 // ...
67 // int size = 50;
68 // double* vect = new double[size];
69 // FunctDist.FireArray (size, vect);
70 
71 //========================================================================================
72 
74  private:
75  std::vector<double> fIntegralPdf;
76  int fNBins;
77  double fOneOverNbins;
79 
80  public:
81  RandArrayFunction(const double *aProbFunc, int theProbSize, int interpolationType = 0);
82  RandArrayFunction(int probSize, int interpolationType = 0);
83 
84  double Shoot()const;
85  double Fire()const;
86  double operator()()const;
87  void ShootArray(int size, double *array)const;
88  void FireArray(int size, double *array)const;
89 
90  void PrepareTable(const double *aProbFunc);
91 
92  private:
93  void UseFlatDistribution();
94  double MapRandom(double rand)const;
95  double StandardRand()const;
96 };
97 
98 inline double RandArrayFunction::StandardRand() const {
99  return CLHEP::RandFlat::shoot(hjRandomEngine);
100 }
101 
102 inline double RandArrayFunction::Fire() const {
103  return MapRandom(StandardRand());
104 }
105 
106 inline double RandArrayFunction::Shoot() const {
107  return Fire();
108 }
109 
110 inline double RandArrayFunction::operator()() const {
111  return Fire();
112 }
113 
114 inline void RandArrayFunction::ShootArray(int size, double *array) const {
115  FireArray(size, array);
116 }
117 
118 #endif
tuple array
Definition: mps_check.py:181
std::vector< double > fIntegralPdf
void PrepareTable(const double *aProbFunc)
double operator()() const
void FireArray(int size, double *array) const
void ShootArray(int size, double *array) const
double StandardRand() const
double Shoot() const
CLHEP::HepRandomEngine * hjRandomEngine
Signal rand(Signal arg)
Definition: vlib.cc:442
RandArrayFunction(const double *aProbFunc, int theProbSize, int interpolationType=0)
tuple size
Write out results.
double Fire() const
double MapRandom(double rand) const