]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TUHKMgen/UHKM/RandArrayFunction.h
Updated object after ALiZDCPreprocessor correction
[u/mrichter/AliRoot.git] / TUHKMgen / UHKM / RandArrayFunction.h
CommitLineData
b1c2e580 1#ifndef RANDARRAYFUNCTION_INCLUDED
2#define RANDARRAYFUNCTION_INCLUDED
3
4#include <vector>
5
6#include <TRandom.h>
7/*
8
9 Nikolai Amelin, Ludmila Malinina, Timur Pocheptsov (C) JINR/Dubna
10 amelin@sunhe.jinr.ru, malinina@sunhe.jinr.ru, pocheptsov@sunhe.jinr.ru
11 November. 2, 2005
12
13*/
14//This class is taken from the GEANT4 tool kit and changed!!!!!
15
16//========================================================================================
17//RandArrayFunction defines several methods for shooting generally distributed random values,
18//given a user-defined probability distribution function.
19
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
22//normalized to 1.
23
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
31 // each bin.
32 // if IntType = 1 no interpolation is performed and the result is a
33 // discrete distribution.
34
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.
39
40// example.
41// ...
42// Double_t* Pdf;
43// Int_t fNBins;
44// ...
45// RandArrayFunction FunctDist(Pdf,fNBins);
46// ...
47// Double_t num = FunctDist.Shoot();//Shoot() provides the same functionality as Fire()
48
49// example.
50// ...
51// Double_t* Pdf;
52// Int_t fNBins;
53// ...
54// RandArrayFunction FunctDist(Pdf,fNBins);
55// ...
56// Double_t num = FunctDist();
57
58// example.
59// ...
60// Double_t* Pdf;
61// Int_t fNBins;
62// ...
63// RandArrayFunction FunctDist(Pdf,fNBins);
64// ...
65// Int_t size = 50;
66// Double_t* vect = new Double_t[size];
67// FunctDist.FireArray (size, vect);
68
69//========================================================================================
70
71class RandArrayFunction {
b1c2e580 72 public:
73 RandArrayFunction(const Double_t *aProbFunc, Int_t theProbSize, Int_t interpolationType = 0);
74 RandArrayFunction(Int_t probSize, Int_t interpolationType = 0);
75
76 Double_t Shoot()const;
77 Double_t Fire()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;
81
82 void PrepareTable(const Double_t *aProbFunc);
83
84 private:
85 void UseFlatDistribution();
86 Double_t MapRandom(Double_t rand)const;
87 Double_t StandardRand()const;
786056a2 88
89 std::vector<Double_t> fIntegralPdf;
90 Int_t fNBins;
91 Double_t fOneOverNbins;
92 Int_t fInterpolationType;
93
b1c2e580 94};
95
96inline Double_t RandArrayFunction::StandardRand() const {
97 return gRandom->Rndm();
98}
99
100inline Double_t RandArrayFunction::Fire() const {
101 return MapRandom(StandardRand());
102}
103
104inline Double_t RandArrayFunction::Shoot() const {
105 return Fire();
106}
107
108inline Double_t RandArrayFunction::operator()() const {
109 return Fire();
110}
111
112inline void RandArrayFunction::ShootArray(Int_t size, Double_t *array) const {
113 FireArray(size, array);
114}
115
116#endif