CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
analysisSelections.cc
Go to the documentation of this file.
1 #include "Math/VectorUtil.h"
7 
8 namespace HWWFunctions {
9 
10  void doCutFlow(HWW& hww, int i_hyp, EventMonitor::hypo_monitor& monitor, EGammaMvaEleEstimator* egammaMvaEleEstimator, MuonMVAEstimator* muonMVAEstimator){
11 
13  double weight = 1.0;
14 
15  monitor.count(type, "baseline", weight);
16  if(!passCharge(hww, i_hyp)) return;
17  monitor.count(type, "opposite sign", weight);
18  if(!passFullLep(hww, i_hyp, egammaMvaEleEstimator, muonMVAEstimator)) return;
19  monitor.count(type, "full lepton selection", weight);
20  if(!passExtraLeptonVeto(hww, i_hyp, egammaMvaEleEstimator, muonMVAEstimator)) return;
21  monitor.count(type, "extra lepton veto", weight);
22  if(!(hww.evt_pfmet() > 20.0)) return;
23  monitor.count(type, "met > 20 GeV", weight);
24  if(!(hww.hyp_p4().at(i_hyp).mass() > 12.0)) return;
25  monitor.count(type, "mll > 12 GeV", weight);
26  if(!passZVeto(hww, i_hyp)) return;
27  monitor.count(type, "|mll - mZ| > 15 GeV", weight);
28  if(!passMinMet(hww, i_hyp)) return;
29  monitor.count(type, "minMET > 20 GeV", weight);
30  if(!passMinMet40(hww, i_hyp)) return;
31  monitor.count(type, "minMET > 40 GeV for ee/mm", weight);
32  if(!passDPhiDiLepJet(hww, i_hyp)) return;
33  monitor.count(type, "dPhiDiLepJet < 165 dg for ee/mm", weight);
34  if(!passSoftMuonVeto(hww, i_hyp)) return;
35  monitor.count(type, "SoftMuons==0", weight);
36  if(!passTopVeto(hww, i_hyp)) return;
37  monitor.count(type, "top veto", weight);
38  if(hww.hyp_p4().at(i_hyp).pt() <= 45.0) return;
39  monitor.count(type, "ptll > 45 GeV", weight);
40 
41  int njets = numberOfJets(hww, i_hyp);
42  std::vector<JetPair> sortedJets = getJets(hww, i_hyp, 30.0, 4.7, true, false);
43 
44  LorentzVector jet1;
45  LorentzVector jet2;
46  LorentzVector jet3;
47 
48  if(njets==0){
49  monitor.count(type, "njets == 0", weight);
50  if(max(hww.hyp_ll_p4().at(i_hyp).pt(), hww.hyp_lt_p4().at(i_hyp).pt()) < 30) return;
51  monitor.count(type, "max(lep1.pt(),lep2.pt())>30", weight);
52  if(min(hww.hyp_ll_p4().at(i_hyp).pt(), hww.hyp_lt_p4().at(i_hyp).pt()) < 25) return;
53  monitor.count(type, "min(lep1.pt(),lep2.pt())>25", weight);
54  }
55  if(njets==1){
56  monitor.count( type, "njets == 1", weight);
57  }
58  if ( njets==2 || njets==3 ) {
59  monitor.count(type, "njets == 2 or 3", weight);
60  if (fabs(sortedJets[0].first.eta())>=4.7 || fabs(sortedJets[1].first.eta())>=4.7) return;
61  monitor.count(type,"abs(jet1.eta())<4.7 && abs(jet2.eta())<4.7",weight);
62  if (njets==3 && sortedJets[2].first.pt()>30 && ((sortedJets[0].first.eta()-sortedJets[2].first.eta() > 0 && sortedJets[1].first.eta()-sortedJets[2].first.eta() < 0) ||
63  (sortedJets[1].first.eta()-sortedJets[2].first.eta() > 0 && sortedJets[0].first.eta()-sortedJets[2].first.eta() < 0)) ) return;
64  monitor.count(type, "no central jets", weight);
65 
66  }
67 
68  return;
69 
70  }
71 
72  int bestHypothesis(HWW& hww, const std::vector<int>& candidates){
73  int best = -1;
74  for( unsigned int i = 0; i < candidates.size(); ++i ) {
75  unsigned int i_hyp = candidates.at(i);
76  if (best<0){
77  best = i_hyp;
78  continue;
79  }
80  if ( std::max(hww.hyp_lt_p4().at(i_hyp).pt(), hww.hyp_ll_p4().at(i_hyp).pt()) >= //GC add = in case the lepton is the same
81  std::max(hww.hyp_lt_p4().at(best).pt(), hww.hyp_ll_p4().at(best).pt()) &&
82  std::min(hww.hyp_lt_p4().at(i_hyp).pt(), hww.hyp_ll_p4().at(i_hyp).pt()) >=
83  std::min(hww.hyp_lt_p4().at(best).pt(), hww.hyp_ll_p4().at(best).pt()) )
84  best = i_hyp;
85  }
86  return best;
87  }
88 
89  bool passFirstCuts(HWW& hww, int i_hyp){
90 
91  if ( std::min(hww.hyp_lt_p4().at(i_hyp).pt(),hww.hyp_ll_p4().at(i_hyp).pt())<10 ) return false;
92  if ( std::max(hww.hyp_lt_p4().at(i_hyp).pt(),hww.hyp_ll_p4().at(i_hyp).pt())<20 ) return false;
93  if (hww.trks_d0().size()==0) return false;
94  if (!isGoodVertex(hww, 0)) return false;
95  if (nGoodVertex(hww)<1) return false;
96  if (hww.hyp_p4().at(i_hyp).mass2()<0) return false;
97 
98  return true;
99  }
100 
101  bool passCharge(HWW& hww, int i_hyp){
102 
103  if (hww.hyp_lt_id().at(i_hyp)*hww.hyp_ll_id().at(i_hyp)>0) return false;
104  return true;
105  }
106 
107  bool passBaseline(HWW& hww, int i_hyp, EGammaMvaEleEstimator* egammaMvaEleEstimator, MuonMVAEstimator* muonMVAEstimator){
108 
109  if (abs(hww.hyp_lt_id().at(i_hyp)) == 13 && !ww_muBase(hww, hww.hyp_lt_index().at(i_hyp)) ) return false;
110  if (abs(hww.hyp_ll_id().at(i_hyp)) == 13 && !ww_muBase(hww, hww.hyp_ll_index().at(i_hyp)) ) return false;
111  if (abs(hww.hyp_lt_id().at(i_hyp)) == 11 && !ww_elBase(hww, hww.hyp_lt_index().at(i_hyp)) ) return false;
112  if (abs(hww.hyp_ll_id().at(i_hyp)) == 11 && !ww_elBase(hww, hww.hyp_ll_index().at(i_hyp)) ) return false;
113 
114  bool lockToCoreSelectors = false;
115  bool useLHeleId = false;
116  int useMVAeleId = 1;//zero means off, otherwise it's the mva version
117  bool useMVAmuId = false;
118 
119  MuonIDMVA* muonIdMVA = 0;
120  std::vector<Int_t> nullMu; // null identified muons
121  std::vector<Int_t> nullEle; // null identified electrons
122 
123  bool PASSED_LT_FINAL = false;
124  bool PASSED_LT_FO_MU2 = false;
125  bool PASSED_LT_FO_ELEV4 = false;
126  bool PASSED_LL_FINAL = false;
127  bool PASSED_LL_FO_MU2 = false;
128  bool PASSED_LL_FO_ELEV4 = false;
129 
130  if (abs(hww.hyp_lt_id().at(i_hyp)) == 13){
131  unsigned int index = hww.hyp_lt_index().at(i_hyp);
132  if ( goodMuonIsolated(hww, index, lockToCoreSelectors, useMVAmuId, muonIdMVA, muonMVAEstimator, nullMu, nullEle) ) PASSED_LT_FINAL = true;
133  if ( fakableMuon(hww, index,MuFOV2, muonMVAEstimator, nullMu, nullEle) && !goodMuonIsolated(hww, index, lockToCoreSelectors, useMVAmuId, muonIdMVA, muonMVAEstimator, nullMu, nullEle)) PASSED_LT_FO_MU2 = true;
134  }
135  if (abs(hww.hyp_ll_id().at(i_hyp)) == 13){
136  unsigned int index = hww.hyp_ll_index().at(i_hyp);
137  if ( goodMuonIsolated(hww, index, lockToCoreSelectors, useMVAmuId, muonIdMVA, muonMVAEstimator, nullMu, nullEle) ) PASSED_LL_FINAL = true;
138  if ( fakableMuon(hww, index,MuFOV2, muonMVAEstimator, nullMu, nullEle) && !goodMuonIsolated(hww, index, lockToCoreSelectors, useMVAmuId, muonIdMVA, muonMVAEstimator, nullMu, nullEle)) PASSED_LL_FO_MU2 = true;
139  }
140  if (abs(hww.hyp_lt_id().at(i_hyp)) == 11){
141  unsigned int index = hww.hyp_lt_index().at(i_hyp);
142  if ( goodElectronIsolated(hww, index, useLHeleId, useMVAeleId, egammaMvaEleEstimator, lockToCoreSelectors) ) PASSED_LT_FINAL = true;
143  if ( fakableElectron(hww, index,EleFOV4) && !goodElectronIsolated(hww, index, useLHeleId, useMVAeleId, egammaMvaEleEstimator, lockToCoreSelectors)) PASSED_LT_FO_ELEV4 = true;
144  }
145  if (abs(hww.hyp_ll_id().at(i_hyp)) == 11){
146  unsigned int index = hww.hyp_ll_index().at(i_hyp);
147  if ( goodElectronIsolated(hww, index, useLHeleId, useMVAeleId, egammaMvaEleEstimator, lockToCoreSelectors) ) PASSED_LL_FINAL = true;
148  if ( fakableElectron(hww, index,EleFOV4) && !goodElectronIsolated(hww, index, useLHeleId, useMVAeleId, egammaMvaEleEstimator, lockToCoreSelectors)) PASSED_LL_FO_ELEV4 = true;
149  }
150 
151  if( PASSED_LT_FINAL && PASSED_LL_FINAL ) return true;
152  if( PASSED_LT_FINAL && PASSED_LL_FO_MU2 ) return true;
153  if( PASSED_LT_FINAL && PASSED_LL_FO_ELEV4 ) return true;
154  if( PASSED_LL_FINAL && PASSED_LT_FINAL ) return true;
155  if( PASSED_LL_FINAL && PASSED_LT_FO_MU2 ) return true;
156  if( PASSED_LL_FINAL && PASSED_LT_FO_ELEV4 ) return true;
157 
158  return false;
159  }
160 
161  bool passFullLep(HWW& hww, int i_hyp, EGammaMvaEleEstimator* egammaMvaEleEstimator, MuonMVAEstimator* muonMVAEstimator){
162 
163  bool lockToCoreSelectors = false;
164  bool useLHeleId = false;
165  int useMVAeleId = 1;//zero means off, otherwise it's the mva version
166  bool useMVAmuId = false;
167 
168  MuonIDMVA* muonIdMVA = 0;
169  std::vector<Int_t> nullMu; // null identified muons
170  std::vector<Int_t> nullEle; // null identified electrons
171 
172  bool PASSED_LT_FINAL = false;
173  bool PASSED_LL_FINAL = false;
174 
175  if (abs(hww.hyp_lt_id().at(i_hyp)) == 13){
176  unsigned int index = hww.hyp_lt_index().at(i_hyp);
177  if ( goodMuonIsolated(hww, index, lockToCoreSelectors, useMVAmuId, muonIdMVA, muonMVAEstimator, nullMu, nullEle) ) PASSED_LT_FINAL = true;
178  }
179  if (abs(hww.hyp_ll_id().at(i_hyp)) == 13){
180  unsigned int index = hww.hyp_ll_index().at(i_hyp);
181  if ( goodMuonIsolated(hww, index, lockToCoreSelectors, useMVAmuId, muonIdMVA, muonMVAEstimator, nullMu, nullEle) ) PASSED_LL_FINAL = true;
182  }
183  if (abs(hww.hyp_lt_id().at(i_hyp)) == 11){
184  unsigned int index = hww.hyp_lt_index().at(i_hyp);
185  if ( goodElectronIsolated(hww, index, useLHeleId, useMVAeleId, egammaMvaEleEstimator, lockToCoreSelectors) ) PASSED_LT_FINAL = true;
186  }
187  if (abs(hww.hyp_ll_id().at(i_hyp)) == 11){
188  unsigned int index = hww.hyp_ll_index().at(i_hyp);
189  if ( goodElectronIsolated(hww, index, useLHeleId, useMVAeleId, egammaMvaEleEstimator, lockToCoreSelectors) ) PASSED_LL_FINAL = true;
190  }
191 
192  if(PASSED_LT_FINAL && PASSED_LL_FINAL) return true;
193 
194  return false;
195  }
196 
197 
198  bool passExtraLeptonVeto(HWW& hww, int i_hyp, EGammaMvaEleEstimator* egammaMvaEleEstimator, MuonMVAEstimator* muonMVAEstimator){
199 
200  bool useLHeleId = false;
201  int useMVAeleId = 1;//zero means off, otherwise it's the mva version
202  bool useMVAmuId = false;
203 
204  MuonIDMVA* muonIdMVA = 0;
205  std::vector<Int_t> nullMu; // null identified muons
206  std::vector<Int_t> nullEle; // null identified electrons
207 
208  return ( numberOfExtraLeptons(hww, i_hyp,10, useLHeleId, useMVAeleId, egammaMvaEleEstimator, useMVAmuId, muonIdMVA,muonMVAEstimator, nullMu, nullEle) == 0);
209 
210  }
211 
212  bool passZVeto(HWW& hww, int i_hyp){
213 
214  if(hww.hyp_type().at(i_hyp) == 1 || hww.hyp_type().at(i_hyp) == 2) return true; //em or me dileptons have no cut on the z mass
215  if(fabs(hww.hyp_p4().at(i_hyp).mass() - 91.1876) > 15.0) return true;
216  return false;
217 
218  }
219 
220 
221  bool passMinMet(HWW& hww, int i_hyp){
222 
223  double pmet = projectedMet(hww, i_hyp, hww.evt_pfmet(), hww.evt_pfmetPhi());
224  double pTrackMet = projectedMet(hww, i_hyp, hww.trk_met().at(i_hyp), hww.trk_metPhi().at(i_hyp) );
225  return(min(pmet,pTrackMet)>20);
226 
227  }
228 
229  bool passMinMet40(HWW& hww, int i_hyp){
230 
231  //require minMet > 40 GeV for ee and mm hypotheses
232 
233  if(hww.hyp_type().at(i_hyp) == 1) return true;
234  if(hww.hyp_type().at(i_hyp) == 2) return true;
235  double pmet = projectedMet(hww, i_hyp, hww.evt_pfmet(), hww.evt_pfmetPhi());
236  double pTrackMet = projectedMet(hww, i_hyp, hww.trk_met().at(i_hyp), hww.trk_metPhi().at(i_hyp) );
237  return(min(pmet,pTrackMet)>40);
238 
239  }
240 
241 
242  bool passDPhiDiLepJet(HWW& hww, int i_hyp){
243 
244  //pass if em or me hypothesis
245  if(hww.hyp_type().at(i_hyp)==1) return true;
246  if(hww.hyp_type().at(i_hyp)==2) return true;
247 
248  int njets = numberOfJets(hww, i_hyp);
249  std::vector<JetPair> sortedJets = getJets(hww, i_hyp, 15.0, 4.7, true, false);
250 
251  if (sortedJets.size()>0) {
252  if (njets<2 && fabs(ROOT::Math::VectorUtil::DeltaPhi(sortedJets[0].first,hww.hyp_p4().at(i_hyp))) >= (165.*TMath::Pi()/180.)) return false;
253  else if ( (njets>= 2) && (fabs(ROOT::Math::VectorUtil::DeltaPhi( (sortedJets[0].first+sortedJets[1].first),hww.hyp_p4().at(i_hyp))) >= (165.*TMath::Pi()/180.)) ) return false;
254  else return true;
255  }
256  return true;
257 
258  }
259 
260 
261  bool passSoftMuonVeto(HWW& hww, int i_hyp){
262 
263  return(numberOfSoftMuons(hww, i_hyp,true)==0);
264 
265  }
266 
267 
268  bool passTopVeto(HWW& hww, int i_hyp){
269 
270  return(!toptag(hww, i_hyp, 10));
271 
272  }
273 
274 
275  std::vector<JetPair> getJets(HWW& hww, int i_hyp, double etThreshold, double etaMax, bool sortJets, bool btag){
276 
277  std::vector<JetPair> jets;
278  const double vetoCone = 0.3;
279  // bug fix for mva jet id
280  vector <float> fixedpfjetmva_analobj; getGoodMVAs(hww, fixedpfjetmva_analobj, "mvavalue");
281 
282  for ( unsigned int i=0; i < hww.pfjets_p4().size(); ++i) {
283  double jec = hww.pfjets_JEC().at(i);
284 
285  if ( (hww.pfjets_p4().at(i).pt() * jec) < etThreshold ) continue;
286  if ( btag && !defaultBTag(hww, i, jec) ) continue;
287  if ( TMath::Abs(hww.pfjets_p4().at(i).eta()) > etaMax ) continue;
288  if ( (hww.hyp_lt_p4().at(i_hyp).pt() > 0 && TMath::Abs(ROOT::Math::VectorUtil::DeltaR(hww.hyp_lt_p4().at(i_hyp), hww.pfjets_p4().at(i))) < vetoCone) ||
289  (hww.hyp_ll_p4().at(i_hyp).pt() > 0 && TMath::Abs(ROOT::Math::VectorUtil::DeltaR(hww.hyp_ll_p4().at(i_hyp), hww.pfjets_p4().at(i))) < vetoCone) ) continue;
290  if ( !passMVAJetId(hww.pfjets_p4().at(i).pt() * jec, hww.pfjets_p4().at(i).eta(), fixedpfjetmva_analobj[i], 2) ) continue;
291 
292 
293  jets.push_back(JetPair(hww.pfjets_p4().at(i) * jec,i));
294  }
295  if ( sortJets ) std::sort(jets.begin(), jets.end(), comparePt);
296  return jets;
297  }
298 
299 
300 
301  std::vector<JetPair> getDefaultJets(HWW& hww, unsigned int i_hyp, bool btagged){
302  return getJets(hww, i_hyp, 30, 4.7, false, btagged);
303  }
304 
305 
306 
307  unsigned int numberOfJets(HWW& hww, unsigned int i_hyp){
308  return getDefaultJets(hww, i_hyp, false).size();
309  }
310 
311 
312 
313  bool defaultBTag(HWW& hww, unsigned int iJet, float jec) {
314 
315  if ( hww.pfjets_trackCountingHighEffBJetTag().at(iJet) > 2.1) return true;
316  return 0;
317  }
318 
319  Bool_t comparePt(JetPair lv1, JetPair lv2) {
320  return lv1.first.pt() > lv2.first.pt();
321  }
322 
323 
324 
325  // tightness : 2=loose 1=medium 0=tight
326  bool passMVAJetId(double corjetpt, double jeteta, double mvavalue, unsigned int tightness)
327  {
328  if(tightness>2)
329  {
330  edm::LogError("InvalidParameter") << "ERROR : tightness should be 0, 1, or 2. ";
331  return false;
332  }
333 
334  double fMVACut[3][4][4];
335 
336  //Tight Id
337  fMVACut[0][0][0] = 0.5; fMVACut[0][0][1] = 0.6; fMVACut[0][0][2] = 0.6; fMVACut[0][0][3] = 0.9;
338  fMVACut[0][1][0] = -0.2; fMVACut[0][1][1] = 0.2; fMVACut[0][1][2] = 0.2; fMVACut[0][1][3] = 0.6;
339  fMVACut[0][2][0] = 0.3; fMVACut[0][2][1] = 0.4; fMVACut[0][2][2] = 0.7; fMVACut[0][2][3] = 0.8;
340  fMVACut[0][3][0] = 0.5; fMVACut[0][3][1] = 0.4; fMVACut[0][3][2] = 0.8; fMVACut[0][3][3] = 0.9;
341  //Medium id
342  fMVACut[1][0][0] = 0.2; fMVACut[1][0][1] = 0.4; fMVACut[1][0][2] = 0.2; fMVACut[1][0][3] = 0.6;
343  fMVACut[1][1][0] = -0.3; fMVACut[1][1][1] = 0. ; fMVACut[1][1][2] = 0. ; fMVACut[1][1][3] = 0.5;
344  fMVACut[1][2][0] = 0.2; fMVACut[1][2][1] = 0.2; fMVACut[1][2][2] = 0.5; fMVACut[1][2][3] = 0.7;
345  fMVACut[1][3][0] = 0.3; fMVACut[1][3][1] = 0.2; fMVACut[1][3][2] = 0.7; fMVACut[1][3][3] = 0.8;
346  //Loose Id
347  fMVACut[2][0][0] = -0.2; fMVACut[2][0][1] = 0. ; fMVACut[2][0][2] = 0.2; fMVACut[2][0][3] = 0.5;
348  fMVACut[2][1][0] = -0.4; fMVACut[2][1][1] = -0.4; fMVACut[2][1][2] = -0.4; fMVACut[2][1][3] = 0.4;
349  fMVACut[2][2][0] = 0. ; fMVACut[2][2][1] = 0. ; fMVACut[2][2][2] = 0.2; fMVACut[2][2][3] = 0.6;
350  fMVACut[2][3][0] = 0. ; fMVACut[2][3][1] = 0. ; fMVACut[2][3][2] = 0.6; fMVACut[2][3][3] = 0.2;
351 
352  // pT categorization
353  int ptId = 0;
354  if( corjetpt > 10 && corjetpt < 20 ) ptId = 1;
355  if( corjetpt > 20 && corjetpt < 30 ) ptId = 2;
356  if( corjetpt > 30 ) ptId = 3;
357 
358  // eta categorization
359  int etaId = 0;
360  if( fabs(jeteta) > 2.5 && fabs(jeteta) < 2.75 ) etaId = 1;
361  if( fabs(jeteta) > 2.75 && fabs(jeteta) < 3.0 ) etaId = 2;
362  if( fabs(jeteta) > 3.0 && fabs(jeteta) < 5.0 ) etaId = 3;
363 
364  // return
365  if( mvavalue > fMVACut[tightness][ptId][etaId] ) return true;
366  return false;
367  }
368 
369 
370  bool isGoodVertex(HWW& hww, int ivtx) {
371 
372  if (hww.vtxs_isFake().at(ivtx)) return false;
373  if (hww.vtxs_ndof().at(ivtx) <= 4.) return false;
374  if (hww.vtxs_position().at(ivtx).Rho() > 2.0) return false;
375  if (fabs(hww.vtxs_position().at(ivtx).Z()) > 24.0) return false;
376  return true;
377 
378  }
379 
380  unsigned int nGoodVertex(HWW& hww) {
381  unsigned int nVtx = 0;
382  for ( unsigned int i = 0; i < hww.vtxs_sumpt().size(); ++i ){
383  if (!isGoodVertex(hww, i)) continue;
384  nVtx++;
385  }
386  return nVtx;
387  }
388 
390  return 0;
391  }
392 
393  //
394  // Electron ID
395  //
396 
397  bool goodElectronWithoutIsolation(HWW& hww, unsigned int i, bool useLHeleId, int useMVAeleId, EGammaMvaEleEstimator* egammaMvaEleEstimator){
398  return ww_elBase(hww, i) && ww_elId(hww, i, useLHeleId, useMVAeleId, egammaMvaEleEstimator) && ww_eld0PV(hww, i) && ww_eldZPV(hww, i);
399  }
400 
401  bool goodElectronIsolated(HWW& hww, unsigned int i, bool useLHeleId, int useMVAeleId, EGammaMvaEleEstimator* egammaMvaEleEstimator, bool lockToCoreSelectors){
402  bool ptcut = hww.els_p4().at(i).pt() >= 10.0;
403  bool core = ptcut && pass_electronSelection(hww, i, electronSelection_smurfV6);
404  bool internal = ww_elBase(hww, i) && ww_elId(hww, i, useLHeleId, useMVAeleId, egammaMvaEleEstimator) && ww_eld0PV(hww, i) && ww_eldZPV(hww, i) && ww_elIso(hww, i);
405  assert(!lockToCoreSelectors || core==internal);
406  return internal;
407  }
408 
409  bool ElectronFOIdV4(HWW& hww, unsigned int i) {
410 
411  float pt = hww.els_p4().at(i).pt();
412  float etaSC = hww.els_etaSC().at(i);
413 
414  if (fabs(etaSC)<1.479) {
415  if (hww.els_sigmaIEtaIEta().at(i)>0.01 ||
416  fabs(hww.els_dEtaIn().at(i))>0.007 ||
417  fabs(hww.els_dPhiIn().at(i))>0.15 ||
418  hww.els_hOverE().at(i)>0.12 ||
419  hww.els_tkIso().at(i)/pt>0.2 ||
420  (hww.els_ecalIso().at(i) - 1.0)/pt>0.2 ||
421  hww.els_hcalIso().at(i)/pt>0.2 ) return false;
422  } else {
423  if (hww.els_sigmaIEtaIEta().at(i)>0.03 ||
424  fabs(hww.els_dEtaIn().at(i))>0.009 ||
425  fabs(hww.els_dPhiIn().at(i))>0.10 ||
426  hww.els_hOverE().at(i)>0.10 ||
427  hww.els_tkIso().at(i)/pt>0.2 ||
428  hww.els_ecalIso().at(i)/pt>0.2 ||
429  hww.els_hcalIso().at(i)/pt>0.2 ) return false;
430  }
431 
432  // MIT conversion
433  if ( isFromConversionMIT(hww, i) ) return false;
434  // conversion rejection - hit based
435  if ( hww.els_exp_innerlayers().at(i) > 0 ) return false;
436 
437  return true;
438  }
439 
440  bool ElectronFOV4(HWW& hww, unsigned int i){
441  return ww_elBase(hww, i) && ElectronFOIdV4(hww, i) && ww_eld0PV(hww, i) && ww_eldZPV(hww, i);
442  }
443 
444  bool fakableElectron(HWW& hww, unsigned int i, EleFOTypes type){
445  if ( hww.els_p4().at(i).pt() < 10.0 ) return false;
446  switch (type){
450  case EleFOV4: return ElectronFOV4(hww, i);
451  }
452  return false;
453  }
454 
455  //
456  // Muon ID
457  //
458 
459  bool goodMuonTMVA(HWW& hww, MuonIDMVA* mva, unsigned int i) {
460  //Find MVA Bin
461  int subdet = 0;
462  if (fabs(hww.mus_p4().at(i).eta()) < 1.479) subdet = 0;
463  else subdet = 1;
464  int ptBin = 0;
465  if (hww.mus_p4().at(i).pt() > 14.5) ptBin = 1;
466  if (hww.mus_p4().at(i).pt() > 20.0) ptBin = 2;
467 
468  int MVABin = -1;
469  if (subdet == 0 && ptBin == 0) MVABin = 0;
470  if (subdet == 1 && ptBin == 0) MVABin = 1;
471  if (subdet == 0 && ptBin == 1) MVABin = 2;
472  if (subdet == 1 && ptBin == 1) MVABin = 3;
473  if (subdet == 0 && ptBin == 2) MVABin = 4;
474  if (subdet == 1 && ptBin == 2) MVABin = 5;
475 
476  double MVACut = -999.;
477  //same signal eff as cut-based (using V10 - Detector Based Iso)
478  if (MVABin == 0) MVACut = -0.5618;
479  if (MVABin == 1) MVACut = -0.3002;
480  if (MVABin == 2) MVACut = -0.4642;
481  if (MVABin == 3) MVACut = -0.2478;
482  if (MVABin == 4) MVACut = 0.1706;
483  if (MVABin == 5) MVACut = 0.8146;
484 
485  double mvaValue=mva->MVAValue(hww, i, 0);
486 
487  //Isolation
488  double iso03 = 0;
489  iso03 = muonIsoValuePF(hww, i,0,0.3);
490 
491  //Explicitly Apply M2 Denominator Cuts
492  bool pass = true;
493  if (hww.mus_p4().at(i).pt() < 10) pass = false;
494  if (fabs(hww.mus_p4().at(i).eta()) >= 2.4) pass = false;
495 
496  if (! ( (0==0)
497  &&
498  (
499  (((hww.mus_type().at(i)) & (1<<1)) == (1<<1)
500  && hww.mus_gfit_chi2().at(i)/hww.mus_gfit_ndof().at(i) < 10.0
501  && (hww.mus_gfit_validSTAHits().at(i) > 0)
502  && (hww.mus_nmatches().at(i) > 1 )
503  )
504  ||
505  ( ((hww.mus_type().at(i)) & (1<<2)) == (1<<2)
506  && hww.mus_pid_TMLastStationTight().at(i) == 1
507  )
508  )
509  && ((hww.mus_type().at(i)) & (1<<2)) == (1<<2)
510  && hww.mus_validHits().at(i) > 10
511  && (hww.trks_valid_pixelhits().at(hww.mus_trkidx().at(i)) > 0)
512  && iso03 < 0.4
513  && ( hww.mus_ptErr().at(i)/hww.mus_p4().at(i).pt() < 0.1)
514  && hww.mus_trkKink().at(i) < 20.
515  && mvaValue > MVACut
516  )
517  ) {
518  pass = false;
519  }
520  return pass;
521  }
522 
523  bool goodMuonWithoutIsolation(HWW& hww, unsigned int i, bool useMVAmuId, MuonIDMVA *mva,
524  MuonMVAEstimator* muonMVAEstimator, std::vector<Int_t> IdentifiedMu, std::vector<Int_t> IdentifiedEle){
525  return ww_muBase(hww, i) && ww_mud0PV(hww, i) && ww_mudZPV(hww, i, 0.1) && ww_muId(hww, i, useMVAmuId, mva) && passMuonRingsMVAFO(hww, i, muonMVAEstimator, IdentifiedMu, IdentifiedEle);
526  }
527 
528  bool goodMuonIsolated(HWW& hww, unsigned int i, bool lockToCoreSelectors, bool useMVAmuId, MuonIDMVA *mva,
529  MuonMVAEstimator* muonMVAEstimator, std::vector<Int_t> IdentifiedMu, std::vector<Int_t> IdentifiedEle ){
530  bool ptcut = hww.mus_p4().at(i).pt() >= 10.0;
531  bool core = ptcut && muonId(hww, i, NominalSmurfV6);
532  bool internal = ww_muBase(hww, i) && ww_mud0PV(hww, i) && ww_mudZPV(hww, i, 0.1) && ww_muId(hww, i, useMVAmuId, mva) && ww_muIso(hww, i, muonMVAEstimator, IdentifiedMu, IdentifiedEle);
533  assert(!lockToCoreSelectors || core==internal);
534  return internal;
535  }
536 
537 
541 
542  bool ww_elBase(HWW& hww, unsigned int index){
543  if (hww.els_p4().at(index).pt() < 10.0) return false;
544  if (fabs(hww.els_p4().at(index).eta()) > 2.5) return false;
545  return true;
546  }
547 
548 
549  bool ww_elId(HWW& hww, unsigned int index, bool useLHeleId, int useMVAeleId, EGammaMvaEleEstimator* egammaMvaEleEstimator) {
550 
551  if (useLHeleId) {
552  if (hww.els_p4().at(index).pt()>20 && (passLikelihoodId_v2(hww, index,hww.els_lh().at(index),0) & (1<<ELEID_ID))!=(1<<ELEID_ID) ) return false;
553  if (hww.els_p4().at(index).pt()<20 && (passLikelihoodId_v2(hww, index,hww.els_lh().at(index),0) & (1<<ELEID_ID))!=(1<<ELEID_ID) ) return false;
554  }
555  if (useMVAeleId>0){
556  if (!goodElectronTMVA(hww, egammaMvaEleEstimator, useMVAeleId, index)) return false;
557  } else {
558  if (!pass_electronSelection(hww, index, electronSelection_smurfV3_id, false, false) ) return false;
559  }
560 
561  // MIT conversion
562  if ( isFromConversionMIT(hww, index) ) return false;
563  // conversion rejection - hit based
564  if ( hww.els_exp_innerlayers().at(index) > 0 ) return false;
565 
566  return true;
567  }
568 
569  bool ww_eld0(HWW& hww, unsigned int index){
570  return fabs(hww.els_d0corr().at(index)) < 0.02;
571  }
572 
573 
574  bool ww_eld0PV(HWW& hww, unsigned int index){
575  int vtxIndex = primaryVertex();
576  if (vtxIndex<0) return false;
577  double dxyPV = hww.els_d0().at(index)-
578  hww.vtxs_position().at(vtxIndex).x()*sin(hww.els_trk_p4().at(index).phi())+
579  hww.vtxs_position().at(vtxIndex).y()*cos(hww.els_trk_p4().at(index).phi());
580  return fabs(dxyPV) < 0.02;
581  }
582 
583  bool ww_eldZPV(HWW& hww, unsigned int index){
584  int vtxIndex = primaryVertex();
585  if (vtxIndex<0) return false;
586  double dzpv = dzPV(hww.els_vertex_p4().at(index), hww.els_trk_p4().at(index), hww.vtxs_position().at(vtxIndex));
587  return fabs(dzpv)<0.1;
588  }
589 
590  double ww_elIsoVal(HWW& hww, unsigned int index){
592  }
593 
594  bool ww_elIso(HWW& hww, unsigned int index){
595  float pfiso = ww_elIsoVal(hww, index);
596  return pfiso<0.15;
597  }
598 
599 
603 
604  bool ww_muBase(HWW& hww, unsigned int index){
605  if (hww.mus_p4().at(index).pt() < 10.0) return false;
606  if (fabs(hww.mus_p4().at(index).eta()) > 2.4) return false;
607  if (hww.mus_type().at(index) == 8) return false; // not STA
608  return true;
609  }
610 
611  bool ww_mud0(HWW& hww, unsigned int index){
612  return fabs(hww.mus_d0corr().at(index)) < 0.02;
613  }
614 
615  double ww_mud0ValuePV(HWW& hww, unsigned int index){
616  int vtxIndex = primaryVertex();
617  if (vtxIndex<0) return 9999;
618  double dxyPV = hww.mus_d0().at(index)-
619  hww.vtxs_position().at(vtxIndex).x()*sin(hww.mus_trk_p4().at(index).phi())+
620  hww.vtxs_position().at(vtxIndex).y()*cos(hww.mus_trk_p4().at(index).phi());
621  return fabs(dxyPV);
622  }
623 
624  bool ww_mud0PV(HWW& hww, unsigned int index){
625  if ( hww.mus_p4().at(index).pt() < 20. ) return ww_mud0ValuePV(hww, index) < 0.01;
626  return ww_mud0ValuePV(hww, index) < 0.02;
627  }
628 
629  bool ww_mudZPV(HWW& hww, unsigned int index, float cut){
630  int vtxIndex = primaryVertex();
631  if (vtxIndex<0) return false;
632  double dzpv = dzPV(hww.mus_vertex_p4().at(index), hww.mus_trk_p4().at(index), hww.vtxs_position().at(vtxIndex));
633  return fabs(dzpv)<cut;
634  }
635 
636  bool ww_muId(HWW& hww, unsigned int index, bool useMVAmuId, MuonIDMVA *mva){
637  if (useMVAmuId){
638  if (!goodMuonTMVA(hww, mva,index)) return false;
639  return true;
640  }
641 
642  if (((hww.mus_type().at(index)) & (1<<2)) == 0) return false; // tracker muon
643  if (hww.trks_nlayers().at(hww.mus_trkidx().at(index)) < 6) return false; // # of tracker hits
644  if (hww.mus_ptErr().at(index)/hww.mus_trk_p4().at(index).pt()>0.1) return false; // Does pt come from track?
645  if (hww.trks_valid_pixelhits().at(hww.mus_trkidx().at(index))==0) return false;
646  if (hww.mus_trkKink().at(index) > 20.) return false; //kink finder
647  if (!hww.mus_pid_PFMuon().at(index)) return false; // should be a pfmuon
648  // global muon
649  bool goodMuonGlobalMuon = false;
650  if (((hww.mus_type().at(index)) & (1<<1)) == (1<<1)){
651  goodMuonGlobalMuon = true;
652  if (hww.mus_gfit_chi2().at(index)/hww.mus_gfit_ndof().at(index) >= 10) goodMuonGlobalMuon = false; //glb fit chisq
653  if (hww.mus_gfit_validSTAHits().at(index)==0 ) goodMuonGlobalMuon = false;
654  if (hww.mus_nmatches().at(index)<2) goodMuonGlobalMuon = false;
655  }
656  return goodMuonGlobalMuon ||
657  hww.mus_pid_TMLastStationTight().at(index) == 1; // TM id
658  }
659 
660  double ww_muIsoVal(HWW& hww, unsigned int index){
661  double sum = hww.mus_iso03_sumPt().at(index) +
662  hww.mus_iso03_emEt().at(index) +
663  hww.mus_iso03_hadEt().at(index);
664  double pt = hww.mus_p4().at(index).pt();
665  return sum/pt;
666  }
667 
668  bool ww_muIso(HWW& hww, unsigned int index){
669  if (hww.mus_p4().at(index).pt()>20) {
670  if (TMath::Abs(hww.mus_p4().at(index).eta())<1.479)
671  return muonIsoValuePF(hww, index,0,0.3) < 0.13;
672  else
673  return muonIsoValuePF(hww, index,0,0.3) < 0.09;
674  } else {
675  if (TMath::Abs(hww.mus_p4().at(index).eta())<1.479)
676  return muonIsoValuePF(hww, index,0,0.3) < 0.06;
677  else
678  return muonIsoValuePF(hww, index,0,0.3) < 0.05;
679  }
680  }
681 
682  bool ww_muIso(HWW& hww, unsigned int index, MuonMVAEstimator* muonMVAEstimator, std::vector<Int_t> IdentifiedMu, std::vector<Int_t> IdentifiedEle){
683  return passMuonRingsMVA(hww, index, muonMVAEstimator, IdentifiedMu, IdentifiedEle);
684  }
685 
686 
687 
688  bool goodElectronTMVA(HWW& hww, EGammaMvaEleEstimator* egammaMvaEleEstimator, int useMVAeleId, unsigned int i)
689  {
690 
691  float pt = hww.els_p4().at(i).pt();
692  float etaSC = hww.els_etaSC().at(i);
693 
694  //preselection
695  if (fabs(etaSC)<1.479) {
696  if (hww.els_sigmaIEtaIEta().at(i)>0.01 ||
697  fabs(hww.els_dEtaIn().at(i))>0.007 ||
698  fabs(hww.els_dPhiIn().at(i))>0.15 ||
699  hww.els_hOverE().at(i)>0.12 ||
700  hww.els_tkIso().at(i)/pt>0.2 ||
701  TMath::Max(hww.els_ecalIso().at(i) - 1.0, 0.0)/pt>0.20 ||
702  hww.els_hcalIso().at(i)/pt>0.20 ) return 0;
703  } else {
704  if (hww.els_sigmaIEtaIEta().at(i)>0.03 ||
705  fabs(hww.els_dEtaIn().at(i))>0.009 ||
706  fabs(hww.els_dPhiIn().at(i))>0.10 ||
707  hww.els_hOverE().at(i)>0.10 ||
708  hww.els_tkIso().at(i)/pt>0.2 ||
709  hww.els_ecalIso().at(i)/pt>0.20 ||
710  hww.els_hcalIso().at(i)/pt>0.20 ) return 0;
711  }
712 
713  // MIT conversion
714  if ( isFromConversionMIT(hww, i) ) return false;
715  // conversion rejection - hit based
716  if ( hww.els_exp_innerlayers().at(i) > 0 ) return false;
717 
718  double mvavalue = egammaMvaEleEstimator->mvaValue(hww, i,false);
719 
720  if( pt > 20 ) {
721  if( fabs(etaSC)>=1.479 && mvavalue>0.92) return true;
722  if( fabs(etaSC)>=0.8 && fabs(etaSC)<1.479 && mvavalue>0.85) return true;
723  if( fabs(etaSC)<0.8 && mvavalue>0.94) return true;
724  return false;
725  }
726  else {
727  if( fabs(etaSC)>=1.479 && mvavalue>0.62) return true;
728  if( fabs(etaSC)>=0.8 && fabs(etaSC)<1.479 && mvavalue>0.1) return true;
729  if( fabs(etaSC)<0.8 && mvavalue>0.0) return true;
730  return false;
731  }
732  }
733 
734  bool passMuonRingsMVA(HWW& hww, unsigned int mu, MuonMVAEstimator* muonMVAEstimator, std::vector<Int_t> IdentifiedMu, std::vector<Int_t> IdentifiedEle)
735  {
736  double mvavalue = muonMVAEstimator->mvaValueIso(hww, mu, hww.evt_ww_rho(), MuonEffectiveArea::kMuEAFall11MC,
737  IdentifiedEle, IdentifiedMu, false );
738 
739  double pt = hww.mus_trk_p4().at(mu).pt();
740  double eta = hww.mus_trk_p4().at(mu).eta();
741 
742  if( pt>20 ) {
743  if( fabs(eta)>=1.479 && fabs(eta)<2.4 && mvavalue>0.86 ) return true;
744  if( fabs(eta)<1.479 && mvavalue>0.82 ) return true;
745  return false;
746  }
747  else {
748  if( fabs(eta)>=1.479 && fabs(eta)<2.4 && mvavalue>0.82 ) return true;
749  if( fabs(eta)<1.479 && mvavalue>0.86 ) return true;
750  return false;
751  }
752  }
753 
754  bool passMuonRingsMVAFO(HWW& hww, unsigned int mu, MuonMVAEstimator* muonMVAEstimator, std::vector<Int_t> IdentifiedMu, std::vector<Int_t> IdentifiedEle)
755  {
756  double mvavalue = muonMVAEstimator->mvaValueIso(hww, mu, hww.evt_ww_rho(), MuonEffectiveArea::kMuEAFall11MC,
757  IdentifiedEle, IdentifiedMu, false );
758 
759  if( mvavalue>-0.6 ) return true;
760  return false;
761  }
762 
763  bool MuonFOV2(HWW& hww, unsigned int i, MuonMVAEstimator* muonMVAEstimator,
764  std::vector<Int_t> IdentifiedMu, std::vector<Int_t> IdentifiedEle){
765 
766  if (((hww.mus_type().at(i)) & (1<<2)) == 0) return false; // tracker muon
767  if (hww.trks_nlayers().at(hww.mus_trkidx().at(i)) < 6) return false; // # of tracker hits
768  if (hww.mus_ptErr().at(i)/hww.mus_trk_p4().at(i).pt()>0.1) return false; // Does pt come from track?
769  if (hww.trks_valid_pixelhits().at(hww.mus_trkidx().at(i))==0) return false;
770  if (hww.mus_trkKink().at(i) > 20.) return false; //kink finder
771  if (!hww.mus_pid_PFMuon().at(i)) return false; // should be a pfmuon
772  // global muon
773  bool goodMuonGlobalMuon = false;
774  if (((hww.mus_type().at(i)) & (1<<1)) == (1<<1)) {
775  goodMuonGlobalMuon = true;
776  if (hww.mus_gfit_chi2().at(i)/hww.mus_gfit_ndof().at(i) >= 10) goodMuonGlobalMuon = false; //glb fit chisq
777  if (hww.mus_gfit_validSTAHits().at(i)==0 ) goodMuonGlobalMuon = false;
778  if (hww.mus_nmatches().at(i)<2) goodMuonGlobalMuon = false;
779  }
780 
781  return (goodMuonGlobalMuon || hww.mus_pid_TMLastStationTight().at(i) == 1) && // ---> Id
782  ww_muBase(hww, i) &&
783  ww_mud0ValuePV(hww, i)<0.2 &&
784  ww_mudZPV(hww, i) &&
785  passMuonRingsMVAFO(hww, i, muonMVAEstimator, IdentifiedMu, IdentifiedEle);
786  }
787 
788 
789  bool fakableMuon(HWW& hww, unsigned int i, MuFOTypes type,MuonMVAEstimator* muonMVAEstimator,
790  std::vector<Int_t> IdentifiedMu, std::vector<Int_t> IdentifiedEle){
791  if ( hww.mus_p4().at(i).pt() < 10.0 ) return false;
792  switch (type){
793  case MuFOV1: return muonId(hww, i, muonSelectionFO_mu_smurf_10);
794  case MuFOV2: return MuonFOV2(hww, i, muonMVAEstimator, IdentifiedMu, IdentifiedEle);
795  }
796  return false;
797  }
798 
799 
800  std::vector<LeptonPair> getExtraLeptons(HWW& hww, int i_hyp, double minPt, bool useLHeleId, int useMVAeleId, EGammaMvaEleEstimator* egammaMvaEleEstimator, bool useMVAmuId, MuonIDMVA *mumva,
801  MuonMVAEstimator* muonMVAEstimator, std::vector<Int_t> IdentifiedMu, std::vector<Int_t> IdentifiedEle ){
802 
803  std::vector<LeptonPair> leptons;
804  for (int i=0; i < int(hww.mus_charge().size()); ++i) {
805  if ( hww.mus_p4().at(i).pt() < minPt ) continue;
806  if ( TMath::Abs(hww.hyp_lt_id().at(i_hyp)) == 13 && hww.hyp_lt_index().at(i_hyp) == i ) continue;
807  if ( TMath::Abs(hww.hyp_ll_id().at(i_hyp)) == 13 && hww.hyp_ll_index().at(i_hyp) == i ) continue;
808  if ( ! (ww_mud0PV(hww, i) && ww_muId(hww, i, useMVAmuId, mumva) && ww_muIso(hww, i, muonMVAEstimator, IdentifiedMu, IdentifiedEle) &&
809  fabs(hww.mus_p4().at(i).eta()) <2.4) ) continue;
810  leptons.push_back(LeptonPair(true,i));
811  }
812  for (int i=0; i < int(hww.els_charge().size()); ++i) {
813  if ( hww.els_p4().at(i).pt() < minPt ) continue;
814  if ( TMath::Abs(ROOT::Math::VectorUtil::DeltaR(hww.hyp_lt_p4().at(i_hyp),hww.els_p4().at(i)) <0.1) ) continue;
815  if ( TMath::Abs(ROOT::Math::VectorUtil::DeltaR(hww.hyp_ll_p4().at(i_hyp),hww.els_p4().at(i)) <0.1) ) continue;
816  if ( !(ww_elId(hww, i, useLHeleId, useMVAeleId, egammaMvaEleEstimator) && ww_eld0PV(hww, i) && ww_elIso(hww, i) &&
817  fabs(hww.els_p4().at(i).eta()) < 2.5) ) continue;
818  leptons.push_back(LeptonPair(false,i));
819  }
820  return leptons;
821  }
822 
823  unsigned int numberOfExtraLeptons(HWW& hww, int i_hyp, double minPt, bool useLHeleId, int useMVAeleId, EGammaMvaEleEstimator* egammaMvaEleEstimator, bool useMVAmuId, MuonIDMVA *mumva,
824  MuonMVAEstimator* muonMVAEstimator, std::vector<Int_t> IdentifiedMu, std::vector<Int_t> IdentifiedEle){
825  return getExtraLeptons(hww, i_hyp, minPt, useLHeleId, useMVAeleId, egammaMvaEleEstimator, useMVAmuId, mumva,muonMVAEstimator,IdentifiedMu,IdentifiedEle).size();
826  }
827 
828 
829  unsigned int numberOfSoftMuons(HWW& hww, int i_hyp, bool nonisolated)
830  {
831 
832  const std::vector<JetPair> vetojets = std::vector<JetPair>(); //empty, so there is no jet veto
833 
834  unsigned int nMuons = 0;
835  for (int imu=0; imu < int(hww.mus_charge().size()); ++imu) {
836  // quality cuts
837  if ( ((hww.mus_goodmask().at(imu)) & (1<<19)) == 0 ) continue; // TMLastStationAngTight
838  if ( hww.mus_p4().at(imu).pt() < 3 ) continue;
839  if ( ww_mud0ValuePV(hww, imu) > 0.2) continue;
840  if ( ! ww_mudZPV(hww, imu,0.2) ) continue; //newcuts, was 0.1
841  if (hww.trks_nlayers().at(hww.mus_trkidx().at(imu)) < 6) return false; // # of tracker hits
842  if ( TMath::Abs(hww.hyp_lt_id().at(i_hyp)) == 13 && hww.hyp_lt_index().at(i_hyp) == imu ) continue;
843  if ( TMath::Abs(hww.hyp_ll_id().at(i_hyp)) == 13 && hww.hyp_ll_index().at(i_hyp) == imu ) continue;
844  if ( nonisolated && ww_muIsoVal(hww, imu)<0.1 && hww.mus_p4().at(imu).pt()>20 ) continue;
845  bool skip = false;
846  for ( std::vector<JetPair>::const_iterator ijet = vetojets.begin(); ijet != vetojets.end(); ++ijet ){
847  if ( TMath::Abs(ROOT::Math::VectorUtil::DeltaR(ijet->first,hww.mus_p4().at(imu))) < 0.3 ) skip=true;
848  }
849  if ( skip ) continue;
850  ++nMuons;
851  }
852  return nMuons;
853  }
854 
855 
856  double nearestDeltaPhi(HWW& hww, double Phi, int i_hyp)
857  {
858  double tightDPhi = fabs(hww.hyp_lt_p4().at(i_hyp).Phi() - Phi);
859  tightDPhi = std::min(2*TMath::Pi() - tightDPhi, tightDPhi);
860  double looseDPhi = fabs(hww.hyp_ll_p4().at(i_hyp).Phi() - Phi);
861  looseDPhi = std::min(2*TMath::Pi() - looseDPhi, looseDPhi);
862  return TMath::Min(tightDPhi, looseDPhi);
863  }
864 
865 
866  double projectedMet(HWW& hww, unsigned int i_hyp, double met, double phi)
867  {
868  double DeltaPhi = nearestDeltaPhi(hww, phi,i_hyp);
869  if (DeltaPhi < TMath::Pi()/2) return met*TMath::Sin(DeltaPhi);
870  return met;
871  }
872 
873 
874 
875  bool toptag(HWW& hww, int i_hyp, double minPt, std::vector<JetPair> ignoreJets)
876  {
877  const double vetoCone = 0.3;
878  // bug fix for mva jet id
879  vector <float> fixedpfjetmva_analsel; getGoodMVAs(hww, fixedpfjetmva_analsel, "mvavalue");
880 
881  for ( unsigned int i=0; i < hww.pfjets_p4().size(); ++i) {
882 
883  if ( hww.pfjets_p4().at(i).pt() < minPt ) continue;
884  bool ignoreJet = false;
885  for ( std::vector<JetPair>::const_iterator ijet = ignoreJets.begin();
886  ijet != ignoreJets.end(); ++ijet )
887  if ( TMath::Abs(ROOT::Math::VectorUtil::DeltaR(ijet->first,hww.pfjets_p4().at(i))) < vetoCone ) ignoreJet=true;
888  if ( ignoreJet ) continue;
889 
890  if ( TMath::Abs(ROOT::Math::VectorUtil::DeltaR(hww.hyp_lt_p4().at(i_hyp),hww.pfjets_p4().at(i))) < vetoCone ||
891  TMath::Abs(ROOT::Math::VectorUtil::DeltaR(hww.hyp_ll_p4().at(i_hyp),hww.pfjets_p4().at(i))) < vetoCone ) continue;
892 
893  double jec = hww.pfjets_JEC().at(i);
894 
895  if ( !passMVAJetId( hww.pfjets_p4().at(i).pt() * jec, hww.pfjets_p4().at(i).eta(), fixedpfjetmva_analsel[i], 2) ) continue;
896 
897  if ( !defaultBTag(hww, i, jec) ) continue;
898 
899  return true;
900  }
901  return false;
902  }
903 }
static const cuts_t electronSelection_smurfV6
float & evt_pfmetPhi()
Definition: HWW.cc:643
bool ww_mud0(HWW &hww, unsigned int i)
bool ww_muId(HWW &hww, unsigned int i, bool useMVAmuId, MuonIDMVA *mva)
const double Pi
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
std::vector< float > & trk_met()
Definition: HWW.cc:761
bool passMinMet40(HWW &, int)
bool fakableElectron(HWW &hww, unsigned int i, EleFOTypes)
Bool_t comparePt(JetPair lv1, JetPair lv2)
std::vector< int > & mus_pid_PFMuon()
Definition: HWW.cc:539
Double_t mvaValue(Double_t fbrem, Double_t kfchi2, Int_t kfhits, Double_t gsfchi2, Double_t deta, Double_t dphi, Double_t detacalo, Double_t see, Double_t spp, Double_t etawidth, Double_t phiwidth, Double_t e1x5e5x5, Double_t R9, Double_t HoE, Double_t EoP, Double_t IoEmIoP, Double_t eleEoPout, Double_t PreShowerOverRaw, Double_t d0, Double_t ip3d, Double_t eta, Double_t pt, Bool_t printDebug=kFALSE)
double ww_muIsoVal(HWW &hww, unsigned int i)
std::vector< float > & els_tkIso()
Definition: HWW.cc:137
std::vector< int > & els_exp_innerlayers()
Definition: HWW.cc:337
std::vector< int > & hyp_ll_id()
Definition: HWW.cc:585
std::vector< int > & trks_valid_pixelhits()
Definition: HWW.cc:63
bool ww_elId(HWW &hww, unsigned int i, bool useLHeleId, int useMVAeleId, EGammaMvaEleEstimator *egammaMvaEleEstimator)
std::pair< LorentzVector, unsigned int > JetPair
Definition: analysisEnums.h:11
bool passLikelihoodId_v2(HWW &, unsigned int index, float lhValue, int workingPoint)
float & evt_pfmet()
Definition: HWW.cc:639
HypothesisType getHypothesisTypeNew(HWW &, unsigned int i_hyp)
Definition: wwtypes.cc:57
bool passTopVeto(HWW &, int)
EleFOTypes
Definition: analysisEnums.h:25
bool goodElectronIsolated(HWW &hww, unsigned int i, bool useLHeleId, int useMVAeleId, EGammaMvaEleEstimator *egammaMvaEleEstimator, bool lockToCoreSelectors)
std::vector< float > & mus_gfit_chi2()
Definition: HWW.cc:383
bool passCharge(HWW &, int)
bool goodElectronTMVA(HWW &hww, EGammaMvaEleEstimator *egammaMvaEleEstimator, int useMVAeleId, unsigned int i)
std::vector< float > & mus_d0corr()
Definition: HWW.cc:399
unsigned int numberOfSoftMuons(HWW &hww, int i_hyp, bool nonisolated)
bool passBaseline(HWW &, int, EGammaMvaEleEstimator *, MuonMVAEstimator *)
std::vector< LorentzVector > & els_vertex_p4()
Definition: HWW.cc:109
std::vector< float > & els_hOverE()
Definition: HWW.cc:133
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool muonId(HWW &, unsigned int index, SelectionType type)
bool goodElectronWithoutIsolation(HWW &hww, unsigned int i, bool useLHeleId, int useMVAeleId, EGammaMvaEleEstimator *egammaMvaEleEstimator)
std::vector< int > & mus_pid_TMLastStationTight()
Definition: HWW.cc:543
std::vector< float > & els_d0corr()
Definition: HWW.cc:141
bool passMVAJetId(double, double, double, unsigned int)
std::vector< float > & trk_metPhi()
Definition: HWW.cc:765
std::vector< int > & mus_trkidx()
Definition: HWW.cc:535
bool ww_eldZPV(HWW &hww, unsigned int i)
bool goodMuonWithoutIsolation(HWW &hww, unsigned int i, bool useMVAmuId, MuonIDMVA *mva, MuonMVAEstimator *muonMVAEstimator, std::vector< Int_t > IdentifiedMu, std::vector< Int_t > IdentifiedEle)
std::vector< float > & els_d0()
Definition: HWW.cc:145
std::vector< float > & mus_ptErr()
Definition: HWW.cc:391
std::vector< int > & hyp_lt_index()
Definition: HWW.cc:581
bool toptag(HWW &hww, int i_hyp, double minPt, std::vector< JetPair > ignoreJets=std::vector< JetPair >())
std::vector< LeptonPair > getExtraLeptons(HWW &hww, int i_hyp, double minPt, bool useLHeleId, int useMVAeleId, EGammaMvaEleEstimator *egammaMvaEleEstimator, bool useMVAmuId, MuonIDMVA *mumva, MuonMVAEstimator *muonMVAEstimator, std::vector< Int_t > IdentifiedMu, std::vector< Int_t > IdentifiedEle)
std::vector< LorentzVector > & mus_p4()
Definition: HWW.cc:367
bool ElectronFOV4(HWW &hww, unsigned int i)
std::vector< float > & mus_iso03_hadEt()
Definition: HWW.cc:467
std::vector< int > & mus_nmatches()
Definition: HWW.cc:547
T Min(T a, T b)
Definition: MathUtil.h:39
T eta() const
MuFOTypes
Definition: analysisEnums.h:26
bool goodMuonTMVA(HWW &hww, MuonIDMVA *mva, unsigned int i)
bool ww_eld0(HWW &hww, unsigned int i)
std::vector< float > & mus_iso03_sumPt()
Definition: HWW.cc:459
std::vector< float > & trks_d0()
Definition: HWW.cc:55
float electronIsoValuePF2012_FastJetEffArea_HWW(HWW &, int index)
std::vector< int > & mus_gfit_validSTAHits()
Definition: HWW.cc:515
void doCutFlow(HWW &, int, EventMonitor::hypo_monitor &, EGammaMvaEleEstimator *, MuonMVAEstimator *)
std::pair< bool, unsigned int > LeptonPair
Definition: analysisEnums.h:12
bool passMuonRingsMVA(HWW &hww, unsigned int mu, MuonMVAEstimator *muonMVAEstimator, std::vector< Int_t > IdentifiedMu, std::vector< Int_t > IdentifiedEle)
double ww_mud0ValuePV(HWW &hww, unsigned int index)
double projectedMet(HWW &hww, unsigned int i_hyp, double met, double phi)
bool ww_elIso(HWW &hww, unsigned int i)
bool ww_mud0PV(HWW &hww, unsigned int i)
bool defaultBTag(HWW &hww, unsigned int, float)
bool ElectronFOIdV4(HWW &hww, unsigned int i)
std::vector< LorentzVector > & hyp_ll_p4()
Definition: HWW.cc:569
bool passDPhiDiLepJet(HWW &, int)
std::vector< LorentzVector > & mus_trk_p4()
Definition: HWW.cc:371
std::vector< int > & mus_validHits()
Definition: HWW.cc:531
bool fakableMuon(HWW &hww, unsigned int i, MuFOTypes, MuonMVAEstimator *muonMVAEstimator, std::vector< Int_t > IdentifiedMu, std::vector< Int_t > IdentifiedEle)
std::vector< float > & els_ecalIso()
Definition: HWW.cc:261
static const cuts_t electronSelectionFO_el_smurf_v1
std::vector< JetPair > getJets(HWW &hww, int, double, double, bool, bool)
vector< PseudoJet > jets
static const cuts_t electronSelection_smurfV3_id
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< float > & vtxs_ndof()
Definition: HWW.cc:9
T Abs(T a)
Definition: MathUtil.h:49
std::vector< int > & mus_charge()
Definition: HWW.cc:527
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< float > & mus_gfit_ndof()
Definition: HWW.cc:387
std::vector< float > & els_lh()
Definition: HWW.cc:113
int bestHypothesis(HWW &hww, const std::vector< int > &)
unsigned int numberOfJets(HWW &hww, unsigned int)
Double_t mvaValueIso(HWW &, Int_t imu, Double_t rho, MuonEffectiveArea::MuonEffectiveAreaTarget EATarget, std::vector< Int_t > IdentifiedEle, std::vector< Int_t > IdentifiedMu, Bool_t printDebug)
std::vector< LorentzVector > & vtxs_position()
Definition: HWW.cc:5
const int mu
Definition: Constants.h:22
T min(T a, T b)
Definition: MathUtil.h:58
std::vector< int > & hyp_type()
Definition: HWW.cc:601
std::vector< float > & els_hcalIso()
Definition: HWW.cc:265
bool first
Definition: L1TdeRCT.cc:75
std::vector< LorentzVector > & els_p4()
Definition: HWW.cc:101
std::vector< float > & els_etaSC()
Definition: HWW.cc:117
bool ww_elBase(HWW &hww, unsigned int i)
static const cuts_t electronSelectionFO_el_smurf_v3
bool pass_electronSelection(HWW &, const unsigned int index, const cuts_t selectionType, bool applyAlignmentCorrection=false, bool removedEtaCutInEndcap=false, bool useGsfTrack=true)
bool ww_muBase(HWW &hww, unsigned int i)
Definition: HWW.h:12
bool passExtraLeptonVeto(HWW &, int, EGammaMvaEleEstimator *, MuonMVAEstimator *)
tuple btag
Definition: BTagSF.py:17
bool goodMuonIsolated(HWW &hww, unsigned int i, bool lockToCoreSelectors, bool useMVAmuId, MuonIDMVA *mva, MuonMVAEstimator *muonMVAEstimator, std::vector< Int_t > IdentifiedMu, std::vector< Int_t > IdentifiedEle)
bool passSoftMuonVeto(HWW &, int)
T Max(T a, T b)
Definition: MathUtil.h:44
bool ww_mudZPV(HWW &hww, unsigned int i, float cut=0.1)
double muonIsoValuePF(HWW &, unsigned int imu, unsigned int ivtx, float coner=0.4, float minptn=1.0, float dzcut=0.1, int filterId=0)
bool passFirstCuts(HWW &, int)
std::vector< float > & mus_trkKink()
Definition: HWW.cc:395
bool MuonFOV2(HWW &hww, unsigned int i, MuonMVAEstimator *muonMVAEstimator, std::vector< Int_t > IdentifiedMu, std::vector< Int_t > IdentifiedEle)
unsigned int nGoodVertex(HWW &hww)
std::vector< int > & els_charge()
Definition: HWW.cc:329
bool getGoodMVAs(HWW &, std::vector< float > &goodmvas, std::string variable)
std::vector< LorentzVector > & hyp_p4()
Definition: HWW.cc:565
std::vector< float > & pfjets_trackCountingHighEffBJetTag()
Definition: HWW.cc:789
std::vector< float > & mus_d0()
Definition: HWW.cc:403
bool isFromConversionMIT(HWW &, const unsigned int index)
double nearestDeltaPhi(HWW &hww, double Phi, int i_hyp)
double ww_elIsoVal(HWW &hww, unsigned int i)
std::vector< int > & hyp_lt_id()
Definition: HWW.cc:589
bool passMuonRingsMVAFO(HWW &hww, unsigned int mu, MuonMVAEstimator *muonMVAEstimator, std::vector< Int_t > IdentifiedMu, std::vector< Int_t > IdentifiedEle)
std::vector< float > & els_dPhiIn()
Definition: HWW.cc:129
double dzPV(const LorentzVector &vtx, const LorentzVector &p4, const LorentzVector &pv)
std::vector< LorentzVector > & hyp_lt_p4()
Definition: HWW.cc:573
std::vector< int > & vtxs_isFake()
Definition: HWW.cc:17
std::vector< float > & pfjets_JEC()
Definition: HWW.cc:781
std::vector< float > & els_dEtaIn()
Definition: HWW.cc:125
bool ww_muIso(HWW &hww, unsigned int i)
bool passFullLep(HWW &, int, EGammaMvaEleEstimator *, MuonMVAEstimator *)
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< float > > LorentzVector
Definition: pfjetMVAtools.h:10
std::vector< int > & trks_nlayers()
Definition: HWW.cc:59
float & evt_ww_rho()
Definition: HWW.cc:627
std::vector< LorentzVector > & pfjets_p4()
Definition: HWW.cc:769
volatile std::atomic< bool > shutdown_flag false
int weight
Definition: histoStyle.py:50
void count(HypothesisType type, const char *name, double weight=1.0)
Definition: monitor.cc:11
std::vector< LorentzVector > & mus_vertex_p4()
Definition: HWW.cc:375
std::vector< JetPair > getDefaultJets(HWW &hww, unsigned int, bool)
std::vector< float > & els_sigmaIEtaIEta()
Definition: HWW.cc:121
Double_t MVAValue(HWW &, const unsigned int mu, const unsigned int vertex)
Definition: MuonIDMVA.cc:211
bool ww_eld0PV(HWW &hww, unsigned int i)
std::vector< int > & mus_goodmask()
Definition: HWW.cc:551
unsigned int numberOfExtraLeptons(HWW &hww, int i_hyp, double minPt, bool useLHeleId, int useMVAeleId, EGammaMvaEleEstimator *egammaMvaEleEstimator, bool useMVAmuId, MuonIDMVA *mumva, MuonMVAEstimator *muonMVAEstimator, std::vector< Int_t > IdentifiedMu, std::vector< Int_t > IdentifiedEle)
static const cuts_t electronSelectionFO_el_smurf_v2
std::vector< float > & vtxs_sumpt()
Definition: HWW.cc:13
std::vector< float > & mus_iso03_emEt()
Definition: HWW.cc:463
std::vector< LorentzVector > & els_trk_p4()
Definition: HWW.cc:105
bool passMinMet(HWW &, int)
std::vector< int > & mus_type()
Definition: HWW.cc:555
bool passZVeto(HWW &, int)
bool isGoodVertex(HWW &hww, int)
Definition: DDAxes.h:10
std::vector< int > & hyp_ll_index()
Definition: HWW.cc:577