Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-06 02:54:08

0001 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/GhostBusterPreferRefDt.h"
0002 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/OMTFConfiguration.h"
0003 
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 
0006 #include <sstream>
0007 
0008 namespace {
0009 
0010   struct AlgoMuonEtaFix : public AlgoMuon {
0011     AlgoMuonEtaFix(const AlgoMuon& mu) : AlgoMuon(mu), fixedEta(mu.getEtaHw()) {}
0012     unsigned int fixedEta;
0013   };
0014 
0015 }  // namespace
0016 
0017 AlgoMuons GhostBusterPreferRefDt::select(AlgoMuons muonsIN, int charge) {
0018   // sorting within GB.
0019   auto customLess = [&](const AlgoMuons::value_type& a, const AlgoMuons::value_type& b) -> bool {
0020     if (!a->isValid()) {
0021       return true;
0022     }
0023     if (!b->isValid()) {
0024       return false;
0025     }
0026 
0027     int aRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[a->getRefLayer()];
0028     int bRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[b->getRefLayer()];
0029     if (a->getQ() > b->getQ())
0030       return false;
0031     else if (a->getQ() == b->getQ() && aRefLayerLogicNum < bRefLayerLogicNum) {
0032       return false;
0033     } else if (a->getQ() == b->getQ() && aRefLayerLogicNum == bRefLayerLogicNum && a->getDisc() > b->getDisc())
0034       return false;
0035     else if (a->getQ() == b->getQ() && aRefLayerLogicNum == bRefLayerLogicNum && a->getDisc() == b->getDisc() &&
0036              a->getPatternNumber() > b->getPatternNumber())
0037       return false;
0038     else if (a->getQ() == b->getQ() && aRefLayerLogicNum == bRefLayerLogicNum && a->getDisc() == b->getDisc() &&
0039              a->getPatternNumber() == b->getPatternNumber() && a->getRefHitNumber() < b->getRefHitNumber())
0040       return false;
0041     else
0042       return true;
0043   };
0044 
0045   auto customLessByFPLLH = [&](const AlgoMuons::value_type& a, const AlgoMuons::value_type& b) -> bool {
0046     if (!a->isValid()) {
0047       return true;
0048     }
0049     if (!b->isValid()) {
0050       return false;
0051     }
0052 
0053     if (a->getQ() > b->getQ())
0054       return false;
0055     else if (a->getQ() == b->getQ()) {
0056       return false;
0057     } else if (a->getQ() == b->getQ() && a->getDisc() > b->getDisc())
0058       return false;
0059     else if (a->getQ() == b->getQ() && a->getDisc() == b->getDisc() && a->getPatternNumber() > b->getPatternNumber())
0060       return false;
0061     else if (a->getQ() == b->getQ() && a->getDisc() == b->getDisc() && a->getPatternNumber() == b->getPatternNumber() &&
0062              a->getRefHitNumber() < b->getRefHitNumber())
0063       return false;
0064     else
0065       return true;
0066   };
0067 
0068   auto customLessByLLH = [&](const AlgoMuons::value_type& a, const AlgoMuons::value_type& b) -> bool {
0069     if (!a->isValid()) {
0070       return true;
0071     }
0072     if (!b->isValid()) {
0073       return false;
0074     }
0075 
0076     if (a->getDisc() > b->getDisc())
0077       return false;
0078     else if (a->getDisc() == b->getDisc() && a->getPatternNumber() > b->getPatternNumber())
0079       return false;
0080     else if (a->getDisc() == b->getDisc() && a->getPatternNumber() == b->getPatternNumber() &&
0081              a->getRefHitNumber() < b->getRefHitNumber())
0082       return false;
0083     else
0084       return true;
0085   };
0086 
0087   auto customLessByReLayer = [&](const AlgoMuons::value_type& a, const AlgoMuons::value_type& b) -> bool {
0088     if (!a->isValid()) {
0089       return true;
0090     }
0091     if (!b->isValid()) {
0092       return false;
0093     }
0094 
0095     int aRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[a->getRefLayer()];
0096     int bRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[b->getRefLayer()];
0097 
0098     if (aRefLayerLogicNum < bRefLayerLogicNum) {
0099       return false;
0100     }
0101     //TODO maybe use getQ here?
0102     // if(a->getQ() > b->getQ())
0103     //   return false;
0104     else if (aRefLayerLogicNum == bRefLayerLogicNum && a->getDisc() > b->getDisc())
0105       return false;
0106     else if (aRefLayerLogicNum == bRefLayerLogicNum && a->getDisc() == b->getDisc() &&
0107              a->getPatternNumber() > b->getPatternNumber())
0108       return false;
0109     else if (aRefLayerLogicNum == bRefLayerLogicNum && a->getDisc() == b->getDisc() &&
0110              a->getPatternNumber() == b->getPatternNumber() && a->getRefHitNumber() < b->getRefHitNumber())
0111       return false;
0112     else
0113       return true;
0114   };
0115 
0116   if (omtfConfig->getGhostBusterType() == "byLLH")
0117     std::sort(muonsIN.rbegin(), muonsIN.rend(), customLessByLLH);
0118   else if (omtfConfig->getGhostBusterType() == "byFPLLH")
0119     std::sort(muonsIN.rbegin(), muonsIN.rend(), customLessByFPLLH);
0120   else if (omtfConfig->getGhostBusterType() == "byReLayer")
0121     std::sort(muonsIN.rbegin(), muonsIN.rend(), customLessByReLayer);
0122   else
0123     std::sort(muonsIN.rbegin(), muonsIN.rend(), customLess);
0124 
0125   // actual GhostBusting. Overwrite eta in case of no DT info.
0126   std::vector<AlgoMuonEtaFix> refHitCleanCandsFixedEta;
0127   for (const auto& muIN : muonsIN) {
0128     if (!muIN->isValid())
0129       continue;
0130 
0131     //LogTrace("l1tOmtfEventPrint")<< "GhostBusting "<<*muIN<<" phiGMT "<<omtfConfig->procPhiToGmtPhi(muIN->getPhi())<< std::endl;
0132 
0133     refHitCleanCandsFixedEta.push_back(*muIN);  //FIXME to much copying here...
0134     auto killIt = refHitCleanCandsFixedEta.end();
0135 
0136     //do not accept candidates with similar phi (any charge combination)
0137     //veto window 5 degree in GMT scale is 5/360*576=8 units
0138     for (auto it1 = refHitCleanCandsFixedEta.begin(); it1 != refHitCleanCandsFixedEta.end(); ++it1) {
0139       for (auto it2 = std::next(it1); it2 != refHitCleanCandsFixedEta.end(); ++it2) {
0140         if (it2->isValid() &&
0141             std::abs(omtfConfig->procPhiToGmtPhi(it1->getPhi()) - omtfConfig->procPhiToGmtPhi(it2->getPhi())) < 8) {
0142           killIt = it2;
0143           if ((omtfConfig->fwVersion() >= 6) &&
0144               ((abs(it1->getEtaHw()) == 75 || abs(it1->getEtaHw()) == 79 || abs(it1->getEtaHw()) == 92)) &&
0145               ((abs(it2->getEtaHw()) != 75 && abs(it2->getEtaHw()) != 79 && abs(it2->getEtaHw()) != 92)))
0146             it1->fixedEta = it2->getEtaHw();
0147         }
0148       }
0149     }
0150     if (killIt != refHitCleanCandsFixedEta.end())
0151       refHitCleanCandsFixedEta.erase(killIt);
0152   }
0153 
0154   // fill outgoing collection
0155   AlgoMuons refHitCleanCands;
0156   for (const auto& mu : refHitCleanCandsFixedEta) {
0157     AlgoMuon fixed = mu;
0158     fixed.setEta(mu.fixedEta);
0159     refHitCleanCands.emplace_back(new AlgoMuon(fixed));
0160   }
0161 
0162   while (refHitCleanCands.size() < 3)
0163     refHitCleanCands.emplace_back(new AlgoMuon());
0164 
0165   return refHitCleanCands;
0166 }