diff --git a/L1Trigger/Phase2L1GMT/interface/TPSAlgorithm.h b/L1Trigger/Phase2L1GMT/interface/TPSAlgorithm.h index bec3898fc1086..c3d566cf61e10 100644 --- a/L1Trigger/Phase2L1GMT/interface/TPSAlgorithm.h +++ b/L1Trigger/Phase2L1GMT/interface/TPSAlgorithm.h @@ -20,7 +20,7 @@ namespace Phase2L1GMT { const unsigned int PHIDIVIDER = 1 << (BITSPHI - BITSSTUBCOORD); const unsigned int ETADIVIDER = 1 << (BITSETA - BITSSTUBETA); - typedef struct { + struct propagation_t { ap_int coord1; ap_uint sigma_coord1; ap_int coord2; @@ -30,47 +30,49 @@ namespace Phase2L1GMT { ap_uint sigma_eta2; ap_uint<1> valid; ap_uint<1> is_barrel; - } propagation_t; + }; - typedef struct { + struct match_t { ap_uint quality; ap_uint id; ap_uint<2> valid; - bool isGlobal; + bool isGlobal = false; l1t::SAMuonRef muRef; l1t::MuonStubRef stubRef; - - } match_t; + }; class TPSAlgorithm { public: - TPSAlgorithm(const edm::ParameterSet& iConfig); - ~TPSAlgorithm(); + explicit TPSAlgorithm(const edm::ParameterSet& iConfig); + TPSAlgorithm() = delete; + ~TPSAlgorithm() = default; std::vector processNonant(const std::vector& convertedTracks, - const l1t::MuonStubRefVector& stubs); + const l1t::MuonStubRefVector& stubs) const; std::vector cleanNeighbor(const std::vector& muons, const std::vector& muonsPrevious, const std::vector& muonsNext, - bool equality); - std::vector convert(std::vector& muons, uint maximum); - bool outputGT(std::vector& muons); - void SetQualityBits(std::vector& muons); - std::vector sort(std::vector& muons, uint maximum); + bool equality) const; + std::vector convert(const std::vector& muons, uint maximum) const; + bool outputGT(std::vector& muons) const; + void SetQualityBits(std::vector& muons) const; + std::vector sort(std::vector& muons, uint maximum) const; private: int verbose_; - propagation_t propagate(const ConvertedTTTrack& track, uint layer); - ap_uint deltaEta(const ap_int& eta1, const ap_int& eta2); - ap_uint deltaCoord(const ap_int& phi1, const ap_int& phi2); - match_t match(const propagation_t prop, const l1t::MuonStubRef& stub, uint trackID); - match_t propagateAndMatch(const ConvertedTTTrack& track, const l1t::MuonStubRef& stub, uint trackID); - match_t getBest(const std::vector matches); - PreTrackMatchedMuon processTrack(const ConvertedTTTrack&, const l1t::MuonStubRefVector&); - ap_uint<5> cleanMuon(const PreTrackMatchedMuon& mu, const PreTrackMatchedMuon& other, bool eq); - void matchingInfos(std::vector matchInfo, PreTrackMatchedMuon& muon, ap_uint& quality); - std::vector clean(std::vector& muons); + propagation_t propagate(const ConvertedTTTrack& track, uint layer) const; + ap_uint deltaEta(const ap_int& eta1, const ap_int& eta2) const; + ap_uint deltaCoord(const ap_int& phi1, const ap_int& phi2) const; + match_t match(const propagation_t prop, const l1t::MuonStubRef& stub, uint trackID) const; + match_t propagateAndMatch(const ConvertedTTTrack& track, const l1t::MuonStubRef& stub, uint trackID) const; + match_t getBest(const std::vector& matches) const; + PreTrackMatchedMuon processTrack(const ConvertedTTTrack&, const l1t::MuonStubRefVector&) const; + ap_uint<5> cleanMuon(const PreTrackMatchedMuon& mu, const PreTrackMatchedMuon& other, bool eq) const; + void matchingInfos(const std::vector& matchInfo, + PreTrackMatchedMuon& muon, + ap_uint& quality) const; + std::vector clean(const std::vector& muons) const; }; } // namespace Phase2L1GMT diff --git a/L1Trigger/Phase2L1GMT/src/TPSAlgorithm.cc b/L1Trigger/Phase2L1GMT/src/TPSAlgorithm.cc index ae0b40edff5d9..24e3af10b1282 100644 --- a/L1Trigger/Phase2L1GMT/src/TPSAlgorithm.cc +++ b/L1Trigger/Phase2L1GMT/src/TPSAlgorithm.cc @@ -4,10 +4,8 @@ using namespace Phase2L1GMT; TPSAlgorithm::TPSAlgorithm(const edm::ParameterSet& iConfig) : verbose_(iConfig.getParameter("verbose")) {} -TPSAlgorithm::~TPSAlgorithm() {} - std::vector TPSAlgorithm::processNonant(const std::vector& convertedTracks, - const l1t::MuonStubRefVector& stubs) { + const l1t::MuonStubRefVector& stubs) const { std::vector preMuons; for (const auto& track : convertedTracks) { PreTrackMatchedMuon mu = processTrack(track, stubs); @@ -21,7 +19,7 @@ std::vector TPSAlgorithm::processNonant(const std::vector TPSAlgorithm::cleanNeighbor(const std::vector& muons, const std::vector& muonsPrevious, const std::vector& muonsNext, - bool equality) { + bool equality) const { std::vector out; if (muons.empty()) @@ -55,7 +53,7 @@ std::vector TPSAlgorithm::cleanNeighbor(const std::vector

TPSAlgorithm::convert(std::vector& muons, uint maximum) { +std::vector TPSAlgorithm::convert(const std::vector& muons, uint maximum) const { std::vector out; for (const auto& mu : muons) { if (out.size() == maximum) @@ -83,7 +81,7 @@ std::vector TPSAlgorithm::convert(std::vector& muons) { +void TPSAlgorithm::SetQualityBits(std::vector& muons) const { for (auto& mu : muons) { // A preliminary suggestion. Need feedback from the menu group bool veryloose = mu.numberOfMatches() > 0; @@ -96,7 +94,7 @@ void TPSAlgorithm::SetQualityBits(std::vector& muons) { } } -bool TPSAlgorithm::outputGT(std::vector& muons) { +bool TPSAlgorithm::outputGT(std::vector& muons) const { for (auto& mu : muons) { wordtype word1 = 0; wordtype word2 = 0; @@ -121,22 +119,17 @@ bool TPSAlgorithm::outputGT(std::vector& muons) { return true; } -std::vector TPSAlgorithm::sort(std::vector& muons, uint maximum) { +std::vector TPSAlgorithm::sort(std::vector& muons, uint maximum) const { if (muons.size() < 2) return muons; std::sort(muons.begin(), muons.end(), [](l1t::TrackerMuon a, l1t::TrackerMuon b) { return a.hwPt() > b.hwPt(); }); - std::vector out; - for (unsigned int i = 0; i < muons.size(); ++i) { - out.push_back(muons[i]); - if (i == (maximum - 1)) - break; - } + std::vector out{muons.begin(), muons.begin() + (maximum < muons.size() ? maximum : muons.size())}; return out; } -propagation_t TPSAlgorithm::propagate(const ConvertedTTTrack& track, uint layer) { +propagation_t TPSAlgorithm::propagate(const ConvertedTTTrack& track, uint layer) const { static const std::array*, 5> lt_prop_coord1 = { {lt_prop_coord1_0, lt_prop_coord1_1, lt_prop_coord1_2, lt_prop_coord1_3, lt_prop_coord1_4}}; static const std::array*, 5> lt_prop_coord2 = { @@ -255,7 +248,8 @@ propagation_t TPSAlgorithm::propagate(const ConvertedTTTrack& track, uint layer) return out; } -ap_uint TPSAlgorithm::deltaEta(const ap_int& eta1, const ap_int& eta2) { +ap_uint TPSAlgorithm::deltaEta(const ap_int& eta1, + const ap_int& eta2) const { ap_fixed dEta = eta1 - eta2; if (dEta < 0) return ap_uint(-dEta); @@ -264,7 +258,7 @@ ap_uint TPSAlgorithm::deltaEta(const ap_int& eta1 } ap_uint TPSAlgorithm::deltaCoord(const ap_int& phi1, - const ap_int& phi2) { + const ap_int& phi2) const { ap_int dPhiRoll = phi1 - phi2; ap_ufixed dPhi; if (dPhiRoll < 0) @@ -275,7 +269,7 @@ ap_uint TPSAlgorithm::deltaCoord(const ap_int return ap_uint(dPhi); } -match_t TPSAlgorithm::match(const propagation_t prop, const l1t::MuonStubRef& stub, uint trackID) { +match_t TPSAlgorithm::match(const propagation_t prop, const l1t::MuonStubRef& stub, uint trackID) const { if (verbose_ == 1) { edm::LogInfo("TPSAlgo") << "Matching to coord1=" << stub->coord1() << " coord2=" << stub->coord2() << " eta1=" << stub->eta1() << " eta2=" << stub->eta2(); @@ -385,12 +379,14 @@ match_t TPSAlgorithm::match(const propagation_t prop, const l1t::MuonStubRef& st return out; } -match_t TPSAlgorithm::propagateAndMatch(const ConvertedTTTrack& track, const l1t::MuonStubRef& stub, uint trackID) { +match_t TPSAlgorithm::propagateAndMatch(const ConvertedTTTrack& track, + const l1t::MuonStubRef& stub, + uint trackID) const { propagation_t prop = propagate(track, stub->tfLayer()); return match(prop, stub, trackID); } -match_t TPSAlgorithm::getBest(const std::vector matches) { +match_t TPSAlgorithm::getBest(const std::vector& matches) const { match_t best = matches[0]; for (const auto& m : matches) { if (m.quality > best.quality) @@ -400,9 +396,9 @@ match_t TPSAlgorithm::getBest(const std::vector matches) { return best; } -void TPSAlgorithm::matchingInfos(std::vector matchInfo, +void TPSAlgorithm::matchingInfos(const std::vector& matchInfo, PreTrackMatchedMuon& muon, - ap_uint& quality) { + ap_uint& quality) const { if (!matchInfo.empty()) { match_t b = getBest(matchInfo); if (b.valid != 0) { @@ -414,7 +410,8 @@ void TPSAlgorithm::matchingInfos(std::vector matchInfo, } } -PreTrackMatchedMuon TPSAlgorithm::processTrack(const ConvertedTTTrack& track, const l1t::MuonStubRefVector& stubs) { +PreTrackMatchedMuon TPSAlgorithm::processTrack(const ConvertedTTTrack& track, + const l1t::MuonStubRefVector& stubs) const { std::array, 6> matchInfos; if (verbose_ == 1 && !stubs.empty()) { @@ -478,7 +475,7 @@ PreTrackMatchedMuon TPSAlgorithm::processTrack(const ConvertedTTTrack& track, co return muon; } -ap_uint<5> TPSAlgorithm::cleanMuon(const PreTrackMatchedMuon& mu, const PreTrackMatchedMuon& other, bool eq) { +ap_uint<5> TPSAlgorithm::cleanMuon(const PreTrackMatchedMuon& mu, const PreTrackMatchedMuon& other, bool eq) const { ap_uint<5> valid = 0; ap_uint<5> overlap = 0; constexpr int bittest = 0xfff; // 4095, corresponding to 11bits @@ -514,7 +511,7 @@ ap_uint<5> TPSAlgorithm::cleanMuon(const PreTrackMatchedMuon& mu, const PreTrack return valid; } -std::vector TPSAlgorithm::clean(std::vector& muons) { +std::vector TPSAlgorithm::clean(const std::vector& muons) const { std::vector out; if (muons.empty()) return out;