CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
GammaFunctionGenerator Class Reference

#include <GammaFunctionGenerator.h>

Public Member Functions

 GammaFunctionGenerator ()
 Constructor. More...
 
void setParameters (double a, double b, double xm)
 The parameters must be set before shooting. More...
 
double shoot (RandomEngineAndDistribution const *) const
 
virtual ~GammaFunctionGenerator ()
 Destructor. More...
 

Private Member Functions

double gammaFrac (RandomEngineAndDistribution const *) const
 values 0<a<1. More...
 
double gammaInt (RandomEngineAndDistribution const *) const
 integer values More...
 

Private Attributes

double alpha
 
std::vector< double > approxLimit
 
bool badRange
 
double beta
 
std::vector< double > coreCoeff
 
double coreProba
 
double frac
 
std::vector< double > integralToApproxLimit
 
Genfun::IncompleteGamma myIncompleteGamma
 
unsigned na
 
std::vector
< GammaNumericalGenerator
theGammas
 
double xmax
 
double xmin
 

Detailed Description

Definition at line 21 of file GammaFunctionGenerator.h.

Constructor & Destructor Documentation

GammaFunctionGenerator::GammaFunctionGenerator ( )

Constructor.

Definition at line 5 of file GammaFunctionGenerator.cc.

References approxLimit, coreCoeff, alignCSCRings::e, i, integralToApproxLimit, myIncompleteGamma, theGammas, and xmax.

6 {
7  xmax = 30.;
8 
9  for(unsigned i=1;i<=12;++i)
10  {
11  // For all let's put the limit at 2.*(alpha-1) (alpha-1 is the max of the dist)
12  approxLimit.push_back(2*((double)i));
13  myIncompleteGamma.a().setValue((double)i);
15  theGammas.push_back(
16  GammaNumericalGenerator((double)i,1.,0,approxLimit[i-1]+1.));
17  }
18  coreCoeff.push_back(0.); // alpha=1 not used
19  coreCoeff.push_back(1./8.24659e-01);
20  coreCoeff.push_back(1./7.55976e-01);
21  coreCoeff.push_back(1./7.12570e-01);
22  coreCoeff.push_back(1./6.79062e-01);
23  coreCoeff.push_back(1./6.65496e-01);
24  coreCoeff.push_back(1./6.48736e-01);
25  coreCoeff.push_back(1./6.25185e-01);
26  coreCoeff.push_back(1./6.09188e-01);
27  coreCoeff.push_back(1./6.06221e-01);
28  coreCoeff.push_back(1./6.05057e-01);
29 }
int i
Definition: DBlmapReader.cc:9
std::vector< GammaNumericalGenerator > theGammas
std::vector< double > approxLimit
std::vector< double > coreCoeff
Genfun::IncompleteGamma myIncompleteGamma
std::vector< double > integralToApproxLimit
GammaFunctionGenerator::~GammaFunctionGenerator ( )
virtual

Destructor.

Definition at line 31 of file GammaFunctionGenerator.cc.

31 {}

Member Function Documentation

double GammaFunctionGenerator::gammaFrac ( RandomEngineAndDistribution const *  random) const
private

values 0<a<1.

Definition at line 62 of file GammaFunctionGenerator.cc.

References create_public_lumi_plots::exp, RandomEngineAndDistribution::flatShoot(), frac, fff_deleter::log, AlCaHLTBitMon_ParallelJobs::p, lumiQueryAPI::q, findQualityFiles::v, and x.

Referenced by shoot().

63 {
64  /* This is exercise 16 from Knuth; see page 135, and the solution is
65  on page 551. */
66 
67  double p, q, x, u, v;
68  p = M_E / (frac + M_E);
69  do
70  {
71  u = random->flatShoot();
72  v = random->flatShoot();
73 
74  if (u < p)
75  {
76  x = exp ((1 / frac) * log (v));
77  q = exp (-x);
78  }
79  else
80  {
81  x = 1 - log (v);
82  q = exp ((frac - 1) * log (x));
83  }
84  }
85  while (random->flatShoot() >= q);
86 
87  return x;
88 }
TRandom random
Definition: MVATrainer.cc:138
Definition: DDAxes.h:10
double GammaFunctionGenerator::gammaInt ( RandomEngineAndDistribution const *  random) const
private

integer values

Definition at line 90 of file GammaFunctionGenerator.cc.

References approxLimit, coreCoeff, coreProba, RandomEngineAndDistribution::flatShoot(), fff_deleter::log, na, theGammas, and xmin.

Referenced by shoot().

91 {
92  // Exponential distribution : no approximation
93  if(na==1)
94  {
95  return xmin-log(random->flatShoot());
96  }
97 
98  unsigned gn=na-1;
99 
100  // are we sure to be in the tail
101  if(coreProba==0.)
102  return xmin-coreCoeff[gn]*log(random->flatShoot());
103 
104  // core-tail interval
105  if(random->flatShoot()<coreProba)
106  {
107  return theGammas[gn].gamma_lin(random);
108  }
109  // std::cout << " Tail called " << std::endl;
110  return approxLimit[gn]-coreCoeff[gn]*log(random->flatShoot());
111 }
std::vector< GammaNumericalGenerator > theGammas
TRandom random
Definition: MVATrainer.cc:138
std::vector< double > approxLimit
std::vector< double > coreCoeff
void GammaFunctionGenerator::setParameters ( double  a,
double  b,
double  xm 
)

The parameters must be set before shooting.

Definition at line 113 of file GammaFunctionGenerator.cc.

References a, alpha, approxLimit, b, badRange, beta, coreProba, frac, integralToApproxLimit, myIncompleteGamma, na, theGammas, tmp, xmax, and xmin.

Referenced by EMShower::compute().

114 {
115  // std::cout << "Setting parameters " << std::endl;
116  alpha=a;
117  beta=b;
118  xmin=xm*beta;
119  if(xm>xmax)
120  {
121  badRange=true;
122  return;
123  }
124  badRange=false;
125  na=0;
126 
127  if(alpha>0.&&alpha<12)
128  na=(unsigned)floor(alpha);
129 
130  frac=alpha-na;
131  // Now calculate the probability to shoot between approxLimit and xmax
132  // The Incomplete gamma is normalized to 1
133  if(na<=1) return;
134 
135  myIncompleteGamma.a().setValue((double)na);
136 
137  unsigned gn=na-1;
138  // std::cout << " na " << na << " xm " << xm << " beta " << beta << " xmin " << xmin << " approxLimit " << approxLimit[gn] << std::endl;
139  if(xmin>approxLimit[gn])
140  {
141  coreProba=0.;
142  }
143  else
144  {
145  double tmp=(xmin!=0.) ?myIncompleteGamma(xmin) : 0.;
146  coreProba=(integralToApproxLimit[gn]-tmp)/(1.-tmp);
147  theGammas[gn].setSubInterval(xmin,approxLimit[gn]);
148  }
149  // std::cout << " Proba " << coreProba << std::endl;
150 }
std::vector< GammaNumericalGenerator > theGammas
std::vector< double > approxLimit
Genfun::IncompleteGamma myIncompleteGamma
double b
Definition: hdecay.h:120
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
double a
Definition: hdecay.h:121
std::vector< double > integralToApproxLimit
double GammaFunctionGenerator::shoot ( RandomEngineAndDistribution const *  random) const

shoot along a gamma distribution with shape parameter alpha and scale beta values > xmin

Definition at line 33 of file GammaFunctionGenerator.cc.

References alpha, badRange, beta, gammaFrac(), gammaInt(), gf, na, and xmin.

Referenced by EMShower::compute().

34 {
35  if(alpha<0.) return -1.;
36  if(badRange) return xmin/beta;
37  if(alpha<12)
38  {
39 
40  if (alpha == na)
41  {
42  return gammaInt(random)/beta;
43  }
44  else if (na == 0)
45  {
46  return gammaFrac(random)/beta;
47  }
48  else
49  {
50  double gi=gammaInt(random);
51  double gf=gammaFrac(random);
52  return (gi+gf)/beta;
53  }
54  }
55  else
56  {
57  // an other generator has to be used in such a case
58  return -1.;
59  }
60 }
double gammaInt(RandomEngineAndDistribution const *) const
integer values
double gammaFrac(RandomEngineAndDistribution const *) const
values 0&lt;a&lt;1.
TRandom random
Definition: MVATrainer.cc:138
double gf
Definition: hdecay.h:34

Member Data Documentation

double GammaFunctionGenerator::alpha
private

Definition at line 67 of file GammaFunctionGenerator.h.

Referenced by setParameters(), and shoot().

std::vector<double> GammaFunctionGenerator::approxLimit
private

Definition at line 56 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), gammaInt(), and setParameters().

bool GammaFunctionGenerator::badRange
private

Definition at line 75 of file GammaFunctionGenerator.h.

Referenced by setParameters(), and shoot().

double GammaFunctionGenerator::beta
private

Definition at line 67 of file GammaFunctionGenerator.h.

Referenced by setParameters(), and shoot().

std::vector<double> GammaFunctionGenerator::coreCoeff
private

Definition at line 50 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), and gammaInt().

double GammaFunctionGenerator::coreProba
private

Definition at line 53 of file GammaFunctionGenerator.h.

Referenced by gammaInt(), and setParameters().

double GammaFunctionGenerator::frac
private

Definition at line 65 of file GammaFunctionGenerator.h.

Referenced by gammaFrac(), and setParameters().

std::vector<double> GammaFunctionGenerator::integralToApproxLimit
private

Definition at line 72 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), and setParameters().

Genfun::IncompleteGamma GammaFunctionGenerator::myIncompleteGamma
private

Definition at line 69 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), and setParameters().

unsigned GammaFunctionGenerator::na
private

Definition at line 63 of file GammaFunctionGenerator.h.

Referenced by gammaInt(), setParameters(), and shoot().

std::vector<GammaNumericalGenerator> GammaFunctionGenerator::theGammas
private

Definition at line 47 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), gammaInt(), and setParameters().

double GammaFunctionGenerator::xmax
private
double GammaFunctionGenerator::xmin
private