susy_cfa  b611ccad937ea179f86a1f5663960264616c0a20
phys_objects.cpp
Go to the documentation of this file.
1 // phys_objects: Class with the standard physics objects that inherits from the cfa class.
2 // Reduced tree makers should inherit from this class
3 
4 #include "phys_objects.hpp"
5 
6 #include <cfloat>
7 #include <cmath>
8 #include <cstdio>
9 #include <cstdlib>
10 
11 #include <iomanip>
12 #include <fstream>
13 #include <iostream>
14 #include <limits>
15 #include <typeinfo>
16 #include <stdexcept>
17 #include <set>
18 
19 #include "TMath.h"
20 #include "TVector3.h"
21 #include "TLorentzVector.h"
22 
24 #include "JetCorrector.hpp"
25 
26 #include "cfa_8.hpp"
27 #include "cfa_13.hpp"
28 #include "pdtlund.hpp"
29 #include "utilities.hpp"
30 
31 
32 using namespace std;
33 
34 namespace{
35  const float fltmax = numeric_limits<float>::max();
36  vector<string> jec_files;
37 }
38 
39 float phys_objects::MinJetPt = 30.0;
40 float phys_objects::MinRA2bJetPt = 30.0;
44 float phys_objects::bad_val = -999.;
45 
46 // const std::vector<std::vector<int> > VRunLumiPrompt(MakeVRunLumi("Golden"));
47 // const std::vector<std::vector<int> > VRunLumi24Aug(MakeVRunLumi("24Aug"));
48 // const std::vector<std::vector<int> > VRunLumi13Jul(MakeVRunLumi("13Jul"));
49 const std::vector<std::vector<int> > VRunLumi2015golden(MakeVRunLumi("2015golden"));
50 const std::vector<std::vector<int> > VRunLumi2015dcs(MakeVRunLumi("2015dcs"));
51 
52 
53 
54 phys_objects::phys_objects(const std::string &fileName, const bool is_8TeV):
55  cfa(fileName, is_8TeV),
56  jet_corrector_(NULL),
57  jets_corr_p4_(0),
58  set_jets_(false),
59  met_corr_(bad_val),
60  met_phi_corr_(bad_val){
61  if(GetVersion()==78) {
62  jec_files.push_back("txt/jec/phys14_v4_mc/PHYS14_V4_MC_L1FastJet_AK4PFchs.txt");
63  jec_files.push_back("txt/jec/phys14_v4_mc/PHYS14_V4_MC_L2Relative_AK4PFchs.txt");
64  jec_files.push_back("txt/jec/phys14_v4_mc/PHYS14_V4_MC_L3Absolute_AK4PFchs.txt");
65  }
66  if(GetVersion()==82) {
67  if(isData()) {
68  jec_files.push_back("txt/jec/summer15_v3/Summer15_50nsV3_DATA_L1FastJet_AK4PFchs.txt");
69  //jec_files.push_back("txt/jec/summer15_v3/Summer15_50nsV3_DATA_L1RC_AK4PFchs.txt");
70  jec_files.push_back("txt/jec/summer15_v3/Summer15_50nsV3_DATA_L2Relative_AK4PFchs.txt");
71  jec_files.push_back("txt/jec/summer15_v3/Summer15_50nsV3_DATA_L3Absolute_AK4PFchs.txt");
72  jec_files.push_back("txt/jec/summer15_v3/Summer15_50nsV3_DATA_L2L3Residual_AK4PFchs.txt");
73  } else if(SampleName().rfind("50ns") != std::string::npos){
74  jec_files.push_back("txt/jec/summer15_v3/Summer15_50nsV3_MC_L1FastJet_AK4PFchs.txt");
75  //jec_files.push_back("txt/jec/summer15_v3/Summer15_50nsV3_MC_L1RC_AK4PFchs.txt");
76  jec_files.push_back("txt/jec/summer15_v3/Summer15_50nsV3_MC_L2Relative_AK4PFchs.txt");
77  jec_files.push_back("txt/jec/summer15_v3/Summer15_50nsV3_MC_L3Absolute_AK4PFchs.txt");
78  } // For now, use the cfA JECs for 25ns MC
79  }
81 
82 }
83 
85  if(jet_corrector_){
86  delete jet_corrector_;
87  jet_corrector_ = NULL;
88  }
89 }
90 
91 void phys_objects::GetEntry(const long entry){
92  jets_corr_p4_.clear();
93  set_jets_ = false;
94  cfa::GetEntry(entry);
95 }
96 
97 
99 bool phys_objects::GetTriggerInfo(vector<TString> &trig_names, vector<bool> &trig_dec,
100  vector<float> &trig_prescale){
101  bool want_event(yes_trig.size()==0); // If yes_trig is not set up, we keep every event
102  bool duplicate(false);
103  TString trigname;
104  trig_dec.resize(trig_names.size(), false);
105  trig_prescale.resize(trig_names.size(), 1.);
106  for(int unsigned itrig=0;itrig<trigger_decision()->size();itrig++){
107  trigname = trigger_name()->at(itrig);
108  bool trigdec = trigger_decision()->at(itrig);
109  for(unsigned itn(0); itn < trig_names.size(); itn++){
110  if(trigname.Contains(trig_names[itn])){
111  trig_dec[itn] = trigdec;
112  trig_prescale[itn] = trigger_prescalevalue()->at(itrig);
113  }
114  } // Loop over trigger names
115 
116  // Checking if the event passes at least one yes_trig and none of no_trig
117  for(unsigned ind(0); ind<yes_trig.size() && !want_event && !duplicate; ind++)
118  if(trigname.Contains(yes_trig[ind])) want_event = (want_event || trigdec);
119  for(unsigned ind(0); ind<no_trig.size() && !duplicate; ind++)
120  if(trigname.Contains(no_trig[ind])) duplicate = (duplicate || trigdec);
121  } // Loop over cfA triggers
122 
123  return want_event&&!duplicate;
124 }
125 
126 bool phys_objects::PassesJSONCut(TString type){
127  string sampleName = SampleName();
128 
129  if(isData()){
130  if(type=="golden") return inJSON(VRunLumi2015golden, run(), lumiblock());
131  if(type=="dcs") return inJSON(VRunLumi2015dcs, run(), lumiblock());
132  }
133  return true;
134 }
135 
136 
137 
139 
140 
141 
145 vector<int> phys_objects::GetMuons(bool doSignal, bool mini) const {
146  vector<int> muons;
147  for(unsigned index=0; index<mus_pt()->size(); index++)
148  if(doSignal){
149  if(IsSignalMuon(index, mini)) muons.push_back(index);
150  }else{
151  if(IsVetoMuon(index, mini)) muons.push_back(index);
152  }
153  return muons;
154 }
155 
156 bool phys_objects::IsSignalMuon(unsigned imu, bool mini) const {
157  if(imu >= mus_pt()->size()) return false;
158  return IsSignalIdMuon(imu)
159  && 0.2>GetMuonIsolation(imu, mini)
160  && mus_pt()->at(imu)>MinSignalLeptonPt;
161 }
162 
163 bool phys_objects::IsVetoMuon(unsigned imu, bool mini) const{
164  if(imu >= mus_pt()->size()) return false;
165  return IsVetoIdMuon(imu)
166  && 0.2>GetMuonIsolation(imu, mini)
167  && mus_pt()->at(imu)>MinVetoLeptonPt;
168 }
169 
170 bool phys_objects::IsSignalIdMuon(unsigned imu) const {
171  if(imu >= mus_pt()->size()) return false;
172  int version = GetVersion();
173  bool dec = false;
174  if(version<80) dec = IsIdMuon(imu, kTight);
175  else dec = IsIdMuon(imu, kMedium);
176  return dec && fabs(mus_eta()->at(imu))<2.4;
177 }
178 
179 bool phys_objects::IsVetoIdMuon(unsigned imu) const {
180  if(imu >= mus_pt()->size()) return false;
181  int version = GetVersion();
182  bool dec = false;
183  if(version<80) dec = IsIdMuon(imu, kTight); //Intentionally vetoing on "tight" muons!
184  else dec = IsIdMuon(imu, kLoose);
185  return dec && fabs(mus_eta()->at(imu))<2.4;
186 }
187 
188 bool phys_objects::IsIdMuon(unsigned imu, CutLevel threshold) const{
189  if(imu>=mus_pt()->size()) return false;
190 
191  bool pf_cut, global_cut, global_or_tracker_cut, globalprompttight_cut;
192  double chisq_cut, hits_cut, stations_cut, dxy_cut, dz_cut, pixel_cut, layers_cut;
193  const double d0 = mus_tk_d0dum()->at(imu)
194  -pv_x()->at(0)*sin(mus_tk_phi()->at(imu))
195  +pv_y()->at(0)*cos(mus_tk_phi()->at(imu));
196  const double dz = mus_tk_vz()->at(imu)-pv_z()->at(0);
197 
198  //See https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideMuonId#Tight_Muon
199  switch(threshold){
200  default:
201  case kVeto:
202  case kLoose:
203  if(GetVersion()>=80) return mus_isLooseMuon()->at(imu);
204  else {
205  pf_cut = true;
206  global_or_tracker_cut = true;
207  global_cut = false;
208  globalprompttight_cut = false;
209  chisq_cut = fltmax;
210  hits_cut = -fltmax;
211  stations_cut = -fltmax;
212  dxy_cut = fltmax;
213  dz_cut = fltmax;
214  pixel_cut = -fltmax;
215  layers_cut = -fltmax;
216  }
217  break;
218 
219  case kMedium:
220  return mus_isMediumMuon()->at(imu) && fabs(d0)<=0.2 && fabs(dz)<=0.5;
221  break;
222 
223 
224  case kTight:
225  if(GetVersion()>=80) return mus_isTightMuon()->at(imu);
226  else {
227  pf_cut = true;
228  global_or_tracker_cut = false;
229  global_cut = true;
230  globalprompttight_cut = true;
231  chisq_cut = 10.0;
232  hits_cut = 0.0;
233  stations_cut = 1.0;
234  dxy_cut = 0.2;
235  dz_cut = 0.5;
236  pixel_cut = 0;
237  layers_cut = 5;
238  }
239  break;
240  }
241 
242  bool isPF = true;
243  if(Type()==typeid(cfa_8)){
244  isPF = mus_isPFMuon()->at(imu);
245  }else if(Type()==typeid(cfa_13)){
246  isPF = mus_isPF()->at(imu);
247  }
248  return (!pf_cut || isPF)
249  && (!global_or_tracker_cut || mus_isGlobalMuon()->at(imu)>0 || mus_isTrackerMuon()->at(imu)>0)
250  && (!global_cut || mus_isGlobalMuon()->at(imu)>0)
251  && (!globalprompttight_cut || mus_id_GlobalMuonPromptTight()->at(imu)>0)
252  && (true || chisq_cut)//Not available in cfa. Included in isGlobalMuonPromptTight for 2011 at least.
253  && (true || hits_cut)//Not available in cfa?
254  && mus_numberOfMatchedStations()->at(imu) > stations_cut
255  && dxy_cut > fabs(d0)
256  && dz_cut > fabs(dz)
257  && mus_tk_numvalPixelhits()->at(imu) > pixel_cut
258  && mus_tk_LayersWithMeasurement()->at(imu) > layers_cut;
259 }
260 
261 float phys_objects::GetMuonIsolation(unsigned imu, bool mini) const {
262  if(imu >= mus_pt()->size()) return -999;
263  if(!mini){
264  double sumEt = mus_pfIsolationR04_sumNeutralHadronEt()->at(imu)
265  + mus_pfIsolationR04_sumPhotonEt()->at(imu)
266  - 0.5*mus_pfIsolationR04_sumPUPt()->at(imu);
267  if(sumEt<0.0) sumEt=0.0;
268  return (mus_pfIsolationR04_sumChargedHadronPt()->at(imu) + sumEt)/mus_pt()->at(imu);
269  }else{
270  return mus_miniso()->at(imu);
271  }
272 }
273 
277 vector<int> phys_objects::GetElectrons(bool doSignal, bool mini) const {
278  vector<int> electrons;
279  for(unsigned index=0; index<els_pt()->size(); index++)
280  if(doSignal){
281  if(IsSignalElectron(index, mini)) electrons.push_back(index);
282  }else{
283  if(IsVetoElectron(index, mini)) electrons.push_back(index);
284  }
285  return electrons;
286 }
287 
288 bool phys_objects::IsSignalElectron(unsigned iel, bool mini) const {
289  if(iel >= els_pt()->size()) return false;
290  double iso_cut(0.1);
291  if (!mini) {
292  //can't get this from IsSignalIdElectron since we use kMedium Id but kVeto iso
293  bool barrel = false;
294  if(els_isEB()->at(iel) && !els_isEE()->at(iel)){
295  barrel = true;
296  }else if(els_isEE()->at(iel) && !els_isEB()->at(iel)){
297  barrel = false;
298  }else{
299  return false;
300  }
301  iso_cut = barrel ? 0.164369 : 0.212604;
302  }
303  return IsSignalIdElectron(iel, false)
304  && iso_cut>GetElectronIsolation(iel, mini)
305  && els_pt()->at(iel)>=MinSignalLeptonPt;
306 }
307 
308 bool phys_objects::IsVetoElectron(unsigned iel, bool mini) const {
309  if(iel >= els_pt()->size()) return false;
310  return IsVetoIdElectron(iel, false)
311  && 0.1>GetElectronIsolation(iel, mini)
312  && els_pt()->at(iel)>=MinVetoLeptonPt;
313 }
314 
315 bool phys_objects::IsSignalIdElectron(unsigned iel, bool do_iso) const {
316  if(iel >= els_pt()->size()) return false;
317  return IsIdElectron(iel, kMedium, do_iso);
318 }
319 
320 bool phys_objects::IsVetoIdElectron(unsigned iel, bool do_iso) const {
321  if(iel >= els_pt()->size()) return false;
322  return IsIdElectron(iel, kVeto, do_iso);
323 }
324 
325 bool phys_objects::IsIdElectron(unsigned iel, CutLevel threshold, bool do_iso) const{
326  if(iel>=els_pt()->size()) return false;
327  bool barrel;
328  if(fabs(els_scEta()->at(iel))>2.5) return false;
329  if(els_isEB()->at(iel) && !els_isEE()->at(iel)){
330  barrel = true;
331  }else if(els_isEE()->at(iel) && !els_isEB()->at(iel)){
332  barrel = false;
333  }else{
334  return false;
335  }
336 
337  double deta_cut, dphi_cut, ieta_cut, hovere_cut, d0_cut, dz_cut,
338  ooeminusoop_cut, reliso_cut, misshits_cut;
339  bool req_conv_veto;
340 
341  if(Type()==typeid(cfa_8)){
342  //See https://twiki.cern.ch/twiki/bin/viewauth/CMS/EgammaCutBasedIdentification#Barrel_Cuts_eta_supercluster_1_4
343  //N.B.: vertex fit probability cut for conversion rejection not used (not available in cfA)
344  const bool high_pt = els_pt()->at(iel)>20.0;
345  switch(threshold){
346  default:
347  case kVeto:
348  deta_cut = barrel ? 0.007 : 0.01;
349  dphi_cut = barrel ? 0.8 : 0.7;
350  ieta_cut = barrel ? 0.01 : 0.03;
351  hovere_cut = barrel ? 0.15 : fltmax;
352  d0_cut = barrel ? 0.04 : 0.04;
353  dz_cut = barrel ? 0.2 : 0.2;
354  ooeminusoop_cut = barrel ? fltmax : fltmax;
355  reliso_cut = barrel ? 0.15 : 0.15;
356  misshits_cut = barrel ? fltmax : fltmax;
357  req_conv_veto = barrel ? true : true;
358  break;
359  case kLoose:
360  deta_cut = barrel ? 0.007 : 0.009;
361  dphi_cut = barrel ? 0.15 : 0.10;
362  ieta_cut = barrel ? 0.01 : 0.03;
363  hovere_cut = barrel ? 0.12 : 0.10;
364  d0_cut = barrel ? 0.02 : 0.02;
365  dz_cut = barrel ? 0.2 : 0.2;
366  ooeminusoop_cut = barrel ? 0.05 : 0.05;
367  reliso_cut = barrel ? 0.15 : (high_pt ? 0.15 : 0.10);
368  misshits_cut = barrel ? 1 : 1;
369  req_conv_veto = barrel ? true : true;
370  break;
371  case kMedium:
372  deta_cut = barrel ? 0.004 : 0.007;
373  dphi_cut = barrel ? 0.06 : 0.03;
374  ieta_cut = barrel ? 0.01 : 0.03;
375  hovere_cut = barrel ? 0.12 : 0.1;
376  d0_cut = barrel ? 0.02 : 0.02;
377  dz_cut = barrel ? 0.1 : 0.1;
378  ooeminusoop_cut = barrel ? 0.05 : 0.05;
379  reliso_cut = barrel ? 0.15 : (high_pt ? 0.15 : 0.10);
380  misshits_cut = barrel ? 1 : 1;
381  req_conv_veto = barrel ? true : true;
382  break;
383  case kTight:
384  deta_cut = barrel ? 0.004 : 0.005;
385  dphi_cut = barrel ? 0.03 : 0.02;
386  ieta_cut = barrel ? 0.01 : 0.03;
387  hovere_cut = barrel ? 0.12 : 0.10;
388  d0_cut = barrel ? 0.02 : 0.02;
389  dz_cut = barrel ? 0.1 : 0.1;
390  ooeminusoop_cut = barrel ? 0.05 : 0.05;
391  reliso_cut = barrel ? 0.10 : (high_pt ? 0.10 : 0.07);
392  misshits_cut = barrel ? 1 : 0;
393  req_conv_veto = barrel ? true : true;
394  break;
395  }
396  }else{
397 
398  //https://twiki.cern.ch/twiki/bin/viewauth/CMS/CutBasedElectronIdentificationRun2#Working_points_for_PHYS14_sample
399  // Values from May 7th
400  if(barrel){
401  ieta_cut = chooseVal(threshold, 0.012, 0.0105, 0.0101, 0.0101 );
402  deta_cut = chooseVal(threshold, 0.0126, 0.00976, 0.0094, 0.0095 );
403  dphi_cut = chooseVal(threshold, 0.107, 0.0929, 0.0296, 0.0291 );
404  hovere_cut = chooseVal(threshold, 0.186, 0.0765, 0.0372, 0.0372 );
405  reliso_cut = chooseVal(threshold, 0.161, 0.118, 0.0987, 0.0468 );
406  ooeminusoop_cut = chooseVal(threshold, 0.239, 0.184, 0.118, 0.0174 );
407  d0_cut = chooseVal(threshold, 0.0621, 0.0227, 0.0151, 0.0144 );
408  dz_cut = chooseVal(threshold, 0.613, 0.379, 0.238, 0.323 );
409  misshits_cut = chooseVal(threshold, 2, 2, 2, 2 );
410  req_conv_veto = chooseVal(threshold, true, true, true, true );
411  } else {
412  ieta_cut = chooseVal(threshold, 0.0339, 0.0318, 0.0287, 0.0287 );
413  deta_cut = chooseVal(threshold, 0.0109, 0.00952, 0.00773, 0.00762);
414  dphi_cut = chooseVal(threshold, 0.219, 0.181, 0.148, 0.0439 );
415  hovere_cut = chooseVal(threshold, 0.0962, 0.0824, 0.0546, 0.0544 );
416  reliso_cut = chooseVal(threshold, 0.193, 0.118, 0.0902, 0.0759 );
417  ooeminusoop_cut = chooseVal(threshold, 0.141, 0.125, 0.104, 0.01 );
418  d0_cut = chooseVal(threshold, 0.279, 0.242, 0.0535, 0.0377 );
419  dz_cut = chooseVal(threshold, 0.947, 0.921, 0.572, 0.571 );
420  misshits_cut = chooseVal(threshold, 3, 1, 1, 1 );
421  req_conv_veto = chooseVal(threshold, true, true, true, true );
422  }
423  }
424 
425  const double d0 = els_d0dum()->at(iel)
426  -pv_x()->at(0)*sin(els_tk_phi()->at(iel))
427  +pv_y()->at(0)*cos(els_tk_phi()->at(iel));
428  const double dz = fabs(els_vz()->at(iel)-pv_z()->at(0));
429  const double sigietaieta = (Type()==typeid(cfa_13)
430  ? els_full5x5_sigmaIetaIeta()->at(iel)
431  : els_sigmaIEtaIEta()->at(iel));
432 
433  return deta_cut > fabs(els_dEtaIn()->at(iel))
434  && dphi_cut > fabs(els_dPhiIn()->at(iel))
435  && ieta_cut > sigietaieta
436  && hovere_cut > els_hadOverEm()->at(iel)
437  && d0_cut > fabs(d0)
438  && dz_cut > fabs(dz)
439  && ooeminusoop_cut > fabs((1.0-els_eOverPIn()->at(iel))/els_caloEnergy()->at(iel))
440  && (!do_iso || reliso_cut>GetElectronIsolation(iel))
441  && (!req_conv_veto || els_PATpassConversionVeto()->at(iel))
442  && (misshits_cut >= els_expectedMissingInnerHits()->at(iel));
443 }
444 
445 float phys_objects::GetElectronIsolation(unsigned iel, bool mini) const {
446  if(!mini){
447  if(Type()==typeid(cfa_8)){
448  double sumEt = els_PFphotonIsoR03()->at(iel)
449  + els_PFneutralHadronIsoR03()->at(iel)
451  if(sumEt<0.0) sumEt=0;
452  return (els_PFchargedHadronIsoR03()->at(iel) + sumEt)/els_pt()->at(iel);
453  }else if(Type()==typeid(cfa_13)){
454  float absiso = els_pfIsolationR03_sumChargedHadronPt()->at(iel)
455  + std::max(0.0,
458  -0.5*els_pfIsolationR03_sumPUPt()->at(iel));
459  return absiso/els_pt()->at(iel);
460  }else{
461  throw std::logic_error("Unknown type "
462  +std::string(Type().name())
463  +" in phys_objects::GetElectronIsolation");
464  return 0.0;
465  }
466  }else{
467  return els_miniso()->at(iel);
468  }
469 }
470 
471 float phys_objects::GetEffectiveArea(float SCEta, bool isMC) const {
472  SCEta = fabs(SCEta);
473  if(isMC){
474  if( SCEta < 1.0 ) return 0.110;
475  else if(SCEta < 1.479) return 0.130;
476  else if(SCEta < 2.0 ) return 0.089;
477  else if(SCEta < 2.2 ) return 0.130;
478  else if(SCEta < 2.3 ) return 0.150;
479  else if(SCEta < 2.4 ) return 0.160;
480  else return 0.190;
481  }else{
482  //kEleGammaAndNeutralHadronIso03 from 2011 data
483  //obtained from http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/EGamma/EGammaAnalysisTools/interface/ElectronEffectiveArea.h?revision=1.3&view=markup
484  if( SCEta < 1.0 ) return 0.100;
485  else if(SCEta < 1.479) return 0.120;
486  else if(SCEta < 2.0 ) return 0.085;
487  else if(SCEta < 2.2 ) return 0.110;
488  else if(SCEta < 2.4 ) return 0.120;
489  else return 0.130;
490  }
491 }
492 
496 bool phys_objects::PassPhys14TauID(const int itau, const bool againstEMu, const bool mt_cut) const {
497  if (taus_pt()->at(itau) < 20.) return false;
498  if (fabs(taus_eta()->at(itau)) > 2.3) // cout << "pass eta" << endl;
499  if (!taus_byDecayModeFinding()->at(itau)) return false;
500  if (taus_chargedIsoPtSum()->at(itau) > 1.) return false;
501  if (againstEMu && (!taus_againstMuonLoose3()->at(itau) || !taus_againstElectronLooseMVA5()->at(itau))) return false;
502  if (mt_cut && GetMT(taus_pt()->at(itau), taus_phi()->at(itau),
503  met_corr(), met_phi_corr())>100) return false;
504 
505  return true;
506 }
507 
511 bool phys_objects::IsGoodIsoTrack(unsigned itrk, bool mt_cut) const{
512  if(itrk>=isotk_pt()->size()) return false;
513  return isotk_pt()->at(itrk)>=15.
514  && (isotk_iso()->at(itrk)/isotk_pt()->at(itrk) < 0.1)
515  && (fabs(isotk_dzpv()->at(itrk))<0.05)
516  && (fabs(isotk_eta()->at(itrk))<2.4)
517  && ( !mt_cut || GetMT(isotk_pt()->at(itrk), isotk_phi()->at(itrk),
518  met_corr(), met_phi_corr())<100 ) ;
519 }
520 
525  CorrectJets();
526  return met_corr_;
527 }
528 
530  CorrectJets();
531  return met_phi_corr_;
532 }
533 
537 const vector<TLorentzVector> & phys_objects::jets_corr_p4() const{
538  CorrectJets();
539  return jets_corr_p4_;
540 }
541 
542 vector<TLorentzVector> & phys_objects::jets_corr_p4(){
543  CorrectJets();
544  return jets_corr_p4_;
545 }
546 
548  if(set_jets_) return;
549 
550  bool do_metcorr(false); // For now we don't correct MET
551  //bool do_metcorr(true);
552  jets_corr_p4_.clear();
553  TLorentzVector corr_p4, uncorr_p4, miniaod_p4;
554  float METx = mets_et()*cos(mets_phi());
555  float METy = mets_et()*sin(mets_phi());
556  for(size_t ijet = 0; ijet < jets_pt()->size(); ++ijet){
557  miniaod_p4.SetPtEtaPhiM(jets_pt()->at(ijet), jets_eta()->at(ijet),
558  jets_phi()->at(ijet), jets_mass()->at(ijet));
559  uncorr_p4 = miniaod_p4*jets_corrFactorRaw()->at(ijet);
560  corr_p4 = miniaod_p4;
561  if(jec_files.size() > 0){
562  corr_p4 *= jets_corrFactorRaw()->at(ijet); // First, uncorrect it
563 
564  jet_corrector_->setJetEta(corr_p4.Eta());
565  jet_corrector_->setJetPt(corr_p4.Pt());
566  jet_corrector_->setJetA(jets_area()->at(ijet));
568 
569  corr_p4 *= jet_corrector_->getCorrection();
570  if(uncorr_p4.Pt() > 10 && do_metcorr) {
571  METx += miniaod_p4.Px();
572  METy += miniaod_p4.Py();
573  METx -= corr_p4.Px();
574  METy -= corr_p4.Py();
575  }
576  } // if there are corrections to make
577  jets_corr_p4_.push_back(corr_p4);
578  } // Loop over jets
579 
580  if(do_metcorr){
581  float correctedMET = sqrt(METx*METx + METy*METy);
582  float correctedMETPhi = atan2(METy,METx);
583  met_corr_ = correctedMET;
584  met_phi_corr_ = TVector2::Phi_mpi_pi(correctedMETPhi);
585  } else {
586  met_corr_ = mets_et();
587  met_phi_corr_ = mets_phi();
588  }
589  set_jets_ = true;
590 }
591 
592 vector<int> phys_objects::GetJets(const vector<int> &VetoEl, const vector<int> &VetoMu,
593  double pt_thresh, double eta_thresh) const {
594  vector<int> jets;
595  vector<bool> jet_is_lepton(jets_corr_p4().size(), false);
596  map<size_t,vector<size_t> > mu_matches, el_matches;
597  GetMatchedLeptons(VetoMu, VetoEl, mu_matches, el_matches);
598 
599  for(size_t ijet = 0; ijet < jets_corr_p4().size(); ++ijet){
600  if(mu_matches.find(ijet) != mu_matches.end()
601  || el_matches.find(ijet) != el_matches.end()){
602  jet_is_lepton[ijet] = true;
603  }
604  }
605 
606  // Tau/photon cleaning, and calculation of HT
607  for(unsigned ijet = 0; ijet<jets_corr_p4().size(); ijet++) {
608  if(!IsGoodJet(ijet, pt_thresh, eta_thresh) || jet_is_lepton[ijet]) continue;
609 
610  jets.push_back(ijet);
611  } // Loop over jets
612 
613  return jets;
614 }
615 
616 bool phys_objects::AllGoodJets(const vector<int> &VetoEl, const vector<int> &VetoMu,
617  double pt_thresh, double eta_thresh) const {
618  vector<bool> jet_is_lepton(jets_corr_p4().size(), false);
619  map<size_t,vector<size_t> > mu_matches, el_matches;
620  GetMatchedLeptons(VetoMu, VetoEl, mu_matches, el_matches);
621 
622  for(size_t ijet = 0; ijet < jets_corr_p4().size(); ++ijet){
623  if(mu_matches.find(ijet) != mu_matches.end()
624  || el_matches.find(ijet) != el_matches.end()){
625  jet_is_lepton[ijet] = true;
626  }
627  }
628 
629  bool bad_jets(true);
630  for(unsigned ijet = 0; ijet<jets_corr_p4().size(); ijet++) {
631  if(!jet_is_lepton[ijet] && jets_corr_p4().at(ijet).Pt()>pt_thresh &&
632  fabs(jets_corr_p4().at(ijet).Eta())<eta_thresh && !IsBasicJet(ijet)) {
633  bad_jets = false;
634  break;
635  }
636  } // Loop over jets
637  return bad_jets;
638 }
639 
640 void phys_objects::GetMatchedLeptons(const vector<int> &veto_mu,
641  const vector<int> &veto_el,
642  map<size_t,vector<size_t> > &mu_matches,
643  map<size_t,vector<size_t> > &el_matches) const{
644  mu_matches.clear();
645  el_matches.clear();
646  //Match muons to jets
647  for(size_t ivmu = 0; ivmu < veto_mu.size(); ++ivmu){
648  int imu = veto_mu.at(ivmu);
649  size_t imatch = 0;
650  float mindr = numeric_limits<float>::max();
651  for(size_t ijet = 0; mindr > 0. && ijet < jets_corr_p4().size(); ++ijet){
652  if(mus_isPF()->at(imu) && mus_jet_ind()->at(imu) == static_cast<int>(ijet)){
653  imatch = ijet;
654  mindr = 0.;
655  }else{
656  double dr = dR(jets_corr_p4().at(ijet).Eta(), mus_eta()->at(imu),
657  jets_corr_p4().at(ijet).Phi(), mus_phi()->at(imu));
658  if(dr<mindr){
659  mindr=dr;
660  imatch = ijet;
661  }
662  }
663  }
664  if(mindr < 0.4) mu_matches[imatch].push_back(imu);
665  else cout<<"mus "<<imu<<" not matched. p = ("<<mus_pt()->at(imu)<<","<<mus_eta()->at(imu)
666  <<","<<mus_phi()->at(imu)<<")"<<endl;
667  }
668 
669  //Match electrons to jets
670  for(size_t ivel = 0; ivel < veto_el.size(); ++ivel){
671  int iel = veto_el.at(ivel);
672  size_t imatch = 0;
673  float mindr = numeric_limits<float>::max();
674  for(size_t ijet = 0; mindr > 0. && ijet < jets_corr_p4().size(); ++ijet){
675  if(els_isPF()->at(iel) && els_jet_ind()->at(iel) == static_cast<int>(ijet)){
676  imatch = ijet;
677  mindr = 0.;
678  }else{
679  double dr = dR(jets_corr_p4().at(ijet).Eta(), els_eta()->at(iel),
680  jets_corr_p4().at(ijet).Phi(), els_phi()->at(iel));
681  if(dr<mindr){
682  mindr=dr;
683  imatch = ijet;
684  }
685  }
686  }
687  if(mindr < 0.4) el_matches[imatch].push_back(iel);
688  else cout<<"els "<<iel<<" not matched. p = ("<<els_pt()->at(iel)<<","<<els_eta()->at(iel)
689  <<","<<els_phi()->at(iel)<<")"<<endl;
690  }
691 }
692 
693 vector<Jet> phys_objects::GetSubtractedJets(const vector<int> &veto_el, const vector<int> &veto_mu,
694  double pt_thresh, double eta_thresh) const{
695  vector<Jet> jets(0);
696  map<size_t,vector<size_t> > mu_matches, el_matches;
697 
698  GetMatchedLeptons(veto_mu, veto_el, mu_matches, el_matches);
699 
700  //Compute subtracted jets
701  for(size_t ijet = 0; ijet < jets_corr_p4().size(); ++ijet){
702  if(!IsGoodJet(ijet, 0., 999.)) continue;
703  TLorentzVector p4jet(jets_corr_p4().at(ijet)), p4sub;
704 
705  int subtracted = 0;
706  float mindr = numeric_limits<float>::max();
707  //Remove muons
708  if(mu_matches.find(ijet) != mu_matches.end()){
709  const vector<size_t> &matches = mu_matches.at(ijet);
710  for(size_t imatch = 0; imatch < matches.size(); ++imatch){
711  size_t imu = matches.at(imatch);
712  TLorentzVector p4mu;
713  p4mu.SetPtEtaPhiE(mus_pt()->at(imu), mus_eta()->at(imu),
714  mus_phi()->at(imu), mus_energy()->at(imu));
715  float dr = p4mu.DeltaR(p4jet);
716  if(dr<mindr) mindr = dr;
717  p4sub += p4mu;
718  ++subtracted;
719  }
720  }
721 
722  //Remove electrons
723  if(el_matches.find(ijet) != el_matches.end()){
724  const vector<size_t> &matches = el_matches.at(ijet);
725  for(size_t imatch = 0; imatch < matches.size(); ++imatch){
726  size_t iel = matches.at(imatch);
727  TLorentzVector p4el;
728  p4el.SetPtEtaPhiE(els_pt()->at(iel), els_eta()->at(iel),
729  els_phi()->at(iel), els_energy()->at(iel));
730  float dr = p4el.DeltaR(p4jet);
731  if(dr<mindr) mindr = dr;
732  p4sub += p4el;
733  ++subtracted;
734  }
735  }
736  p4jet -= p4sub;
737 
738  //Apply eta and pt cut to subtracted momentum
739  if(fabs(p4jet.Eta())>eta_thresh || p4jet.Pt()<pt_thresh) continue;
740 
741  //Record subtracted jets passing quality, eta, and pt cuts
742  jets.push_back(Jet());
743  jets.back().p4 = p4jet;
744  jets.back().csv = jets_btag_inc_secVertexCombined()->at(ijet);
745  jets.back().nleps = subtracted;
746  jets.back().id = TMath::Nint(jets_parton_Id()->at(ijet));
747  jets.back().p4sub = p4sub;
748  jets.back().mindr = mindr;
749  }
750 
751  return jets;
752 }
753 
754 bool phys_objects::IsGoodJet(unsigned ijet, double ptThresh, double etaThresh) const{
755  if(jets_corr_p4().size()<=ijet) return false;
756  if(!IsBasicJet(ijet)) return false;
757  if(jets_corr_p4().at(ijet).Pt()<ptThresh || fabs(jets_corr_p4().at(ijet).Eta())>etaThresh) return false;
758  return true;
759 }
760 
761 bool phys_objects::IsBasicJet(unsigned ijet) const{
762  //NOTE: This may need to be updated to match:
763  //https://twiki.cern.ch/twiki/bin/view/CMS/JetID
764  double rawRatio =(jets_rawPt()->at(ijet)/jets_pt()->at(ijet)); // Same as jets_corrFactorRaw
765  const double jetenergy = jets_energy()->at(ijet) * rawRatio;
766  double NEMF = -999., CEMF = -999., NHF=-999., CHF=-999.;
767  double CHM=jets_chg_Mult()->at(ijet);
768  double NumConst=jets_mu_Mult()->at(ijet)+jets_neutral_Mult()->at(ijet)+jets_chg_Mult()->at(ijet);
769  double NumNeutralParticles = jets_neutral_Mult()->at(ijet);
770 
771  if(jetenergy > 0){
772  NEMF = jets_neutralEmE()->at(ijet)/jetenergy;
773  CEMF = jets_chgEmE()->at(ijet)/jetenergy;
774  NHF = jets_neutralHadE()->at(ijet)/jetenergy;
775  CHF = jets_chgHadE()->at(ijet)/jetenergy;
776  }
777 
778  double eta(jets_corr_p4().at(ijet).Eta());
779  bool eta_leq_3 = (NHF<0.99 && NEMF<0.99 && NumConst>1) && ((fabs(eta)<=2.4 && CHF>0 && CHM>0 && CEMF<0.99) || fabs(eta)>2.4);
780  bool eta_g_3 = NEMF<0.90 && NumNeutralParticles>10;
781 
782  return (eta_leq_3 && fabs(eta)<=3.) || (eta_g_3 && fabs(eta)>3.);
783 
784  // return (NEMF < 0.99 && NHF < 0.99 && NumConst > 1
785  // && (fabs(jets_corr_p4().at(ijet).Eta())>=2.4 || (CEMF < 0.99 && CHF > 0 && CHM > 0)) );
786 }
787 
791 int phys_objects::GetTrueMuon(int index, int &momID, bool &fromW, float &closest_deltaR, double &pT, double &phi) const {
792  if(index < 0 || index >= static_cast<int>(mus_eta()->size())) return -1;
793 
794  closest_deltaR = 9999.; // Old deltaR
795  int closest_imc = -1, idLepton = 0;
796  float RecPt = mus_pt()->at(index), RecEta = mus_eta()->at(index), RecPhi = mus_phi()->at(index);
797  closest_imc = GetTrueParticle(RecPt, RecEta, RecPhi, closest_deltaR, pdtlund::mu_minus);
798 
799  closest_deltaR = 9999.;
800  if(closest_imc >= 0){
801  idLepton = static_cast<int>(mc_doc_id()->at(closest_imc));
802 
803  pT = mc_doc_pt()->at(closest_imc);
804  phi = mc_doc_phi()->at(closest_imc);
805 
806  momID = GetMom(mc_doc_id()->at(closest_imc), mc_doc_mother_id()->at(closest_imc),
807  mc_doc_grandmother_id()->at(closest_imc),
808  mc_doc_ggrandmother_id()->at(closest_imc),
809  fromW);
810  // Finding mindR with respect to partons from top or W or status 23
811  for(unsigned imc=0; imc < mc_doc_id()->size(); imc++){
812  if((abs(mc_doc_mother_id()->at(imc)) != 24 && abs(mc_doc_mother_id()->at(imc)) != 6 &&
813  mc_doc_status()->at(imc) != 23) || abs(mc_doc_id()->at(imc)) > 5) continue;
814  float MCEta = mc_doc_eta()->at(imc); float MCPhi = mc_doc_phi()->at(imc);
815  float deltaR = dR(RecEta,MCEta, RecPhi,MCPhi);
816  if(deltaR < closest_deltaR) closest_deltaR = deltaR;
817  }
818  } else {
819  closest_imc = GetTrueParticle(RecPt, RecEta, RecPhi, closest_deltaR, 0);
820  if(closest_imc >= 0){
821  idLepton = static_cast<int>(mc_doc_id()->at(closest_imc));
822  pT = mc_doc_pt()->at(closest_imc);
823  phi = mc_doc_phi()->at(closest_imc);
824 
825  momID = GetMom(mc_doc_id()->at(closest_imc), mc_doc_mother_id()->at(closest_imc),
826  mc_doc_grandmother_id()->at(closest_imc),
827  mc_doc_ggrandmother_id()->at(closest_imc),
828  fromW);
829  } else {
830  momID = 0;
831  idLepton = 0;
832  fromW = false;
833  pT = -1;
834  phi = -1;
835  }
836  }
837  return idLepton;
838 }
839 
840 int phys_objects::GetTrueElectron(int index, int &momID, bool &fromW, float &closest_deltaR, double &pT, double &phi) const {
841  if(index < 0 || index >= static_cast<int>(els_eta()->size())) return -1;
842 
843  closest_deltaR = 9999.;
844  int closest_imc = -1, idLepton = 0;
845  float RecPt = els_pt()->at(index), RecEta = els_eta()->at(index), RecPhi = els_phi()->at(index);
846  closest_imc = GetTrueParticle(RecPt, RecEta, RecPhi, closest_deltaR, pdtlund::e_minus);
847 
848  closest_deltaR = 9999.;
849  if(closest_imc >= 0){
850  idLepton = static_cast<int>(mc_doc_id()->at(closest_imc));
851 
852  pT = mc_doc_pt()->at(closest_imc);
853  phi = mc_doc_phi()->at(closest_imc);
854 
855  momID = GetMom(mc_doc_id()->at(closest_imc), mc_doc_mother_id()->at(closest_imc),
856  mc_doc_grandmother_id()->at(closest_imc),
857  mc_doc_ggrandmother_id()->at(closest_imc),
858  fromW);
859  // Finding mindR with respect to partons from top or W or status 23
860  for(unsigned imc=0; imc < mc_doc_id()->size(); imc++){
861  if((abs(mc_doc_mother_id()->at(imc)) != 24 && abs(mc_doc_mother_id()->at(imc)) != 6 &&
862  mc_doc_status()->at(imc) != 23) || abs(mc_doc_id()->at(imc)) > 5) continue;
863  float MCEta = mc_doc_eta()->at(imc); float MCPhi = mc_doc_phi()->at(imc);
864  float deltaR = dR(RecEta,MCEta, RecPhi,MCPhi);
865  if(deltaR < closest_deltaR) closest_deltaR = deltaR;
866  }
867  } else {
868  closest_imc = GetTrueParticle(RecPt, RecEta, RecPhi, closest_deltaR, 0);
869  if(closest_imc >= 0){
870  momID = GetMom(mc_doc_id()->at(closest_imc), mc_doc_mother_id()->at(closest_imc),
871  mc_doc_grandmother_id()->at(closest_imc),
872  mc_doc_ggrandmother_id()->at(closest_imc),
873  fromW);
874  idLepton = static_cast<int>(mc_doc_id()->at(closest_imc));
875  pT = mc_doc_pt()->at(closest_imc);
876  phi = mc_doc_phi()->at(closest_imc);
877  } else {
878  momID = 0;
879  idLepton = 0;
880  fromW = false;
881  pT=-1;
882  phi=-1;
883  }
884  }
885  return idLepton;
886 }
887 
888 int phys_objects::GetTrueParticle(float RecPt, float RecEta, float RecPhi,
889  float &closest_deltaR, int ID) const {
890  const float pT_Threshold(0.3), dR_Threshold(0.1);
891  int closest_imc = -1;
892  float deltaR = 9999.; closest_deltaR = 9999.;
893  float MCEta, MCPhi;
894  for(unsigned imc=0; imc < mc_doc_id()->size(); imc++){
895  if(ID!=0 && abs(mc_doc_id()->at(imc)) != ID) continue;
896  MCEta = mc_doc_eta()->at(imc); MCPhi = mc_doc_phi()->at(imc);
897  deltaR = dR(RecEta,MCEta, RecPhi,MCPhi);
898  if(deltaR > dR_Threshold || abs(mc_doc_pt()->at(imc)-RecPt)/RecPt > pT_Threshold) continue;
899  if(deltaR < closest_deltaR && deltaR < dR_Threshold) {
900  closest_deltaR = deltaR;
901  closest_imc = imc;
902  }
903  }
904  return closest_imc;
905 }
906 
907 int phys_objects::GetMom(const float id, const float mom, const float gmom,
908  const float ggmom, bool &fromW){
909  const int iid = TMath::Nint(id);
910  const int imom = TMath::Nint(mom);
911  const int igmom = TMath::Nint(gmom);
912  const int iggmom = TMath::Nint(ggmom);
913 
914  int ret_mom = 0;
915  if(imom != iid) ret_mom = imom;
916  else if(igmom != iid) ret_mom = igmom;
917  else ret_mom = iggmom;
918 
919  // There's various leptons that seem to come from W->udsc->l. We won't call them prompt
920  fromW = abs(ret_mom)==24 || (abs(ret_mom)==15 && (abs(igmom)==24 || abs(iggmom)==24));
921 
922  return ret_mom;
923 }
924 
925 void phys_objects::GetBestLepton(bool &is_muon, size_t &index){
926  //Returns index of highest pt signal lepton, if there is one. Falls back to veto leptons if there are no signal leptons and then all leptons if there are no veto leptons.
927  is_muon = false;
928  index = -1;
929  double max_pt = -1.0;
930  for(size_t imu = 0; imu < mus_pt()->size(); ++imu){
931  if(!IsSignalMuon(imu)) continue;
932  if(mus_pt()->at(imu)>max_pt){
933  max_pt = mus_pt()->at(imu);
934  is_muon = true;
935  index = imu;
936  }
937  }
938  for(size_t iel = 0; iel < els_pt()->size(); ++iel){
939  if(!IsSignalElectron(iel)) continue;
940  if(els_pt()->at(iel)>max_pt){
941  max_pt = els_pt()->at(iel);
942  is_muon = false;
943  index = iel;
944  }
945  }
946  if(max_pt<0.){
947  for(size_t imu = 0; imu < mus_pt()->size(); ++imu){
948  if(!IsVetoMuon(imu)) continue;
949  if(mus_pt()->at(imu)>max_pt){
950  max_pt = mus_pt()->at(imu);
951  is_muon = true;
952  index = imu;
953  }
954  }
955  for(size_t iel = 0; iel < els_pt()->size(); ++iel){
956  if(!IsVetoElectron(iel)) continue;
957  if(els_pt()->at(iel)>max_pt){
958  max_pt = els_pt()->at(iel);
959  is_muon = false;
960  index = iel;
961  }
962  }
963  }
964  if(max_pt<0.){
965  for(size_t imu = 0; imu < mus_pt()->size(); ++imu){
966  if(mus_pt()->at(imu)>max_pt){
967  max_pt = mus_pt()->at(imu);
968  is_muon = true;
969  index = imu;
970  }
971  }
972  for(size_t iel = 0; iel < els_pt()->size(); ++iel){
973  if(els_pt()->at(iel)>max_pt){
974  max_pt = els_pt()->at(iel);
975  is_muon = false;
976  index = iel;
977  }
978  }
979  }
980 }
981 
982 vector<mc_particle> phys_objects::GetMCParticles() const{
983  vector<mc_particle> parts;
984  for(size_t idoc = 0; idoc < mc_doc_id()->size(); ++idoc){
985  TLorentzVector v(mc_doc_px()->at(idoc),
986  mc_doc_py()->at(idoc),
987  mc_doc_pz()->at(idoc),
988  mc_doc_energy()->at(idoc));
989 
990  parts.push_back(mc_particle(v,
991  mc_doc_charge()->at(idoc),
992  TMath::Nint(mc_doc_id()->at(idoc)),
993  TMath::Nint(mc_doc_mother_id()->at(idoc)),
994  TMath::Nint(mc_doc_grandmother_id()->at(idoc)),
995  TMath::Nint(mc_doc_ggrandmother_id()->at(idoc)),
996  TMath::Nint(mc_doc_status()->at(idoc))));
997  }
998  size_t to_search = parts.size();
999 
1000  for(size_t ifinal = 0; ifinal < mc_final_id()->size(); ++ifinal){
1001  TLorentzVector v;
1002  v.SetPtEtaPhiE(mc_final_pt()->at(ifinal),
1003  mc_final_eta()->at(ifinal),
1004  mc_final_phi()->at(ifinal),
1005  mc_final_energy()->at(ifinal));
1006  float charge = mc_final_charge()->at(ifinal);
1007  int id = TMath::Nint(mc_final_id()->at(ifinal));
1008  int mom = TMath::Nint(mc_final_mother_id()->at(ifinal));
1009  int gmom = TMath::Nint(mc_final_grandmother_id()->at(ifinal));
1010  int ggmom = TMath::Nint(mc_final_ggrandmother_id()->at(ifinal));
1011 
1012  //Comment out next line to avoid appending particles already in mc_doc
1013  to_search = 0;
1014  bool skip = false;
1015  for(size_t i = 0; !skip && i < to_search; ++i){
1016  mc_particle &part = parts.at(i);
1017  if(TMath::Nint(3.*charge) == part.charge_
1018  && id == part.id_
1019  && mom == part.mom_
1020  && gmom == part.gmom_
1021  && ggmom == part.ggmom_
1022  && (v-part.momentum_).Vect().Mag()<0.01) skip = true;
1023  }
1024  if(!skip){
1025  parts.push_back(mc_particle(v, charge, id, mom, gmom, ggmom, 0));
1026  }
1027  }
1028  return parts;
1029 }
1030 
1031 // size_t phys_objects::MatchCandToStatus1(size_t icand,
1032 // const vector<mc_particle> &parts) const{
1033 // const size_t bad_index = static_cast<size_t>(-1);
1034 // if(icand >= pfcand_charge()->size()) return bad_index;
1035 
1036 // if(is_nan(pfcand_pt()->at(icand))
1037 // || is_nan(pfcand_eta()->at(icand))
1038 // || is_nan(pfcand_phi()->at(icand))) return bad_index;
1039 
1040 // TVector3 p3cand(pfcand_pt()->at(icand)*cos(pfcand_phi()->at(icand)),
1041 // pfcand_pt()->at(icand)*sin(pfcand_phi()->at(icand)),
1042 // pfcand_pt()->at(icand)*sinh(pfcand_eta()->at(icand)));
1043 
1044 // float best_score = numeric_limits<float>::max();
1045 // size_t best_part = bad_index;
1046 // for(size_t imc = parts.size()-1; imc < parts.size(); --imc){
1047 // const mc_particle &part = parts.at(imc);
1048 // if(part.status_ != 0) continue;
1049 // if(fabs(3.*part.charge_)<0.5) continue;
1050 // float this_score = (part.momentum_.Vect()-p3cand).Mag2();
1051 // if(this_score < best_score){
1052 // best_score = this_score;
1053 // best_part = imc;
1054 // }
1055 // }
1056 
1057 // return best_part;
1058 // }
1059 
1060 size_t phys_objects::GetMom(size_t index, const vector<mc_particle> &parts){
1061  const size_t bad_index = static_cast<size_t>(-1);
1062  if(index >= parts.size()) return bad_index;
1063 
1064  const mc_particle &daughter = parts.at(index);
1065 
1066  size_t low_cousin = index, high_cousin = index;
1067  bool abort = false;
1068  for(size_t imc = index - 1 ; !abort && imc < parts.size(); --imc){
1069  const mc_particle &cousin = parts.at(imc);
1070 
1071  if(cousin.mom_ == daughter.mom_
1072  && cousin.gmom_ == daughter.gmom_
1073  && cousin.ggmom_ == daughter.ggmom_){
1074  low_cousin = imc;
1075  }else{
1076  abort = true;
1077  }
1078  }
1079 
1080  abort = false;
1081  for(size_t imc = index + 1 ; !abort && imc < parts.size(); ++imc){
1082  const mc_particle &cousin = parts.at(imc);
1083 
1084  if(cousin.mom_ == daughter.mom_
1085  && cousin.gmom_ == daughter.gmom_
1086  && cousin.ggmom_ == daughter.ggmom_){
1087  high_cousin = imc;
1088  }else{
1089  abort = true;
1090  }
1091  }
1092 
1093  float best_score = numeric_limits<float>::max();
1094  size_t best_parent = bad_index;
1095  //Loop over possible parents
1096  for(size_t imc = 0; imc < index; ++imc){
1097  const mc_particle &mom = parts.at(imc);
1098 
1099  if(!(mom.id_ == daughter.mom_
1100  && mom.mom_ == daughter.gmom_
1101  && mom.gmom_ == daughter.ggmom_)) continue;
1102 
1103  //Find parent best momentum matched to sum of consecutive potential daughters
1104  for(size_t low = low_cousin; low <= index; ++low){
1105  TVector3 diff = mom.momentum_.Vect();
1106  for(size_t high = low; high <= high_cousin; ++high){
1107  const mc_particle &sister = parts.at(high);
1108  diff -= sister.momentum_.Vect();
1109  if(high < index) continue;
1110  float this_score = diff.Mag2();
1111  if(this_score < best_score){
1112  best_score = this_score;
1113  best_parent = imc;
1114  }
1115  }
1116  }
1117  }
1118 
1119  return best_parent;
1120 }
1121 
1122 vector<size_t> phys_objects::GetMoms(const vector<mc_particle> &parts){
1123  vector<size_t> moms(parts.size());
1124  for(size_t imc = 0; imc < moms.size(); ++imc){
1125  moms.at(imc) = GetMom(imc, parts);
1126  }
1127  return moms;
1128 }
1129 
1130 bool phys_objects::IsBrem(size_t index,
1131  const vector<mc_particle> &parts,
1132  const vector<size_t> &moms){
1133  if(index >= moms.size() || moms.at(index) >= moms.size()) return false;
1134  const mc_particle &part = parts.at(index);
1135  int id = part.id_;
1136  if(abs(id) != 11 && abs(id) != 13 && abs(id) != 15) return false;
1137  int mom = parts.at(moms.at(index)).id_;
1138  if(abs(mom) != 11 && abs(mom) != 13 && abs(mom) !=15) return false;
1139 
1140  size_t low, high;
1141  for(low = index; low < moms.size(); --low){
1142  if(moms.at(low) != moms.at(index)) break;
1143  }
1144  ++low;
1145  for(high = index; high < moms.size(); ++high){
1146  if(moms.at(high) != moms.at(index)) break;
1147  }
1148 
1149  unsigned p = 0, n = 0;
1150  size_t hp = 0, hn = 0;
1151  float pp = 0, np = 0;
1152  for(size_t i = low; i < high; ++i){
1153  float p3 = parts.at(i).momentum_.Vect().Mag2();
1154  if(parts.at(i).id_ == abs(id)){
1155  ++p;
1156  if(p3>pp){
1157  pp = p3;
1158  hp = i;
1159  }
1160  }else if(parts.at(i).id_ == -abs(id)){
1161  ++n;
1162  if(p3>np){
1163  np = p;
1164  hn = i;
1165  }
1166  }
1167  }
1168 
1169  if(((p>n && id > 0 && index == hp) || (n>p && id < 0 && index == hn))){
1170  return false;
1171  }else{
1172  return true;
1173  }
1174 }
1175 
1176 bool phys_objects::FromStatus23(size_t index,
1177  const vector<mc_particle> &parts,
1178  const vector<size_t> &moms){
1179  if(index >= moms.size()) return false;
1180 
1181  bool found_23 = false;
1182  while(index < moms.size() && !found_23){
1183  if(parts.at(index).status_ == 23){
1184  found_23 = true;
1185  }
1186  index = moms.at(index);
1187  }
1188  return found_23;
1189 }
1190 
1191 bool phys_objects::FromTop(size_t index,
1192  const vector<mc_particle> &parts,
1193  const vector<size_t> &moms){
1194  if(index >= moms.size()) return false;
1195 
1196  bool found_top = false;
1197  while(index < moms.size() && !found_top){
1198  if(abs(parts.at(index).id_) == 6){
1199  found_top = true;
1200  }
1201  index = moms.at(index);
1202  }
1203  return found_top;
1204 }
1205 
1206 bool phys_objects::FromW(size_t index,
1207  const vector<mc_particle> &parts,
1208  const vector<size_t> &moms){
1209  if(index >= moms.size()) return false;
1210  if(IsBrem(index, parts, moms)) return false;
1211 
1212  index = moms.at(index);
1213  bool found_w = false;
1214  bool found_bad = false;
1215  while(index < moms.size()){
1216  int id = abs(parts.at(index).id_);
1217  bool bad = (id < 11 || id >16 ) && id != 24;
1218  if(id == 24){
1219  if(found_bad){
1220  return false;
1221  }else{
1222  found_w = true;
1223  }
1224  }
1225  if(bad){
1226  if(found_w){
1227  found_bad = true;
1228  }else{
1229  return false;
1230  }
1231  }
1232  index = moms.at(index);
1233  }
1234  return found_w;
1235 }
1236 
1237 bool phys_objects::FromTau(size_t index,
1238  const vector<mc_particle> &parts,
1239  const vector<size_t> &moms){
1240  if(index >= moms.size()) return false;
1241  int id = parts.at(index).id_;
1242  size_t i = moms.at(index);
1243  while(i < moms.size()){
1244  if(abs(parts.at(i).id_) == 15 && FromW(i, parts, moms)) return true;
1245  if(parts.at(i).id_ != id) return false;
1246  i = moms.at(i);
1247  }
1248  return false;
1249 }
1250 
1251 void phys_objects::CountLeptons(const vector<mc_particle> &parts,
1252  const vector<size_t> &moms,
1253  unsigned &nleps,
1254  unsigned &ntaus,
1255  unsigned &ntauleps){
1256  nleps = 0;
1257  ntaus = 0;
1258  ntauleps = 0;
1259  set<size_t> used_by_emu, used_by_tau;
1260  used_by_emu.insert(-1);
1261  used_by_tau.insert(-1);
1262  for(size_t i = 0; i < parts.size(); ++i){
1263  int id = abs(parts.at(i).id_);
1264  if((id == 11 || id == 13 || id == 15) && FromW(i, parts, moms)){
1265  size_t parent_w = ParentW(i, parts, moms);
1266  if(used_by_emu.find(parent_w) == used_by_emu.end()){
1267  switch(id){
1268  case 11:
1269  case 13:
1270  ++nleps;
1271  used_by_emu.insert(parent_w);
1272  if(FromTau(i, parts, moms)){
1273  ++ ntauleps;
1274  }
1275  break;
1276  case 15:
1277  if(used_by_tau.find(parent_w) == used_by_tau.end()){
1278  used_by_tau.insert(parent_w);
1279  ++ntaus;
1280  }
1281  break;
1282  default:
1283  break;
1284  }
1285  }
1286  }
1287  }
1288 }
1289 
1290 size_t phys_objects::ParentW(size_t index,
1291  const vector<mc_particle> &parts,
1292  const vector<size_t> &moms){
1293  size_t w = static_cast<size_t>(-1);
1294  while(index < moms.size()){
1295  if(abs(parts.at(index).id_) == 24) w = index;
1296  index = moms.at(index);
1297  }
1298  return w;
1299 }
1300 
1301 size_t phys_objects::ParentTau(size_t index,
1302  const vector<mc_particle> &parts,
1303  const vector<size_t> &moms){
1304  size_t tau = static_cast<size_t>(-1);
1305  while(index < moms.size()){
1306  if(abs(parts.at(index).id_) == 15 && FromW(index, parts, moms)) tau = index;
1307  index = moms.at(index);
1308  }
1309  return tau;
1310 }
1311 
1313  const vector<mc_particle> &parts,
1314  const vector<size_t> &moms){
1315  if(index >= moms.size()) return 0;
1316  size_t parent_tau = ParentTau(index, parts, moms);
1317  return NumDescendants(parent_tau, parts, moms, true);
1318 }
1319 
1320 bool phys_objects::FromTauLep(size_t index,
1321  const vector<mc_particle> &parts,
1322  const vector<size_t> &moms){
1323  if(index >= moms.size()) return false;
1324  size_t parent_tau = ParentTau(index, parts, moms);
1325  for(size_t ilep = parts.size()-1; ilep < parts.size(); --ilep){
1326  const mc_particle &part = parts.at(ilep);
1327  if((abs(part.id_) == 11 || abs(part.id_) == 13)
1328  && IsDescendantOf(ilep, parent_tau, moms)
1329  && NumDescendants(ilep, parts, moms)==0){
1330  return true;
1331  }
1332  }
1333  return false;
1334 }
1335 
1336 unsigned phys_objects::NumChildren(size_t index,
1337  const vector<mc_particle> &parts,
1338  const vector<size_t> &moms,
1339  bool req_chg){
1340  unsigned num_children = 0;
1341  for(size_t istart = index + 1; istart < moms.size(); ++istart){
1342  if(parts.at(istart).status_ == 0
1343  && (!req_chg || parts.at(istart).charge_!=0)
1344  && moms.at(istart)==index) ++num_children;
1345  }
1346  return num_children;
1347 }
1348 
1349 unsigned phys_objects::NumDescendants(size_t index,
1350  const vector<mc_particle> &parts,
1351  const vector<size_t> &moms,
1352  bool req_chg){
1353  unsigned num_descendants = 0;
1354  for(size_t istart = index + 1; istart < moms.size(); ++istart){
1355  if(parts.at(istart).status_ == 0
1356  && (!req_chg || parts.at(istart).charge_!=0)
1357  && IsDescendantOf(istart, index, moms)) ++num_descendants;
1358  }
1359  return num_descendants;
1360 }
1361 
1362 bool phys_objects::IsDescendantOf(size_t descendant, size_t ancestor,
1363  const vector<size_t> &moms){
1364  if(descendant <= ancestor || descendant >= moms.size()) return false;
1365  size_t i = moms.at(descendant);
1366  while(i < moms.size()){
1367  if(i == ancestor) return true;
1368  i = moms.at(i);
1369  }
1370  return false;
1371 }
1372 
1377  if(beamSpot_x()->size()<1 || pv_x()->size()<1) return false;
1378  const double pv_rho(AddInQuadrature(pv_x()->at(0), pv_y()->at(0)));
1379  if(pv_ndof()->at(0)>4 && fabs(pv_z()->at(0))<24. && pv_rho<2.0 && pv_isFake()->at(0)==0) return true;
1380  return false;
1381 }
1382 
1384  bool hbhe(false), ecalTP(false), scrapingVeto(false);
1385  if(Type()==typeid(cfa_8)){
1386  hbhe = hbhefilter_decision();
1387  ecalTP = ecalTPfilter_decision();
1388  scrapingVeto = scrapingVeto_decision();
1389  }else if(Type()==typeid(cfa_13)){
1390  hbhe = true;
1391  ecalTP = true;
1392  scrapingVeto = true;
1393  }else{
1394  return false;
1395  }
1396  return cschalofilter_decision()
1397  && hbhe
1399  && ecalTP
1402  && scrapingVeto;
1403 }
1404 
1405 double phys_objects::getDZ(double vx, double vy, double vz, double px, double py, double pz, int firstGoodVertex) const {
1406  return vz - pv_z()->at(firstGoodVertex)
1407  -((vx-pv_x()->at(firstGoodVertex))*px+(vy-pv_y()->at(firstGoodVertex))*py)*pz/(px*px+py*py);
1408 }
1409 
1413 
1414 bool phys_objects::isData() const {
1415  return (SampleName().find("Run201") != string::npos);
1416 }
1417 
1418 long double phys_objects::SumDeltaPhi(long double phi_x, long double phi_a, long double phi_b){
1419  //N.B.: long doubles and checks are necessary! Want to get exact same value of SumDeltaPhi for all jets between the met and lepton or their negatives!
1420  long double pxa = DeltaPhi(phi_x, phi_a);
1421  long double pxb = DeltaPhi(phi_x, phi_b);
1422  long double sdp = pxa + pxb;
1423  if(Sign(SignedDeltaPhi(phi_x,phi_a))*Sign(SignedDeltaPhi(phi_x,phi_b))<=0){
1424  long double pab = DeltaPhi(phi_a, phi_b);
1425  if(sdp>PI){
1426  return 2.L*PI-pab;
1427  }else{
1428  return pab;
1429  }
1430  }else{
1431  return sdp;
1432  }
1433 }
1434 
1435 double phys_objects::GetDeltaPhiMETN(unsigned goodJetI, float otherpt, float othereta, bool useArcsin) const {
1436  double deltaT = GetDeltaPhiMETN_deltaT(goodJetI, otherpt, othereta);
1437  double dp = fabs(DeltaPhi(jets_corr_p4().at(goodJetI).Phi(), met_phi_corr()));
1438  double dpN = 0.0;
1439  if(useArcsin) {
1440  if( deltaT/met_corr() >= 1.0){
1441  dpN = dp / (PI/2.0);
1442  }else{
1443  dpN = dp / asin(deltaT/met_corr());
1444  }
1445  }else{
1446  dpN = dp / atan2(deltaT, static_cast<double>(met_corr()));
1447  }
1448  return dpN;
1449 }
1450 
1451 double phys_objects::GetDeltaPhiMETN_deltaT(unsigned goodJetI,
1452  float otherpt, float
1453  othereta) const {
1454  if(goodJetI>=jets_corr_p4().size()) return -99.;
1455 
1456  double sum = 0;
1457  for (unsigned i=0; i< jets_corr_p4().size(); i++) {
1458  if(i==goodJetI) continue;
1459  if(IsGoodJet(i, otherpt, othereta)){
1460  double jetres = 0.1;
1461  sum += pow( jetres*(jets_corr_p4().at(goodJetI).Px()*jets_corr_p4().at(i).Py() - jets_corr_p4().at(goodJetI).Py()*jets_corr_p4().at(i).Px()), 2);
1462  }
1463  }
1464  double deltaT = sqrt(sum)/jets_corr_p4().at(goodJetI).Pt();
1465  return deltaT;
1466 }
1467 
1468 double phys_objects::GetMinDeltaPhiMETN(unsigned maxjets, float mainpt, float maineta,
1469  float otherpt, float othereta, bool useArcsin) const {
1470  double mdpN=std::numeric_limits<double>::max();
1471  unsigned nGoodJets(0);
1472  for (unsigned i=0; i<jets_corr_p4().size(); i++) {
1473  if (!IsGoodJet(i, mainpt, maineta)) continue;
1474  nGoodJets++;
1475  double dpN = GetDeltaPhiMETN(i, otherpt, othereta, useArcsin);
1476  if (dpN>=0&&dpN<mdpN) mdpN=dpN;
1477  if (nGoodJets>=maxjets) break;
1478  }
1479  return mdpN;
1480 }
1481 
1482 double phys_objects::GetHT(const vector<int> &good_jets, double pt_cut) const{
1483  double ht = 0.0;
1484  for(size_t i = 0; i < good_jets.size(); ++i){
1485  const double pt = jets_corr_p4().at(good_jets.at(i)).Pt();
1486  if(pt>pt_cut) ht += pt;
1487  }
1488  return ht;
1489 }
1490 
1491 double phys_objects::GetMHT(const vector<int> &good_jets, double pt_cut) const {
1492  double px(0.), py(0.);
1493  for(size_t ijet = 0; ijet < good_jets.size(); ++ijet){
1494  const double pt = jets_corr_p4().at(good_jets.at(ijet)).Pt();
1495  if(pt>pt_cut){
1496  px += jets_corr_p4().at(good_jets.at(ijet)).Px();
1497  py += jets_corr_p4().at(good_jets.at(ijet)).Py();
1498  }
1499  }
1500  return AddInQuadrature(px, py);
1501 }
1502 
1503 size_t phys_objects::GetNumJets(const vector<int> &good_jets,
1504  double pt_cut,
1505  double csv_cut) const{
1506  size_t num_jets = 0;
1507  for(size_t i = 0; i < good_jets.size(); ++i){
1508  if(jets_corr_p4().at(good_jets.at(i)).Pt() > pt_cut
1509  && jets_btag_inc_secVertexCombined()->at(good_jets.at(i)) > csv_cut){
1510  ++num_jets;
1511  }
1512  }
1513  return num_jets;
1514 }
1515 
1516 double phys_objects::GetSphericity(const std::vector<TLorentzVector> &vs){
1517  double sumpt = 0.;
1518  double xx = 0., xy=0., yy =0.;
1519  for(size_t iv = 0; iv < vs.size(); ++iv){
1520  const TLorentzVector &v = vs.at(iv);
1521  sumpt += v.Pt();
1522  double inv_pt = 1./v.Pt();
1523  xx += v.Px()*v.Px()*inv_pt;
1524  xy += v.Px()*v.Py()*inv_pt;
1525  yy += v.Py()*v.Py()*inv_pt;
1526  }
1527  xx/=sumpt;
1528  xy/=sumpt;
1529  yy/=sumpt;
1530  return (xx+yy!=0.)?(xx+yy-AddInQuadrature(xx-yy,2.*xy))/(xx+yy):-1.;
1531 }
1532 
1536 // bool phys_objects::hasPFMatch(int index, particleId::leptonType type, int &pfIdx) const {
1537 // double deltaRVal = 999.;
1538 // double deltaPT = 999.;
1539 // double leptonEta = 0, leptonPhi = 0, leptonPt = 0;
1540 // int pdgid = 0;
1541 // if(type == particleId::muon ) {
1542 // leptonEta = mus_eta()->at(index);
1543 // leptonPhi = mus_phi()->at(index);
1544 // leptonPt = mus_pt()->at(index);
1545 // pdgid = 13;
1546 // } else if(type == particleId::electron) {
1547 // leptonEta = els_eta()->at(index);
1548 // leptonPhi = els_phi()->at(index);
1549 // leptonPt = els_pt()->at(index);
1550 // pdgid = 11;
1551 // }
1552 // for(unsigned iCand=0; iCand<pfcand_pt()->size(); iCand++) {
1553 // if(is_nan(pfcand_pt()->at(iCand))
1554 // || is_nan(pfcand_eta()->at(iCand))
1555 // || is_nan(pfcand_phi()->at(iCand))) continue;
1556 // if(fabs(TMath::Nint(pfcand_pdgId()->at(iCand)))==pdgid) {
1557 // double tempDeltaR = dR(leptonEta, pfcand_eta()->at(iCand), leptonPhi, pfcand_phi()->at(iCand));
1558 // if(tempDeltaR < deltaRVal) {
1559 // deltaRVal = tempDeltaR;
1560 // deltaPT = fabs(leptonPt-pfcand_pt()->at(iCand));
1561 // pfIdx=iCand;
1562 // }
1563 // }
1564 // }
1565 
1566 // if(type == particleId::electron) return (deltaPT<10);
1567 // else return (deltaPT<5);
1568 // }
1569 
1570 void phys_objects::GetLeadingBJets(const vector<int> &good_jets,
1571  double pt_cut, double csv_cut,
1572  size_t &lead, size_t &sub){
1573  lead = -1;
1574  sub = -1;
1575 
1576  float pt1 = -1., pt2 = -1.;
1577  for(size_t i = 0; i < good_jets.size(); ++i){
1578  size_t ijet = good_jets.at(i);
1579  double pt = jets_corr_p4().at(ijet).Pt();
1580  if(pt > pt_cut
1581  && jets_btag_inc_secVertexCombined()->at(ijet) > csv_cut){
1582  if(pt > pt1){
1583  pt2 = pt1;
1584  pt1 = pt;
1585  sub = lead;
1586  lead = ijet;
1587  }else if(pt > pt2){
1588  pt2 = pt;
1589  sub = ijet;
1590  }
1591  }
1592  }
1593 }
1594 
std::vector< bool > *const & taus_againstMuonLoose3() const
Definition: cfa.cpp:6220
std::vector< float > *const & els_pt() const
Definition: cfa.cpp:752
std::vector< float > *const & mc_doc_energy() const
Definition: cfa.cpp:1848
std::vector< float > *const & jets_neutralHadE() const
Definition: cfa.cpp:7365
const long double PI
Definition: utilities.hpp:21
virtual void GetEntry(const long entry)
virtual ~phys_objects()
double getDZ(double vx, double vy, double vz, double px, double py, double pz, int firstGoodVertex) const
std::vector< bool > *const & taus_byDecayModeFinding() const
Definition: cfa.cpp:6232
std::vector< float > *const & taus_chargedIsoPtSum() const
Definition: cfa.cpp:6296
const std::string & SampleName() const
Definition: cfa.cpp:31
static float MinTrackPt
static int GetMom(float id, float mom, float gmom, float ggmom, bool &fromW)
static bool FromTop(size_t index, const std::vector< mc_particle > &parts, const std::vector< size_t > &moms)
std::vector< float > *const & els_eta() const
Definition: cfa.cpp:576
static size_t ParentW(size_t index, const std::vector< mc_particle > &parts, const std::vector< size_t > &moms)
void CorrectJets() const
std::vector< TString > yes_trig
std::vector< float > *const & mus_tk_d0dum() const
Definition: cfa.cpp:3492
bool GetTriggerInfo(std::vector< TString > &trig_names, std::vector< bool > &trig_dec, std::vector< float > &trig_prescale)
long double GetMT(long double m1, long double pt1, long double phi1, long double m2, long double pt2, long double phi2)
Definition: utilities.cpp:291
bool PassPhys14TauID(const int itau, const bool againstEMu, const bool mt_cut) const
bool IsSignalElectron(unsigned iel, bool mini=true) const
std::vector< float > *const & trigger_prescalevalue() const
Definition: cfa.cpp:6636
std::vector< float > *const & els_pfIsolationR03_sumNeutralHadronEt() const
Definition: cfa.cpp:732
int GetTrueParticle(float RecPt, float RecEta, float RecPhi, float &closest_dR, int ID) const
Float_t const & rho_kt6PFJetsForIsolation2011() const
Definition: cfa.cpp:6120
bool inJSON(std::vector< std::vector< int > > VRunLumi, int Run, int LS)
Int_t const & cschalofilter_decision() const
Definition: cfa.cpp:332
std::vector< bool > *const & mus_isMediumMuon() const
Definition: cfa.cpp:3060
static float MinSignalLeptonPt
std::vector< bool > *const & trigger_decision() const
Definition: cfa.cpp:6624
std::vector< float > *const & mus_tk_vz() const
Definition: cfa.cpp:3580
FactorizedJetCorrector * jet_corrector_
int GetTrueElectron(int index, int &momID, bool &fromW, float &closest_dR, double &els_mc_pt, double &els_mc_phi) const
Int_t const & hcallaserfilter_decision() const
Definition: cfa.cpp:1032
std::vector< float > *const & els_energy() const
Definition: cfa.cpp:568
std::vector< float > *const & mc_final_grandmother_id() const
Definition: cfa.cpp:2040
std::vector< float > *const & mus_numberOfMatchedStations() const
Definition: cfa.cpp:3148
float met_corr() const
TLorentzVector momentum_
std::vector< float > *const & jets_neutralEmE() const
Definition: cfa.cpp:7354
std::vector< float > *const & jets_parton_Id() const
Definition: cfa.cpp:7409
std::vector< float > *const & els_hadOverEm() const
Definition: cfa.cpp:668
float GetEffectiveArea(float SCEta, bool isMC) const
std::vector< float > *const & jets_rawPt() const
Definition: cfa.cpp:7574
std::vector< float > *const & els_dPhiIn() const
Definition: cfa.cpp:500
std::vector< float > *const & mc_final_mother_id() const
Definition: cfa.cpp:2056
std::vector< float > *const & els_PFchargedHadronIsoR03() const
Definition: cfa.cpp:400
std::vector< float > *const & mc_doc_id() const
Definition: cfa.cpp:1864
std::vector< float > *const & pv_isFake() const
Definition: cfa.cpp:6056
std::vector< float > *const & mc_final_pt() const
Definition: cfa.cpp:2072
static std::vector< size_t > GetMoms(const std::vector< mc_particle > &parts)
std::vector< float > *const & mus_id_GlobalMuonPromptTight() const
Definition: cfa.cpp:3000
std::vector< float > *const & jets_chg_Mult() const
Definition: cfa.cpp:6925
std::vector< int > *const & els_jet_ind() const
Definition: cfa.cpp:696
std::vector< float > *const & pv_y() const
Definition: cfa.cpp:6080
std::vector< float > *const & jets_mu_Mult() const
Definition: cfa.cpp:7277
std::vector< float > *const & pv_x() const
Definition: cfa.cpp:6072
float met_phi_corr() const
STL namespace.
static float MinRA2bJetPt
std::vector< float > *const & isotk_iso() const
Definition: cfa.cpp:1052
std::vector< float > *const & jets_pt() const
Definition: cfa.cpp:7530
bool IsVetoIdElectron(unsigned iel, bool do_iso=false) const
bool isData() const
std::vector< float > *const & mc_doc_pt() const
Definition: cfa.cpp:1904
static unsigned NumChildren(size_t index, const std::vector< mc_particle > &parts, const std::vector< size_t > &moms, bool req_chg=false)
std::vector< float > *const & els_PFphotonIsoR03() const
Definition: cfa.cpp:408
std::vector< float > *const & mus_miniso() const
Definition: cfa.cpp:3140
std::vector< float > *const & beamSpot_x() const
Definition: cfa.cpp:304
std::vector< float > *const & els_vz() const
Definition: cfa.cpp:940
FactorizedJetCorrector * makeJetCorrector(std::vector< std::string > &vector_of_file_names)
Definition: JetCorrector.cpp:4
std::vector< float > *const & els_pfIsolationR03_sumChargedHadronPt() const
Definition: cfa.cpp:728
Float_t const & mets_et() const
Definition: cfa.cpp:8432
size_t GetNumJets(const std::vector< int > &good_jets, double pt_cut=0.0, double csv_cut=-std::numeric_limits< float >::max()) const
const std::type_info & Type() const
Definition: cfa.cpp:48
std::vector< float > *const & els_dEtaIn() const
Definition: cfa.cpp:492
bool IsBasicJet(unsigned ijet) const
std::vector< float > *const & isotk_pt() const
Definition: cfa.cpp:1060
void GetBestLepton(bool &is_muon, size_t &index)
float GetMuonIsolation(unsigned imu, bool mini=true) const
double GetMinDeltaPhiMETN(unsigned maxjets, float mainpt, float maineta, float otherpt, float othereta, bool useArcsin) const
std::vector< TString > no_trig
std::vector< float > *const & jets_corrFactorRaw() const
Definition: cfa.cpp:6969
std::vector< float > *const & els_d0dum() const
Definition: cfa.cpp:484
std::vector< float > *const & mc_final_id() const
Definition: cfa.cpp:2044
bool IsSignalIdMuon(unsigned iel) const
std::vector< bool > *const & taus_againstElectronLooseMVA5() const
Definition: cfa.cpp:6196
std::vector< std::string > *const & trigger_name() const
Definition: cfa.cpp:6632
T chooseVal(CutLevel threshold, T valVeto, T valLoose, T valMedium, T valTight) const
Float_t const & mets_phi() const
Definition: cfa.cpp:8443
bool IsIdElectron(unsigned iel, CutLevel threshold, bool do_iso=false) const
std::vector< float > *const & mc_final_charge() const
Definition: cfa.cpp:2024
std::vector< float > *const & taus_pt() const
Definition: cfa.cpp:6432
phys_objects(const std::string &filename, bool is_8TeV=false)
std::vector< float > *const & mus_pt() const
Definition: cfa.cpp:3332
void GetMatchedLeptons(const std::vector< int > &veto_mu, const std::vector< int > &veto_el, std::map< size_t, std::vector< size_t > > &mu_matches, std::map< size_t, std::vector< size_t > > &el_matches) const
static float bad_val
std::vector< float > *const & els_pfIsolationR03_sumPhotonEt() const
Definition: cfa.cpp:740
quick veto to Loose Most MC is Spring15 with cfA v80 Added mumu_m and elel_m with the dilepton invariant mass Added online lepton pT
std::vector< float > *const & jets_chgHadE() const
Definition: cfa.cpp:6903
const std::vector< std::vector< int > > VRunLumi2015golden(MakeVRunLumi("2015golden"))
std::vector< float > *const & mc_doc_px() const
Definition: cfa.cpp:1908
bool IsSignalMuon(unsigned imu, bool mini=true) const
long double SumDeltaPhi(long double phi_x, long double phi_a, long double phi_b)
std::vector< float > *const & taus_eta() const
Definition: cfa.cpp:6344
static unsigned NumDescendants(size_t index, const std::vector< mc_particle > &parts, const std::vector< size_t > &moms, bool req_chg=false)
Int_t const & hbhefilter_decision() const
Definition: cfa.cpp:1028
static bool FromStatus23(size_t index, const std::vector< mc_particle > &parts, const std::vector< size_t > &moms)
std::vector< float > *const & mc_doc_py() const
Definition: cfa.cpp:1912
std::vector< float > *const & jets_energy() const
Definition: cfa.cpp:7013
static void CountLeptons(const std::vector< mc_particle > &parts, const std::vector< size_t > &moms, unsigned &nleps, unsigned &ntaus, unsigned &ntauleps)
std::vector< float > *const & els_PATpassConversionVeto() const
Definition: cfa.cpp:396
std::vector< float > *const & jets_mass() const
Definition: cfa.cpp:7255
UInt_t const & run() const
Definition: cfa.cpp:6128
std::vector< int > GetJets(const std::vector< int > &VetoEl, const std::vector< int > &VetoMu, double pt_thresh, double eta_thresh) const
bool PassesPVCut() const
Definition: cfa.hpp:12
std::vector< bool > *const & mus_isPF() const
Definition: cfa.cpp:3064
std::vector< float > *const & mc_doc_eta() const
Definition: cfa.cpp:1852
Float_t const & fixedGridRhoFastjetAll() const
Definition: cfa.cpp:952
bool IsVetoMuon(unsigned imu, bool mini=true) const
std::vector< float > *const & mus_tk_phi() const
Definition: cfa.cpp:3540
static float MinVetoLeptonPt
std::vector< float > *const & els_expectedMissingInnerHits() const
Definition: cfa.cpp:584
std::vector< float > *const & mus_pfIsolationR04_sumPUPt() const
Definition: cfa.cpp:3196
std::vector< float > *const & pv_z() const
Definition: cfa.cpp:6088
Int_t const & trackingfailurefilter_decision() const
Definition: cfa.cpp:6532
std::vector< float > *const & jets_btag_inc_secVertexCombined() const
Definition: cfa.cpp:6771
std::vector< float > *const & mc_final_phi() const
Definition: cfa.cpp:2068
std::vector< float > *const & els_sigmaIEtaIEta() const
Definition: cfa.cpp:832
short GetVersion() const
Definition: cfa.cpp:27
std::vector< mc_particle > GetMCParticles() const
std::vector< int > GetMuons(bool doSignal=true, bool mini=true) const
static float MinJetPt
std::vector< float > *const & mc_doc_status() const
Definition: cfa.cpp:1920
std::vector< Jet > GetSubtractedJets(const std::vector< int > &veto_el, const std::vector< int > &veto_mu, double pt_thresh, double eta_thresh) const
std::vector< float > *const & jets_neutral_Mult() const
Definition: cfa.cpp:7376
std::vector< float > *const & mc_doc_phi() const
Definition: cfa.cpp:1900
short Sign(T val)
Definition: utilities.hpp:56
float dR(float eta1, float eta2, float phi1, float phi2)
Definition: utilities.cpp:241
bool IsSignalIdElectron(unsigned iel, bool do_iso=false) const
static size_t ParentTau(size_t index, const std::vector< mc_particle > &parts, const std::vector< size_t > &moms)
std::vector< int > GetElectrons(bool doSignal=true, bool mini=true) const
std::vector< TLorentzVector > jets_corr_p4_
std::vector< float > *const & els_miniso() const
Definition: cfa.cpp:704
std::vector< float > *const & mus_energy() const
Definition: cfa.cpp:2884
std::vector< float > *const & els_eOverPIn() const
Definition: cfa.cpp:556
std::vector< float > *const & els_full5x5_sigmaIetaIeta() const
Definition: cfa.cpp:592
std::vector< float > *const & mus_pfIsolationR04_sumNeutralHadronEt() const
Definition: cfa.cpp:3188
std::vector< float > *const & mc_final_eta() const
Definition: cfa.cpp:2032
long double SignedDeltaPhi(long double phi1, long double phi2)
Definition: utilities.cpp:230
std::vector< float > *const & pv_ndof() const
Definition: cfa.cpp:6064
std::vector< float > *const & mus_eta() const
Definition: cfa.cpp:2892
std::vector< float > *const & isotk_phi() const
Definition: cfa.cpp:1056
std::vector< float > *const & mus_phi() const
Definition: cfa.cpp:3208
const std::vector< std::vector< int > > VRunLumi2015dcs(MakeVRunLumi("2015dcs"))
bool PassesJSONCut(TString type)
std::vector< float > *const & els_caloEnergy() const
Definition: cfa.cpp:420
Int_t const & eebadscfilter_decision() const
Definition: cfa.cpp:348
std::vector< float > *const & els_pfIsolationR03_sumPUPt() const
Definition: cfa.cpp:736
void GetLeadingBJets(const std::vector< int > &good_jets, double pt_cut, double csv_cut, size_t &lead, size_t &sub)
std::vector< float > *const & jets_phi() const
Definition: cfa.cpp:7486
std::vector< float > *const & mc_doc_ggrandmother_id() const
Definition: cfa.cpp:1856
double GetMHT(const std::vector< int > &good_jets, double pt_cut) const
std::vector< float > *const & els_scEta() const
Definition: cfa.cpp:800
virtual void GetEntry(const long entry)
Definition: cfa.cpp:23
bool IsVetoElectron(unsigned iel, bool mini=true) const
std::vector< int > *const & mus_jet_ind() const
Definition: cfa.cpp:3136
std::vector< float > *const & mc_doc_grandmother_id() const
Definition: cfa.cpp:1860
bool AllGoodJets(const std::vector< int > &VetoEl, const std::vector< int > &VetoMu, double pt_thresh, double eta_thresh) const
std::vector< float > *const & mc_doc_pz() const
Definition: cfa.cpp:1916
std::vector< float > *const & mus_isTrackerMuon() const
Definition: cfa.cpp:3084
bool PassesMETCleaningCut() const
UInt_t const & lumiblock() const
Definition: cfa.cpp:1840
static bool IsBrem(size_t index, const std::vector< mc_particle > &parts, const std::vector< size_t > &moms)
std::vector< float > *const & mus_pfIsolationR04_sumChargedHadronPt() const
Definition: cfa.cpp:3180
std::vector< float > *const & mc_doc_mother_id() const
Definition: cfa.cpp:1880
bool IsGoodIsoTrack(unsigned itrk, bool mt_cut) const
const std::vector< TLorentzVector > & jets_corr_p4() const
static bool FromTau(size_t index, const std::vector< mc_particle > &parts, const std::vector< size_t > &moms)
bool IsVetoIdMuon(unsigned iel) const
std::vector< float > *const & mus_tk_numvalPixelhits() const
Definition: cfa.cpp:3532
long double DeltaPhi(long double phi1, long double phi2)
Definition: utilities.cpp:225
std::vector< float > *const & jets_chgEmE() const
Definition: cfa.cpp:6892
std::vector< float > *const & mc_final_ggrandmother_id() const
Definition: cfa.cpp:2036
double GetDeltaPhiMETN(unsigned goodJetI, float otherpt, float othereta, bool useArcsin) const
std::vector< std::vector< int > > MakeVRunLumi(std::string input)
std::vector< float > *const & mus_isPFMuon() const
Definition: cfa.cpp:3068
std::vector< float > *const & isotk_dzpv() const
Definition: cfa.cpp:1044
std::vector< float > *const & mus_isGlobalMuon() const
Definition: cfa.cpp:3052
std::vector< float > *const & isotk_eta() const
Definition: cfa.cpp:1048
std::vector< bool > *const & els_isPF() const
Definition: cfa.cpp:692
std::vector< float > *const & els_PFneutralHadronIsoR03() const
Definition: cfa.cpp:404
bool IsIdMuon(unsigned imu, CutLevel threshold) const
std::vector< float > *const & mus_pfIsolationR04_sumPhotonEt() const
Definition: cfa.cpp:3200
std::vector< float > *const & mc_final_energy() const
Definition: cfa.cpp:2028
std::vector< float > *const & jets_eta() const
Definition: cfa.cpp:7035
std::vector< float > *const & jets_area() const
Definition: cfa.cpp:6716
std::vector< float > *const & mc_doc_charge() const
Definition: cfa.cpp:1844
quick veto to Loose Most MC is Spring15 with cfA v80 Added mumu_m and elel_m with the dilepton invariant mass Added online lepton nb Added nb[t, m, l] variables Changed MJ eta threshold to and removed pT GeV threshold All jets associated with signal leptons are included in don t skip pfcands in the miniso calculation It kills of good non PF electrons
std::vector< float > *const & els_phi() const
Definition: cfa.cpp:744
static unsigned ParentTauDescendants(size_t index, const std::vector< mc_particle > &parts, const std::vector< size_t > &moms)
static bool FromTauLep(size_t index, const std::vector< mc_particle > &parts, const std::vector< size_t > &moms)
float GetElectronIsolation(unsigned iel, bool mini=true) const
static double GetSphericity(const std::vector< TLorentzVector > &vs)
int GetTrueMuon(int index, int &momID, bool &fromW, float &closest_dR, double &mus_mc_pt, double &mus_mc_phi) const
Definition: cfa_8.hpp:11
Int_t const & scrapingVeto_decision() const
Definition: cfa.cpp:6132
double GetDeltaPhiMETN_deltaT(unsigned goodJetI, float otherpt, float othereta) const
std::vector< float > *const & els_tk_phi() const
Definition: cfa.cpp:908
std::vector< float > *const & els_isEE() const
Definition: cfa.cpp:688
std::vector< float > *const & taus_phi() const
Definition: cfa.cpp:6428
std::vector< bool > *const & mus_isLooseMuon() const
Definition: cfa.cpp:3056
std::vector< float > *const & els_isEB() const
Definition: cfa.cpp:684
double GetHT(const std::vector< int > &good_jets, double pt_cut=0.0) const
static bool IsDescendantOf(size_t descendant, size_t ancestor, const std::vector< size_t > &moms)
Int_t const & ecalTPfilter_decision() const
Definition: cfa.cpp:340
std::vector< bool > *const & mus_isTightMuon() const
Definition: cfa.cpp:3080
long double AddInQuadrature(long double x, long double y)
Definition: utilities.cpp:275
bool IsGoodJet(unsigned ijet, double ptThresh, double etaThresh) const
std::vector< float > *const & mus_tk_LayersWithMeasurement() const
Definition: cfa.cpp:3468
static bool FromW(size_t index, const std::vector< mc_particle > &parts, const std::vector< size_t > &moms)