CMS 3D CMS Logo

LeptonRecoSkim.cc
Go to the documentation of this file.
1 
2 // -*- C++ -*-
3 //
4 // Package: LeptonRecoSkim
5 // Class: LeptonRecoSkim
6 //
14 //
15 // Original Author: Massimiliano Chiorboli,40 4-A01,+41227671535,
16 // Created: Wed Mar 31 21:49:08 CEST 2010
17 // $Id: LeptonRecoSkim.cc,v 1.1 2010/11/05 18:37:51 torimoto Exp $
18 //
19 //
20 
21 
23 
24 
25 using namespace edm;
26 using namespace reco;
27 using namespace std;
28 
29 //
30 // constructors and destructor
31 //
33  hltLabel(iConfig.getParameter<edm::InputTag>("HltLabel")),
34  filterName(iConfig.getParameter<std::string>("@module_label")),
35  m_electronSrc(iConfig.getParameter<edm::InputTag>("electronCollection")),
36  m_pfelectronSrc(iConfig.getParameter<edm::InputTag>("pfElectronCollection")),
37  m_muonSrc(iConfig.getParameter<edm::InputTag>("muonCollection")),
38  m_jetsSrc(iConfig.getParameter<edm::InputTag>("caloJetCollection")),
39  m_pfjetsSrc(iConfig.getParameter<edm::InputTag>("PFJetCollection")),
40  m_ebRecHitsSrc(iConfig.getParameter<edm::InputTag>("ecalBarrelRecHitsCollection")),
41  m_eeRecHitsSrc(iConfig.getParameter<edm::InputTag>("ecalEndcapRecHitsCollection")),
42  useElectronSelection(iConfig.getParameter<bool>("UseElectronSelection")),
43  usePfElectronSelection(iConfig.getParameter<bool>("UsePfElectronSelection")),
44  useMuonSelection(iConfig.getParameter<bool>("UseMuonSelection")),
45  useHtSelection(iConfig.getParameter<bool>("UseHtSelection")),
46  usePFHtSelection(iConfig.getParameter<bool>("UsePFHtSelection")),
47  ptElecMin(iConfig.getParameter<double>("electronPtMin")),
48  ptPfElecMin(iConfig.getParameter<double>("pfElectronPtMin")),
49  nSelectedElectrons(iConfig.getParameter<int>("electronN")),
50  nSelectedPfElectrons(iConfig.getParameter<int>("pfElectronN")),
51  ptGlobalMuonMin(iConfig.getParameter<double>("globalMuonPtMin")),
52  ptTrackerMuonMin(iConfig.getParameter<double>("trackerMuonPtMin")),
53  nSelectedMuons(iConfig.getParameter<int>("muonN")),
54  htMin(iConfig.getParameter<double>("HtMin")),
55  pfHtMin(iConfig.getParameter<double>("PFHtMin")),
56  htJetThreshold(iConfig.getParameter<double>("HtJetThreshold")),
57  pfHtJetThreshold(iConfig.getParameter<double>("PFHtJetThreshold"))
58 {
59  NeventsTotal = 0;
60  NeventsFiltered = 0;
61  NHltMu9 = 0;
62  NHltDiMu3 = 0;
63 
64  NtotalElectrons = 0;
65  NmvaElectrons = 0;
66 }
67 
68 
70 {
71 
72  // do anything here that needs to be done at desctruction time
73  // (e.g. close files, deallocate resources etc.)
74 
75 }
76 
77 
78 //
79 // member functions
80 //
81 
82 // ------------ method called on each new Event ------------
83 bool
85 {
86 
87 
88  bool accept = false;
89 
90  NeventsTotal++;
91 
92  ElectronCutPassed = false;
93  PfElectronCutPassed = false;
94  MuonCutPassed = false;
95  HtCutPassed = false;
96  PFHtCutPassed = false;
97 
98  // edm::Handle<TriggerResults> trhv;
99  // iEvent.getByLabel(hltLabel,trhv);
100 
101  // const edm::TriggerNames& triggerNames_ = iEvent.triggerNames(*trhv);
102 
103  // if(trhv->at(triggerNames_.triggerIndex("HLT_Mu9")).accept()) NHltMu9++;
104  // if(trhv->at(triggerNames_.triggerIndex("HLT_DoubleMu3")).accept()) NHltDiMu3++;
105 
106  this->handleObjects(iEvent,iSetup);
107 
109  int nElecPassingCut = 0;
110  for(unsigned int i=0; i<theElectronCollection->size(); i++) {
111  GsfElectron electron = (*theElectronCollection)[i];
112  // if (electron.ecalDrivenSeed()) {
113  float elpt = electron.pt();
114  // if (electron.sigmaIetaIeta() < 0.002) continue;
115  if(elpt>ptElecMin) {
116  NtotalElectrons++;
117  nElecPassingCut++;
118  if(electron.mva_e_pi()>-0.1) NmvaElectrons++;
119  }
120  LogDebug("LeptonRecoSkim") << "elpt = " << elpt << endl;
121  // } // closes if (electron.ecalDrivenSeed()) {
122  }
123  if(nElecPassingCut>=nSelectedElectrons) ElectronCutPassed = true;
124  }
125  else ElectronCutPassed = true;
126 
128  int nPfElecPassingCut = 0;
129  for(unsigned int i=0; i<thePfCandidateCollection->size(); i++) {
130  const reco::PFCandidate& thePfCandidate = (*thePfCandidateCollection)[i];
131  if(thePfCandidate.particleId()!=reco::PFCandidate::e) continue;
132  if(thePfCandidate.gsfTrackRef().isNull()) continue;
133  float pfelpt = thePfCandidate.pt();
134  // if (electron.sigmaIetaIeta() < 0.002) continue;
135  if(pfelpt>ptPfElecMin) nPfElecPassingCut++;
136  LogDebug("LeptonRecoSkim") << "pfelpt = " << pfelpt << endl;
137  }
138  if(nPfElecPassingCut>=nSelectedPfElectrons) PfElectronCutPassed = true;
139  }
140  else PfElectronCutPassed = true;
141 
142 
143 
144  if(useMuonSelection) {
145  int nMuonPassingCut = 0;
146  for(unsigned int i=0; i<theMuonCollection->size(); i++) {
147  Muon muon = (*theMuonCollection)[i];
148  if(! (muon.isGlobalMuon() || muon.isTrackerMuon()) ) continue;
149  const TrackRef siTrack = muon.innerTrack();
150  const TrackRef globalTrack = muon.globalTrack();
151  float muonpt;
152  float ptMuonMin;
153  // if (siTrack.isNonnull() && globalTrack.isNonnull()) {
154  if (muon.isGlobalMuon() && muon.isTrackerMuon()) {
155  muonpt = max(siTrack->pt(), globalTrack->pt());
156  ptMuonMin = ptGlobalMuonMin;
157  }
158  else if (muon.isGlobalMuon() && !(muon.isTrackerMuon())) {
159  muonpt = globalTrack->pt();
160  ptMuonMin = ptGlobalMuonMin;
161  }
162  else if (muon.isTrackerMuon() && !(muon.isGlobalMuon())) {
163  muonpt = siTrack->pt();
164  ptMuonMin = ptTrackerMuonMin;
165  }
166  else {
167  muonpt = 0; // if we get here this is a STA only muon
168  ptMuonMin = 999999.;
169  }
170  if(muonpt>ptMuonMin) nMuonPassingCut++;
171  LogDebug("RecoSelectorCuts") << "muonpt = " << muonpt << endl;
172  }
173  if(nMuonPassingCut>=nSelectedMuons) MuonCutPassed = true;
174  }
175  else MuonCutPassed = true;
176 
177  if(useHtSelection) {
178  double Ht = 0;
179  for(unsigned int i=0; i<theCaloJetCollection->size(); i++) {
180  // if((*theCaloJetCollection)[i].eta()<2.6 && (*theCaloJetCollection)[i].emEnergyFraction() <= 0.01) continue;
181  if((*theCaloJetCollection)[i].pt()>htJetThreshold) Ht += (*theCaloJetCollection)[i].pt();
182  }
183  if(Ht>htMin) HtCutPassed = true;
184  }
185  else HtCutPassed = true;
186 
187  if(usePFHtSelection) {
188  double PFHt = 0;
189  for(unsigned int i=0; i<thePFJetCollection->size(); i++) {
190  if((*thePFJetCollection)[i].pt()>pfHtJetThreshold) PFHt += (*thePFJetCollection)[i].pt();
191  }
192  if(PFHt>pfHtMin) PFHtCutPassed = true;
193  }
194  else PFHtCutPassed = true;
195 
196 
197  if(PfElectronCutPassed &&
199  MuonCutPassed &&
200  HtCutPassed &&
201  PFHtCutPassed ) accept = true;
202 
203  if(accept) NeventsFiltered++;
204 
205  firstEvent = false;
206  return accept;
207 
208 
209 
210 }
211 
212 // ------------ method called once each job just before starting event loop ------------
213 void
215 {
216  firstEvent = true;
217 }
218 
219 // ------------ method called once each job just after ending the event loop ------------
220 void
222  cout << "Filter Name = " << filterName << endl;
223  cout << "Total number of events = " << NeventsTotal << endl;
224  cout << "Total HLT_Mu9 = " << NHltMu9 << endl;
225  cout << "Total HLT_DoubleMu3 = " << NHltDiMu3 << endl;
226  cout << "Filtered events = " << NeventsFiltered << endl;
227  cout << "Filter Efficiency = " << (float)NeventsFiltered / (float)NeventsTotal << endl;
228  cout << endl;
229  cout << "N total electrons = " << NtotalElectrons << endl;
230  cout << "N mva>-0.1 electrons = " << NmvaElectrons << endl;
231  cout << endl;
232  cout << endl;
233 }
234 
235 
236 
237 
239 {
240  //Get the electrons
241  Handle<GsfElectronCollection> theElectronCollectionHandle;
242  iEvent.getByLabel(m_electronSrc, theElectronCollectionHandle);
243  theElectronCollection = theElectronCollectionHandle.product();
244 
245  //Get the pf electrons
246  Handle<reco::PFCandidateCollection> thePfCandidateHandle;
247  iEvent.getByLabel(m_pfelectronSrc, thePfCandidateHandle);
248  thePfCandidateCollection = thePfCandidateHandle.product();
249 
250  //Get the Muons
251  Handle<MuonCollection> theMuonCollectionHandle;
252  iEvent.getByLabel(m_muonSrc, theMuonCollectionHandle);
253  theMuonCollection = theMuonCollectionHandle.product();
254 
255  //Get the CaloJets
256  Handle<CaloJetCollection> theCaloJetCollectionHandle;
257  iEvent.getByLabel(m_jetsSrc, theCaloJetCollectionHandle);
258  theCaloJetCollection = theCaloJetCollectionHandle.product();
259 
260  //Get the PfJets
261  Handle<PFJetCollection> thePFJetCollectionHandle;
262  iEvent.getByLabel(m_pfjetsSrc, thePFJetCollectionHandle);
263  thePFJetCollection = thePFJetCollectionHandle.product();
264 
265  //Get the ECAL rechhits to clean the spikes
266 // Get EB RecHits
267  edm::Handle<EcalRecHitCollection> ebRecHitsHandle;
268  iEvent.getByLabel(m_ebRecHitsSrc, ebRecHitsHandle);
269  theEcalBarrelCollection = ebRecHitsHandle.product();
270 // Get EE RecHits
271  edm::Handle<EcalRecHitCollection> eeRecHitsHandle;
272  iEvent.getByLabel(m_eeRecHitsSrc, eeRecHitsHandle);
273  theEcalEndcapCollection = eeRecHitsHandle.product();
274 
275 // Get topology for spike cleaning
276  edm::ESHandle<CaloGeometry> geometryHandle;
277  iSetup.get<CaloGeometryRecord>().get(geometryHandle);
278  theCaloGeometry = geometryHandle.product();
279 // theCaloBarrelSubdetTopology = new EcalBarrelTopology(geometryHandle);
280 // theCaloEndcapSubdetTopology = new EcalEndcapTopology(geometryHandle);
281 
282  edm::ESHandle<CaloTopology> pTopology;
283  iSetup.get<CaloTopologyRecord>().get(pTopology);
284  theCaloTopology = pTopology.product();
285 
286 
287 
288 
289 }
290 
291 
292 
293 
294 //define this as a plug-in
#define LogDebug(id)
const reco::CaloJetCollection * theCaloJetCollection
std::string filterName
edm::InputTag m_ebRecHitsSrc
void handleObjects(const edm::Event &, const edm::EventSetup &iSetup)
virtual TrackRef innerTrack() const
Definition: Muon.h:48
void endJob() override
edm::InputTag m_eeRecHitsSrc
bool filter(edm::Event &, const edm::EventSetup &) override
bool usePfElectronSelection
const reco::PFCandidateCollection * thePfCandidateCollection
double pt() const final
transverse momentum
edm::InputTag m_pfelectronSrc
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
edm::InputTag m_pfjetsSrc
bool isTrackerMuon() const override
Definition: Muon.h:292
double ptTrackerMuonMin
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Definition: Muon.py:1
const reco::GsfElectronCollection * theElectronCollection
void beginJob() override
bool isGlobalMuon() const override
Definition: Muon.h:291
bool useElectronSelection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
bool isNull() const
Checks for null.
Definition: Ref.h:248
edm::InputTag m_jetsSrc
edm::InputTag m_muonSrc
T const * product() const
Definition: Handle.h:74
const reco::MuonCollection * theMuonCollection
float mva_e_pi() const
Definition: GsfElectron.h:702
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
fixed size matrix
const EcalRecHitCollection * theEcalBarrelCollection
HLT enums.
T get() const
Definition: EventSetup.h:71
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:480
~LeptonRecoSkim() override
LeptonRecoSkim(const edm::ParameterSet &)
const reco::PFJetCollection * thePFJetCollection
edm::InputTag m_electronSrc
double ptGlobalMuonMin
virtual ParticleType particleId() const
Definition: PFCandidate.h:374
T const * product() const
Definition: ESHandle.h:86
const CaloGeometry * theCaloGeometry
double pfHtJetThreshold
const CaloTopology * theCaloTopology
const EcalRecHitCollection * theEcalEndcapCollection
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54