-
Notifications
You must be signed in to change notification settings - Fork 6
/
bbggLTMaker.C
353 lines (301 loc) · 13.5 KB
/
bbggLTMaker.C
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
#define bbggLTMaker_cxx
#include "bbggLTMaker.h"
const bool DEBUG = 0;
// Cuts for 2016 categorization (_which==0):
const Float_t cutJetBtag = 0.55;
const Float_t boundary_MX[3] = {0,350,35000};
const Float_t boundary_MVA_tagger2016_LM[3] = {0.600, 0.985, 1.0};
const Float_t boundary_MVA_tagger2016_HM[3] = {0.600, 0.970, 1.0};
// Cuts for 2017 tagger, using 2016 categorization (_which==1):
const Float_t boundary_MVA_tagger2017_LM[3] = {0.115, 0.597, 1.0};
const Float_t boundary_MVA_tagger2017_HM[3] = {0.226, 0.6195, 1.0};
// Cuts for 2017 tagger, using 2017 optimized categorization (_which==2):
const Float_t boundary_MVA_tagger2017[4] = {0.271, 0.543, 0.740, 1.05};
const Float_t boundary_MX_2017[5] = {250, 341.4, 426.1, 544, 35000};
const Float_t MjjCuts_Low[] = {88.0, 81.0, 75.0,
95.0, 95.0, 102.0,
99.0, 91.0, 95.0,
108.0, 108.0, 103.0};
const Float_t MjjCuts_High[] = {151.0, 155.0, 155.0,
155.0, 166.0, 155.0,
148.0, 160.0, 167.0,
159.0, 155.0, 151.0};
/*
// Fixed cuts are to test the 1D fit option in bbgg2Dfitter
const Float_t MjjCuts_Low[] = {100.0, 100.0, 100.0,
100.0, 100.0, 100.0,
100.0, 100.0, 100.0,
100.0, 100.0, 100.0};
const Float_t MjjCuts_High[] = {150.0, 150.0, 150.0,
150.0, 150.0, 150.0,
150.0, 150.0, 150.0,
150.0, 150.0, 150.0};
*/
void bbggLTMaker::Begin(TTree * /*tree*/)
{
TString option = GetOption();
cout<<"Options are: \n \t "<<option.Data()<<endl;
TObjArray *args = (TObjArray*)option.Tokenize(" ");
_normalization = std::stod((string)((TObjString*)args->At(0))->GetString());
_outFileName = (string)((TObjString*)args->At(1))->GetString();
_genDiPhotonFilter = (Bool_t) std::stoi( (string)((TObjString*)args->At(2))->GetString() );
_whichCategorization = (Int_t) std::stoi( (string)((TObjString*)args->At(3))->GetString() );
std::cout<<"Input paremeters:\n"
<<"_normalization: "<<_normalization<<"\n"
<<"_outFileName: "<< _outFileName<<"\n"
<<"_genDiPhotonFilter: "<< _genDiPhotonFilter<<"\n"
<<std::endl;
// Could make those come from external options as well:
_phoVariation = 0;
_trigVariation = 0;
_outFile = new TFile(_outFileName, "RECREATE");
_outTree = new TTree("LT", "A tree for studying new particles");
_outTree->Branch("run", &o_run, "o_run/i");
_outTree->Branch("evt", &o_evt, "o_evt/l");
_outTree->Branch("evWeight", &o_weight, "o_weight/D");
_outTree->Branch("mgg", &o_mgg, "o_mgg/D");
_outTree->Branch("mjj", &o_mjj, "o_mjj/D");
_outTree->Branch("MX", &o_MX, "o_MX/D");
_outTree->Branch("mbbgg", &o_bbggMass, "o_bbggMass/D");
_outTree->Branch("catID", &o_catID, "o_catID/I");
TString phoSFID_file = TString(std::getenv("CMSSW_BASE")) + TString("/src/HiggsAnalysis/bbggLimits2018/Weights/MVAID/egammaEffi.txt_EGM2D.root");
if (DEBUG) cout << "phoSFsID file: " << phoSFID_file << endl;
TString phoSFeveto_file = TString(std::getenv("CMSSW_BASE")) + TString("/src/HiggsAnalysis/bbggLimits2018/Weights/MVAID/ScalingFactors_80X_Summer16.root");
if (DEBUG) cout << "phoSFsEV file: " << phoSFeveto_file << endl;
bbggLTMaker::SetupPhotonSF( phoSFID_file, phoSFeveto_file);
TString trig_file = TString(std::getenv("CMSSW_BASE")) + TString("/src/HiggsAnalysis/bbggLimits2018/Weights/TriggerSF/TriggerSFs.root");
if (DEBUG) cout << "TriggSF file: " << trig_file << endl;
bbggLTMaker::SetupTriggerSF(trig_file);
}
void bbggLTMaker::SlaveBegin(TTree * /*tree*/)
{
TString option = GetOption();
}
Bool_t bbggLTMaker::Process(Long64_t entry)
{
GetEntry(entry);
//std::cout<<"Processing event "<<event<<" in run "<<run<<std::endl;
if (!isSignal) return kTRUE; // This means signal region.
if( _genDiPhotonFilter && nPromptInDiPhoton < 2 ) return kTRUE;
o_run = run;
o_evt = event;
o_weight = 1;
o_mgg = (*leadingPhoton + *subleadingPhoton).M();
o_mjj = dijetCandidate->M();
o_bbggMass = (*dijetCandidate + *leadingPhoton + *subleadingPhoton).M();
o_MX = o_bbggMass - o_mjj - o_mgg + 250.;
//if (fabs(o_MX-MX)/o_MX > 0.0001) std::cout<<"MXes are not equal!! o_mx="<<o_MX<<" treMX="<<MX<<std::endl;
o_catID = -1;
//std::cout<<"lead photon pt = "<<(*leadingPhoton).Pt()<<std::endl;
//std::cout<<"Mbbgg = "<<o_bbggMass<<" MX = "<<o_MX<<std::endl;
if (_whichCategorization==0){
if (o_MX > boundary_MX[0] && o_MX <= boundary_MX[1]){
if( leadingJet_bDis < cutJetBtag || subleadingJet_bDis < cutJetBtag)
return kTRUE; // Some clean-up based on b-tag scores
if (HHTagger_LM > boundary_MVA_tagger2016_LM[0] && HHTagger_LM <= boundary_MVA_tagger2016_LM[1])
o_catID = 3;
else if (HHTagger_LM > boundary_MVA_tagger2016_LM[1] && HHTagger_LM <= boundary_MVA_tagger2016_LM[2])
o_catID = 2;
else {
//if (DEBUG) std::cout<<"MVA is out of bounds! MVA="<<HHTagger_LM<<std::endl;
return kTRUE;
}
}
else if (o_MX > boundary_MX[1] && o_MX <= boundary_MX[2]){
if (HHTagger_HM > boundary_MVA_tagger2016_HM[0] && HHTagger_HM <= boundary_MVA_tagger2016_HM[1])
o_catID = 1;
else if (HHTagger_HM > boundary_MVA_tagger2016_HM[1] && HHTagger_HM <= boundary_MVA_tagger2016_HM[2])
o_catID = 0;
else {
//if (DEBUG) std::cout<<"MVA is out of bounds! MVA="<<HHTagger_HM<<std::endl;
return kTRUE;
}
}
else {
std::cout<<"MX is out of bounds! MX="<<o_MX<<std::endl;
return kTRUE;
}
}
else if (_whichCategorization==1){
if (o_MX > boundary_MX[0] && o_MX <= boundary_MX[1]){
if( leadingJet_bDis < cutJetBtag || subleadingJet_bDis < cutJetBtag)
return kTRUE; // Some clean-up based on b-tag scores
if (HHTagger2017_transform > boundary_MVA_tagger2017_LM[0] && HHTagger2017_transform <= boundary_MVA_tagger2017_LM[1])
o_catID = 3;
else if (HHTagger2017_transform > boundary_MVA_tagger2017_LM[1] && HHTagger2017_transform <= boundary_MVA_tagger2017_LM[2])
o_catID = 2;
else {
//if (DEBUG) std::cout<<"MVA is out of bounds! MVA="<<HHTagger_LM<<std::endl;
return kTRUE;
}
}
else if (o_MX > boundary_MX[1] && o_MX <= boundary_MX[2]){
if (HHTagger2017_transform > boundary_MVA_tagger2017_HM[0] && HHTagger2017_transform <= boundary_MVA_tagger2017_HM[1])
o_catID = 1;
else if (HHTagger2017_transform > boundary_MVA_tagger2017_HM[1] && HHTagger2017_transform <= boundary_MVA_tagger2017_HM[2])
o_catID = 0;
else {
//if (DEBUG) std::cout<<"MVA is out of bounds! MVA="<<HHTagger_HM<<std::endl;
return kTRUE;
}
}
else {
std::cout<<"MX is out of bounds! MX="<<o_MX<<std::endl;
return kTRUE;
}
}
else if (_whichCategorization==2 || _whichCategorization==3){
if (o_MX > boundary_MX_2017[0] && o_MX <= boundary_MX_2017[1]){
if (HHTagger2017_transform > boundary_MVA_tagger2017[0] && HHTagger2017_transform <= boundary_MVA_tagger2017[1]){
o_catID = 2;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else if (HHTagger2017_transform > boundary_MVA_tagger2017[1] && HHTagger2017_transform <= boundary_MVA_tagger2017[2]){
o_catID = 1;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else if (HHTagger2017_transform > boundary_MVA_tagger2017[2] && HHTagger2017_transform <= boundary_MVA_tagger2017[3]){
o_catID = 0;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else {
//if (DEBUG) std::cout<<"MVA is out of bounds! MVA="<<HHTagger_LM<<std::endl;
return kTRUE;
}
}
else if (o_MX > boundary_MX_2017[1] && o_MX <= boundary_MX_2017[2]){
if (HHTagger2017_transform > boundary_MVA_tagger2017[0] && HHTagger2017_transform <= boundary_MVA_tagger2017[1]){
o_catID = 5;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else if (HHTagger2017_transform > boundary_MVA_tagger2017[1] && HHTagger2017_transform <= boundary_MVA_tagger2017[2]){
o_catID = 4;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else if (HHTagger2017_transform > boundary_MVA_tagger2017[2] && HHTagger2017_transform <= boundary_MVA_tagger2017[3]){
o_catID = 3;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else {
return kTRUE;
}
}
else if (o_MX > boundary_MX_2017[2] && o_MX <= boundary_MX_2017[3]){
if (HHTagger2017_transform > boundary_MVA_tagger2017[0] && HHTagger2017_transform <= boundary_MVA_tagger2017[1]){
o_catID = 8;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else if (HHTagger2017_transform > boundary_MVA_tagger2017[1] && HHTagger2017_transform <= boundary_MVA_tagger2017[2]){
o_catID = 7;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else if (HHTagger2017_transform > boundary_MVA_tagger2017[2] && HHTagger2017_transform <= boundary_MVA_tagger2017[3]){
o_catID = 6;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else {
return kTRUE;
}
}
else if (o_MX > boundary_MX_2017[3] && o_MX <= boundary_MX_2017[4]){
if (HHTagger2017_transform > boundary_MVA_tagger2017[0] && HHTagger2017_transform <= boundary_MVA_tagger2017[1]){
o_catID = 11;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else if (HHTagger2017_transform > boundary_MVA_tagger2017[1] && HHTagger2017_transform <= boundary_MVA_tagger2017[2]){
o_catID = 10;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else if (HHTagger2017_transform > boundary_MVA_tagger2017[2] && HHTagger2017_transform <= boundary_MVA_tagger2017[3]){
o_catID = 9;
if (_whichCategorization==3 && (o_mjj < MjjCuts_Low[o_catID] || o_mjj > MjjCuts_High[o_catID]) )
return kTRUE;
}
else {
return kTRUE;
}
}
else {
std::cout<<"MX is out of bounds! MX="<<o_MX<<std::endl;
return kTRUE;
}
}
else {
std::cout<<"This categorization is not supported: "<<_whichCategorization<<std::endl;
return kTRUE;
}
const Double_t preweight = genTotalWeight*_normalization;
if( preweight == 1) o_weight = 1; // When preweight == 1 it's the data, no SF needed.
else {
const Double_t pho1_sf = bbggLTMaker::PhotonSF(*leadingPhoton, _phoVariation);
const Double_t pho2_sf = bbggLTMaker::PhotonSF(*subleadingPhoton, _phoVariation);
const Double_t trig_sf = bbggLTMaker::TriggerSF(*leadingPhoton, leadingPhotonR9full5x5, *subleadingPhoton, subleadingPhotonR9full5x5, _trigVariation);
if(DEBUG)
cout << "Trigger sf: " << trig_sf << " lpt " << leadingPhoton->Pt()<< " spt " << subleadingPhoton->Pt()
<< " leta "<< leadingPhoton->Eta() << " seta "<< subleadingPhoton->Eta()
<< " lr9 "<< leadingPhotonR9full5x5 << " sr9 "<< subleadingPhotonR9full5x5 << std::endl;
const Double_t bDiffWeight = 0.96; // Use an average SF for b-tagging
o_weight = preweight*bDiffWeight*pho1_sf*pho2_sf*trig_sf;
}
// This is temporary, to check effect on fake data
//if (_normalization == 1) o_weight = 1;
_outTree->Fill();
return kTRUE;
}
void bbggLTMaker::SlaveTerminate()
{
}
void bbggLTMaker::Terminate()
{
_outFile->Write();
_outFile->Close();
}
void bbggLTMaker::SetupPhotonSF(TString idfile, TString evfile)
{
photonidFile = new TFile(idfile, "READ");
photonIDhist = (TH2F*) photonidFile->Get("EGamma_SF2D;1");
csevFile = new TFile(evfile, "READ");
csevhist = (TH2F*) csevFile->Get("Scaling_Factors_CSEV_R9 Inclusive");
}
float bbggLTMaker::PhotonSF(bbggLTMaker::LorentzVector pho, int phovar)
{
float sf_id = -99, sf_ev = -99, sf_id_err = -99, sf_ev_err = -99;
sf_id_err = photonIDhist->GetBinError( photonIDhist->FindBin(pho.eta(), pho.pt()) );
sf_id = photonIDhist->GetBinContent( photonIDhist->FindBin(pho.eta(), pho.pt()) ) + phovar*sf_id_err;
sf_ev_err = csevhist->GetBinContent( csevhist->FindBin(pho.eta(), pho.pt()) );
if(sf_ev_err==1) sf_ev_err=0;
sf_ev = csevhist->GetBinContent( csevhist->FindBin(fabs(pho.eta()), pho.pt()) ) + phovar*sf_ev_err;
float totSF = sf_id*sf_ev;
if (totSF < 1E-1) return 1;
else return totSF;
}
void bbggLTMaker::SetupTriggerSF(TString sfFile)
{
triggerFile = new TFile(sfFile, "READ");
ltriggerHist = (TH3F*) triggerFile->Get("leadingPhotonTSF");
striggerHist = (TH3F*) triggerFile->Get("subleadingPhotonTSF");
}
float bbggLTMaker::TriggerSF(LorentzVector lpho, float lr9, LorentzVector spho, float sr9, int var)
{
int leadingBin = ltriggerHist->FindBin(lr9, fabs(lpho.Eta()), lpho.Pt());
int subleadingBin = striggerHist->FindBin(sr9, fabs(spho.Eta()), spho.Pt());
if(DEBUG) cout << "[bbggLTMaker::TriggerSF] leading Bin: " << leadingBin << " subleadingBin " << subleadingBin << std::endl;
float leadingSF = ltriggerHist->GetBinContent(leadingBin);
float sleadingSF =striggerHist->GetBinContent(subleadingBin);
if(DEBUG) cout << "[bbggLTMaker::TriggerSF] leading SF: " << leadingSF << " subleadingSF " << sleadingSF << std::endl;
float leadingErr = ltriggerHist->GetBinError(leadingBin);
float subleadingErr = striggerHist->GetBinError(subleadingBin);
if(DEBUG) cout << "[bbggLTMaker::TriggerSF] leading SFerr: " << leadingErr << " subleadingSFerr " << subleadingErr << std::endl;
return (leadingSF + var*leadingErr)*(sleadingSF + var*subleadingErr);
}