20 for (
size_t il = 0; il <
deadvectors.size(); il++) {
33 l.beginRegistrationOfHits(*orig_hitvectors[
l.is_pixel() ? 0 : 1]);
48 l.endRegistrationOfHits(
false);
58 for (
int i = 0;
i <
track.nTotalHits(); ++
i) {
59 const int hitidx =
track.getHitIdx(
i);
60 const int hitlyr =
track.getHitLyr(
i);
62 const auto &loh = eoh[hitlyr];
63 track.setHitIdx(
i, loh.getHitIndexFromOriginal(hitidx));
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);
75 const auto &loh = eoh[hitlyr];
76 track.setHitIdx(
i, loh.getOriginalHitIndex(hitidx));
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);
114 const bool merge_hits =
true;
115 const float ptmax_merge_lowPtQuad = 0.2;
116 const float etamin_merge_lowPtQuad = 1.5;
121 const int ns =
seeds.size();
123 std::cout <<
"before seed cleaning " <<
seeds.size() << std::endl;
126 cleanSeedTracks.reserve(ns);
127 std::vector<bool> writetrack(ns,
true);
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);
151 for (
int ts = 0; ts < ns; ts++) {
172 for (
int sorted_ts = 0; sorted_ts < ns; sorted_ts++) {
173 int ts = phi_eta_binnor.
m_ranks[sorted_ts];
175 if (not writetrack[ts])
178 const float oldPhi1 = oldPhi[ts];
179 const float pos2_first = pos2[ts];
181 const float pt1 =
pt[ts];
182 const float invptq_first = invptq[ts];
185 int n_ovlp_hits_added = 0;
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];
196 if (not writetrack[ts])
198 if (not writetrack[tss])
203 const float pt2 =
pt[tss];
211 if (thisDPt > dpt_common *
pt1)
217 const float oldPhi2 = oldPhi[tss];
219 const float pos2_second = pos2[tss];
220 const float thisDXYSign05 = pos2_second > pos2_first ? -0.5f : 0.5f;
224 const float invptq_second = invptq[tss];
226 const float newPhi1 = oldPhi1 - thisDXY * invR1GeV * invptq_first;
227 const float newPhi2 = oldPhi2 + thisDXY * invR1GeV * invptq_second;
231 const float dr2 = deta2 + dphi * dphi;
233 const float thisDZ = z[ts] - z[tss] - thisDXY * (ctheta[ts] + ctheta[tss]);
234 const float dz2 = thisDZ * thisDZ;
238 bool overlapping =
false;
240 if (
pt1 > ptmin_hpt) {
241 if (dz2 * dzmax2_inv_bh + dr2 * drmax2_inv_bh < 1.0
f)
244 if (dz2 * dzmax2_inv_bl + dr2 * drmax2_inv_bl < 1.0
f)
248 if (
pt1 > ptmin_hpt) {
249 if (dz2 * dzmax2_inv_eh + dr2 * drmax2_inv_eh < 1.0
f)
252 if (dz2 * dzmax2_inv_el + dr2 * drmax2_inv_el < 1.0
f)
261 if (
d0[tss] >
d0[ts])
262 writetrack[tss] =
false;
264 writetrack[ts] =
false;
274 (pt1 < ptmax_merge_lowPtQuad && std::abs(eta1) > etamin_merge_lowPtQuad))) {
277 float fakeChi2 = 0.0;
299 if (n_ovlp_hits_added > 0)
306 if (writetrack[ts]) {
307 cleanSeedTracks.emplace_back(
seeds[ts]);
311 seeds.swap(cleanSeedTracks);
315 const int ns2 =
seeds.size();
316 printf(
"Number of CMS seeds before %d --> after %d cleaning\n", ns, ns2);
318 for (
int it = 0;
it < ns2;
it++) {
320 printf(
" %3i q=%+i pT=%7.3f eta=% 7.3f nHits=%i label=% i\n",
340 register_seed_cleaners() {
357 float eta1, phi1,
pt1, deta, dphi, dr2;
362 for (
auto itrack = 0
U; itrack <
ntracks - 1; itrack++) {
365 phi1 =
track.momPhi();
367 for (
auto jtrack = itrack + 1; jtrack <
ntracks; jtrack++) {
368 auto &track2 =
tracks[jtrack];
369 if (
track.label() == track2.label())
371 if (
track.algoint() != track2.algoint())
385 maxdRSquared *= 16.0f;
387 maxdRSquared *= 9.0f;
388 dr2 = dphi * dphi + deta * deta;
389 if (dr2 < maxdRSquared) {
391 if (
track.score() > track2.score())
392 track2.setDuplicateValue(
true);
394 track.setDuplicateValue(
true);
399 if (track2.pT() == 0)
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);
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);
414 if (
it !=
track.endHitsOnTrack())
419 float fracHitsShared = numHitsShared /
std::min(
track.nFoundHits(), track2.nFoundHits());
425 if (
track.score() > track2.score())
426 track2.setDuplicateValue(
true);
428 track.setDuplicateValue(
true);
445 std::vector<float> ctheta(
ntracks);
446 std::multimap<int, int> hitMap;
448 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
451 for (
int i = 0;
i <
trk.nTotalHits(); ++
i) {
452 if (
trk.getHitIdx(
i) < 0)
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));
460 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
462 auto phi1 =
trk.momPhi();
463 auto ctheta1 = ctheta[itrack];
465 std::map<int, int> sharingMap;
466 for (
int i = 0;
i <
trk.nTotalHits(); ++
i) {
467 if (
trk.getHitIdx(
i) < 0)
469 int a =
trk.getHitLyr(
i);
470 int b =
trk.getHitIdx(
i);
471 auto range = hitMap.equal_range(
b * 1000 +
a);
475 if (
i == 0 &&
it->second < 0)
481 for (
const auto &elem : sharingMap) {
482 auto &track2 =
tracks[elem.first];
485 auto dctheta =
std::abs(ctheta[elem.first] - ctheta1);
494 if (
trk.score() > track2.score())
495 track2.setDuplicateValue(
true);
497 trk.setDuplicateValue(
true);
512 std::vector<float> ctheta(
ntracks);
513 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
518 float phi1, invpt1, dctheta, ctheta1, dphi, dr2;
519 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
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())
529 dctheta =
std::abs(ctheta[jtrack] - ctheta1);
539 float maxdRSquared = drth_central * drth_central;
541 maxdRSquared = drth_forward * drth_forward;
543 maxdRSquared = drth_obarrel * drth_obarrel;
544 dr2 = dphi * dphi + dctheta * dctheta;
545 if (dr2 < maxdRSquared) {
547 if (
trk.score() > track2.score())
548 track2.setDuplicateValue(
true);
550 trk.setDuplicateValue(
true);
557 auto sharedCount = 0;
558 auto sharedFirst = 0;
559 const auto minFoundHits =
std::min(
trk.nFoundHits(), track2.nFoundHits());
561 for (
int i = 0;
i <
trk.nTotalHits(); ++
i) {
562 if (
trk.getHitIdx(
i) < 0)
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)
569 const int c = track2.getHitLyr(
j);
570 const int d = track2.getHitIdx(
j);
573 if (
a ==
c &&
b ==
d)
575 if (
j == 0 &&
i == 0 &&
a ==
c &&
b ==
d)
578 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction))
581 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction))
586 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction)) {
587 if (
trk.score() > track2.score())
588 track2.setDuplicateValue(
true);
590 trk.setDuplicateValue(
true);
600 register_duplicate_cleaners() {
616 template <
class TRACK>
618 int seedHits =
t.getNSeedHits();
619 int seedReduction = (seedHits <= 5) ? 2 : 3;
620 return t.nFoundHits() - seedReduction >=
j.params_cur().minHitsQF;
624 template <
class TRACK>
626 return t.nFoundHits() >=
j.params_cur().minHitsQF;
631 template <
class TRACK>
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();
645 float invptmin = 1.43;
646 float d0BS =
t.d0BeamSpot(bspot.
x, bspot.
y);
650 bool endsInsidePix = (llyr == 2 || llyr == 18 || llyr == 45);
652 bool lastInsidePix = ((0 <= lplyr && lplyr < 3) || (18 <= lplyr && lplyr < 20) || (45 <= lplyr && lplyr < 47));
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));
661 template <
class TRACK>
665 float d0BS =
t.d0BeamSpot(bspot.
x, bspot.
y);
669 encoded =
t.nLayersByTypeEncoded(tk_info);
670 int nLyrs =
t.nTotMatchDecoded(encoded);
671 encoded =
t.nHitsByTypeEncoded(tk_info);
672 int nHits =
t.nTotMatchDecoded(encoded);
675 int seedReduction = (
t.getNSeedHits() <= 5) ? 2 : 3;
678 float invpt =
t.invpT();
679 float invptmin = 1.11;
682 float thetasymmin = 1.11;
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));
693 template <
class TRACK>
697 float d0BS =
t.d0BeamSpot(bspot.
x, bspot.
y);
701 encoded =
t.nLayersByTypeEncoded(tk_info);
702 int nLyrs =
t.nTotMatchDecoded(encoded);
703 encoded =
t.nHitsByTypeEncoded(tk_info);
704 int nHits =
t.nTotMatchDecoded(encoded);
707 float invpt =
t.invpT();
708 float invptmin = 1.11;
711 float thetasymmin_l = 0.80;
712 float thetasymmin_h = 1.11;
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)));
723 register_quality_filters() {
726 qfilter_n_hits_pixseed<TrackCand>);
739 const int ntailholes,
740 const int noverlaphits,
744 const bool inFindCandidates) {
745 float maxBonus = 8.0;
751 penalty *= inFindCandidates ? 1.7f : 1.5f;
752 bonus =
std::min(bonus * (inFindCandidates ? 0.9
f : 1.0
f), maxBonus);
755 bonus * nfoundhits + overlapBonus * noverlaphits - penalty * nmisshits - tailPenalty * ntailholes -
chi2;
761 register_track_scorers() {
std::vector< DeadVec > deadvectors
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)
bool qfilter_n_hits_pixseed(const TRACK &t, const MkJob &j)
constexpr float validHitBonus_
const float minFracHitsShared
constexpr float missingHitPenalty_