-
Notifications
You must be signed in to change notification settings - Fork 0
/
FakeRate.cc
435 lines (395 loc) · 14.2 KB
/
FakeRate.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#include "FakeFunctions.h"
int nthdigit(int x, int n) {
static int powersof10[] = {1, 10, 100, 1000, 10000, 100000};
return ((x / powersof10[n]) % 10);
}
bool isPrompt(long pdgid) {
pdgid = abs(pdgid);
/*if (pdgid >= 1000001 && pdgid <= 1000006) return true; // SUSY squarks
else if (pdgid >= 1000011 && pdgid <= 1000016) return true; // SUSY sleptons sneutrinos
else if (pdgid >= 2000001 && pdgid <= 2000006) return true; // SUSY squarks
else if (pdgid >= 2000011 && pdgid <= 2000015) return true; // SUSY sleptons
else if (pdgid >= 1000021 && pdgid <= 1000025) return true; // SUSY gluino chargino neutralinos
else if (pdgid >= 1000035 && pdgid <= 1000039) return true; // SUSY neutralinos charginos gravitino*/
if (pdgid == 24) return true; // Z
else if (pdgid == 23) return true; // W
else if (pdgid == 15) return true; // taus
else if (pdgid == 90) return true; // N
else if (pdgid == 13) return true;
else return false;
// return indexToPromptBool[ abs(pdgToIndex[pdgid]) ];
}
void getFakerate(TH2F* h1, TH2F* h2, TH2F* out, int nbinX, int nbinY) {
double frate,ferr;
for (int i=1; i<nbinX+1; i++)
for (int j=1; j<nbinY+1; j++){
double a = h1->GetBinContent(i,j);
double b = h2->GetBinContent(i,j);
if (b){
frate = ((double) a)/((double) b);
ferr = sqrt( frate*(1-frate)/(double) b);
out->SetBinContent(i,j,frate);
out->SetBinError(i,j,ferr);
}
else {
out->SetBinContent(i,j,0);
}
}
}
void getFakerate(TH1F* h1, TH1F* h2, TH1F* out, int nbinX) {
double frate,ferr;
for (int i=1; i<nbinX+1; i++) {
double a = h1->GetBinContent(i);
double b = h2->GetBinContent(i);
if (b){
frate = ((double) a)/((double) b);
ferr = sqrt( frate*(1-frate)/(double) b);
out->SetBinContent(i,frate);
out->SetBinError(i,ferr);
}
else {
out->SetBinContent(i,0);
}
}
}
void DoubleANDSinglebkg(std::vector<Lepton>& leptonColli, UInt_t &ilep, std::vector<Lepton>& leptonCollj, UInt_t &jlep, Double_t *****fakeN, UInt_t &type) {
/*
double arrayeta[] = {0.0,1.0,1.479,2.0,2.5};
if (pT35)
double arraypT [] = {10.,15.,20.,25.,35.,45.,60.,80.,100.};
else {
arraypT = new double [nintpT+1];
arraypT[0] = 10.;
arraypT[1] = 15.;
arraypT[2] = 20.;
arraypT[3] = 25.;
arraypT[4] = minbin;
for (UInt_t i=0; i+5<nintpT+1; i++)
arraypT[i+5] = minbin + binwidh * exp (i);
}
*/
int i0=1; int j0=1;
int i1=1; int j1=1;
double eta0= fabs(leptonColli[ilep].eta());
double Pt0 = leptonColli[ilep].lorentzVec().Pt();
double eta1= fabs(leptonCollj[jlep].eta());
double Pt1 = leptonCollj[jlep].lorentzVec().Pt();
if (eta0<0.0 || eta0>=2.5) {cout<<"CACCHIO eta!!!! "<<eta0<<endl; eta0<0.0 ? eta0=0.0 : eta0=2.49;}
if (Pt0<10.0) {cout<<"CACCHIO Pt!!!! "<<Pt0<<endl; Pt0=10.0;}
if (eta1<0.0 || eta1>=2.5) {cout<<"CACCHIO eta!!!! "<<eta1<<endl; eta1<0.0 ? eta1=0.0 : eta1=2.49;}
if (Pt1<10.0) {cout<<"CACCHIO Pt!!!! "<<Pt1<<endl; Pt1=10.0;}
while(1) {
if( arrayeta[(i0-1)%(ninteta+1)]<=eta0 && arrayeta[i0%(ninteta+1)]>eta0 )
break;
i0++;
}
if (Pt0>=arraypT[nintpT]) j0=nintpT;
else {
while(1) {
if( arraypT[(j0-1)%(nintpT+1)]<=Pt0 && arraypT[j0%(nintpT+1)]>Pt0 )
break;
j0++;
}
}
while(1) {
if( arrayeta[(i1-1)%(ninteta+1)]<=eta1 && arrayeta[i1%(ninteta+1)]>eta1 )
break;
i1++;
}
if (Pt1>=arraypT[nintpT]) j1=nintpT;
else {
while(1) {
if( arraypT[(j1-1)%(nintpT+1)]<=Pt1 && arraypT[j1%(nintpT+1)]>Pt1 )
break;
j1++;
}
}
fakeN[0][i1-1][j1-1][i0-1][j0-1]+=1;
fakeN[type][i1-1][j1-1][i0-1][j0-1]+=1;
}
double DoublebackGround(TH2F* fakerate, std::vector<Lepton>& leptonColl, UInt_t &ilep, UInt_t &jlep, Double_t *****fakeN, UInt_t &type, Double_t weight) {
double bkg=0;
int i0=1; int j0=1;
int i1=1; int j1=1;
double eta0= fabs(leptonColl[ilep].eta());
double Pt0 = leptonColl[ilep].lorentzVec().Pt();
double eta1= fabs(leptonColl[jlep].eta());
double Pt1 = leptonColl[jlep].lorentzVec().Pt();
if (eta0<0.0 || eta0>=2.5) {cout<<"CACCHIO eta!!!! "<<eta0<<endl; eta0<0.0 ? eta0=0.0 : eta0=2.49;}
if (Pt0<10.0) {cout<<"CACCHIO Pt!!!! "<<Pt0<<endl; Pt0=10.0;}
if (eta1<0.0 || eta1>=2.5) {cout<<"CACCHIO eta!!!! "<<eta1<<endl; eta1<0.0 ? eta1=0.0 : eta1=2.49;}
if (Pt1<10.0) {cout<<"CACCHIO Pt!!!! "<<Pt1<<endl; Pt1=10.0;}
while(1) {
if( arrayeta[(i0-1)%(ninteta+1)]<=eta0 && eta0<arrayeta[i0%(ninteta+1)] )
break;
i0++;
}
if (Pt0>=arraypT[nintpT]) j0=nintpT;
else {
while(1) {
if( arraypT[(j0-1)%(nintpT+1)]<=Pt0 && Pt0<arraypT[j0%(nintpT+1)] )
break;
j0++;
}
}
while(1) {
if( arrayeta[(i1-1)%(ninteta+1)]<=eta1 && eta1<arrayeta[i1%(ninteta+1)] )
break;
i1++;
}
if (Pt1>=arraypT[nintpT]) j1=nintpT;
else {
while(1) {
if( arraypT[(j1-1)%(nintpT+1)]<=Pt1 && Pt1<arraypT[j1%(nintpT+1)] )
break;
j1++;
}
}
double A = fakerate->GetBinContent(i0,j0);
double B = fakerate->GetBinContent(i1,j1);
//double deltaA = fakerate->GetBinError(i0,j0);
//double deltaB = fakerate->GetBinError(i1,j1);
fakeN[0][i0-1][j0-1][i1-1][j1-1]+=weight;
fakeN[type][i0-1][j0-1][i1-1][j1-1]+=weight;
bkg = A*B / (( 1-A )*( 1-B ));
//errbkg = sqrt ( ( B*(1-B)*deltaA+A*(1-A)*deltaB )/( pow(1-A,2)*pow(1-B,2) ) );
return bkg;
}
double SinglebackGround(TH2F* fakerate, std::vector<Lepton>& leptonColl, UInt_t &ilep, Double_t ***fakeN, UInt_t &type, Double_t weight) {
double bkg=0;
int i=1; int j=1;
double eta= fabs(leptonColl[ilep].eta());
double Pt = leptonColl[ilep].lorentzVec().Pt();
if (eta<0.0 || eta>=2.5) {cout<<"CACCHIO eta!!!! "<<eta<<endl; eta<0.0 ? eta=0.0 : eta=2.49;}
if (Pt<10.0) {cout<<"CACCHIO Pt!!!! "<<Pt<<endl; Pt=10.0;}
while(1) {
if( arrayeta[(i-1)%(ninteta+1)]<=eta && eta<arrayeta[i%(ninteta+1)] )
break;
i++;
}
if (Pt>=arraypT[nintpT]) j=nintpT;
else {
while(1) {
if( arraypT[(j-1)%(nintpT+1)]<=Pt && Pt<arraypT[j%(nintpT+1)] )
break;
j++;
}
}
fakeN[0][i-1][j-1]+=weight;
fakeN[type][i-1][j-1]+=weight;
bkg = fakerate->GetBinContent(i,j) /( 1-fakerate->GetBinContent(i,j) );
//errbkg = fakerate->GetBinError(i,j) / pow( 1-fakerate->GetBinContent(i,j),2 );
return bkg;
}
double DoubleTOSinglebkg(TH2F* fakerate, std::vector<Lepton>& leptonColl, UInt_t &ilep, UInt_t &jlep) {
double bkg=0;
int i0=1; int j0=1;
int i1=1; int j1=1;
double eta0= fabs(leptonColl[ilep].eta());
double Pt0 = leptonColl[ilep].lorentzVec().Pt();
double eta1= fabs(leptonColl[jlep].eta());
double Pt1 = leptonColl[jlep].lorentzVec().Pt();
if (eta0<0.0 || eta0>=2.5) {cout<<"CACCHIO eta!!!! "<<eta0<<endl; eta0<0.0 ? eta0=0.0 : eta0=2.49;}
if (Pt0<10.0) {cout<<"CACCHIO Pt!!!! "<<Pt0<<endl; Pt0=10.0;}
if (eta1<0.0 || eta1>=2.5) {cout<<"CACCHIO eta!!!! "<<eta1<<endl; eta1<0.0 ? eta1=0.0 : eta1=2.49;}
if (Pt1<10.0) {cout<<"CACCHIO Pt!!!! "<<Pt1<<endl; Pt1=10.0;}
while(1) {
if( arrayeta[(i0-1)%(ninteta+1)]<=eta0 && eta0<arrayeta[i0%(ninteta+1)] )
break;
i0++;
}
if (Pt0>=arraypT[nintpT]) j0=nintpT;
else {
while(1) {
if( arraypT[(j0-1)%(nintpT+1)]<=Pt0 && Pt0<arraypT[j0%(nintpT+1)] )
break;
j0++;
}
}
while(1) {
if( arrayeta[(i1-1)%(ninteta+1)]<=eta1 && eta1<arrayeta[i1%(ninteta+1)] )
break;
i1++;
}
if (Pt1>=arraypT[nintpT]) j1=nintpT;
else {
while(1) {
if( arraypT[(j1-1)%(nintpT+1)]<=Pt1 && Pt1<arraypT[j1%(nintpT+1)] )
break;
j1++;
}
}
double A = fakerate->GetBinContent(i0,j0);
double B = fakerate->GetBinContent(i1,j1);
bkg = (-A/(1-A))* (A*(1-B)+B*(1-A)) / (( 1-A )*( 1-B ));
return bkg;
}
void BackGroundEstimate(TH2F* fakerate, Double_t ***fakeN1, Double_t *****prova, Double_t *****fakeN2, Double_t *singolo, Double_t *errsingolo, Double_t *doppio, Double_t *errdoppio, Double_t *singoloreale, Double_t *errsingoloreale, Double_t *doppioreale, Double_t *totale, Double_t *doubletosingle, Double_t *errdoubletosingle) {
UInt_t nbinX=fakerate->GetNbinsX(); UInt_t nbinY=fakerate->GetNbinsY();
Double_t tmperrsingolo, tmperrdoppio, tmperrsingoloreale, tmpdoubletosinglerr;
for (UInt_t z=0; z<4; z++) {
tmperrsingolo=tmperrdoppio=tmperrsingoloreale=tmpdoubletosinglerr=0;
for (UInt_t i=1; i<nbinX+1; i++)
for (UInt_t j=1; j<nbinY+1; j++) {
if (fakeN1[z][i-1][j-1]) {
Double_t FR = fakerate->GetBinContent(i,j);
Double_t deltaFR = fakerate->GetBinError(i,j);
singolo[z]+=fakeN1[z][i-1][j-1]*FR/(1-FR);
tmperrsingolo+=pow(fakeN1[z][i-1][j-1],2)*pow( (deltaFR/pow( (1-FR) ,2)) ,2) + fakeN1[z][i-1][j-1]*pow(FR/(1-FR),2);
}
for (UInt_t m=1; m<nbinX+1; m++)
for (UInt_t n=1; n<nbinY+1; n++) {
if (fakeN2[z][i-1][j-1][m-1][n-1]) {
Double_t FRi = fakerate->GetBinContent(i,j);
Double_t deltaFRi = fakerate->GetBinError(i,j);
Double_t FRm = fakerate->GetBinContent(m,n);
Double_t deltaFRm = fakerate->GetBinError(m,n);
Double_t W = FRi*FRm / ((1-FRi)*(1-FRm));
Double_t deltaW = sqrt( ( pow(FRi*(1-FRi), 2)*pow(deltaFRm,2) + pow(FRm*(1-FRm), 2)*pow(deltaFRi,2 ) ) / ( pow( (1-FRi) ,4)*pow( (1-FRm) ,4) ) );
doppio[z]+=fakeN2[z][i-1][j-1][m-1][n-1]*W;
tmperrdoppio+=pow(fakeN2[z][i-1][j-1][m-1][n-1],2)*pow(deltaW,2) + fakeN2[z][i-1][j-1][m-1][n-1]*pow(W,2);
}
if (fakeN2[z][i-1][j-1][m-1][n-1] || prova[z][i-1][j-1][m-1][n-1]) {
Double_t FRi = fakerate->GetBinContent(i,j);
Double_t FRm = fakerate->GetBinContent(m,n);
Double_t deltaFRi = fakerate->GetBinError(i,j);
Double_t deltaFRm = fakerate->GetBinError(m,n);
Double_t singolorealetmp= FRi/(1-FRi) * ( prova[z][i-1][j-1][m-1][n-1] - ( fakeN2[z][i-1][j-1][m-1][n-1] * ( FRm*(1-FRi)+FRi*(1-FRm) ) / ((1-FRi)*(1-FRm)) ) );
singoloreale[z]+= FRi/(1-FRi) * ( prova[z][i-1][j-1][m-1][n-1] - ( fakeN2[z][i-1][j-1][m-1][n-1] * ( FRm*(1-FRi)+FRi*(1-FRm) ) / ((1-FRi)*(1-FRm)) ) );
tmperrsingoloreale+=pow(prova[z][i-1][j-1][m-1][n-1], 2)*pow(deltaFRi/pow(1-FRi,2), 2) + prova[z][i-1][j-1][m-1][n-1]*pow(FRi/(1-FRi), 2) + pow(fakeN2[z][i-1][j-1][m-1][n-1], 2)*(pow(FRm-1, 2)*pow(FRm+FRi*(2-3*FRm), 2)*pow(deltaFRi,2) + pow(FRi-1, 4)*pow(FRi, 2)*pow(deltaFRm,2)) / (pow( (FRi-1) ,6)*pow( (FRm-1) ,4)) + fakeN2[z][i-1][j-1][m-1][n-1]*pow( (( FRm*(1-FRi)+FRi*(1-FRm) ) / ((1-FRi)*(1-FRm)))*FRi/(1-FRi) ,2);
Double_t doppiorealetmp= FRi*FRm*fakeN2[z][i-1][j-1][m-1][n-1] / ((1-FRi)*(1-FRm));
doppioreale[z]+= FRi*FRm*fakeN2[z][i-1][j-1][m-1][n-1] / ((1-FRi)*(1-FRm));
totale[z]+=singolorealetmp + doppiorealetmp;
doubletosingle[z] += fakeN2[z][i-1][j-1][m-1][n-1] * ( FRm*(1-FRi)+FRi*(1-FRm) ) / ((1-FRi)*(1-FRm));
tmpdoubletosinglerr += fakeN2[z][i-1][j-1][m-1][n-1]*pow(( FRm*(1-FRi)+FRi*(1-FRm) ) / ((1-FRi)*(1-FRm)),2) + pow(fakeN2[z][i-1][j-1][m-1][n-1]*deltaFRi/pow(1-FRi,2),2) + pow(fakeN2[z][i-1][j-1][m-1][n-1]*deltaFRm/pow(1-FRm,2),2);
}
}
}
errsingoloreale[z]=sqrt(tmperrsingoloreale);
errsingolo[z]=sqrt(tmperrsingolo);
errdoppio[z]=sqrt(tmperrdoppio);
errdoubletosingle[z]=sqrt(tmpdoubletosinglerr);
}
}
void WeigthedMean(std::vector<double>& value, std::vector<double>& error, double &mean, double &stddev) {
if (value.size()>0) {
double DEN=0; double NUM=0; double weight;
for(UInt_t iii=0; iii<value.size(); iii++) {
weight=1/pow(error[iii],2);
DEN+=weight;
NUM+=value[iii]*weight;
}
mean=NUM/DEN;
stddev=sqrt(1/DEN);
}
}
// Function to reverse the trigger weight on the events
/*
Double_t TriggerWeight(stringtobool* HLT_triggered) {
Char_t name[20];
Int_t pt[]={5,8,12,15,30};
Int_t mu5[]={0,0,40,100,100,150,0,320,320,640,320,320,320};
Int_t mu8[]={4,20,20,0,60,120,120,40,80,80,80,0,0};
Int_t mu12[]={10,420,420,0,630,450,450,70,70,70,70,0,0};
Int_t mu15[]={0,1,160,160,0,240,720,720,65,25,25,25,0};
Int_t mu30[]={1,1,1,0,25,80,80,10,4,4,4,0,0};
Int_t L1_Mu3[]={60,90,120,180,240,600};
Int_t L1_Mu7[]={1,1,40,60,80,100};
Int_t L1_Mu10[]={1,1,1,20,30,80};
Int_t L1_Mu12[]={1,1,1,15,20,60};
Int_t all[5][13];
for(Int_t i=0;i<5;i++)
for(Int_t j=0;j<13;j++) {
switch (i) {
case 0:
if(j<4)
all[i][j]=mu5[j]*L1_Mu3[0];
else if(j<7)
all[i][j]=mu5[j]*L1_Mu3[1];
else if (j<8)
all[i][j]=mu5[j]*L1_Mu3[2];
else if (j<9)
all[i][j]=mu5[j]*L1_Mu3[3];
else if (j<10)
all[i][j]=mu5[j]*L1_Mu3[4];
else if (j<13)
all[i][j]=mu5[j]*L1_Mu3[5];
else
all[i][j]=0;
break;
case 1:
if(j<2)
all[i][j]=mu8[j]*L1_Mu3[0];
else if(j<5)
all[i][j]=mu8[j]*L1_Mu3[1];
else if (j<6)
all[i][j]=mu8[j]*L1_Mu3[2];
else if (j<7)
all[i][j]=mu8[j]*L1_Mu3[3];
else if (j<8)
all[i][j]=mu8[j]*L1_Mu3[4];
else if (j<11)
all[i][j]=mu8[j]*L1_Mu3[5];
else
all[i][j]=0;
break;
case 2:
if(j<2)
all[i][j]=mu12[j]*L1_Mu7[0];
else if(j<5)
all[i][j]=mu12[j]*L1_Mu7[1];
else if (j<6)
all[i][j]=mu12[j]*L1_Mu7[2];
else if (j<7)
all[i][j]=mu12[j]*L1_Mu7[3];
else if (j<8)
all[i][j]=mu12[j]*L1_Mu7[4];
else if (j<11)
all[i][j]=mu12[j]*L1_Mu7[5];
else
all[i][j]=0;
break;
case 3:
if(j<3)
all[i][j]=mu15[j]*L1_Mu10[0];
else if(j<6)
all[i][j]=mu15[j]*L1_Mu10[1];
else if (j<7)
all[i][j]=mu15[j]*L1_Mu10[2];
else if (j<8)
all[i][j]=mu15[j]*L1_Mu10[3];
else if (j<9)
all[i][j]=mu15[j]*L1_Mu10[4];
else if (j<12)
all[i][j]=mu15[j]*L1_Mu10[5];
else
all[i][j]=0;
break;
case 4:
if(j<2)
all[i][j]=mu30[j]*L1_Mu12[0];
else if(j<5)
all[i][j]=mu30[j]*L1_Mu12[1];
else if (j<6)
all[i][j]=mu30[j]*L1_Mu12[2];
else if (j<7)
all[i][j]=mu30[j]*L1_Mu12[3];
else if (j<8)
all[i][j]=mu30[j]*L1_Mu12[4];
else if (j<11)
all[i][j]=mu30[j]*L1_Mu12[5];
else
all[i][j]=0;
break;
}
}
for(Int_t i=4;i>=0;i--)
for(Int_t ver=0;ver<13;ver++) {
strcpy(name,"");strcpy(name,"");
sprintf(name,"HLT_Mu%i_v%i",pt[i],ver+1);
if ( HLT_triggered->find(name) != HLT_triggered->end() && (*HLT_triggered)[name] )
return all[i][ver];
}
return -1;
}
*/