CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WZInterestingEventSelector.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 //
4 //
5 //
6 
7 
8 // system include files
9 #include <memory>
10 #include <iostream>
11 #include <fstream>
12 #include <sstream>
13 #include <string>
14 #include <stdio.h>
15 #include <stdlib.h>
16 // user include files
19 
23 
25 
37 
38 #include "TLorentzVector.h"
39 //
40 // class declaration
41 //
42 
43 using namespace reco;
44 
46 public:
47  struct event
48  {
49  long run;
50  long event;
51  long ls;
52  int nEle;
53  float maxPt;
54  float maxPtEleEta;
55  float maxPtElePhi;
56  float invMass;
57  float met;
58  float metPhi;
59  };
60 
63 
64 private:
65  virtual bool filter(edm::Event&, const edm::EventSetup&);
66  virtual void endJob();
67  bool electronSelection( const GsfElectron* eleRef , math::XYZPoint bspotPosition);
68  // ----------member data ---------------------------
69 
70  //std::vector<event> interestingEvents_;
71 
72  //Pt cut
73  float ptCut_;
75 
76  //EB ID+ISO cuts
77  float eb_trIsoCut_;
80  float eb_hoeCut_;
81  float eb_seeCut_;
82 
83  //EE ID+ISO cuts
84  float ee_trIsoCut_;
87  float ee_hoeCut_;
88  float ee_seeCut_;
89 
90  //met Cut
91  float metCut_;
92 
93  //invMass Cut
94  float invMassCut_;
95 
99 
100 };
101 
102 //
103 // constructors and destructor
104 //
106 {
107  ptCut_ = iConfig.getParameter<double>("ptCut");
108  missHitCut_ = iConfig.getParameter<int>("missHitsCut");
109 
110  eb_trIsoCut_ = iConfig.getParameter<double>("eb_trIsoCut");
111  eb_ecalIsoCut_ = iConfig.getParameter<double>("eb_ecalIsoCut");
112  eb_hcalIsoCut_ = iConfig.getParameter<double>("eb_hcalIsoCut");
113  eb_hoeCut_ = iConfig.getParameter<double>("eb_hoeCut");
114  eb_seeCut_ = iConfig.getParameter<double>("eb_seeCut");
115 
116  ee_trIsoCut_ = iConfig.getParameter<double>("ee_trIsoCut");
117  ee_ecalIsoCut_ = iConfig.getParameter<double>("ee_ecalIsoCut");
118  ee_hcalIsoCut_ = iConfig.getParameter<double>("ee_hcalIsoCut");
119  ee_hoeCut_ = iConfig.getParameter<double>("ee_hoeCut");
120  ee_seeCut_ = iConfig.getParameter<double>("ee_seeCut");
121 
122  metCut_ = iConfig.getParameter<double>("metCut");
123  invMassCut_ = iConfig.getParameter<double>("invMassCut");
124 
125  electronCollection_ = iConfig.getUntrackedParameter<edm::InputTag>("electronCollection",edm::InputTag("gsfElectrons"));
126  pfMetCollection_ = iConfig.getUntrackedParameter<edm::InputTag>("pfMetCollection",edm::InputTag("pfMet"));
127  offlineBSCollection_ = iConfig.getUntrackedParameter<edm::InputTag>("offlineBSCollection",edm::InputTag("offlineBeamSpot"));
128 
129 }
130 
131 
133 {
134 
135  // do anything here that needs to be done at desctruction time
136  // (e.g. close files, deallocate resources etc.)
137 
138 }
139 
140 
141 //
142 // member functions
143 //
144 
145 // ------------ method called on each new Event ------------
146 
148 
149 // if (interestingEvents_.size()<1)
150 // return;
151 
152 // std::ostringstream oss;
153 // for (unsigned int iEvent=0;iEvent<interestingEvents_.size();++iEvent)
154 // {
155 // oss << "==================================" << std::endl;
156 // oss << "Run: " << interestingEvents_[iEvent].run << " Event: " << interestingEvents_[iEvent].event << " LS: " << interestingEvents_[iEvent].ls << std::endl;
157 // oss << "nGoodEle: " << interestingEvents_[iEvent].nEle << " maxPt " << interestingEvents_[iEvent].maxPt << " maxPtEta " << interestingEvents_[iEvent].maxPtEleEta << " maxPtPhi " << interestingEvents_[iEvent].maxPtElePhi << std::endl;
158 // oss << "invMass " << interestingEvents_[iEvent].invMass << " met " << interestingEvents_[iEvent].met << " metPhi " << interestingEvents_[iEvent].metPhi << std::endl;
159 // }
160 // std::string mailText;
161 // mailText = oss.str();
162 
163 // std::ofstream outputTxt;
164 // outputTxt.open("interestingEvents.txt");
165 // outputTxt << mailText;
166 // outputTxt.close();
167 
168  //Sending email
169 // std::ostringstream subject;
170 // subject << "Interesting events in Run#" << interestingEvents_[0].run;
171 
172 // std::ostringstream command;
173 // command << "cat interestingEvents.txt | mail -s \"" << subject.str() << "\" Paolo.Meridiani@cern.ch";
174 
175 // std::string commandStr = command.str();
176 // char* pch = (char*)malloc( sizeof( char ) *(commandStr.length() +1) );
177 // string::traits_type::copy( pch, commandStr.c_str(), commandStr.length() +1 );
178 // int i=system(pch);
179 
180 }
181 
183 {
184 
185 
186 // if (eleRef->trackerDrivenSeed() && !eleRef->ecalDrivenSeed())
187 // return false;
188 
189 // if (eleRef->ecalDrivenSeed())
190 // {
191 
192  if (eleRef->pt()<ptCut_) return false;
193 
194  if (eleRef->isEB())
195  {
196  if (eleRef->dr03TkSumPt()/eleRef->pt()>eb_trIsoCut_) return false;
197  if (eleRef->dr03EcalRecHitSumEt()/eleRef->pt()>eb_ecalIsoCut_) return false;
198  if (eleRef->dr03HcalTowerSumEt()/eleRef->pt()>eb_hcalIsoCut_) return false;
199  if (eleRef->sigmaIetaIeta()>eb_seeCut_) return false;
200  if (eleRef->hcalOverEcal()>eb_hoeCut_) return false;
201  }
202  else if (eleRef->isEE())
203  {
204  if (eleRef->dr03TkSumPt()/eleRef->pt()>ee_trIsoCut_) return false;
205  if (eleRef->dr03EcalRecHitSumEt()/eleRef->pt()>ee_ecalIsoCut_) return false;
206  if (eleRef->dr03HcalTowerSumEt()/eleRef->pt()>ee_hcalIsoCut_) return false;
207  if (eleRef->sigmaIetaIeta()>ee_seeCut_) return false;
208  if (eleRef->hcalOverEcal()>ee_hoeCut_) return false;
209  }
210 
211  if (eleRef->gsfTrack()->trackerExpectedHitsInner().numberOfHits()>missHitCut_) return false;
212 
213  return true;
214 }
215 
216 bool
218 {
219  // using namespace edm;
221  iEvent.getByLabel(electronCollection_,gsfElectrons);
222 
223 // edm::Handle<reco::CaloMETCollection> caloMET;
224 // iEvent.getByLabel(edm::InputTag("met"), caloMET);
225 
227  iEvent.getByLabel(pfMetCollection_, pfMET);
228 
229  edm::Handle<reco::BeamSpot> pBeamSpot;
230  iEvent.getByLabel(offlineBSCollection_, pBeamSpot);
231 
232  const reco::BeamSpot *bspot = pBeamSpot.product();
233  math::XYZPoint bspotPosition = bspot->position();
234 
235  std::vector<const GsfElectron*> goodElectrons;
236  float ptMax=-999.;
237  const GsfElectron* ptMaxEle=0;
238  for(reco::GsfElectronCollection::const_iterator myEle=gsfElectrons->begin();myEle!=gsfElectrons->end();++myEle)
239  {
240  //Apply a minimal isolated electron selection
241  if (!electronSelection(&(*myEle),bspotPosition)) continue;
242  goodElectrons.push_back(&(*myEle));
243  if (myEle->pt() > ptMax )
244  {
245  ptMax = myEle->pt();
246  ptMaxEle = &(*myEle);
247  }
248  }
249 
250  event thisEvent;
251  thisEvent.run=iEvent.run();
252  thisEvent.event=iEvent.eventAuxiliary().event();
253  thisEvent.ls=iEvent.getLuminosityBlock().luminosityBlock();
254  thisEvent.nEle=goodElectrons.size();
255 
256  if (ptMaxEle)
257  {
258  thisEvent.maxPt=ptMax;
259  thisEvent.maxPtEleEta=ptMaxEle->eta();
260  thisEvent.maxPtElePhi=ptMaxEle->phi();
261 
262  }
263 
264  if (pfMET.isValid())
265  {
266  thisEvent.met=pfMET->begin()->et();
267  thisEvent.metPhi=pfMET->begin()->phi();
268  }
269 
270 
271  float maxInv=-999.;
272  TLorentzVector v1;
273  if (ptMaxEle)
274  v1.SetPtEtaPhiM(ptMaxEle->pt(),ptMaxEle->eta(),ptMaxEle->phi(),0);
275  if (goodElectrons.size()>1)
276  {
277  for (unsigned int iEle=0; iEle<goodElectrons.size(); ++iEle)
278  if (goodElectrons[iEle]!=ptMaxEle && (goodElectrons[iEle]->charge() * ptMaxEle->charge() == -1) )
279  {
280  TLorentzVector v2;
281  v2.SetPtEtaPhiM(goodElectrons[iEle]->pt(),goodElectrons[iEle]->eta(),goodElectrons[iEle]->phi(),0.);
282  if ( (v1+v2).M() > maxInv )
283  maxInv = (v1+v2).M();
284  }
285  }
286 
287  if (maxInv > invMassCut_)
288  thisEvent.invMass = maxInv;
289 
290  //Z filt: Retain event if more then 1 good ele and invMass above threshold (zee)
291  if (goodElectrons.size()>1 && maxInv > invMassCut_)
292  {
293  //interestingEvents_.push_back(thisEvent);
294  return true;
295  }
296 
297  //W filt: Retain event also event with at least 1 good ele and some met
298  if (goodElectrons.size()>=1 && (pfMET->begin()->et()>metCut_))
299  {
300  //interestingEvents_.push_back(thisEvent);
301  return true;
302  }
303 
304  return false;
305 }
306 
307 //define this as a plug-in
virtual bool filter(edm::Event &, const edm::EventSetup &)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
T eta() const
double charge(const std::vector< uint8_t > &Ampls)
virtual double eta() const
momentum pseudorapidity
bool isEE() const
Definition: GsfElectron.h:341
bool isEB() const
Definition: GsfElectron.h:340
LuminosityBlockNumber_t luminosityBlock() const
int iEvent
Definition: GenABIO.cc:243
float sigmaIetaIeta() const
Definition: GsfElectron.h:384
bool electronSelection(const GsfElectron *eleRef, math::XYZPoint bspotPosition)
virtual int charge() const
electric charge
float hcalOverEcal() const
Definition: GsfElectron.h:390
RunNumber_t run() const
Definition: Event.h:66
float dr03TkSumPt() const
Definition: GsfElectron.h:428
LuminosityBlock const & getLuminosityBlock() const
Definition: Event.h:58
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
EventAuxiliary const & eventAuxiliary() const
Definition: Event.h:55
GsfTrackRef gsfTrack() const
reference to a GsfTrack
Definition: GsfElectron.h:169
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
Definition: align_tpl.py:86
virtual double pt() const
transverse momentum
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
T const * product() const
Definition: Handle.h:74
float dr03EcalRecHitSumEt() const
Definition: GsfElectron.h:429
float dr03HcalTowerSumEt() const
Definition: GsfElectron.h:432
const Point & position() const
position
Definition: BeamSpot.h:63
virtual double phi() const
momentum azimuthal angle
EventNumber_t event() const
WZInterestingEventSelector(const edm::ParameterSet &)
Definition: DDAxes.h:10