-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZewkSelection.cc
More file actions
387 lines (317 loc) · 14.6 KB
/
ZewkSelection.cc
File metadata and controls
387 lines (317 loc) · 14.6 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
#include <iostream>
#include <string>
#include <TTree.h>
#include "CommonTools/include/Counters.hh"
#include "CommonTools/include/Selection.hh"
#include "CommonTools/include/Utils.hh"
#include "HiggsAnalysisTools/include/kFactorEvaluator.hh"
#include "HiggsAnalysisTools/include/ZewkSelection.hh"
ZewkSelection::ZewkSelection(TTree *tree)
: HiggsBase(tree) {
// Initialize kine selection
std::string fileCuts = "config/noteEWK/zeeCuts.txt";
std::string fileSwitches = "config/noteEWK/zeeSwitches.txt";
_selection = new Selection(fileCuts,fileSwitches);
_selection->addSwitch("MCtruth");
_selection->addSwitch("trigger");
_selection->addSwitch("apply_weight");
_selection->addCut("nRecoEle");
_selection->addCut("etaEleAcc");
_selection->addCut("etaCrack1");
_selection->addCut("etaCrack2");
_selection->addCut("ptEleAcc");
_selection->addCut("trackerPtSum");
_selection->addSwitch("TwoGolden");
_selection->addSwitch("TwoGoldenID");
_selection->addSwitch("OneTightGolden");
_selection->addSwitch("robustID");
_selection->addCut("Mee");
// EleID selection
Selection *_goldenSelectionEB = new Selection("config/noteEWK/electronIDGoldenCutsEB.txt","config/noteEWK/goldenIDSwitches.txt");
Selection *_robustSelectionEB = new Selection("config/noteEWK/electronIDRobustCutsEB.txt","config/noteEWK/robustIDSwitches.txt");
Selection *_goldenSelectionEE = new Selection("config/noteEWK/electronIDGoldenCutsEE.txt","config/noteEWK/goldenIDSwitches.txt");
Selection *_robustSelectionEE = new Selection("config/noteEWK/electronIDRobustCutsEE.txt","config/noteEWK/robustIDSwitches.txt");
_eleGoldenSelection.push_back(_goldenSelectionEB);
_eleGoldenSelection.push_back(_goldenSelectionEE);
_eleRobustSelection.push_back(_robustSelectionEB);
_eleRobustSelection.push_back(_robustSelectionEE);
std::vector<Selection*>::iterator goldenSelItr;
for(goldenSelItr=_eleGoldenSelection.begin();goldenSelItr!=_eleGoldenSelection.end();goldenSelItr++) {
Selection *eleGSelection = *goldenSelItr;
eleGSelection->addCut("hOverE");
eleGSelection->addCut("s9s25");
eleGSelection->addCut("deta");
eleGSelection->addCut("dphiIn");
eleGSelection->addCut("dphiOut");
eleGSelection->addCut("invEMinusInvP");
eleGSelection->addCut("bremFraction");
eleGSelection->addCut("covEtaEta");
eleGSelection->addCut("covPhiPhi");
eleGSelection->addCut("eOverPout");
eleGSelection->addCut("eOverPin");
eleGSelection->summary();
}
std::vector<Selection*>::iterator robSelItr;
for(robSelItr=_eleRobustSelection.begin();robSelItr!=_eleRobustSelection.end();robSelItr++) {
Selection *eleRSelection = *robSelItr;
eleRSelection->addCut("hOverE");
eleRSelection->addCut("deta");
eleRSelection->addCut("dphiIn");
eleRSelection->addCut("covEtaEta");
eleRSelection->summary();
}
std::map<std::string,std::pair<float,float> > selectionMap = _selection->getSelection();
_selection->summary();
// Initialize additional counters...
_counter.SetTitle("EVENT COUNTER");
_counter.AddVar("event");
_counter.AddVar("MCtruth");
_counter.AddVar("eveHLT");
_counter.AddVar("eleReco");
_counter.AddVar("eleEta");
_counter.AddVar("eleCrack");
_counter.AddVar("elePt");
_counter.AddVar("eleIso");
_counter.AddVar("eleTwoGolden");
_counter.AddVar("eleTwoGoldenID");
_counter.AddVar("eleOneTightGolden");
_counter.AddVar("eleRobustID");
_counter.AddVar("mee");
_counter.AddVar("final");
_eleCounter.SetTitle("SINGLE ELECTRON COUNTER");
_eleCounter.AddVar("electrons");
_eleCounter.AddVar("hOverE");
_eleCounter.AddVar("s9s25");
_eleCounter.AddVar("deta");
_eleCounter.AddVar("dphiIn");
_eleCounter.AddVar("dphiOut");
_eleCounter.AddVar("invEMinusInvP");
_eleCounter.AddVar("bremFraction");
_eleCounter.AddVar("covEtaEta");
_eleCounter.AddVar("covPhiPhi");
_eleCounter.AddVar("eOverPout");
_eleCounter.AddVar("eOverPin");
_eleCounter.AddVar("finalEleID");
// the kinematic vectors
_p4Ele = new TLorentzVector(0.,0.,0.,0.);
_p4Pos = new TLorentzVector(0.,0.,0.,0.);
}
ZewkSelection::~ZewkSelection(){
delete _p4Ele;
delete _p4Pos;
}
bool ZewkSelection::findMcTree(const char* processType) {
// bool processOk = false;
// if(strcmp(processType,"bbar_550")==0) {
// if ( (genFilterEff == 0.00019)
// && (genProcessId == 11 || genProcessId == 12 || genProcessId == 13 || genProcessId == 28 || genProcessId == 68 || genProcessId == 53 || genProcessId == 95)
// && (genPtHat > 5 && genPtHat < 50)
// )
// { processOk = true; }
// }
// if(strcmp(processType,"bbar_50170")==0) {
// if ( (genFilterEff == 0.0068)
// && (genProcessId == 11 || genProcessId == 12 || genProcessId == 13 || genProcessId == 28 || genProcessId == 68 || genProcessId == 53 || genProcessId == 95)
// && (genPtHat > 50 && genPtHat < 170)
// ){ processOk = true; }
// }
// if (strcmp(processType,"bbar_170up")==0) {
// if ( (genFilterEff == 0.0195)
// && (genProcessId == 11 || genProcessId == 12 || genProcessId == 13 || genProcessId == 28 || genProcessId == 68 || genProcessId == 53 || genProcessId == 95)
// && (genPtHat > 170)
// ){ processOk = true; }
// }
// return processOk;
return true;
}
void ZewkSelection::Loop() {
_verbose=true;
if(fChain == 0) return;
// tree
Long64_t nbytes = 0, nb = 0;
Long64_t nentries = fChain->GetEntries();
if(_verbose) std::cout << "Number of entries = " << nentries << std::endl;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
if (_verbose && jentry%1000 == 0) std::cout << ">>> Processing event # " << jentry << std::endl;
// get the weight of the event for the soup
float weight = 1.0;
// if(_selection->getSwitch("apply_weight")) weight = genWeight;
if(_selection->getSwitch("apply_weight")) weight = 1.0;
_counter.IncrVar("event",weight);
// event type for the soup
bool foundMcTree = findMcTree("bbar_550");
if(_selection->getSwitch("MCtruth") &&
!foundMcTree ) continue;
_counter.IncrVar("MCtruth",weight);
Utils anaUtils;
if(_selection->getSwitch("trigger") && !( anaUtils.getTriggersOR(m_requiredTriggers, firedTrg) ) ) continue;
_counter.IncrVar("eveHLT",weight);
if(!_selection->passCut("nRecoEle",nEle)) continue;
_counter.IncrVar("eleReco",weight);
int theEle(getBestLeptonPair().first);
int thePos(getBestLeptonPair().second);
if(theEle<0 || thePos<0) {
std::cout << "mah, non dovrebbe succedere mai" << std::endl;
continue;
}
setKinematics(theEle, thePos);
addVariables();
if(_selection->getSwitch("ptEleAcc") && !_selection->passCut("ptEleAcc",etEle[theEle]) ) continue;
if(_selection->getSwitch("ptEleAcc") && !_selection->passCut("ptEleAcc",etEle[thePos]) ) continue;
_counter.IncrVar("elePt",weight);
if(_selection->getSwitch("etaEleAcc") && !_selection->passCut("etaEleAcc",etaEle[theEle]) ) continue;
if(_selection->getSwitch("etaEleAcc") && !_selection->passCut("etaEleAcc",etaEle[thePos]) ) continue;
_counter.IncrVar("eleEta",weight);
float absEleEta = fabs(etaEle[theEle]);
float absPosEta = fabs(etaEle[thePos]);
if(_selection->getSwitch("etaCrack1") &&
_selection->getSwitch("etaCrack2") &&
!_selection->passCut("etaCrack1",absEleEta) &&
!_selection->passCut("etaCrack2",absEleEta)
) continue;
if(_selection->getSwitch("etaCrack1") &&
_selection->getSwitch("etaCrack2") &&
!_selection->passCut("etaCrack1",absPosEta) &&
!_selection->passCut("etaCrack2",absPosEta)
) continue;
_counter.IncrVar("eleCrack",weight);
float myEleIso = eleSumPt04Ele[theEle];
float myPosIso = eleSumPt04Ele[thePos];
if(_selection->getSwitch("trackerPtSum") &&
( !_selection->passCut("trackerPtSum",myEleIso) )) continue;
if(_selection->getSwitch("trackerPtSum") &&
( !_selection->passCut("trackerPtSum",myPosIso) )) continue;
_counter.IncrVar("eleIso",weight);
bool isEleGolden = false;
bool isPosGolden = false;
if((classificationEle[theEle]==0) || (classificationEle[theEle]==100)) isEleGolden = true;
if((classificationEle[thePos]==0) || (classificationEle[thePos]==100)) isPosGolden = true;
if(_selection->getSwitch("TwoGolden") && !isEleGolden) continue;
if(_selection->getSwitch("TwoGolden") && !isPosGolden) continue;
_counter.IncrVar("eleTwoGolden",weight);
if(_selection->getSwitch("TwoGoldenID") && !isGoldenID(theEle)) continue;
if(_selection->getSwitch("TwoGoldenID") && !isGoldenID(thePos)) continue;
_counter.IncrVar("eleTwoGoldenID",weight);
bool noGoldenEle = false;
bool noGoldenPos = false;
if(!isGoldenID(theEle)) noGoldenEle = true;
if(!isGoldenID(thePos)) noGoldenPos = true;
if(_selection->getSwitch("OneTightGolden") && noGoldenEle && noGoldenPos) continue;
_counter.IncrVar("eleOneTightGolden",weight);
if(_selection->getSwitch("robustID") && (!isRobustID(theEle) || !isRobustID(thePos)) ) continue;
_counter.IncrVar("eleRobustID",weight);
float mee = (*_p4Ele+*_p4Pos).M();
if(_selection->getSwitch("Mee") && !_selection->passCut("Mee",mee)) continue;
_counter.IncrVar("mee",weight);
_counter.IncrVar("final",weight);
}
}
void ZewkSelection::displayEfficiencies() {
_eleCounter.Draw();
_eleCounter.Draw("hOverE","electrons");
_eleCounter.Draw("s9s25","hOverE");
_eleCounter.Draw("deta","s9s25");
_eleCounter.Draw("dphiIn","deta");
_eleCounter.Draw("dphiOut","dphiIn");
_eleCounter.Draw("invEMinusInvP","dphiOut");
_eleCounter.Draw("bremFraction","invEMinusInvP");
_eleCounter.Draw("covEtaEta","bremFraction");
_eleCounter.Draw("covPhiPhi","covEtaEta");
_eleCounter.Draw("eOverPout","covPhiPhi");
_eleCounter.Draw("eOverPin","eOverPout");
_eleCounter.Draw("finalEleID","eOverPin");
_eleCounter.Draw("finalEleID","electrons");
_counter.Draw();
_counter.Draw("MCtruth", "event");
_counter.Draw("eveHLT", "MCtruth");
_counter.Draw("eleReco", "eveHLT");
_counter.Draw("elePt", "eleReco");
_counter.Draw("eleEta", "elePt");
_counter.Draw("eleCrack", "eleEta");
_counter.Draw("eleIso", "eleCrack");
_counter.Draw("eleTwoGolden", "eleIso");
_counter.Draw("eleTwoGoldenID", "eleTwoGolden");
_counter.Draw("eleOneTightGoldenID", "eleTwoGoldenID");
_counter.Draw("eleRobustID", "eleOneTightGolden");
_counter.Draw("mee", "eleRobustID");
_counter.Draw("final", "mee");
_counter.Draw("final", "MCtruth");
}
// also charge requirement?
std::pair<int,int> ZewkSelection::getBestLeptonPair() {
int theEle1=-1;
int theEle2=-1;
float maxPt1=-1000.;
float maxPt2=-1001.;
std::vector<int> goodRecoLeptons;
for(int i=0;i<nEle;i++) {
TVector3 pEle(pxEle[i],pyEle[i],pzEle[i]);
float thisPt=pEle.Pt();
if (thisPt>maxPt1 && thisPt>maxPt2){ maxPt2 = maxPt1; maxPt1 = thisPt; theEle2 = theEle1; theEle1 = i; }
if (thisPt<maxPt1 && thisPt>maxPt2){ maxPt2 = thisPt; theEle2 = i; }
}
return make_pair(theEle1,theEle2);
}
bool ZewkSelection::isGoldenID(int eleIndex) {
TVector3 pTrkAtInner(pxAtInnerEle[eleIndex],pyAtInnerEle[eleIndex],pzAtInnerEle[eleIndex]);
TVector3 pTrkAtOuter(pxAtOuterEle[eleIndex],pyAtOuterEle[eleIndex],pzAtOuterEle[eleIndex]);
int GsfClass = classificationEle[eleIndex];
Selection *selection;
if(GsfClass<100) selection=_eleGoldenSelection[0];
else if(GsfClass>=100) selection=_eleGoldenSelection[1];
_eleCounter.IncrVar("electrons");
if(selection->getSwitch("hOverE") && !selection->passCut("hOverE",hOverEEle[eleIndex])) return false;
_eleCounter.IncrVar("hOverE");
if(selection->getSwitch("s9s25") && !selection->passCut("s9s25",s9s25Ele[eleIndex])) return false;
_eleCounter.IncrVar("s9s25");
if(selection->getSwitch("deta") && !selection->passCut("deta",deltaEtaAtVtxEle[eleIndex])) return false;
_eleCounter.IncrVar("deta");
if(selection->getSwitch("dphiIn") && !selection->passCut("dphiIn",deltaPhiAtVtxEle[eleIndex])) return false;
_eleCounter.IncrVar("dphiIn");
if(selection->getSwitch("dphiOut") && !selection->passCut("dphiOut",deltaPhiAtCaloEle[eleIndex])) return false;
_eleCounter.IncrVar("dphiOut");
if(selection->getSwitch("invEMinusInvP") && !selection->passCut("invEMinusInvP",1./fabs(ecalEle[eleIndex]-1./pTrkAtInner.Mag()))) return false;
_eleCounter.IncrVar("invEMinusInvP");
if(selection->getSwitch("bremFraction") &&
!selection->passCut("bremFraction",fabs(pTrkAtInner.Mag()-pTrkAtOuter.Mag())/pTrkAtInner.Mag())) return false;
_eleCounter.IncrVar("bremFraction");
if(selection->getSwitch("covEtaEta") && !selection->passCut("covEtaEta",covEtaEtaEle[eleIndex])) return false;
_eleCounter.IncrVar("covEtaEta");
if(selection->getSwitch("covPhiPhi") && !selection->passCut("covPhiPhi",covPhiPhiEle[eleIndex])) return false;
_eleCounter.IncrVar("covPhiPhi");
if(selection->getSwitch("eOverPout") && !selection->passCut("eOverPout",eSeedOverPoutEle[eleIndex])) return false;
_eleCounter.IncrVar("eOverPout");
if(selection->getSwitch("eOverPin") && !selection->passCut("eOverPin",eSuperClusterOverPEle[eleIndex])) return false;
_eleCounter.IncrVar("eOverPin");
_eleCounter.IncrVar("finalEleID");
return true;
}
bool ZewkSelection::isRobustID(int eleIndex) {
int GsfClass = classificationEle[eleIndex];
Selection *selection;
if(GsfClass <100) selection=_eleRobustSelection[0];
else if(GsfClass>=100) selection=_eleRobustSelection[1];
_eleCounter.IncrVar("electrons");
if(selection->getSwitch("hOverE") && !selection->passCut("hOverE",hOverEEle[eleIndex])) return false;
_eleCounter.IncrVar("hOverE");
if(selection->getSwitch("deta") && !selection->passCut("deta",deltaEtaAtVtxEle[eleIndex])) return false;
_eleCounter.IncrVar("deta");
if(selection->getSwitch("dphiIn") && !selection->passCut("dphiIn",deltaPhiAtVtxEle[eleIndex])) return false;
_eleCounter.IncrVar("dphiIn");
if(selection->getSwitch("covEtaEta") && !selection->passCut("covEtaEta",covEtaEtaEle[eleIndex])) return false;
_eleCounter.IncrVar("covEtaEta");
_eleCounter.IncrVar("finalEleID");
return true;
}
void ZewkSelection::addVariables() {
for(int i=0;i<nEle;i++) {
_eOverP[i]=ecalEle[i]/energyEle[i];
}
}
void ZewkSelection::setKinematics(int theEle, int thePos) {
_p4Ele->SetXYZT(pxEle[theEle],pyEle[theEle],pzEle[theEle],energyEle[theEle]);
_p4Pos->SetXYZT(pxEle[thePos],pyEle[thePos],pzEle[thePos],energyEle[thePos]);
}