Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-01 01:02:22

0001 
0002 
0003 // system include files
0004 #include <memory>
0005 #include <iostream>
0006 
0007 // user include files
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/global/EDFilter.h"
0010 
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 
0016 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0017 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0018 #include "RecoParticleFlow/PFProducer/interface/PFMuonAlgo.h"
0019 
0020 //
0021 // class declaration
0022 //
0023 
0024 class GreedyMuonPFCandidateFilter : public edm::global::EDFilter<> {
0025 public:
0026   explicit GreedyMuonPFCandidateFilter(const edm::ParameterSet&);
0027 
0028 private:
0029   bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0030 
0031   const edm::EDGetTokenT<reco::PFCandidateCollection> tokenPFCandidates_;
0032   // ----------member data ---------------------------
0033 
0034   const double eOverPMax_;
0035 
0036   const bool debug_;
0037 
0038   const bool taggingMode_;
0039 };
0040 
0041 //
0042 // constants, enums and typedefs
0043 //
0044 
0045 //
0046 // static data member definitions
0047 //
0048 
0049 //
0050 // constructors and destructor
0051 //
0052 GreedyMuonPFCandidateFilter::GreedyMuonPFCandidateFilter(const edm::ParameterSet& iConfig)
0053     //now do what ever initialization is needed
0054     : tokenPFCandidates_(consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("PFCandidates"))),
0055       eOverPMax_(iConfig.getParameter<double>("eOverPMax")),
0056       debug_(iConfig.getParameter<bool>("debug")),
0057       taggingMode_(iConfig.getParameter<bool>("taggingMode")) {
0058   produces<bool>();
0059   produces<reco::PFCandidateCollection>("muons");
0060 }
0061 
0062 //
0063 // member functions
0064 //
0065 
0066 // ------------ method called on each new Event  ------------
0067 bool GreedyMuonPFCandidateFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0068   using namespace std;
0069   using namespace edm;
0070 
0071   Handle<reco::PFCandidateCollection> pfCandidates;
0072   iEvent.getByToken(tokenPFCandidates_, pfCandidates);
0073 
0074   bool foundMuon = false;
0075 
0076   auto pOutputCandidateCollection = std::make_unique<reco::PFCandidateCollection>();
0077 
0078   for (unsigned i = 0; i < pfCandidates->size(); i++) {
0079     const reco::PFCandidate& cand = (*pfCandidates)[i];
0080 
0081     //    if( cand.particleId() != 3 ) // not a muon
0082     if (cand.particleId() != reco::PFCandidate::mu)  // not a muon
0083       continue;
0084 
0085     if (!PFMuonAlgo::isIsolatedMuon(cand.muonRef()))  // muon is not isolated
0086       continue;
0087 
0088     double totalCaloEnergy = cand.rawEcalEnergy() + cand.rawHcalEnergy();
0089     double eOverP = totalCaloEnergy / cand.p();
0090 
0091     if (eOverP < eOverPMax_)
0092       continue;
0093 
0094     foundMuon = true;
0095 
0096     pOutputCandidateCollection->push_back(cand);
0097 
0098     if (debug_) {
0099       cout << cand << " HCAL E=" << endl;
0100       cout << "\t"
0101            << "ECAL energy " << cand.rawEcalEnergy() << endl;
0102       cout << "\t"
0103            << "HCAL energy " << cand.rawHcalEnergy() << endl;
0104       cout << "\t"
0105            << "E/p " << eOverP << endl;
0106     }
0107   }
0108 
0109   iEvent.put(std::move(pOutputCandidateCollection), "muons");
0110 
0111   bool pass = !foundMuon;
0112 
0113   iEvent.put(std::make_unique<bool>(pass));
0114 
0115   return taggingMode_ || pass;
0116 }
0117 
0118 //define this as a plug-in
0119 DEFINE_FWK_MODULE(GreedyMuonPFCandidateFilter);