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
0010
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
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())
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
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
0135
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
0145 refHitCleanCandsFixedEta[iMu2]->kill();
0146 refHitCleanCandsFixedEta[iMu1]->getKilledMuons().emplace_back(muIN2);
0147
0148
0149
0150
0151
0152
0153
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
0165
0166
0167
0168
0169
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 }