File indexing completed on 2024-04-06 12:26:44
0001
0002
0003
0004 #include <memory>
0005 #include <iostream>
0006
0007
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
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
0033
0034 const double eOverPMax_;
0035
0036 const bool debug_;
0037
0038 const bool taggingMode_;
0039 };
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 GreedyMuonPFCandidateFilter::GreedyMuonPFCandidateFilter(const edm::ParameterSet& iConfig)
0053
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
0064
0065
0066
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
0082 if (cand.particleId() != reco::PFCandidate::mu)
0083 continue;
0084
0085 if (!PFMuonAlgo::isIsolatedMuon(cand.muonRef()))
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
0119 DEFINE_FWK_MODULE(GreedyMuonPFCandidateFilter);