Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:12:49

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