File indexing completed on 2024-11-05 05:20:09
0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "DataFormats/MuonReco/interface/Muon.h"
0005 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/global/EDFilter.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012
0013 class AlignmentRelCombIsoMuonSelector : public edm::global::EDFilter<> {
0014 public:
0015 explicit AlignmentRelCombIsoMuonSelector(const edm::ParameterSet&);
0016 ~AlignmentRelCombIsoMuonSelector() override = default;
0017
0018 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0019
0020 private:
0021 bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0022
0023 edm::EDGetTokenT<reco::MuonCollection> muonToken_;
0024 const double relCombIsoCut_;
0025 const bool useTrackerOnlyIsolation_;
0026 const bool filterEvents_;
0027 };
0028
0029 void AlignmentRelCombIsoMuonSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0030 edm::ParameterSetDescription desc;
0031 desc.add<edm::InputTag>("src", edm::InputTag("muons"))->setComment("Input muon collection");
0032 desc.add<double>("relCombIsoCut", 0.15)->setComment("cut on the relative combined isolation");
0033 desc.add<bool>("useTrackerOnlyIsolation", false)->setComment("use only tracker isolation");
0034 desc.add<bool>("filter", true);
0035 descriptions.addWithDefaultLabel(desc);
0036 }
0037
0038 AlignmentRelCombIsoMuonSelector::AlignmentRelCombIsoMuonSelector(const edm::ParameterSet& iConfig)
0039 : muonToken_(consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("src"))),
0040 relCombIsoCut_(iConfig.getParameter<double>("relCombIsoCut")),
0041 useTrackerOnlyIsolation_(iConfig.getParameter<bool>("useTrackerOnlyIsolation")),
0042 filterEvents_(iConfig.getParameter<bool>("filter")) {
0043 produces<reco::MuonCollection>();
0044 }
0045
0046 bool AlignmentRelCombIsoMuonSelector::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
0047 edm::Handle<reco::MuonCollection> muons;
0048 iEvent.getByToken(muonToken_, muons);
0049
0050 auto selectedMuons = std::make_unique<reco::MuonCollection>();
0051
0052 for (const auto& muon : *muons) {
0053 double relCombIso;
0054 if (useTrackerOnlyIsolation_) {
0055
0056 relCombIso = muon.isolationR03().sumPt / muon.pt();
0057 } else {
0058
0059 relCombIso = (muon.isolationR03().sumPt + muon.isolationR03().emEt + muon.isolationR03().hadEt) / muon.pt();
0060 }
0061
0062 if (relCombIso < relCombIsoCut_) {
0063 selectedMuons->push_back(muon);
0064 }
0065 }
0066
0067 const bool passEvent = !selectedMuons->empty();
0068 iEvent.put(std::move(selectedMuons));
0069
0070
0071 return filterEvents_ ? passEvent : true;
0072 }
0073
0074 #include "FWCore/Framework/interface/MakerMacros.h"
0075 DEFINE_FWK_MODULE(AlignmentRelCombIsoMuonSelector);