-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClosureTest.C
More file actions
415 lines (367 loc) · 17.1 KB
/
ClosureTest.C
File metadata and controls
415 lines (367 loc) · 17.1 KB
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
#ifndef ClosureTest_cxx
#define ClosureTest_cxx
#include "LoadData_2012.C"
#include "tPrimeStandardHistos.C"
#include <iomanip>
#include "Objects/interface/HcalLaserEventFilter2012.h"
#include "Objects/interface/LumiReWeighting.h"
#include "MassAMWT/interface/TopMassVariables.h"
#include "MassAMWT/interface/AMWT.h"
#include "TCanvas.h"
using std::cout;
using std::endl;
int main( int argc, const char* argv[] ){
int MIN_BTAG_FR =-1;
bool b_MuMu = false;
bool b_ElEl = false;
bool b_MuEl = false;
int year;
if (argc < 4){
cout<<"Four arguments are required: channel, year, sample name and file name"<<endl;
return 0;
}
HcalLaserEventFilter2012 hcal("./AllBadHCALLaser.txt.gz");
TString treeSuf;
TString suffix;
int channel;
if (strcmp(argv[1],"MuMu")==0) {
b_MuMu = true;
channel = 0;
cout<<"Processing MuMu"<<endl;
suffix = "MuMu";
treeSuf = "mumu";
} else if (strcmp(argv[1],"MuEl")==0) {
channel = 1;
b_MuEl = true;
cout<<"Processing MuEl"<<endl;
suffix = "MuEl";
treeSuf = "muel";
} else if (strcmp(argv[1],"ElEl")==0){
channel = 2;
b_ElEl = true;
cout<<"Processing ElEl"<<endl;
suffix = "ElEl";
treeSuf = "elel";
}
else {
cout<<"Dilepton channel must be MuMu/ElEl/MuEl"<<endl;
return 0;
}
year = atoi(argv[2]);
TString sampleName(argv[3]);
TString fileName(argv[4]);
TprimeEvent * teve = new TprimeEvent();
if (year ==2011) {
initAll_2011(treeSuf, fileName, channel, sampleName);
} else if (year ==2012) {
initAll_2012(fileName, channel, sampleName);
} else {
cout <<"Year has to be 2011 or 2012\n";
return 0;
}
cout << "Init LumiReWeighting"<<endl;
std::string generatedFile("/data1/speer/tblsm/tools/data/pu_mc.root");
std::string dataFile("/data1/speer/tblsm/tools/data/pu_data.root");
std::string genHistName("PUS10_Distr");
std::string dataHistName("PUS10_Distr");
fexists(generatedFile,true);
fexists(dataFile,true);
LumiReWeighting lumiReWeighting(generatedFile, dataFile, genHistName, dataHistName);
//lumiReWeighting.weight(treeClass->nTrueInteractions);
cout << "Done lumi reweighting" << endl;
TCanvas* c = new TCanvas("c", "c", 600, 400);
TH1D* h_weight = new TH1D("h_weight", "h_weight", 100, 0.0, 5.0);
//Output file
TFile* outFile = new TFile("gfOutFile_"+sampleName+"_"+suffix+".root", "RECREATE");
unsigned int nCutSteps = 6;
int nProc=0;
int nRawEvents=0;
double observed_events=0.0;
double predicted_events=0.0;
int N_events=0;
int unmatched_0 = 0;
int unmatched_1 = 0;
int l_matched_0 = 0;
int l_matched_1 = 0;
int c_matched_0 = 0;
int c_matched_1 = 0;
int b_matched_0 = 0;
int b_matched_1 = 0;
int w_matched_0 = 0;
int w_matched_1 = 0;
int bad_from_b_0 = 0;
int bad_from_b_1 = 0;
int bad_from_c_0 = 0;
int bad_from_c_1 = 0;
int bad_from_l_0 = 0;
int bad_from_l_1 = 0;
int bad_from_w_0 = 0;
int bad_from_w_1 = 0;
int bad_unmatched_0 = 0;
int bad_unmatched_1 = 0;
int N_events_bad_muons = 0;
int N_events_bad_electrons = 0;
int predicted_events_bad_muons = 0;
int predicted_events_bad_electrons = 0;
int badMuons_from_b_0 = 0;
int badMuons_from_b_1 = 0;
int badMuons_from_c_0 = 0;
int badMuons_from_c_1 = 0;
int badMuons_from_l_0 = 0;
int badMuons_from_l_1 = 0;
int badMuons_from_w_0 = 0;
int badMuons_from_w_1 = 0;
int badMuons_unmatched_0 = 0;
int badMuons_unmatched_1 = 0;
int badElectrons_from_b_0 = 0;
int badElectrons_from_b_1 = 0;
int badElectrons_from_c_0 = 0;
int badElectrons_from_c_1 = 0;
int badElectrons_from_l_0 = 0;
int badElectrons_from_l_1 = 0;
int badElectrons_from_w_0 = 0;
int badElectrons_from_w_1 = 0;
int badElectrons_unmatched_0 = 0;
int badElectrons_unmatched_1 = 0;
for (unsigned int i = 0; i < NSAMPLES; i++){
unsigned int isam = samples[i];
if(samples[i] == FakeRate_Data){// || samples[i] == FakeRate_MC ){
Long64_t nEIT = treeClass.at(i)->getEntries();
cout<<"Events to be processed: "<<nEIT<<endl;
Long64_t iEvent = (Long64_t)(treeClass.at(i)->event + 0.01);
for (Long64_t il = 0; il < nEIT; il++){
treeClass.at(i)->GetEntry(il);
hcal.filter(treeClass.at(i)->run,treeClass.at(i)->lumi,treeClass.at(i)->event);
if (nProc % 100000 == 0) cout<<"Processed "<<nProc<<" events so far"<<endl;
nRawEvents++;
nProc++;
//Initialize TprimeEvent class
teve->clearEvent();
teve->suffix = suffix;
teve->isam = isam;
//Require exactly 1 lepton
bool b_LepCuts = false;
bool b_Tight=false;
double fake_rate=0.0;
if ((treeClass.at(i)->looseLeptons.size() ==2 )){
teve->lepton1=treeClass.at(i)->looseLeptons.at(0);
teve->lepton2=treeClass.at(i)->looseLeptons.at(1);
if (b_ElEl) {
if(treeClass.at(i)->looseElecs.size() == 2 && treeClass.at(i)->looseMuons.size() == 0){
b_LepCuts = true;
fake_rate=0.154;
}
}
else if(b_MuEl && treeClass.at(i)->looseMuons.size() == 1 && treeClass.at(i)->looseElecs.size() == 1){
b_LepCuts = true;
}
else if(b_MuMu && treeClass.at(i)->looseMuons.size() == 2 && treeClass.at(i)->looseElecs.size() == 0){
b_LepCuts = true;
fake_rate=0.284;
}
}
if ((treeClass.at(i)->goodLeptons.size() ==2)){
teve->lepton1 = treeClass.at(i)->goodLeptons.at(0);
teve->lepton2 = treeClass.at(i)->goodLeptons.at(1);
if(b_ElEl) {
if(treeClass.at(i)->goodElecs.size() == 2 && treeClass.at(i)->goodMuons.size() == 0 ){
b_Tight=true;
}
}
else if(b_MuEl && treeClass.at(i)->goodElecs.size() == 1 && treeClass.at(i)->goodMuons.size() == 1){
b_Tight = true;
}
else if(b_MuMu &&
treeClass.at(i)->goodMuons.size() == 2 && treeClass.at(i)->goodElecs.size() == 0){
b_Tight=true;
}
}
lumiReWeighting.weight(treeClass.at(i)->nTrueInteractions);
h_weight->Fill(lumiReWeighting.weight(treeClass.at(i)->nTrueInteractions));
if(b_LepCuts){
if(abs(treeClass.at(i)->looseLeptons.at(0)->charge + treeClass.at(i)->looseLeptons.at(1)->charge)==2){
if(b_MuMu || b_ElEl){
if((( treeClass.at(i)->looseLeptons.at(0)->origin()==24 && treeClass.at(i)->looseLeptons.at(0)->goodLepton())
&& (treeClass.at(i)->looseLeptons.at(1)->origin()!=24 && treeClass.at(i)->looseLeptons.at(1)->goodLepton()))
|| ((treeClass.at(i)->looseLeptons.at(1)->origin()==24 && treeClass.at(i)->looseLeptons.at(1)->goodLepton())
&& (treeClass.at(i)->looseLeptons.at(0)->origin()!=24 && treeClass.at(i)->looseLeptons.at(0)->goodLepton())) ){ observed_events++;// = observed_events + lumiReWeighting.weight(treeClass.at(i)->nTrueInteractions);
if(treeClass.at(i)->looseLeptons.at(0)->origin()==0){
unmatched_0++;
}
if(treeClass.at(i)->looseLeptons.at(0)->origin()==1){
l_matched_0++;
}
if(treeClass.at(i)->looseLeptons.at(0)->origin()==4){
c_matched_0++;
}
if(treeClass.at(i)->looseLeptons.at(0)->origin()==5){
b_matched_0++;
}
if(treeClass.at(i)->looseLeptons.at(0)->origin()==24){
w_matched_0++;
}
if(treeClass.at(i)->looseLeptons.at(1)->origin()==0){
unmatched_1++;
}
if(treeClass.at(i)->looseLeptons.at(1)->origin()==1){
l_matched_1++;
}
if(treeClass.at(i)->looseLeptons.at(1)->origin()==4){
c_matched_1++;
}
if(treeClass.at(i)->looseLeptons.at(1)->origin()==5){
b_matched_1++;
}
if(treeClass.at(i)->looseLeptons.at(1)->origin()==24){
w_matched_1++;
}
}
if((((treeClass.at(i)->looseLeptons.at(0)->origin()==24 && treeClass.at(i)->looseLeptons.at(0)->goodLepton()))
&& !treeClass.at(i)->looseLeptons.at(1)->goodLepton())
|| ((treeClass.at(i)->looseLeptons.at(1)->origin()==24
&& treeClass.at(i)->looseLeptons.at(1)->goodLepton())
&& !treeClass.at(i)->looseLeptons.at(0)->goodLepton())){
N_events++;// = N_events + lumiReWeighting.weight(treeClass.at(i)->nTrueInteractions);
predicted_events=(fake_rate/(1 - fake_rate))*N_events;
if(treeClass.at(i)->looseLeptons.at(0)->origin()==24 && treeClass.at(i)->looseLeptons.at(0)->goodLepton()){
if(!treeClass.at(i)->looseLeptons.at(1)->goodLepton() && treeClass.at(i)->looseLeptons.at(1)->origin()==5) bad_from_b_1++;
if(!treeClass.at(i)->looseLeptons.at(1)->goodLepton() && treeClass.at(i)->looseLeptons.at(1)->origin()==24) bad_from_w_1++;
if(!treeClass.at(i)->looseLeptons.at(1)->goodLepton() && treeClass.at(i)->looseLeptons.at(1)->origin()==4) bad_from_c_1++;
if(!treeClass.at(i)->looseLeptons.at(1)->goodLepton() && treeClass.at(i)->looseLeptons.at(1)->origin()==1)bad_from_l_1++;
if(!treeClass.at(i)->looseLeptons.at(1)->goodLepton() && treeClass.at(i)->looseLeptons.at(1)->origin()==0) bad_unmatched_1++;
}
if(treeClass.at(i)->looseLeptons.at(1)->origin()==24 && treeClass.at(i)->looseLeptons.at(1)->goodLepton()){
if(!treeClass.at(i)->looseLeptons.at(0)->goodLepton() && treeClass.at(i)->looseLeptons.at(0)->origin()==5) bad_from_b_0++;
if(!treeClass.at(i)->looseLeptons.at(0)->goodLepton() && treeClass.at(i)->looseLeptons.at(0)->origin()==24) bad_from_w_0++;
if(!treeClass.at(i)->looseLeptons.at(0)->goodLepton() && treeClass.at(i)->looseLeptons.at(0)->origin()==4) bad_from_c_0++;
if(!treeClass.at(i)->looseLeptons.at(0)->goodLepton() && treeClass.at(i)->looseLeptons.at(0)->origin()==1)bad_from_l_0++;
if(!treeClass.at(i)->looseLeptons.at(0)->goodLepton() && treeClass.at(i)->looseLeptons.at(0)->origin()==0) bad_unmatched_0++;
}
}
}//MuMu and ElEl condition closed
else if(b_MuEl){
if(((treeClass.at(i)->looseElecs.at(0)->origin()==24 &&
treeClass.at(i)->looseElecs.at(0)->goodElectron()) &&
(treeClass.at(i)->looseMuons.at(0)->origin()!=24 &&
treeClass.at(i)->looseMuons.at(0)->goodMuon())) ||
((treeClass.at(i)->looseMuons.at(0)->origin()==24 &&
treeClass.at(i)->looseMuons.at(0)->goodMuon()) &&
(treeClass.at(i)->looseElecs.at(0)->origin()!=24 &&
treeClass.at(i)->looseElecs.at(0)->goodElectron()))){
observed_events++;
if(treeClass.at(i)->looseElecs.at(0)->origin()==0){
unmatched_0++;
}
if(treeClass.at(i)->looseElecs.at(0)->origin()==1){
l_matched_0++;
}
if(treeClass.at(i)->looseElecs.at(0)->origin()==4){
c_matched_0++;
}
if(treeClass.at(i)->looseElecs.at(0)->origin()==5){
b_matched_0++;
}
if(treeClass.at(i)->looseElecs.at(0)->origin()==24){
w_matched_0++;
}
if(treeClass.at(i)->looseMuons.at(0)->origin()==0){
unmatched_1++;
}
if(treeClass.at(i)->looseMuons.at(0)->origin()==1){
l_matched_1++;
}
if(treeClass.at(i)->looseMuons.at(0)->origin()==4){
c_matched_1++;
}
if(treeClass.at(i)->looseMuons.at(0)->origin()==5){
b_matched_1++;
}
if(treeClass.at(i)->looseMuons.at(0)->origin()==24){
w_matched_1++;
}
}
if(((treeClass.at(i)->looseElecs.at(0)->origin()==24 &&
treeClass.at(i)->looseElecs.at(0)->goodElectron()) &&
!treeClass.at(i)->looseMuons.at(0)->goodMuon())){
N_events_bad_muons++;
double fake_rate=0.284;
predicted_events_bad_muons = (fake_rate/(1 - fake_rate))*N_events_bad_muons;
if(treeClass.at(i)->looseElecs.at(0)->origin()==24 && treeClass.at(i)->looseElecs.at(0)->goodElectron()){
if(!treeClass.at(i)->looseMuons.at(0)->goodMuon() && treeClass.at(i)->looseMuons.at(0)->origin()==5) badMuons_from_b_0++;
if(!treeClass.at(i)->looseMuons.at(0)->goodMuon() && treeClass.at(i)->looseMuons.at(0)->origin()==24) badMuons_from_w_0++;
if(!treeClass.at(i)->looseMuons.at(0)->goodMuon() && treeClass.at(i)->looseMuons.at(0)->origin()==4) badMuons_from_c_0++;
if(!treeClass.at(i)->looseMuons.at(0)->goodMuon() && treeClass.at(i)->looseMuons.at(0)->origin()==1) badMuons_from_l_0++;
if(!treeClass.at(i)->looseMuons.at(0)->goodMuon() && treeClass.at(i)->looseMuons.at(0)->origin()==0) badMuons_unmatched_0++;
}
}//predicted if closed
if(((treeClass.at(i)->looseMuons.at(0)->origin()==24 && treeClass.at(i)->looseMuons.at(0)->goodMuon()) && (!treeClass.at(i)->looseElecs.at(0)->goodElectron() && treeClass.at(i)->looseElecs.at(0)->origin()!=24))){
N_events_bad_electrons++;
double fake_rate=0.154;
predicted_events_bad_electrons = (fake_rate/(1 - fake_rate))*N_events_bad_electrons;
if(treeClass.at(i)->looseMuons.at(0)->origin()==24 && treeClass.at(i)->looseMuons.at(0)->goodMuon()){
if(!treeClass.at(i)->looseElecs.at(0)->goodElectron() && treeClass.at(i)->looseElecs.at(0)->origin()==5) badElectrons_from_b_0++;
if(!treeClass.at(i)->looseElecs.at(0)->goodElectron() && treeClass.at(i)->looseElecs.at(0)->origin()==24) badElectrons_from_w_0++;
if(!treeClass.at(i)->looseElecs.at(0)->goodElectron() && treeClass.at(i)->looseElecs.at(0)->origin()==4) badElectrons_from_c_0++;
if(!treeClass.at(i)->looseElecs.at(0)->goodElectron() && treeClass.at(i)->looseElecs.at(0)->origin()==1) badElectrons_from_l_0++;
if(!treeClass.at(i)->looseElecs.at(0)->goodElectron() && treeClass.at(i)->looseElecs.at(0)->origin()==0) badElectrons_unmatched_0++;
}
}//predicted "if" closed
}//b_MuEl requirement
}//same sign charge requirement for loose leptons
}//b_LepCuts/setting multiplicity
}//loop over entries
}//if statement
}//loop over samples
//couts
cout << "observed_events = " << observed_events << endl;
cout << "N_events = " << N_events << endl;
cout << "predicted_events = " << predicted_events << endl;
cout << "N_events_bad_electrons = " << N_events_bad_electrons << endl;
cout << "N_events_bad_muons = " << N_events_bad_muons << endl;
cout << "unmatched_0 = " << unmatched_0 << endl;
cout << "predicted_events_bad_muons = " << predicted_events_bad_muons << endl;
cout << "predicted_events_bad_electrons = " << predicted_events_bad_electrons << endl;
cout << "unmatched_1 = " << unmatched_1 << endl;
cout << "l_matched_0 = " << l_matched_0 << endl;
cout << "l_matched_1 = " << l_matched_1 << endl;
cout << "c_matched_0 = " << c_matched_0 << endl;
cout << "c_matched_1 = " << c_matched_1 << endl;
cout << "b_matched_0 = " << b_matched_0 << endl;
cout << "b_matched_1 = " << b_matched_1 << endl;
cout << "w_matched_0 = " << w_matched_0 << endl;
cout << "w_matched_1 = " << w_matched_1 << endl;
cout << "bad_unmatched_0 = " << bad_unmatched_0 << endl;
cout << "bad_unmatched_1 = " << bad_unmatched_1 << endl;
cout << "bad_from_1_0 = " << bad_from_l_0 << endl;
cout << "bad_from_1_1 = " << bad_from_l_1 << endl;
cout << "bad_from_c_0 = " << bad_from_c_0 << endl;
cout << "bad_from_c_1 = " << bad_from_c_1 << endl;
cout << "bad_from_b_0 = " << bad_from_b_0 << endl;
cout << "bad_from_b_1 = " << bad_from_b_1 << endl;
cout << "bad_from_w_0 = " << bad_from_w_0 << endl;
cout << "bad_from_w_1 = " << bad_from_w_1 << endl;
cout << "badMuons_unmatched_0 = " << badMuons_unmatched_0 << endl;
cout << "badMuons_unmatched_1 = " << badMuons_unmatched_1 << endl;
cout << "badMuons_from_1_0 = " << badMuons_from_l_0 << endl;
cout << "badMuons_from_1_1 = " << badMuons_from_l_1 << endl;
cout << "badMuons_from_c_0 = " << badMuons_from_c_0 << endl;
cout << "badMuons_from_c_1 = " << badMuons_from_c_1 << endl;
cout << "badMuons_from_b_0 = " << badMuons_from_b_0 << endl;
cout << "badMuons_from_b_1 = " << badMuons_from_b_1 << endl;
cout << "badMuons_from_w_0 = " << badMuons_from_w_0 << endl;
cout << "badMuons_from_w_1 = " << badMuons_from_w_1 << endl;
cout << "badElectrons_unmatched_0 = " << badElectrons_unmatched_0 << endl;
cout << "badElectrons_unmatched_1 = " << badElectrons_unmatched_1 << endl;
cout << "badElectrons_from_1_0 = " << badElectrons_from_l_0 << endl;
cout << "badElectrons_from_1_1 = " << badElectrons_from_l_1 << endl;
cout << "badElectrons_from_c_0 = " << badElectrons_from_c_0 << endl;
cout << "badElectrons_from_c_1 = " << badElectrons_from_c_1 << endl;
cout << "badElectrons_from_b_0 = " << badElectrons_from_b_0 << endl;
cout << "badElectrons_from_b_1 = " << badElectrons_from_b_1 << endl;
cout << "badElectrons_from_w_0 = " << badElectrons_from_w_0 << endl;
cout << "badElectrons_from_w_1 = " << badElectrons_from_w_1 << endl;
h_weight->Draw();
c->SaveAs("weights.pdf");
return 0;
}
#endif