CMS 3D CMS Logo

MkStdSeqs.cc
Go to the documentation of this file.
3 
8 
10 
11 namespace mkfit {
12 
13  namespace StdSeq {
14 
15  //=========================================================================
16  // Hit processing
17  //=========================================================================
18 
19  void loadDeads(EventOfHits &eoh, const std::vector<DeadVec> &deadvectors) {
20  for (size_t il = 0; il < deadvectors.size(); il++) {
21  eoh.suckInDeads(int(il), deadvectors[il]);
22  }
23  }
24 
25  // Loading hits in CMSSW from two "large multi-layer vectors".
26  // orig_hitvectors[0] - pixels,
27  // orig_hitvectors[1] - strips.
28 
29  void cmssw_LoadHits_Begin(EventOfHits &eoh, const std::vector<const HitVec *> &orig_hitvectors) {
30  eoh.reset();
31  for (int i = 0; i < eoh.nLayers(); ++i) {
32  auto &&l = eoh[i];
33  l.beginRegistrationOfHits(*orig_hitvectors[l.is_pixel() ? 0 : 1]);
34  }
35  }
36 
37  // Loop with LayerOfHits::registerHit(int idx) - it takes Hit out of original HitVec to
38  // extract phi, r/z, and calculate qphifines
39  //
40  // Something like what is done in MkFitInputConverter::convertHits
41  //
42  // Problem is I don't know layers for each large-vector;
43  // Also, layer is calculated for each detset when looping over the HitCollection
44 
46  for (int i = 0; i < eoh.nLayers(); ++i) {
47  auto &&l = eoh[i];
48  l.endRegistrationOfHits(false);
49  }
50  }
51 
52  //=========================================================================
53  // Hit-index mapping / remapping
54  //=========================================================================
55 
57  for (auto &&track : seeds) {
58  for (int i = 0; i < track.nTotalHits(); ++i) {
59  const int hitidx = track.getHitIdx(i);
60  const int hitlyr = track.getHitLyr(i);
61  if (hitidx >= 0) {
62  const auto &loh = eoh[hitlyr];
63  track.setHitIdx(i, loh.getHitIndexFromOriginal(hitidx));
64  }
65  }
66  }
67  }
68 
69  void cmssw_ReMap_TrackHitIndices(const EventOfHits &eoh, TrackVec &out_tracks) {
70  for (auto &&track : out_tracks) {
71  for (int i = 0; i < track.nTotalHits(); ++i) {
72  const int hitidx = track.getHitIdx(i);
73  const int hitlyr = track.getHitLyr(i);
74  if (hitidx >= 0) {
75  const auto &loh = eoh[hitlyr];
76  track.setHitIdx(i, loh.getOriginalHitIndex(hitidx));
77  }
78  }
79  }
80  }
81 
82  //=========================================================================
83  // Seed cleaning (multi-iter)
84  //=========================================================================
85  int clean_cms_seedtracks_iter(TrackVec &seeds, const IterationConfig &itrcfg, const BeamSpot &bspot) {
87 
88  const float etamax_brl = Config::c_etamax_brl;
89  const float dpt_common = Config::c_dpt_common;
90 
91  const float dzmax_bh = itrcfg.sc_dzmax_bh;
92  const float drmax_bh = itrcfg.sc_drmax_bh;
93  const float dzmax_eh = itrcfg.sc_dzmax_eh;
94  const float drmax_eh = itrcfg.sc_drmax_eh;
95  const float dzmax_bl = itrcfg.sc_dzmax_bl;
96  const float drmax_bl = itrcfg.sc_drmax_bl;
97  const float dzmax_el = itrcfg.sc_dzmax_el;
98  const float drmax_el = itrcfg.sc_drmax_el;
99 
100  const float ptmin_hpt = itrcfg.sc_ptthr_hpt;
101 
102  const float dzmax2_inv_bh = 1.f / (dzmax_bh * dzmax_bh);
103  const float drmax2_inv_bh = 1.f / (drmax_bh * drmax_bh);
104  const float dzmax2_inv_eh = 1.f / (dzmax_eh * dzmax_eh);
105  const float drmax2_inv_eh = 1.f / (drmax_eh * drmax_eh);
106  const float dzmax2_inv_bl = 1.f / (dzmax_bl * dzmax_bl);
107  const float drmax2_inv_bl = 1.f / (drmax_bl * drmax_bl);
108  const float dzmax2_inv_el = 1.f / (dzmax_el * dzmax_el);
109  const float drmax2_inv_el = 1.f / (drmax_el * drmax_el);
110 
111  // Merge hits from overlapping seeds?
112  // For now always true, we require extra hits after seed,
113  // except for lowPtQuadStep, where we only merge hits for seeds at low pT and large pseudo-rapidity
114  const bool merge_hits = true; // itrcfg.merge_seed_hits_during_cleaning();
115  const float ptmax_merge_lowPtQuad = 0.2;
116  const float etamin_merge_lowPtQuad = 1.5;
117 
118  if (seeds.empty())
119  return 0;
120 
121  const int ns = seeds.size();
122 #ifdef DEBUG
123  std::cout << "before seed cleaning " << seeds.size() << std::endl;
124 #endif
125  TrackVec cleanSeedTracks;
126  cleanSeedTracks.reserve(ns);
127  std::vector<bool> writetrack(ns, true);
128 
129  const float invR1GeV = 1.f / Config::track1GeVradius;
130 
131  std::vector<int> nHits(ns);
132  std::vector<int> charge(ns);
133  std::vector<float> oldPhi(ns);
134  std::vector<float> pos2(ns);
135  std::vector<float> eta(ns);
136  std::vector<float> ctheta(ns);
137  std::vector<float> invptq(ns);
138  std::vector<float> pt(ns);
139  std::vector<float> x(ns);
140  std::vector<float> y(ns);
141  std::vector<float> z(ns);
142  std::vector<float> d0(ns);
143  int i1, i2; //for the sorting
144 
146  axis<float, unsigned short, 8, 8> ax_eta(-3.0, 3.0, 30u);
148 
149  phi_eta_binnor.begin_registration(ns);
150 
151  for (int ts = 0; ts < ns; ts++) {
152  const Track &tk = seeds[ts];
153  nHits[ts] = tk.nFoundHits();
154  charge[ts] = tk.charge();
155  oldPhi[ts] = tk.momPhi();
156  pos2[ts] = std::pow(tk.x(), 2) + std::pow(tk.y(), 2);
157  eta[ts] = tk.momEta();
158  ctheta[ts] = 1.f / std::tan(tk.theta());
159  invptq[ts] = tk.charge() * tk.invpT();
160  pt[ts] = tk.pT();
161  x[ts] = tk.x();
162  y[ts] = tk.y();
163  z[ts] = tk.z();
164  d0[ts] = tk.d0BeamSpot(bspot.x, bspot.y);
165 
166  phi_eta_binnor.register_entry_safe(oldPhi[ts], eta[ts]);
167  // If one is sure values are *within* axis ranges: b.register_entry(oldPhi[ts], eta[ts]);
168  }
169 
170  phi_eta_binnor.finalize_registration();
171 
172  for (int sorted_ts = 0; sorted_ts < ns; sorted_ts++) {
173  int ts = phi_eta_binnor.m_ranks[sorted_ts];
174 
175  if (not writetrack[ts])
176  continue; // Note: this speed up prevents transitive masking (possibly marginal gain).
177 
178  const float oldPhi1 = oldPhi[ts];
179  const float pos2_first = pos2[ts];
180  const float eta1 = eta[ts];
181  const float pt1 = pt[ts];
182  const float invptq_first = invptq[ts];
183 
184  // To study some more details -- need EventOfHits for this
185  int n_ovlp_hits_added = 0;
186 
187  auto phi_rng = ax_phi.from_R_rdr_to_N_bins(oldPhi[ts], 0.08f);
188  auto eta_rng = ax_eta.from_R_rdr_to_N_bins(eta[ts], .1f);
189 
190  for (auto i_phi = phi_rng.begin; i_phi != phi_rng.end; i_phi = ax_phi.next_N_bin(i_phi)) {
191  for (auto i_eta = eta_rng.begin; i_eta != eta_rng.end; i_eta = ax_eta.next_N_bin(i_eta)) {
192  const auto cbin = phi_eta_binnor.get_content(i_phi, i_eta);
193  for (auto i = cbin.first; i < cbin.end(); ++i) {
194  int tss = phi_eta_binnor.m_ranks[i];
195 
196  if (not writetrack[ts])
197  continue;
198  if (not writetrack[tss])
199  continue;
200  if (tss == ts)
201  continue;
202 
203  const float pt2 = pt[tss];
204 
205  // Always require charge consistency. If different charge is assigned, do not remove seed-track
206  if (charge[tss] != charge[ts])
207  continue;
208 
209  const float thisDPt = std::abs(pt2 - pt1);
210  // Require pT consistency between seeds. If dpT is large, do not remove seed-track.
211  if (thisDPt > dpt_common * pt1)
212  continue;
213 
214  const float eta2 = eta[tss];
215  const float deta2 = std::pow(eta1 - eta2, 2);
216 
217  const float oldPhi2 = oldPhi[tss];
218 
219  const float pos2_second = pos2[tss];
220  const float thisDXYSign05 = pos2_second > pos2_first ? -0.5f : 0.5f;
221 
222  const float thisDXY = thisDXYSign05 * sqrt(std::pow(x[ts] - x[tss], 2) + std::pow(y[ts] - y[tss], 2));
223 
224  const float invptq_second = invptq[tss];
225 
226  const float newPhi1 = oldPhi1 - thisDXY * invR1GeV * invptq_first;
227  const float newPhi2 = oldPhi2 + thisDXY * invR1GeV * invptq_second;
228 
229  const float dphi = cdist(std::abs(newPhi1 - newPhi2));
230 
231  const float dr2 = deta2 + dphi * dphi;
232 
233  const float thisDZ = z[ts] - z[tss] - thisDXY * (ctheta[ts] + ctheta[tss]);
234  const float dz2 = thisDZ * thisDZ;
235 
236  // Reject tracks within dR-dz elliptical window.
237  // Adaptive thresholds, based on observation that duplicates are more abundant at large pseudo-rapidity and low track pT
238  bool overlapping = false;
239  if (std::abs(eta1) < etamax_brl) {
240  if (pt1 > ptmin_hpt) {
241  if (dz2 * dzmax2_inv_bh + dr2 * drmax2_inv_bh < 1.0f)
242  overlapping = true;
243  } else {
244  if (dz2 * dzmax2_inv_bl + dr2 * drmax2_inv_bl < 1.0f)
245  overlapping = true;
246  }
247  } else {
248  if (pt1 > ptmin_hpt) {
249  if (dz2 * dzmax2_inv_eh + dr2 * drmax2_inv_eh < 1.0f)
250  overlapping = true;
251  } else {
252  if (dz2 * dzmax2_inv_el + dr2 * drmax2_inv_el < 1.0f)
253  overlapping = true;
254  }
255  }
256 
257  if (overlapping) {
258  //Mark tss as a duplicate
259  i1 = ts;
260  i2 = tss;
261  if (d0[tss] > d0[ts])
262  writetrack[tss] = false;
263  else {
264  writetrack[ts] = false;
265  i2 = ts;
266  i1 = tss;
267  }
268  // Add hits from tk2 to the seed we are keeping.
269  // NOTE: We have a limit in Track::Status for the number of seed hits.
270  // There is a check at entry and after adding of a new hit.
271  Track &tk = seeds[i1];
272  if (merge_hits && tk.nTotalHits() < Track::Status::kMaxSeedHits &&
274  (pt1 < ptmax_merge_lowPtQuad && std::abs(eta1) > etamin_merge_lowPtQuad))) {
275  const Track &tk2 = seeds[i2];
276  //We are not actually fitting to the extra hits; use chi2 of 0
277  float fakeChi2 = 0.0;
278 
279  for (int j = 0; j < tk2.nTotalHits(); ++j) {
280  int hitidx = tk2.getHitIdx(j);
281  int hitlyr = tk2.getHitLyr(j);
282  if (hitidx >= 0) {
283  bool unique = true;
284  for (int i = 0; i < tk.nTotalHits(); ++i) {
285  if ((hitidx == tk.getHitIdx(i)) && (hitlyr == tk.getHitLyr(i))) {
286  unique = false;
287  break;
288  }
289  }
290  if (unique) {
291  tk.addHitIdx(tk2.getHitIdx(j), tk2.getHitLyr(j), fakeChi2);
292  ++n_ovlp_hits_added;
294  break;
295  }
296  }
297  }
298  }
299  if (n_ovlp_hits_added > 0)
300  tk.sortHitsByLayer();
301  }
302  } //end of inner loop over tss
303  } //eta bin
304  } //phi bin
305 
306  if (writetrack[ts]) {
307  cleanSeedTracks.emplace_back(seeds[ts]);
308  }
309  }
310 
311  seeds.swap(cleanSeedTracks);
312 
313 #ifdef DEBUG
314  {
315  const int ns2 = seeds.size();
316  printf("Number of CMS seeds before %d --> after %d cleaning\n", ns, ns2);
317 
318  for (int it = 0; it < ns2; it++) {
319  const Track &ss = seeds[it];
320  printf(" %3i q=%+i pT=%7.3f eta=% 7.3f nHits=%i label=% i\n",
321  it,
322  ss.charge(),
323  ss.pT(),
324  ss.momEta(),
325  ss.nFoundHits(),
326  ss.label());
327  }
328  }
329 #endif
330 
331 #ifdef DEBUG
332  std::cout << "AFTER seed cleaning " << seeds.size() << std::endl;
333 #endif
334 
335  return seeds.size();
336  }
337 
338  namespace {
339  CMS_SA_ALLOW struct register_seed_cleaners {
340  register_seed_cleaners() {
342  }
343  } rsc_instance;
344  } // namespace
345 
346  //=========================================================================
347  // Duplicate cleaning
348  //=========================================================================
349 
351  tracks.erase(std::remove_if(tracks.begin(), tracks.end(), [](auto track) { return track.getDuplicateValue(); }),
352  tracks.end());
353  }
354 
356  const auto ntracks = tracks.size();
357  float eta1, phi1, pt1, deta, dphi, dr2;
358 
359  if (ntracks == 0) {
360  return;
361  }
362  for (auto itrack = 0U; itrack < ntracks - 1; itrack++) {
363  auto &track = tracks[itrack];
364  eta1 = track.momEta();
365  phi1 = track.momPhi();
366  pt1 = track.pT();
367  for (auto jtrack = itrack + 1; jtrack < ntracks; jtrack++) {
368  auto &track2 = tracks[jtrack];
369  if (track.label() == track2.label())
370  continue;
371  if (track.algoint() != track2.algoint())
372  continue;
373 
374  deta = std::abs(track2.momEta() - eta1);
375  if (deta > Config::maxdEta)
376  continue;
377 
378  dphi = std::abs(squashPhiMinimal(phi1 - track2.momPhi()));
379  if (dphi > Config::maxdPhi)
380  continue;
381 
382  float maxdR = Config::maxdR;
383  float maxdRSquared = maxdR * maxdR;
384  if (std::abs(eta1) > 2.5f)
385  maxdRSquared *= 16.0f;
386  else if (std::abs(eta1) > 1.44f)
387  maxdRSquared *= 9.0f;
388  dr2 = dphi * dphi + deta * deta;
389  if (dr2 < maxdRSquared) {
390  //Keep track with best score
391  if (track.score() > track2.score())
392  track2.setDuplicateValue(true);
393  else
394  track.setDuplicateValue(true);
395  continue;
396  } else {
397  if (pt1 == 0)
398  continue;
399  if (track2.pT() == 0)
400  continue;
401 
402  if (std::abs((1 / track2.pT()) - (1 / pt1)) < Config::maxdPt) {
404  float numHitsShared = 0;
405  for (int ihit2 = 0; ihit2 < track2.nTotalHits(); ihit2++) {
406  const int hitidx2 = track2.getHitIdx(ihit2);
407  const int hitlyr2 = track2.getHitLyr(ihit2);
408  if (hitidx2 >= 0) {
409  auto const it = std::find_if(track.beginHitsOnTrack(),
410  track.endHitsOnTrack(),
411  [&hitidx2, &hitlyr2](const HitOnTrack &element) {
412  return (element.index == hitidx2 && element.layer == hitlyr2);
413  });
414  if (it != track.endHitsOnTrack())
415  numHitsShared++;
416  }
417  }
418 
419  float fracHitsShared = numHitsShared / std::min(track.nFoundHits(), track2.nFoundHits());
420  //Only remove one of the tracks if they share at least X% of the hits (denominator is the shorter track)
421  if (fracHitsShared < Config::minFracHitsShared)
422  continue;
423  }
424  //Keep track with best score
425  if (track.score() > track2.score())
426  track2.setDuplicateValue(true);
427  else
428  track.setDuplicateValue(true);
429  } //end of if dPt
430  } //end of else
431  } //end of loop over track2
432  } //end of loop over track1
433 
435  }
436 
437  //=========================================================================
438  // SHARED HITS DUPLICATE CLEANING
439  //=========================================================================
440 
442  const float fraction = itconf.dc_fracSharedHits;
443  const auto ntracks = tracks.size();
444 
445  std::vector<float> ctheta(ntracks);
446  std::multimap<int, int> hitMap;
447 
448  for (auto itrack = 0U; itrack < ntracks; itrack++) {
449  auto &trk = tracks[itrack];
450  ctheta[itrack] = 1.f / std::tan(trk.theta());
451  for (int i = 0; i < trk.nTotalHits(); ++i) {
452  if (trk.getHitIdx(i) < 0)
453  continue;
454  int a = trk.getHitLyr(i);
455  int b = trk.getHitIdx(i);
456  hitMap.insert(std::make_pair(b * 1000 + a, i > 0 ? itrack : -itrack)); //negative for first hit in trk
457  }
458  }
459 
460  for (auto itrack = 0U; itrack < ntracks; itrack++) {
461  auto &trk = tracks[itrack];
462  auto phi1 = trk.momPhi();
463  auto ctheta1 = ctheta[itrack];
464 
465  std::map<int, int> sharingMap;
466  for (int i = 0; i < trk.nTotalHits(); ++i) {
467  if (trk.getHitIdx(i) < 0)
468  continue;
469  int a = trk.getHitLyr(i);
470  int b = trk.getHitIdx(i);
471  auto range = hitMap.equal_range(b * 1000 + a);
472  for (auto it = range.first; it != range.second; ++it) {
473  if (std::abs(it->second) >= (int)itrack)
474  continue; // don't check your own hits (==) nor sym. checks (>)
475  if (i == 0 && it->second < 0)
476  continue; // shared first - first is not counted
477  sharingMap[std::abs(it->second)]++;
478  }
479  }
480 
481  for (const auto &elem : sharingMap) {
482  auto &track2 = tracks[elem.first];
483 
484  // broad dctheta-dphi compatibility checks; keep mostly to preserve consistency with old results
485  auto dctheta = std::abs(ctheta[elem.first] - ctheta1);
486  if (dctheta > 1.)
487  continue;
488 
489  auto dphi = std::abs(squashPhiMinimal(phi1 - track2.momPhi()));
490  if (dphi > 1.)
491  continue;
492 
493  if (elem.second >= std::min(trk.nFoundHits(), track2.nFoundHits()) * fraction) {
494  if (trk.score() > track2.score())
495  track2.setDuplicateValue(true);
496  else
497  trk.setDuplicateValue(true);
498  }
499  } // end sharing hits loop
500  } // end trk loop
501 
503  }
504 
506  const float fraction = itconf.dc_fracSharedHits;
507  const float drth_central = itconf.dc_drth_central;
508  const float drth_obarrel = itconf.dc_drth_obarrel;
509  const float drth_forward = itconf.dc_drth_forward;
510  const auto ntracks = tracks.size();
511 
512  std::vector<float> ctheta(ntracks);
513  for (auto itrack = 0U; itrack < ntracks; itrack++) {
514  auto &trk = tracks[itrack];
515  ctheta[itrack] = 1.f / std::tan(trk.theta());
516  }
517 
518  float phi1, invpt1, dctheta, ctheta1, dphi, dr2;
519  for (auto itrack = 0U; itrack < ntracks; itrack++) {
520  auto &trk = tracks[itrack];
521  phi1 = trk.momPhi();
522  invpt1 = trk.invpT();
523  ctheta1 = ctheta[itrack];
524  for (auto jtrack = itrack + 1; jtrack < ntracks; jtrack++) {
525  auto &track2 = tracks[jtrack];
526  if (trk.label() == track2.label())
527  continue;
528 
529  dctheta = std::abs(ctheta[jtrack] - ctheta1);
530 
531  if (dctheta > Config::maxdcth)
532  continue;
533 
534  dphi = std::abs(squashPhiMinimal(phi1 - track2.momPhi()));
535 
536  if (dphi > Config::maxdphi)
537  continue;
538 
539  float maxdRSquared = drth_central * drth_central;
540  if (std::abs(ctheta1) > Config::maxcth_fw)
541  maxdRSquared = drth_forward * drth_forward;
542  else if (std::abs(ctheta1) > Config::maxcth_ob)
543  maxdRSquared = drth_obarrel * drth_obarrel;
544  dr2 = dphi * dphi + dctheta * dctheta;
545  if (dr2 < maxdRSquared) {
546  //Keep track with best score
547  if (trk.score() > track2.score())
548  track2.setDuplicateValue(true);
549  else
550  trk.setDuplicateValue(true);
551  continue;
552  }
553 
554  if (std::abs(track2.invpT() - invpt1) > Config::maxd1pt)
555  continue;
556 
557  auto sharedCount = 0;
558  auto sharedFirst = 0;
559  const auto minFoundHits = std::min(trk.nFoundHits(), track2.nFoundHits());
560 
561  for (int i = 0; i < trk.nTotalHits(); ++i) {
562  if (trk.getHitIdx(i) < 0)
563  continue;
564  const int a = trk.getHitLyr(i);
565  const int b = trk.getHitIdx(i);
566  for (int j = 0; j < track2.nTotalHits(); ++j) {
567  if (track2.getHitIdx(j) < 0)
568  continue;
569  const int c = track2.getHitLyr(j);
570  const int d = track2.getHitIdx(j);
571 
572  //this is to count once shared matched hits (may be done more properly...)
573  if (a == c && b == d)
574  sharedCount += 1;
575  if (j == 0 && i == 0 && a == c && b == d)
576  sharedFirst += 1;
577 
578  if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) * fraction))
579  continue;
580  }
581  if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) * fraction))
582  continue;
583  }
584 
585  //selection here - 11percent fraction of shared hits to label a duplicate
586  if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) * fraction)) {
587  if (trk.score() > track2.score())
588  track2.setDuplicateValue(true);
589  else
590  trk.setDuplicateValue(true);
591  }
592  }
593  } //end loop one over tracks
594 
596  }
597 
598  namespace {
599  CMS_SA_ALLOW struct register_duplicate_cleaners {
600  register_duplicate_cleaners() {
602  IterationConfig::register_duplicate_cleaner("phase1:clean_duplicates_sharedhits",
604  IterationConfig::register_duplicate_cleaner("phase1:clean_duplicates_sharedhits_pixelseed",
606  }
607  } rdc_instance;
608  } // namespace
609 
610  //=========================================================================
611  // Quality filters
612  //=========================================================================
613 
614  // quality filter for n hits with seed hit "penalty" for strip-based seeds
615  // this implicitly separates triplets and doublet seeds with glued layers
616  template <class TRACK>
617  bool qfilter_n_hits(const TRACK &t, const MkJob &j) {
618  int seedHits = t.getNSeedHits();
619  int seedReduction = (seedHits <= 5) ? 2 : 3;
620  return t.nFoundHits() - seedReduction >= j.params_cur().minHitsQF;
621  }
622 
623  // simple hit-count quality filter; used with pixel-based seeds
624  template <class TRACK>
625  bool qfilter_n_hits_pixseed(const TRACK &t, const MkJob &j) {
626  return t.nFoundHits() >= j.params_cur().minHitsQF;
627  }
628 
629  // layer-dependent quality filter
630  // includes ad hoc tuning for phase-1
631  template <class TRACK>
632  bool qfilter_n_layers(const TRACK &t, const MkJob &j) {
633  const BeamSpot &bspot = j.m_beam_spot;
634  const TrackerInfo &trk_inf = j.m_trk_info;
635  int enhits = t.nHitsByTypeEncoded(trk_inf);
636  int npixhits = t.nPixelDecoded(enhits);
637  int enlyrs = t.nLayersByTypeEncoded(trk_inf);
638  int npixlyrs = t.nPixelDecoded(enlyrs);
639  int nmatlyrs = t.nTotMatchDecoded(enlyrs);
640  int llyr = t.getLastFoundHitLyr();
641  int lplyr = t.getLastFoundPixelHitLyr();
642  float invpt = t.invpT();
643 
644  // based on fr and eff vs pt (convert to native invpt)
645  float invptmin = 1.43; // min 1/pT (=1/0.7) for full filter on (npixhits<=3 .or. npixlyrs<=3)
646  float d0BS = t.d0BeamSpot(bspot.x, bspot.y);
647  float d0_max = 0.1; // 1 mm, max for somewhat prompt
648 
649  // next-to-outermost pixel layers (almost): BPIX3 or FPIX1
650  bool endsInsidePix = (llyr == 2 || llyr == 18 || llyr == 45);
651  // not last pixel layers: BPIX[123] or FPIX[12]
652  bool lastInsidePix = ((0 <= lplyr && lplyr < 3) || (18 <= lplyr && lplyr < 20) || (45 <= lplyr && lplyr < 47));
653  // reject short tracks missing last pixel layer except for prompt-looking
654  return !(((npixhits <= 3 || npixlyrs <= 3) && endsInsidePix &&
655  (invpt < invptmin || (invpt >= invptmin && std::abs(d0BS) > d0_max))) ||
656  ((npixlyrs <= 3 && nmatlyrs <= 6) && lastInsidePix && llyr != lplyr && std::abs(d0BS) > d0_max));
657  }
658 
660  // includes ad hoc tuning for phase-1
661  template <class TRACK>
662  bool qfilter_pixelLessFwd(const TRACK &t, const MkJob &j) {
663  const BeamSpot &bspot = j.m_beam_spot;
664  const TrackerInfo &tk_info = j.m_trk_info;
665  float d0BS = t.d0BeamSpot(bspot.x, bspot.y);
666  float d0_max = 0.05; // 0.5 mm, max for somewhat prompt
667 
668  int encoded;
669  encoded = t.nLayersByTypeEncoded(tk_info);
670  int nLyrs = t.nTotMatchDecoded(encoded);
671  encoded = t.nHitsByTypeEncoded(tk_info);
672  int nHits = t.nTotMatchDecoded(encoded);
673 
674  // to subtract stereo seed layers to count just r-phi seed layers (better pt err)
675  int seedReduction = (t.getNSeedHits() <= 5) ? 2 : 3;
676 
677  // based on fr and eff vs pt and eta (convert to native invpt and theta)
678  float invpt = t.invpT();
679  float invptmin = 1.11; // =1/0.9
680 
681  float thetasym = std::abs(t.theta() - Const::PIOver2);
682  float thetasymmin = 1.11; // -> |eta|=1.45
683 
684  // accept longer tracks, reject too short and displaced
685  return (((t.nFoundHits() - seedReduction >= 4 && invpt < invptmin) ||
686  (t.nFoundHits() - seedReduction >= 3 && invpt > invptmin && thetasym <= thetasymmin) ||
687  (t.nFoundHits() - seedReduction >= 4 && invpt > invptmin && thetasym > thetasymmin)) &&
688  !((nLyrs <= 4 || nHits <= 4) && std::abs(d0BS) > d0_max && invpt < invptmin));
689  }
690 
692  // includes ad hoc tuning for phase-1
693  template <class TRACK>
694  bool qfilter_pixelLessBkwd(const TRACK &t, const MkJob &j) {
695  const BeamSpot &bspot = j.m_beam_spot;
696  const TrackerInfo &tk_info = j.m_trk_info;
697  float d0BS = t.d0BeamSpot(bspot.x, bspot.y);
698  float d0_max = 0.1; // 1 mm
699 
700  int encoded;
701  encoded = t.nLayersByTypeEncoded(tk_info);
702  int nLyrs = t.nTotMatchDecoded(encoded);
703  encoded = t.nHitsByTypeEncoded(tk_info);
704  int nHits = t.nTotMatchDecoded(encoded);
705 
706  // based on fr and eff vs pt and eta (convert to native invpt and theta)
707  float invpt = t.invpT();
708  float invptmin = 1.11; // =1/0.9
709 
710  float thetasym = std::abs(t.theta() - Const::PIOver2);
711  float thetasymmin_l = 0.80; // -> |eta|=0.9
712  float thetasymmin_h = 1.11; // -> |eta|=1.45
713 
714  // reject too short or too displaced tracks
715  return !(
716  ((nLyrs <= 3 || nHits <= 3)) ||
717  ((nLyrs <= 4 || nHits <= 4) && (invpt < invptmin || (thetasym > thetasymmin_l && std::abs(d0BS) > d0_max))) ||
718  ((nLyrs <= 5 || nHits <= 5) && (invpt > invptmin && thetasym > thetasymmin_h && std::abs(d0BS) > d0_max)));
719  }
720 
721  namespace {
722  CMS_SA_ALLOW struct register_quality_filters {
723  register_quality_filters() {
724  IterationConfig::register_candidate_filter("phase1:qfilter_n_hits", qfilter_n_hits<TrackCand>);
725  IterationConfig::register_candidate_filter("phase1:qfilter_n_hits_pixseed",
726  qfilter_n_hits_pixseed<TrackCand>);
727  IterationConfig::register_candidate_filter("phase1:qfilter_n_layers", qfilter_n_layers<TrackCand>);
728  IterationConfig::register_candidate_filter("phase1:qfilter_pixelLessFwd", qfilter_pixelLessFwd<TrackCand>);
729  IterationConfig::register_candidate_filter("phase1:qfilter_pixelLessBkwd", qfilter_pixelLessBkwd<TrackCand>);
730  }
731  } rqf_instance;
732  } // namespace
733 
734  //=========================================================================
735  // Track scoring
736  //=========================================================================
737 
738  float trackScoreDefault(const int nfoundhits,
739  const int ntailholes,
740  const int noverlaphits,
741  const int nmisshits,
742  const float chi2,
743  const float pt,
744  const bool inFindCandidates) {
745  float maxBonus = 8.0;
746  float bonus = Config::validHitSlope_ * nfoundhits + Config::validHitBonus_;
747  float penalty = Config::missingHitPenalty_;
748  float tailPenalty = Config::tailMissingHitPenalty_;
749  float overlapBonus = Config::overlapHitBonus_;
750  if (pt < 0.9) {
751  penalty *= inFindCandidates ? 1.7f : 1.5f;
752  bonus = std::min(bonus * (inFindCandidates ? 0.9f : 1.0f), maxBonus);
753  }
754  float score =
755  bonus * nfoundhits + overlapBonus * noverlaphits - penalty * nmisshits - tailPenalty * ntailholes - chi2;
756  return score;
757  }
758 
759  namespace {
760  CMS_SA_ALLOW struct register_track_scorers {
761  register_track_scorers() {
764  }
765  } rts_instance;
766  } // namespace
767 
768  } // namespace StdSeq
769 } // namespace mkfit
std::vector< DeadVec > deadvectors
int getHitIdx(int posHitIdx) const
Definition: Track.h:450
float d0BeamSpot(const float x_bs, const float y_bs, bool linearize=false) const
Definition: Track.cc:191
bool qfilter_pixelLessFwd(const TRACK &t, const MkJob &j)
quality filter tuned for pixelLess iteration during forward search
Definition: MkStdSeqs.cc:662
float squashPhiMinimal(float phi)
Definition: Hit.h:26
int getHitLyr(int posHitIdx) const
Definition: Track.h:451
const float maxdPt
Definition: Config.cc:21
const float maxdphi
Definition: Config.cc:28
const float maxd1pt
Definition: Config.cc:27
int charge() const
Definition: Track.h:171
#define CMS_SA_ALLOW
void cmssw_Map_TrackHitIndices(const EventOfHits &eoh, TrackVec &seeds)
Definition: MkStdSeqs.cc:56
void clean_duplicates(TrackVec &tracks, const IterationConfig &itconf)
Definition: MkStdSeqs.cc:355
const float maxdcth
Definition: Config.cc:29
constexpr float validHitSlope_
Definition: Config.h:81
static void register_track_scorer(const std::string &name, track_score_func func)
I_pair from_R_rdr_to_N_bins(R r, R dr) const
Definition: binnor.h:73
float pT() const
Definition: Track.h:157
constexpr float c_dpt_common
Definition: Config.h:100
void cmssw_LoadHits_End(EventOfHits &eoh)
Definition: MkStdSeqs.cc:45
bool qfilter_n_hits(const TRACK &t, const MkJob &j)
Definition: MkStdSeqs.cc:617
float trackScoreDefault(const int nfoundhits, const int ntailholes, const int noverlaphits, const int nmisshits, const float chi2, const float pt, const bool inFindCandidates)
Definition: MkStdSeqs.cc:738
Trktree trk
Definition: Trktree.cc:2
C_pair get_content(B_pair n_bin) const
Definition: binnor.h:240
const float maxdR
Definition: Config.cc:24
static constexpr int kMaxSeedHits
Definition: Track.h:200
int nLayers() const
I next_N_bin(I bin) const
Definition: binnor.h:113
constexpr float PIOver2
Definition: Config.h:9
static void register_duplicate_cleaner(const std::string &name, clean_duplicates_func func)
float invpT() const
Definition: Track.h:158
void cmssw_LoadHits_Begin(EventOfHits &eoh, const std::vector< const HitVec *> &orig_hitvectors)
Definition: MkStdSeqs.cc:29
void finalize_registration()
Definition: binnor.h:289
axis_base< R, I, M, N >::I_pair from_R_rdr_to_N_bins(R r, R dr) const
Definition: binnor.h:110
const float maxcth_fw
Definition: Config.cc:31
float theta() const
Definition: Track.h:162
int nFoundHits() const
Definition: Track.h:511
float momEta() const
Definition: Track.h:161
void remove_duplicates(TrackVec &tracks)
Definition: MkStdSeqs.cc:350
float y() const
Definition: Track.h:147
const float maxcth_ob
Definition: Config.cc:30
std::vector< C > m_ranks
Definition: binnor.h:211
void sortHitsByLayer()
Definition: Track.cc:394
constexpr float c_etamax_brl
Definition: Config.h:99
void cmssw_ReMap_TrackHitIndices(const EventOfHits &eoh, TrackVec &out_tracks)
Definition: MkStdSeqs.cc:69
const float maxdEta
Definition: Config.cc:23
constexpr float PI
Definition: Config.h:7
static void register_seed_cleaner(const std::string &name, clean_seeds_func func)
const float maxdPhi
Definition: Config.cc:22
T sqrt(T t)
Definition: SSEVec.h:23
def unique(seq, keepstr=True)
Definition: tier0.py:24
void register_entry_safe(typename A1::real_t r1, typename A2::real_t r2)
Definition: binnor.h:282
constexpr float tailMissingHitPenalty_
Definition: Config.h:84
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
void loadDeads(EventOfHits &eoh, const std::vector< DeadVec > &deadvectors)
Definition: MkStdSeqs.cc:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
bool qfilter_pixelLessBkwd(const TRACK &t, const MkJob &j)
quality filter tuned for pixelLess iteration during backward search
Definition: MkStdSeqs.cc:694
void addHitIdx(int hitIdx, int hitLyr, float chi2)
Definition: Track.h:437
float cdist(float a)
Definition: Config.h:33
d
Definition: ztail.py:151
void begin_registration(C n_items)
Definition: binnor.h:264
constexpr float overlapHitBonus_
Definition: Config.h:82
bool qfilter_n_layers(const TRACK &t, const MkJob &j)
Definition: MkStdSeqs.cc:632
std::vector< Track > TrackVec
static constexpr float d0
float z() const
Definition: Track.h:148
constexpr float track1GeVradius
Definition: Config.h:98
double b
Definition: hdecay.h:120
int nTotalHits() const
Definition: Track.h:512
double a
Definition: hdecay.h:121
float x
TrackAlgorithm
track algorithm; copy from TrackBase.h to keep in standalone builds
Definition: Track.h:272
float x() const
Definition: Track.h:146
const bool useHitsForDuplicates
Definition: Config.h:114
int clean_cms_seedtracks_iter(TrackVec &seeds, const IterationConfig &itrcfg, const BeamSpot &bspot)
Definition: MkStdSeqs.cc:85
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
float momPhi() const
Definition: Track.h:160
void clean_duplicates_sharedhits_pixelseed(TrackVec &tracks, const IterationConfig &itconf)
Definition: MkStdSeqs.cc:505
I next_N_bin(I bin) const
Definition: binnor.h:74
void suckInDeads(int layer, const DeadVec &deadv)
static void register_candidate_filter(const std::string &name, filter_candidates_func func)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
Definition: fakeMenu.h:6
void clean_duplicates_sharedhits(TrackVec &tracks, const IterationConfig &itconf)
Definition: MkStdSeqs.cc:441
bool qfilter_n_hits_pixseed(const TRACK &t, const MkJob &j)
Definition: MkStdSeqs.cc:625
constexpr float validHitBonus_
Definition: Config.h:80
const float minFracHitsShared
Definition: Config.cc:25
constexpr float missingHitPenalty_
Definition: Config.h:83