-
Notifications
You must be signed in to change notification settings - Fork 1
/
factorizedPtCorr.h
377 lines (294 loc) · 15.1 KB
/
factorizedPtCorr.h
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
//=============================================
// Author: Chris McGinn
//
// DiJet Analysis Class (MC)
//
//=============================================
#include "TFile.h"
#include "TProfile.h"
#include "TProfile2D.h"
#include "etaPhiFunc.h"
#include <iostream>
#include "sType.h"
#include "TMath.h"
//Current # of correction histograms
const Int_t nHistPbPb = 29;
const Int_t nHistPP = 4;
//HI Vs Calo
TFile* VsCaloFile_p[nHistPbPb];
TProfile* VsCalocent_p[nHistPbPb];
TProfile2D* VsCalophiEta_p[nHistPbPb];
TProfile* VsCalopt_p[nHistPbPb];
TProfile* VsCalodelR_p[nHistPbPb];
TFile* FakeVsCaloFile_p[nHistPbPb];
TProfile* FakeVsCalocent_p[nHistPbPb];
TProfile2D* FakeVsCalophiEta_p[nHistPbPb];
TProfile* FakeVsCalopt_p[nHistPbPb];
TProfile* FakeVsCalodelR_p[nHistPbPb];
Int_t posArrPbPb[7] = {0, 5, 10, 15, 20, 25, 28};
//PP Vs Calo
TFile* CaloFile_p[nHistPP];
TProfile2D* CalophiEta_p[nHistPP];
TProfile* Calopt_p[nHistPP];
TProfile* CalodelR_p[nHistPP];
TFile* FakeCaloFile_p[nHistPP];
TProfile2D* FakeCalophiEta_p[nHistPP];
TProfile* FakeCalopt_p[nHistPP];
TProfile* FakeCalodelR_p[nHistPP];
TFile* SecondCaloFile_p;
TH2D* SecondCaloptEta_p;
TFile* MultrecoCaloFile_p;
TH2D* MultrecoCaloptEta_p;
void InitFactCorrFiles(sampleType sType = kHIDATA)
{
//File names w/ various binnings, ordered by pt and then centrality. Each Jet Algorithm gets a file array
if(sType == kHIDATA || sType == kHIMC){
VsCaloFile_p[0] = new TFile("eff_pt50_55_cent0_10.root", "READ");
VsCaloFile_p[1] = new TFile("eff_pt50_55_cent10_20.root", "READ");
VsCaloFile_p[2] = new TFile("eff_pt50_55_cent20_30.root", "READ");
VsCaloFile_p[3] = new TFile("eff_pt50_55_cent30_50.root", "READ");
VsCaloFile_p[4] = new TFile("eff_pt50_55_cent50_100.root", "READ");
VsCaloFile_p[5] = new TFile("eff_pt55_65_cent0_10.root", "READ");
VsCaloFile_p[6] = new TFile("eff_pt55_65_cent10_20.root", "READ");
VsCaloFile_p[7] = new TFile("eff_pt55_65_cent20_30.root", "READ");
VsCaloFile_p[8] = new TFile("eff_pt55_65_cent30_50.root", "READ");
VsCaloFile_p[9] = new TFile("eff_pt55_65_cent50_100.root", "READ");
VsCaloFile_p[10] = new TFile("eff_pt65_80_cent0_10.root", "READ");
VsCaloFile_p[11] = new TFile("eff_pt65_80_cent10_20.root", "READ");
VsCaloFile_p[12] = new TFile("eff_pt65_80_cent20_30.root", "READ");
VsCaloFile_p[13] = new TFile("eff_pt65_80_cent30_50.root", "READ");
VsCaloFile_p[14] = new TFile("eff_pt65_80_cent50_100.root", "READ");
VsCaloFile_p[15] = new TFile("eff_pt80_100_cent0_10.root", "READ");
VsCaloFile_p[16] = new TFile("eff_pt80_100_cent10_20.root", "READ");
VsCaloFile_p[17] = new TFile("eff_pt80_100_cent20_30.root", "READ");
VsCaloFile_p[18] = new TFile("eff_pt80_100_cent30_50.root", "READ");
VsCaloFile_p[19] = new TFile("eff_pt80_100_cent50_100.root", "READ");
VsCaloFile_p[20] = new TFile("eff_pt100_300_cent0_10.root", "READ");
VsCaloFile_p[21] = new TFile("eff_pt100_300_cent10_20.root", "READ");
VsCaloFile_p[22] = new TFile("eff_pt100_300_cent20_30.root", "READ");
VsCaloFile_p[23] = new TFile("eff_pt100_300_cent30_50.root", "READ");
VsCaloFile_p[24] = new TFile("eff_pt100_300_cent50_100.root", "READ");
VsCaloFile_p[25] = new TFile("eff_pt300_800_cent0_10.root", "READ");
VsCaloFile_p[26] = new TFile("eff_pt300_800_cent10_20.root", "READ");
VsCaloFile_p[27] = new TFile("eff_pt300_800_cent20_100.root", "READ");
VsCaloFile_p[28] = new TFile("eff_pt800_30000_cent0_100.root", "READ");
//Fakes VsCalo
FakeVsCaloFile_p[0] = new TFile("fake_pt50_55_cent0_10.root", "READ");
FakeVsCaloFile_p[1] = new TFile("fake_pt50_55_cent10_20.root", "READ");
FakeVsCaloFile_p[2] = new TFile("fake_pt50_55_cent20_30.root", "READ");
FakeVsCaloFile_p[3] = new TFile("fake_pt50_55_cent30_50.root", "READ");
FakeVsCaloFile_p[4] = new TFile("fake_pt50_55_cent50_100.root", "READ");
FakeVsCaloFile_p[5] = new TFile("fake_pt55_65_cent0_10.root", "READ");
FakeVsCaloFile_p[6] = new TFile("fake_pt55_65_cent10_20.root", "READ");
FakeVsCaloFile_p[7] = new TFile("fake_pt55_65_cent20_30.root", "READ");
FakeVsCaloFile_p[8] = new TFile("fake_pt55_65_cent30_50.root", "READ");
FakeVsCaloFile_p[9] = new TFile("fake_pt55_65_cent50_100.root", "READ");
FakeVsCaloFile_p[10] = new TFile("fake_pt65_80_cent0_10.root", "READ");
FakeVsCaloFile_p[11] = new TFile("fake_pt65_80_cent10_20.root", "READ");
FakeVsCaloFile_p[12] = new TFile("fake_pt65_80_cent20_30.root", "READ");
FakeVsCaloFile_p[13] = new TFile("fake_pt65_80_cent30_50.root", "READ");
FakeVsCaloFile_p[14] = new TFile("fake_pt65_80_cent50_100.root", "READ");
FakeVsCaloFile_p[15] = new TFile("fake_pt80_100_cent0_10.root", "READ");
FakeVsCaloFile_p[16] = new TFile("fake_pt80_100_cent10_20.root", "READ");
FakeVsCaloFile_p[17] = new TFile("fake_pt80_100_cent20_30.root", "READ");
FakeVsCaloFile_p[18] = new TFile("fake_pt80_100_cent30_50.root", "READ");
FakeVsCaloFile_p[19] = new TFile("fake_pt80_100_cent50_100.root", "READ");
FakeVsCaloFile_p[20] = new TFile("fake_pt100_300_cent0_10.root", "READ");
FakeVsCaloFile_p[21] = new TFile("fake_pt100_300_cent10_20.root", "READ");
FakeVsCaloFile_p[22] = new TFile("fake_pt100_300_cent20_30.root", "READ");
FakeVsCaloFile_p[23] = new TFile("fake_pt100_300_cent30_50.root", "READ");
FakeVsCaloFile_p[24] = new TFile("fake_pt100_300_cent50_100.root", "READ");
FakeVsCaloFile_p[25] = new TFile("fake_pt300_800_cent0_10.root", "READ");
FakeVsCaloFile_p[26] = new TFile("fake_pt300_800_cent10_20.root", "READ");
FakeVsCaloFile_p[27] = new TFile("fake_pt300_800_cent20_100.root", "READ");
FakeVsCaloFile_p[28] = new TFile("fake_pt800_30000_cent0_100.root", "READ");
}
else if(sType == kPPDATA || sType == kPPMC){
CaloFile_p[0] = new TFile("eff_pt0_1_ak3Calo_dogenjet0.root", "READ");
CaloFile_p[1] = new TFile("eff_pt1_3_ak3Calo_dogenjet0.root", "READ");
CaloFile_p[2] = new TFile("eff_pt3_8_ak3Calo_dogenjet0.root", "READ");
CaloFile_p[3] = new TFile("eff_pt8_300_ak3Calo_dogenjet0.root", "READ");
FakeCaloFile_p[0] = new TFile("fake_pt0_1_ak3Calo_dogenjet0.root", "READ");
FakeCaloFile_p[1] = new TFile("fake_pt1_3_ak3Calo_dogenjet0.root", "READ");
FakeCaloFile_p[2] = new TFile("fake_pt3_8_ak3Calo_dogenjet0.root", "READ");
FakeCaloFile_p[3] = new TFile("fake_pt8_300_ak3Calo_dogenjet0.root", "READ");
SecondCaloFile_p = new TFile("secondary_pp.root", "READ");
MultrecoCaloFile_p = new TFile("multiplereco_pp.root", "READ");
}
return;
}
void InitFactCorrHists(sampleType sType = kHIDATA)
{
if(sType == kHIDATA || sType == kHIMC){
for(Int_t hIter = 0; hIter < nHistPbPb; hIter++){
VsCalocent_p[hIter] = (TProfile*)VsCaloFile_p[hIter]->Get("p_eff_cent");
VsCalophiEta_p[hIter] = (TProfile2D*)VsCaloFile_p[hIter]->Get("p_eff_acceptance");
VsCalopt_p[hIter] = (TProfile*)VsCaloFile_p[hIter]->Get("p_eff_pt");
VsCalodelR_p[hIter] = (TProfile*)VsCaloFile_p[hIter]->Get("p_eff_rmin");
FakeVsCalocent_p[hIter] = (TProfile*)FakeVsCaloFile_p[hIter]->Get("p_fake_cent");
FakeVsCalophiEta_p[hIter] = (TProfile2D*)FakeVsCaloFile_p[hIter]->Get("p_fake_acceptance");
FakeVsCalopt_p[hIter] = (TProfile*)FakeVsCaloFile_p[hIter]->Get("p_fake_pt");
FakeVsCalodelR_p[hIter] = (TProfile*)FakeVsCaloFile_p[hIter]->Get("p_fake_rmin");
}
}
else if(sType == kPPDATA || sType == kPPMC){
for(Int_t hIter = 0; hIter < nHistPP; hIter++){
CalophiEta_p[hIter] = (TProfile2D*)CaloFile_p[hIter]->Get("p_eff_acceptance");
Calopt_p[hIter] = (TProfile*)CaloFile_p[hIter]->Get("p_eff_pt");
CalodelR_p[hIter] = (TProfile*)CaloFile_p[hIter]->Get("p_eff_rmin");
FakeCalophiEta_p[hIter] = (TProfile2D*)FakeCaloFile_p[hIter]->Get("p_fake_acceptance");
FakeCalopt_p[hIter] = (TProfile*)FakeCaloFile_p[hIter]->Get("p_fake_pt");
FakeCalodelR_p[hIter] = (TProfile*)FakeCaloFile_p[hIter]->Get("p_fake_rmin");
}
SecondCaloptEta_p = (TH2D*)SecondCaloFile_p->Get("hpt_eta");
MultrecoCaloptEta_p = (TH2D*)MultrecoCaloFile_p->Get("hpt_eta");
}
return;
}
void InitPosArrPbPb(Int_t hiBin)
{
if(hiBin < 0 || hiBin > 199){
std::cout << "InitPosArrPbPb: hiBin out of range; check input" << std::endl;
return;
}
Int_t startArrPbPb[7] = {0, 5, 10, 15, 20, 25, 28};
Int_t hiBinDiv[5] = {20, 40, 60, 100, 200};
for(Int_t hiBinIter = 0; hiBinIter < 5; hiBinIter++){
if(hiBin < hiBinDiv[hiBinIter]){
for(Int_t arrIter = 0; arrIter < 6; arrIter++){
posArrPbPb[arrIter] = startArrPbPb[arrIter] + hiBinIter;
}
break;
}
}
if(hiBin >= 60)
posArrPbPb[5] = 27;
return;
}
Int_t getPtBin(Float_t pt, sampleType sType = kHIDATA)
{
if(pt > 1000000){
std::cout << "getPtBin: pt outside of acceptable range; check input" << std::endl;
return -1;
}
else if(pt <= 0.50) pt = .500001;
else if(pt > .649999 && pt < .650001) pt = 0.650001;
if(sType == kHIDATA || sType == kHIMC){
Float_t ptArr[8] = {.50, .55, .65, .80, 1.00, 3.00, 8.00, 1000000};
for(Int_t ptPosIter = 0; ptPosIter < 7; ptPosIter++){
if(pt >= ptArr[ptPosIter] && pt < ptArr[ptPosIter + 1]){
return posArrPbPb[ptPosIter];
}
}
}
else if(sType == kPPDATA || sType == kPPMC){
Float_t ptArr[5] = {.50, 1.00, 3.00, 8.00, 1000000};
for(Int_t ptPosIter = 0; ptPosIter < 4; ptPosIter++){
if(pt > ptArr[ptPosIter] && pt <= ptArr[ptPosIter + 1])
return ptPosIter;
}
}
std::cout << "getPtBin: Shouldn't reach this point; check input" << std::endl;
return -1;
}
Float_t getTrkRMin(Float_t trkPhi, Float_t trkEta, Int_t nJt, Float_t jtPt[], Float_t jtPhi[], Float_t jtEta[], Bool_t disp = false)
{
Float_t trkRMin = 199;
Float_t jtFinPt = 0;
Float_t jtFinPhi = 0;
Float_t jtFinEta = 0;
if(nJt != 0){
for(Int_t jtEntry = 0; jtEntry < nJt; jtEntry++){
if(jtPt[jtEntry] < 50.0) continue;
if(TMath::Abs(jtEta[jtEntry]) > 2.0) continue;
if(trkRMin > getDR(trkEta, trkPhi, jtEta[jtEntry], jtPhi[jtEntry], 0)){
trkRMin = getDR(trkEta, trkPhi, jtEta[jtEntry], jtPhi[jtEntry], 0);
jtFinPt = jtPt[jtEntry];
jtFinPhi = jtPhi[jtEntry];
jtFinEta = jtEta[jtEntry];
}
}
}
if(disp) std::cout << jtFinEta << ",";
if(false) std::cout << " jtPt, Phi, eta: " << jtFinPt << ", " << jtFinPhi << ", " << jtFinEta << std::endl;
return trkRMin;
}
Float_t getEffCorr(Int_t corrBin, Int_t hiBin, Float_t pt, Float_t phi, Float_t eta, Float_t rmin, sampleType sType = kHIDATA)
{
Float_t effCorr = 1;
Bool_t isR = (rmin < 198);
if(sType == kHIDATA || sType == kHIMC){
effCorr = effCorr*(VsCalocent_p[corrBin]->GetBinContent(VsCalocent_p[corrBin]->FindBin(hiBin)));
effCorr = effCorr*(VsCalophiEta_p[corrBin]->GetBinContent(VsCalophiEta_p[corrBin]->FindBin(phi, eta)));
effCorr = effCorr*(VsCalopt_p[corrBin]->GetBinContent(VsCalopt_p[corrBin]->FindBin(pt)));
if(isR) effCorr = effCorr*(VsCalodelR_p[corrBin]->GetBinContent(VsCalodelR_p[corrBin]->FindBin(rmin)));
}
else if(sType == kPPDATA || kPPMC){
effCorr = effCorr*(CalophiEta_p[corrBin]->GetBinContent(CalophiEta_p[corrBin]->FindBin(phi, eta)));
effCorr = effCorr*(Calopt_p[corrBin]->GetBinContent(Calopt_p[corrBin]->FindBin(pt)));
if(isR) effCorr = effCorr*(CalodelR_p[corrBin]->GetBinContent(CalodelR_p[corrBin]->FindBin(rmin)));
}
if(effCorr == 0) std::cout << "Efficiency corr 0; pt, phi, eta, hiBin, rmin: " << pt << ", " << phi << ", " << eta << ", " << hiBin << ", " << rmin << std::endl;
return effCorr;
}
Float_t getFakeCorr(Int_t corrBin, Int_t hiBin, Float_t pt, Float_t phi, Float_t eta, Float_t rmin, sampleType sType = kHIDATA)
{
Float_t fakeCorr = 0;
Bool_t isR = (rmin < 198);
if(sType == kHIDATA || sType == kHIMC){
fakeCorr = fakeCorr + (FakeVsCalocent_p[corrBin]->GetBinContent(FakeVsCalocent_p[corrBin]->FindBin(hiBin)));
fakeCorr = fakeCorr + (FakeVsCalophiEta_p[corrBin]->GetBinContent(FakeVsCalophiEta_p[corrBin]->FindBin(phi, eta)));
fakeCorr = fakeCorr + (FakeVsCalopt_p[corrBin]->GetBinContent(FakeVsCalopt_p[corrBin]->FindBin(pt)));
if(isR) fakeCorr = fakeCorr + (FakeVsCalodelR_p[corrBin]->GetBinContent(FakeVsCalodelR_p[corrBin]->FindBin(rmin)));
}
else if(sType == kPPDATA || kPPMC){
fakeCorr = fakeCorr + (FakeCalophiEta_p[corrBin]->GetBinContent(FakeCalophiEta_p[corrBin]->FindBin(phi, eta)));
fakeCorr = fakeCorr + (FakeCalopt_p[corrBin]->GetBinContent(FakeCalopt_p[corrBin]->FindBin(pt)));
if(isR) fakeCorr = fakeCorr + (FakeCalodelR_p[corrBin]->GetBinContent(FakeCalodelR_p[corrBin]->FindBin(rmin)));
}
return fakeCorr;
}
//Feed variables and the histograms along w/ the appropriate rmincut (currently rmin only defined to 3 for PuPF and 5 for calo)
Float_t factorizedPtCorr(Int_t corrBin, Int_t hiBin, Float_t pt, Float_t phi, Float_t eta, Float_t rmin, sampleType sType = kHIDATA)
{
if(hiBin < 0 || hiBin > 199){
std::cout << "factorizedPtCorr: hiBin outside of acceptable range; check input" << std::endl;
return 1;
}
else if(pt >= 300.0) return 1;
// if(pt <= 0.50) pt = 0.500001;
if(pt <= 0.50) return 1;
else if(pt > .649999 && pt < .650001) pt = 0.650001;
if(hiBin > 195) hiBin = 195;
Float_t corrFactor = 1;
Float_t fake = getFakeCorr(corrBin, hiBin, pt, phi, eta, rmin, sType);
Float_t eff = getEffCorr(corrBin, hiBin, pt, phi, eta, rmin, sType);
corrFactor = (1 - fake)/(eff);
// if(corrFactor > 10) corrFactor = 1;
if(sType == kPPDATA || sType == kPPMC){
corrFactor = corrFactor*(1 - SecondCaloptEta_p->GetBinContent(SecondCaloptEta_p->FindBin(pt, eta)));
corrFactor = corrFactor/(1 + MultrecoCaloptEta_p->GetBinContent(MultrecoCaloptEta_p->FindBin(pt, eta)));
}
if(TMath::Abs(corrFactor) > 1000){
std::cout << "Problem: " << corrFactor << std::endl;
std::cout << "pt, phi, eta, hiBin, rmin: " << pt << ", " << phi << ", " << eta << ", " << hiBin << ", " << rmin << std::endl;
return 0;
}
return corrFactor;
}
/*
Example use:
In a directory with correction files open
InitCorrFiles(sType); // Initializes files
InitCorrHists(sType); // Initializes histograms
// Start looping over events
for(Int_t jentry = 0; jentry < nentries; jentry++){
tree->GetEntry(jentry);
InitPosArrPbPb(hiBin); // Initializes array with correct histogram position stored based on hiBin
// Now loop over tracks and grab corrections
for(Int_t trkIter = 0; trkIter < nTrk; trkIter++){
// call function to get correct array position (first arg) withing function grabbing correction
Float_t trkCorr = factorizedPtCorr(getPtBin(trkPt[trkIter], sType), hiBin, trkPt[trkIter], trkPhi[trkIter], trkEta[trkIter], trkRMin[trkIter], sType);
}
}
*/