Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-15 04:21:50

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 AlgoMuons GhostBusterPreferRefDt::select(AlgoMuons muonsIN, int charge) {
0009   // sorting within GB.
0010   //this function is only for the OMTF version without unconstrained pt
0011   auto customLess = [&](const AlgoMuons::value_type& a, const AlgoMuons::value_type& b) -> bool {
0012     if (!a->isValid()) {
0013       return true;
0014     }
0015     if (!b->isValid()) {
0016       return false;
0017     }
0018 
0019     int aRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[a->getRefLayer()];
0020     int bRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[b->getRefLayer()];
0021     if (a->getFiredLayerCntConstr() > b->getFiredLayerCntConstr())
0022       return false;
0023     else if (a->getFiredLayerCntConstr() == b->getFiredLayerCntConstr() && aRefLayerLogicNum < bRefLayerLogicNum) {
0024       return false;
0025     } else if (a->getFiredLayerCntConstr() == b->getFiredLayerCntConstr() && aRefLayerLogicNum == bRefLayerLogicNum &&
0026                a->getPdfSumConstr() > b->getPdfSumConstr())
0027       return false;
0028     else if (a->getFiredLayerCntConstr() == b->getFiredLayerCntConstr() && aRefLayerLogicNum == bRefLayerLogicNum &&
0029              a->getPdfSumConstr() == b->getPdfSumConstr() && a->getPatternNumConstr() > b->getPatternNumConstr())
0030       return false;
0031     else if (a->getFiredLayerCntConstr() == b->getFiredLayerCntConstr() && aRefLayerLogicNum == bRefLayerLogicNum &&
0032              a->getPdfSumConstr() == b->getPdfSumConstr() && a->getPatternNumConstr() == b->getPatternNumConstr() &&
0033              a->getRefHitNumber() < b->getRefHitNumber())
0034       return false;
0035     else
0036       return true;
0037   };
0038 
0039   auto customLessByFPLLH = [&](const AlgoMuons::value_type& a, const AlgoMuons::value_type& b) -> bool {
0040     if (!a->isValid()) {
0041       return true;
0042     }
0043     if (!b->isValid()) {
0044       return false;
0045     }
0046 
0047     if (a->getFiredLayerCntConstr() > b->getFiredLayerCntConstr())
0048       return false;
0049     else if (a->getFiredLayerCntConstr() == b->getFiredLayerCntConstr() && a->getPdfSumConstr() > b->getPdfSumConstr())
0050       return false;
0051     else if (a->getFiredLayerCntConstr() == b->getFiredLayerCntConstr() &&
0052              a->getPdfSumConstr() == b->getPdfSumConstr() && a->getPatternNumConstr() > b->getPatternNumConstr())
0053       return false;
0054     else if (a->getFiredLayerCntConstr() == b->getFiredLayerCntConstr() &&
0055              a->getPdfSumConstr() == b->getPdfSumConstr() && a->getPatternNumConstr() == b->getPatternNumConstr() &&
0056              a->getRefHitNumber() < b->getRefHitNumber())
0057       return false;
0058     else
0059       return true;
0060   };
0061 
0062   auto customLessByLLH = [&](const AlgoMuons::value_type& a, const AlgoMuons::value_type& b) -> bool {
0063     if (!a->isValid()) {
0064       return true;
0065     }
0066     if (!b->isValid()) {
0067       return false;
0068     }
0069 
0070     if (a->getPdfSumConstr() > b->getPdfSumConstr())
0071       return false;
0072     else if (a->getPdfSumConstr() == b->getPdfSumConstr() && a->getPatternNumConstr() > b->getPatternNumConstr())
0073       return false;
0074     else if (a->getPdfSumConstr() == b->getPdfSumConstr() && a->getPatternNumConstr() == b->getPatternNumConstr() &&
0075              a->getRefHitNumber() < b->getRefHitNumber())
0076       return false;
0077     else
0078       return true;
0079   };
0080 
0081   //this function is for the OMTF version with unconstrained pt
0082   auto customByRefLayer = [&](const AlgoMuons::value_type& a, const AlgoMuons::value_type& b) -> bool {
0083     if (!a->isValid()) {
0084       return true;
0085     }
0086     if (!b->isValid()) {
0087       return false;
0088     }
0089 
0090     int aRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[a->getRefLayer()];
0091     int bRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[b->getRefLayer()];
0092 
0093     if (aRefLayerLogicNum < bRefLayerLogicNum) {
0094       return false;
0095     } else if (aRefLayerLogicNum == bRefLayerLogicNum && a->getPdfSum() > b->getPdfSum())
0096       return false;
0097     else if (aRefLayerLogicNum == bRefLayerLogicNum && a->getPdfSum() == b->getPdfSum() &&
0098              a->getPatternNumConstr() >
0099                  b->getPatternNumConstr())  //should be rather getPatternNum(), but for FW getPatternNumConstr() is easier
0100       return false;
0101     else if (aRefLayerLogicNum == bRefLayerLogicNum && a->getPdfSum() == b->getPdfSum() &&
0102              a->getPatternNumConstr() == b->getPatternNumConstr())
0103       return false;
0104     else
0105       return true;
0106   };
0107 
0108   if (omtfConfig->getGhostBusterType() == "byLLH")
0109     std::sort(muonsIN.rbegin(), muonsIN.rend(), customLessByLLH);
0110   else if (omtfConfig->getGhostBusterType() == "byFPLLH")
0111     std::sort(muonsIN.rbegin(), muonsIN.rend(), customLessByFPLLH);
0112   else if (omtfConfig->getGhostBusterType() == "byRefLayer")
0113     std::sort(muonsIN.rbegin(), muonsIN.rend(), customByRefLayer);
0114   else
0115     std::sort(muonsIN.rbegin(), muonsIN.rend(), customLess);
0116 
0117   // actual GhostBusting. Overwrite eta in case of no DT info.
0118   AlgoMuons refHitCleanCandsFixedEta;
0119 
0120   for (unsigned int iMu1 = 0; iMu1 < muonsIN.size(); iMu1++) {
0121     if (muonsIN[iMu1]->getPdfSumConstr() < -1) {
0122       LogTrace("OMTFReconstruction") << *(muonsIN[iMu1]) << std::endl
0123                                      << muonsIN[iMu1]->getGpResultConstr() << std::endl
0124                                      << muonsIN[iMu1]->getGpResultUnconstr() << std::endl;
0125     }
0126     refHitCleanCandsFixedEta.emplace_back(new AlgoMuon(*(muonsIN[iMu1])));
0127 
0128     if (omtfConfig->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::bits)
0129       refHitCleanCandsFixedEta.back()->setEta(OMTFConfiguration::etaBits2HwEta(muonsIN[iMu1]->getEtaHw()));
0130   }
0131 
0132   for (unsigned int iMu1 = 0; iMu1 < refHitCleanCandsFixedEta.size(); iMu1++) {
0133     auto& muIN1 = refHitCleanCandsFixedEta[iMu1];
0134     //watch out: the muIN1 is AlgoMuonPtr, so setting the eta here changes the eta in the input muonsIN
0135     //this affects algoCandidates in OMTFProcessor<GoldenPatternType>::run
0136 
0137     if (!muIN1->isValid() || muIN1->isKilled())
0138       continue;
0139 
0140     for (unsigned int iMu2 = refHitCleanCandsFixedEta.size() - 1; iMu2 >= iMu1 + 1; iMu2--) {
0141       auto& muIN2 = refHitCleanCandsFixedEta[iMu2];
0142       if (muIN2->isValid() &&
0143           std::abs(omtfConfig->procPhiToGmtPhi(muIN1->getPhi()) - omtfConfig->procPhiToGmtPhi(muIN2->getPhi())) < 8) {
0144         //the candidates are sorted, so only the  muIN2 can be killed, as it is "worse" than the muIN1
0145         refHitCleanCandsFixedEta[iMu2]->kill();
0146         refHitCleanCandsFixedEta[iMu1]->getKilledMuons().emplace_back(muIN2);
0147 
0148         //for the DT stubs, if there is no eta, the middle of the chamber is set as the stub eta, i.e. 75, 79 or 92 respectively
0149         //in this case the eta can be replaced by the eta from the killed algoMuon.
0150         //Eta 121 is outside of the OMTF region, therefore all candidates with this eta have quality 0,
0151         //so there is no sense to assign this eta to the candidates with eta 75, 79 or 92.
0152         //The condition  abs(muIN2->getEtaHw()) != 121 was added in the FW in 2024
0153         //TODO add 95 meaning no DT segment was found, or don't use 95 in OmtfAngleConverter::getGlobalEta
0154         if (omtfConfig->getRefToLogicNumber()[muIN1->getRefLayer()] <= 5 && (omtfConfig->fwVersion() >= 6) &&
0155             (abs(muIN1->getEtaHw()) == 75 || abs(muIN1->getEtaHw()) == 79 || abs(muIN1->getEtaHw()) == 92) &&
0156             (abs(muIN2->getEtaHw()) != 75 && abs(muIN2->getEtaHw()) != 79 && abs(muIN2->getEtaHw()) != 92 &&
0157              abs(muIN2->getEtaHw()) != 121)) {
0158           muIN1->setEta(muIN2->getEtaHw());
0159         }
0160       }
0161     }
0162   }
0163 
0164   // fill outgoing collection
0165   /* there is nowhere a cut on the pdfSum > 0 for a muon to be valid
0166    * muon is valid if getPtConstr() > 0 || getPtUnconstr() > 0,
0167    * i.e. when there was a fitting pattern
0168    * this mean there can be a muon with pdfSumConstrained = 0 but with not 0 PtConstr
0169    * which is OK. See also comment in the GoldenPatternResult::finalise10()
0170    */
0171   AlgoMuons refHitCleanCands;
0172   for (const auto& mu : refHitCleanCandsFixedEta) {
0173     if (mu->isValid() && !(mu->isKilled()))
0174       refHitCleanCands.emplace_back(mu);
0175     if (refHitCleanCands.size() >= 3)
0176       break;
0177   }
0178 
0179   while (refHitCleanCands.size() < 3)
0180     refHitCleanCands.emplace_back(new AlgoMuon());
0181 
0182   return refHitCleanCands;
0183 }