File indexing completed on 2024-09-07 04:37:07
0001
0002
0003
0004 #include "L1Trigger/TrackFindingTMTT/interface/MuxHToutputs.h"
0005 #include "L1Trigger/TrackFindingTMTT/interface/Settings.h"
0006 #include "L1Trigger/TrackFindingTMTT/interface/PrintL1trk.h"
0007
0008 #include "FWCore/Utilities/interface/Exception.h"
0009
0010 #include <sstream>
0011 #include <mutex>
0012
0013 using namespace std;
0014
0015 namespace tmtt {
0016
0017
0018
0019 MuxHToutputs::MuxHToutputs(const Settings* settings)
0020 : settings_(settings),
0021 muxOutputsHT_(static_cast<MuxAlgoName>(settings_->muxOutputsHT())),
0022 numPhiNonants_(settings_->numPhiNonants()),
0023 numPhiSectors_(settings_->numPhiSectors()),
0024 numPhiSecPerNon_(numPhiSectors_ / numPhiNonants_),
0025 numEtaRegions_(settings_->numEtaRegions()),
0026 busySectorKill_(settings_->busySectorKill()),
0027 busySectorNumStubs_(settings_->busySectorNumStubs()),
0028 busySectorMbinRanges_(
0029 settings_->busySectorMbinRanges()),
0030 busySectorUseMbinRanges_(not busySectorMbinRanges_.empty())
0031 {
0032
0033 if (numPhiSectors_ % numPhiNonants_ != 0)
0034 throw cms::Exception("BadConfig")
0035 << "MuxHToutputs: Number of phi sectors is not a multiple of number of nonants!";
0036
0037 if (!busySectorUseMbinRanges_)
0038 throw cms::Exception("BadConfig") << "MuxHToutputs: The implemented MUX algorithm requires you to be using the "
0039 "busySectorMbinRanges cfg option!";
0040
0041
0042 this->sanityCheck();
0043
0044 std::stringstream text;
0045 text << "=== The R-PHI HT output is multiplexed onto " << this->numLinksPerNonant()
0046 << " pairs of opto-links per nonant.";
0047 static std::once_flag printOnce;
0048 std::call_once(printOnce, [](string t) { PrintL1trk() << t; }, text.str());
0049 }
0050
0051
0052
0053
0054
0055
0056 void MuxHToutputs::exec(Array2D<unique_ptr<HTrphi>>& mHtRphis) const {
0057
0058
0059
0060
0061
0062
0063 for (unsigned int iPhiNon = 0; iPhiNon < numPhiNonants_; iPhiNon++) {
0064 vector<unsigned int> numStubsPerLink(this->numLinksPerNonant(), 0);
0065
0066 for (unsigned int iSecInNon = 0; iSecInNon < numPhiSecPerNon_; iSecInNon++) {
0067 unsigned int iPhiSec = iPhiNon * numPhiSecPerNon_ + iSecInNon;
0068
0069 for (unsigned int iEtaReg = 0; iEtaReg < numEtaRegions_; iEtaReg++) {
0070 HTrphi* htRphi = mHtRphis(iPhiSec, iEtaReg).get();
0071
0072 list<L1track2D> keptTracks;
0073 const list<L1track2D>& tracks = htRphi->trackCands2D();
0074
0075 for (const L1track2D& trk : tracks) {
0076 L1track2D trkTmp = trk;
0077 unsigned int nStubs = trkTmp.numStubs();
0078 unsigned int mBinRange = htRphi->getMbinRange(trkTmp);
0079
0080 unsigned int link = this->linkID(iSecInNon, iEtaReg, mBinRange);
0081
0082 trkTmp.setOptoLinkID(link);
0083
0084 numStubsPerLink[link] += nStubs;
0085
0086 bool keep = ((not busySectorKill_) || (numStubsPerLink[link] <= busySectorNumStubs_));
0087
0088
0089 if (keep)
0090 keptTracks.push_back(trkTmp);
0091 }
0092
0093
0094 htRphi->replaceTrackCands2D(keptTracks);
0095 }
0096 }
0097 }
0098 }
0099
0100
0101
0102 unsigned int MuxHToutputs::muxFactor() const {
0103 if (muxOutputsHT_ == MuxAlgoName::mBinPerLink) {
0104 return numEtaRegions_ * numPhiSecPerNon_;
0105 } else {
0106 throw cms::Exception("BadConfig") << "MuxHToutputs: Unknown MuxOutputsHT configuration option!";
0107 }
0108 }
0109
0110
0111
0112
0113 unsigned int MuxHToutputs::linkID(unsigned int iSecInNon, unsigned int iEtaReg, unsigned int mBinRange) const {
0114 unsigned int link;
0115
0116 if (muxOutputsHT_ == MuxAlgoName::mBinPerLink) {
0117
0118
0119 link = 0;
0120 link += mBinRange;
0121
0122 } else {
0123 throw cms::Exception("BadConfig") << "MuxHToutputs: Unknown MuxOutputsHT configuration option!";
0124 }
0125
0126 if (link >= this->numLinksPerNonant())
0127 throw cms::Exception("LogicError") << "MuxHToutputs: Calculated link ID exceeded expected number of links! "
0128 << link << " " << this->numLinksPerNonant();
0129 return link;
0130 }
0131
0132
0133
0134 void MuxHToutputs::sanityCheck() {
0135 if (numPhiSecPerNon_ * numEtaRegions_ % this->muxFactor() != 0)
0136 throw cms::Exception("LogicError")
0137 << "MuxHToutputs: Number of sectors per phi nonant is not a multiple of muxFactor().";
0138
0139 vector<unsigned int> nObsElementsPerLink(this->numLinksPerNonant(), 0);
0140 for (unsigned int iSecInNon = 0; iSecInNon < numPhiSecPerNon_; iSecInNon++) {
0141 for (unsigned int iEtaReg = 0; iEtaReg < numEtaRegions_; iEtaReg++) {
0142 unsigned int iCorr = (settings_->miniHTstage()) ? 1 : 0;
0143 for (unsigned int mBinRange = 0; mBinRange < busySectorMbinRanges_.size() - iCorr; mBinRange++) {
0144 unsigned int link = this->linkID(iSecInNon, iEtaReg, mBinRange);
0145 nObsElementsPerLink[link] += 1;
0146 }
0147 }
0148 }
0149 }
0150
0151 }