CMS 3D CMS Logo

ttbarEventSelector.cc
Go to the documentation of this file.
6 
9 #include "TH1.h"
11 
12 using namespace std;
13 using namespace edm;
14 
16  : electronTag_(ps.getUntrackedParameter<edm::InputTag>("electronInputTag", edm::InputTag("gedGsfElectrons"))),
17  jetsTag_(ps.getUntrackedParameter<edm::InputTag>("jetsInputTag", edm::InputTag("ak4PFJetsCHS"))),
18  bjetsTag_(ps.getUntrackedParameter<edm::InputTag>("bjetsInputTag", edm::InputTag("pfDeepCSVJetTags", "probb"))),
19  pfmetTag_(ps.getUntrackedParameter<edm::InputTag>("pfmetTag", edm::InputTag("pfMet"))),
20  muonTag_(ps.getUntrackedParameter<edm::InputTag>("muonInputTag", edm::InputTag("muons"))),
21  bsTag_(ps.getUntrackedParameter<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"))),
22  electronToken_(consumes<reco::GsfElectronCollection>(electronTag_)),
23  jetsToken_(consumes<reco::PFJetCollection>(jetsTag_)),
24  bjetsToken_(consumes<reco::JetTagCollection>(bjetsTag_)),
25  pfmetToken_(consumes<reco::PFMETCollection>(pfmetTag_)),
26  muonToken_(consumes<reco::MuonCollection>(muonTag_)),
27  bsToken_(consumes<reco::BeamSpot>(bsTag_)),
28  maxEtaEle_(ps.getUntrackedParameter<double>("maxEta", 2.4)),
29  maxEtaMu_(ps.getUntrackedParameter<double>("maxEta", 2.4)),
30  minPt_(ps.getUntrackedParameter<double>("minPt", 5)),
31 
32  // for Electron only
33  maxDeltaPhiInEB_(ps.getUntrackedParameter<double>("maxDeltaPhiInEB", .15)),
34  maxDeltaEtaInEB_(ps.getUntrackedParameter<double>("maxDeltaEtaInEB", .007)),
35  maxHOEEB_(ps.getUntrackedParameter<double>("maxHOEEB", .12)),
36  maxSigmaiEiEEB_(ps.getUntrackedParameter<double>("maxSigmaiEiEEB", .01)),
37  maxDeltaPhiInEE_(ps.getUntrackedParameter<double>("maxDeltaPhiInEE", .1)),
38  maxDeltaEtaInEE_(ps.getUntrackedParameter<double>("maxDeltaEtaInEE", .009)),
39  maxHOEEE_(ps.getUntrackedParameter<double>("maxHOEEB_", .10)),
40  maxSigmaiEiEEE_(ps.getUntrackedParameter<double>("maxSigmaiEiEEE", .03)),
41 
42  // for Muon only
43  minChambers_(ps.getUntrackedParameter<uint32_t>("minChambers", 2)),
44  minMatches_(ps.getUntrackedParameter<uint32_t>("minMatches", 2)),
45  minMatchedStations_(ps.getUntrackedParameter<double>("minMatchedStations", 2)),
46 
47  // for Jets only
48  maxEtaHighest_Jets_(ps.getUntrackedParameter<double>("maxEtaHighest_Jets", 2.4)),
49  maxEta_Jets_(ps.getUntrackedParameter<double>("maxEta_Jets", 3.0)),
50 
51  // for b-tag only
52  btagFactor_(ps.getUntrackedParameter<double>("btagFactor", 0.6)),
53 
54  maxNormChi2_(ps.getUntrackedParameter<double>("maxNormChi2", 10)),
55  maxD0_(ps.getUntrackedParameter<double>("maxD0", 0.02)),
56  maxDz_(ps.getUntrackedParameter<double>("maxDz", 20.)),
57  minPixelHits_(ps.getUntrackedParameter<uint32_t>("minPixelHits", 1)),
58  minStripHits_(ps.getUntrackedParameter<uint32_t>("minStripHits", 8)),
59  maxIsoEle_(ps.getUntrackedParameter<double>("maxIso", 0.5)),
60  maxIsoMu_(ps.getUntrackedParameter<double>("maxIso", 0.3)),
61  minPtHighestMu_(ps.getUntrackedParameter<double>("minPtHighestMu", 24)),
62  minPtHighestEle_(ps.getUntrackedParameter<double>("minPtHighestEle", 32)),
63  minPtHighest_Jets_(ps.getUntrackedParameter<double>("minPtHighest_Jets", 30)),
64  minPt_Jets_(ps.getUntrackedParameter<double>("minPt_Jets", 20)),
65  minInvMass_(ps.getUntrackedParameter<double>("minInvMass", 140)),
66  maxInvMass_(ps.getUntrackedParameter<double>("maxInvMass", 200)),
67  minMet_(ps.getUntrackedParameter<double>("minMet", 50)),
68  maxMet_(ps.getUntrackedParameter<double>("maxMet", 80)),
69  minWmass_(ps.getUntrackedParameter<double>("minWmass", 50)),
70  maxWmass_(ps.getUntrackedParameter<double>("maxWmass", 130)) {}
71 
73  // beamspot
75  iEvent.getByToken(bsToken_, beamSpot);
76 
77  int le = 0, lm = 0, lj = 0, lbj = 0;
78 
79  // Read Electron Collection
81  iEvent.getByToken(electronToken_, electronColl);
82  std::vector<TLorentzVector> list_ele;
83  std::vector<int> chrgeList_ele;
84 
85  if (electronColl.isValid()) {
86  for (auto const& ele : *electronColl) {
87  if (!ele.ecalDriven())
88  continue;
89  if (ele.pt() < minPt_)
90  continue;
91  // set a max Eta cut
92  if (!(ele.isEB() || ele.isEE()))
93  continue;
94 
95  double hOverE = ele.hadronicOverEm();
96  double sigmaee = ele.sigmaIetaIeta();
97  double deltaPhiIn = ele.deltaPhiSuperClusterTrackAtVtx();
98  double deltaEtaIn = ele.deltaEtaSuperClusterTrackAtVtx();
99 
100  // separate cut for barrel and endcap
101  if (ele.isEB()) {
102  if (fabs(deltaPhiIn) >= maxDeltaPhiInEB_ && fabs(deltaEtaIn) >= maxDeltaEtaInEB_ && hOverE >= maxHOEEB_ &&
103  sigmaee >= maxSigmaiEiEEB_)
104  continue;
105  } else if (ele.isEE()) {
106  if (fabs(deltaPhiIn) >= maxDeltaPhiInEE_ && fabs(deltaEtaIn) >= maxDeltaEtaInEE_ && hOverE >= maxHOEEE_ &&
107  sigmaee >= maxSigmaiEiEEE_)
108  continue;
109  }
110 
111  reco::GsfTrackRef trk = ele.gsfTrack();
112  if (!trk.isNonnull())
113  continue; // only electrons with tracks
114  double chi2 = trk->chi2();
115  double ndof = trk->ndof();
116  double chbyndof = (ndof > 0) ? chi2 / ndof : 0;
117  if (chbyndof >= maxNormChi2_)
118  continue;
119 
120  double trkd0 = trk->d0();
121  if (beamSpot.isValid()) {
122  trkd0 = -(trk->dxy(beamSpot->position()));
123  } else {
124  edm::LogError("ElectronSelector") << "Error >> Failed to get BeamSpot for label: " << bsTag_;
125  }
126  if (std::fabs(trkd0) >= maxD0_)
127  continue;
128 
129  const reco::HitPattern& hitp = trk->hitPattern();
130  int nPixelHits = hitp.numberOfValidPixelHits();
131  if (nPixelHits < minPixelHits_)
132  continue;
133 
134  int nStripHits = hitp.numberOfValidStripHits();
135  if (nStripHits < minStripHits_)
136  continue;
137 
138  // PF Isolation
139  reco::GsfElectron::PflowIsolationVariables pfIso = ele.pfIsolationVariables();
140  const float eiso =
141  pfIso.sumChargedHadronPt + std::max(0.0, pfIso.sumNeutralHadronEt + pfIso.sumPhotonEt - 0.5 * pfIso.sumPUPt);
142  if (eiso > maxIsoEle_ * ele.pt())
143  continue;
144 
145  TLorentzVector lv_ele;
146  lv_ele.SetPtEtaPhiE(ele.pt(), ele.eta(), ele.phi(), ele.energy());
147  list_ele.push_back(lv_ele);
148  chrgeList_ele.push_back(ele.charge());
149  }
150  le = list_ele.size();
151  } else {
152  edm::LogError("ElectronSelector") << "Error >> Failed to get ElectronCollection for label: " << electronTag_;
153  }
154 
155  // Read Muon Collection
157  iEvent.getByToken(muonToken_, muonColl);
158 
159  std::vector<TLorentzVector> list_mu;
160  std::vector<int> chrgeList_mu;
161  if (muonColl.isValid()) {
162  for (auto const& mu : *muonColl) {
163  if (!mu.isGlobalMuon())
164  continue;
165  if (!mu.isPFMuon())
166  continue;
167  if (std::fabs(mu.eta()) >= maxEtaMu_)
168  continue;
169  if (mu.pt() < minPt_)
170  continue;
171 
172  reco::TrackRef gtk = mu.globalTrack();
173  double chi2 = gtk->chi2();
174  double ndof = gtk->ndof();
175  double chbyndof = (ndof > 0) ? chi2 / ndof : 0;
176  if (chbyndof >= maxNormChi2_)
177  continue;
178 
179  reco::TrackRef tk = mu.innerTrack();
180  if (beamSpot.isValid()) {
181  double trkd0 = -(tk->dxy(beamSpot->position()));
182  if (std::fabs(trkd0) >= maxD0_)
183  continue;
184  double trkdz = tk->dz(beamSpot->position());
185  if (std::fabs(trkdz) >= maxDz_)
186  continue;
187  } else {
188  edm::LogError("MuonSelector") << "Error >> Failed to get BeamSpot for label: " << bsTag_;
189  }
190 
191  const reco::HitPattern& hitp = gtk->hitPattern();
193  continue;
195  continue;
196 
197  // Hits/section in the muon chamber
198  if (mu.numberOfChambers() < minChambers_)
199  continue;
200  if (mu.numberOfMatches() < minMatches_)
201  continue;
202  if (mu.numberOfMatchedStations() < minMatchedStations_)
203  continue;
205  continue;
206 
207  // PF Isolation
208  const reco::MuonPFIsolation& pfIso04 = mu.pfIsolationR04();
209  double absiso = pfIso04.sumChargedHadronPt +
210  std::max(0.0, pfIso04.sumNeutralHadronEt + pfIso04.sumPhotonEt - 0.5 * pfIso04.sumPUPt);
211  if (absiso > maxIsoMu_ * mu.pt())
212  continue;
213 
214  TLorentzVector lv_mu;
215  lv_mu.SetPtEtaPhiE(mu.pt(), mu.eta(), mu.phi(), mu.energy());
216  list_mu.push_back(lv_mu);
217  chrgeList_mu.push_back(mu.charge());
218  }
219  lm = list_mu.size();
220  } else {
221  edm::LogError("MuonSelector") << "Error >> Failed to get MuonCollection for label: " << muonTag_;
222  return false;
223  }
224 
225  // for Track jet collections
227  iEvent.getByToken(jetsToken_, jetColl);
228  std::vector<TLorentzVector> list_jets;
229 
230  if (jetColl.isValid()) {
231  for (const auto& jets : *jetColl) {
232  if (jets.pt() < minPt_Jets_)
233  continue;
234  if (std::fabs(jets.eta()) > maxEta_Jets_)
235  continue;
236  TLorentzVector lv_jets; // lv_bJets;
237  lv_jets.SetPtEtaPhiE(jets.pt(), jets.eta(), jets.phi(), jets.energy());
238  list_jets.push_back(lv_jets);
239  }
240  lj = list_jets.size();
241  }
242 
244  iEvent.getByToken(bjetsToken_, bTagHandle);
245  const reco::JetTagCollection& bTags = *(bTagHandle.product());
246  std::vector<TLorentzVector> list_bjets;
247 
248  if (!bTags.empty()) {
249  for (unsigned bj = 0; bj != bTags.size(); ++bj) {
250  TLorentzVector lv_bjets;
251  lv_bjets.SetPtEtaPhiE(
252  bTags[bj].first->pt(), bTags[bj].first->eta(), bTags[bj].first->phi(), bTags[bj].first->energy());
253  if ((bTags[bj].second > btagFactor_) && (lv_bjets.Pt() > minPt_Jets_))
254  list_bjets.push_back(lv_bjets);
255  }
256  lbj = list_bjets.size();
257  }
258 
259  // for MET collection
261  iEvent.getByToken(pfmetToken_, pfColl);
262  if (EventCategory(le, lm, lj, lbj) == 11) { // dilepton- ele ele
263  if (list_ele[0].Pt() < minPtHighestEle_)
264  return false;
265  if ((list_ele[0].Pt() < list_mu[0].Pt()) || (list_ele[1].Pt() < list_mu[0].Pt()))
266  return false;
267  if (chrgeList_ele[0] + chrgeList_ele[1] != 0)
268  return false;
269  if (pfColl.isValid()) {
270  double mt1 = getMt(list_ele[0], pfColl->front());
271  double mt2 = getMt(list_ele[1], pfColl->front());
272  double mt = mt1 + mt2;
273  if (mt < 2 * minMet_ || mt > 2 * maxMet_)
274  return false;
275  } else {
276  edm::LogError("ttbarEventSelector")
277  << "Error >> Failed to get PFMETCollection in dilepton ele-ele channel for label: " << pfmetTag_;
278  return false;
279  }
280  } else if (EventCategory(le, lm, lj, lbj) == 12) { // dilepton - mu mu
281  if (list_mu[0].Pt() < minPtHighestMu_)
282  return false;
283  if ((list_mu[0].Pt() < list_ele[0].Pt()) || (list_mu[1].Pt() < list_ele[0].Pt()))
284  return false;
285  if (chrgeList_mu[0] + chrgeList_mu[1] != 0)
286  return false;
287  if (pfColl.isValid()) {
288  double mt1 = getMt(list_mu[0], pfColl->front());
289  double mt2 = getMt(list_mu[1], pfColl->front());
290  double mt = mt1 + mt2;
291  if (mt < 2 * minMet_ || mt > 2 * maxMet_)
292  return false;
293  } else {
294  edm::LogError("ttbarEventSelector")
295  << "Error >> Failed to get PFMETCollection in dilepton mu-mu channel for label: " << pfmetTag_;
296  return false;
297  }
298  } else if (EventCategory(le, lm, lj, lbj) == 13) { // dilepton - ele mu
299  if ((list_mu[0].Pt() < list_ele[1].Pt()) || (list_ele[0].Pt() < list_mu[1].Pt()))
300  return false;
301  if ((list_mu[0].Pt() < minPtHighestMu_) || (list_ele[0].Pt() < minPtHighestEle_))
302  return false;
303  if (chrgeList_mu[0] + chrgeList_ele[0] != 0)
304  return false;
305  if (pfColl.isValid()) {
306  double mt1 = getMt(list_mu[0], pfColl->front());
307  double mt2 = getMt(list_ele[0], pfColl->front());
308  double mt = mt1 + mt2;
309  if (mt < 2 * minMet_ || mt > 2 * maxMet_)
310  return false;
311  } else {
312  edm::LogError("ttbarEventSelector")
313  << "Error >> Failed to get PFMETCollection in dilepton ele-mu channel for label: " << pfmetTag_;
314  return false;
315  }
316  }
317  if (EventCategory(le, lm, lj, lbj) == 21) { // semilepton - ele or mu
318  if (list_jets[0].Pt() < minPtHighest_Jets_)
319  return false;
320 
321  if (list_ele[0].Pt() < minPtHighestEle_)
322  return false;
323  // Both should not be present at the same time
324  if ((!list_ele.empty() && list_ele[0].Pt() > minPtHighestEle_) &&
325  (!list_mu.empty() && list_mu[0].Pt() > minPtHighestMu_))
326  return false;
327 
328  return true;
329  }
330  if (EventCategory(le, lm, lj, lbj) == 22) { // semilepton - ele or mu
331  if (list_jets[0].Pt() < minPtHighest_Jets_)
332  return false;
333 
334  if (list_mu[0].Pt() < minPtHighestMu_)
335  return false;
336  // Both should not be present at the same time
337  if ((!list_ele.empty() && list_ele[0].Pt() > minPtHighestEle_) &&
338  (!list_mu.empty() && list_mu[0].Pt() > minPtHighestMu_))
339  return false;
340 
341  return true;
342  } else if (EventCategory(le, lm, lj, lbj) == 30) {
343  if (list_jets[0].Pt() < minPtHighest_Jets_)
344  return false;
345  for (int i = 0; i < 4; i++) {
346  TLorentzVector vjet1;
347  for (int j = i + 1; j < 4; j++) {
348  TLorentzVector vjet2;
349  vjet1 = list_jets[i];
350  vjet2 = list_jets[j];
351  TLorentzVector vjet = vjet1 + vjet2;
352  if (vjet.M() < minWmass_ || vjet.M() > maxWmass_)
353  return false;
354  }
355  }
356  } else if (EventCategory(le, lm, lj, lbj) == 50)
357  return false;
358 
359  return false;
360 }
361 
362 int ttbarEventSelector::EventCategory(int& nEle, int& nMu, int& nJets, int& nbJets) {
363  int cat = 0;
364  if ((nEle >= 2 || nMu >= 2) && nJets > 1 && nbJets > 1) { // di-lepton
365  if (nEle >= 2 && nJets < 2)
366  cat = 11;
367  else if (nMu >= 2 && nJets < 2)
368  cat = 12;
369  else if (nEle >= 1 && nMu >= 1 && nJets < 2)
370  cat = 13;
371  } else if ((nEle >= 1 || nMu >= 1) && nJets > 3 && nbJets > 2) { //semi-lepton
372  if (nEle >= 1 && nJets > 1)
373  cat = 21;
374  else if (nMu >= 1 && nJets > 1)
375  cat = 22;
376  } else if ((nEle < 1 && nMu < 1) && nJets > 5 && nbJets > 1)
377  cat = 30;
378  else
379  cat = 50;
380  return cat;
381 }
382 
383 double ttbarEventSelector::getMt(const TLorentzVector& vlep, const reco::PFMET& obj) {
384  double met = obj.et();
385  double phi = obj.phi();
386 
387  TLorentzVector vmet;
388  double metx = met * std::cos(phi);
389  double mety = met * std::sin(phi);
390  vmet.SetPxPyPzE(metx, mety, 0.0, met);
391 
392  // transverse mass
393  TLorentzVector vw = vlep + vmet;
394 
395  return std::sqrt(2 * vlep.Et() * met * (1 - std::cos(deltaPhi(vlep.Phi(), phi))));
396 }
397 
398 // Define this as a plug-in
const edm::InputTag pfmetTag_
int numberOfValidPixelHits() const
Definition: HitPattern.h:831
const edm::EDGetTokenT< reco::MuonCollection > muonToken_
const edm::EDGetTokenT< reco::JetTagCollection > bjetsToken_
bool filter(edm::Event &, edm::EventSetup const &) override
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const edm::EDGetTokenT< reco::PFJetCollection > jetsToken_
T const * product() const
Definition: Handle.h:70
const edm::EDGetTokenT< reco::PFMETCollection > pfmetToken_
float sumPUPt
sum pt of charged Particles not from PV (for Pu corrections)
Definition: GsfElectron.h:670
const double minPt_Jets_
const float maxD0_
Definition: Constants.h:82
const double minPtHighestMu_
const edm::InputTag electronTag_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
JetFloatAssociation::Container JetTagCollection
Definition: JetTag.h:17
Log< level::Error, false > LogError
int EventCategory(int &nEle, int &nMu, int &nJets, int &nbJets)
const double maxEta_Jets_
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
const double minMatches_
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
const double maxSigmaiEiEEE_
int numberOfValidStripHits() const
Definition: HitPattern.h:843
const double maxDeltaPhiInEB_
const edm::InputTag bsTag_
U second(std::pair< T, U > const &p)
const edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_
const double minMatchedStations_
int iEvent
Definition: GenABIO.cc:224
def cat(path)
Definition: eostools.py:401
const edm::InputTag muonTag_
const double maxDeltaEtaInEB_
T sqrt(T t)
Definition: SSEVec.h:19
const double maxSigmaiEiEEB_
float sumPhotonEt
sum pt of PF photons // old float photonIso ;
Definition: GsfElectron.h:665
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
float sumNeutralHadronEt
sum pt of neutral hadrons // old float neutralHadronIso ;
Definition: GsfElectron.h:664
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
const edm::EDGetTokenT< reco::BeamSpot > bsToken_
double getMt(const TLorentzVector &vlep, const reco::PFMET &obj)
const double minPtHighest_Jets_
bool isValid() const
Definition: HandleBase.h:70
const double maxNormChi2_
std::vector< PFJet > PFJetCollection
collection of PFJet objects
fixed size matrix
HLT enums.
const double minChambers_
const double btagFactor_
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
Definition: GsfElectron.h:663
ttbarEventSelector(const edm::ParameterSet &)
const double minPtHighestEle_
const double maxDeltaPhiInEE_
const double maxDeltaEtaInEE_
Collection of PF MET.