File indexing completed on 2024-04-06 12:20:48
0001 #include "L1Trigger/L1TMuon/interface/MicroGMTIsolationUnit.h"
0002
0003 #include "L1Trigger/L1TMuon/interface/GMTInternalMuon.h"
0004 #include "DataFormats/L1TMuon/interface/MuonCaloSum.h"
0005 #include "DataFormats/L1Trigger/interface/Muon.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007
0008 l1t::MicroGMTIsolationUnit::MicroGMTIsolationUnit() : m_fwVersion(0), m_initialSums(false) {}
0009
0010 l1t::MicroGMTIsolationUnit::~MicroGMTIsolationUnit() {}
0011
0012 void l1t::MicroGMTIsolationUnit::initialise(L1TMuonGlobalParamsHelper* microGMTParamsHelper) {
0013 m_fwVersion = microGMTParamsHelper->fwVersion();
0014 m_BEtaExtrapolation = l1t::MicroGMTExtrapolationLUTFactory::create(
0015 microGMTParamsHelper->bEtaExtrapolationLUT(), MicroGMTConfiguration::ETA_OUT, m_fwVersion);
0016 m_BPhiExtrapolation = l1t::MicroGMTExtrapolationLUTFactory::create(
0017 microGMTParamsHelper->bPhiExtrapolationLUT(), MicroGMTConfiguration::PHI_OUT, m_fwVersion);
0018 m_OEtaExtrapolation = l1t::MicroGMTExtrapolationLUTFactory::create(
0019 microGMTParamsHelper->oEtaExtrapolationLUT(), MicroGMTConfiguration::ETA_OUT, m_fwVersion);
0020 m_OPhiExtrapolation = l1t::MicroGMTExtrapolationLUTFactory::create(
0021 microGMTParamsHelper->oPhiExtrapolationLUT(), MicroGMTConfiguration::PHI_OUT, m_fwVersion);
0022 m_FEtaExtrapolation = l1t::MicroGMTExtrapolationLUTFactory::create(
0023 microGMTParamsHelper->fEtaExtrapolationLUT(), MicroGMTConfiguration::ETA_OUT, m_fwVersion);
0024 m_FPhiExtrapolation = l1t::MicroGMTExtrapolationLUTFactory::create(
0025 microGMTParamsHelper->fPhiExtrapolationLUT(), MicroGMTConfiguration::PHI_OUT, m_fwVersion);
0026 m_IdxSelMemEta = l1t::MicroGMTCaloIndexSelectionLUTFactory::create(
0027 microGMTParamsHelper->idxSelMemEtaLUT(), MicroGMTConfiguration::ETA, m_fwVersion);
0028 m_IdxSelMemPhi = l1t::MicroGMTCaloIndexSelectionLUTFactory::create(
0029 microGMTParamsHelper->idxSelMemPhiLUT(), MicroGMTConfiguration::PHI, m_fwVersion);
0030 m_RelIsoCheckMem =
0031 l1t::MicroGMTRelativeIsolationCheckLUTFactory::create(microGMTParamsHelper->relIsoCheckMemLUT(), m_fwVersion);
0032 m_AbsIsoCheckMem =
0033 l1t::MicroGMTAbsoluteIsolationCheckLUTFactory::create(microGMTParamsHelper->absIsoCheckMemLUT(), m_fwVersion);
0034
0035 m_etaExtrapolationLUTs[tftype::bmtf] = m_BEtaExtrapolation;
0036 m_phiExtrapolationLUTs[tftype::bmtf] = m_BPhiExtrapolation;
0037 m_etaExtrapolationLUTs[tftype::omtf_pos] = m_OEtaExtrapolation;
0038 m_etaExtrapolationLUTs[tftype::omtf_neg] = m_OEtaExtrapolation;
0039 m_phiExtrapolationLUTs[tftype::omtf_pos] = m_OPhiExtrapolation;
0040 m_phiExtrapolationLUTs[tftype::omtf_neg] = m_OPhiExtrapolation;
0041 m_etaExtrapolationLUTs[tftype::emtf_pos] = m_FEtaExtrapolation;
0042 m_etaExtrapolationLUTs[tftype::emtf_neg] = m_FEtaExtrapolation;
0043 m_phiExtrapolationLUTs[tftype::emtf_pos] = m_FPhiExtrapolation;
0044 m_phiExtrapolationLUTs[tftype::emtf_neg] = m_FPhiExtrapolation;
0045
0046 m_caloInputsToDisable = microGMTParamsHelper->caloInputsToDisable();
0047 m_maskedCaloInputs = microGMTParamsHelper->maskedCaloInputs();
0048 }
0049
0050 int l1t::MicroGMTIsolationUnit::getCaloIndex(MicroGMTConfiguration::InterMuon& mu) const {
0051
0052 int phi = (mu.hwGlobalPhi() + mu.hwDPhi()) % 576;
0053 if (phi < 0) {
0054 phi = 576 + phi;
0055 }
0056
0057 int phiIndex = m_IdxSelMemPhi->lookup(phi);
0058 int eta = mu.hwEta() + mu.hwDEta();
0059 eta = MicroGMTConfiguration::getTwosComp(eta, 9);
0060 int etaIndex = m_IdxSelMemEta->lookup(eta);
0061 mu.setHwCaloEta(etaIndex);
0062 mu.setHwCaloPhi(phiIndex);
0063
0064 return phiIndex + etaIndex * 36;
0065 }
0066
0067 void l1t::MicroGMTIsolationUnit::extrapolateMuons(MicroGMTConfiguration::InterMuonList& inputmuons) const {
0068 int outputShiftPhi = 3;
0069 int outputShiftEta = 3;
0070 if (m_fwVersion >= 0x4010000) {
0071 outputShiftPhi = 2;
0072 outputShiftEta = 0;
0073 }
0074
0075 for (auto& mu : inputmuons) {
0076
0077 std::shared_ptr<MicroGMTExtrapolationLUT> phiExtrapolationLUT = m_phiExtrapolationLUTs.at(mu->trackFinderType());
0078 int ptRedInWidth = phiExtrapolationLUT->getPtRedInWidth();
0079 int ptMask = (1 << ptRedInWidth) - 1;
0080 int etaRedInWidth = phiExtrapolationLUT->getEtaRedInWidth();
0081 int redEtaShift = 8 - etaRedInWidth;
0082
0083
0084 int ptRed = mu->hwPt() & ptMask;
0085
0086 int etaAbsRed = (std::abs(mu->hwEta()) >> redEtaShift) & ((1 << etaRedInWidth) - 1);
0087
0088 int deltaPhi = 0;
0089 int deltaEta = 0;
0090
0091 if (mu->hwPt() < (1 << ptRedInWidth)) {
0092 int sign = 1;
0093 if (mu->hwSign() == 1) {
0094 sign = -1;
0095 }
0096 deltaPhi = (phiExtrapolationLUT->lookup(etaAbsRed, ptRed) << outputShiftPhi) * sign;
0097 deltaEta = (m_etaExtrapolationLUTs.at(mu->trackFinderType())->lookup(etaAbsRed, ptRed) << outputShiftEta);
0098 if (mu->hwEta() > 0) {
0099 deltaEta *= -1;
0100 }
0101 }
0102
0103 mu->setExtrapolation(deltaEta, deltaPhi);
0104 }
0105 }
0106
0107 void l1t::MicroGMTIsolationUnit::calculate5by1Sums(const MicroGMTConfiguration::CaloInputCollection& inputs, int bx) {
0108 m_5by1TowerSums.clear();
0109 if (inputs.size(bx) == 0)
0110 return;
0111
0112 for (int iphi = 0; iphi < 36; ++iphi) {
0113 int iphiIndexOffset = iphi * 28;
0114
0115
0116 for (int ieta = 0; ieta < 2; ++ieta) {
0117 int sum = 0;
0118 for (int dIEta = 0 - ieta; dIEta <= 2; ++dIEta) {
0119 if (m_caloInputsToDisable.test(ieta + dIEta) || m_maskedCaloInputs.test(ieta + dIEta))
0120 continue;
0121 sum += inputs.at(bx, iphiIndexOffset + dIEta).etBits();
0122 }
0123 m_5by1TowerSums.push_back(sum);
0124 }
0125
0126 for (int ieta = 2; ieta < 26; ++ieta) {
0127 int sum = 0;
0128 for (int dIEta = -2; dIEta <= 2; ++dIEta) {
0129 if (m_caloInputsToDisable.test(ieta + dIEta) || m_maskedCaloInputs.test(ieta + dIEta))
0130 continue;
0131 sum += inputs.at(bx, iphiIndexOffset + dIEta).etBits();
0132 }
0133 m_5by1TowerSums.push_back(sum);
0134 }
0135
0136
0137 for (int ieta = 26; ieta < 28; ++ieta) {
0138 int sum = 0;
0139 for (int dIEta = -2; dIEta <= 27 - ieta; ++dIEta) {
0140 if (m_caloInputsToDisable.test(ieta + dIEta) || m_maskedCaloInputs.test(ieta + dIEta))
0141 continue;
0142 sum += inputs.at(bx, iphiIndexOffset + dIEta).etBits();
0143 }
0144 m_5by1TowerSums.push_back(sum);
0145 }
0146 }
0147
0148 m_initialSums = true;
0149 }
0150
0151 int l1t::MicroGMTIsolationUnit::calculate5by5Sum(unsigned index) const {
0152 if (index > m_5by1TowerSums.size()) {
0153 edm::LogWarning("energysum out of bounds!");
0154 return 0;
0155 }
0156
0157 int returnSum = 0;
0158 for (int dIPhi = -2; dIPhi <= 2; ++dIPhi) {
0159 int currIndex = (index + dIPhi * 28) % 1008;
0160 if (currIndex < 0)
0161 currIndex = 1008 + currIndex;
0162 if ((unsigned)currIndex < m_5by1TowerSums.size()) {
0163 returnSum += m_5by1TowerSums[currIndex];
0164 } else {
0165 edm::LogWarning("energysum out of bounds!");
0166 }
0167 }
0168 return std::min(31, returnSum);
0169 }
0170
0171 void l1t::MicroGMTIsolationUnit::isolate(MicroGMTConfiguration::InterMuonList& muons) const {
0172 for (auto& mu : muons) {
0173 int caloIndex = getCaloIndex(*mu);
0174 int energySum = calculate5by5Sum(caloIndex);
0175 mu->setHwIsoSum(energySum);
0176
0177 int absIso = m_AbsIsoCheckMem->lookup(energySum);
0178 int relIso = m_RelIsoCheckMem->lookup(energySum, mu->hwPt());
0179
0180 mu->setHwRelIso(relIso);
0181 mu->setHwAbsIso(absIso);
0182 }
0183 }
0184
0185 void l1t::MicroGMTIsolationUnit::setTowerSums(const MicroGMTConfiguration::CaloInputCollection& inputs, int bx) {
0186 m_towerEnergies.clear();
0187 if (bx < inputs.getFirstBX() || bx > inputs.getLastBX())
0188 return;
0189 if (inputs.size(bx) == 0)
0190 return;
0191 for (auto input = inputs.begin(bx); input != inputs.end(bx); ++input) {
0192 if (m_caloInputsToDisable.test(input->hwEta()) || m_maskedCaloInputs.test(input->hwEta())) {
0193 continue;
0194 }
0195 if (input->etBits() != 0) {
0196 m_towerEnergies[input->hwEta() * 36 + input->hwPhi()] = input->etBits();
0197 }
0198 }
0199
0200 m_initialSums = true;
0201 }
0202
0203 void l1t::MicroGMTIsolationUnit::isolatePreSummed(MicroGMTConfiguration::InterMuonList& muons) const {
0204 for (const auto& mu : muons) {
0205 int caloIndex = getCaloIndex(*mu);
0206 int energySum = 0;
0207 if (m_towerEnergies.count(caloIndex) == 1) {
0208 energySum = m_towerEnergies.at(caloIndex);
0209 }
0210
0211 mu->setHwIsoSum(energySum);
0212
0213 int absIso = m_AbsIsoCheckMem->lookup(energySum);
0214 int relIso = m_RelIsoCheckMem->lookup(energySum, mu->hwPt());
0215
0216 mu->setHwRelIso(relIso);
0217 mu->setHwAbsIso(absIso);
0218 }
0219 }