Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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->getPatternNum() > b->getPatternNum())
0099       return false;
0100     else if (aRefLayerLogicNum == bRefLayerLogicNum && a->getPdfSum() == b->getPdfSum() &&
0101              a->getPatternNum() == b->getPatternNum() && a->getRefHitNumber() < b->getRefHitNumber())
0102       return false;
0103     else
0104       return true;
0105   };
0106 
0107   if (omtfConfig->getGhostBusterType() == "byLLH")
0108     std::sort(muonsIN.rbegin(), muonsIN.rend(), customLessByLLH);
0109   else if (omtfConfig->getGhostBusterType() == "byFPLLH")
0110     std::sort(muonsIN.rbegin(), muonsIN.rend(), customLessByFPLLH);
0111   else if (omtfConfig->getGhostBusterType() == "byRefLayer")
0112     std::sort(muonsIN.rbegin(), muonsIN.rend(), customByRefLayer);
0113   else
0114     std::sort(muonsIN.rbegin(), muonsIN.rend(), customLess);
0115 
0116   // actual GhostBusting. Overwrite eta in case of no DT info.
0117   AlgoMuons refHitCleanCandsFixedEta;
0118 
0119   for (unsigned int iMu1 = 0; iMu1 < muonsIN.size(); iMu1++) {
0120     refHitCleanCandsFixedEta.emplace_back(new AlgoMuon(*(muonsIN[iMu1])));
0121 
0122     if (omtfConfig->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::bits)
0123       refHitCleanCandsFixedEta.back()->setEta(OMTFConfiguration::etaBits2HwEta(muonsIN[iMu1]->getEtaHw()));
0124   }
0125 
0126   for (unsigned int iMu1 = 0; iMu1 < refHitCleanCandsFixedEta.size(); iMu1++) {
0127     auto& muIN1 = refHitCleanCandsFixedEta[iMu1];
0128     //watch out: the muIN1 is AlgoMuonPtr, so setting the eta here changes the eta in the input muonsIN
0129     //this affects algoCandidates in OMTFProcessor<GoldenPatternType>::run
0130 
0131     if (!muIN1->isValid() || muIN1->isKilled())
0132       continue;
0133 
0134     for (unsigned int iMu2 = refHitCleanCandsFixedEta.size() - 1; iMu2 >= iMu1 + 1; iMu2--) {
0135       auto& muIN2 = refHitCleanCandsFixedEta[iMu2];
0136       if (muIN2->isValid() &&
0137           std::abs(omtfConfig->procPhiToGmtPhi(muIN1->getPhi()) - omtfConfig->procPhiToGmtPhi(muIN2->getPhi())) < 8) {
0138         //the candidates are sorted, so only the  muIN2 can be killed, as it is "worse" than the muIN1
0139         refHitCleanCandsFixedEta[iMu2]->kill();
0140         refHitCleanCandsFixedEta[iMu1]->getKilledMuons().emplace_back(muIN2);
0141 
0142         //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
0143         //in this case the eta can be replaced by the eta from the killed algoMuon
0144         if (omtfConfig->getRefToLogicNumber()[muIN1->getRefLayer()] <= 5 && (omtfConfig->fwVersion() >= 6) &&
0145             ((abs(muIN1->getEtaHw()) == 75 || abs(muIN1->getEtaHw()) == 79 || abs(muIN1->getEtaHw()) == 92)) &&
0146             ((abs(muIN2->getEtaHw()) != 75 && abs(muIN2->getEtaHw()) != 79 &&
0147               abs(muIN2->getEtaHw()) != 92))) {  //FIXME condition in this do not affects the final result
0148 
0149           muIN1->setEta(muIN2->getEtaHw());
0150         }
0151       }
0152     }
0153   }
0154 
0155   // fill outgoing collection
0156   /* there is nowhere a cut on the pdfSum > 0 for a muon to be valid
0157    * muon is valid if getPtConstr() > 0 || getPtUnconstr() > 0,
0158    * i.e. when there was a fitting pattern
0159    * this mean there can be a muon with pdfSumConstrained = 0 but with not 0 PtConstr
0160    * which is OK. See also comment in the GoldenPatternResult::finalise10()
0161    */
0162   AlgoMuons refHitCleanCands;
0163   for (const auto& mu : refHitCleanCandsFixedEta) {
0164     if (mu->isValid() && !(mu->isKilled()))
0165       refHitCleanCands.emplace_back(mu);
0166     if (refHitCleanCands.size() >= 3)
0167       break;
0168   }
0169 
0170   while (refHitCleanCands.size() < 3)
0171     refHitCleanCands.emplace_back(new AlgoMuon());
0172 
0173   return refHitCleanCands;
0174 }