-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScanChain.h
282 lines (209 loc) · 9.37 KB
/
ScanChain.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
// Usage:
// > root -b doAll.C
//
// 2016 MET study looper. Written by Bobak Hashemi May 13 2016
//
// C++
#include <iostream>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <fstream>
// ROOT
#include "TBenchmark.h"
#include "TChain.h"
#include "TDirectory.h"
#include "TFile.h"
#include "TROOT.h"
#include "TTreeCache.h"
#include "TEfficiency.h"
#include "TH1.h"
#include "TH2.h"
#include "TH3.h"
// Analysis Specific
#include "WWW.cc"
// CORE
//You can not include headers!!! This is not compiled code.
#include "External/dorky.cc"
#include "External/goodrun.cc"
#include "External/MT2Utility.cc"
#include "External/MT2.cc"
// Configuration parsing
#include "ConfigParser.C"
#include "ConfigHelper.C"
using namespace std;
//using namespace zmet;
using namespace duplicate_removal;
typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > LorentzVector;
//Global Vars
ConfigParser *conf;
int nDuplicates=0;
int num_events_veto_ttbar=0;
int num_events_veto_ttgamma=0;
bool MCTriggerEmulation = true;
vector<pair <TH1D*, TString> > g_reweight_pairs;
TDirectory *rootdir = gDirectory->GetDirectory("Rint:");
TH1D *g_pileup_hist, *g_l1prescale_hist22, *g_l1prescale_hist30, *g_l1prescale_hist36;
//Btag and ISR Scale Factor overall normalization
TH2D *g_btagsf_norm, *g_btagsf_light_norm_up, *g_btagsf_heavy_norm_up;
TH2D *g_isr_norm, *g_isr_norm_up;
TFile *g_SUSYsf_norm_file;
TEfficiency *g_pt_eff_barrel, *g_pt_eff_endcap;
TFile *g_weight_hist_file, *g_pileup_hist_file, *g_l1prescale_file;
TString g_sample_name;
TFile* currentFile = 0;
double g_scale_factor=1; //Holds scale factors for sample.
TH1I *numEvents; //Holds the number of events in the whole script and the number that pass various cuts
// ----------------
// DEBUG MODE
// ----------------
set<tuple<long,long,long>> inspection_set_erl = {make_tuple(123855,1,620), make_tuple(137607,1,689)};
//set<long> inspection_set = {99795815,998615983,998751102,999957050};
set<tuple<long,long,long>> inspection_copy = inspection_set_erl;
bool printStats = false;
bool printFail = false;
//=======================================================
// Global variables used for uncertainty fluctuations
//=======================================================
double g_dphi_metj1;
double g_dphi_metj2;
int g_njets;
double g_mbb;
double g_mjj_mindphi;
int g_nBJetMedium;
int g_nBJetLoose;
double g_met;
double g_met_phi;
double g_mt2;
double g_mt2b;
double g_ht;
vector<float> g_jets_csv;
vector<LorentzVector> g_jets_p4;
vector<LorentzVector> g_jets_medb_p4;
const double Z_MASS = 91.1876;
const double W_MASS = 80.385;
const double BJET_CSV_TIGHT = 0.9535;
const double BJET_CSV_MED = 0.8484;
const double BJET_CSV_LOOSE = 0.5426;
double MAX_DR_JET_LEP_OVERLAP, JET_PT_MIN, JET_ETA_MAX, BJET_PT_MIN, BJET_ETA_MAX;
double W_JET_WINDOW_LOW, W_JET_WINDOW_HIGH, Z_VETO_WINDOW_LOW, Z_VETO_WINDOW_HIGH;
/* returns two most B-like jet indicies */
pair<int, int> getMostBlike();
/*Finds the pair of B tagged jets (csv medium) with dijet mass closest to the mass of the higgs*/
pair<int,int> getClosestBPairToHiggsMass();
/*Builds MT2b from two highest CSV jets*/
double getMT2B();
/*Builds Mbb from two highest CSV jets*/
double getMbb();
/*Builds MT2 (jet lepton sum) from two most W-like jets*/
double getMT2_JL();
/*This function gets the MT2 built out of the two Bjets in an event, no guarentee
is made about selecting the highest csv jets*/
double getMT2ForBjets(bool select_highest_csv=false);
/*Builds MT2 for the two leading Bjets unless select_closest_higgs_mass is set, in which case it
builds it out of the two bjets with dijet mass nearest the mass of the higgs.*/
double getMT2HiggsZ(bool select_highest_closest_higgs_mass=false);
/*Returns boson Pt, determines whether sample is gjets or zjets first*/
double bosonPt();
/* Builds the MT from the lepton at index id and the MET vector (assumes massless particles)*/
double getMTLepMET(short id=0);
/* Builds the delta R (sqrt(dPhi^2 + dEta^2)) between the lepton at index id and the leading photon*/
double getdRGammaLep(short id=0);
/*Searches the vector of lorentz vectors for the pair with mass nearest (furthest) from the target mass if 'close' is true (false)*/
pair<int, int> getPairWithMass(const vector<LorentzVector> &vecs, double target_mass, bool close);
/*These get the 4 vectors for objects with mass closest or furthest from the mass of the W or Z using getPairWithMass()*/
pair<int,int> getMostZlikePair(const vector<LorentzVector> &vecs);
pair<int,int> getLeastZlikePair(const vector<LorentzVector> &vecs);
pair<int,int> getMostWlikePair(const vector<LorentzVector> &vecs);
/* Goes pairwise through jet collection and finds the pair of jets with the minium delta eta. */
pair<int,int> getClosestJetsInEta();
/*Loops through pairs of entries in the lep_pdgId vector and counts how many have opposite value*/
int getNumOSSFPairs();
/*Returns a string which gives the exact flavor composition of the leptons in the event*/
TString getLepFlavorString();
/*Returns the DeltaR between objects p1 and p2.*/
double DeltaR(const LorentzVector p1, const LorentzVector p2);
/* checks the gen record for a lepton with the index specified */
bool isCleanLepFromW(int index);
//=============================
// Triggers
//=============================
/*Checks that the event passes an "emulated photon trigger"*/
bool passPhotonEmulatedTrigger();
/*Ensures the event is within the efficiency plateu of the highest pt trigger it passed*/
bool passPhotonTriggers();
/*MC passes immediately, ensures data events were gathered from di-muon triggers*/
bool passMuonTriggers();
/*MC passes immediately, ensures data events were gathered from di-electron triggers*/
bool passElectronTriggers();
/*MC passes immediately, ensures data events were gathered from EMu triggers*/
bool passEMuTriggers();
/*MC passes immediately, ensures data events were gathered from SingleMu trigger*/
bool passSingleMuTriggers();
/*Helper method which chooses which above method to call. Calls EMu if the dil_flavor is emu, otherwise uses
the hyp_type to determine which to call. Events fail if they are hyp_type 2 and not tagged for emu*/
bool passLeptonHLTs();
//=============================
// Has Good Event Functions
//=============================
/*Lepton quality and Z mass cuts*/
bool hasGoodZ();
/*Photon quality cuts*/
bool hasGoodPhoton();
/*Method for testing whether the event has a good gamma mu pair trigger requirements are on the photon.
It just checks muon quality stuff and then calls hasGoodPhoton()*/
bool hasGoodGammaMu();
/*Just a helper method that chooses which hasGood method to call based on the config event_type*/
bool hasGoodEvent();
//=============================
// Event Weight Assignment
//=============================
/*Goes through the chain of weight_from config options down to a config which does not have weight_from and
then adds a pair (config_name, hist_file) to the vector g_reweight_pairs.
For now this is depricated: NEEDS TO BE UPDATED WITH NEW CODE FIXES*/
void readyReweightHists();
/* Adds the vpt reweighting histogram to the g_reweight_pairs vector */
void readyVPTReweight(TString save_path);
/* Returns the trigger efficiency from g_pt_eff */
double getEff(const double &pt, const double &eta);
/*Loads the reweight hists from g_reweight_pairs and multiplies returns the weight associated with the proper
bin in the histogram*/
double getReweight();
/*This method stores fixes to the evt_scale1fb in the event of file corruptions.
It's basically just a lookup table*/
double scale1fbFix();
/*Main function for determining the weights for each event*/
double getWeight();
/*Returns the weight associated with the photon prescales*/
double getPrescaleWeight();
//=============================
// Cuts
//=============================
/*Holds the cuts for all the signal regions, basically all the cuts that are turned on with a config option*/
bool passSignalRegionCuts();
/*Checks for a gen Neutrino (Real MET) and a gen Z (Real Z), only should be run when running
over samples tagged as "rares". This is only neccesary for the full prediction.*/
bool passRareCuts();
/*Front end method to "Dorky" duplicate removal*/
bool isDuplicate();
/*Checks for MET filters*/
bool passMETFilters();
/*Holds baseline cuts*/
bool passBaseCut();
/*Method which holds all the file specific selections, for instance cutting out the
events with genht > 100 in the DY inclusive samples*/
bool passFileSelections();
//=============================
// Setup
//=============================
/*Takes in a p4 for a jet and determines whether that jet is less than MAX_DR_JET_LEP_OVERLAP for all leptons*/
bool isOverlapJet(const LorentzVector &jet_p4);
/*This function writes only elements of the given vector to g_jets_p4 variable, it can be passed the up and down variations as well.*/
void writeCleanedJets(const vector<LorentzVector> &vecs);
/*This function writes only elements of the given vector to g_jets_medb_p4 variable, it can be passed the up and down variations as well. Distingushed from the regular jet function because we need to keep track of the CSV values as well.*/
void writeCleanedBJets(const vector<LorentzVector> &vecs, const vector<float> &csvs);
/*Sets up global variables for the event which are the quantities that might be fluctuated in the process of computing uncertainty limits*/
void setupGlobals();
/*Obvi the event looper*/
int ScanChain( TChain* chain, ConfigParser *configuration, bool fast = true, int nEvents = -1);