forked from folguera/TOP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreeAnalysisTop.h
444 lines (397 loc) · 11.6 KB
/
TreeAnalysisTop.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
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
436
437
438
439
440
441
442
443
444
#ifndef TREEANALYSIS_TOP_H
#define TREEANALYSIS_TOP_H 1
#include "PAFAnalysis.h"
#include "TCounterUI.h"
#include "PUWeight.h"
//#include "GlobalVariables.h"
#include "LeptonSF.h"
#include "BTagSFUtil.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TEfficiency.h"
#include "TLorentzVector.h"
#include "TVector3.h"
#include "TTree.h"
#include "TString.h"
#include "TRandom3.h"
#include <fstream>
#include <iostream>
#include <vector>
enum gChannel{
channels_begin,
Muon = channels_begin,
Elec,
ElMu,
gNCHANNELS,
};
TString gChanLabel[gNCHANNELS] = {"Muon","Elec","ElMu"};
enum gFPSwitch{
SigSup,
ZDecay,
Sig
};
enum iCut{
iDilepton,
iZVeto,
iMET,
i2jets,
i1btag,
iExact1btag,
iExact2btag,
iNCUTS
};
TString sCut[iNCUTS] = {"dilepton", "ZVeto", "MET", "2jets", "1btag","Exact1btag","Exact2btag"};
enum gSystFlag{
Norm,
BtagUp,
BtagDown,
MisTagUp,
MisTagDown,
JESUp,
JESDown,
JER,
LESUp,
LESDown,
/* LepUp,
LepDown,
TrigUp,
TrigDown,
*/
PUUp,
PUDown,
TopPt,
gNSYST
};
TString SystName[gNSYST] = {
"Normal",
"BtagUp",
"BtagDown",
"MisTagUp",
"MisTagDown",
"JESUp",
"JESDown",
"JER",
"LESUp",
"LESDown",
/* "LepUp",
"LepDown",
"TrigUp",
"TrigDown",*/
// "METUp",
// "METDown",
"PUUp",
"PUDown",
"TopPt",
};
enum FakeSource{
HF_mu,
Other_mu,
HF_el,
Conv_el,
Other_el,
RightSign,
WrongSign,
gNFAKESOURCE
};
class lepton{
public:
lepton(){}
lepton(const lepton &l): p(l.p), charge(l.charge), type(l.type), index(l.index){ };
lepton(TLorentzVector vec, int ch, int ty, int ind){
p = vec;
charge = ch;
type = ty;
index = ind;
}
TLorentzVector p;
int charge;
int type; // -1(unknown), 0(mu), 1(ele)
int index;
};
class jet{
public:
jet(){};
jet(TLorentzVector vec, bool btag, int ind){
p = vec;
isbtag = btag;
index = ind;
};
TLorentzVector p;
bool isbtag;
int index;
};
const int gNMuFPtBins = 6;
const int gNMuPPtbins = 10;
const int gNMuEtabins = 5;
const int gNElFPtBins = 8;
const int gNElPPtbins = 10;
const int gNElEtabins = 5;
const int gNElCMIdbins = 2;
// Muon Binning
double gMuFPtBins[gNMuFPtBins+1] = {20., 25., 30., 35., 40., 50., 60.};
double gMuPPtbins[gNMuPPtbins+1] = {20., 25., 30., 35., 40., 50., 60., 70., 80., 90., 100.};
double gMuEtabins[gNMuEtabins+1] = {0., 0.5, 1.0, 1.479, 2.0, 2.5};
// Electron Binning //////////////////////////////////////////////////////////////
double gElFPtBins[gNElFPtBins+1] = {20., 25., 30., 40., 50., 60., 70., 80., 100.};
double gElPPtbins[gNElPPtbins+1] = {20., 25., 30., 35., 40., 50., 60., 70., 80., 90., 100.};
double gElEtabins[gNElEtabins+1] = {0., 0.5, 1.0, 1.479, 2.0, 2.5};
int getNFPtBins(gChannel chan){ // fake ratios
if(chan == Muon || chan == ElMu) return gNMuFPtBins;
if(chan == Elec) return gNElFPtBins;
else return -99;
};
double *getFPtBins (gChannel chan){
if(chan == Muon || chan == ElMu) return gMuFPtBins;
else return gElFPtBins;
// if(chan == Elec) return gElFPtBins;
// else return *-999;
};
int getNPPtBins(gChannel chan){
if(chan == Muon || chan == ElMu) return gNMuPPtbins;
if(chan == Elec) return gNElPPtbins;
else return -99;
};
double *getPPtBins (gChannel chan){
if(chan == Muon || chan == ElMu) return gMuPPtbins;
else return gElPPtbins;
// if(chan == Elec) return gElPPtbins;
// else return -99;
};
int getNEtaBins(gChannel chan){
if(chan == Muon || chan == ElMu) return gNMuEtabins;
if(chan == Elec) return gNElEtabins;
else return -99;
};
double *getEtaBins (gChannel chan){
if(chan == Muon || chan == ElMu) return gMuEtabins;
else return gElEtabins;
// if(chan == Elec) return gElEtabins;
// else return *-99.;
};
class TreeAnalysisTop: public PAFAnalysis {
public:
TreeAnalysisTop(TTree *tree=0);
virtual ~TreeAnalysisTop() {}
virtual void Initialise();
virtual void InitialiseYieldsHistos();
virtual void InitialiseKinematicHistos();
virtual void InitialiseDYHistos();
virtual void InitialiseGenHistos();
virtual void InitialiseSystematicHistos();
virtual void InsideLoop();
virtual void SetDataMembersAtTermination();
virtual void Summary();
// Saving Histograms.
void WriteHistos();
void WriteValidationsHistos(){};
// Counters
//TCounterUI *nEvents;
// My member functions
//----------------------------------------------------------------------------
void GetParameters();
Int_t SelectedVertexIndex();
bool PassTriggerMuMu();
bool PassTriggerEE();
bool PassTriggerEMu();
bool PassesZVeto();
bool PassesNJetsCut();
bool PassesMETCut();
bool PassesNBtagCut();
bool PassesMllVeto();
bool Passes3rdLeptonVeto();
bool PassesMuonEta2p1(gChannel);
bool PassesTopDCut();
int getNJets();
int getNBTags();
int getLeadingJetbTag();
float getDRClosestJet(TLorentzVector);
float getDPhiClosestJet(TLorentzVector);
// int getNBTagsMed();
void setMET(float);
float getMET();
float getMETPhi();
float getMT(int, gChannel);
float getHT();
float getJetPtIndex(unsigned int);
float getBtagJetPtIndex(unsigned int);
float getErrPt(float,float);
float getJERScale(int);
float getSF(gChannel);
float getLeptonError(gChannel);
float getTriggerError(gChannel);
float getTopPtSF();
float getTopD();
float getDeltaPhillJet();
// Lepton selection methods
int getSelectedLeptons();
bool IsVetoMuon(unsigned int, float ptcut=20.);
bool IsTightMuon(unsigned int, float ptcut=20.);
float getMuonIso(int);
bool IsVetoElectron(unsigned int,float ptcut=20.);
bool IsMVAIDElectron(unsigned int);
bool IsTightElectron(unsigned int,float ptcut=20.);
float getElecIso(int);
float getEACorrection(float);
std::vector<lepton> SortLeptonsByPt(std::vector<lepton>&);
int getSelectedJets();
bool IsGoodJet(unsigned int, float ptcut=30.);
std::vector<int> CleanedJetIndices(float);
void SmearJetPts(int);
void propagateMET(TLorentzVector,TLorentzVector);
void ScaleMET(int);
void ScaleLeptons(int);
//void GetGenMuon();
//void GetGenElec();
void SelectedGenLepton();
/////////////////////////////////////////////////////////////////////////////
// Selecting Methods
/////////////////////////////////////////////////////////////////////////////
int IsDileptonEvent();
bool IsMuMuEvent();
bool IsElMuEvent();
bool IsElElEvent();
/////////////////////////////////////////////////////////////////////////////
// Filling Methods
/////////////////////////////////////////////////////////////////////////////
void FillYieldsHistograms(gChannel, iCut, gSystFlag);
void FillYields(gSystFlag sys=Norm);
void FillDYHistograms();
void FillKinematicHistos(gChannel,iCut);
/////////////////////////////////////////////////////////////////////////////
// Set/Reset methods
/////////////////////////////////////////////////////////////////////////////
void SetOriginalObjects();
void ResetOriginalObjects();
void SetEventObjects();
void ResetHypLeptons();
protected:
// Input parameters
//----------------------------------------------------------------------------
TString gSampleName;
TString gfileSuffix;
Float_t gWeight;
Float_t gLumiForPU;
Float_t gTotalLumi;
Int_t gSysSource;
Int_t gSysDirection;
Bool_t gDoSystStudies;
Bool_t gIsData;
Bool_t gUseCSVM;
Bool_t gDoSF;
Bool_t gDoDF;
Float_t gStopMass;
Float_t gLspMass;
PUWeight *fPUWeight; //The PU weight utility
PUWeight *fPUWeightUp; //The PU weight utility
PUWeight *fPUWeightDown; //The PU weight utility
BTagSFUtil *fBTagSF; //The BTag SF utility
LeptonSF *fLeptonSF;
TRandom3 *fRand3;
// EventWeight
//----------------------------------------------------------------------------
float EventWeight;
float PUSF;
bool fChargeSwitch;
//////////////////////////////////////////////////////////////////////////////
// Data members
//////////////////////////////////////////////////////////////////////////////
// HISTOGRAMS
//++ Yields
TH1F* fHDummy;
TH1F* hWeight;
TH1F* fHyields [gNCHANNELS][gNSYST];
TH1F* fHSSyields[gNCHANNELS][gNSYST];
TH1F* fHTopPtWeight;
TH1F* fHpdfWeightSum;
TH1F* fHpdfWeight;
TH1F* fHLepSys[gNCHANNELS][iNCUTS];
TH1F* fHTrigSys[gNCHANNELS][iNCUTS];
TH2F* fHDY_InvMassVsNPV [gNCHANNELS][iNCUTS];
TH2F* fHDY_InvMassVsMET [gNCHANNELS][iNCUTS];
TH2F* fHDY_InvMassVsNjets [gNCHANNELS][iNCUTS];
TH2F* fHDY_InvMassVsNbtags[gNCHANNELS][iNCUTS];
TH1F* fHDY_InvMass [gNCHANNELS][iNCUTS];
//++ Origin Histos
// TH2F* fHSSOrigins[gNCHANNELS][iNCUTS];
// TH2F* fHOrigins[gNCHANNELS][iNCUTS];
//++ Kinematic
TH1F* fHMET[gNCHANNELS][iNCUTS];
TH1F* fHDiLepPt[gNCHANNELS][iNCUTS];
TH1F* fHLep0Pt[gNCHANNELS][iNCUTS];
TH1F* fHLep1Pt[gNCHANNELS][iNCUTS];
TH1F* fHDelLepPhi[gNCHANNELS][iNCUTS];
TH1F* fHNJets[gNCHANNELS][iNCUTS];
TH1F* fHHT[gNCHANNELS][iNCUTS];
TH1F* fHNBtagJets[gNCHANNELS][iNCUTS];
TH1F* fHJet0Pt[gNCHANNELS][iNCUTS];
TH1F* fHJet1Pt[gNCHANNELS][iNCUTS];
TH1F* fHBtagJet0Pt[gNCHANNELS][iNCUTS];
TH1F* fHInvMass[gNCHANNELS][iNCUTS][gNSYST];
TH1F* fHSSInvMass[gNCHANNELS][iNCUTS][gNSYST];
TH1F* fHNBtagsNJets[gNCHANNELS][iNCUTS][gNSYST];
TH1F* fHSSNBtagsNJets[gNCHANNELS][iNCUTS][gNSYST];
TH1F* fHCSVTag[gNCHANNELS][iNCUTS];
TH1F* fHTopD[gNCHANNELS][iNCUTS];
TH1F* fHDelPhillJet[gNCHANNELS][iNCUTS];
TH1F* fHDRLep[gNCHANNELS][iNCUTS];
TH1F* fHDRLep0Jet[gNCHANNELS][iNCUTS];
TH1F* fHDPhiLep0Jet[gNCHANNELS][iNCUTS];
TH1F* fHLep0Iso[gNCHANNELS][iNCUTS];
TH1F* fHDRLep1Jet[gNCHANNELS][iNCUTS];
TH1F* fHDPhiLep1Jet[gNCHANNELS][iNCUTS];
TH1F* fHLep1Iso[gNCHANNELS][iNCUTS];
/// STOP
//TH1F* fHAbsDelPhiLep[gNCHANNELS][iNCUTS];
TH1F* fHminDelRJetsLeps[gNCHANNELS][iNCUTS][gNSYST];
TH1F* fHSSminDelRJetsLeps[gNCHANNELS][iNCUTS][gNSYST];
TH1F* fHdelPhi2LeadJets[gNCHANNELS][iNCUTS][gNSYST];
TH1F* fHSSdelPhi2LeadJets[gNCHANNELS][iNCUTS][gNSYST];
TH1F* fHAbsDelPhiLeps[gNCHANNELS][iNCUTS][gNSYST];
TH1F* fHSSAbsDelPhiLeps[gNCHANNELS][iNCUTS][gNSYST];
TH1F* fHStopMass[gNCHANNELS][iNCUTS];
TH1F* fHChi0Mass[gNCHANNELS][iNCUTS];
TH2F* fHChi0StopMass[gNCHANNELS][iNCUTS];
TH1F* fHvertices[gNCHANNELS][iNCUTS];
//++ Gen Info
TH1F* fHDeltaRLepJet[gNCHANNELS-1];
lepton fHypLepton1;
lepton fHypLepton2;
std::vector<Double_t> Gen_Muon_Charge;
std::vector<Double_t> Gen_Elec_Charge;
std::vector<TLorentzVector> Gen_Muon;
std::vector<TLorentzVector> Gen_Elec;
std::vector<Int_t> NGen_Jet;
std::vector<Int_t> NGen_b;
std::vector<Double_t> PtGen_Jet;
std::vector<Double_t> PtGen_b;
Int_t nGenElec;
Int_t nGenMuon;
Int_t nGenTau;
Int_t nGenLepton;
Int_t nTauElec;
Int_t nTauMuon;
Int_t nSGenMuon;
Int_t nSGenElec;
Int_t nGoodVertex;
Int_t nBtags;
Int_t nJets;
Int_t nMuon;
Int_t nElec;
Int_t nLeptons;
///// OBJECTS
std::vector<lepton> Lepton;
std::vector<jet> Jet;
// std::vector<jet> Jet15;
std::vector<float> JetEt;
std::vector<float> JetPhi;
std::vector<float> MuPx;
std::vector<float> MuPy;
std::vector<float> ElPx;
std::vector<float> ElPy;
float MET;
float MET_Phi;
ClassDef(TreeAnalysisTop,0);
};
#endif
/* LocalWords: ifndef
*/