00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMatcher.h"
00024
00025
00026
00027
00028
00029 #include <iostream>
00030 #include <iomanip>
00031 #include <cmath>
00032
00033 #include <fstream>
00034 #include <sstream>
00035
00036
00037
00038
00039
00040 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTConfig.h"
00041 #include "L1Trigger/GlobalMuonTrigger/interface/L1MuGlobalMuonTrigger.h"
00042 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTPSB.h"
00043 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTMatrix.h"
00044 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTDebugBlock.h"
00045 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTSortRankUnit.h"
00046 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTLFDeltaEtaLUT.h"
00047 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTLFCOUDeltaEtaLUT.h"
00048 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTLFOvlEtaConvLUT.h"
00049 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTLFMatchQualLUT.h"
00050 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTLFDisableHotLUT.h"
00051 #include "CondFormats/L1TObjects/interface/L1MuPacking.h"
00052
00053 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00054
00055
00056
00057
00058
00059
00060
00061
00062 L1MuGMTMatcher::L1MuGMTMatcher(const L1MuGlobalMuonTrigger& gmt, int id) :
00063 m_gmt(gmt), m_id(id), first(MaxMatch), second(MaxMatch),
00064 matchQuality(MaxMatch,MaxMatch), pairMatrix(MaxMatch,MaxMatch) {
00065
00066 first.reserve(MaxMatch);
00067 second.reserve(MaxMatch);
00068
00069 }
00070
00071
00072
00073
00074 L1MuGMTMatcher::~L1MuGMTMatcher() {
00075
00076 reset();
00077
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087 void L1MuGMTMatcher::run() {
00088
00089 load();
00090 match();
00091
00092 }
00093
00094
00095
00096
00097 void L1MuGMTMatcher::reset() {
00098
00099 matchQuality.init(0);
00100 pairMatrix.init(false);
00101
00102 for ( unsigned i = 0; i < MaxMatch; i++ ) {
00103 first[i] = 0;
00104 second[i] = 0;
00105 }
00106
00107 }
00108
00109
00110
00111
00112
00113 void L1MuGMTMatcher::print() {
00114
00115 edm::LogVerbatim("GMT_Matcher_info");
00116 if ( L1MuGMTConfig::Debug(4) ) {
00117 edm::LogVerbatim("GMT_Matcher_info") << "MATCH Quality : ";
00118 matchQuality.print();
00119 }
00120
00121 edm::LogVerbatim("GMT_Matcher_info") << "PAIR Matrix : ";
00122 pairMatrix.print();
00123
00124 edm::LogVerbatim("GMT_Matcher_info");
00125
00126 }
00127
00128
00129
00130
00131
00132 void L1MuGMTMatcher::load() {
00133
00134
00135 if ( m_id == 0 ) {
00136 for ( unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++ ) {
00137 first[idt] = m_gmt.Data()->DTBXMuon(idt);
00138 }
00139 for ( unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCbarrel; irpc++ ) {
00140 second[irpc] = m_gmt.Data()->RPCMuon(irpc);
00141 }
00142 }
00143
00144
00145 if ( m_id == 1 ) {
00146 for ( unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++ ) {
00147 first[icsc] = m_gmt.Data()->CSCMuon(icsc);
00148 }
00149 for ( unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCendcap; irpc++ ) {
00150 second[irpc] = m_gmt.Data()->RPCMuon(irpc+4);
00151 }
00152 }
00153
00154
00155 if ( m_id == 2 ) {
00156 for ( unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++ ) {
00157 first[idt] = m_gmt.Data()->DTBXMuon(idt);
00158 }
00159 for ( unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++ ) {
00160 second[icsc] = m_gmt.Data()->CSCMuon(icsc);
00161 }
00162 }
00163
00164
00165 if ( m_id==3 ) {
00166 for ( unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++ ) {
00167 first[icsc] = m_gmt.Data()->CSCMuon(icsc);
00168 }
00169 for ( unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++ ) {
00170 second[idt] = m_gmt.Data()->DTBXMuon(idt);
00171 }
00172 }
00173
00174
00175 if ( m_id == 4 ) {
00176 for ( unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCbarrel; irpc++ ) {
00177 first[irpc] = m_gmt.Data()->RPCMuon(irpc);
00178 }
00179 for ( unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++ ) {
00180 second[icsc] = m_gmt.Data()->CSCMuon(icsc);
00181 }
00182 }
00183
00184
00185 if ( m_id == 5 ) {
00186 for ( unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCendcap; irpc++ ) {
00187 first[irpc] = m_gmt.Data()->RPCMuon(irpc+4);
00188 }
00189 for ( unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++ ) {
00190 second[idt] = m_gmt.Data()->DTBXMuon(idt);
00191 }
00192 }
00193 }
00194
00195
00196
00197
00198
00199 void L1MuGMTMatcher::match() {
00200
00201 L1MuGMTMatrix<bool> maxMatrix(MaxMatch,MaxMatch);
00202 L1MuGMTMatrix<bool> disableMatrix(MaxMatch,MaxMatch);
00203 maxMatrix.init(false);
00204 disableMatrix.init(false);
00205
00206
00207
00208 unsigned i,j;
00209 for ( i = 0; i < MaxMatch; i++ )
00210 for ( j = 0; j < MaxMatch; j++ )
00211 matchQuality(i,j) = lookup_mq(i,j);
00212
00213
00214 m_gmt.DebugBlockForFill()->SetMQMatrix( m_id, matchQuality) ;
00215
00216
00217
00218 for ( i = 0; i < MaxMatch; i++ )
00219 for ( j = 0; j < MaxMatch; j++ )
00220 maxMatrix(i,j) = matchQuality.isMax(i,j) && (matchQuality(i,j) != 0);
00221
00222
00223
00224 for ( i = 0; i < MaxMatch; i++ )
00225 for ( j = 0; j < MaxMatch; j++ ) {
00226
00227 for ( unsigned i1 = 0; i1 < MaxMatch; i1++ )
00228 if ( i1 != i ) disableMatrix(i,j) = disableMatrix(i,j) || maxMatrix(i1,j);
00229
00230 for ( unsigned j1 = 0; j1 < MaxMatch; j1++ )
00231 if ( j1 != j ) disableMatrix(i,j) = disableMatrix(i,j) || maxMatrix(i,j1);
00232 }
00233
00234
00235
00236 for ( i = 0; i < MaxMatch; i++ ) {
00237 for ( j = 0; j < MaxMatch; j++ ) {
00238
00239 bool max = true;
00240
00241 for ( unsigned i1 = 0; i1 < i; i1++ ) {
00242 max = max && ((matchQuality(i,j) > matchQuality(i1,j)) ||
00243 disableMatrix(i1,j));
00244 }
00245
00246 for ( unsigned i1 = i+1; i1 < MaxMatch; i1++ ) {
00247 max = max && ((matchQuality(i,j) >= matchQuality(i1,j)) ||
00248 disableMatrix(i1,j));
00249 }
00250
00251 for ( unsigned j1 = 0; j1 < j; j1++ ) {
00252 max = max && ((matchQuality(i,j) > matchQuality(i,j1)) ||
00253 disableMatrix(i,j1));
00254 }
00255
00256 for ( unsigned j1 = j+1; j1 < MaxMatch; j1++ ) {
00257 max = max && ((matchQuality(i,j) >= matchQuality(i,j1)) ||
00258 disableMatrix(i,j1));
00259 }
00260
00261 pairMatrix(i,j) = max && (matchQuality(i,j) != 0);
00262
00263 }
00264 }
00265
00266
00267 m_gmt.DebugBlockForFill()->SetPairMatrix( m_id, pairMatrix) ;
00268 }
00269
00270
00271
00272
00273 int L1MuGMTMatcher::lookup_mq(int i, int j) {
00274
00275 bool empty1 = ( first[i] != 0 ) ? first[i]->empty() : true;
00276 bool empty2 = ( second[j] != 0 ) ? second[j]->empty() : true;
00277 if ( empty1 || empty2) return 0;
00278
00279
00280
00281
00282 unsigned phi1 = first[i]->phi_packed();
00283 unsigned phi2 = second[j]->phi_packed();
00284
00285 int delta_phi = ( ( phi1 - phi2 + 3*72 ) % 144 ) - 72;
00286
00287 if (delta_phi < -3 || delta_phi >3)
00288 delta_phi = -4;
00289
00290 L1MuSignedPacking<3> DPhiPacking;
00291 unsigned delta_phi_packed = DPhiPacking.packedFromIdx (delta_phi);
00292
00293
00294
00295
00296 unsigned eta1 = first[i]->eta_packed();
00297 unsigned eta2 = second[j]->eta_packed();
00298
00299 unsigned delta_eta_packed = 0;
00300
00301 if (m_id == 0 || m_id == 1) {
00302
00303
00304 bool disable1 = L1MuGMTSortRankUnit::isDisabled(first[i]);
00305 bool disable2 = L1MuGMTSortRankUnit::isDisabled(second[j]);;
00306
00307 if (disable1 || disable2) return 0;
00308
00309 L1MuGMTLFDeltaEtaLUT* de_lut = L1MuGMTConfig::getLFDeltaEtaLUT();
00310 delta_eta_packed = de_lut->SpecificLookup_delta_eta (m_id, eta1, eta2);
00311 }
00312 else {
00313
00314 int idx1 = first[i]->type_idx();
00315 int idx1_dcrr = (idx1==1)?2:(idx1==2)?1:idx1;
00316
00317 int idx2 = second[j]->type_idx();
00318 int idx2_dcrr = (idx2==1)?2:(idx2==2)?1:idx2;
00319
00320 bool disable1 = L1MuGMTSortRankUnit::isDisabled(first[i]);
00321
00322 L1MuGMTLFDisableHotLUT* dishot_lut = L1MuGMTConfig::getLFDisableHotLUT();
00323 bool disable2 = dishot_lut->SpecificLookup_disable_hot (idx2_dcrr,
00324 second[j]->eta_packed(),
00325 second[j]->phi_packed()) == 1;
00326
00327 if (disable1 || disable2) return 0;
00328
00329
00330 L1MuGMTLFOvlEtaConvLUT* econv_lut = L1MuGMTConfig::getLFOvlEtaConvLUT();
00331
00332
00333 unsigned eta1_4bit = econv_lut->SpecificLookup_eta_ovl (idx1_dcrr, eta1);
00334 unsigned eta2_4bit = econv_lut->SpecificLookup_eta_ovl (idx2_dcrr, eta2);
00335
00336
00337 L1MuGMTLFCOUDeltaEtaLUT* cou_de_lut = L1MuGMTConfig::getLFCOUDeltaEtaLUT();
00338 delta_eta_packed = cou_de_lut->SpecificLookup_delta_eta (m_id-2, eta1_4bit, eta2_4bit);
00339 }
00340
00341
00342
00343
00344 L1MuGMTLFMatchQualLUT* mq_lut = L1MuGMTConfig::getLFMatchQualLUT();
00345
00346 unsigned mq = mq_lut->SpecificLookup_mq(m_id, delta_eta_packed, delta_phi_packed);
00347
00348 return mq;
00349 }
00350