3 Nikolai Amelin, Ludmila Malinina, Timur Pocheptsov (C) JINR/Dubna
4 amelin@sunhe.jinr.ru, malinina@sunhe.jinr.ru, pocheptsov@sunhe.jinr.ru
8 //This class is taken from the GEANT4 tool kit and changed!!!!!
10 //========================================================================================
11 //RandArrayFunction defines several methods for shooting generally distributed random values,
12 //given a user-defined probability distribution function.
14 //The probability distribution function Pdf must be provided by the user as an array of
15 //positive real numbers. The array size must also be provided. Pdf doesn't need to be
18 // if IntType = 0 ( default value ) a uniform random number is
19 // generated using the StandardRand() engine. The uniform number is then transformed
20 // to the user's distribution using the cumulative probability
21 // distribution constructed from his histogram. The cumulative
22 // distribution is inverted using a binary search for the nearest
23 // bin boundary and a linear interpolation within the
24 // bin. RandArrayFunction therefore generates a constant density within
26 // if IntType = 1 no interpolation is performed and the result is a
27 // discrete distribution.
29 //A speculate set of Shoot()/ShootArray() and Fire()/FireArray() methods is provided
30 //to Shoot random numbers via an instantiated RandArrayFunction object. These methods
31 //act directly on the flat distribution provided by a StandardRand() engine.
32 //An Operator () is also provided.
39 // RandArrayFunction FunctDist(Pdf,fNBins);
41 // Double_t num = FunctDist.Shoot();//Shoot() provides the same functionality as Fire()
48 // RandArrayFunction FunctDist(Pdf,fNBins);
50 // Double_t num = FunctDist();
57 // RandArrayFunction FunctDist(Pdf,fNBins);
60 // Double_t* vect = new Double_t[size];
61 // FunctDist.FireArray (size, vect);
63 //========================================================================================
65 #ifndef RANDARRAYFUNCTION_H
66 #define RANDARRAYFUNCTION_H
71 class RandArrayFunction {
73 RandArrayFunction(const Double_t *aProbFunc, Int_t theProbSize, Int_t interpolationType = 0);
74 RandArrayFunction(Int_t probSize, Int_t interpolationType = 0);
76 Double_t Shoot()const;
78 Double_t operator()()const;
79 void ShootArray(Int_t size, Double_t *array)const;
80 void FireArray(Int_t size, Double_t *array)const;
82 void PrepareTable(const Double_t *aProbFunc);
85 void UseFlatDistribution();
86 Double_t MapRandom(Double_t rand)const;
87 Double_t StandardRand()const;
89 std::vector<Double_t> fIntegralPdf; //
91 Double_t fOneOverNbins; //
92 Int_t fInterpolationType; //
96 inline Double_t RandArrayFunction::StandardRand() const {
97 return gRandom->Rndm();
100 inline Double_t RandArrayFunction::Fire() const {
101 return MapRandom(StandardRand());
104 inline Double_t RandArrayFunction::Shoot() const {
108 inline Double_t RandArrayFunction::operator()() const {
112 inline void RandArrayFunction::ShootArray(Int_t size, Double_t *array) const {
113 FireArray(size, array);