1 #ifndef RANDARRAYFUNCTION_INCLUDED
2 #define RANDARRAYFUNCTION_INCLUDED
9 Nikolai Amelin, Ludmila Malinina, Timur Pocheptsov (C) JINR/Dubna
10 amelin@sunhe.jinr.ru, malinina@sunhe.jinr.ru, pocheptsov@sunhe.jinr.ru
14 //This class is taken from the GEANT4 tool kit and changed!!!!!
16 //========================================================================================
17 //RandArrayFunction defines several methods for shooting generally distributed random values,
18 //given a user-defined probability distribution function.
20 //The probability distribution function Pdf must be provided by the user as an array of
21 //positive real numbers. The array size must also be provided. Pdf doesn't need to be
24 // if IntType = 0 ( default value ) a uniform random number is
25 // generated using the StandardRand() engine. The uniform number is then transformed
26 // to the user's distribution using the cumulative probability
27 // distribution constructed from his histogram. The cumulative
28 // distribution is inverted using a binary search for the nearest
29 // bin boundary and a linear interpolation within the
30 // bin. RandArrayFunction therefore generates a constant density within
32 // if IntType = 1 no interpolation is performed and the result is a
33 // discrete distribution.
35 //A speculate set of Shoot()/ShootArray() and Fire()/FireArray() methods is provided
36 //to Shoot random numbers via an instantiated RandArrayFunction object. These methods
37 //act directly on the flat distribution provided by a StandardRand() engine.
38 //An Operator () is also provided.
45 // RandArrayFunction FunctDist(Pdf,fNBins);
47 // Double_t num = FunctDist.Shoot();//Shoot() provides the same functionality as Fire()
54 // RandArrayFunction FunctDist(Pdf,fNBins);
56 // Double_t num = FunctDist();
63 // RandArrayFunction FunctDist(Pdf,fNBins);
66 // Double_t* vect = new Double_t[size];
67 // FunctDist.FireArray (size, vect);
69 //========================================================================================
71 class RandArrayFunction {
73 std::vector<Double_t> fIntegralPdf;
75 Double_t fOneOverNbins;
76 Int_t fInterpolationType;
79 RandArrayFunction(const Double_t *aProbFunc, Int_t theProbSize, Int_t interpolationType = 0);
80 RandArrayFunction(Int_t probSize, Int_t interpolationType = 0);
82 Double_t Shoot()const;
84 Double_t operator()()const;
85 void ShootArray(Int_t size, Double_t *array)const;
86 void FireArray(Int_t size, Double_t *array)const;
88 void PrepareTable(const Double_t *aProbFunc);
91 void UseFlatDistribution();
92 Double_t MapRandom(Double_t rand)const;
93 Double_t StandardRand()const;
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);