11 #include "oneapi/tbb/parallel_for.h" 22 for (
size_t il = 0; il <
deadvectors.size(); il++) {
35 l.beginRegistrationOfHits(*orig_hitvectors[
l.is_pixel() ? 0 : 1]);
50 l.endRegistrationOfHits(
false);
60 for (
int i = 0;
i <
track.nTotalHits(); ++
i) {
61 const int hitidx =
track.getHitIdx(
i);
62 const int hitlyr =
track.getHitLyr(
i);
64 const auto &loh = eoh[hitlyr];
65 track.setHitIdx(
i, loh.getHitIndexFromOriginal(hitidx));
72 for (
auto &&
track : out_tracks) {
73 for (
int i = 0;
i <
track.nTotalHits(); ++
i) {
74 const int hitidx =
track.getHitIdx(
i);
75 const int hitlyr =
track.getHitLyr(
i);
77 const auto &loh = eoh[hitlyr];
78 track.setHitIdx(
i, loh.getOriginalHitIndex(hitidx));
104 const float dzmax2_inv_bh = 1.f / (dzmax_bh * dzmax_bh);
105 const float drmax2_inv_bh = 1.f / (drmax_bh * drmax_bh);
106 const float dzmax2_inv_eh = 1.f / (dzmax_eh * dzmax_eh);
107 const float drmax2_inv_eh = 1.f / (drmax_eh * drmax_eh);
108 const float dzmax2_inv_bl = 1.f / (dzmax_bl * dzmax_bl);
109 const float drmax2_inv_bl = 1.f / (drmax_bl * drmax_bl);
110 const float dzmax2_inv_el = 1.f / (dzmax_el * dzmax_el);
111 const float drmax2_inv_el = 1.f / (drmax_el * drmax_el);
116 const bool merge_hits =
true;
117 const float ptmax_merge_lowPtQuad = 0.2;
118 const float etamin_merge_lowPtQuad = 1.5;
123 const int ns =
seeds.size();
125 std::cout <<
"before seed cleaning " <<
seeds.size() << std::endl;
128 cleanSeedTracks.reserve(ns);
129 std::vector<bool> writetrack(ns,
true);
133 std::vector<int>
nHits(ns);
134 std::vector<int>
charge(ns);
135 std::vector<float> oldPhi(ns);
136 std::vector<float> pos2(ns);
137 std::vector<float>
eta(ns);
138 std::vector<float> ctheta(ns);
139 std::vector<float> invptq(ns);
140 std::vector<float>
pt(ns);
141 std::vector<float>
x(ns);
142 std::vector<float> y(ns);
143 std::vector<float> z(ns);
144 std::vector<float>
d0(ns);
153 for (
int ts = 0; ts < ns; ts++) {
174 for (
int sorted_ts = 0; sorted_ts < ns; sorted_ts++) {
175 int ts = phi_eta_binnor.
m_ranks[sorted_ts];
177 if (not writetrack[ts])
180 const float oldPhi1 = oldPhi[ts];
181 const float pos2_first = pos2[ts];
183 const float pt1 =
pt[ts];
184 const float invptq_first = invptq[ts];
187 int n_ovlp_hits_added = 0;
192 for (
auto i_phi = phi_rng.begin; i_phi != phi_rng.end; i_phi = ax_phi.
next_N_bin(i_phi)) {
193 for (
auto i_eta = eta_rng.begin; i_eta != eta_rng.end; i_eta = ax_eta.
next_N_bin(i_eta)) {
194 const auto cbin = phi_eta_binnor.
get_content(i_phi, i_eta);
195 for (
auto i = cbin.first;
i < cbin.end(); ++
i) {
196 int tss = phi_eta_binnor.
m_ranks[
i];
198 if (not writetrack[ts])
200 if (not writetrack[tss])
205 const float pt2 =
pt[tss];
213 if (thisDPt > dpt_common *
pt1)
219 const float oldPhi2 = oldPhi[tss];
221 const float pos2_second = pos2[tss];
222 const float thisDXYSign05 = pos2_second > pos2_first ? -0.5f : 0.5f;
226 const float invptq_second = invptq[tss];
228 const float newPhi1 = oldPhi1 - thisDXY * invR1GeV * invptq_first;
229 const float newPhi2 = oldPhi2 + thisDXY * invR1GeV * invptq_second;
233 const float dr2 = deta2 + dphi * dphi;
235 const float thisDZ = z[ts] - z[tss] - thisDXY * (ctheta[ts] + ctheta[tss]);
236 const float dz2 = thisDZ * thisDZ;
240 bool overlapping =
false;
242 if (
pt1 > ptmin_hpt) {
243 if (dz2 * dzmax2_inv_bh + dr2 * drmax2_inv_bh < 1.0
f)
246 if (dz2 * dzmax2_inv_bl + dr2 * drmax2_inv_bl < 1.0
f)
250 if (
pt1 > ptmin_hpt) {
251 if (dz2 * dzmax2_inv_eh + dr2 * drmax2_inv_eh < 1.0
f)
254 if (dz2 * dzmax2_inv_el + dr2 * drmax2_inv_el < 1.0
f)
263 if (
d0[tss] >
d0[ts])
264 writetrack[tss] =
false;
266 writetrack[ts] =
false;
276 (pt1 < ptmax_merge_lowPtQuad && std::abs(eta1) > etamin_merge_lowPtQuad))) {
279 float fakeChi2 = 0.0;
301 if (n_ovlp_hits_added > 0)
308 if (writetrack[ts]) {
309 cleanSeedTracks.emplace_back(
seeds[ts]);
313 seeds.swap(cleanSeedTracks);
317 const int ns2 =
seeds.size();
318 printf(
"Number of CMS seeds before %d --> after %d cleaning\n", ns, ns2);
320 for (
int it = 0;
it < ns2;
it++) {
322 printf(
" %3i q=%+i pT=%7.3f eta=% 7.3f nHits=%i label=% i\n",
342 register_seed_cleaners() {
359 float eta1, phi1,
pt1, deta, dphi, dr2;
364 for (
auto itrack = 0
U; itrack <
ntracks - 1; itrack++) {
367 phi1 =
track.momPhi();
369 for (
auto jtrack = itrack + 1; jtrack <
ntracks; jtrack++) {
370 auto &track2 =
tracks[jtrack];
371 if (
track.label() == track2.label())
373 if (
track.algoint() != track2.algoint())
387 maxdRSquared *= 16.0f;
389 maxdRSquared *= 9.0f;
390 dr2 = dphi * dphi + deta * deta;
391 if (dr2 < maxdRSquared) {
393 if (
track.score() > track2.score())
394 track2.setDuplicateValue(
true);
396 track.setDuplicateValue(
true);
401 if (track2.pT() == 0)
406 float numHitsShared = 0;
407 for (
int ihit2 = 0; ihit2 < track2.nTotalHits(); ihit2++) {
408 const int hitidx2 = track2.getHitIdx(ihit2);
409 const int hitlyr2 = track2.getHitLyr(ihit2);
411 auto const it = std::find_if(
track.beginHitsOnTrack(),
412 track.endHitsOnTrack(),
413 [&hitidx2, &hitlyr2](
const HitOnTrack &element) {
414 return (element.index == hitidx2 && element.layer == hitlyr2);
416 if (
it !=
track.endHitsOnTrack())
421 float fracHitsShared = numHitsShared /
std::min(
track.nFoundHits(), track2.nFoundHits());
427 if (
track.score() > track2.score())
428 track2.setDuplicateValue(
true);
430 track.setDuplicateValue(
true);
447 std::vector<float> ctheta(
ntracks);
448 std::multimap<int, int> hitMap;
450 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
451 auto &trk =
tracks[itrack];
452 ctheta[itrack] = 1.f /
std::tan(trk.theta());
453 for (
int i = 0;
i < trk.nTotalHits(); ++
i) {
454 if (trk.getHitIdx(
i) < 0)
456 int a = trk.getHitLyr(
i);
457 int b = trk.getHitIdx(
i);
458 hitMap.insert(std::make_pair(
b * 1000 +
a,
i > 0 ? itrack : -itrack));
462 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
463 auto &trk =
tracks[itrack];
464 auto phi1 = trk.momPhi();
465 auto ctheta1 = ctheta[itrack];
467 std::map<int, int> sharingMap;
468 for (
int i = 0;
i < trk.nTotalHits(); ++
i) {
469 if (trk.getHitIdx(
i) < 0)
471 int a = trk.getHitLyr(
i);
472 int b = trk.getHitIdx(
i);
473 auto range = hitMap.equal_range(
b * 1000 +
a);
477 if (
i == 0 &&
it->second < 0)
483 for (
const auto &elem : sharingMap) {
484 auto &track2 =
tracks[elem.first];
487 auto dctheta =
std::abs(ctheta[elem.first] - ctheta1);
495 if (elem.second >=
std::min(trk.nFoundHits(), track2.nFoundHits()) *
fraction) {
496 if (trk.score() > track2.score())
497 track2.setDuplicateValue(
true);
499 trk.setDuplicateValue(
true);
514 std::vector<float> ctheta(
ntracks);
515 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
516 auto &trk =
tracks[itrack];
517 ctheta[itrack] = 1.f /
std::tan(trk.theta());
520 float phi1, invpt1, dctheta, ctheta1, dphi, dr2;
521 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
522 auto &trk =
tracks[itrack];
524 invpt1 = trk.invpT();
525 ctheta1 = ctheta[itrack];
526 for (
auto jtrack = itrack + 1; jtrack <
ntracks; jtrack++) {
527 auto &track2 =
tracks[jtrack];
528 if (trk.label() == track2.label())
531 dctheta =
std::abs(ctheta[jtrack] - ctheta1);
541 float maxdRSquared = drth_central * drth_central;
543 maxdRSquared = drth_forward * drth_forward;
545 maxdRSquared = drth_obarrel * drth_obarrel;
546 dr2 = dphi * dphi + dctheta * dctheta;
547 if (dr2 < maxdRSquared) {
549 if (trk.score() > track2.score())
550 track2.setDuplicateValue(
true);
552 trk.setDuplicateValue(
true);
559 auto sharedCount = 0;
560 auto sharedFirst = 0;
561 const auto minFoundHits =
std::min(trk.nFoundHits(), track2.nFoundHits());
563 for (
int i = 0;
i < trk.nTotalHits(); ++
i) {
564 if (trk.getHitIdx(
i) < 0)
566 const int a = trk.getHitLyr(
i);
567 const int b = trk.getHitIdx(
i);
568 for (
int j = 0;
j < track2.nTotalHits(); ++
j) {
569 if (track2.getHitIdx(
j) < 0)
571 const int c = track2.getHitLyr(
j);
572 const int d = track2.getHitIdx(
j);
575 if (
a ==
c &&
b ==
d)
577 if (
j == 0 &&
i == 0 &&
a ==
c &&
b ==
d)
580 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction))
583 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction))
588 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction)) {
589 if (trk.score() > track2.score())
590 track2.setDuplicateValue(
true);
592 trk.setDuplicateValue(
true);
602 register_duplicate_cleaners() {
618 template <
class TRACK>
620 int seedHits =
t.getNSeedHits();
621 int seedReduction = (seedHits <= 5) ? 2 : 3;
622 return t.nFoundHits() - seedReduction >=
j.params_cur().minHitsQF;
626 template <
class TRACK>
628 return t.nFoundHits() >=
j.params_cur().minHitsQF;
633 template <
class TRACK>
637 int enhits =
t.nHitsByTypeEncoded(trk_inf);
638 int npixhits =
t.nPixelDecoded(enhits);
639 int enlyrs =
t.nLayersByTypeEncoded(trk_inf);
640 int npixlyrs =
t.nPixelDecoded(enlyrs);
641 int nmatlyrs =
t.nTotMatchDecoded(enlyrs);
642 int llyr =
t.getLastFoundHitLyr();
643 int lplyr =
t.getLastFoundPixelHitLyr();
644 float invpt =
t.invpT();
647 float invptmin = 1.43;
648 float d0BS =
t.d0BeamSpot(bspot.
x, bspot.
y);
652 bool endsInsidePix = (llyr == 2 || llyr == 18 || llyr == 45);
654 bool lastInsidePix = ((0 <= lplyr && lplyr < 3) || (18 <= lplyr && lplyr < 20) || (45 <= lplyr && lplyr < 47));
656 return !(((npixhits <= 3 || npixlyrs <= 3) && endsInsidePix &&
657 (invpt < invptmin || (invpt >= invptmin &&
std::abs(d0BS) >
d0_max))) ||
658 ((npixlyrs <= 3 && nmatlyrs <= 6) && lastInsidePix && llyr != lplyr &&
std::abs(d0BS) >
d0_max));
663 template <
class TRACK>
667 float d0BS =
t.d0BeamSpot(bspot.
x, bspot.
y);
671 encoded =
t.nLayersByTypeEncoded(tk_info);
672 int nLyrs =
t.nTotMatchDecoded(encoded);
673 encoded =
t.nHitsByTypeEncoded(tk_info);
674 int nHits =
t.nTotMatchDecoded(encoded);
677 int seedReduction = (
t.getNSeedHits() <= 5) ? 2 : 3;
680 float invpt =
t.invpT();
681 float invptmin = 1.11;
684 float thetasymmin = 1.11;
687 return (((
t.nFoundHits() - seedReduction >= 4 && invpt < invptmin) ||
688 (
t.nFoundHits() - seedReduction >= 3 && invpt > invptmin && thetasym <= thetasymmin) ||
689 (
t.nFoundHits() - seedReduction >= 4 && invpt > invptmin && thetasym > thetasymmin)) &&
690 !((nLyrs <= 4 || nHits <= 4) && std::abs(d0BS) >
d0_max && invpt < invptmin));
695 template <
class TRACK>
699 float d0BS =
t.d0BeamSpot(bspot.
x, bspot.
y);
703 encoded =
t.nLayersByTypeEncoded(tk_info);
704 int nLyrs =
t.nTotMatchDecoded(encoded);
705 encoded =
t.nHitsByTypeEncoded(tk_info);
706 int nHits =
t.nTotMatchDecoded(encoded);
709 float invpt =
t.invpT();
710 float invptmin = 1.11;
713 float thetasymmin_l = 0.80;
714 float thetasymmin_h = 1.11;
718 ((nLyrs <= 3 ||
nHits <= 3)) ||
719 ((nLyrs <= 4 || nHits <= 4) && (invpt < invptmin || (thetasym > thetasymmin_l &&
std::abs(d0BS) >
d0_max))) ||
720 ((nLyrs <= 5 ||
nHits <= 5) && (invpt > invptmin && thetasym > thetasymmin_h &&
std::abs(d0BS) >
d0_max)));
725 register_quality_filters() {
728 qfilter_n_hits_pixseed<TrackCand>);
741 const int ntailholes,
742 const int noverlaphits,
746 const bool inFindCandidates) {
747 float maxBonus = 8.0;
753 penalty *= inFindCandidates ? 1.7f : 1.5f;
754 bonus =
std::min(bonus * (inFindCandidates ? 0.9
f : 1.0
f), maxBonus);
757 bonus * nfoundhits + overlapBonus * noverlaphits - penalty * nmisshits - tailPenalty * ntailholes -
chi2;
763 register_track_scorers() {
int getHitIdx(int posHitIdx) const
float d0BeamSpot(const float x_bs, const float y_bs, bool linearize=false) const
bool qfilter_pixelLessFwd(const TRACK &t, const MkJob &j)
quality filter tuned for pixelLess iteration during forward search
float squashPhiMinimal(float phi)
int getHitLyr(int posHitIdx) const
void cmssw_Map_TrackHitIndices(const EventOfHits &eoh, TrackVec &seeds)
void clean_duplicates(TrackVec &tracks, const IterationConfig &itconf)
constexpr float validHitSlope_
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
constexpr float c_dpt_common
void cmssw_LoadHits_End(EventOfHits &eoh)
bool qfilter_n_hits(const TRACK &t, const MkJob &j)
float trackScoreDefault(const int nfoundhits, const int ntailholes, const int noverlaphits, const int nmisshits, const float chi2, const float pt, const bool inFindCandidates)
C_pair get_content(B_pair n_bin) const
static constexpr int kMaxSeedHits
I next_N_bin(I bin) const
static void register_duplicate_cleaner(const std::string &name, clean_duplicates_func func)
void cmssw_LoadHits_Begin(EventOfHits &eoh, const std::vector< const HitVec *> &orig_hitvectors)
void finalize_registration()
axis_base< R, I, M, N >::I_pair from_R_rdr_to_N_bins(R r, R dr) const
void remove_duplicates(TrackVec &tracks)
constexpr float c_etamax_brl
void cmssw_ReMap_TrackHitIndices(const EventOfHits &eoh, TrackVec &out_tracks)
static void register_seed_cleaner(const std::string &name, clean_seeds_func func)
def unique(seq, keepstr=True)
void register_entry_safe(typename A1::real_t r1, typename A2::real_t r2)
constexpr float tailMissingHitPenalty_
Tan< T >::type tan(const T &t)
void loadDeads(EventOfHits &eoh, const std::vector< DeadVec > &deadvectors)
Abs< T >::type abs(const T &t)
bool qfilter_pixelLessBkwd(const TRACK &t, const MkJob &j)
quality filter tuned for pixelLess iteration during backward search
void addHitIdx(int hitIdx, int hitLyr, float chi2)
void begin_registration(C n_items)
constexpr float overlapHitBonus_
bool qfilter_n_layers(const TRACK &t, const MkJob &j)
std::vector< Track > TrackVec
static constexpr float d0
constexpr float track1GeVradius
TrackAlgorithm
track algorithm; copy from TrackBase.h to keep in standalone builds
const bool useHitsForDuplicates
int clean_cms_seedtracks_iter(TrackVec &seeds, const IterationConfig &itrcfg, const BeamSpot &bspot)
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
void clean_duplicates_sharedhits_pixelseed(TrackVec &tracks, const IterationConfig &itconf)
I next_N_bin(I bin) const
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)
void clean_duplicates_sharedhits(TrackVec &tracks, const IterationConfig &itconf)
std::vector< DeadVec > deadvectors
bool qfilter_n_hits_pixseed(const TRACK &t, const MkJob &j)
constexpr float validHitBonus_
const float minFracHitsShared
constexpr float missingHitPenalty_