CP3-llbb Framework
Rochester.h
1 #include "TRandom3.h"
2 #include "TMath.h"
3 
4 struct CrystalBall{
5  static const double pi;
6  static const double SPiO2;
7  static const double S2;
8 
9  double m;
10  double s;
11  double a;
12  double n;
13 
14  double B;
15  double C;
16  double D;
17  double N;
18 
19  double NA;
20  double Ns;
21  double NC;
22  double F;
23  double G;
24  double k;
25 
26  double cdfMa;
27  double cdfPa;
28 
29  CrystalBall(){
30  init(0, 1, 10, 10);
31  }
32  CrystalBall(double m_, double s_, double a_, double n_){
33  init(m_, s_, a_, n_);
34  }
35 
36  void init(double m_, double s_, double a_, double n_){
37  m=m_;
38  s=s_;
39  a=a_;
40  n=n_;
41 
42  double fa = fabs(a);
43  double expa = exp(-fa*fa/2);
44  double A = pow(n/fa, n)*expa;
45  double C1 = n/fa/(n-1)*expa;
46  double D1 = 2*SPiO2*erf(fa/S2);
47 
48  B = n/fa-fa;
49  C = (D1+2*C1)/C1;
50  D = (D1+2*C1)/2;
51 
52  N = 1.0/s/(D1+2*C1);
53  k = 1.0/(n-1);
54 
55  NA = N*A;
56  Ns = N*s;
57  NC = Ns*C1;
58  F = 1-fa*fa/n;
59  G = s*n/fa;
60 
61  cdfMa=cdf(m-a*s);
62  cdfPa=cdf(m+a*s);
63  }
64 
65  double pdf(double x) const{
66  double d=(x-m)/s;
67  if(d<-a) return NA*pow(B-d, -n);
68  if(d> a) return NA*pow(B+d, -n);
69  return N*exp(-d*d/2);
70  }
71 
72  double pdf(double x, double ks, double dm) const{
73  double d=(x-m-dm)/(s*ks);
74  if(d<-a) return NA/ks*pow(B-d, -n);
75  if(d> a) return NA/ks*pow(B+d, -n);
76  return N/ks*exp(-d*d/2);
77  }
78 
79  double cdf(double x) const{
80  double d = (x-m)/s;
81  if(d<-a) return NC / pow(F-s*d/G, n-1);
82  if(d> a) return NC * (C - pow(F+s*d/G, 1-n) );
83  return Ns*(D-SPiO2*erf(-d/S2));
84  }
85 
86  double invcdf(double u) const{
87  if(u<cdfMa) return m + G*(F - pow(NC/u, k) );
88  if(u>cdfPa) return m - G*(F - pow(C-u/NC, -k) );
89  return m - S2*s*TMath::ErfInverse((D - u/Ns ) / SPiO2);
90  }
91 };
92 const double CrystalBall::pi = TMath::Pi();
93 const double CrystalBall::SPiO2 = sqrt(TMath::Pi()/2.0);
94 const double CrystalBall::S2 = sqrt(2.0);
95 
96 
97 class RocRes{
98  private:
99  static const int NMAXETA=12;
100  static const int NMAXTRK=12;
101 
102  int NETA;
103  int NTRK;
104  int NMIN;
105 
106  double BETA[NMAXETA+1];
107  double ntrk[NMAXETA][NMAXTRK+1];
108  double dtrk[NMAXETA][NMAXTRK+1];
109 
110  double width[NMAXETA][NMAXTRK];
111  double alpha[NMAXETA][NMAXTRK];
112  double power[NMAXETA][NMAXTRK];
113 
114  double rmsA[NMAXETA][NMAXTRK];
115  double rmsB[NMAXETA][NMAXTRK];
116  double rmsC[NMAXETA][NMAXTRK];
117 
118  double kDat[NMAXETA];
119  double kRes[NMAXETA];
120 
121  int getBin(double x, const int NN, const double *b) const;
122 
123 
124  public:
125  enum TYPE {MC, Data, Extra};
126 
127  CrystalBall cb[NMAXETA][NMAXTRK];
128 
129  RocRes();
130  int getEtaBin(double feta) const;
131  int getNBinDT(double v, int H) const;
132  int getNBinMC(double v, int H) const;
133  double getUrnd(int H, int F, double v) const;
134  void dumpParams();
135  void init(std::string filename);
136 
137  void reset();
138 
139  ~RocRes(){}
140 
141  double Sigma(double pt, int H, int F) const;
142  double kSpread(double gpt, double rpt, double eta, int nlayers, double w) const;
143  double kSmear(double pt, double eta, TYPE type, double v, double u) const;
144  double kSmear(double pt, double eta, TYPE type, double v, double u, int n) const;
145  double kExtra(double pt, double eta, int nlayers, double u, double w) const;
146  double getkDat(int H) const{return kDat[H];}
147  double getkRes(int H) const{return kRes[H];}
148 };
149 
150 
151 class RocOne{
152  private:
153  static const int NMAXETA=22;
154  static const int NMAXPHI=16;
155  static const double MPHI;
156 
157  int NETA;
158  int NPHI;
159 
160  double BETA[NMAXETA+1];
161  double DPHI;
162 
163  double M[2][NMAXETA][NMAXPHI];
164  double A[2][NMAXETA][NMAXPHI];
165  double D[2][NMAXETA];
166 
167  RocRes RR;
168 
169  int getBin(double x, const int NN, const double *b) const;
170  int getBin(double x, const int nmax, const double xmin, const double dx) const;
171 
172  public:
173  enum TYPE{MC, DT};
174 
175  RocOne();
176  ~RocOne(){}
177 
178  RocOne(std::string filename, int iTYPE=0, int iSYS=0, int iMEM=0);
179  bool checkSYS(int iSYS, int iMEM, int kSYS=0, int kMEM=0);
180  bool checkTIGHT(int iTYPE, int iSYS, int iMEM, int kTYPE=0, int kSYS=0, int kMEM=0);
181  void reset();
182  void init(std::string filename, int iTYPE=0, int iSYS=0, int iMEM=0);
183 
184  double kScaleDT(int Q, double pt, double eta, double phi) const;
185  double kScaleMC(int Q, double pt, double eta, double phi, double kSMR=1) const;
186  double kScaleAndSmearMC(int Q, double pt, double eta, double phi, int n, double u, double w) const;
187  double kScaleFromGenMC(int Q, double pt, double eta, double phi, int n, double gt, double w) const;
188  double kGenSmear(double pt, double eta, double v, double u, RocRes::TYPE TT=RocRes::Data) const;
189 
190  double getM(int T, int H, int F) const{return M[T][H][F];}
191  double getA(int T, int H, int F) const{return A[T][H][F];}
192  double getK(int T, int H) const{return T==DT?RR.getkDat(H):RR.getkRes(H);}
193  RocRes& getR() {return RR;}
194 };
195 
196 
197 class RoccoR{
198  public:
199  RoccoR();
200  RoccoR(std::string dirname);
201  ~RoccoR();
202 
203  void init(std::string dirname);
204 
205  double kGenSmear(double pt, double eta, double v, double u, RocRes::TYPE TT=RocRes::Data, int s=0, int m=0) const;
206  double kScaleDT(int Q, double pt, double eta, double phi, int s=0, int m=0) const;
207 
208  double kScaleAndSmearMC(int Q, double pt, double eta, double phi, int n, double u, double w, int s=0, int m=0) const;
209  double kScaleFromGenMC(int Q, double pt, double eta, double phi, int n, double gt, double w, int s=0, int m=0) const;
210 
211 
212  double getM(int T, int H, int F, int E=0, int m=0) const{return RC[E][m].getM(T,H,F);}
213  double getA(int T, int H, int F, int E=0, int m=0) const{return RC[E][m].getA(T,H,F);}
214  double getK(int T, int H, int E=0, int m=0) const{return RC[E][m].getK(T,H);}
215 
216  int Nset() const{return RC.size();}
217  int Nmem(int s=0) const{return RC[s].size();}
218 
219  private:
220  std::vector<std::vector<RocOne> > RC;
221 };
Definition: Rochester.h:151
Definition: Rochester.h:97
Definition: Rochester.h:197
Definition: Rochester.h:4