8 #include "oneapi/tbb/parallel_for.h" 19 for (
size_t il = 0; il < deadvectors.size(); il++) {
32 l.beginRegistrationOfHits(*orig_hitvectors[
l.is_pixel() ? 0 : 1]);
47 l.endRegistrationOfHits(
false);
57 for (
int i = 0;
i <
track.nTotalHits(); ++
i) {
58 const int hitidx =
track.getHitIdx(
i);
59 const int hitlyr =
track.getHitLyr(
i);
61 const auto &loh = eoh[hitlyr];
62 track.setHitIdx(
i, loh.getHitIndexFromOriginal(hitidx));
69 for (
auto &&
track : out_tracks) {
70 for (
int i = 0;
i <
track.nTotalHits(); ++
i) {
71 const int hitidx =
track.getHitIdx(
i);
72 const int hitlyr =
track.getHitLyr(
i);
74 const auto &loh = eoh[hitlyr];
75 track.setHitIdx(
i, loh.getOriginalHitIndex(hitidx));
101 const float dzmax2_inv_bh = 1.f / (dzmax_bh * dzmax_bh);
102 const float drmax2_inv_bh = 1.f / (drmax_bh * drmax_bh);
103 const float dzmax2_inv_eh = 1.f / (dzmax_eh * dzmax_eh);
104 const float drmax2_inv_eh = 1.f / (drmax_eh * drmax_eh);
105 const float dzmax2_inv_bl = 1.f / (dzmax_bl * dzmax_bl);
106 const float drmax2_inv_bl = 1.f / (drmax_bl * drmax_bl);
107 const float dzmax2_inv_el = 1.f / (dzmax_el * dzmax_el);
108 const float drmax2_inv_el = 1.f / (drmax_el * drmax_el);
113 const bool merge_hits =
true;
114 const float ptmax_merge_lowPtQuad = 0.2;
115 const float etamin_merge_lowPtQuad = 1.5;
117 if (seed_ptr ==
nullptr)
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",
344 float eta1, phi1,
pt1, deta, dphi, dr2;
349 for (
auto itrack = 0
U; itrack <
ntracks - 1; itrack++) {
356 phi1 =
track.momPhi();
358 for (
auto jtrack = itrack + 1; jtrack <
ntracks; jtrack++) {
359 auto &track2 =
tracks[jtrack];
360 if (
track.label() == track2.label())
362 if (
track.algoint() != track2.algoint())
376 maxdRSquared *= 16.0f;
378 maxdRSquared *= 9.0f;
379 dr2 = dphi * dphi + deta * deta;
380 if (dr2 < maxdRSquared) {
382 if (
track.score() > track2.score())
383 track2.setDuplicateValue(
true);
385 track.setDuplicateValue(
true);
390 if (track2.pT() == 0)
395 float numHitsShared = 0;
396 for (
int ihit2 = 0; ihit2 < track2.nTotalHits(); ihit2++) {
397 const int hitidx2 = track2.getHitIdx(ihit2);
398 const int hitlyr2 = track2.getHitLyr(ihit2);
400 auto const it = std::find_if(
track.beginHitsOnTrack(),
401 track.endHitsOnTrack(),
402 [&hitidx2, &hitlyr2](
const HitOnTrack &element) {
403 return (element.index == hitidx2 && element.layer == hitlyr2);
405 if (it !=
track.endHitsOnTrack())
410 float fracHitsShared = numHitsShared /
std::min(
track.nFoundHits(), track2.nFoundHits());
416 if (
track.score() > track2.score())
417 track2.setDuplicateValue(
true);
419 track.setDuplicateValue(
true);
438 std::vector<float> ctheta(
ntracks);
439 std::multimap<int, int> hitMap;
441 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
442 auto &trk =
tracks[itrack];
443 ctheta[itrack] = 1.f /
std::tan(trk.theta());
444 for (
int i = 0;
i < trk.nTotalHits(); ++
i) {
445 if (trk.getHitIdx(
i) < 0)
447 int a = trk.getHitLyr(
i);
448 int b = trk.getHitIdx(
i);
449 hitMap.insert(std::make_pair(
b * 1000 +
a,
i > 0 ? itrack : -itrack));
453 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
454 auto &trk =
tracks[itrack];
455 auto phi1 = trk.momPhi();
456 auto ctheta1 = ctheta[itrack];
458 std::map<int, int> sharingMap;
459 for (
int i = 0;
i < trk.nTotalHits(); ++
i) {
460 if (trk.getHitIdx(
i) < 0)
462 int a = trk.getHitLyr(
i);
463 int b = trk.getHitIdx(
i);
464 auto range = hitMap.equal_range(
b * 1000 +
a);
465 for (
auto it =
range.first; it !=
range.second; ++it) {
466 if (
std::abs(it->second) >= (
int)itrack)
468 if (
i == 0 && it->second < 0)
474 for (
const auto &elem : sharingMap) {
475 auto &track2 =
tracks[elem.first];
478 auto dctheta =
std::abs(ctheta[elem.first] - ctheta1);
486 if (elem.second >=
std::min(trk.nFoundHits(), track2.nFoundHits()) *
fraction) {
487 if (trk.score() > track2.score())
488 track2.setDuplicateValue(
true);
490 trk.setDuplicateValue(
true);
501 const float drth_central,
502 const float drth_obarrel,
503 const float drth_forward) {
506 std::vector<float> ctheta(
ntracks);
507 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
508 auto &trk =
tracks[itrack];
509 ctheta[itrack] = 1.f /
std::tan(trk.theta());
512 float phi1, invpt1, dctheta, ctheta1, dphi, dr2;
513 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
514 auto &trk =
tracks[itrack];
516 invpt1 = trk.invpT();
517 ctheta1 = ctheta[itrack];
518 for (
auto jtrack = itrack + 1; jtrack <
ntracks; jtrack++) {
519 auto &track2 =
tracks[jtrack];
520 if (trk.label() == track2.label())
523 dctheta =
std::abs(ctheta[jtrack] - ctheta1);
533 float maxdRSquared = drth_central * drth_central;
535 maxdRSquared = drth_forward * drth_forward;
537 maxdRSquared = drth_obarrel * drth_obarrel;
538 dr2 = dphi * dphi + dctheta * dctheta;
539 if (dr2 < maxdRSquared) {
541 if (trk.score() > track2.score())
542 track2.setDuplicateValue(
true);
544 trk.setDuplicateValue(
true);
551 auto sharedCount = 0;
552 auto sharedFirst = 0;
553 const auto minFoundHits =
std::min(trk.nFoundHits(), track2.nFoundHits());
555 for (
int i = 0;
i < trk.nTotalHits(); ++
i) {
556 if (trk.getHitIdx(
i) < 0)
558 const int a = trk.getHitLyr(
i);
559 const int b = trk.getHitIdx(
i);
560 for (
int j = 0;
j < track2.nTotalHits(); ++
j) {
561 if (track2.getHitIdx(
j) < 0)
563 const int c = track2.getHitLyr(
j);
564 const int d = track2.getHitIdx(
j);
567 if (
a ==
c &&
b ==
d)
569 if (
j == 0 &&
i == 0 &&
a ==
c &&
b ==
d)
572 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction))
575 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction))
580 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction)) {
581 if (trk.score() > track2.score())
582 track2.setDuplicateValue(
true);
584 trk.setDuplicateValue(
true);
600 std::cout <<
" find_and_remove_duplicates: input track size " <<
tracks.size() << std::endl;
616 std::cout <<
" find_and_remove_duplicates: output track size " <<
tracks.size() << std::endl;
617 for (
auto const &tk :
tracks) {
618 std::cout << tk.parameters() << std::endl;
void find_and_remove_duplicates(TrackVec &tracks, const IterationConfig &itconf)
int getHitIdx(int posHitIdx) const
float d0BeamSpot(const float x_bs, const float y_bs, bool linearize=false) const
float squashPhiMinimal(float phi)
int getHitLyr(int posHitIdx) const
void cmssw_Map_TrackHitIndices(const EventOfHits &eoh, TrackVec &seeds)
void find_duplicates(TrackVec &tracks)
I_pair from_R_rdr_to_N_bins(R r, R dr) const
constexpr float c_dpt_common
void cmssw_LoadHits_End(EventOfHits &eoh)
void find_duplicates_sharedhits_pixelseed(TrackVec &tracks, const float fraction, const float drth_central, const float drth_obarrel, const float drth_forward)
C_pair get_content(B_pair n_bin) const
static constexpr int kMaxSeedHits
I next_N_bin(I bin) const
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 find_duplicates_sharedhits(TrackVec &tracks, const float fraction)
void remove_duplicates(TrackVec &tracks)
constexpr float c_etamax_brl
void cmssw_ReMap_TrackHitIndices(const EventOfHits &eoh, TrackVec &out_tracks)
bool m_requires_dupclean_tight
def unique(seq, keepstr=True)
void register_entry_safe(typename A1::real_t r1, typename A2::real_t r2)
Tan< T >::type tan(const T &t)
void loadDeads(EventOfHits &eoh, const std::vector< DeadVec > &deadvectors)
Abs< T >::type abs(const T &t)
void addHitIdx(int hitIdx, int hitLyr, float chi2)
void begin_registration(C n_items)
std::vector< Track > TrackVec
static constexpr float d0
auto const & tracks
cannot be loose
constexpr float track1GeVradius
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
TrackAlgorithm
track algorithm; copy from TrackBase.h to keep in standalone builds
const bool useHitsForDuplicates
I next_N_bin(I bin) const
void suckInDeads(int layer, const DeadVec &deadv)
Power< A, B >::type pow(const A &a, const B &b)
bool m_requires_quality_filter
int clean_cms_seedtracks_iter(TrackVec *seed_ptr, const IterationConfig &itrcfg, const BeamSpot &bspot)
const float minFracHitsShared