susy_cfa  b611ccad937ea179f86a1f5663960264616c0a20
phys_objects.hpp
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 #ifndef H_PHYS_OBJECTS
5 #define H_PHYS_OBJECTS
6 
7 #include <cstdlib>
8 
9 #include <iostream>
10 #include <vector>
11 #include <string>
12 #include <limits>
13 #include <map>
14 
15 #include "TLorentzVector.h"
16 #include "TString.h"
17 #include "TMath.h"
18 
19 #include "cfa.hpp"
20 #include "pdtlund.hpp"
21 #include "in_json_2012.hpp"
22 
23 struct Jet{
24  TLorentzVector p4;
25  float csv;
26  int id;
27  int nleps;
28  TLorentzVector p4sub;
29  float mindr;
30 };
31 
32 namespace particleId {
33  enum leptonType {
34  X=0,
36  muon=3,
39  };
40 }
41 
42 struct mc_particle{
43  mc_particle(const TLorentzVector &momentum,
44  float charge,
45  int id, int mom, int gmom, int ggmom,
46  int status):
47  momentum_(momentum),
48  charge_(TMath::Nint(3.*charge)),
49  id_(id),
50  mom_(mom),
51  gmom_(gmom),
52  ggmom_(ggmom),
53  status_(status){
54  }
55 
56  TLorentzVector momentum_;
57  float charge_;
58  int id_, mom_, gmom_, ggmom_;
59  int status_;
60 };
61 
63 
64 class phys_objects : public cfa{
65 public:
66  explicit phys_objects(const std::string &filename, bool is_8TeV=false);
67  virtual ~phys_objects();
68 
69  enum CutLevel{kVeto, kLoose, kMedium, kTight};
70 
71  virtual void GetEntry(const long entry);
72  //Triggers
73  bool GetTriggerInfo(std::vector<TString> &trig_names, std::vector<bool> &trig_dec,
74  std::vector<float> &trig_prescale);
75  std::vector<TString> yes_trig, no_trig;
76  bool PassesJSONCut(TString type);
77  // Muons
78  std::vector<int> GetMuons(bool doSignal = true, bool mini = true) const;
79 
80  bool IsSignalMuon(unsigned imu, bool mini = true) const;
81  bool IsVetoMuon(unsigned imu, bool mini = true) const;
82  bool IsSignalIdMuon(unsigned iel) const;
83  bool IsVetoIdMuon(unsigned iel) const;
84 
85  bool IsIdMuon(unsigned imu, CutLevel threshold) const;
86 
87  float GetMuonIsolation(unsigned imu, bool mini=true) const;
88 
89  // Electrons
90  std::vector<int> GetElectrons(bool doSignal = true, bool mini = true) const;
91 
92  bool IsSignalElectron(unsigned iel, bool mini = true) const;
93  bool IsVetoElectron(unsigned iel, bool mini = true) const;
94  bool IsSignalIdElectron(unsigned iel, bool do_iso=false) const;
95  bool IsVetoIdElectron(unsigned iel, bool do_iso=false) const;
96 
97  bool IsIdElectron(unsigned iel, CutLevel threshold, bool do_iso=false) const;
98 
99  float GetElectronIsolation(unsigned iel, bool mini=true) const;
100  float GetEffectiveArea(float SCEta, bool isMC) const;
101 
102  // Leptons
103  static int GetMom(float id, float mom, float gmom, float ggmom,
104  bool &fromW);
105  void GetBestLepton(bool &is_muon, size_t &index);
106  double GetMiniIsolation(int particle_type, int ilep, double riso_min = 0.05, double riso_max = 0.2,
107  bool add_ph = true, bool add_nh = true, bool add_ch = true,
108  bool use_pf_weight = false, double kt_scale = 10.) const;
109 
110  // Taus
111  bool PassPhys14TauID(const int itau, const bool againstEMu, const bool mt_cut) const;
112  // Tracks
113  bool IsGoodIsoTrack(unsigned itrk, bool mt_cut) const;
114 
115  // MET
116  float met_corr() const;
117  float met_phi_corr() const;
118 
119  // Jets
120  std::vector<int> GetJets(const std::vector<int> &VetoEl, const std::vector<int> &VetoMu,
121  double pt_thresh, double eta_thresh) const;
122  bool AllGoodJets(const std::vector<int> &VetoEl, const std::vector<int> &VetoMu,
123  double pt_thresh, double eta_thresh) const;
124  void GetMatchedLeptons(const std::vector<int> &veto_mu,
125  const std::vector<int> &veto_el,
126  std::map<size_t,std::vector<size_t> > &mu_matches,
127  std::map<size_t,std::vector<size_t> > &el_matches) const;
128 
129  std::vector<Jet> GetSubtractedJets(const std::vector<int> &veto_el, const std::vector<int> &veto_mu,
130  double pt_thresh, double eta_thresh) const;
131  bool IsGoodJet(unsigned ijet, double ptThresh, double etaThresh) const;
132  bool IsBasicJet(unsigned ijet) const;
133  const std::vector<TLorentzVector> & jets_corr_p4() const;
134  std::vector<TLorentzVector> & jets_corr_p4();
135 
136  // Truth matching
137  int GetTrueElectron(int index, int &momID, bool &fromW, float &closest_dR, double &els_mc_pt, double &els_mc_phi) const;
138  int GetTrueMuon(int index, int &momID, bool &fromW, float &closest_dR, double &mus_mc_pt, double &mus_mc_phi) const;
139  int GetTrueParticle(float RecPt, float RecEta, float RecPhi, float &closest_dR, int ID) const;
140  std::vector<mc_particle> GetMCParticles() const;
141  size_t MatchCandToStatus1(size_t icand,
142  const std::vector<mc_particle> &parts) const;
143  static size_t GetMom(size_t index, const std::vector<mc_particle> &parts);
144  static std::vector<size_t> GetMoms(const std::vector<mc_particle> &parts);
145  static bool IsBrem(size_t index,
146  const std::vector<mc_particle> &parts,
147  const std::vector<size_t> &moms);
148  static bool FromStatus23(size_t index,
149  const std::vector<mc_particle> &parts,
150  const std::vector<size_t> &moms);
151  static bool FromTop(size_t index,
152  const std::vector<mc_particle> &parts,
153  const std::vector<size_t> &moms);
154  static bool FromW(size_t index,
155  const std::vector<mc_particle> &parts,
156  const std::vector<size_t> &moms);
157  static bool FromTau(size_t index,
158  const std::vector<mc_particle> &parts,
159  const std::vector<size_t> &moms);
160  static bool FromTauLep(size_t index,
161  const std::vector<mc_particle> &parts,
162  const std::vector<size_t> &moms);
163  static unsigned NumChildren(size_t index,
164  const std::vector<mc_particle> &parts,
165  const std::vector<size_t> &moms,
166  bool req_chg=false);
167  static unsigned NumDescendants(size_t index,
168  const std::vector<mc_particle> &parts,
169  const std::vector<size_t> &moms,
170  bool req_chg=false);
171  static bool IsDescendantOf(size_t descendant, size_t ancestor,
172  const std::vector<size_t> &moms);
173  static unsigned ParentTauDescendants(size_t index,
174  const std::vector<mc_particle> &parts,
175  const std::vector<size_t> &moms);
176  static size_t ParentW(size_t index,
177  const std::vector<mc_particle> &parts,
178  const std::vector<size_t> &moms);
179  static size_t ParentTau(size_t index,
180  const std::vector<mc_particle> &parts,
181  const std::vector<size_t> &moms);
182  static void CountLeptons(const std::vector<mc_particle> &parts,
183  const std::vector<size_t> &moms,
184  unsigned &nleps,
185  unsigned &ntaus,
186  unsigned &ntauleps);
187 
188  // Event cleaning
189  bool PassesMETCleaningCut() const;
190  bool PassesPVCut() const;
191  double getDZ(double vx, double vy, double vz, double px, double py, double pz, int firstGoodVertex) const;
192 
193  // Event variables
194  long double SumDeltaPhi(long double phi_x, long double phi_a, long double phi_b);
195  double GetDeltaPhiMETN(unsigned goodJetI, float otherpt, float othereta, bool useArcsin) const;
196  double GetDeltaPhiMETN_deltaT(unsigned goodJetI, float otherpt, float othereta) const;
197  double GetMinDeltaPhiMETN(unsigned maxjets, float mainpt, float maineta,
198  float otherpt, float othereta, bool useArcsin) const;
199  double GetHT(const std::vector<int> &good_jets, double pt_cut=0.0) const;
200  double GetMHT(const std::vector<int> &good_jets, double pt_cut) const;
201  size_t GetNumJets(const std::vector<int> &good_jets,
202  double pt_cut=0.0,
203  double csv_cut=-std::numeric_limits<float>::max()) const;
204  static double GetSphericity(const std::vector<TLorentzVector> &vs);
205 
206  // Utilities
207  bool isData() const;
208  bool hasPFMatch(int index, particleId::leptonType type, int &pfIdx) const;
209 
210  void GetLeadingBJets(const std::vector<int> &good_jets,
211  double pt_cut, double csv_cut,
212  size_t &lead, size_t &sub);
213 
214  static float MinJetPt, MinRA2bJetPt, MinSignalLeptonPt, MinVetoLeptonPt, MinTrackPt;
215  static float bad_val;
216 
217 
218  template<class T>
219  T chooseVal(CutLevel threshold, T valVeto, T valLoose, T valMedium, T valTight) const{
220  switch(threshold){
221  default:
222  case kVeto:
223  return valVeto;
224  case kLoose:
225  return valLoose;
226  case kMedium:
227  return valMedium;
228  case kTight:
229  return valTight;
230  }
231  return valVeto;
232  }
233 
234 
235 private:
237  mutable std::vector<TLorentzVector> jets_corr_p4_;
238  mutable bool set_jets_;
239  mutable float met_corr_, met_phi_corr_;
240 
241  void CorrectJets() const;
242 };
243 
244 #endif
std::vector< TString > yes_trig
int id
FactorizedJetCorrector * jet_corrector_
float mindr
TLorentzVector momentum_
TLorentzVector p4
mc_particle(const TLorentzVector &momentum, float charge, int id, int mom, int gmom, int ggmom, int status)
T chooseVal(CutLevel threshold, T valVeto, T valLoose, T valMedium, T valTight) const
static float bad_val
TLorentzVector p4sub
Definition: cfa.hpp:12
static float MinVetoLeptonPt
std::vector< TLorentzVector > jets_corr_p4_
string filename
Definition: data_combine.py:22
float csv
int nleps