File indexing completed on 2024-04-06 12:19:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMatcher.h"
0022
0023
0024
0025
0026
0027 #include <iostream>
0028 #include <iomanip>
0029 #include <cmath>
0030
0031 #include <fstream>
0032 #include <sstream>
0033
0034
0035
0036
0037
0038 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTConfig.h"
0039 #include "L1Trigger/GlobalMuonTrigger/interface/L1MuGlobalMuonTrigger.h"
0040 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTPSB.h"
0041 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMatrix.h"
0042 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTDebugBlock.h"
0043 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTSortRankUnit.h"
0044 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTLFDeltaEtaLUT.h"
0045 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTLFCOUDeltaEtaLUT.h"
0046 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTLFOvlEtaConvLUT.h"
0047 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTLFMatchQualLUT.h"
0048 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTLFDisableHotLUT.h"
0049 #include "CondFormats/L1TObjects/interface/L1MuPacking.h"
0050
0051 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0052
0053
0054
0055
0056
0057
0058
0059
0060 L1MuGMTMatcher::L1MuGMTMatcher(const L1MuGlobalMuonTrigger& gmt, int id)
0061 : m_gmt(gmt),
0062 m_id(id),
0063 first(MaxMatch),
0064 second(MaxMatch),
0065 matchQuality(MaxMatch, MaxMatch, 0),
0066 pairMatrix(MaxMatch, MaxMatch, false) {
0067 first.reserve(MaxMatch);
0068 second.reserve(MaxMatch);
0069 }
0070
0071
0072
0073
0074 L1MuGMTMatcher::~L1MuGMTMatcher() { reset(); }
0075
0076
0077
0078
0079
0080
0081
0082
0083 void L1MuGMTMatcher::run() {
0084 load();
0085 match();
0086 }
0087
0088
0089
0090
0091 void L1MuGMTMatcher::reset() {
0092 matchQuality.reset(0);
0093 pairMatrix.reset(false);
0094
0095 for (unsigned i = 0; i < MaxMatch; i++) {
0096 first[i] = nullptr;
0097 second[i] = nullptr;
0098 }
0099 }
0100
0101
0102
0103
0104 void L1MuGMTMatcher::print() {
0105 edm::LogVerbatim("GMT_Matcher_info");
0106 if (L1MuGMTConfig::Debug(4)) {
0107 edm::LogVerbatim("GMT_Matcher_info") << "MATCH Quality : ";
0108 matchQuality.print();
0109 }
0110
0111 edm::LogVerbatim("GMT_Matcher_info") << "PAIR Matrix : ";
0112 pairMatrix.print();
0113
0114 edm::LogVerbatim("GMT_Matcher_info");
0115 }
0116
0117
0118
0119
0120 void L1MuGMTMatcher::load() {
0121
0122 if (m_id == 0) {
0123 for (unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++) {
0124 first[idt] = m_gmt.Data()->DTBXMuon(idt);
0125 }
0126 for (unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCbarrel; irpc++) {
0127 second[irpc] = m_gmt.Data()->RPCMuon(irpc);
0128 }
0129 }
0130
0131
0132 if (m_id == 1) {
0133 for (unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++) {
0134 first[icsc] = m_gmt.Data()->CSCMuon(icsc);
0135 }
0136 for (unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCendcap; irpc++) {
0137 second[irpc] = m_gmt.Data()->RPCMuon(irpc + 4);
0138 }
0139 }
0140
0141
0142 if (m_id == 2) {
0143 for (unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++) {
0144 first[idt] = m_gmt.Data()->DTBXMuon(idt);
0145 }
0146 for (unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++) {
0147 second[icsc] = m_gmt.Data()->CSCMuon(icsc);
0148 }
0149 }
0150
0151
0152 if (m_id == 3) {
0153 for (unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++) {
0154 first[icsc] = m_gmt.Data()->CSCMuon(icsc);
0155 }
0156 for (unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++) {
0157 second[idt] = m_gmt.Data()->DTBXMuon(idt);
0158 }
0159 }
0160
0161
0162 if (m_id == 4) {
0163 for (unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCbarrel; irpc++) {
0164 first[irpc] = m_gmt.Data()->RPCMuon(irpc);
0165 }
0166 for (unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++) {
0167 second[icsc] = m_gmt.Data()->CSCMuon(icsc);
0168 }
0169 }
0170
0171
0172 if (m_id == 5) {
0173 for (unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCendcap; irpc++) {
0174 first[irpc] = m_gmt.Data()->RPCMuon(irpc + 4);
0175 }
0176 for (unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++) {
0177 second[idt] = m_gmt.Data()->DTBXMuon(idt);
0178 }
0179 }
0180 }
0181
0182
0183
0184
0185 void L1MuGMTMatcher::match() {
0186 L1MuGMTMatrix<bool> maxMatrix(MaxMatch, MaxMatch, false);
0187 L1MuGMTMatrix<bool> disableMatrix(MaxMatch, MaxMatch, false);
0188
0189
0190
0191 unsigned i, j;
0192 for (i = 0; i < MaxMatch; i++)
0193 for (j = 0; j < MaxMatch; j++)
0194 matchQuality(i, j) = lookup_mq(i, j);
0195
0196
0197 m_gmt.DebugBlockForFill()->SetMQMatrix(m_id, matchQuality);
0198
0199
0200
0201 for (i = 0; i < MaxMatch; i++)
0202 for (j = 0; j < MaxMatch; j++)
0203 maxMatrix(i, j) = matchQuality.isMax(i, j) && (matchQuality(i, j) != 0);
0204
0205
0206
0207 for (i = 0; i < MaxMatch; i++)
0208 for (j = 0; j < MaxMatch; j++) {
0209 for (unsigned i1 = 0; i1 < MaxMatch; i1++)
0210 if (i1 != i)
0211 disableMatrix(i, j) = disableMatrix(i, j) || maxMatrix(i1, j);
0212
0213 for (unsigned j1 = 0; j1 < MaxMatch; j1++)
0214 if (j1 != j)
0215 disableMatrix(i, j) = disableMatrix(i, j) || maxMatrix(i, j1);
0216 }
0217
0218
0219
0220 for (i = 0; i < MaxMatch; i++) {
0221 for (j = 0; j < MaxMatch; j++) {
0222 bool max = true;
0223
0224 for (unsigned i1 = 0; i1 < i; i1++) {
0225 max = max && ((matchQuality(i, j) > matchQuality(i1, j)) || disableMatrix(i1, j));
0226 }
0227
0228 for (unsigned i1 = i + 1; i1 < MaxMatch; i1++) {
0229 max = max && ((matchQuality(i, j) >= matchQuality(i1, j)) || disableMatrix(i1, j));
0230 }
0231
0232 for (unsigned j1 = 0; j1 < j; j1++) {
0233 max = max && ((matchQuality(i, j) > matchQuality(i, j1)) || disableMatrix(i, j1));
0234 }
0235
0236 for (unsigned j1 = j + 1; j1 < MaxMatch; j1++) {
0237 max = max && ((matchQuality(i, j) >= matchQuality(i, j1)) || disableMatrix(i, j1));
0238 }
0239
0240 pairMatrix(i, j) = max && (matchQuality(i, j) != 0);
0241 }
0242 }
0243
0244
0245 m_gmt.DebugBlockForFill()->SetPairMatrix(m_id, pairMatrix);
0246 }
0247
0248
0249
0250
0251 int L1MuGMTMatcher::lookup_mq(int i, int j) {
0252 bool empty1 = (first[i] != nullptr) ? first[i]->empty() : true;
0253 bool empty2 = (second[j] != nullptr) ? second[j]->empty() : true;
0254 if (empty1 || empty2)
0255 return 0;
0256
0257
0258
0259
0260 unsigned phi1 = first[i]->phi_packed();
0261 unsigned phi2 = second[j]->phi_packed();
0262
0263 int delta_phi = ((phi1 - phi2 + 3 * 72) % 144) - 72;
0264
0265 if (delta_phi < -3 || delta_phi > 3)
0266 delta_phi = -4;
0267
0268 L1MuSignedPacking<3> DPhiPacking;
0269 unsigned delta_phi_packed = DPhiPacking.packedFromIdx(delta_phi);
0270
0271
0272
0273
0274 unsigned eta1 = first[i]->eta_packed();
0275 unsigned eta2 = second[j]->eta_packed();
0276
0277 unsigned delta_eta_packed = 0;
0278
0279 if (m_id == 0 || m_id == 1) {
0280
0281
0282 bool disable1 = L1MuGMTSortRankUnit::isDisabled(first[i]);
0283 bool disable2 = L1MuGMTSortRankUnit::isDisabled(second[j]);
0284 ;
0285
0286 if (disable1 || disable2)
0287 return 0;
0288
0289 L1MuGMTLFDeltaEtaLUT* de_lut = L1MuGMTConfig::getLFDeltaEtaLUT();
0290 delta_eta_packed = de_lut->SpecificLookup_delta_eta(m_id, eta1, eta2);
0291 } else {
0292
0293 int idx1 = first[i]->type_idx();
0294 int idx1_dcrr = (idx1 == 1) ? 2 : (idx1 == 2) ? 1 : idx1;
0295
0296 int idx2 = second[j]->type_idx();
0297 int idx2_dcrr = (idx2 == 1) ? 2 : (idx2 == 2) ? 1 : idx2;
0298
0299 bool disable1 = L1MuGMTSortRankUnit::isDisabled(first[i]);
0300
0301 L1MuGMTLFDisableHotLUT* dishot_lut = L1MuGMTConfig::getLFDisableHotLUT();
0302 bool disable2 =
0303 dishot_lut->SpecificLookup_disable_hot(idx2_dcrr, second[j]->eta_packed(), second[j]->phi_packed()) == 1;
0304
0305 if (disable1 || disable2)
0306 return 0;
0307
0308
0309 L1MuGMTLFOvlEtaConvLUT* econv_lut = L1MuGMTConfig::getLFOvlEtaConvLUT();
0310
0311 unsigned eta1_4bit = econv_lut->SpecificLookup_eta_ovl(idx1_dcrr, eta1);
0312 unsigned eta2_4bit = econv_lut->SpecificLookup_eta_ovl(idx2_dcrr, eta2);
0313
0314
0315 L1MuGMTLFCOUDeltaEtaLUT* cou_de_lut = L1MuGMTConfig::getLFCOUDeltaEtaLUT();
0316 delta_eta_packed = cou_de_lut->SpecificLookup_delta_eta(m_id - 2, eta1_4bit, eta2_4bit);
0317 }
0318
0319
0320
0321
0322 L1MuGMTLFMatchQualLUT* mq_lut = L1MuGMTConfig::getLFMatchQualLUT();
0323
0324 unsigned mq = mq_lut->SpecificLookup_mq(m_id, delta_eta_packed, delta_phi_packed);
0325
0326 return mq;
0327 }