CMS 3D CMS Logo

WtoLNuSelector.cc
Go to the documentation of this file.
1 // W->lnu Event Selector
2 
3 // user includes
26 
27 // ROOT includes
28 #include "TLorentzVector.h"
29 #include "TMath.h"
30 
32 public:
33  explicit WtoLNuSelector(const edm::ParameterSet&);
34  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
35 
36 private:
37  bool filter(edm::Event&, edm::EventSetup const&) override;
38  double getMt(const TLorentzVector& vlep, const reco::PFMET& obj);
39 
40 private:
41  // module config parameters
50 };
51 
54  desc.addUntracked<edm::InputTag>("electronInputTag", edm::InputTag("gedGsfElectrons"));
55  desc.addUntracked<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"));
56  desc.addUntracked<edm::InputTag>("muonInputTag", edm::InputTag("muons"));
57  desc.addUntracked<edm::InputTag>("pfmetTag", edm::InputTag("pfMetT1T2Txy"));
58  descriptions.addWithDefaultLabel(desc);
59 }
60 
62  : electronTag_(ps.getUntrackedParameter<edm::InputTag>("electronInputTag", edm::InputTag("gedGsfElectrons"))),
63  bsTag_(ps.getUntrackedParameter<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"))),
64  muonTag_(ps.getUntrackedParameter<edm::InputTag>("muonInputTag", edm::InputTag("muons"))),
65  pfmetTag_(ps.getUntrackedParameter<edm::InputTag>("pfmetTag", edm::InputTag("pfMetT1T2Txy"))),
66  electronToken_(consumes<reco::GsfElectronCollection>(electronTag_)),
67  bsToken_(consumes<reco::BeamSpot>(bsTag_)),
68  muonToken_(consumes<reco::MuonCollection>(muonTag_)),
69  pfmetToken_(consumes<reco::PFMETCollection>(pfmetTag_)) {}
70 
72  // Read Electron Collection
74  iEvent.getByToken(electronToken_, electronColl);
75 
77  iEvent.getByToken(bsToken_, beamSpot);
78 
79  std::vector<TLorentzVector> eleList;
80  if (electronColl.isValid()) {
81  for (auto const& ele : *electronColl) {
82  if (!ele.ecalDriven())
83  continue;
84 
85  double hOverE = ele.hadronicOverEm();
86  double sigmaee = ele.sigmaIetaIeta();
87  double deltaPhiIn = ele.deltaPhiSuperClusterTrackAtVtx();
88  double deltaEtaIn = ele.deltaEtaSuperClusterTrackAtVtx();
89 
90  // separate cut for barrel and endcap
91  if (ele.isEB()) {
92  if (std::fabs(deltaPhiIn) >= .15 && std::fabs(deltaEtaIn) >= .007 && hOverE >= .12 && sigmaee >= .01)
93  continue;
94  } else if (ele.isEE()) {
95  if (std::fabs(deltaPhiIn) >= .10 && std::fabs(deltaEtaIn) >= .009 && hOverE >= .10 && sigmaee >= .03)
96  continue;
97  }
98 
99  reco::GsfTrackRef trk = ele.gsfTrack();
100  if (!trk.isNonnull())
101  continue; // only electrons wd tracks
102  double chi2 = trk->chi2();
103  double ndof = trk->ndof();
104  double chbyndof = (ndof > 0) ? chi2 / ndof : 0;
105  double trkd0 = trk->d0();
106  double trkdz = trk->dz();
107  if (beamSpot.isValid()) {
108  trkd0 = -(trk->dxy(beamSpot->position()));
109  trkdz = trk->dz(beamSpot->position());
110  } else {
111  edm::LogError("WtoLNuSelector") << "Error >> Failed to get BeamSpot for label: " << bsTag_;
112  }
113  if (chbyndof >= 10 || std::fabs(trkd0) >= 0.02 || std::fabs(trkdz) >= 20)
114  continue;
115  const reco::HitPattern& hitp = trk->hitPattern();
116  int nPixelHits = hitp.numberOfValidPixelHits();
117  int nStripHits = hitp.numberOfValidStripHits();
118  if (nPixelHits < 1 || nStripHits < 8)
119  continue;
120 
121  // PF Isolation
122  reco::GsfElectron::PflowIsolationVariables pfIso = ele.pfIsolationVariables();
123  float absiso =
124  pfIso.sumChargedHadronPt + std::max(0.0, pfIso.sumNeutralHadronEt + pfIso.sumPhotonEt - 0.5 * pfIso.sumPUPt);
125  float eiso = absiso / ele.pt();
126  if (eiso > 0.3)
127  continue;
128 
129  TLorentzVector le;
130  le.SetPtEtaPhiE(ele.pt(), ele.eta(), ele.phi(), ele.energy());
131  eleList.push_back(le);
132  }
133  } else {
134  edm::LogError("WtoLNuSelector") << "Error >> Failed to get ElectronCollection for label: " << electronTag_;
135  }
136 
137  // Read Muon Collection
139  iEvent.getByToken(muonToken_, muonColl);
140 
141  std::vector<TLorentzVector> muList;
142  if (muonColl.isValid()) {
143  for (auto const& mu : *muonColl) {
144  if (!mu.isGlobalMuon() || !mu.isPFMuon() || std::fabs(mu.eta()) > 2.1 || mu.pt() <= 5)
145  continue;
146 
147  reco::TrackRef gtrkref = mu.globalTrack();
148  if (!gtrkref.isNonnull())
149  continue;
150  const reco::Track* gtk = &(*gtrkref);
151  double chi2 = gtk->chi2();
152  double ndof = gtk->ndof();
153  double chbyndof = (ndof > 0) ? chi2 / ndof : 0;
154 
155  const reco::HitPattern& hitp = gtk->hitPattern();
156  int nPixelHits = hitp.numberOfValidPixelHits();
157  int nStripHits = hitp.numberOfValidStripHits();
158 
159  reco::TrackRef itrkref = mu.innerTrack(); // tracker segment only
160  if (!itrkref.isNonnull())
161  continue;
162  const reco::Track* tk = &(*itrkref);
163  double trkd0 = tk->d0();
164  double trkdz = tk->dz();
165  if (beamSpot.isValid()) {
166  trkd0 = -(tk->dxy(beamSpot->position()));
167  trkdz = tk->dz(beamSpot->position());
168  }
169  // Hits/section in the muon chamber
170  int nChambers = mu.numberOfChambers();
171  int nMatches = mu.numberOfMatches();
172  int nMatchedStations = mu.numberOfMatchedStations();
173 
174  // PF Isolation
175  const reco::MuonPFIsolation& pfIso04 = mu.pfIsolationR04();
176  double absiso = pfIso04.sumChargedParticlePt +
177  std::max(0.0, pfIso04.sumNeutralHadronEt + pfIso04.sumPhotonEt - 0.5 * pfIso04.sumPUPt);
178 
179  // Final selection
180  if (chbyndof < 10 && std::fabs(trkd0) < 0.02 && std::fabs(trkdz) < 20.0 && nPixelHits > 1 && nStripHits > 8 &&
181  nChambers > 2 && nMatches > 2 && nMatchedStations > 2 && absiso / mu.pt() < 0.3) {
182  TLorentzVector lm;
183  lm.SetPtEtaPhiE(mu.pt(), mu.eta(), mu.phi(), mu.energy());
184  muList.push_back(lm);
185  }
186  }
187  } else {
188  edm::LogError("WtoLNuSelector") << "Error >> Failed to get MuonCollection for label: " << muonTag_;
189  }
190 
191  // Require either a high pt electron or muon
192  if (eleList.empty() && muList.empty())
193  return false;
194 
195  // Both should not be present at the same time
196  if ((!eleList.empty() && eleList[0].Pt() > 20) && (!muList.empty() && muList[0].Pt() > 20))
197  return false;
198 
199  // find the high pt lepton
200  TLorentzVector vlep;
201  if (!eleList.empty() && !muList.empty()) {
202  vlep = (eleList[0].Pt() > muList[0].Pt()) ? eleList[0] : muList[0];
203  } else if (!eleList.empty()) {
204  vlep = eleList[0];
205  } else {
206  vlep = muList[0];
207  }
208  if (vlep.Pt() < 20)
209  return false;
210 
212  iEvent.getByToken(pfmetToken_, pfColl);
213 
214  if (pfColl.isValid()) {
215  double mt = getMt(vlep, pfColl->front());
216  if (mt < 60 || mt > 80)
217  return false;
218  } else {
219  edm::LogError("WtoLNuSelector") << "Error >> Failed to get PFMETCollection for label: " << pfmetTag_;
220  return false;
221  }
222 
223  return true;
224 }
225 double WtoLNuSelector::getMt(const TLorentzVector& vlep, const reco::PFMET& obj) {
226  double met = obj.et();
227  double phi = obj.phi();
228 
229  TLorentzVector vmet;
230  double metx = met * std::cos(phi);
231  double mety = met * std::sin(phi);
232  vmet.SetPxPyPzE(metx, mety, 0.0, met);
233 
234  // transverse mass
235  TLorentzVector vw = vlep + vmet;
236 
237  return std::sqrt(2 * vlep.Et() * met * (1 - std::cos(deltaPhi(vlep.Phi(), phi))));
238 }
239 // Define this as a plug-in
const edm::EDGetTokenT< reco::BeamSpot > bsToken_
int numberOfValidPixelHits() const
Definition: HitPattern.h:831
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
double getMt(const TLorentzVector &vlep, const reco::PFMET &obj)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
float sumPUPt
sum pt of charged Particles not from PV (for Pu corrections)
Definition: GsfElectron.h:670
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
const edm::InputTag electronTag_
const edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_
Log< level::Error, false > LogError
WtoLNuSelector(const edm::ParameterSet &)
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
int numberOfValidStripHits() const
Definition: HitPattern.h:843
double ndof() const
number of degrees of freedom of the fit
Definition: TrackBase.h:590
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:622
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< reco::MuonCollection > muonToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T sqrt(T t)
Definition: SSEVec.h:23
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
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:504
double d0() const
dxy parameter in perigee convention (d0 = -dxy)
Definition: TrackBase.h:611
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:587
const edm::InputTag bsTag_
bool filter(edm::Event &, edm::EventSetup const &) override
const edm::InputTag muonTag_
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
HLT enums.
const edm::InputTag pfmetTag_
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
Definition: GsfElectron.h:663
const edm::EDGetTokenT< reco::PFMETCollection > pfmetToken_
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:608
Collection of PF MET.