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
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
double pt() const final
transverse momentum
const Point & position() const
position
Definition: BeamSpot.h:59
goodElectrons
/ ___|___ / _| ____| | ___ ___| |_ _ __ ___ _ __ | | _/ __| |_| _| | |/ _ \/ __| __| &#39;__/ _ | &#39;_ \...
float sigmaIetaIeta() const
Definition: GsfElectron.h:419
T const * product() const
Definition: Handle.h:70
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float charge(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:73
bool isEB() const
Definition: GsfElectron.h:328
T getUntrackedParameter(std::string const &, T const &) const
float dr03TkSumPt() const
Definition: GsfElectron.h:557
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:156
int iEvent
Definition: GenABIO.cc:224
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float phi(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:80
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
float hcalOverEcal(const ShowerShape &ss, int depth) const
Definition: GsfElectron.h:425
bool electronSelection(const GsfElectron *eleRef, const math::XYZPoint &bspotPosition)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
bool isEE() const
Definition: GsfElectron.h:329
fixed size matrix
float dr03EcalRecHitSumEt() const
Definition: GsfElectron.h:559
float dr03HcalTowerSumEt(int depth=0) const
Definition: GsfElectron.h:576
double phi() const final
momentum azimuthal angle
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: event.py:1
int charge() const final
electric charge
WZInterestingEventSelector(const edm::ParameterSet &)
double eta() const final
momentum pseudorapidity