Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-06 09:40:16

0001 #include "DataFormats/Common/interface/Handle.h"
0002 #include "FWCore/Framework/interface/global/EDFilter.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 
0007 #include "DataFormats/Common/interface/View.h"
0008 
0009 #include "DataFormats/PatCandidates/interface/Electron.h"
0010 #include "DataFormats/PatCandidates/interface/Muon.h"
0011 #include "DataFormats/PatCandidates/interface/Tau.h"
0012 
0013 namespace pat {
0014 
0015   class PATLeptonCountFilter : public edm::global::EDFilter<> {
0016   public:
0017     explicit PATLeptonCountFilter(const edm::ParameterSet& iConfig);
0018     ~PATLeptonCountFilter() override;
0019 
0020   private:
0021     bool filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0022 
0023   private:
0024     const edm::EDGetTokenT<edm::View<Electron> > electronToken_;
0025     const edm::EDGetTokenT<edm::View<Muon> > muonToken_;
0026     const edm::EDGetTokenT<edm::View<Tau> > tauToken_;
0027     const bool countElectrons_;
0028     const bool countMuons_;
0029     const bool countTaus_;
0030     const unsigned int minNumber_;
0031     const unsigned int maxNumber_;
0032   };
0033 
0034 }  // namespace pat
0035 
0036 using namespace pat;
0037 
0038 PATLeptonCountFilter::PATLeptonCountFilter(const edm::ParameterSet& iConfig)
0039     : electronToken_(mayConsume<edm::View<Electron> >(iConfig.getParameter<edm::InputTag>("electronSource"))),
0040       muonToken_(mayConsume<edm::View<Muon> >(iConfig.getParameter<edm::InputTag>("muonSource"))),
0041       tauToken_(mayConsume<edm::View<Tau> >(iConfig.getParameter<edm::InputTag>("tauSource"))),
0042       countElectrons_(iConfig.getParameter<bool>("countElectrons")),
0043       countMuons_(iConfig.getParameter<bool>("countMuons")),
0044       countTaus_(iConfig.getParameter<bool>("countTaus")),
0045       minNumber_(iConfig.getParameter<unsigned int>("minNumber")),
0046       maxNumber_(iConfig.getParameter<unsigned int>("maxNumber")) {}
0047 
0048 PATLeptonCountFilter::~PATLeptonCountFilter() {}
0049 
0050 bool PATLeptonCountFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0051   edm::Handle<edm::View<Electron> > electrons;
0052   if (countElectrons_)
0053     iEvent.getByToken(electronToken_, electrons);
0054   edm::Handle<edm::View<Muon> > muons;
0055   if (countMuons_)
0056     iEvent.getByToken(muonToken_, muons);
0057   edm::Handle<edm::View<Tau> > taus;
0058   if (countTaus_)
0059     iEvent.getByToken(tauToken_, taus);
0060   unsigned int nrLeptons = 0;
0061   nrLeptons += (countElectrons_ ? electrons->size() : 0);
0062   nrLeptons += (countMuons_ ? muons->size() : 0);
0063   nrLeptons += (countTaus_ ? taus->size() : 0);
0064   return nrLeptons >= minNumber_ && nrLeptons <= maxNumber_;
0065 }
0066 
0067 #include "FWCore/Framework/interface/MakerMacros.h"
0068 DEFINE_FWK_MODULE(PATLeptonCountFilter);