CMS 3D CMS Logo

TPSAlgorithm.cc
Go to the documentation of this file.
2 
3 using namespace Phase2L1GMT;
4 
5 TPSAlgorithm::TPSAlgorithm(const edm::ParameterSet& iConfig) : verbose_(iConfig.getParameter<int>("verbose")) {}
6 
7 std::vector<PreTrackMatchedMuon> TPSAlgorithm::processNonant(const std::vector<ConvertedTTTrack>& convertedTracks,
8  const l1t::MuonStubRefVector& stubs) const {
9  std::vector<PreTrackMatchedMuon> preMuons;
10  for (const auto& track : convertedTracks) {
12  if (mu.valid() && preMuons.size() < 16)
13  preMuons.push_back(mu);
14  }
15  std::vector<PreTrackMatchedMuon> cleanedMuons = clean(preMuons);
16  return cleanedMuons;
17 }
18 
19 std::vector<PreTrackMatchedMuon> TPSAlgorithm::cleanNeighbor(const std::vector<PreTrackMatchedMuon>& muons,
20  const std::vector<PreTrackMatchedMuon>& muonsPrevious,
21  const std::vector<PreTrackMatchedMuon>& muonsNext,
22  bool equality) const {
23  std::vector<PreTrackMatchedMuon> out;
24 
25  if (muons.empty())
26  return out;
27 
28  if (verbose_ == 1) {
29  edm::LogInfo("TPSAlgo") << "-----Cleaning Up Muons in the neighbours";
30  edm::LogInfo("TPSAlgo") << "Before:";
31  }
32 
33  for (uint i = 0; i < muons.size(); ++i) {
34  if (verbose_ == 1) {
35  muons[i].print();
36  }
37  ap_uint<5> mask = 0x1f;
38  for (uint j = 0; j < muonsPrevious.size(); ++j) {
39  mask = mask & cleanMuon(muons[i], muonsPrevious[j], equality);
40  }
41  for (uint j = 0; j < muonsNext.size(); ++j) {
42  mask = mask & cleanMuon(muons[i], muonsNext[j], equality);
43  }
44  if (mask) {
45  if (verbose_ == 1)
46  edm::LogInfo("TPSAlgo") << "kept";
47  out.push_back(muons[i]);
48  } else {
49  if (verbose_ == 1)
50  edm::LogInfo("TPSAlgo") << "discarded";
51  }
52  }
53  return out;
54 }
55 
56 std::vector<l1t::TrackerMuon> TPSAlgorithm::convert(const std::vector<PreTrackMatchedMuon>& muons, uint maximum) const {
57  std::vector<l1t::TrackerMuon> out;
58  for (const auto& mu : muons) {
59  if (out.size() == maximum)
60  break;
61  l1t::TrackerMuon muon(mu.trkPtr(), mu.charge(), mu.pt(), mu.eta(), mu.phi(), mu.z0(), mu.d0(), mu.quality());
62  muon.setMuonRef(mu.muonRef());
63  for (const auto& stub : mu.stubs())
64  muon.addStub(stub);
65 
66  uint matches = 0;
67  uint mask = mu.matchMask();
68 
69  for (uint i = 0; i < 10; i = i + 1) {
70  if (mask & (1 << i))
71  matches++;
72  }
73  muon.setNumberOfMatches(matches);
74  out.push_back(muon);
75 
76  if (verbose_ == 1) {
77  edm::LogInfo("TPSAlgo") << "Final Muon:" << std::flush;
78  muon.print();
79  }
80  }
81  return out;
82 }
83 
84 void TPSAlgorithm::SetQualityBits(std::vector<l1t::TrackerMuon>& muons) const {
85  for (auto& mu : muons) {
86  // A preliminary suggestion. Need feedback from the menu group
87  bool veryloose = mu.numberOfMatches() > 0;
88  bool loose = mu.numberOfMatches() > 1;
89  bool medium = mu.stubs().size() > 1;
90  bool tight = mu.numberOfMatches() > 2;
91  int qualbit = 0;
92  qualbit = (veryloose << 0) | (loose << 1) | (medium << 2) | (tight << 3);
93  mu.setHwQual(qualbit);
94  }
95 }
96 
97 bool TPSAlgorithm::outputGT(std::vector<l1t::TrackerMuon>& muons) const {
98  for (auto& mu : muons) {
99  wordtype word1 = 0;
100  wordtype word2 = 0;
101 
102  int bstart = 0;
103  bstart = wordconcat<wordtype>(word1, bstart, mu.hwPt() > 0, 1);
104  bstart = wordconcat<wordtype>(word1, bstart, mu.hwPt(), BITSGTPT);
105  bstart = wordconcat<wordtype>(word1, bstart, mu.hwPhi(), BITSGTPHI);
106  bstart = wordconcat<wordtype>(word1, bstart, mu.hwEta(), BITSGTETA);
107  bstart = wordconcat<wordtype>(word1, bstart, mu.hwZ0(), BITSGTZ0);
108  wordconcat<wordtype>(word1, bstart, (mu.hwD0() >> 2), BITSGTD0);
109 
110  bstart = 0;
111  bstart = wordconcat<wordtype>(word2, bstart, mu.hwCharge(), 1);
112  bstart = wordconcat<wordtype>(word2, bstart, mu.hwQual(), BITSGTQUAL);
113  bstart = wordconcat<wordtype>(word2, bstart, mu.hwIso(), BITSGTISO);
114  wordconcat<wordtype>(word2, bstart, mu.hwBeta(), BITSGTBETA);
115 
116  std::array<uint64_t, 2> wordout = {{word1, word2}};
117  mu.setWord(wordout);
118  }
119  return true;
120 }
121 
122 std::vector<l1t::TrackerMuon> TPSAlgorithm::sort(std::vector<l1t::TrackerMuon>& muons, uint maximum) const {
123  if (muons.size() < 2)
124  return muons;
125 
126  std::sort(muons.begin(), muons.end(), [](l1t::TrackerMuon a, l1t::TrackerMuon b) { return a.hwPt() > b.hwPt(); });
127  std::vector<l1t::TrackerMuon> out{muons.begin(), muons.begin() + (maximum < muons.size() ? maximum : muons.size())};
128 
129  return out;
130 }
131 
133  static const std::array<const ap_uint<BITSPROPCOORD>*, 5> lt_prop1_coord1 = {
135  static const std::array<const ap_uint<BITSPROPCOORD>*, 5> lt_prop1_coord2 = {
137  static const std::array<const ap_uint<BITSPROPCOORD>*, 5> lt_prop2_coord1 = {
139  static const std::array<const ap_uint<BITSPROPCOORD>*, 5> lt_prop2_coord2 = {
141 
142  static const std::array<const ap_uint<BITSPROPSIGMACOORD_A>*, 5> lt_res0_coord1 = {
144  static const std::array<const ap_uint<BITSPROPSIGMACOORD_B>*, 5> lt_res1_coord1 = {
146  static const std::array<const ap_uint<BITSPROPSIGMACOORD_A>*, 5> lt_res0_coord2 = {
148  static const std::array<const ap_uint<BITSPROPSIGMACOORD_B>*, 5> lt_res1_coord2 = {
150 
151  static const std::array<const ap_uint<BITSPROPSIGMAETA_A>*, 5> lt_res0_eta1 = {
153  static const std::array<const ap_uint<BITSPROPSIGMAETA_A>*, 5> lt_res1_eta1 = {
155 
156  static const std::array<const ap_uint<BITSPROPSIGMAETA_A>*, 5> lt_res0_eta2 = {
158 
159  static const uint barrellimit[5] = {barrelLimit0_, barrelLimit1_, barrelLimit2_, barrelLimit3_, barrelLimit4_};
160 
161  ap_uint<BITSPROPCOORD> prop1_coord1 = 0;
162  ap_uint<BITSPROPCOORD> prop1_coord2 = 0;
163  ap_uint<BITSPROPCOORD> prop2_coord1 = 0;
164  ap_uint<BITSPROPCOORD> prop2_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  //Propagate to layers
177  assert(layer < 5);
178  prop1_coord1 = lt_prop1_coord1[layer][reducedAbsEta];
179  prop1_coord2 = lt_prop1_coord2[layer][reducedAbsEta];
180  prop2_coord1 = lt_prop2_coord1[layer][reducedAbsEta];
181  prop2_coord2 = lt_prop2_coord2[layer][reducedAbsEta];
182  res0_coord1 = lt_res0_coord1[layer][reducedAbsEta];
183  res1_coord1 = lt_res1_coord1[layer][reducedAbsEta];
184  res0_coord2 = lt_res0_coord2[layer][reducedAbsEta];
185  res1_coord2 = lt_res1_coord2[layer][reducedAbsEta];
186  res0_eta1 = lt_res0_eta1[layer][reducedAbsEta];
187  res1_eta = lt_res1_eta1[layer][reducedAbsEta];
188  res0_eta2 = lt_res0_eta2[layer][reducedAbsEta];
189  is_barrel = reducedAbsEta < barrellimit[layer] ? 1 : 0;
190 
191  //try inflating res0's
192  //res0_coord1 = 2 * res0_coord1;
193  //res0_coord2 = 2 * res0_coord2;
194 
196  ap_int<BITSTTCURV> curvature = track.curvature();
197  ap_int<BITSPHI> phi = track.phi();
198 
199  //should be enough bits to hold all of c1k + d1kabsK, so if each are the same number of bits (they should be), that is 1 more bit (12 bits in this case)
200  ap_uint<BITSPROPCOORD + BITSTTCURV - 12> absDphiOverflow;
201  ap_int<BITSPROP + 1> dphi;
202 
203  ap_uint<BITSTTCURV - 1> absK = 0;
204  ap_uint<1> negativeCurv;
205  if (track.curvature() < 0) {
206  absK = ap_uint<BITSTTCURV - 1>(-track.curvature());
207  negativeCurv = 1;
208  } else {
209  absK = ap_uint<BITSTTCURV - 1>(track.curvature());
210  negativeCurv = 0;
211  }
212 
213  ap_uint<BITSPROPCOORD + BITSTTCURV - 1> c1kFull = prop1_coord1 * absK;
214  ap_uint<BITSPROPCOORD + BITSTTCURV - 13> c1k = (c1kFull) >> 12; // 1024;
215  //ap_int<BITSPHI> coord1 = phi - c1k;
216 
217  ap_uint<BITSPROPCOORD + 2 * BITSTTCURV - 2> d1kabsKFull = prop2_coord1 * absK * absK;
218  ap_uint<BITSPROPCOORD + 2 * BITSTTCURV - 28> d1kabsK = (d1kabsKFull) >> 26; // 16777216;
219 
220  absDphiOverflow = c1k + d1kabsK;
221  if (absDphiOverflow > PROPMAX)
222  dphi = PROPMAX;
223  else
224  dphi = absDphiOverflow;
225 
226  if (negativeCurv == 1)
227  dphi = -dphi;
228 
229  //ap_int<BITSPHI> coord1 = phi - dphi;
230  out.coord1 = (phi - dphi) / PHIDIVIDER;
231 
232  ap_uint<BITSPROPCOORD + BITSTTCURV - 1> c2kFull = prop1_coord2 * absK;
233  ap_uint<BITSPROPCOORD + BITSTTCURV - 13> c2k = (c2kFull) >> 12; // 1024;
234 
235  ap_uint<BITSPROPCOORD + 2 * BITSTTCURV - 2> d2kabsKFull = prop2_coord2 * absK * absK;
236  ap_uint<BITSPROPCOORD + 2 * BITSTTCURV - 28> d2kabsK = (d2kabsKFull) >> 26; // 16777216;
237 
238  absDphiOverflow = c2k + d2kabsK;
239  if (absDphiOverflow > PROPMAX)
240  dphi = PROPMAX;
241  else
242  dphi = absDphiOverflow;
243 
244  if (negativeCurv == 1)
245  dphi = -dphi;
246 
247  if (is_barrel)
248  out.coord2 = -dphi / PHIDIVIDER;
249  else
250  out.coord2 = (phi - dphi) / PHIDIVIDER;
251 
252  ap_int<BITSETA> eta = track.eta();
253  out.eta = eta / ETADIVIDER;
254 
255  ap_uint<2 * BITSTTCURV - 2> curvature2All = curvature * curvature;
256  ap_uint<BITSTTCURV2> curvature2 = curvature2All / 2;
257  /*
259  ap_uint<BITSTTCURV - 1> absK = 0;
260  if (track.curvature() < 0)
261  absK = ap_uint<BITSTTCURV - 1>(-track.curvature());
262  else
263  absK = ap_uint<BITSTTCURV - 1>(track.curvature());
264  */
265  //bound the resolution propagation
266  //if (absK > 6000)
267  // absK = 6000;
268 
269  ap_uint<BITSPROPSIGMAETA_B + BITSTTCURV2> resetak = (res1_eta * curvature2) >> 23;
270  ap_ufixed<BITSSIGMAETA, BITSSIGMAETA, AP_TRN_ZERO, AP_SAT_SYM> sigma_eta1 = res0_eta1 + resetak;
271  out.sigma_eta1 = ap_uint<BITSSIGMAETA>(sigma_eta1);
272  ap_ufixed<BITSSIGMAETA, BITSSIGMAETA, AP_TRN_ZERO, AP_SAT_SYM> sigma_eta2 = res0_eta2 + resetak;
273  out.sigma_eta2 = ap_uint<BITSSIGMAETA>(sigma_eta2);
274 
275  ap_uint<BITSPROPSIGMACOORD_B + BITSTTCURV - 1> s1kFull = res1_coord1 * absK;
276  ap_uint<BITSPROPSIGMACOORD_B + BITSTTCURV - 1 - 10> s1k = res0_coord1 + (s1kFull >> 10);
277  if (s1k >= (1 << (BITSSIGMACOORD + BITSPHI - BITSSTUBCOORD)))
278  out.sigma_coord1 = ~ap_uint<BITSSIGMACOORD>(0);
279  else if (s1k < PHIDIVIDER)
280  out.sigma_coord1 = 1;
281  else
282  out.sigma_coord1 = s1k / PHIDIVIDER;
283 
284  ap_uint<BITSPROPSIGMACOORD_B + BITSTTCURV - 1> s2kFull = res1_coord2 * absK;
285  ap_uint<BITSPROPSIGMACOORD_B + BITSTTCURV - 1 - 10> s2k = res0_coord2 + (s2kFull >> 10);
286  if (s2k >= (1 << (BITSSIGMACOORD + BITSPHI - BITSSTUBCOORD)))
287  out.sigma_coord2 = ~ap_uint<BITSSIGMACOORD>(0);
288  else if (s2k < PHIDIVIDER)
289  out.sigma_coord2 = 1;
290  else
291  out.sigma_coord2 = s2k / PHIDIVIDER;
292 
293  out.valid = 1;
294  out.is_barrel = is_barrel;
295 
296  if (verbose_ == 1) {
297  edm::LogInfo("TPSAlgo") << "Propagating to layer " << int(layer) << ":is barrel=" << out.is_barrel.to_int()
298  << " coords=" << out.coord1.to_int() << "+-" << out.sigma_coord1.to_int() << " , "
299  << out.coord2.to_int() << " +-" << out.sigma_coord2.to_int()
300  << " etas = " << out.eta.to_int() << " +- " << out.sigma_eta1.to_int() << " +-"
301  << out.sigma_eta2.to_int();
302 
303  edm::LogInfo("TPSAlgo") << "----- breakout of sigma 1 : constant=" << res0_coord1.to_int()
304  << " slope=" << res1_coord1.to_int() << " before division=" << s1k.to_int();
305 
306  edm::LogInfo("TPSAlgo") << "----- breakout of sigma 2 : constant=" << res0_coord2.to_int()
307  << " slope=" << res1_coord2.to_int() << " before division=" << s2k.to_int();
308  }
309  return out;
310 }
311 
312 ap_uint<BITSSIGMAETA + 1> TPSAlgorithm::deltaEta(const ap_int<BITSSTUBETA>& eta1,
313  const ap_int<BITSSTUBETA>& eta2) const {
314  ap_fixed<BITSSIGMAETA + 2, BITSSIGMAETA + 2, AP_TRN_ZERO, AP_SAT_SYM> dEta = eta1 - eta2;
315  if (dEta < 0)
316  return ap_uint<BITSSIGMAETA + 1>(-dEta);
317  else
318  return ap_uint<BITSSIGMAETA + 1>(dEta);
319 }
320 
321 ap_uint<BITSSIGMACOORD + 1> TPSAlgorithm::deltaCoord(const ap_int<BITSSTUBCOORD>& phi1,
322  const ap_int<BITSSTUBCOORD>& phi2) const {
323  ap_int<BITSSTUBCOORD> dPhiRoll = phi1 - phi2;
324  ap_ufixed<BITSSIGMACOORD + 1, BITSSIGMACOORD + 1, AP_TRN_ZERO, AP_SAT_SYM> dPhi;
325  if (dPhiRoll < 0)
326  dPhi = ap_ufixed<BITSSIGMACOORD + 1, BITSSIGMACOORD + 1, AP_TRN_ZERO, AP_SAT_SYM>(-dPhiRoll);
327  else
328  dPhi = ap_ufixed<BITSSIGMACOORD + 1, BITSSIGMACOORD + 1, AP_TRN_ZERO, AP_SAT_SYM>(dPhiRoll);
329 
330  return ap_uint<BITSSIGMACOORD + 1>(dPhi);
331 }
332 
333 match_t TPSAlgorithm::match(const propagation_t prop, const l1t::MuonStubRef& stub, uint trackID) const {
334  if (verbose_ == 1) {
335  edm::LogInfo("TPSAlgo") << "Matching to coord1=" << stub->coord1() << " coord2=" << stub->coord2()
336  << " eta1=" << stub->eta1() << " eta2=" << stub->eta2();
337 
338  stub->print();
339  }
340  //Matching of Coord1
341  ap_uint<1> coord1Matched;
342  ap_uint<BITSSIGMACOORD + 1> deltaCoord1 = deltaCoord(prop.coord1, stub->coord1());
343  if (deltaCoord1 <= prop.sigma_coord1 && (stub->quality() & 0x1)) {
344  coord1Matched = 1;
345  } else {
346  coord1Matched = 0;
347  }
348  if (verbose_ == 1)
349  edm::LogInfo("TPSAlgo") << "Coord1 matched=" << coord1Matched.to_int() << " delta=" << deltaCoord1.to_int()
350  << " res=" << prop.sigma_coord1.to_int();
351 
352  //Matching of Coord2
353  ap_uint<1> coord2Matched;
354  ap_uint<BITSSIGMACOORD + 1> deltaCoord2 = deltaCoord(prop.coord2, stub->coord2());
355  if (deltaCoord2 <= prop.sigma_coord2 && (stub->quality() & 0x2)) {
356  coord2Matched = 1;
357  } else {
358  coord2Matched = 0;
359  }
360  if (verbose_ == 1)
361  edm::LogInfo("TPSAlgo") << "Coord2 matched=" << coord2Matched.to_int() << " delta=" << deltaCoord2.to_int()
362  << " res=" << prop.sigma_coord2.to_int();
363 
364  //Matching of Eta1
365 
366  ap_uint<1> eta1Matched;
367 
368  //if we have really bad quality[Barrel no eta]
369  //increase the resolution
370  ap_ufixed<BITSSIGMAETA, BITSSIGMAETA, AP_TRN_ZERO, AP_SAT_SYM> prop_sigma_eta1;
371  if (stub->etaQuality() == 0)
372  prop_sigma_eta1 = prop.sigma_eta1 + 6;
373  else
374  prop_sigma_eta1 = prop.sigma_eta1;
375 
376  ap_uint<BITSSIGMAETA + 1> deltaEta1 = deltaEta(prop.eta, stub->eta1());
377  if (deltaEta1 <= prop_sigma_eta1 && (stub->etaQuality() == 0 || (stub->etaQuality() & 0x1)))
378  eta1Matched = 1;
379  else
380  eta1Matched = 0;
381 
382  if (verbose_ == 1)
383  edm::LogInfo("TPSAlgo") << "eta1 matched=" << eta1Matched.to_int() << " delta=" << deltaEta1.to_int()
384  << " res=" << prop_sigma_eta1.to_int();
385 
386  //Matching of Eta2
387 
388  ap_uint<1> eta2Matched;
389 
390  ap_uint<BITSSIGMAETA + 1> deltaEta2 = deltaEta(prop.eta, stub->eta2());
391  if (deltaEta2 <= prop.sigma_eta2 && (stub->etaQuality() & 0x2))
392  eta2Matched = 1;
393  else
394  eta2Matched = 0;
395  match_t out;
396  out.id = trackID;
397 
398  if (verbose_ == 1)
399  edm::LogInfo("TPSAlgo") << "eta2 matched=" << eta2Matched.to_int() << " delta=" << deltaEta2.to_int()
400  << " res=" << prop.sigma_eta2.to_int();
401 
402  //Note I divided by 4 because of the new coordinate. Make it automatic
403 
404  //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
405  if (prop.is_barrel) {
406  out.valid = (coord1Matched == 1 && (eta1Matched == 1 || eta2Matched == 1)) ? 1 : 0;
407  if (out.valid == 0) {
408  out.quality = 0;
409  } else {
410  out.quality = 32 - deltaCoord1 / 4;
411  if (coord2Matched == 1) {
412  out.quality += 32 - deltaCoord2 / 4;
413  out.valid = 3;
414  }
415  }
416  }
417  //if endcap each coordinate is independent except the case where phiQuality=1 and etaQuality==3
418  else {
419  bool match1 = (coord1Matched == 1 && eta1Matched == 1);
420  bool match2 = (coord2Matched == 1 && eta2Matched == 1);
421  bool match3 =
422  (coord1Matched == 1 && (eta1Matched || eta2Matched) && stub->etaQuality() == 3 && stub->quality() == 1);
423  out.valid = (match1 || match2 || match3) ? 1 : 0;
424  if (out.valid == 0)
425  out.quality = 0;
426  else {
427  out.quality = 0;
428  if (match1 || match3)
429  out.quality += 32 - deltaCoord1 / 4;
430  if (match2) {
431  out.quality += 32 - deltaCoord2 / 4;
432  if (match1 || match3)
433  out.valid = 3;
434  }
435  }
436  }
437  if (verbose_ == 1)
438  edm::LogInfo("TPSAlgo") << "GlobalMatchQuality = " << out.quality.to_int();
439  out.stubRef = stub;
440  return out;
441 }
442 
444  const l1t::MuonStubRef& stub,
445  uint trackID) const {
446  propagation_t prop = propagate(track, stub->tfLayer());
447  return match(prop, stub, trackID);
448 }
449 
450 match_t TPSAlgorithm::getBest(const std::vector<match_t>& matches) const {
451  match_t best = matches[0];
452  for (const auto& m : matches) {
453  if (m.quality > best.quality)
454  best = m;
455  }
456 
457  return best;
458 }
459 
460 void TPSAlgorithm::matchingInfos(const std::vector<match_t>& matchInfo,
462  ap_uint<BITSMATCHQUALITY>& quality) const {
463  if (!matchInfo.empty()) {
464  match_t b = getBest(matchInfo);
465  if (b.valid != 0) {
466  muon.addStub(b.stubRef, b.valid);
467  if (b.isGlobal)
468  muon.addMuonRef(b.muRef);
469  quality += b.quality;
470  }
471  }
472 }
473 
475  const l1t::MuonStubRefVector& stubs) const {
476  std::array<std::vector<match_t>, 6> matchInfos;
477 
478  if (verbose_ == 1 && !stubs.empty()) {
479  edm::LogInfo("TPSAlgo") << "-----------processing new track----------";
480  track.print();
481  }
482  for (const auto& stub : stubs) {
483  match_t m = propagateAndMatch(track, stub, 0);
484  if (m.valid != 0 && stub->tfLayer() < 6) {
485  matchInfos[stub->tfLayer()].push_back(m);
486  }
487  }
488 
489  ap_ufixed<6, 6, AP_TRN_ZERO, AP_SAT_SYM> ptPenalty = ap_ufixed<6, 6, AP_TRN_ZERO, AP_SAT_SYM>(track.pt() / 32);
490 
491  ap_uint<BITSMATCHQUALITY> quality = 0;
492  PreTrackMatchedMuon muon(track.charge(), track.pt(), track.eta(), track.phi(), track.z0(), track.d0());
493 
494  for (auto&& m : matchInfos)
496 
497  muon.setOfflineQuantities(track.offline_pt(), track.offline_eta(), track.offline_phi());
498  muon.setTrkPtr(track.trkPtr());
499 
500  ap_uint<8> etaAddr = muon.eta() < 0 ? ap_uint<8>(-muon.eta() / 256) : ap_uint<8>((muon.eta()) / 256);
501  ap_uint<8> ptAddr = muon.pt() > 4095 ? ap_uint<8>(15) : ap_uint<8>(muon.pt() / 256);
502  ap_uint<8> addr = ptAddr | (etaAddr << 4);
503  ap_uint<8> qualityCut = lt_tpsID[addr];
504 
505  if (!muon.stubs().empty()) { //change the ID for now
506  muon.setValid(true);
507  muon.setQuality(quality + ptPenalty);
508  } else {
509  muon.setValid(false);
510  muon.setQuality(0);
511  muon.resetGlobal();
512  }
513  if (verbose_ == 1)
514  muon.print();
515 
516  if (verbose_ == 1 && !stubs.empty()) { //patterns for HLS
517 
518  edm::LogInfo("TPSAlgo") << "TPS " << track.trkPtr()->phiSector() << std::flush;
519  track.printWord();
520 
521  for (uint i = 0; i < 16; ++i) {
522  if (stubs.size() > i) {
523  edm::LogInfo("TPSAlgo") << "remember to implement printout of muon";
524  } else {
525  edm::LogInfo("TPSAlgo") << std::hex << std::setw(8) << 0 << std::flush;
526  edm::LogInfo("TPSAlgo") << std::hex << std::setw(16) << 0x1ff000000000000 << std::flush;
527  edm::LogInfo("TPSAlgo") << std::hex << std::setw(16) << 0x1ff000000000000 << std::flush;
528  edm::LogInfo("TPSAlgo") << std::hex << std::setw(16) << 0x1ff000000000000 << std::flush;
529  edm::LogInfo("TPSAlgo") << std::hex << std::setw(16) << 0x1ff000000000000 << std::flush;
530  edm::LogInfo("TPSAlgo") << std::hex << std::setw(16) << 0x1ff000000000000 << std::flush;
531  }
532  }
533  muon.printWord();
534  edm::LogInfo("TPSAlgo") << std::endl;
535  }
536 
537  return muon;
538 }
539 
540 ap_uint<5> TPSAlgorithm::cleanMuon(const PreTrackMatchedMuon& mu, const PreTrackMatchedMuon& other, bool eq) const {
541  ap_uint<5> valid = 0;
542  ap_uint<5> overlap = 0;
543  constexpr int bittest = 0xfff; // 4095, corresponding to 11bits
544  if (mu.stubID0() != bittest) {
545  valid = valid | 0x1;
546  if (mu.stubID0() == other.stubID0())
547  overlap = overlap | 0x1;
548  }
549  if (mu.stubID1() != bittest) {
550  valid = valid | 0x2;
551  if (mu.stubID1() == other.stubID1())
552  overlap = overlap | 0x2;
553  }
554  if (mu.stubID2() != bittest) {
555  valid = valid | 0x4;
556  if (mu.stubID2() == other.stubID2())
557  overlap = overlap | 0x4;
558  }
559  if (mu.stubID3() != bittest) {
560  valid = valid | 0x8;
561  if (mu.stubID3() == other.stubID3())
562  overlap = overlap | 0x8;
563  }
564  if (mu.stubID4() != bittest) {
565  valid = valid | 0x10;
566  if (mu.stubID4() == other.stubID4())
567  overlap = overlap | 0x10;
568  }
569 
570  if (((mu.quality() < other.quality()) && (!eq)) || ((mu.quality() <= other.quality()) && (eq)))
571  return valid & (~overlap);
572  else
573  return valid;
574 }
575 
576 std::vector<PreTrackMatchedMuon> TPSAlgorithm::clean(const std::vector<PreTrackMatchedMuon>& muons) const {
577  std::vector<PreTrackMatchedMuon> out;
578  if (muons.empty())
579  return out;
580  if (verbose_ == 1) {
581  edm::LogInfo("TPSAlgo") << "-----Cleaning Up Muons in the same Nonant";
582  edm::LogInfo("TPSAlgo") << "Before:";
583  }
584  for (uint i = 0; i < muons.size(); ++i) {
585  if (verbose_ == 1)
586  muons[i].print();
587 
588  ap_uint<5> mask = 0x1f;
589  for (uint j = 0; j < muons.size(); ++j) {
590  if (i == j)
591  continue;
592  mask = mask & cleanMuon(muons[i], muons[j], false);
593  }
594  if (mask) {
595  if (verbose_ == 1)
596  edm::LogInfo("TPSAlgo") << "kept";
597  out.push_back(muons[i]);
598  } else {
599  if (verbose_ == 1)
600  edm::LogInfo("TPSAlgo") << "discarded";
601  }
602  }
603  return out;
604 }
const ap_uint< BITSPROPCOORD > lt_prop1_coord2_1[512]
Definition: TPSLUTs.h:510
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_3[512]
Definition: TPSLUTs.h:921
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_0[512]
Definition: TPSLUTs.h:1167
const int barrelLimit0_
Definition: Constants.h:85
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_4[512]
Definition: TPSLUTs.h:1251
const ap_uint< BITSPROPCOORD > lt_prop1_coord1_3[512]
Definition: TPSLUTs.h:435
ap_uint< BITSSIGMACOORD > sigma_coord1
Definition: TPSAlgorithm.h:27
const unsigned int PROPMAX
Definition: TPSAlgorithm.h:23
const int BITSGTZ0
Definition: Constants.h:63
const int barrelLimit1_
Definition: Constants.h:86
const int BITSSTUBCOORD
Definition: Constants.h:31
ap_uint< BITSSIGMAETA+1 > deltaEta(const ap_int< BITSSTUBETA > &eta1, const ap_int< BITSSTUBETA > &eta2) const
const int barrelLimit3_
Definition: Constants.h:88
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_2[512]
Definition: TPSLUTs.h:1464
const ap_uint< BITSPROPCOORD > lt_prop2_coord2_1[512]
Definition: TPSLUTs.h:760
const int BITSGTETA
Definition: Constants.h:62
ap_uint< BITSSIGMACOORD+1 > deltaCoord(const ap_int< BITSSTUBCOORD > &phi1, const ap_int< BITSSTUBCOORD > &phi2) const
const int BITSGTISO
Definition: Constants.h:67
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_0[512]
Definition: TPSLUTs.h:1272
const int BITSGTPHI
Definition: Constants.h:61
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_2[512]
Definition: TPSLUTs.h:1104
ap_int< BITSSTUBCOORD > coord1
Definition: TPSAlgorithm.h:26
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_1[512]
Definition: TPSLUTs.h:1448
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_4[512]
Definition: TPSLUTs.h:1041
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_3[512]
Definition: TPSLUTs.h:1125
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_4[512]
Definition: TPSLUTs.h:1336
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_1[512]
Definition: TPSLUTs.h:1288
const int BITSSIGMACOORD
Definition: Constants.h:46
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_1[512]
Definition: TPSLUTs.h:978
const ap_uint< BITSPROPCOORD > lt_prop1_coord2_3[512]
Definition: TPSLUTs.h:560
const ap_uint< BITSPROPCOORD > lt_prop2_coord2_0[512]
Definition: TPSLUTs.h:735
const int BITSPROPSIGMACOORD_B
Definition: Constants.h:49
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_3[512]
Definition: TPSLUTs.h:1400
const ap_uint< BITSPROPCOORD > lt_prop2_coord2_4[512]
Definition: TPSLUTs.h:831
const ap_uint< BITSPROPCOORD > lt_prop2_coord1_2[512]
Definition: TPSLUTs.h:660
const ap_uint< BITSPROPCOORD > lt_prop2_coord1_0[512]
Definition: TPSLUTs.h:610
const int BITSGTQUAL
Definition: Constants.h:65
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
assert(be >=bs)
ap_uint< BITSSIGMAETA > sigma_eta2
Definition: TPSAlgorithm.h:32
T curvature(T InversePt, const MagneticField &field)
ap_uint< BITSSIGMACOORD > sigma_coord2
Definition: TPSAlgorithm.h:29
std::vector< PreTrackMatchedMuon > cleanNeighbor(const std::vector< PreTrackMatchedMuon > &muons, const std::vector< PreTrackMatchedMuon > &muonsPrevious, const std::vector< PreTrackMatchedMuon > &muonsNext, bool equality) const
Definition: TPSAlgorithm.cc:19
std::vector< edm::Ref< MuonStubCollection > > MuonStubRefVector
Definition: MuonStub.h:44
ap_uint< 64 > wordtype
Definition: Constants.h:101
const int barrelLimit2_
Definition: Constants.h:87
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_2[512]
Definition: TPSLUTs.h:1304
void SetQualityBits(std::vector< l1t::TrackerMuon > &muons) const
Definition: TPSAlgorithm.cc:84
string quality
std::vector< PreTrackMatchedMuon > clean(const std::vector< PreTrackMatchedMuon > &muons) const
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_4[512]
Definition: TPSLUTs.h:1496
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_2[512]
Definition: TPSLUTs.h:999
const ap_uint< BITSPROPCOORD > lt_prop2_coord1_4[512]
Definition: TPSLUTs.h:710
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_1[512]
Definition: TPSLUTs.h:1083
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_1[512]
Definition: TPSLUTs.h:879
PreTrackMatchedMuon processTrack(const ConvertedTTTrack &, const l1t::MuonStubRefVector &) const
match_t match(const propagation_t prop, const l1t::MuonStubRef &stub, uint trackID) const
const int barrelLimit4_
Definition: Constants.h:89
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_0[512]
Definition: TPSLUTs.h:1352
void matchingInfos(const std::vector< match_t > &matchInfo, PreTrackMatchedMuon &muon, ap_uint< BITSMATCHQUALITY > &quality) const
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_0[512]
Definition: TPSLUTs.h:957
bool outputGT(std::vector< l1t::TrackerMuon > &muons) const
Definition: TPSAlgorithm.cc:97
const ap_uint< BITSPROPCOORD > lt_prop1_coord2_0[512]
Definition: TPSLUTs.h:485
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_0[512]
Definition: TPSLUTs.h:1062
const int BITSPHI
Definition: Constants.h:25
const int BITSGTPT
Definition: Constants.h:60
std::vector< PreTrackMatchedMuon > processNonant(const std::vector< ConvertedTTTrack > &convertedTracks, const l1t::MuonStubRefVector &stubs) const
Definition: TPSAlgorithm.cc:7
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_2[512]
Definition: TPSLUTs.h:1384
const int BITSTTCURV
Definition: Constants.h:10
ap_uint< 5 > cleanMuon(const PreTrackMatchedMuon &mu, const PreTrackMatchedMuon &other, bool eq) const
ap_uint< BITSSIGMAETA > sigma_eta1
Definition: TPSAlgorithm.h:31
match_t propagateAndMatch(const ConvertedTTTrack &track, const l1t::MuonStubRef &stub, uint trackID) const
const ap_uint< BITSPROPCOORD > lt_prop1_coord2_4[512]
Definition: TPSLUTs.h:585
Log< level::Info, false > LogInfo
std::vector< l1t::TrackerMuon > sort(std::vector< l1t::TrackerMuon > &muons, uint maximum) const
std::vector< l1t::TrackerMuon > convert(const std::vector< PreTrackMatchedMuon > &muons, uint maximum) const
Definition: TPSAlgorithm.cc:56
const int BITSGTD0
Definition: Constants.h:64
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_3[512]
Definition: TPSLUTs.h:1020
double b
Definition: hdecay.h:120
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_4[512]
Definition: TPSLUTs.h:1416
ap_int< BITSSTUBETA > eta
Definition: TPSAlgorithm.h:30
const unsigned int PHIDIVIDER
Definition: TPSAlgorithm.h:20
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_4[512]
Definition: TPSLUTs.h:941
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_2[512]
Definition: TPSLUTs.h:1209
const ap_uint< BITSPROPCOORD > lt_prop2_coord2_2[512]
Definition: TPSLUTs.h:785
match_t getBest(const std::vector< match_t > &matches) const
double a
Definition: hdecay.h:121
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_3[512]
Definition: TPSLUTs.h:1230
const ap_uint< 8 > lt_tpsID[256]
Definition: TPSLUTs.h:1518
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_4[512]
Definition: TPSLUTs.h:1146
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_0[512]
Definition: TPSLUTs.h:1432
const ap_uint< BITSPROPCOORD > lt_prop1_coord1_1[512]
Definition: TPSLUTs.h:385
const ap_uint< BITSPROPCOORD > lt_prop1_coord1_0[512]
Definition: TPSLUTs.h:360
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_1[512]
Definition: TPSLUTs.h:1368
const int BITSPROPCOORD
Definition: Constants.h:47
const ap_uint< BITSPROPCOORD > lt_prop1_coord2_2[512]
Definition: TPSLUTs.h:535
const ap_uint< BITSPROPCOORD > lt_prop2_coord2_3[512]
Definition: TPSLUTs.h:810
const ap_uint< BITSPROPCOORD > lt_prop1_coord1_2[512]
Definition: TPSLUTs.h:410
propagation_t propagate(const ConvertedTTTrack &track, uint layer) const
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_3[512]
Definition: TPSLUTs.h:1320
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_3[512]
Definition: TPSLUTs.h:1480
const ap_uint< BITSPROPCOORD > lt_prop2_coord1_1[512]
Definition: TPSLUTs.h:635
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_0[512]
Definition: TPSLUTs.h:858
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_2[512]
Definition: TPSLUTs.h:900
const ap_uint< BITSPROPCOORD > lt_prop2_coord1_3[512]
Definition: TPSLUTs.h:685
ap_int< BITSSTUBCOORD > coord2
Definition: TPSAlgorithm.h:28
const ap_uint< BITSPROPCOORD > lt_prop1_coord1_4[512]
Definition: TPSLUTs.h:460
const int BITSGTBETA
Definition: Constants.h:68
const unsigned int ETADIVIDER
Definition: TPSAlgorithm.h:21
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_1[512]
Definition: TPSLUTs.h:1188