File indexing completed on 2024-07-16 02:43:04
0001
0002 #ifndef PHASE2GMT_SAMUONGHOSTCLEANER
0003 #define PHASE2GMT_SAMUONGHOSTCLEANER
0004
0005
0006 #include <memory>
0007 #include <sstream>
0008
0009
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 #include "FWCore/Framework/interface/stream/EDProducer.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/Utilities/interface/StreamID.h"
0016 #include "DataFormats/L1Trigger/interface/Muon.h"
0017 #include "DataFormats/L1TMuonPhase2/interface/SAMuon.h"
0018 #include "L1Trigger/Phase2L1GMT/interface/SAMuonCleaner.h"
0019
0020
0021
0022 using namespace Phase2L1GMT;
0023 using namespace l1t;
0024
0025 class Phase2L1TGMTSAMuonGhostCleaner : public edm::stream::EDProducer<> {
0026 public:
0027 explicit Phase2L1TGMTSAMuonGhostCleaner(const edm::ParameterSet&);
0028 ~Phase2L1TGMTSAMuonGhostCleaner() override = default;
0029
0030 private:
0031 void produce(edm::Event&, const edm::EventSetup&) override;
0032
0033 std::vector<l1t::SAMuon> prodMuons(std::vector<l1t::SAMuon>& muons);
0034
0035
0036 edm::EDGetTokenT<std::vector<l1t::SAMuon> > barrelTokenPrompt_;
0037 edm::EDGetTokenT<std::vector<l1t::SAMuon> > barrelTokenDisp_;
0038 edm::EDGetTokenT<std::vector<l1t::SAMuon> > fwdTokenPrompt_;
0039 edm::EDGetTokenT<std::vector<l1t::SAMuon> > fwdTokenDisp_;
0040
0041 SAMuonCleaner ghostCleaner;
0042 };
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 Phase2L1TGMTSAMuonGhostCleaner::Phase2L1TGMTSAMuonGhostCleaner(const edm::ParameterSet& iConfig)
0055 : barrelTokenPrompt_(consumes<std::vector<l1t::SAMuon> >(iConfig.getParameter<edm::InputTag>("barrelPrompt"))),
0056 barrelTokenDisp_(consumes<std::vector<l1t::SAMuon> >(iConfig.getParameter<edm::InputTag>("barrelDisp"))),
0057 fwdTokenPrompt_(consumes<std::vector<l1t::SAMuon> >(iConfig.getParameter<edm::InputTag>("forwardPrompt"))),
0058 fwdTokenDisp_(consumes<std::vector<l1t::SAMuon> >(iConfig.getParameter<edm::InputTag>("forwardDisp"))) {
0059 produces<std::vector<l1t::SAMuon> >("prompt");
0060 produces<std::vector<l1t::SAMuon> >("displaced");
0061 }
0062
0063
0064
0065
0066
0067 std::vector<l1t::SAMuon> Phase2L1TGMTSAMuonGhostCleaner::prodMuons(std::vector<l1t::SAMuon>& muons) {
0068 std::vector<l1t::SAMuon> cleanedMuons = ghostCleaner.cleanTFMuons(muons);
0069
0070 std::vector<l1t::SAMuon> finalMuons;
0071 for (const auto& mu : cleanedMuons) {
0072 l1t::SAMuon m = mu;
0073 if (m.tfType() == l1t::tftype::bmtf)
0074 m.setHwQual(m.hwQual() >> 4);
0075 int bstart = 0;
0076 wordtype word(0);
0077 bstart = wordconcat<wordtype>(word, bstart, m.hwPt() > 0, 1);
0078 bstart = wordconcat<wordtype>(word, bstart, m.hwPt(), BITSGTPT);
0079 bstart = wordconcat<wordtype>(word, bstart, m.hwPhi(), BITSGTPHI);
0080 bstart = wordconcat<wordtype>(word, bstart, m.hwEta(), BITSGTETA);
0081 bstart = wordconcat<wordtype>(word, bstart, m.hwZ0(), BITSSAZ0);
0082 bstart = wordconcat<wordtype>(word, bstart, m.hwD0(), BITSSAD0);
0083 bstart = wordconcat<wordtype>(word, bstart, m.hwCharge(), 1);
0084 bstart = wordconcat<wordtype>(word, bstart, m.hwQual(), BITSSAQUAL);
0085 m.setWord(word);
0086 finalMuons.push_back(m);
0087 }
0088 return finalMuons;
0089 }
0090
0091
0092 void Phase2L1TGMTSAMuonGhostCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0093 using namespace edm;
0094
0095 edm::Handle<std::vector<l1t::SAMuon> > barrelPrompt;
0096 iEvent.getByToken(barrelTokenPrompt_, barrelPrompt);
0097
0098 edm::Handle<std::vector<l1t::SAMuon> > barrelDisp;
0099 iEvent.getByToken(barrelTokenDisp_, barrelDisp);
0100
0101 edm::Handle<std::vector<l1t::SAMuon> > forwardPrompt;
0102 iEvent.getByToken(fwdTokenPrompt_, forwardPrompt);
0103
0104 edm::Handle<std::vector<l1t::SAMuon> > forwardDisp;
0105 iEvent.getByToken(fwdTokenDisp_, forwardDisp);
0106
0107
0108 std::vector<l1t::SAMuon> muons = *barrelPrompt.product();
0109 muons.insert(muons.end(), forwardPrompt->begin(), forwardPrompt->end());
0110 std::vector<l1t::SAMuon> finalPrompt = prodMuons(muons);
0111
0112
0113 muons.clear();
0114 muons = *barrelDisp.product();
0115 muons.insert(muons.end(), forwardDisp->begin(), forwardDisp->end());
0116 std::vector<l1t::SAMuon> finalDisp = prodMuons(muons);
0117
0118 std::unique_ptr<std::vector<l1t::SAMuon> > prompt_ptr = std::make_unique<std::vector<l1t::SAMuon> >(finalPrompt);
0119 std::unique_ptr<std::vector<l1t::SAMuon> > disp_ptr = std::make_unique<std::vector<l1t::SAMuon> >(finalDisp);
0120 iEvent.put(std::move(prompt_ptr), "prompt");
0121 iEvent.put(std::move(disp_ptr), "displaced");
0122 }
0123
0124 DEFINE_FWK_MODULE(Phase2L1TGMTSAMuonGhostCleaner);
0125
0126 #endif