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 Attributes
DoubleCrystalBallGenerator Class Reference

#include <DoubleCrystalBallGenerator.h>

Public Member Functions

 DoubleCrystalBallGenerator (const RandomEngine *engine)
 
double shoot (double mu, double sigma, double aL, double nL, double aR, double nR)
 
virtual ~DoubleCrystalBallGenerator ()
 

Private Attributes

const RandomEnginerandom
 

Detailed Description

Definition at line 12 of file DoubleCrystalBallGenerator.h.

Constructor & Destructor Documentation

DoubleCrystalBallGenerator::DoubleCrystalBallGenerator ( const RandomEngine engine)
inline

Definition at line 16 of file DoubleCrystalBallGenerator.h.

16 : random(engine) {}
virtual DoubleCrystalBallGenerator::~DoubleCrystalBallGenerator ( )
inlinevirtual

Definition at line 18 of file DoubleCrystalBallGenerator.h.

18 {}

Member Function Documentation

double DoubleCrystalBallGenerator::shoot ( double  mu,
double  sigma,
double  aL,
double  nL,
double  aR,
double  nR 
)

Definition at line 11 of file DoubleCrystalBallGenerator.cc.

References PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi::dR, N, Pi, random, x, and detailsBasic3DVector::y.

Referenced by HCALResponse::cballShootNoNegative().

11  {
12  if(nL<=1 || nR<=1) return 0; //n>1 required
13 
14  double dL = nL/aL;
15  double dR = nR/aR;
16  double N = 1/(sigma*(nL/aL*1/(nL-1)*Exp(-aL*aL/2) + Sqrt(Pi()/2)*(Erf(aL/Sqrt(2))+Erf(aR/Sqrt(2))) + nR/aR*1/(nR-1)*Exp(-aR*aR/2)));
17 
18  //start x as NaN
19  double x = 0./0.;
20  while(!Finite(x)){
21  //shoot a flat random number
22  double y = random->flatShoot();
23 
24  //check range
25  //crystal ball CDF changes at (x-mu)/sigma = -aL && (x-mu)/sigma = aR
26  //compute this in pieces because it is awful
27  double AL = dL/(nL-1)*Exp(-aL*aL/2);
28  double CL = Sqrt(Pi()/2)*Erf(aL/Sqrt(2));
29  double CR = Sqrt(Pi()/2)*Erf(aR/Sqrt(2));
30  if(y < sigma*N*AL){//below lower boundary, use inverted power law CDF (left side)
31  double BL = dL/(nL-1)*Exp(-aL*aL/2);
32  x = mu + sigma*(-dL*Power(y/(sigma*N*BL),1/(-nL+1)) - aL + dL);
33  }
34  else if(y > sigma*N*(AL+CL+CR)){//above lower boundary, use inverted power law CDF (right side)
35  double AR = dR/(nR-1)*Exp(-aR*aR/2);
36  double BR = dR/(1-nR)*Exp(-aR*aR/2);
37  double D = (y/(sigma*N)-AL-CL-CR-AR)/BR;
38  x = mu + sigma*(dR*Power(D,1/(-nR+1)) + aR - dR);
39  }
40  else{//between boundaries, use gaussian CDF with proper normalization (in terms of erfc)
41  double D = 1 - Sqrt(2/Pi())*(y/(sigma*N)-AL-CL);
42  x = mu + sigma*Sqrt(2)*ErfcInverse(D);
43  }
44  }
45 
46  return x;
47 
48 }
const double Pi
const int mu
Definition: Constants.h:23
#define N
Definition: blowfish.cc:9
double flatShoot(double xmin=0.0, double xmax=1.0) const
Definition: RandomEngine.h:30
Definition: DDAxes.h:10
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150

Member Data Documentation

const RandomEngine* DoubleCrystalBallGenerator::random
private

Definition at line 25 of file DoubleCrystalBallGenerator.h.