CMS 3D CMS Logo

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 { return CLHEP::RandFlat::shoot(hjRandomEngine); }
99 
100 inline double RandArrayFunction::Fire() const { return MapRandom(StandardRand()); }
101 
102 inline double RandArrayFunction::Shoot() const { return Fire(); }
103 
104 inline double RandArrayFunction::operator()() const { return Fire(); }
105 
106 inline void RandArrayFunction::ShootArray(int size, double *array) const { FireArray(size, array); }
107 
108 #endif
MessageLogger.h
RandArrayFunction
Definition: RandArrayFunction.h:73
RandArrayFunction::operator()
double operator()() const
Definition: RandArrayFunction.h:104
RandArrayFunction::fNBins
int fNBins
Definition: RandArrayFunction.h:76
mps_check.array
array
Definition: mps_check.py:216
RandArrayFunction::ShootArray
void ShootArray(int size, double *array) const
Definition: RandArrayFunction.h:106
RandArrayFunction::fIntegralPdf
std::vector< double > fIntegralPdf
Definition: RandArrayFunction.h:75
RandArrayFunction::Fire
double Fire() const
Definition: RandArrayFunction.h:100
RandArrayFunction::Shoot
double Shoot() const
Definition: RandArrayFunction.h:102
RandArrayFunction::StandardRand
double StandardRand() const
Definition: RandArrayFunction.h:98
RandArrayFunction::PrepareTable
void PrepareTable(const double *aProbFunc)
Definition: RandArrayFunction.cc:19
RandArrayFunction::fOneOverNbins
double fOneOverNbins
Definition: RandArrayFunction.h:77
RandArrayFunction::UseFlatDistribution
void UseFlatDistribution()
Definition: RandArrayFunction.cc:62
RandArrayFunction::RandArrayFunction
RandArrayFunction(const double *aProbFunc, int theProbSize, int interpolationType=0)
Definition: RandArrayFunction.cc:12
RandArrayFunction::MapRandom
double MapRandom(double rand) const
Definition: RandArrayFunction.cc:71
hjRandomEngine
CLHEP::HepRandomEngine * hjRandomEngine
Definition: Hydjet2Hadronizer.h:55
RandArrayFunction::fInterpolationType
int fInterpolationType
Definition: RandArrayFunction.h:78
RandArrayFunction::FireArray
void FireArray(int size, double *array) const
Definition: RandArrayFunction.cc:110
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443