File indexing completed on 2024-04-06 12:21:05
0001 #include <cassert>
0002 #include <iostream>
0003 #include <algorithm>
0004 #include <bitset>
0005
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007
0008 #include "L1Trigger/L1TMuonOverlap/interface/OMTFConfiguration.h"
0009 #include "L1Trigger/L1TMuonOverlap/interface/OMTFSorter.h"
0010
0011 #include "L1Trigger/RPCTrigger/interface/RPCConst.h"
0012
0013
0014 AlgoMuon OMTFSorter::sortSingleResult(const OMTFResult& aResult) {
0015 OMTFResult::vector1D pdfValsVec = aResult.getSummaryVals();
0016 OMTFResult::vector1D nHitsVec = aResult.getSummaryHits();
0017 OMTFResult::vector1D refPhiVec = aResult.getRefPhis();
0018 OMTFResult::vector1D refEtaVec = aResult.getRefEtas();
0019 OMTFResult::vector1D hitsVec = aResult.getHitsWord();
0020 OMTFResult::vector1D refPhiRHitVec = aResult.getRefPhiRHits();
0021
0022 assert(pdfValsVec.size() == nHitsVec.size());
0023
0024 unsigned int nHitsMax = 0;
0025 unsigned int pdfValMax = 0;
0026 unsigned int hitsWord = 0;
0027 int refPhi = 1024;
0028 int refEta = -10;
0029 int refLayer = -1;
0030 int refPhiRHit = 1024;
0031
0032 AlgoMuon sortedResult(pdfValMax, refPhi, refEta, refLayer, hitsWord, nHitsMax);
0033
0034
0035 for (auto itHits : nHitsVec) {
0036 if (itHits > nHitsMax)
0037 nHitsMax = itHits;
0038 }
0039
0040 if (!nHitsMax)
0041 return sortedResult;
0042
0043 for (unsigned int ipdfVal = 0; ipdfVal < pdfValsVec.size(); ++ipdfVal) {
0044 if (nHitsVec[ipdfVal] == nHitsMax) {
0045 if (pdfValsVec[ipdfVal] > pdfValMax) {
0046 pdfValMax = pdfValsVec[ipdfVal];
0047 refPhi = refPhiVec[ipdfVal];
0048 refEta = refEtaVec[ipdfVal];
0049 refLayer = ipdfVal;
0050 hitsWord = hitsVec[ipdfVal];
0051 refPhiRHit = refPhiRHitVec[ipdfVal];
0052 }
0053 }
0054 }
0055
0056 sortedResult.setDisc(pdfValMax);
0057 sortedResult.setPhi(refPhi);
0058 sortedResult.setEta(refEta);
0059 sortedResult.setRefLayer(refLayer);
0060 sortedResult.setHits(hitsWord);
0061 sortedResult.setQ(nHitsMax);
0062 sortedResult.setPhiRHit(refPhiRHit);
0063
0064 return sortedResult;
0065 }
0066
0067
0068 AlgoMuon OMTFSorter::sortRefHitResults(const OMTFProcessor::resultsMap& aResultsMap, int charge) {
0069 unsigned int pdfValMax = 0;
0070 unsigned int nHitsMax = 0;
0071 unsigned int hitsWord = 0;
0072 int refPhi = 9999;
0073 int refEta = 999;
0074 int refLayer = -1;
0075 int refPhiRHit = 9999;
0076 Key bestKey;
0077
0078
0079 for (const auto& itKey : aResultsMap) {
0080 if (charge != 0 && itKey.first.theCharge != charge)
0081 continue;
0082 AlgoMuon val = sortSingleResult(itKey.second);
0083
0084 if (val.getQ() < 3)
0085 continue;
0086
0087 if (val.getQ() > (int)nHitsMax) {
0088 nHitsMax = val.getQ();
0089 pdfValMax = val.getDisc();
0090 refPhi = val.getPhi();
0091 refEta = val.getEta();
0092 refLayer = val.getRefLayer();
0093 hitsWord = val.getHits();
0094 refPhiRHit = val.getPhiRHit();
0095 bestKey = itKey.first;
0096
0097 } else if (val.getQ() == (int)nHitsMax && val.getDisc() > (int)pdfValMax) {
0098 pdfValMax = val.getDisc();
0099 refPhi = val.getPhi();
0100 refEta = val.getEta();
0101 refLayer = val.getRefLayer();
0102 hitsWord = val.getHits();
0103 refPhiRHit = val.getPhiRHit();
0104 bestKey = itKey.first;
0105
0106 } else if (val.getQ() == (int)nHitsMax && val.getDisc() == (int)pdfValMax &&
0107 itKey.first.number() < bestKey.number()) {
0108
0109 pdfValMax = val.getDisc();
0110 refPhi = val.getPhi();
0111 refEta = val.getEta();
0112 refLayer = val.getRefLayer();
0113 hitsWord = val.getHits();
0114 refPhiRHit = val.getPhiRHit();
0115 bestKey = itKey.first;
0116
0117 }
0118 }
0119
0120 AlgoMuon candidate(pdfValMax, refPhi, refEta, refLayer, hitsWord, nHitsMax, 0, bestKey.thePtCode, bestKey.theCharge);
0121
0122 candidate.setPhiRHit(refPhiRHit);
0123 candidate.setPatternNumber(bestKey.number());
0124
0125
0126 return candidate;
0127 }
0128
0129
0130 void OMTFSorter::sortRefHitResults(const std::vector<OMTFProcessor::resultsMap>& procResults,
0131 std::vector<AlgoMuon>& refHitCands,
0132 int charge) {
0133
0134 for (unsigned int iRefHit = 0; iRefHit < procResults.size(); iRefHit++) {
0135 AlgoMuon mu = sortRefHitResults(procResults[iRefHit], charge);
0136 mu.setRefHitNumber(iRefHit);
0137 refHitCands.push_back(mu);
0138 }
0139 }
0140
0141
0142 bool OMTFSorter::checkHitPatternValidity(unsigned int hits) {
0143
0144 std::vector<unsigned int> badPatterns = {
0145 99840, 34304, 3075, 36928, 12300, 98816, 98944, 33408, 66688, 66176, 7171, 20528, 33856, 35840, 4156, 34880};
0146
0147 for (auto aHitPattern : badPatterns) {
0148 if (hits == aHitPattern)
0149 return false;
0150 }
0151
0152 return true;
0153 }
0154
0155
0156 std::vector<l1t::RegionalMuonCand> OMTFSorter::candidates(unsigned int iProcessor,
0157 l1t::tftype mtfType,
0158 const std::vector<AlgoMuon>& algoCands) {
0159 std::vector<l1t::RegionalMuonCand> result;
0160
0161 for (const auto& myCand : algoCands) {
0162 l1t::RegionalMuonCand candidate;
0163 candidate.setHwPt(myCand.getPt());
0164 candidate.setHwEta(myCand.getEta());
0165
0166 int phiValue = myCand.getPhi();
0167 if (phiValue >= int(nPhiBins))
0168 phiValue -= nPhiBins;
0169
0170 phiValue = floor(phiValue * 437. / pow(2, 12));
0171 candidate.setHwPhi(phiValue);
0172
0173 candidate.setHwSign(myCand.getCharge() < 0 ? 1 : 0);
0174 candidate.setHwSignValid(1);
0175
0176 unsigned int quality = checkHitPatternValidity(myCand.getHits()) ? 0 | (1 << 2) | (1 << 3) : 0 | (1 << 2);
0177 if (abs(myCand.getEta()) == 115 &&
0178 (static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000001110000000").to_ulong() ||
0179 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000001110000000").to_ulong() ||
0180 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000000110000000").to_ulong() ||
0181 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000001100000000").to_ulong() ||
0182 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000001010000000").to_ulong()))
0183 quality = 4;
0184 if (myOmtfConfig->fwVersion() >= 5) {
0185 if (static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000010000000011").to_ulong() ||
0186 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000100000000011").to_ulong() ||
0187 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000001000000000011").to_ulong() ||
0188 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000010000000000011").to_ulong() ||
0189 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000100000000000011").to_ulong() ||
0190 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("001000000000000011").to_ulong() ||
0191 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("010000000000000011").to_ulong() ||
0192 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000000000000011").to_ulong() ||
0193 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000010000001100").to_ulong() ||
0194 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000100000001100").to_ulong() ||
0195 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000001000000001100").to_ulong() ||
0196 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000010000000001100").to_ulong() ||
0197 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000100000000001100").to_ulong() ||
0198 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("001000000000001100").to_ulong() ||
0199 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("010000000000001100").to_ulong() ||
0200 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000000000001100").to_ulong() ||
0201 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000010000110000").to_ulong() ||
0202 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000100000110000").to_ulong() ||
0203 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000001000000110000").to_ulong() ||
0204 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000010000000110000").to_ulong() ||
0205 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000100000000110000").to_ulong() ||
0206 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("001000000000110000").to_ulong() ||
0207 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("010000000000110000").to_ulong() ||
0208 static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000000000110000").to_ulong())
0209 quality = 1;
0210 }
0211
0212
0213 if (abs(myCand.getEta()) == 121)
0214 quality = 0;
0215
0216 candidate.setHwQual(quality);
0217
0218 std::map<int, int> trackAddr;
0219 trackAddr[0] = myCand.getHits();
0220 trackAddr[1] = myCand.getRefLayer();
0221 trackAddr[2] = myCand.getDisc();
0222 candidate.setTrackAddress(trackAddr);
0223 candidate.setTFIdentifiers(iProcessor, mtfType);
0224 if (candidate.hwPt())
0225 result.push_back(candidate);
0226 }
0227 return result;
0228 }
0229
0230