CMS 3D CMS Logo

WZInterestingEventSelector.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 //
4 //
5 //
6 
7 // system include files
8 #include <memory>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 #include <string>
13 #include <cstdio>
14 #include <cstdlib>
15 // user include files
18 
22 
24 
36 
37 #include "TLorentzVector.h"
38 //
39 // class declaration
40 //
41 
42 using namespace reco;
43 
45 public:
46  struct event {
47  long run;
48  long event;
49  long ls;
50  int nEle;
51  float maxPt;
52  float maxPtEleEta;
53  float maxPtElePhi;
54  float invMass;
55  float met;
56  float metPhi;
57  };
58 
60  ~WZInterestingEventSelector() override;
61 
62 private:
63  bool filter(edm::Event&, const edm::EventSetup&) override;
64  void endJob() override;
65  bool electronSelection(const GsfElectron* eleRef, const math::XYZPoint& bspotPosition);
66  // ----------member data ---------------------------
67 
68  //std::vector<event> interestingEvents_;
69 
70  //Pt cut
71  float ptCut_;
73 
74  //EB ID+ISO cuts
75  float eb_trIsoCut_;
78  float eb_hoeCut_;
79  float eb_seeCut_;
80 
81  //EE ID+ISO cuts
82  float ee_trIsoCut_;
85  float ee_hoeCut_;
86  float ee_seeCut_;
87 
88  //met Cut
89  float metCut_;
90 
91  //invMass Cut
92  float invMassCut_;
93 
97 };
98 
99 //
100 // constructors and destructor
101 //
103  ptCut_ = iConfig.getParameter<double>("ptCut");
104  missHitCut_ = iConfig.getParameter<int>("missHitsCut");
105 
106  eb_trIsoCut_ = iConfig.getParameter<double>("eb_trIsoCut");
107  eb_ecalIsoCut_ = iConfig.getParameter<double>("eb_ecalIsoCut");
108  eb_hcalIsoCut_ = iConfig.getParameter<double>("eb_hcalIsoCut");
109  eb_hoeCut_ = iConfig.getParameter<double>("eb_hoeCut");
110  eb_seeCut_ = iConfig.getParameter<double>("eb_seeCut");
111 
112  ee_trIsoCut_ = iConfig.getParameter<double>("ee_trIsoCut");
113  ee_ecalIsoCut_ = iConfig.getParameter<double>("ee_ecalIsoCut");
114  ee_hcalIsoCut_ = iConfig.getParameter<double>("ee_hcalIsoCut");
115  ee_hoeCut_ = iConfig.getParameter<double>("ee_hoeCut");
116  ee_seeCut_ = iConfig.getParameter<double>("ee_seeCut");
117 
118  metCut_ = iConfig.getParameter<double>("metCut");
119  invMassCut_ = iConfig.getParameter<double>("invMassCut");
120 
121  electronCollection_ =
122  iConfig.getUntrackedParameter<edm::InputTag>("electronCollection", edm::InputTag("gsfElectrons"));
123  pfMetCollection_ = iConfig.getUntrackedParameter<edm::InputTag>("pfMetCollection", edm::InputTag("pfMet"));
124  offlineBSCollection_ =
125  iConfig.getUntrackedParameter<edm::InputTag>("offlineBSCollection", edm::InputTag("offlineBeamSpot"));
126 }
127 
129  // do anything here that needs to be done at desctruction time
130  // (e.g. close files, deallocate resources etc.)
131 }
132 
133 //
134 // member functions
135 //
136 
137 // ------------ method called on each new Event ------------
138 
140  // if (interestingEvents_.size()<1)
141  // return;
142 
143  // std::ostringstream oss;
144  // for (unsigned int iEvent=0;iEvent<interestingEvents_.size();++iEvent)
145  // {
146  // oss << "==================================" << std::endl;
147  // oss << "Run: " << interestingEvents_[iEvent].run << " Event: " << interestingEvents_[iEvent].event << " LS: " << interestingEvents_[iEvent].ls << std::endl;
148  // oss << "nGoodEle: " << interestingEvents_[iEvent].nEle << " maxPt " << interestingEvents_[iEvent].maxPt << " maxPtEta " << interestingEvents_[iEvent].maxPtEleEta << " maxPtPhi " << interestingEvents_[iEvent].maxPtElePhi << std::endl;
149  // oss << "invMass " << interestingEvents_[iEvent].invMass << " met " << interestingEvents_[iEvent].met << " metPhi " << interestingEvents_[iEvent].metPhi << std::endl;
150  // }
151  // std::string mailText;
152  // mailText = oss.str();
153 
154  // std::ofstream outputTxt;
155  // outputTxt.open("interestingEvents.txt");
156  // outputTxt << mailText;
157  // outputTxt.close();
158 
159  //Sending email
160  // std::ostringstream subject;
161  // subject << "Interesting events in Run#" << interestingEvents_[0].run;
162 
163  // std::ostringstream command;
164  // command << "cat interestingEvents.txt | mail -s \"" << subject.str() << "\" Paolo.Meridiani@cern.ch";
165 
166  // std::string commandStr = command.str();
167  // char* pch = (char*)malloc( sizeof( char ) *(commandStr.length() +1) );
168  // string::traits_type::copy( pch, commandStr.c_str(), commandStr.length() +1 );
169  // int i=system(pch);
170 }
171 
173  // if (eleRef->trackerDrivenSeed() && !eleRef->ecalDrivenSeed())
174  // return false;
175 
176  // if (eleRef->ecalDrivenSeed())
177  // {
178 
179  if (eleRef->pt() < ptCut_)
180  return false;
181 
182  if (eleRef->isEB()) {
183  if (eleRef->dr03TkSumPt() / eleRef->pt() > eb_trIsoCut_)
184  return false;
185  if (eleRef->dr03EcalRecHitSumEt() / eleRef->pt() > eb_ecalIsoCut_)
186  return false;
187  if (eleRef->dr03HcalTowerSumEt() / eleRef->pt() > eb_hcalIsoCut_)
188  return false;
189  if (eleRef->sigmaIetaIeta() > eb_seeCut_)
190  return false;
191  if (eleRef->hcalOverEcal() > eb_hoeCut_)
192  return false;
193  } else if (eleRef->isEE()) {
194  if (eleRef->dr03TkSumPt() / eleRef->pt() > ee_trIsoCut_)
195  return false;
196  if (eleRef->dr03EcalRecHitSumEt() / eleRef->pt() > ee_ecalIsoCut_)
197  return false;
198  if (eleRef->dr03HcalTowerSumEt() / eleRef->pt() > ee_hcalIsoCut_)
199  return false;
200  if (eleRef->sigmaIetaIeta() > ee_seeCut_)
201  return false;
202  if (eleRef->hcalOverEcal() > ee_hoeCut_)
203  return false;
204  }
205 
206  if (eleRef->gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) > missHitCut_)
207  return false;
208 
209  return true;
210 }
211 
213  // using namespace edm;
215  iEvent.getByLabel(electronCollection_, gsfElectrons);
216 
217  // edm::Handle<reco::CaloMETCollection> caloMET;
218  // iEvent.getByLabel(edm::InputTag("met"), caloMET);
219 
221  iEvent.getByLabel(pfMetCollection_, pfMET);
222 
223  edm::Handle<reco::BeamSpot> pBeamSpot;
224  iEvent.getByLabel(offlineBSCollection_, pBeamSpot);
225 
226  const reco::BeamSpot* bspot = pBeamSpot.product();
227  const math::XYZPoint& bspotPosition = bspot->position();
228 
229  std::vector<const GsfElectron*> goodElectrons;
230  float ptMax = -999.;
231  const GsfElectron* ptMaxEle = nullptr;
232  for (reco::GsfElectronCollection::const_iterator myEle = gsfElectrons->begin(); myEle != gsfElectrons->end();
233  ++myEle) {
234  //Apply a minimal isolated electron selection
235  if (!electronSelection(&(*myEle), bspotPosition))
236  continue;
237  goodElectrons.push_back(&(*myEle));
238  if (myEle->pt() > ptMax) {
239  ptMax = myEle->pt();
240  ptMaxEle = &(*myEle);
241  }
242  }
243 
244  float maxInv = -999.;
245  TLorentzVector v1;
246  if (ptMaxEle)
247  v1.SetPtEtaPhiM(ptMaxEle->pt(), ptMaxEle->eta(), ptMaxEle->phi(), 0);
248  if (goodElectrons.size() > 1) {
249  for (unsigned int iEle = 0; iEle < goodElectrons.size(); ++iEle)
250  if (goodElectrons[iEle] != ptMaxEle && (goodElectrons[iEle]->charge() * ptMaxEle->charge() == -1)) {
251  TLorentzVector v2;
252  v2.SetPtEtaPhiM(goodElectrons[iEle]->pt(), goodElectrons[iEle]->eta(), goodElectrons[iEle]->phi(), 0.);
253  if ((v1 + v2).M() > maxInv)
254  maxInv = (v1 + v2).M();
255  }
256  }
257 
258  //Z filt: Retain event if more then 1 good ele and invMass above threshold (zee)
259  if (goodElectrons.size() > 1 && maxInv > invMassCut_) {
260  //interestingEvents_.push_back(thisEvent);
261  return true;
262  }
263 
264  //W filt: Retain event also event with at least 1 good ele and some met
265  if (!goodElectrons.empty() && (pfMET->begin()->et() > metCut_)) {
266  //interestingEvents_.push_back(thisEvent);
267  return true;
268  }
269 
270  return false;
271 }
272 
273 //define this as a plug-in
WZInterestingEventSelector::eb_hoeCut_
float eb_hoeCut_
Definition: WZInterestingEventSelector.cc:78
WZInterestingEventSelector::event::invMass
float invMass
Definition: WZInterestingEventSelector.cc:54
reco::GsfElectron::isEE
bool isEE() const
Definition: GsfElectron.h:337
WZInterestingEventSelector::ee_trIsoCut_
float ee_trIsoCut_
Definition: WZInterestingEventSelector.cc:82
reco::GsfElectron::dr03TkSumPt
float dr03TkSumPt() const
Definition: GsfElectron.h:529
reco::GsfElectron::isEB
bool isEB() const
Definition: GsfElectron.h:336
reco::GsfElectron::gsfTrack
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:164
WZInterestingEventSelector::electronCollection_
edm::InputTag electronCollection_
Definition: WZInterestingEventSelector.cc:94
WZInterestingEventSelector::event::maxPtEleEta
float maxPtEleEta
Definition: WZInterestingEventSelector.cc:52
edm::Handle::product
T const * product() const
Definition: Handle.h:70
WZInterestingEventSelector::invMassCut_
float invMassCut_
Definition: WZInterestingEventSelector.cc:92
WZInterestingEventSelector::ptCut_
float ptCut_
Definition: WZInterestingEventSelector.cc:71
WZInterestingEventSelector::missHitCut_
int missHitCut_
Definition: WZInterestingEventSelector.cc:72
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
LuminosityBlock.h
EDFilter.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
PFMETCollection.h
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
WZInterestingEventSelector::offlineBSCollection_
edm::InputTag offlineBSCollection_
Definition: WZInterestingEventSelector.cc:96
WZInterestingEventSelector::event::maxPtElePhi
float maxPtElePhi
Definition: WZInterestingEventSelector.cc:53
electronIsolatorFromEffectiveArea_cfi.gsfElectrons
gsfElectrons
Definition: electronIsolatorFromEffectiveArea_cfi.py:4
edm::Handle< reco::GsfElectronCollection >
CaloMETFwd.h
CaloMETCollection.h
WZInterestingEventSelector::ee_hcalIsoCut_
float ee_hcalIsoCut_
Definition: WZInterestingEventSelector.cc:84
MakerMacros.h
WZInterestingEventSelector::ee_seeCut_
float ee_seeCut_
Definition: WZInterestingEventSelector.cc:86
WZInterestingEventSelector::event::maxPt
float maxPt
Definition: WZInterestingEventSelector.cc:51
WZInterestingEventSelector::ee_hoeCut_
float ee_hoeCut_
Definition: WZInterestingEventSelector.cc:85
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
AlignmentTrackSelector_cfi.ptMax
ptMax
Definition: AlignmentTrackSelector_cfi.py:12
WZInterestingEventSelector::event::ls
long ls
Definition: WZInterestingEventSelector.cc:49
CaloMET.h
PVValHelper::eta
Definition: PVValidationHelpers.h:69
WZinterestingEventFilter_cfi.WZInterestingEventSelector
WZInterestingEventSelector
Definition: WZinterestingEventFilter_cfi.py:3
reco::BeamSpot
Definition: BeamSpot.h:21
WZInterestingEventSelector::eb_hcalIsoCut_
float eb_hcalIsoCut_
Definition: WZInterestingEventSelector.cc:77
reco::GsfElectron
Definition: GsfElectron.h:35
reco::BeamSpot::position
const Point & position() const
position
Definition: BeamSpot.h:59
GsfElectron.h
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
WZInterestingEventSelector::event::run
long run
Definition: WZInterestingEventSelector.cc:47
WZInterestingEventSelector::eb_trIsoCut_
float eb_trIsoCut_
Definition: WZInterestingEventSelector.cc:75
WZInterestingEventSelector::filter
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: WZInterestingEventSelector.cc:212
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
GsfElectronFwd.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Event.h
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
PFMET.h
iEvent
int iEvent
Definition: GenABIO.cc:224
WZInterestingEventSelector::ee_ecalIsoCut_
float ee_ecalIsoCut_
Definition: WZInterestingEventSelector.cc:83
GsfTrack.h
edm::EDFilter
Definition: EDFilter.h:39
reco::LeafCandidate::charge
int charge() const final
electric charge
Definition: LeafCandidate.h:106
edm::EventSetup
Definition: EventSetup.h:57
WElectronSkim_cff.goodElectrons
goodElectrons
Definition: WElectronSkim_cff.py:31
reco::GsfElectron::hcalOverEcal
float hcalOverEcal() const
Definition: GsfElectron.h:427
InputTag.h
WZInterestingEventSelector::event::metPhi
float metPhi
Definition: WZInterestingEventSelector.cc:56
WZInterestingEventSelector::~WZInterestingEventSelector
~WZInterestingEventSelector() override
Definition: WZInterestingEventSelector.cc:128
reco::GsfElectron::sigmaIetaIeta
float sigmaIetaIeta() const
Definition: GsfElectron.h:419
WZInterestingEventSelector::eb_seeCut_
float eb_seeCut_
Definition: WZInterestingEventSelector.cc:79
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
PFMETFwd.h
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
Frameworkfwd.h
WZInterestingEventSelector::event::event
long event
Definition: WZInterestingEventSelector.cc:48
reco::HitPattern::MISSING_INNER_HITS
Definition: HitPattern.h:155
WZInterestingEventSelector::event::nEle
int nEle
Definition: WZInterestingEventSelector.cc:50
WZInterestingEventSelector::eb_ecalIsoCut_
float eb_ecalIsoCut_
Definition: WZInterestingEventSelector.cc:76
WZInterestingEventSelector
Definition: WZInterestingEventSelector.cc:44
WZInterestingEventSelector::WZInterestingEventSelector
WZInterestingEventSelector(const edm::ParameterSet &)
Definition: WZInterestingEventSelector.cc:102
WZInterestingEventSelector::event::met
float met
Definition: WZInterestingEventSelector.cc:55
ParameterSet.h
WZInterestingEventSelector::metCut_
float metCut_
Definition: WZInterestingEventSelector.cc:89
event
Definition: event.py:1
reco::GsfElectron::dr03HcalTowerSumEt
float dr03HcalTowerSumEt() const
Definition: GsfElectron.h:534
edm::Event
Definition: Event.h:73
WZInterestingEventSelector::pfMetCollection_
edm::InputTag pfMetCollection_
Definition: WZInterestingEventSelector.cc:95
WZInterestingEventSelector::electronSelection
bool electronSelection(const GsfElectron *eleRef, const math::XYZPoint &bspotPosition)
Definition: WZInterestingEventSelector.cc:172
edm::InputTag
Definition: InputTag.h:15
reco::GsfElectron::dr03EcalRecHitSumEt
float dr03EcalRecHitSumEt() const
Definition: GsfElectron.h:531
WZInterestingEventSelector::endJob
void endJob() override
Definition: WZInterestingEventSelector.cc:139
pfMETBenchmark_cfi.pfMET
pfMET
Definition: pfMETBenchmark_cfi.py:3