CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
22 
23 using namespace edm;
24 using namespace reco;
25 using namespace std;
26 
27 //
28 // constructors and destructor
29 //
31  : hltLabel(iConfig.getParameter<edm::InputTag>("HltLabel")),
32  filterName(iConfig.getParameter<std::string>("@module_label")),
33  m_electronSrc(iConfig.getParameter<edm::InputTag>("electronCollection")),
34  m_pfelectronSrc(iConfig.getParameter<edm::InputTag>("pfElectronCollection")),
35  m_muonSrc(iConfig.getParameter<edm::InputTag>("muonCollection")),
36  m_jetsSrc(iConfig.getParameter<edm::InputTag>("caloJetCollection")),
37  m_pfjetsSrc(iConfig.getParameter<edm::InputTag>("PFJetCollection")),
38  m_ebRecHitsSrc(iConfig.getParameter<edm::InputTag>("ecalBarrelRecHitsCollection")),
39  m_eeRecHitsSrc(iConfig.getParameter<edm::InputTag>("ecalEndcapRecHitsCollection")),
40  useElectronSelection(iConfig.getParameter<bool>("UseElectronSelection")),
41  usePfElectronSelection(iConfig.getParameter<bool>("UsePfElectronSelection")),
42  useMuonSelection(iConfig.getParameter<bool>("UseMuonSelection")),
43  useHtSelection(iConfig.getParameter<bool>("UseHtSelection")),
44  usePFHtSelection(iConfig.getParameter<bool>("UsePFHtSelection")),
45  ptElecMin(iConfig.getParameter<double>("electronPtMin")),
46  ptPfElecMin(iConfig.getParameter<double>("pfElectronPtMin")),
47  nSelectedElectrons(iConfig.getParameter<int>("electronN")),
48  nSelectedPfElectrons(iConfig.getParameter<int>("pfElectronN")),
49  ptGlobalMuonMin(iConfig.getParameter<double>("globalMuonPtMin")),
50  ptTrackerMuonMin(iConfig.getParameter<double>("trackerMuonPtMin")),
51  nSelectedMuons(iConfig.getParameter<int>("muonN")),
52  htMin(iConfig.getParameter<double>("HtMin")),
53  pfHtMin(iConfig.getParameter<double>("PFHtMin")),
54  htJetThreshold(iConfig.getParameter<double>("HtJetThreshold")),
55  pfHtJetThreshold(iConfig.getParameter<double>("PFHtJetThreshold")) {
56  NeventsTotal = 0;
57  NeventsFiltered = 0;
58  NHltMu9 = 0;
59  NHltDiMu3 = 0;
60 
61  NtotalElectrons = 0;
62  NmvaElectrons = 0;
63 }
64 
66  // do anything here that needs to be done at desctruction time
67  // (e.g. close files, deallocate resources etc.)
68 }
69 
70 //
71 // member functions
72 //
73 
74 // ------------ method called on each new Event ------------
76  bool accept = false;
77 
78  NeventsTotal++;
79 
80  ElectronCutPassed = false;
81  PfElectronCutPassed = false;
82  MuonCutPassed = false;
83  HtCutPassed = false;
84  PFHtCutPassed = false;
85 
86  // edm::Handle<TriggerResults> trhv;
87  // iEvent.getByLabel(hltLabel,trhv);
88 
89  // const edm::TriggerNames& triggerNames_ = iEvent.triggerNames(*trhv);
90 
91  // if(trhv->at(triggerNames_.triggerIndex("HLT_Mu9")).accept()) NHltMu9++;
92  // if(trhv->at(triggerNames_.triggerIndex("HLT_DoubleMu3")).accept()) NHltDiMu3++;
93 
94  this->handleObjects(iEvent, iSetup);
95 
97  int nElecPassingCut = 0;
98  for (unsigned int i = 0; i < theElectronCollection->size(); i++) {
99  GsfElectron electron = (*theElectronCollection)[i];
100  // if (electron.ecalDrivenSeed()) {
101  float elpt = electron.pt();
102  // if (electron.sigmaIetaIeta() < 0.002) continue;
103  if (elpt > ptElecMin) {
104  NtotalElectrons++;
105  nElecPassingCut++;
106  if (electron.mva_e_pi() > -0.1)
107  NmvaElectrons++;
108  }
109  LogDebug("LeptonRecoSkim") << "elpt = " << elpt << endl;
110  // } // closes if (electron.ecalDrivenSeed()) {
111  }
112  if (nElecPassingCut >= nSelectedElectrons)
113  ElectronCutPassed = true;
114  } else
115  ElectronCutPassed = true;
116 
118  int nPfElecPassingCut = 0;
119  for (unsigned int i = 0; i < thePfCandidateCollection->size(); i++) {
120  const reco::PFCandidate& thePfCandidate = (*thePfCandidateCollection)[i];
121  if (thePfCandidate.particleId() != reco::PFCandidate::e)
122  continue;
123  if (thePfCandidate.gsfTrackRef().isNull())
124  continue;
125  float pfelpt = thePfCandidate.pt();
126  // if (electron.sigmaIetaIeta() < 0.002) continue;
127  if (pfelpt > ptPfElecMin)
128  nPfElecPassingCut++;
129  LogDebug("LeptonRecoSkim") << "pfelpt = " << pfelpt << endl;
130  }
131  if (nPfElecPassingCut >= nSelectedPfElectrons)
132  PfElectronCutPassed = true;
133  } else
134  PfElectronCutPassed = true;
135 
136  if (useMuonSelection) {
137  int nMuonPassingCut = 0;
138  for (unsigned int i = 0; i < theMuonCollection->size(); i++) {
139  Muon muon = (*theMuonCollection)[i];
140  if (!(muon.isGlobalMuon() || muon.isTrackerMuon()))
141  continue;
142  const TrackRef siTrack = muon.innerTrack();
143  const TrackRef globalTrack = muon.globalTrack();
144  float muonpt;
145  float ptMuonMin;
146  // if (siTrack.isNonnull() && globalTrack.isNonnull()) {
147  if (muon.isGlobalMuon() && muon.isTrackerMuon()) {
148  muonpt = max(siTrack->pt(), globalTrack->pt());
149  ptMuonMin = ptGlobalMuonMin;
150  } else if (muon.isGlobalMuon() && !(muon.isTrackerMuon())) {
151  muonpt = globalTrack->pt();
152  ptMuonMin = ptGlobalMuonMin;
153  } else if (muon.isTrackerMuon() && !(muon.isGlobalMuon())) {
154  muonpt = siTrack->pt();
155  ptMuonMin = ptTrackerMuonMin;
156  } else {
157  muonpt = 0; // if we get here this is a STA only muon
158  ptMuonMin = 999999.;
159  }
160  if (muonpt > ptMuonMin)
161  nMuonPassingCut++;
162  LogDebug("RecoSelectorCuts") << "muonpt = " << muonpt << endl;
163  }
164  if (nMuonPassingCut >= nSelectedMuons)
165  MuonCutPassed = true;
166  } else
167  MuonCutPassed = true;
168 
169  if (useHtSelection) {
170  double Ht = 0;
171  for (unsigned int i = 0; i < theCaloJetCollection->size(); i++) {
172  // if((*theCaloJetCollection)[i].eta()<2.6 && (*theCaloJetCollection)[i].emEnergyFraction() <= 0.01) continue;
173  if ((*theCaloJetCollection)[i].pt() > htJetThreshold)
174  Ht += (*theCaloJetCollection)[i].pt();
175  }
176  if (Ht > htMin)
177  HtCutPassed = true;
178  } else
179  HtCutPassed = true;
180 
181  if (usePFHtSelection) {
182  double PFHt = 0;
183  for (unsigned int i = 0; i < thePFJetCollection->size(); i++) {
184  if ((*thePFJetCollection)[i].pt() > pfHtJetThreshold)
185  PFHt += (*thePFJetCollection)[i].pt();
186  }
187  if (PFHt > pfHtMin)
188  PFHtCutPassed = true;
189  } else
190  PFHtCutPassed = true;
191 
193  accept = true;
194 
195  if (accept)
196  NeventsFiltered++;
197 
198  firstEvent = false;
199  return accept;
200 }
201 
202 // ------------ method called once each job just before starting event loop ------------
204 
205 // ------------ method called once each job just after ending the event loop ------------
207  cout << "Filter Name = " << filterName << endl;
208  cout << "Total number of events = " << NeventsTotal << endl;
209  cout << "Total HLT_Mu9 = " << NHltMu9 << endl;
210  cout << "Total HLT_DoubleMu3 = " << NHltDiMu3 << endl;
211  cout << "Filtered events = " << NeventsFiltered << endl;
212  cout << "Filter Efficiency = " << (float)NeventsFiltered / (float)NeventsTotal << endl;
213  cout << endl;
214  cout << "N total electrons = " << NtotalElectrons << endl;
215  cout << "N mva>-0.1 electrons = " << NmvaElectrons << endl;
216  cout << endl;
217  cout << endl;
218 }
219 
221  //Get the electrons
222  Handle<GsfElectronCollection> theElectronCollectionHandle;
223  iEvent.getByLabel(m_electronSrc, theElectronCollectionHandle);
224  theElectronCollection = theElectronCollectionHandle.product();
225 
226  //Get the pf electrons
227  Handle<reco::PFCandidateCollection> thePfCandidateHandle;
228  iEvent.getByLabel(m_pfelectronSrc, thePfCandidateHandle);
229  thePfCandidateCollection = thePfCandidateHandle.product();
230 
231  //Get the Muons
232  Handle<MuonCollection> theMuonCollectionHandle;
233  iEvent.getByLabel(m_muonSrc, theMuonCollectionHandle);
234  theMuonCollection = theMuonCollectionHandle.product();
235 
236  //Get the CaloJets
237  Handle<CaloJetCollection> theCaloJetCollectionHandle;
238  iEvent.getByLabel(m_jetsSrc, theCaloJetCollectionHandle);
239  theCaloJetCollection = theCaloJetCollectionHandle.product();
240 
241  //Get the PfJets
242  Handle<PFJetCollection> thePFJetCollectionHandle;
243  iEvent.getByLabel(m_pfjetsSrc, thePFJetCollectionHandle);
244  thePFJetCollection = thePFJetCollectionHandle.product();
245 
246  //Get the ECAL rechhits to clean the spikes
247  // Get EB RecHits
248  edm::Handle<EcalRecHitCollection> ebRecHitsHandle;
249  iEvent.getByLabel(m_ebRecHitsSrc, ebRecHitsHandle);
250  theEcalBarrelCollection = ebRecHitsHandle.product();
251  // Get EE RecHits
252  edm::Handle<EcalRecHitCollection> eeRecHitsHandle;
253  iEvent.getByLabel(m_eeRecHitsSrc, eeRecHitsHandle);
254  theEcalEndcapCollection = eeRecHitsHandle.product();
255 
256  // Get topology for spike cleaning
257  edm::ESHandle<CaloGeometry> geometryHandle;
258  iSetup.get<CaloGeometryRecord>().get(geometryHandle);
259  theCaloGeometry = geometryHandle.product();
260  // theCaloBarrelSubdetTopology = new EcalBarrelTopology(geometryHandle);
261  // theCaloEndcapSubdetTopology = new EcalEndcapTopology(geometryHandle);
262 
263  edm::ESHandle<CaloTopology> pTopology;
264  iSetup.get<CaloTopologyRecord>().get(pTopology);
265  theCaloTopology = pTopology.product();
266 }
267 
268 //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:45
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:299
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:298
bool PfElectronCutPassed
bool useElectronSelection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm::InputTag m_jetsSrc
edm::InputTag m_muonSrc
T const * product() const
Definition: Handle.h:69
const reco::MuonCollection * theMuonCollection
float mva_e_pi() const
Definition: GsfElectron.h:665
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:73
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:440
~LeptonRecoSkim() override
LeptonRecoSkim(const edm::ParameterSet &)
const reco::PFJetCollection * thePFJetCollection
edm::InputTag m_electronSrc
double ptGlobalMuonMin
virtual ParticleType particleId() const
Definition: PFCandidate.h:366
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:51