CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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, mps_fire::i, integralToApproxLimit, myIncompleteGamma, theGammas, and xmax.

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

28 {}

Member Function Documentation

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

values 0<a<1.

Definition at line 51 of file GammaFunctionGenerator.cc.

References funct::exp(), RandomEngineAndDistribution::flatShoot(), frac, log, AlCaHLTBitMon_ParallelJobs::p, submitPVResolutionJobs::q, findQualityFiles::v, and x.

Referenced by shoot().

51  {
52  /* This is exercise 16 from Knuth; see page 135, and the solution is
53  on page 551. */
54 
55  double p, q, x, u, v;
56  p = M_E / (frac + M_E);
57  do {
58  u = random->flatShoot();
59  v = random->flatShoot();
60 
61  if (u < p) {
62  x = exp((1 / frac) * log(v));
63  q = exp(-x);
64  } else {
65  x = 1 - log(v);
66  q = exp((frac - 1) * log(x));
67  }
68  } while (random->flatShoot() >= q);
69 
70  return x;
71 }
static std::vector< std::string > checklist log
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
double GammaFunctionGenerator::gammaInt ( RandomEngineAndDistribution const *  random) const
private

integer values

Definition at line 73 of file GammaFunctionGenerator.cc.

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

Referenced by shoot().

73  {
74  // Exponential distribution : no approximation
75  if (na == 1) {
76  return xmin - log(random->flatShoot());
77  }
78 
79  unsigned gn = na - 1;
80 
81  // are we sure to be in the tail
82  if (coreProba == 0.)
83  return xmin - coreCoeff[gn] * log(random->flatShoot());
84 
85  // core-tail interval
86  if (random->flatShoot() < coreProba) {
87  return theGammas[gn].gamma_lin(random);
88  }
89  // std::cout << " Tail called " << std::endl;
90  return approxLimit[gn] - coreCoeff[gn] * log(random->flatShoot());
91 }
std::vector< GammaNumericalGenerator > theGammas
static std::vector< std::string > checklist log
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 93 of file GammaFunctionGenerator.cc.

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

Referenced by EMShower::compute().

93  {
94  // std::cout << "Setting parameters " << std::endl;
95  alpha = a;
96  beta = b;
97  xmin = xm * beta;
98  if (xm > xmax) {
99  badRange = true;
100  return;
101  }
102  badRange = false;
103  na = 0;
104 
105  if (alpha > 0. && alpha < 12)
106  na = (unsigned)floor(alpha);
107 
108  frac = alpha - na;
109  // Now calculate the probability to shoot between approxLimit and xmax
110  // The Incomplete gamma is normalized to 1
111  if (na <= 1)
112  return;
113 
114  myIncompleteGamma.a().setValue((double)na);
115 
116  unsigned gn = na - 1;
117  // std::cout << " na " << na << " xm " << xm << " beta " << beta << " xmin " << xmin << " approxLimit " << approxLimit[gn] << std::endl;
118  if (xmin > approxLimit[gn]) {
119  coreProba = 0.;
120  } else {
121  double tmp = (xmin != 0.) ? myIncompleteGamma(xmin) : 0.;
122  coreProba = (integralToApproxLimit[gn] - tmp) / (1. - tmp);
123  theGammas[gn].setSubInterval(xmin, approxLimit[gn]);
124  }
125  // std::cout << " Proba " << coreProba << std::endl;
126 }
std::vector< GammaNumericalGenerator > theGammas
std::vector< double > approxLimit
Genfun::IncompleteGamma myIncompleteGamma
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
tmp
align.sh
Definition: createJobs.py:716
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 30 of file GammaFunctionGenerator.cc.

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

Referenced by EMShower::compute().

30  {
31  if (alpha < 0.)
32  return -1.;
33  if (badRange)
34  return xmin / beta;
35  if (alpha < 12) {
36  if (alpha == na) {
37  return gammaInt(random) / beta;
38  } else if (na == 0) {
39  return gammaFrac(random) / beta;
40  } else {
41  double gi = gammaInt(random);
42  double gf = gammaFrac(random);
43  return (gi + gf) / beta;
44  }
45  } else {
46  // an other generator has to be used in such a case
47  return -1.;
48  }
49 }
double gammaInt(RandomEngineAndDistribution const *) const
integer values
double gammaFrac(RandomEngineAndDistribution const *) const
values 0&lt;a&lt;1.
double gf
Definition: hdecay.h:34

Member Data Documentation

double GammaFunctionGenerator::alpha
private

Definition at line 64 of file GammaFunctionGenerator.h.

Referenced by setParameters(), and shoot().

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

Definition at line 53 of file GammaFunctionGenerator.h.

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

bool GammaFunctionGenerator::badRange
private

Definition at line 72 of file GammaFunctionGenerator.h.

Referenced by setParameters(), and shoot().

double GammaFunctionGenerator::beta
private

Definition at line 64 of file GammaFunctionGenerator.h.

Referenced by setParameters(), and shoot().

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

Definition at line 47 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), and gammaInt().

double GammaFunctionGenerator::coreProba
private

Definition at line 50 of file GammaFunctionGenerator.h.

Referenced by gammaInt(), and setParameters().

double GammaFunctionGenerator::frac
private

Definition at line 62 of file GammaFunctionGenerator.h.

Referenced by gammaFrac(), and setParameters().

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

Definition at line 69 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), and setParameters().

Genfun::IncompleteGamma GammaFunctionGenerator::myIncompleteGamma
private

Definition at line 66 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), and setParameters().

unsigned GammaFunctionGenerator::na
private

Definition at line 60 of file GammaFunctionGenerator.h.

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

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

Definition at line 44 of file GammaFunctionGenerator.h.

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

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