CMS 3D CMS Logo

WPlusJetsEventSelector.cc
Go to the documentation of this file.
1 
4 
5 #include <iostream>
6 
7 using namespace std;
8 
10  : EventSelector(),
11  muonTag_(params.getParameter<edm::InputTag>("muonSrc")),
12  electronTag_(params.getParameter<edm::InputTag>("electronSrc")),
13  jetTag_(params.getParameter<edm::InputTag>("jetSrc")),
14  metTag_(params.getParameter<edm::InputTag>("metSrc")),
15  trigTag_(params.getParameter<edm::InputTag>("trigSrc")),
16  muTrig_(params.getParameter<std::string>("muTrig")),
17  eleTrig_(params.getParameter<std::string>("eleTrig")),
18  pvSelector_(params.getParameter<edm::ParameterSet>("pvSelector")),
19  muonIdTight_(params.getParameter<edm::ParameterSet>("muonIdTight")),
20  electronIdTight_(params.getParameter<edm::ParameterSet>("electronIdTight")),
21  muonIdLoose_(params.getParameter<edm::ParameterSet>("muonIdLoose")),
22  electronIdLoose_(params.getParameter<edm::ParameterSet>("electronIdLoose")),
23  jetIdLoose_(params.getParameter<edm::ParameterSet>("jetIdLoose")),
24  pfjetIdLoose_(params.getParameter<edm::ParameterSet>("pfjetIdLoose")),
25  minJets_(params.getParameter<int>("minJets")),
26  muJetDR_(params.getParameter<double>("muJetDR")),
27  eleJetDR_(params.getParameter<double>("eleJetDR")),
28  muPlusJets_(params.getParameter<bool>("muPlusJets")),
29  ePlusJets_(params.getParameter<bool>("ePlusJets")),
30  muPtMin_(params.getParameter<double>("muPtMin")),
31  muEtaMax_(params.getParameter<double>("muEtaMax")),
32  eleEtMin_(params.getParameter<double>("eleEtMin")),
33  eleEtaMax_(params.getParameter<double>("eleEtaMax")),
34  muPtMinLoose_(params.getParameter<double>("muPtMinLoose")),
35  muEtaMaxLoose_(params.getParameter<double>("muEtaMaxLoose")),
36  eleEtMinLoose_(params.getParameter<double>("eleEtMinLoose")),
37  eleEtaMaxLoose_(params.getParameter<double>("eleEtaMaxLoose")),
38  jetPtMin_(params.getParameter<double>("jetPtMin")),
39  jetEtaMax_(params.getParameter<double>("jetEtaMax")),
40  jetScale_(params.getParameter<double>("jetScale")),
41  metMin_(params.getParameter<double>("metMin")) {
42  // make the bitset
43  push_back("Inclusive");
44  push_back("Trigger");
45  push_back("PV");
46  push_back(">= 1 Lepton");
47  push_back("== 1 Tight Lepton");
48  push_back("== 1 Tight Lepton, Mu Veto");
49  push_back("== 1 Lepton");
50  push_back("MET Cut");
51  push_back("Z Veto");
52  push_back("Conversion Veto");
53  push_back("Cosmic Veto");
54  push_back(">=1 Jets");
55  push_back(">=2 Jets");
56  push_back(">=3 Jets");
57  push_back(">=4 Jets");
58  push_back(">=5 Jets");
59 
60  // turn (almost) everything on by default
61  set("Inclusive");
62  set("Trigger");
63  set("PV");
64  set(">= 1 Lepton");
65  set("== 1 Tight Lepton");
66  set("== 1 Tight Lepton, Mu Veto");
67  set("== 1 Lepton");
68  set("MET Cut");
69  set("Z Veto");
70  set("Conversion Veto");
71  set("Cosmic Veto");
72  set(">=1 Jets", minJets_ >= 1);
73  set(">=2 Jets", minJets_ >= 2);
74  set(">=3 Jets", minJets_ >= 3);
75  set(">=4 Jets", minJets_ >= 4);
76  set(">=5 Jets", minJets_ >= 5);
77 
78  inclusiveIndex_ = index_type(&bits_, std::string("Inclusive"));
79  triggerIndex_ = index_type(&bits_, std::string("Trigger"));
80  pvIndex_ = index_type(&bits_, std::string("PV"));
81  lep1Index_ = index_type(&bits_, std::string(">= 1 Lepton"));
82  lep2Index_ = index_type(&bits_, std::string("== 1 Tight Lepton"));
83  lep3Index_ = index_type(&bits_, std::string("== 1 Tight Lepton, Mu Veto"));
84  lep4Index_ = index_type(&bits_, std::string("== 1 Lepton"));
85  metIndex_ = index_type(&bits_, std::string("MET Cut"));
86  zvetoIndex_ = index_type(&bits_, std::string("Z Veto"));
87  conversionIndex_ = index_type(&bits_, std::string("Conversion Veto"));
88  cosmicIndex_ = index_type(&bits_, std::string("Cosmic Veto"));
89  jet1Index_ = index_type(&bits_, std::string(">=1 Jets"));
90  jet2Index_ = index_type(&bits_, std::string(">=2 Jets"));
91  jet3Index_ = index_type(&bits_, std::string(">=3 Jets"));
92  jet4Index_ = index_type(&bits_, std::string(">=4 Jets"));
93  jet5Index_ = index_type(&bits_, std::string(">=5 Jets"));
94 
95  if (params.exists("cutsToIgnore"))
96  setIgnoredCuts(params.getParameter<std::vector<std::string> >("cutsToIgnore"));
97 
98  retInternal_ = getBitTemplate();
99 }
100 
102  ret.set(false);
103 
104  selectedJets_.clear();
105  cleanedJets_.clear();
106  selectedMuons_.clear();
107  selectedElectrons_.clear();
108  looseMuons_.clear();
109  looseElectrons_.clear();
110  selectedMETs_.clear();
111 
112  passCut(ret, inclusiveIndex_);
113 
114  bool passTrig = false;
115  if (!ignoreCut(triggerIndex_)) {
117  event.getByLabel(trigTag_, triggerEvent);
118 
120 
121  if (trig->wasRun() && trig->wasAccept()) {
122  pat::TriggerPath const* muPath = trig->path(muTrig_);
123 
124  pat::TriggerPath const* elePath = trig->path(eleTrig_);
125 
126  if (muPlusJets_ && muPath != nullptr && muPath->wasAccept()) {
127  passTrig = true;
128  }
129 
130  if (ePlusJets_ && elePath != nullptr && elePath->wasAccept()) {
131  passTrig = true;
132  }
133  }
134  }
135 
136  if (ignoreCut(triggerIndex_) || passTrig) {
137  passCut(ret, triggerIndex_);
138 
139  bool passPV = false;
140 
141  passPV = pvSelector_(event);
142  if (ignoreCut(pvIndex_) || passPV) {
143  passCut(ret, pvIndex_);
144 
145  edm::Handle<vector<pat::Electron> > electronHandle;
146  event.getByLabel(electronTag_, electronHandle);
147 
148  edm::Handle<vector<pat::Muon> > muonHandle;
149  event.getByLabel(muonTag_, muonHandle);
150 
151  edm::Handle<vector<pat::Jet> > jetHandle;
152 
154 
155  edm::Handle<vector<pat::MET> > metHandle;
156  event.getByLabel(metTag_, metHandle);
157 
158  for (std::vector<pat::Electron>::const_iterator electronBegin = electronHandle->begin(),
159  electronEnd = electronHandle->end(),
160  ielectron = electronBegin;
161  ielectron != electronEnd;
162  ++ielectron) {
163  // Tight cuts
164  if (ielectron->et() > eleEtMin_ && fabs(ielectron->eta()) < eleEtaMax_ && electronIdTight_(*ielectron) &&
165  ielectron->electronID("eidRobustTight") > 0) {
166  selectedElectrons_.push_back(
167  reco::ShallowClonePtrCandidate(edm::Ptr<pat::Electron>(electronHandle, ielectron - electronBegin)));
168  } else {
169  // Loose cuts
170  if (ielectron->et() > eleEtMinLoose_ && fabs(ielectron->eta()) < eleEtaMaxLoose_ &&
171  electronIdLoose_(*ielectron)) {
172  looseElectrons_.push_back(
173  reco::ShallowClonePtrCandidate(edm::Ptr<pat::Electron>(electronHandle, ielectron - electronBegin)));
174  }
175  }
176  }
177 
178  for (std::vector<pat::Muon>::const_iterator muonBegin = muonHandle->begin(),
179  muonEnd = muonHandle->end(),
180  imuon = muonBegin;
181  imuon != muonEnd;
182  ++imuon) {
183  if (!imuon->isGlobalMuon())
184  continue;
185 
186  // Tight cuts
187  bool passTight = muonIdTight_(*imuon, event) && imuon->isTrackerMuon();
188  if (imuon->pt() > muPtMin_ && fabs(imuon->eta()) < muEtaMax_ && passTight) {
189  selectedMuons_.push_back(reco::ShallowClonePtrCandidate(edm::Ptr<pat::Muon>(muonHandle, imuon - muonBegin)));
190  } else {
191  // Loose cuts
192  if (imuon->pt() > muPtMinLoose_ && fabs(imuon->eta()) < muEtaMaxLoose_ && muonIdLoose_(*imuon, event)) {
193  looseMuons_.push_back(reco::ShallowClonePtrCandidate(edm::Ptr<pat::Muon>(muonHandle, imuon - muonBegin)));
194  }
195  }
196  }
197 
199  edm::Ptr<pat::MET>(metHandle, 0), metHandle->at(0).charge(), metHandle->at(0).p4());
200 
201  event.getByLabel(jetTag_, jetHandle);
204  for (std::vector<pat::Jet>::const_iterator jetBegin = jetHandle->begin(),
205  jetEnd = jetHandle->end(),
206  ijet = jetBegin;
207  ijet != jetEnd;
208  ++ijet) {
210  edm::Ptr<pat::Jet>(jetHandle, ijet - jetBegin), ijet->charge(), ijet->p4() * jetScale_));
211  bool passJetID = false;
212  if (ijet->isCaloJet() || ijet->isJPTJet())
213  passJetID = jetIdLoose_(*ijet, ret1);
214  else
215  passJetID = pfjetIdLoose_(*ijet, ret2);
216  if (scaledJet.pt() > jetPtMin_ && fabs(scaledJet.eta()) < jetEtaMax_ && passJetID) {
217  selectedJets_.push_back(scaledJet);
218 
219  if (muPlusJets_) {
220  //Remove some jets
221  bool indeltaR = false;
222  for (std::vector<reco::ShallowClonePtrCandidate>::const_iterator muonBegin = selectedMuons_.begin(),
223  muonEnd = selectedMuons_.end(),
224  imuon = muonBegin;
225  imuon != muonEnd;
226  ++imuon) {
227  if (reco::deltaR(imuon->eta(), imuon->phi(), scaledJet.eta(), scaledJet.phi()) < muJetDR_) {
228  indeltaR = true;
229  }
230  }
231  if (!indeltaR) {
232  cleanedJets_.push_back(scaledJet);
233  } // end if jet is not within dR of a muon
234  } // end if mu+jets
235  else {
236  //Remove some jets
237  bool indeltaR = false;
238  for (std::vector<reco::ShallowClonePtrCandidate>::const_iterator electronBegin = selectedElectrons_.begin(),
239  electronEnd = selectedElectrons_.end(),
240  ielectron = electronBegin;
241  ielectron != electronEnd;
242  ++ielectron) {
243  if (reco::deltaR(ielectron->eta(), ielectron->phi(), scaledJet.eta(), scaledJet.phi()) < eleJetDR_) {
244  indeltaR = true;
245  }
246  }
247  if (!indeltaR) {
248  cleanedJets_.push_back(scaledJet);
249  } // end if jet is not within dR of an electron
250  } // end if e+jets
251  } // end if pass id and kin cuts
252  } // end loop over jets
253 
254  int nleptons = 0;
255  if (muPlusJets_)
256  nleptons += selectedMuons_.size();
257 
258  if (ePlusJets_)
259  nleptons += selectedElectrons_.size();
260 
261  if (ignoreCut(lep1Index_) || (nleptons > 0)) {
262  passCut(ret, lep1Index_);
263 
264  if (ignoreCut(lep2Index_) || (nleptons == 1)) {
265  passCut(ret, lep2Index_);
266 
267  bool oneMuon = (selectedMuons_.size() == 1 &&
268  looseMuons_.size() + selectedElectrons_.size() + looseElectrons_.size() == 0);
269  bool oneElectron = (selectedElectrons_.size() == 1 && selectedMuons_.empty());
270 
271  bool oneMuonMuVeto = (selectedMuons_.size() == 1 && looseMuons_.empty());
272 
273  if (ignoreCut(lep3Index_) || ePlusJets_ || (muPlusJets_ && oneMuonMuVeto)) {
274  passCut(ret, lep3Index_);
275 
276  if (ignoreCut(lep4Index_) || ((muPlusJets_ && oneMuon) ^ (ePlusJets_ && oneElectron))) {
277  passCut(ret, lep4Index_);
278 
279  bool metCut = met_.pt() > metMin_;
280  if (ignoreCut(metIndex_) || metCut) {
281  passCut(ret, metIndex_);
282 
283  bool zVeto = true;
284  if (selectedMuons_.size() == 2) {
285  }
286  if (selectedElectrons_.size() == 2) {
287  }
288  if (ignoreCut(zvetoIndex_) || zVeto) {
289  passCut(ret, zvetoIndex_);
290 
291  bool conversionVeto = true;
292  if (ignoreCut(conversionIndex_) || conversionVeto) {
293  passCut(ret, conversionIndex_);
294 
295  bool cosmicVeto = true;
296  if (ignoreCut(cosmicIndex_) || cosmicVeto) {
297  passCut(ret, cosmicIndex_);
298 
299  if (ignoreCut(jet1Index_) || static_cast<int>(cleanedJets_.size()) >= 1) {
300  passCut(ret, jet1Index_);
301  } // end if >=1 tight jets
302 
303  if (ignoreCut(jet2Index_) || static_cast<int>(cleanedJets_.size()) >= 2) {
304  passCut(ret, jet2Index_);
305  } // end if >=2 tight jets
306 
307  if (ignoreCut(jet3Index_) || static_cast<int>(cleanedJets_.size()) >= 3) {
308  passCut(ret, jet3Index_);
309  } // end if >=3 tight jets
310 
311  if (ignoreCut(jet4Index_) || static_cast<int>(cleanedJets_.size()) >= 4) {
312  passCut(ret, jet4Index_);
313  } // end if >=4 tight jets
314 
315  if (ignoreCut(jet5Index_) || static_cast<int>(cleanedJets_.size()) >= 5) {
316  passCut(ret, jet5Index_);
317  } // end if >=5 tight jets
318 
319  } // end if cosmic veto
320 
321  } // end if conversion veto
322 
323  } // end if z veto
324 
325  } // end if met cut
326 
327  } // end if == 1 lepton
328 
329  } // end if == 1 tight lepton with a muon veto separately
330 
331  } // end if == 1 tight lepton
332 
333  } // end if >= 1 lepton
334 
335  } // end if PV
336 
337  } // end if trigger
338 
339  setIgnored(ret);
340 
341  return (bool)ret;
342 }
std::vector< reco::ShallowClonePtrCandidate > selectedElectrons_
ElectronVPlusJetsIDSelectionFunctor electronIdLoose_
ElectronVPlusJetsIDSelectionFunctor electronIdTight_
double pt() const final
transverse momentum
Selector< edm::EventBase > EventSelector
Definition: EventSelector.h:18
PFJetIDSelectionFunctor pfjetIdLoose_
ret
prodAgent to be discontinued
reco::ShallowClonePtrCandidate met_
JetIDSelectionFunctor jetIdLoose_
std::vector< reco::ShallowClonePtrCandidate > selectedJets_
std::vector< reco::ShallowClonePtrCandidate > selectedMuons_
bool operator()(edm::EventBase const &t, pat::strbitset &ret) override
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
Analysis-level trigger event class.
Definition: TriggerEvent.h:39
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:168
bool wasAccept() const
Get the success flag.
Definition: TriggerPath.h:130
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
std::vector< reco::ShallowClonePtrCandidate > looseElectrons_
HLT enums.
std::vector< reco::ShallowClonePtrCandidate > selectedMETs_
std::vector< reco::ShallowClonePtrCandidate > cleanedJets_
MuonVPlusJetsIDSelectionFunctor muonIdLoose_
MuonVPlusJetsIDSelectionFunctor muonIdTight_
double phi() const final
momentum azimuthal angle
Definition: event.py:1
int charge() const final
electric charge
bool passTrig(const float objEta, float objPhi, const trigger::TriggerEvent &trigEvt, const std::string &filterName, const std::string &processName)
Definition: UtilFuncs.h:14
std::vector< reco::ShallowClonePtrCandidate > looseMuons_
double eta() const final
momentum pseudorapidity