forked from mbluj/ProductionFromNano
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHTTEvent.h
More file actions
435 lines (271 loc) · 12.9 KB
/
HTTEvent.h
File metadata and controls
435 lines (271 loc) · 12.9 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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#ifndef WarsawAnalysis_HTTDataFormats_HTTEvent_h
#define WarsawAnalysis_HTTDataFormats_HTTEvent_h
#include "TLorentzVector.h"
#include "TVector3.h"
#include "TBits.h"
#include <map>
#include <vector>
#include <bitset>
#include <iostream>
#include "PropertyEnum.h"
#include "JecUncEnum.h"
#include "TriggerEnum.h"
#include "FilterEnum.h"
#include "SelectionBitsEnum.h"
#include "AnalysisEnums.h"
///////////////////////////////////////////////////
///////////////////////////////////////////////////
class HTTEvent{
public:
enum sampleTypeEnum {DUMMY = -1, DATA = 0, DY = 1, DYLowM = 2, WJets=3, TTbar=4, h=5, H=6, A=7};
static const int ntauIds = 13;
static const int againstMuIdOffset = 0;
static const int againstEIdOffset = againstMuIdOffset+2;
static const int mvaIsoIdOffset = againstEIdOffset+5;
static const TString tauIDStrings[ntauIds];//implementation in cxx
HTTEvent(){clear();}
~HTTEvent(){}
///Data member setters.
void setRun(unsigned int x){runId = x;}
void setEvent(unsigned long int x){eventId = x;}
void setLS(unsigned long int x){lsId = x;}
void setNPU(float x){nPU = x;}
void setNPV(unsigned int x){nPV = x;}
void setRho(float x){rho = x;}
void setMCatNLOWeight(float x){aMCatNLOweight = x;}
void setMCWeight(float x){mcWeight = x;}
void setPtReWeight(float x){ptReWeight = x;}
void setPtReWeightR1(float x){ptReWeightR1 = x;}
void setPtReWeightSUSY(float x){ptReWeightSUSY = x;}
void setLHE_Ht(float x){lheHt = x;}
void setLHEnOutPartons(int x){lheNOutPartons = x;}
void setSampleType(sampleTypeEnum x){sampleType = x;}
void setDecayModeMinus(int x){decayModeMinus = x;}
void setDecayModePlus(int x){decayModePlus = x;}
void setDecayModeBoson(int x){decayModeBoson = x;}
void setGenBosonP4(const TLorentzVector &p4, const TLorentzVector &visP4) {bosP4 = p4; bosVisP4 = visP4; }
void setGenPV(const TVector3 & aPV) {genPV = aPV;}
void setAODPV(const TVector3 & aPV) {AODPV = aPV;}
void setRefittedPV(const TVector3 & aPV) {refittedPV = aPV;}
void setIsRefit(bool aBit){isRefit = aBit;};
void setNTracksInRefit(const int & nTracks) {nTracksInRefit = nTracks;};
void setSelectionBit(SelectionBitsEnum iBit, bool value = true) {selectionWord.SetBitNumber((int)iBit, value);}
void setMET(const TVector2 &aVector) {met = aVector;}
void setMET_uncorr(const TVector2 &aVector) {met_uncorr = aVector;}
void setMETFilterDecision(unsigned int aMETFilterDecision) {metFilterDecision = aMETFilterDecision;}
void setFilters(const std::vector<Int_t> & aFilters) { filters = aFilters;}
////////////////////////
///Reset class data members
void clear();
void clearSelectionWord() {selectionWord.ResetAllBits();}
///Data member getters.
unsigned int getRunId() const {return runId;}
unsigned long int getEventId() const {return eventId;}
unsigned long int getLSId() const {return lsId;}
float getNPU() const {return nPU;}
unsigned int getNPV() const {return nPV;}
float getRho() const {return rho;}
float getMCatNLOWeight() const {return aMCatNLOweight;}
float getPtReWeight() const {return ptReWeight;}
float getPtReWeightR1() const {return ptReWeightR1;}
float getPtReWeightSUSY() const {return ptReWeightSUSY;}
float getMCWeight() const {return mcWeight;}
float getLHE_Ht() const {return lheHt;}
int getLHEnOutPartons() const {return lheNOutPartons;}
sampleTypeEnum getSampleType() const {return sampleType;}
int getDecayModeMinus() const {return decayModeMinus;}
int getDecayModePlus() const {return decayModePlus;}
int getDecayModeBoson() const {return decayModeBoson;}
TLorentzVector getGenBosonP4(bool visP4=false) const { return visP4 ? bosVisP4 : bosP4 ; }
TVector2 getMET() const {return met;}
TVector2 getMET_uncorr() const {return met_uncorr;}
const TVector3 & getGenPV() const {return genPV;}
const TVector3 & getAODPV() const {return AODPV;}
const TVector3 & getRefittedPV() const {return refittedPV;}
bool getIsRefit() const {return isRefit;};
int getNTracksInRefit() const {return nTracksInRefit;}
bool checkSelectionBit(SelectionBitsEnum iBit) const {return selectionWord.TestBitNumber((unsigned int)iBit);}
unsigned int getMETFilterDecision() const { return metFilterDecision;}
int getFilter(FilterEnum index) const {return (unsigned int)index<filters.size()? filters[(unsigned int)index]: -999;}
private:
///Event run, run and LS number
unsigned int runId;
unsigned long int eventId, lsId;
//Generator event weight
float mcWeight;
///Weight used to modify the pt shape.
float ptReWeight, ptReWeightR1, ptReWeightSUSY;
///Ht value from LHE record.
float lheHt;
///Number of outgoing partons from LHE record
int lheNOutPartons;
///MCatNLO weight
float aMCatNLOweight;
///Number of true PU vertices from MC
float nPU;
//Number of reocnstructed PV
unsigned int nPV;
///PU energy density with FastJet, rho
float rho;
///Type of the physics process or DATA
sampleTypeEnum sampleType;
///Boson (H, Z, W) decay mode
int decayModeBoson;
///Boson (H, Z, W) p4 and visible p4
TLorentzVector bosP4, bosVisP4;
///Tau decay modes
int decayModeMinus, decayModePlus;
///Primary Vertices recontructed with different methods
//Generated PV position
TVector3 genPV;
//PV stored in miniAOD
TVector3 AODPV;
///PV recontructed from PF candidates, refitted
TVector3 refittedPV;
///Flag marking if refit was successfull
bool isRefit;
///Number of tracks used in the refit
int nTracksInRefit;
///Bit word coding event selection result
TBits selectionWord;
//MET vector, uncorrected
TVector2 met_uncorr;
//MET vector, recoil corr
TVector2 met;
//MET filter decision
unsigned int metFilterDecision;
std::vector<Int_t> filters;
};
class HTTParticle{
public:
HTTParticle(){ clear();}
~HTTParticle(){}
void clear();
///Data member setters.
void setP4(const TLorentzVector &aP4) { p4 = aP4;}
void setChargedP4(const TLorentzVector &aP4) { chargedP4 = aP4;}
void setNeutralP4(const TLorentzVector &aP4) { neutralP4 = aP4;}
void setPCA(const TVector3 &aV3) {pca = aV3;}
void setPCARefitPV(const TVector3 &aV3) {pcaRefitPV = aV3;}
void setPCAGenPV(const TVector3 &aV3) {pcaGenPV = aV3;}
void setProperties(const std::vector<Double_t> & aProperties) { properties = aProperties;}
///Data member getters.
const TLorentzVector & getP4(HTTAnalysis::sysEffects type=HTTAnalysis::NOMINAL) const {return getSystScaleP4(type);}
const TLorentzVector & getChargedP4() const {return chargedP4;}
const TLorentzVector getNeutralP4() const {return neutralP4;}
const TVector3 & getPCA() const {return pca;}
const TVector3 & getPCARefitPV() const {return pcaRefitPV;}
const TVector3 & getPCAGenPV() const {return pcaGenPV;}
int getPDGid() const {return getProperty(PropertyEnum::pdgId);}
int getCharge() const {return getProperty(PropertyEnum::charge);}
Double_t getProperty(PropertyEnum index) const {return (unsigned int)index<properties.size()? properties[(unsigned int)index]: -999;}
bool hasTriggerMatch(TriggerEnum index) const {return (unsigned int)getProperty(PropertyEnum::isGoodTriggerType)& (1<<(unsigned int)index) &&
(unsigned int)getProperty(PropertyEnum::FilterFired)& (1<<(unsigned int)index);}
private:
///Return four-momentum modified according DATA/MC energy scale factors.
const TLorentzVector & getNominalShiftedP4() const;
///Return four-momentum modified according to given systematic effect.
///The method recognises particle type, e.g. muons are not affected by
///TES variations etc.
const TLorentzVector & getSystScaleP4(HTTAnalysis::sysEffects type=HTTAnalysis::NOMINAL) const;
///Return four-momentum shifted with scale.
///Shift modifies three-momentum transverse part only, leaving mass constant.
const TLorentzVector & getShiftedP4(float scale, bool preserveMass=true) const;
///Nominal (as recontructed) four-momentum
TLorentzVector p4;
///Scaled four-momentum cache;
mutable TLorentzVector p4Cache;
mutable HTTAnalysis::sysEffects lastSystEffect;
///Charged and neutral components four-momentum
TLorentzVector chargedP4, neutralP4;
///Vectors from primary vertex to point of closest approach (PCA)
///calculated with respect to AOD vertex, refitted and generated vertex.
TVector3 pca, pcaRefitPV, pcaGenPV;
///Vector of various particle properties.
///Index generated automatically during conversion from
///LLR ntuple format
std::vector<Double_t> properties;
//Corrections of nominal tau-scale: https://twiki.cern.ch/twiki/bin/view/CMS/TauIDRecommendation13TeV#Tau_energy_scale
/*dummy
static constexpr float TES_1p=0.0;
static constexpr float TES_1ppi0=0.0;
static constexpr float TES_3p=0.0;
*/
/*early 2016 as SM HTT*/
static constexpr float TES_1p=-0.018;
static constexpr float TES_1ppi0=0.010;
static constexpr float TES_3p=0.004;
/**/
/*final 2016
static constexpr float TES_1p=-0.005;
static constexpr float TES_1ppi0=0.011;
static constexpr float TES_3p=0.006;
*/
static constexpr float TES = 0.012;
static constexpr float EES = 0.03;
static constexpr float MES = 0.03;
};
///////////////////////////////////////////////////
///////////////////////////////////////////////////
class HTTPair{
public:
HTTPair(){ clear();}
~HTTPair(){}
void clear();
///Data member setters.
void setP4(const TLorentzVector &aP4, HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) {p4Vector[(unsigned int)type] = aP4;}
void setLeg1P4(const TLorentzVector &aP4, HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) {leg1p4Vector[(unsigned int)type] = aP4;}
void setLeg2P4(const TLorentzVector &aP4, HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) {leg2p4Vector[(unsigned int)type] = aP4;}
void setMET(const TVector2 &aVector) {met = aVector;}
void setSVMET(const TVector2 &aVector, HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) {svMetVector[(unsigned int)type] = aVector;}
void setMTLeg1(const float & aMT) {mtLeg1 = aMT;}
void setMTLeg2(const float & aMT) {mtLeg2 = aMT;}
void setLeg1(const HTTParticle &aParticle, int idx=-1){leg1 = aParticle; indexLeg1=idx;}
void setLeg2(const HTTParticle &aParticle, int idx=-1){leg2 = aParticle; indexLeg2=idx;}
void setMETMatrix(float m00, float m01, float m10, float m11) {metMatrix.push_back(m00); metMatrix.push_back(m01); metMatrix.push_back(m10); metMatrix.push_back(m11);}
///Data member getters.
const TLorentzVector & getP4(HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) const;
const TLorentzVector & getLeg1P4(HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) const;
const TLorentzVector & getLeg2P4(HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) const;
const TVector2 & getMET(HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) const {return getSystScaleMET(type);}
const TVector2 & getSVMET(HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) const {return svMetVector[(unsigned int)type];}
float getMTLeg1(HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) const {return getSystScaleMT(leg1, type);}
float getMTLeg2(HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) const {return getSystScaleMT(leg2, type);}
const HTTParticle & getLeg1() const {return leg1;}
const HTTParticle & getLeg2() const {return leg2;}
int getIndexLeg1() {return indexLeg1;}
int getIndexLeg2() {return indexLeg2;}
const HTTParticle & getMuon() const {return abs(leg1.getPDGid())==13 ? leg1 : leg2; }
const HTTParticle & getTau() const {return abs(leg1.getPDGid())==15 ? leg1 : leg2; }
float getMTMuon(HTTAnalysis::sysEffects type = HTTAnalysis::NOMINAL) const {return abs(leg1.getPDGid())==13 ? getMTLeg1(type) : getMTLeg2(type); }
std::vector<float> getMETMatrix() const {return metMatrix;}
private:
///Return MET modified according to given systematic effect.
///The MET is corrected for accorging leptons corrections.
///The recoil correctino is not updated.
const TVector2 & getSystScaleMET(HTTAnalysis::sysEffects type=HTTAnalysis::NOMINAL) const;
///Return transverse mass caluculated according to the scale shifts.
float getSystScaleMT(const HTTParticle &aPerticle,
HTTAnalysis::sysEffects type=HTTAnalysis::NOMINAL) const;
///Nominal met as calculated from PF.
///Includes recoil corrections.
TVector2 met;
///Scaled four-momentum cache;
mutable TVector2 metCache;
mutable HTTAnalysis::sysEffects lastSystEffect;
mutable float mtCache;
///Vectors holding p4 and MET for
///for various scale variances.
std::vector<TLorentzVector> p4Vector;
std::vector<TLorentzVector> leg1p4Vector;
std::vector<TLorentzVector> leg2p4Vector;
std::vector<TVector2> svMetVector;
//MVAMET covariance matrix in order 00,01,10,11
std::vector<float> metMatrix;
///MT calculated for (leg1,MET) and (leg2,MET)
float mtLeg1, mtLeg2;
///Pair legs
HTTParticle leg1, leg2;
int indexLeg1, indexLeg2;
};
#endif