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 (const RandomEngine *engine)
 Constructor. More...
 
void setParameters (double a, double b, double xm)
 The parameters must be set before shooting. More...
 
double shoot () const
 
virtual ~GammaFunctionGenerator ()
 Destructor. More...
 

Private Member Functions

double gammaFrac () const
 values 0<a<1. More...
 
double gammaInt () 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
 
const RandomEnginerandom
 
std::vector
< GammaNumericalGenerator
theGammas
 
double xmax
 
double xmin
 

Detailed Description

Definition at line 21 of file GammaFunctionGenerator.h.

Constructor & Destructor Documentation

GammaFunctionGenerator::GammaFunctionGenerator ( const RandomEngine engine)

Constructor.

Definition at line 5 of file GammaFunctionGenerator.cc.

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

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

Destructor.

Definition at line 33 of file GammaFunctionGenerator.cc.

33 {}

Member Function Documentation

double GammaFunctionGenerator::gammaFrac ( ) const
private

values 0<a<1.

Definition at line 64 of file GammaFunctionGenerator.cc.

References create_public_lumi_plots::exp, RandomEngine::flatShoot(), frac, create_public_lumi_plots::log, AlCaHLTBitMon_ParallelJobs::p, lumiQueryAPI::q, random, v, and vdt::x.

Referenced by shoot().

65 {
66  /* This is exercise 16 from Knuth; see page 135, and the solution is
67  on page 551. */
68 
69  double p, q, x, u, v;
70  p = M_E / (frac + M_E);
71  do
72  {
73  u = random->flatShoot();
74  v = random->flatShoot();
75 
76  if (u < p)
77  {
78  x = exp ((1 / frac) * log (v));
79  q = exp (-x);
80  }
81  else
82  {
83  x = 1 - log (v);
84  q = exp ((frac - 1) * log (x));
85  }
86  }
87  while (random->flatShoot() >= q);
88 
89  return x;
90 }
const RandomEngine * random
double flatShoot(double xmin=0.0, double xmax=1.0) const
Definition: RandomEngine.h:30
x
Definition: VDTMath.h:216
mathSSE::Vec4< T > v
double GammaFunctionGenerator::gammaInt ( ) const
private

integer values

Definition at line 92 of file GammaFunctionGenerator.cc.

References approxLimit, coreCoeff, coreProba, RandomEngine::flatShoot(), create_public_lumi_plots::log, na, random, theGammas, and xmin.

Referenced by shoot().

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

The parameters must be set before shooting.

Definition at line 115 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().

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

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

Definition at line 35 of file GammaFunctionGenerator.cc.

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

Referenced by EMShower::compute().

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

Member Data Documentation

double GammaFunctionGenerator::alpha
private

Definition at line 69 of file GammaFunctionGenerator.h.

Referenced by setParameters(), and shoot().

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

Definition at line 58 of file GammaFunctionGenerator.h.

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

bool GammaFunctionGenerator::badRange
private

Definition at line 77 of file GammaFunctionGenerator.h.

Referenced by setParameters(), and shoot().

double GammaFunctionGenerator::beta
private

Definition at line 69 of file GammaFunctionGenerator.h.

Referenced by setParameters(), and shoot().

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

Definition at line 52 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), and gammaInt().

double GammaFunctionGenerator::coreProba
private

Definition at line 55 of file GammaFunctionGenerator.h.

Referenced by gammaInt(), and setParameters().

double GammaFunctionGenerator::frac
private

Definition at line 67 of file GammaFunctionGenerator.h.

Referenced by gammaFrac(), and setParameters().

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

Definition at line 74 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), and setParameters().

Genfun::IncompleteGamma GammaFunctionGenerator::myIncompleteGamma
private

Definition at line 71 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), and setParameters().

unsigned GammaFunctionGenerator::na
private

Definition at line 65 of file GammaFunctionGenerator.h.

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

const RandomEngine* GammaFunctionGenerator::random
private

Definition at line 79 of file GammaFunctionGenerator.h.

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

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

Definition at line 49 of file GammaFunctionGenerator.h.

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

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