Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:04

0001 #include "L1Trigger/L1TMuonOverlap/interface/GhostBusterPreferRefDt.h"
0002 
0003 #include <algorithm>
0004 #include <sstream>
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "L1Trigger/L1TMuonOverlap/interface/OMTFConfiguration.h"
0008 
0009 namespace {
0010 
0011   int phiGMT(int phiAlgo) { return phiAlgo * 437 / pow(2, 12); }
0012 
0013   struct AlgoMuonEtaFix : public AlgoMuon {
0014     AlgoMuonEtaFix(const AlgoMuon& mu) : AlgoMuon(mu), fixedEta(mu.getEta()) {}
0015     unsigned int fixedEta;
0016   };
0017 
0018 }  // namespace
0019 
0020 std::vector<AlgoMuon> GhostBusterPreferRefDt::select(std::vector<AlgoMuon> muonsIN, int charge) {
0021   // sorting within GB.
0022   auto customLess = [&](const AlgoMuon& a, const AlgoMuon& b) -> bool {
0023     // protect against access violation
0024     if (a.getRefLayer() == -1 || b.getRefLayer() == -1)
0025       return false;
0026     int aRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[a.getRefLayer()];
0027     int bRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[b.getRefLayer()];
0028     if (a.getQ() > b.getQ())
0029       return false;
0030     else if (a.getQ() == b.getQ() && aRefLayerLogicNum < bRefLayerLogicNum) {
0031       return false;
0032     } else if (a.getQ() == b.getQ() && aRefLayerLogicNum == bRefLayerLogicNum && a.getDisc() > b.getDisc())
0033       return false;
0034     else if (a.getQ() == b.getQ() && aRefLayerLogicNum == bRefLayerLogicNum && a.getDisc() == b.getDisc() &&
0035              a.getPatternNumber() > b.getPatternNumber())
0036       return false;
0037     else if (a.getQ() == b.getQ() && aRefLayerLogicNum == bRefLayerLogicNum && a.getDisc() == b.getDisc() &&
0038              a.getPatternNumber() == b.getPatternNumber() && a.getRefHitNumber() < b.getRefHitNumber())
0039       return false;
0040     else
0041       return true;
0042   };
0043 
0044   std::sort(muonsIN.rbegin(), muonsIN.rend(), customLess);
0045 
0046   // actual GhostBusting. Overwrite eta in case of no DT info.
0047   std::vector<AlgoMuonEtaFix> refHitCleanCandsFixedEta;
0048   for (const auto& muIN : muonsIN) {
0049     refHitCleanCandsFixedEta.push_back(muIN);
0050     auto killIt = refHitCleanCandsFixedEta.end();
0051 
0052     //do not accept candidates with similar phi (any charge combination)
0053     //veto window 5 degree in GMT scale is 5/360*576=8 units
0054     for (auto it1 = refHitCleanCandsFixedEta.begin(); it1 != refHitCleanCandsFixedEta.end(); ++it1) {
0055       for (auto it2 = std::next(it1); it2 != refHitCleanCandsFixedEta.end(); ++it2) {
0056         if (std::abs(phiGMT(it1->getPhi()) - phiGMT(it2->getPhi())) < 8) {
0057           killIt = it2;
0058           if ((omtfConfig->fwVersion() >= 6) &&
0059               ((abs(it1->getEta()) == 75 || abs(it1->getEta()) == 79 || abs(it1->getEta()) == 92)) &&
0060               ((abs(it2->getEta()) != 75 && abs(it2->getEta()) != 79 && abs(it2->getEta()) != 92)))
0061             it1->fixedEta = it2->getEta();
0062         }
0063       }
0064     }
0065     if (killIt != refHitCleanCandsFixedEta.end())
0066       refHitCleanCandsFixedEta.erase(killIt);
0067   }
0068 
0069   // fill outgoing collection
0070   std::vector<AlgoMuon> refHitCleanCands;
0071   for (const auto& mu : refHitCleanCandsFixedEta) {
0072     AlgoMuon fixed = mu;
0073     fixed.setEta(mu.fixedEta);
0074     refHitCleanCands.push_back(fixed);
0075   }
0076 
0077   refHitCleanCands.resize(3, AlgoMuon(0, 999, 9999, 0, 0, 0, 0, 0));
0078   /*
0079   std::stringstream myStr;
0080   bool hasCandidates = false;
0081   for(unsigned int iRefHit=0;iRefHit<refHitCleanCands.size();++iRefHit){
0082     if(refHitCleanCands[iRefHit].getQ()){
0083       hasCandidates=true;
0084       break;
0085     }
0086   }
0087   for(unsigned int iRefHit=0;iRefHit<refHitCleanCands.size();++iRefHit){
0088     if(refHitCleanCands[iRefHit].getQ()) myStr<<"Ref hit: "<<iRefHit<<" "<<refHitCleanCands[iRefHit]<<std::endl;
0089   }
0090   if(hasCandidates) edm::LogInfo("OMTF Sorter")<<myStr.str();
0091 */
0092 
0093   return refHitCleanCands;
0094 }