CMS 3D CMS Logo

GammaFunctionGenerator Class Reference

#include <FastSimulation/Utilities/interface/GammaFunctionGenerator.h>

List of all members.

Public Member Functions

 GammaFunctionGenerator (const RandomEngine *engine)
 Constructor.
void setParameters (double a, double b, double xm)
 The parameters must be set before shooting.
double shoot () const
 shoot along a gamma distribution with shape parameter alpha and scale beta values > xmin
virtual ~GammaFunctionGenerator ()
 Destructor.

Private Member Functions

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

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, e, i, integralToApproxLimit, myIncompleteGamma, random, theGammas, and xmax.

00005                                                                          :
00006   random(engine)
00007 {
00008 
00009   xmax = 30.;
00010 
00011   for(unsigned i=1;i<=12;++i)
00012     {
00013       // For all let's put the limit at 2.*(alpha-1)      (alpha-1 is the max of the dist)
00014       approxLimit.push_back(2*((double)i));
00015       myIncompleteGamma.a().setValue((double)i);
00016       integralToApproxLimit.push_back(myIncompleteGamma(approxLimit[i-1]));
00017       theGammas.push_back(
00018        GammaNumericalGenerator(random,(double)i,1.,0,approxLimit[i-1]+1.));
00019     }
00020   coreCoeff.push_back(0.);  // alpha=1 not used
00021   coreCoeff.push_back(1./8.24659e-01);
00022   coreCoeff.push_back(1./7.55976e-01);
00023   coreCoeff.push_back(1./7.12570e-01);
00024   coreCoeff.push_back(1./6.79062e-01);
00025   coreCoeff.push_back(1./6.65496e-01);
00026   coreCoeff.push_back(1./6.48736e-01);
00027   coreCoeff.push_back(1./6.25185e-01);
00028   coreCoeff.push_back(1./6.09188e-01);
00029   coreCoeff.push_back(1./6.06221e-01);
00030   coreCoeff.push_back(1./6.05057e-01);
00031 }

GammaFunctionGenerator::~GammaFunctionGenerator (  )  [virtual]

Destructor.

Definition at line 33 of file GammaFunctionGenerator.cc.

00033 {}


Member Function Documentation

double GammaFunctionGenerator::gammaFrac (  )  const [private]

values 0<a<1.

Definition at line 64 of file GammaFunctionGenerator.cc.

References funct::exp(), RandomEngine::flatShoot(), frac, funct::log(), p, random, v, and x.

Referenced by shoot().

00065 {
00066   /* This is exercise 16 from Knuth; see page 135, and the solution is
00067      on page 551.  */
00068 
00069   double p, q, x, u, v;
00070   p = M_E / (frac + M_E);
00071   do
00072     {
00073       u = random->flatShoot();
00074       v = random->flatShoot();
00075 
00076       if (u < p)
00077         {
00078           x = exp ((1 / frac) * log (v));
00079           q = exp (-x);
00080         }
00081       else
00082         {
00083           x = 1 - log (v);
00084           q = exp ((frac - 1) * log (x));
00085         }
00086     }
00087   while (random->flatShoot() >= q);
00088 
00089   return x;
00090 }

double GammaFunctionGenerator::gammaInt (  )  const [private]

integer values

Definition at line 92 of file GammaFunctionGenerator.cc.

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

Referenced by shoot().

00093 {
00094   // Exponential distribution : no approximation
00095   if(na==1)
00096     {
00097       return xmin-log(random->flatShoot());
00098     }
00099 
00100   unsigned gn=na-1;
00101 
00102   // are we sure to be in the tail 
00103   if(coreProba==0.)
00104     return xmin-coreCoeff[gn]*log(random->flatShoot());
00105 
00106   // core-tail interval
00107   if(random->flatShoot()<coreProba)
00108     {
00109       return theGammas[gn].gamma_lin();
00110     }
00111   //  std::cout << " Tail called " << std::endl;
00112   return approxLimit[gn]-coreCoeff[gn]*log(random->flatShoot());
00113 }

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 alpha, approxLimit, badRange, beta, coreProba, frac, integralToApproxLimit, myIncompleteGamma, na, theGammas, tmp, xmax, and xmin.

Referenced by EMShower::compute().

00116 {
00117   //  std::cout << "Setting parameters " << std::endl;
00118   alpha=a;
00119   beta=b;
00120   xmin=xm*beta;
00121   if(xm>xmax) 
00122     {
00123       badRange=true;
00124       return;
00125     }
00126   badRange=false;
00127   na=0;
00128   
00129   if(alpha>0.&&alpha<12) 
00130     na=(unsigned)floor(alpha);
00131 
00132   frac=alpha-na;  
00133   // Now calculate the probability to shoot between approxLimit and xmax
00134   // The Incomplete gamma is normalized to 1 
00135   if(na<=1) return;
00136   
00137   myIncompleteGamma.a().setValue((double)na);
00138   
00139   unsigned gn=na-1;
00140   //  std::cout << " na " << na << " xm " << xm << " beta " << beta << " xmin " << xmin << " approxLimit " << approxLimit[gn] << std::endl;
00141   if(xmin>approxLimit[gn]) 
00142     {
00143       coreProba=0.;
00144     }
00145   else
00146     {
00147       double tmp=myIncompleteGamma(xmin);
00148       coreProba=(integralToApproxLimit[gn]-tmp)/(1.-tmp);
00149       theGammas[gn].setSubInterval(xmin,approxLimit[gn]);
00150     }
00151   //  std::cout << " Proba " << coreProba << std::endl;
00152 }

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(), gf, na, and xmin.

Referenced by EMShower::compute().

00036 {
00037   if(alpha<0.) return -1.;
00038   if(badRange) return xmin/beta;
00039   if(alpha<12)
00040     {
00041 
00042       if (alpha == na)
00043         {
00044           return gammaInt ()/beta;
00045         }
00046       else if (na == 0)
00047         {
00048           return gammaFrac ()/beta;
00049         }
00050       else
00051         {
00052           double gi=gammaInt ();
00053           double gf=gammaFrac ();
00054           return (gi+gf)/beta;
00055         }
00056     }
00057   else
00058     {
00059       // an other generator has to be used in such a case
00060       return -1.;
00061     }
00062 }


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]

Definition at line 62 of file GammaFunctionGenerator.h.

Referenced by GammaFunctionGenerator(), and setParameters().

double GammaFunctionGenerator::xmin [private]

Definition at line 61 of file GammaFunctionGenerator.h.

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


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:21:09 2009 for CMSSW by  doxygen 1.5.4