CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1MuGMTMatcher.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 // Class: L1MuGMTMatcher
4 //
5 // Description: Matcher
6 //
7 //
8 //
9 // Author :
10 // N. Neumeister CERN EP
11 //
12 // Migrated to CMSSW:
13 // I. Mikulec
14 //
15 //--------------------------------------------------
16 
17 //-----------------------
18 // This Class's Header --
19 //-----------------------
20 
22 
23 //---------------
24 // C++ Headers --
25 //---------------
26 
27 #include <iostream>
28 #include <iomanip>
29 #include <cmath>
30 
31 #include <fstream>
32 #include <sstream>
33 
34 //-------------------------------
35 // Collaborating Class Headers --
36 //-------------------------------
37 
50 
52 
53 // --------------------------------
54 // class L1MuGMTMatcher
55 //---------------------------------
56 
57 //----------------
58 // Constructors --
59 //----------------
61  m_gmt(gmt), m_id(id), first(MaxMatch), second(MaxMatch),
62  matchQuality(MaxMatch,MaxMatch), pairMatrix(MaxMatch,MaxMatch) {
63 
64  first.reserve(MaxMatch);
65  second.reserve(MaxMatch);
66 
67 }
68 
69 //--------------
70 // Destructor --
71 //--------------
73 
74  reset();
75 
76 }
77 
78 //--------------
79 // Operations --
80 //--------------
81 
82 //
83 // run Muon Matcher
84 //
86 
87  load();
88  match();
89 
90 }
91 
92 //
93 // clear Matcher
94 //
96 
97  matchQuality.init(0);
98  pairMatrix.init(false);
99 
100  for ( unsigned i = 0; i < MaxMatch; i++ ) {
101  first[i] = 0;
102  second[i] = 0;
103  }
104 
105 }
106 
107 
108 //
109 // print matching results
110 //
112 
113  edm::LogVerbatim("GMT_Matcher_info");
114  if ( L1MuGMTConfig::Debug(4) ) {
115  edm::LogVerbatim("GMT_Matcher_info") << "MATCH Quality : ";
117  }
118 
119  edm::LogVerbatim("GMT_Matcher_info") << "PAIR Matrix : ";
120  pairMatrix.print();
121 
122  edm::LogVerbatim("GMT_Matcher_info");
123 
124 }
125 
126 
127 //
128 // load Matcher (get data from data buffer)
129 //
131 
132  // barrel matcher gets DTBX and barrel RPC muons
133  if ( m_id == 0 ) {
134  for ( unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++ ) {
135  first[idt] = m_gmt.Data()->DTBXMuon(idt);
136  }
137  for ( unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCbarrel; irpc++ ) {
138  second[irpc] = m_gmt.Data()->RPCMuon(irpc);
139  }
140  }
141 
142  // endcap matcher gets CSC and endcap RPC muons
143  if ( m_id == 1 ) {
144  for ( unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++ ) {
145  first[icsc] = m_gmt.Data()->CSCMuon(icsc);
146  }
147  for ( unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCendcap; irpc++ ) {
148  second[irpc] = m_gmt.Data()->RPCMuon(irpc+4);
149  }
150  }
151 
152  // matcher in DT/CSC cancel-out unit gets DTBX and CSC muons
153  if ( m_id == 2 ) {
154  for ( unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++ ) {
155  first[idt] = m_gmt.Data()->DTBXMuon(idt);
156  }
157  for ( unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++ ) {
158  second[icsc] = m_gmt.Data()->CSCMuon(icsc);
159  }
160  }
161 
162  // matcher in CSC/DT cancel-out unit gets CSC and DTBX muons
163  if ( m_id==3 ) {
164  for ( unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++ ) {
165  first[icsc] = m_gmt.Data()->CSCMuon(icsc);
166  }
167  for ( unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++ ) {
168  second[idt] = m_gmt.Data()->DTBXMuon(idt);
169  }
170  }
171 
172  // bRPC/CSC gets barrel RPC and CSC muons
173  if ( m_id == 4 ) {
174  for ( unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCbarrel; irpc++ ) {
175  first[irpc] = m_gmt.Data()->RPCMuon(irpc);
176  }
177  for ( unsigned icsc = 0; icsc < L1MuGMTConfig::MAXCSC; icsc++ ) {
178  second[icsc] = m_gmt.Data()->CSCMuon(icsc);
179  }
180  }
181 
182  // bRPC/DT matcher gets forward RPC and DTBX muons
183  if ( m_id == 5 ) {
184  for ( unsigned irpc = 0; irpc < L1MuGMTConfig::MAXRPCendcap; irpc++ ) {
185  first[irpc] = m_gmt.Data()->RPCMuon(irpc+4);
186  }
187  for ( unsigned idt = 0; idt < L1MuGMTConfig::MAXDTBX; idt++ ) {
188  second[idt] = m_gmt.Data()->DTBXMuon(idt);
189  }
190  }
191 }
192 
193 
194 //
195 // match muons
196 //
198 
200  L1MuGMTMatrix<bool> disableMatrix(MaxMatch,MaxMatch);
201  maxMatrix.init(false);
202  disableMatrix.init(false);
203 
204  // loop over all combinations
205 
206  unsigned i,j;
207  for ( i = 0; i < MaxMatch; i++ )
208  for ( j = 0; j < MaxMatch; j++ )
209  matchQuality(i,j) = lookup_mq(i,j);
210 
211  // store in debug block
213 
214  // fill MAX matrix
215 
216  for ( i = 0; i < MaxMatch; i++ )
217  for ( j = 0; j < MaxMatch; j++ )
218  maxMatrix(i,j) = matchQuality.isMax(i,j) && (matchQuality(i,j) != 0);
219 
220  // fill disable matrix
221 
222  for ( i = 0; i < MaxMatch; i++ )
223  for ( j = 0; j < MaxMatch; j++ ) {
224 
225  for ( unsigned i1 = 0; i1 < MaxMatch; i1++ )
226  if ( i1 != i ) disableMatrix(i,j) = disableMatrix(i,j) || maxMatrix(i1,j);
227 
228  for ( unsigned j1 = 0; j1 < MaxMatch; j1++ )
229  if ( j1 != j ) disableMatrix(i,j) = disableMatrix(i,j) || maxMatrix(i,j1);
230  }
231 
232  // fill pair matrix
233 
234  for ( i = 0; i < MaxMatch; i++ ) {
235  for ( j = 0; j < MaxMatch; j++ ) {
236 
237  bool max = true;
238 
239  for ( unsigned i1 = 0; i1 < i; i1++ ) {
240  max = max && ((matchQuality(i,j) > matchQuality(i1,j)) ||
241  disableMatrix(i1,j));
242  }
243 
244  for ( unsigned i1 = i+1; i1 < MaxMatch; i1++ ) {
245  max = max && ((matchQuality(i,j) >= matchQuality(i1,j)) ||
246  disableMatrix(i1,j));
247  }
248 
249  for ( unsigned j1 = 0; j1 < j; j1++ ) {
250  max = max && ((matchQuality(i,j) > matchQuality(i,j1)) ||
251  disableMatrix(i,j1));
252  }
253 
254  for ( unsigned j1 = j+1; j1 < MaxMatch; j1++ ) {
255  max = max && ((matchQuality(i,j) >= matchQuality(i,j1)) ||
256  disableMatrix(i,j1));
257  }
258 
259  pairMatrix(i,j) = max && (matchQuality(i,j) != 0);
260 
261  }
262  }
263 
264  // store in debug block
266 }
267 
268 //
269 // compare eta and phi of two muons
270 //
272 
273  bool empty1 = ( first[i] != 0 ) ? first[i]->empty() : true;
274  bool empty2 = ( second[j] != 0 ) ? second[j]->empty() : true;
275  if ( empty1 || empty2) return 0;
276 
277  //
278  // (1) calculate delta-phi (integer version)
279  //
280  unsigned phi1 = first[i]->phi_packed();
281  unsigned phi2 = second[j]->phi_packed();
282 
283  int delta_phi = ( ( phi1 - phi2 + 3*72 ) % 144 ) - 72;
284 
285  if (delta_phi < -3 || delta_phi >3)
286  delta_phi = -4;
287 
288  L1MuSignedPacking<3> DPhiPacking;
289  unsigned delta_phi_packed = DPhiPacking.packedFromIdx (delta_phi);
290 
291  //
292  // (2) look-up delta-eta
293  //
294  unsigned eta1 = first[i]->eta_packed();
295  unsigned eta2 = second[j]->eta_packed();
296 
297  unsigned delta_eta_packed = 0;
298 
299  if (m_id == 0 || m_id == 1) { // main matching units
300  // first is dt/csc, second is rpc
301 
302  bool disable1 = L1MuGMTSortRankUnit::isDisabled(first[i]);
303  bool disable2 = L1MuGMTSortRankUnit::isDisabled(second[j]);;
304 
305  if (disable1 || disable2) return 0;
306 
308  delta_eta_packed = de_lut->SpecificLookup_delta_eta (m_id, eta1, eta2);
309  }
310  else { // overlap cancel-out matching units
311  // first is own chip, second is other chip
312  int idx1 = first[i]->type_idx();
313  int idx1_dcrr = (idx1==1)?2:(idx1==2)?1:idx1;
314 
315  int idx2 = second[j]->type_idx();
316  int idx2_dcrr = (idx2==1)?2:(idx2==2)?1:idx2;
317 
318  bool disable1 = L1MuGMTSortRankUnit::isDisabled(first[i]);
319 
321  bool disable2 = dishot_lut->SpecificLookup_disable_hot (idx2_dcrr,
322  second[j]->eta_packed(),
323  second[j]->phi_packed()) == 1;
324 
325  if (disable1 || disable2) return 0;
326 
327  // convert eta to 4-bit, first
329 
330 
331  unsigned eta1_4bit = econv_lut->SpecificLookup_eta_ovl (idx1_dcrr, eta1);
332  unsigned eta2_4bit = econv_lut->SpecificLookup_eta_ovl (idx2_dcrr, eta2);
333 
334  // look up delta eta
336  delta_eta_packed = cou_de_lut->SpecificLookup_delta_eta (m_id-2, eta1_4bit, eta2_4bit);
337  }
338 
339  //
340  // (3) look up match quality
341  //
343 
344  unsigned mq = mq_lut->SpecificLookup_mq(m_id, delta_eta_packed, delta_phi_packed);
345 
346  return mq;
347 }
348 
int i
Definition: DBlmapReader.cc:9
virtual unsigned packedFromIdx(int idx) const
get the packed notation of a value, check range
Definition: L1MuPacking.h:100
const L1MuGlobalMuonTrigger & m_gmt
void init(T v=0)
initialize matrix
bool isMax(int r, int c) const
is the element (r,c) the max. entry in its row and column?
virtual ~L1MuGMTMatcher()
destructor
static bool isDisabled(const L1MuRegionalCand *)
Diable bit.
unsigned SpecificLookup_eta_ovl(int idx, unsigned eta6) const
specific lookup function for eta_ovl
static L1MuGMTLFMatchQualLUT * getLFMatchQualLUT()
void run()
run Matcher
static L1MuGMTLFOvlEtaConvLUT * getLFOvlEtaConvLUT()
unsigned SpecificLookup_mq(int idx, unsigned delta_eta, unsigned delta_phi) const
specific lookup function for mq
void print()
print matching results
const L1MuRegionalCand * CSCMuon(int index) const
get CSC muon
Definition: L1MuGMTPSB.cc:254
std::vector< const L1MuRegionalCand * > second
U second(std::pair< T, U > const &p)
static L1MuGMTLFDeltaEtaLUT * getLFDeltaEtaLUT()
int lookup_mq(int i, int j)
static bool Debug()
void SetPairMatrix(int idx, L1MuGMTMatrix< bool > pm)
Set pair matrices.
unsigned SpecificLookup_delta_eta(int idx, unsigned eta_dtcsc, unsigned eta_rpc) const
specific lookup function for delta_eta
const L1MuGMTPSB * Data() const
return pointer to PSB
const L1MuRegionalCand * RPCMuon(int index) const
get RPC muon
Definition: L1MuGMTPSB.cc:234
int j
Definition: DBlmapReader.cc:9
int irpc
void print() const
print matrix
static const unsigned int MAXCSC
Definition: L1MuGMTConfig.h:89
static const unsigned int MAXDTBX
Definition: L1MuGMTConfig.h:89
static const unsigned int MAXRPCendcap
Definition: L1MuGMTConfig.h:88
static L1MuGMTLFDisableHotLUT * getLFDisableHotLUT()
std::vector< const L1MuRegionalCand * > first
void SetMQMatrix(int idx, L1MuGMTMatrix< int > mqm)
Set match quality matrices.
bool first
Definition: L1TdeRCT.cc:75
double delta_phi(double ph11, double phi2)
Definition: AnglesUtil.h:91
L1MuGMTMatrix< bool > pairMatrix
void reset()
clear Matcher
const L1MuRegionalCand * DTBXMuon(int index) const
get DTBX muon
Definition: L1MuGMTPSB.cc:244
static L1MuGMTLFCOUDeltaEtaLUT * getLFCOUDeltaEtaLUT()
static const unsigned int MaxMatch
L1MuGMTMatcher(const L1MuGlobalMuonTrigger &gmt, int id)
constructor
static const unsigned int MAXRPCbarrel
Definition: L1MuGMTConfig.h:88
L1MuGMTMatrix< int > matchQuality
L1MuGMTDebugBlock * DebugBlockForFill() const
for debug: return the debug block (in order to fill it)
unsigned SpecificLookup_disable_hot(int idx, unsigned eta, unsigned phi) const
specific lookup function for disable_hot
unsigned SpecificLookup_delta_eta(int idx, unsigned eta1, unsigned eta2) const
specific lookup function for delta_eta