CMS 3D CMS Logo

TrackMuonMatchAlgorithm.h
Go to the documentation of this file.
1 #ifndef PHASE2GMT_TRACKMUONMATCHALGO
2 #define PHASE2GMT_TRACKMUONMATCHALGO
3 
12 #include "TrackConverter.h"
13 #include "PreTrackMatchedMuon.h"
15 #include "MuonROI.h"
16 #include "ConvertedTTTrack.h"
17 #include "Constants.h"
18 #include <fstream>
19 
20 namespace Phase2L1GMT {
21 
22  const unsigned int PHIDIVIDER = 1 << (BITSPHI - BITSSTUBCOORD);
23  const unsigned int ETADIVIDER = 1 << (BITSETA - BITSSTUBETA);
24 
25  typedef struct {
26  ap_int<BITSSTUBCOORD> coord1;
27  ap_uint<BITSSIGMACOORD> sigma_coord1;
28  ap_int<BITSSTUBCOORD> coord2;
29  ap_uint<BITSSIGMACOORD> sigma_coord2;
30  ap_int<BITSSTUBETA> eta;
31  ap_uint<BITSSIGMAETA> sigma_eta1;
32  ap_uint<BITSSIGMAETA> sigma_eta2;
33  ap_uint<1> valid;
34  ap_uint<1> is_barrel;
35  } propagation_t;
36 
37  typedef struct {
38  ap_uint<BITSMATCHQUALITY - 2> quality;
39  ap_uint<BITSSTUBID> id;
40  ap_uint<1> valid;
41  bool isGlobal;
44 
45  } match_t;
46 
48  public:
49  TrackMuonMatchAlgorithm(const edm::ParameterSet& iConfig) : verbose_(iConfig.getParameter<int>("verbose")) {}
50 
52 
53  std::vector<PreTrackMatchedMuon> processNonant(const std::vector<ConvertedTTTrack>& convertedTracks,
54  const std::vector<MuonROI>& rois) {
55  std::vector<PreTrackMatchedMuon> preMuons;
56  for (const auto& track : convertedTracks) {
58  if (mu.valid() && preMuons.size() < 16)
59  preMuons.push_back(mu);
60  }
61  std::vector<PreTrackMatchedMuon> cleanedMuons = clean(preMuons);
62  return cleanedMuons;
63  }
64 
65  std::vector<PreTrackMatchedMuon> cleanNeighbor(const std::vector<PreTrackMatchedMuon>& muons,
66  const std::vector<PreTrackMatchedMuon>& muonsPrevious,
67  const std::vector<PreTrackMatchedMuon>& muonsNext,
68  bool equality) {
69  std::vector<PreTrackMatchedMuon> out;
70 
71  if (muons.empty())
72  return out;
73 
74  if (verbose_ == 1) {
75  printf("-----Cleaning Up Muons in the neighbours\n");
76  printf("Before:\n");
77  }
78 
79  for (uint i = 0; i < muons.size(); ++i) {
80  if (verbose_ == 1) {
81  muons[i].print();
82  }
83  ap_uint<5> mask = 0x1f;
84  for (uint j = 0; j < muonsPrevious.size(); ++j) {
85  mask = mask & cleanMuon(muons[i], muonsPrevious[j], equality);
86  }
87  for (uint j = 0; j < muonsNext.size(); ++j) {
88  mask = mask & cleanMuon(muons[i], muonsNext[j], equality);
89  }
90  if (mask) {
91  if (verbose_ == 1)
92  printf("kept\n");
93  out.push_back(muons[i]);
94  } else {
95  if (verbose_ == 1)
96  printf("discarded\n");
97  }
98  }
99  return out;
100  }
101 
102  std::vector<l1t::TrackerMuon> convert(std::vector<PreTrackMatchedMuon>& muons, uint maximum) {
103  std::vector<l1t::TrackerMuon> out;
104  for (const auto& mu : muons) {
105  if (out.size() == maximum)
106  break;
107  l1t::TrackerMuon muon(mu.trkPtr(), mu.charge(), mu.pt(), mu.eta(), mu.phi(), mu.z0(), mu.d0(), mu.quality());
108  //muon.setMuonRef(mu.muonRef());
109  for (const auto& stub : mu.stubs())
110  muon.addStub(stub);
111  out.push_back(muon);
112  if (verbose_ == 1) {
113  printf("Final Muon:");
114  muon.print();
115  }
116  }
117  return out;
118  }
119 
120  bool outputGT(std::vector<l1t::TrackerMuon>& muons) {
121  for (auto& mu : muons) {
122  wordtype word1 = 0;
123  wordtype word2 = 0;
124 
125  int bstart = 0;
126  bstart = wordconcat<wordtype>(word1, bstart, mu.hwPt(), BITSGTPT);
127  bstart = wordconcat<wordtype>(word1, bstart, mu.hwPhi(), BITSGTPHI);
128  bstart = wordconcat<wordtype>(word1, bstart, mu.hwEta(), BITSGTETA);
129  bstart = wordconcat<wordtype>(word1, bstart, mu.hwZ0(), BITSGTZ0);
130  bstart = wordconcat<wordtype>(word1, bstart, (mu.hwD0() >> 2), BITSGTD0);
131 
132  bstart = 0;
133  bstart = wordconcat<wordtype>(word2, bstart, mu.hwCharge(), 1);
134  bstart = wordconcat<wordtype>(word2, bstart, mu.hwQual(), BITSGTQUALITY);
135  bstart = wordconcat<wordtype>(word2, bstart, mu.hwIso(), BITSGTISO);
136  bstart = wordconcat<wordtype>(word2, bstart, mu.hwBeta(), BITSMUONBETA);
137 
138  std::array<uint64_t, 2> wordout = {{word1, word2}};
139  mu.setWord(wordout);
140  }
141  return true;
142  }
143 
144  std::vector<l1t::TrackerMuon> sort(std::vector<l1t::TrackerMuon>& muons, uint maximum) {
145  if (muons.size() < 2)
146  return muons;
147 
148  std::sort(muons.begin(), muons.end(), [](l1t::TrackerMuon a, l1t::TrackerMuon b) { return a.hwPt() > b.hwPt(); });
149  std::vector<l1t::TrackerMuon> out;
150  for (unsigned int i = 0; i < muons.size(); ++i) {
151  out.push_back(muons[i]);
152  if (i == (maximum - 1))
153  break;
154  }
155 
156  return out;
157  }
158 
159  private:
160  int verbose_;
161 
163  ap_uint<BITSPROPCOORD> prop_coord1 = 0;
164  ap_uint<BITSPROPCOORD> prop_coord2 = 0;
165  ap_uint<BITSPROPSIGMACOORD_A> res0_coord1 = 0;
166  ap_uint<BITSPROPSIGMACOORD_B> res1_coord1 = 0;
167  ap_uint<BITSPROPSIGMACOORD_A> res0_coord2 = 0;
168  ap_uint<BITSPROPSIGMACOORD_B> res1_coord2 = 0;
169  ap_uint<BITSPROPSIGMAETA_A> res0_eta1 = 0;
170  ap_uint<BITSPROPSIGMAETA_B> res1_eta = 0;
171  ap_uint<BITSPROPSIGMAETA_A> res0_eta2 = 0;
172  ap_uint<1> is_barrel = 0;
173 
174  uint reducedAbsEta = track.abseta() / 8;
175 
176  if (layer == 0) {
177  prop_coord1 = lt_prop_coord1_0[reducedAbsEta];
178  prop_coord2 = lt_prop_coord2_0[reducedAbsEta];
179  res0_coord1 = lt_res0_coord1_0[reducedAbsEta];
180  res1_coord1 = lt_res1_coord1_0[reducedAbsEta];
181  res0_coord2 = lt_res0_coord2_0[reducedAbsEta];
182  res1_coord2 = lt_res1_coord2_0[reducedAbsEta];
183  res0_eta1 = lt_res0_eta1_0[reducedAbsEta];
184  res1_eta = lt_res1_eta_0[reducedAbsEta];
185  res0_eta2 = lt_res0_eta2_0[reducedAbsEta];
186  is_barrel = reducedAbsEta < barrelLimit0_ ? 1 : 0;
187  } else if (layer == 1) {
188  prop_coord1 = lt_prop_coord1_1[reducedAbsEta];
189  prop_coord2 = lt_prop_coord2_1[reducedAbsEta];
190  res0_coord1 = lt_res0_coord1_1[reducedAbsEta];
191  res1_coord1 = lt_res1_coord1_1[reducedAbsEta];
192  res0_coord2 = lt_res0_coord2_1[reducedAbsEta];
193  res1_coord2 = lt_res1_coord2_1[reducedAbsEta];
194  res0_eta1 = lt_res0_eta1_1[reducedAbsEta];
195  res1_eta = lt_res1_eta_1[reducedAbsEta];
196  res0_eta2 = lt_res0_eta2_1[reducedAbsEta];
197  is_barrel = reducedAbsEta < barrelLimit1_ ? 1 : 0;
198 
199  } else if (layer == 2) {
200  prop_coord1 = lt_prop_coord1_2[reducedAbsEta];
201  prop_coord2 = lt_prop_coord2_2[reducedAbsEta];
202  res0_coord1 = lt_res0_coord1_2[reducedAbsEta];
203  res1_coord1 = lt_res1_coord1_2[reducedAbsEta];
204  res0_coord2 = lt_res0_coord2_2[reducedAbsEta];
205  res1_coord2 = lt_res1_coord2_2[reducedAbsEta];
206  res0_eta1 = lt_res0_eta1_2[reducedAbsEta];
207  res1_eta = lt_res1_eta_2[reducedAbsEta];
208  res0_eta2 = lt_res0_eta2_2[reducedAbsEta];
209  is_barrel = reducedAbsEta < barrelLimit2_ ? 1 : 0;
210 
211  } else if (layer == 3) {
212  prop_coord1 = lt_prop_coord1_3[reducedAbsEta];
213  prop_coord2 = lt_prop_coord2_3[reducedAbsEta];
214  res0_coord1 = lt_res0_coord1_3[reducedAbsEta];
215  res1_coord1 = lt_res1_coord1_3[reducedAbsEta];
216  res0_coord2 = lt_res0_coord2_3[reducedAbsEta];
217  res1_coord2 = lt_res1_coord2_3[reducedAbsEta];
218  res0_eta1 = lt_res0_eta1_3[reducedAbsEta];
219  res1_eta = lt_res1_eta_3[reducedAbsEta];
220  res0_eta2 = lt_res0_eta2_3[reducedAbsEta];
221  is_barrel = reducedAbsEta < barrelLimit3_ ? 1 : 0;
222 
223  } else if (layer == 4) {
224  prop_coord1 = lt_prop_coord1_4[reducedAbsEta];
225  prop_coord2 = lt_prop_coord2_4[reducedAbsEta];
226  res0_coord1 = lt_res0_coord1_4[reducedAbsEta];
227  res1_coord1 = lt_res1_coord1_4[reducedAbsEta];
228  res0_coord2 = lt_res0_coord2_4[reducedAbsEta];
229  res1_coord2 = lt_res1_coord2_4[reducedAbsEta];
230  res0_eta1 = lt_res0_eta1_4[reducedAbsEta];
231  res1_eta = lt_res1_eta_4[reducedAbsEta];
232  res0_eta2 = lt_res0_eta2_4[reducedAbsEta];
233  is_barrel = 0;
234  }
235 
237  ap_int<BITSTTCURV> curvature = track.curvature();
238  ap_int<BITSPHI> phi = track.phi();
239  ap_int<BITSPROPCOORD + BITSTTCURV> c1kFull = prop_coord1 * curvature;
240  ap_int<BITSPROPCOORD + BITSTTCURV - 10> c1k = (c1kFull) / 1024;
241  ap_int<BITSPHI> coord1 = phi - c1k;
242 
243  out.coord1 = coord1 / PHIDIVIDER;
244 
245  ap_int<BITSPROPCOORD + BITSTTCURV> c2kFull = prop_coord2 * curvature;
246 
247  ap_int<BITSPROPCOORD + BITSTTCURV - 10> c2k = (c2kFull) / 1024;
248  if (is_barrel)
249  out.coord2 = -c2k / PHIDIVIDER;
250  else
251  out.coord2 = (phi - c2k) / PHIDIVIDER;
252 
253  ap_int<BITSETA> eta = track.eta();
254  out.eta = eta / ETADIVIDER;
255 
256  ap_uint<2 * BITSTTCURV - 2> curvature2All = curvature * curvature;
257  ap_uint<BITSTTCURV2> curvature2 = curvature2All / 2;
258 
259  //Remember to change emulator with new k2
260  ap_uint<BITSPROPSIGMACOORD_B + BITSTTCURV2> rescoord1k = (res1_coord1 * curvature2) >> 23;
261  ap_ufixed<BITSSIGMACOORD, BITSSIGMACOORD, AP_TRN_ZERO, AP_SAT_SYM> sigma_coord1 = res0_coord1 + rescoord1k;
262  out.sigma_coord1 = ap_uint<BITSSIGMACOORD>(sigma_coord1);
263 
264  ap_uint<BITSPROPSIGMACOORD_B + BITSTTCURV2> rescoord2k = (res1_coord2 * curvature2) >> 23;
265  ap_ufixed<BITSSIGMACOORD, BITSSIGMACOORD, AP_TRN_ZERO, AP_SAT_SYM> sigma_coord2 = res0_coord2 + rescoord2k;
266  out.sigma_coord2 = ap_uint<BITSSIGMACOORD>(sigma_coord2);
267 
268  ap_uint<BITSPROPSIGMAETA_B + BITSTTCURV2> resetak = (res1_eta * curvature2) >> 23;
269  ap_ufixed<BITSSIGMAETA, BITSSIGMAETA, AP_TRN_ZERO, AP_SAT_SYM> sigma_eta1 = res0_eta1 + resetak;
270  out.sigma_eta1 = ap_uint<BITSSIGMAETA>(sigma_eta1);
271  ap_ufixed<BITSSIGMAETA, BITSSIGMAETA, AP_TRN_ZERO, AP_SAT_SYM> sigma_eta2 = res0_eta2 + resetak;
272  out.sigma_eta2 = ap_uint<BITSSIGMAETA>(sigma_eta2);
273  out.valid = 1;
274  out.is_barrel = is_barrel;
275 
276  if (verbose_ == 1)
277 
278  printf("Propagating to layer %d:is barrel=%d coords=%d+-%d , %d +-%d etas = %d +- %d +-%d\n",
279  int(layer),
280  out.is_barrel.to_int(),
281  out.coord1.to_int(),
282  out.sigma_coord1.to_int(),
283  out.coord2.to_int(),
284  out.sigma_coord2.to_int(),
285  out.eta.to_int(),
286  out.sigma_eta1.to_int(),
287  out.sigma_eta2.to_int());
288 
289  return out;
290  }
291 
292  ap_uint<BITSSIGMAETA + 1> deltaEta(const ap_int<BITSSTUBETA>& eta1, const ap_int<BITSSTUBETA>& eta2) {
293  ap_fixed<BITSSIGMAETA + 2, BITSSIGMAETA + 2, AP_TRN_ZERO, AP_SAT_SYM> dEta = eta1 - eta2;
294  if (dEta < 0)
295  return ap_uint<BITSSIGMAETA + 1>(-dEta);
296  else
297  return ap_uint<BITSSIGMAETA + 1>(dEta);
298  }
299 
300  ap_uint<BITSSIGMACOORD + 1> deltaCoord(const ap_int<BITSSTUBCOORD>& phi1, const ap_int<BITSSTUBCOORD>& phi2) {
301  ap_int<BITSSTUBCOORD> dPhiRoll = phi1 - phi2;
302  ap_ufixed<BITSSIGMACOORD + 1, BITSSIGMACOORD + 1, AP_TRN_ZERO, AP_SAT_SYM> dPhi;
303  if (dPhiRoll < 0)
304  dPhi = ap_ufixed<BITSSIGMACOORD + 1, BITSSIGMACOORD + 1, AP_TRN_ZERO, AP_SAT_SYM>(-dPhiRoll);
305  else
306  dPhi = ap_ufixed<BITSSIGMACOORD + 1, BITSSIGMACOORD + 1, AP_TRN_ZERO, AP_SAT_SYM>(dPhiRoll);
307 
308  return ap_uint<BITSSIGMACOORD + 1>(dPhi);
309  }
310 
311  match_t match(const propagation_t prop, const l1t::MuonStubRef& stub) {
312  if (verbose_ == 1) {
313  printf("Matching to ");
314  stub->print();
315  }
316  //Matching of Coord1
317  ap_uint<1> coord1Matched;
318  ap_uint<BITSSIGMACOORD + 1> deltaCoord1 = deltaCoord(prop.coord1, stub->coord1());
319  if (deltaCoord1 <= prop.sigma_coord1 && (stub->quality() & 0x1)) {
320  coord1Matched = 1;
321  } else {
322  coord1Matched = 0;
323  }
324  if (verbose_ == 1)
325  printf("Coord1 matched=%d delta=%d res=%d\n",
326  coord1Matched.to_int(),
327  deltaCoord1.to_int(),
328  prop.sigma_coord1.to_int());
329 
330  //Matching of Coord2
331  ap_uint<1> coord2Matched;
332  ap_uint<BITSSIGMACOORD + 1> deltaCoord2 = deltaCoord(prop.coord2, stub->coord2());
333  if (deltaCoord2 <= prop.sigma_coord2 && (stub->quality() & 0x2)) {
334  coord2Matched = 1;
335  } else {
336  coord2Matched = 0;
337  }
338  if (verbose_ == 1)
339  printf("Coord2 matched=%d delta=%d res=%d\n",
340  coord2Matched.to_int(),
341  deltaCoord2.to_int(),
342  prop.sigma_coord2.to_int());
343 
344  //Matching of Eta1
345 
346  ap_uint<1> eta1Matched;
347 
348  //if we have really bad quality[Barrel no eta]
349  //increase the resolution
350  ap_ufixed<BITSSIGMAETA, BITSSIGMAETA, AP_TRN_ZERO, AP_SAT_SYM> prop_sigma_eta1;
351  if (stub->etaQuality() == 0)
352  prop_sigma_eta1 = prop.sigma_eta1 + 6;
353  else
354  prop_sigma_eta1 = prop.sigma_eta1;
355 
356  ap_uint<BITSSIGMAETA + 1> deltaEta1 = deltaEta(prop.eta, stub->eta1());
357  if (deltaEta1 <= prop_sigma_eta1 && (stub->etaQuality() == 0 || (stub->etaQuality() & 0x1)))
358  eta1Matched = 1;
359  else
360  eta1Matched = 0;
361 
362  if (verbose_ == 1)
363  printf("eta1 matched=%d delta=%d res=%d\n", eta1Matched.to_int(), deltaEta1.to_int(), prop_sigma_eta1.to_int());
364 
365  //Matching of Eta2
366 
367  ap_uint<1> eta2Matched;
368 
369  ap_uint<BITSSIGMAETA + 1> deltaEta2 = deltaEta(prop.eta, stub->eta2());
370  if (deltaEta2 <= prop.sigma_eta2 && (stub->etaQuality() & 0x2))
371  eta2Matched = 1;
372  else
373  eta2Matched = 0;
374  match_t out;
375  out.id = stub->id();
376 
377  if (verbose_ == 1)
378  printf("eta2 matched=%d delta=%d res=%d\n", eta2Matched.to_int(), deltaEta2.to_int(), prop.sigma_eta2.to_int());
379 
380  //if barrel, coord1 has to always be matched, coord2 maybe and eta1 is needed if etaQ=0 or then the one that depends on eta quality
381  if (prop.is_barrel) {
382  out.valid = (coord1Matched == 1 && (eta1Matched == 1 || eta2Matched == 1));
383  if (out.valid == 0) {
384  out.quality = 0;
385  } else {
386  out.quality = 32 - deltaCoord1;
387  if (coord2Matched == 1)
388  out.quality += 32 - deltaCoord2;
389  }
390  }
391  //if endcap each coordinate is independent except the case where phiQuality=1 and etaQuality==3
392  else {
393  bool match1 = (coord1Matched == 1 && eta1Matched == 1);
394  bool match2 = (coord2Matched == 1 && eta2Matched == 1);
395  bool match3 =
396  (coord1Matched == 1 && (eta1Matched || eta2Matched) && stub->etaQuality() == 3 && stub->quality() == 1);
397  out.valid = match1 || match2 || match3;
398  if (out.valid == 0)
399  out.quality = 0;
400  else {
401  out.quality = 0;
402  if (match1 || match3)
403  out.quality += 32 - deltaCoord1;
404  if (match2)
405  out.quality += 32 - deltaCoord2;
406  }
407  }
408  if (verbose_ == 1)
409  printf("GlobalMatchQuality = %d\n", out.quality.to_int());
410  out.stubRef = stub;
411  return out;
412  }
413 
415  propagation_t prop = propagate(track, stub->tfLayer());
416  return match(prop, stub);
417  }
418 
419  match_t getBest(const std::vector<match_t> matches) {
420  match_t best = matches[0];
421  for (const auto& m : matches) {
422  if (m.quality > best.quality)
423  best = m;
424  }
425 
426  return best;
427  }
428 
429  PreTrackMatchedMuon processTrack(const ConvertedTTTrack& track, const std::vector<MuonROI>& rois) {
430  std::vector<match_t> matchInfo0;
431  std::vector<match_t> matchInfo1;
432  std::vector<match_t> matchInfo2;
433  std::vector<match_t> matchInfo3;
434  std::vector<match_t> matchInfo4;
435 
436  if (verbose_ == 1 && !rois.empty()) {
437  printf("-----------processing new track----------");
438  track.print();
439  }
440  for (const auto& roi : rois) {
441  if (verbose_ == 1) {
442  printf("New ROI with %d stubs \n", int(roi.stubs().size()));
443  }
444  for (const auto& stub : roi.stubs()) {
445  match_t m = propagateAndMatch(track, stub);
446  if (m.valid == 1) {
447  if (roi.isGlobalMuon() && roi.muonRef().isNonnull()) {
448  m.isGlobal = true;
449  m.muRef = roi.muonRef();
450  }
451 
452  if (stub->tfLayer() == 0)
453  matchInfo0.push_back(m);
454  else if (stub->tfLayer() == 1)
455  matchInfo1.push_back(m);
456  else if (stub->tfLayer() == 2)
457  matchInfo2.push_back(m);
458  else if (stub->tfLayer() == 3)
459  matchInfo3.push_back(m);
460  else if (stub->tfLayer() == 4)
461  matchInfo4.push_back(m);
462  }
463  }
464  }
465 
466  ap_ufixed<6, 6, AP_TRN_ZERO, AP_SAT_SYM> ptPenalty = ap_ufixed<6, 6, AP_TRN_ZERO, AP_SAT_SYM>(track.pt() / 32);
467 
468  ap_uint<BITSMATCHQUALITY> quality = 0;
469  PreTrackMatchedMuon muon(track.charge(), track.pt(), track.eta(), track.phi(), track.z0(), track.d0());
470 
471  if (!matchInfo0.empty()) {
472  match_t b = getBest(matchInfo0);
473  if (b.valid) {
474  muon.addStub(b.stubRef);
475  if (b.isGlobal)
476  muon.addMuonRef(b.muRef);
477  quality += b.quality;
478  }
479  }
480  if (!matchInfo1.empty()) {
481  match_t b = getBest(matchInfo1);
482  if (b.valid) {
483  muon.addStub(b.stubRef);
484  if (b.isGlobal)
485  muon.addMuonRef(b.muRef);
486  quality += b.quality;
487  }
488  }
489  if (!matchInfo2.empty()) {
490  match_t b = getBest(matchInfo2);
491  if (b.valid) {
492  muon.addStub(b.stubRef);
493  if (b.isGlobal)
494  muon.addMuonRef(b.muRef);
495  quality += b.quality;
496  }
497  }
498  if (!matchInfo3.empty()) {
499  match_t b = getBest(matchInfo3);
500  if (b.valid) {
501  muon.addStub(b.stubRef);
502  if (b.isGlobal)
503  muon.addMuonRef(b.muRef);
504  quality += b.quality;
505  }
506  }
507  if (!matchInfo4.empty()) {
508  match_t b = getBest(matchInfo4);
509  if (b.valid) {
510  muon.addStub(b.stubRef);
511  if (b.isGlobal)
512  muon.addMuonRef(b.muRef);
513  quality += b.quality;
514  }
515  }
516 
517  muon.setOfflineQuantities(track.offline_pt(), track.offline_eta(), track.offline_phi());
518  muon.setTrkPtr(track.trkPtr());
519 
520  ap_uint<8> etaAddr = muon.eta() < 0 ? ap_uint<8>(-muon.eta() / 256) : ap_uint<8>((muon.eta()) / 256);
521  ap_uint<8> ptAddr = muon.pt() > 4095 ? ap_uint<8>(15) : ap_uint<8>(muon.pt() / 256);
522  ap_uint<8> addr = ptAddr | (etaAddr << 4);
523  ap_uint<8> qualityCut = lt_tpsID[addr];
524 
525  if (quality >= qualityCut) {
526  muon.setValid(true);
527  muon.setQuality(quality + ptPenalty);
528  } else {
529  muon.setValid(false);
530  muon.setQuality(0);
531  muon.resetGlobal();
532  }
533  if (verbose_ == 1)
534  muon.print();
535 
536  if (verbose_ == 1 && !rois.empty()) { //patterns for HLS
537 
538  printf("TPS %d", track.trkPtr()->phiSector());
539  track.printWord();
540 
541  for (uint i = 0; i < 16; ++i) {
542  if (rois.size() > i) {
543  rois[i].printROILine();
544  } else {
545  printf("%08x", 0);
546  printf("%016lx", 0x1ff000000000000);
547  printf("%016lx", 0x1ff000000000000);
548  printf("%016lx", 0x1ff000000000000);
549  printf("%016lx", 0x1ff000000000000);
550  printf("%016lx", 0x1ff000000000000);
551  }
552  }
553  muon.printWord();
554  printf("\n");
555  }
556  return muon;
557  }
558 
559  ap_uint<5> cleanMuon(const PreTrackMatchedMuon& mu, const PreTrackMatchedMuon& other, bool eq) {
560  ap_uint<5> valid = 0;
561  ap_uint<5> overlap = 0;
562  if (mu.stubID0() != 511) {
563  valid = valid | 0x1;
564  if (mu.stubID0() == other.stubID0())
565  overlap = overlap | 0x1;
566  }
567  if (mu.stubID1() != 511) {
568  valid = valid | 0x2;
569  if (mu.stubID1() == other.stubID1())
570  overlap = overlap | 0x2;
571  }
572  if (mu.stubID2() != 511) {
573  valid = valid | 0x4;
574  if (mu.stubID2() == other.stubID2())
575  overlap = overlap | 0x4;
576  }
577  if (mu.stubID3() != 511) {
578  valid = valid | 0x8;
579  if (mu.stubID3() == other.stubID3())
580  overlap = overlap | 0x8;
581  }
582  if (mu.stubID4() != 511) {
583  valid = valid | 0x10;
584  if (mu.stubID4() == other.stubID4())
585  overlap = overlap | 0x10;
586  }
587 
588  if (((mu.quality() < other.quality()) && (!eq)) || ((mu.quality() <= other.quality()) && (eq)))
589  return valid & (~overlap);
590  else
591  return valid;
592  }
593 
594  std::vector<PreTrackMatchedMuon> clean(std::vector<PreTrackMatchedMuon>& muons) {
595  std::vector<PreTrackMatchedMuon> out;
596  if (muons.empty())
597  return out;
598  if (verbose_ == 1) {
599  printf("-----Cleaning Up Muons in the same Nonant\n");
600  printf("Before:\n");
601  }
602  for (uint i = 0; i < muons.size(); ++i) {
603  if (verbose_ == 1)
604  muons[i].print();
605 
606  ap_uint<5> mask = 0x1f;
607  for (uint j = 0; j < muons.size(); ++j) {
608  if (i == j)
609  continue;
610  mask = mask & cleanMuon(muons[i], muons[j], false);
611  }
612  if (mask) {
613  if (verbose_ == 1)
614  printf("kept\n");
615  out.push_back(muons[i]);
616  } else {
617  if (verbose_ == 1)
618  printf("discarded\n");
619  }
620  }
621  return out;
622  }
623  };
624 } // namespace Phase2L1GMT
625 
626 #endif
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_3[512]
Definition: Constants.h:635
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_0[512]
Definition: Constants.h:1011
const int barrelLimit0_
Definition: Constants.h:74
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_4[512]
Definition: Constants.h:1092
ap_uint< BITSSIGMACOORD > sigma_coord1
const int BITSGTZ0
Definition: Constants.h:63
const int barrelLimit1_
Definition: Constants.h:75
std::vector< l1t::TrackerMuon > convert(std::vector< PreTrackMatchedMuon > &muons, uint maximum)
const int BITSSTUBCOORD
Definition: Constants.h:31
const int barrelLimit3_
Definition: Constants.h:77
const ap_uint< BITSPROPCOORD > lt_prop_coord1_0[512]
Definition: Constants.h:338
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_2[512]
Definition: Constants.h:1144
const ap_uint< BITSPROPCOORD > lt_prop_coord1_2[512]
Definition: Constants.h:388
const int BITSGTETA
Definition: Constants.h:62
const int BITSGTISO
Definition: Constants.h:66
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_0[512]
Definition: Constants.h:752
const int BITSGTPHI
Definition: Constants.h:61
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_2[512]
Definition: Constants.h:953
std::vector< l1t::TrackerMuon > sort(std::vector< l1t::TrackerMuon > &muons, uint maximum)
const int BITSMATCHQUALITY
Definition: Constants.h:41
ap_int< BITSSTUBCOORD > coord1
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_1[512]
Definition: Constants.h:1128
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_4[512]
Definition: Constants.h:736
const ap_uint< BITSPROPCOORD > lt_prop_coord2_1[512]
Definition: Constants.h:487
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_3[512]
Definition: Constants.h:969
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_4[512]
Definition: Constants.h:816
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_1[512]
Definition: Constants.h:768
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_1[512]
Definition: Constants.h:688
l1t::RegionalMuonCandRef muRef
const ap_uint< BITSPROPCOORD > lt_prop_coord2_4[512]
Definition: Constants.h:562
const ap_uint< BITSPROPCOORD > lt_prop_coord2_0[512]
Definition: Constants.h:463
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_3[512]
Definition: Constants.h:880
const int BITSSTUBETA
Definition: Constants.h:32
ap_uint< BITSSIGMAETA > sigma_eta2
ap_uint< 5 > cleanMuon(const PreTrackMatchedMuon &mu, const PreTrackMatchedMuon &other, bool eq)
const ap_uint< BITSPROPCOORD > lt_prop_coord1_4[512]
Definition: Constants.h:438
constexpr uint32_t mask
Definition: gpuClustering.h:26
T curvature(T InversePt, const MagneticField &field)
ap_uint< BITSSIGMACOORD > sigma_coord2
std::vector< PreTrackMatchedMuon > cleanNeighbor(const std::vector< PreTrackMatchedMuon > &muons, const std::vector< PreTrackMatchedMuon > &muonsPrevious, const std::vector< PreTrackMatchedMuon > &muonsNext, bool equality)
ap_uint< 64 > wordtype
Definition: Constants.h:89
ap_uint< BITSSIGMAETA+1 > deltaEta(const ap_int< BITSSTUBETA > &eta1, const ap_int< BITSSTUBETA > &eta2)
const int barrelLimit2_
Definition: Constants.h:76
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_2[512]
Definition: Constants.h:784
const ap_uint< BITSPROPCOORD > lt_prop_coord1_1[512]
Definition: Constants.h:363
string quality
const ap_uint< BITSPROPCOORD > lt_prop_coord2_3[512]
Definition: Constants.h:537
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_4[512]
Definition: Constants.h:1176
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_2[512]
Definition: Constants.h:704
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_1[512]
Definition: Constants.h:933
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_1[512]
Definition: Constants.h:603
const int BITSETA
Definition: Constants.h:26
std::vector< PreTrackMatchedMuon > processNonant(const std::vector< ConvertedTTTrack > &convertedTracks, const std::vector< MuonROI > &rois)
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_0[512]
Definition: Constants.h:832
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_0[512]
Definition: Constants.h:672
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_0[512]
Definition: Constants.h:913
const int BITSPHI
Definition: Constants.h:25
const int BITSGTPT
Definition: Constants.h:60
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_2[512]
Definition: Constants.h:864
const int BITSTTCURV
Definition: Constants.h:10
bool outputGT(std::vector< l1t::TrackerMuon > &muons)
ap_uint< BITSMATCHQUALITY - 2 > quality
ap_uint< BITSSIGMAETA > sigma_eta1
match_t getBest(const std::vector< match_t > matches)
const int BITSGTD0
Definition: Constants.h:64
ap_uint< BITSSTUBID > id
const int BITSGTQUALITY
Definition: Constants.h:65
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_3[512]
Definition: Constants.h:720
double b
Definition: hdecay.h:118
TrackMuonMatchAlgorithm(const edm::ParameterSet &iConfig)
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_4[512]
Definition: Constants.h:896
ap_uint< BITSSIGMACOORD+1 > deltaCoord(const ap_int< BITSSTUBCOORD > &phi1, const ap_int< BITSSTUBCOORD > &phi2)
const unsigned int PHIDIVIDER
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_4[512]
Definition: Constants.h:656
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_2[512]
Definition: Constants.h:1053
double a
Definition: hdecay.h:119
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_3[512]
Definition: Constants.h:1074
const ap_uint< 8 > lt_tpsID[256]
Definition: Constants.h:1210
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_4[512]
Definition: Constants.h:990
const ap_uint< BITSPROPCOORD > lt_prop_coord2_2[512]
Definition: Constants.h:512
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_0[512]
Definition: Constants.h:1112
const int BITSMUONBETA
Definition: Constants.h:42
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_1[512]
Definition: Constants.h:848
propagation_t propagate(const ConvertedTTTrack &track, uint layer)
const int BITSPROPCOORD
Definition: Constants.h:47
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_3[512]
Definition: Constants.h:800
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_3[512]
Definition: Constants.h:1160
match_t match(const propagation_t prop, const l1t::MuonStubRef &stub)
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_0[512]
Definition: Constants.h:587
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_2[512]
Definition: Constants.h:619
ap_int< BITSSTUBCOORD > coord2
const ap_uint< BITSPROPCOORD > lt_prop_coord1_3[512]
Definition: Constants.h:413
std::vector< PreTrackMatchedMuon > clean(std::vector< PreTrackMatchedMuon > &muons)
match_t propagateAndMatch(const ConvertedTTTrack &track, const l1t::MuonStubRef &stub)
PreTrackMatchedMuon processTrack(const ConvertedTTTrack &track, const std::vector< MuonROI > &rois)
const unsigned int ETADIVIDER
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_1[512]
Definition: Constants.h:1032