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));
99 const float dzmax2_inv_bh = 1.f / (dzmax_bh * dzmax_bh);
100 const float drmax2_inv_bh = 1.f / (drmax_bh * drmax_bh);
101 const float dzmax2_inv_eh = 1.f / (dzmax_eh * dzmax_eh);
102 const float drmax2_inv_eh = 1.f / (drmax_eh * drmax_eh);
103 const float dzmax2_inv_bl = 1.f / (dzmax_bl * dzmax_bl);
104 const float drmax2_inv_bl = 1.f / (drmax_bl * drmax_bl);
105 const float dzmax2_inv_el = 1.f / (dzmax_el * dzmax_el);
106 const float drmax2_inv_el = 1.f / (drmax_el * drmax_el);
110 const bool merge_hits =
true;
112 if (seed_ptr ==
nullptr)
116 const int ns =
seeds.size();
118 std::cout <<
"before seed cleaning " <<
seeds.size() << std::endl;
121 cleanSeedTracks.reserve(ns);
122 std::vector<bool> writetrack(ns,
true);
126 std::vector<int>
nHits(ns);
127 std::vector<int>
charge(ns);
128 std::vector<float> oldPhi(ns);
129 std::vector<float> pos2(ns);
130 std::vector<float>
eta(ns);
131 std::vector<float> ctheta(ns);
132 std::vector<float> invptq(ns);
133 std::vector<float>
pt(ns);
134 std::vector<float>
x(ns);
135 std::vector<float> y(ns);
136 std::vector<float> z(ns);
137 std::vector<float>
d0(ns);
146 for (
int ts = 0; ts < ns; ts++) {
167 for (
int sorted_ts = 0; sorted_ts < ns; sorted_ts++) {
168 int ts = phi_eta_binnor.
m_ranks[sorted_ts];
170 if (not writetrack[ts])
173 const float oldPhi1 = oldPhi[ts];
174 const float pos2_first = pos2[ts];
176 const float pt1 =
pt[ts];
177 const float invptq_first = invptq[ts];
180 int n_ovlp_hits_added = 0;
185 for (
auto i_phi = phi_rng.begin; i_phi != phi_rng.end; i_phi = ax_phi.
next_N_bin(i_phi)) {
186 for (
auto i_eta = eta_rng.begin; i_eta != eta_rng.end; i_eta = ax_eta.
next_N_bin(i_eta)) {
187 const auto cbin = phi_eta_binnor.
get_content(i_phi, i_eta);
188 for (
auto i = cbin.first;
i < cbin.end(); ++
i) {
189 int tss = phi_eta_binnor.
m_ranks[
i];
191 if (not writetrack[ts])
193 if (not writetrack[tss])
198 const float pt2 =
pt[tss];
206 if (thisDPt > dpt_common *
pt1)
212 const float oldPhi2 = oldPhi[tss];
214 const float pos2_second = pos2[tss];
215 const float thisDXYSign05 = pos2_second > pos2_first ? -0.5f : 0.5f;
219 const float invptq_second = invptq[tss];
221 const float newPhi1 = oldPhi1 - thisDXY * invR1GeV * invptq_first;
222 const float newPhi2 = oldPhi2 + thisDXY * invR1GeV * invptq_second;
226 const float dr2 = deta2 + dphi * dphi;
228 const float thisDZ = z[ts] - z[tss] - thisDXY * (ctheta[ts] + ctheta[tss]);
229 const float dz2 = thisDZ * thisDZ;
233 bool overlapping =
false;
235 if (
pt1 > ptmin_hpt) {
236 if (dz2 * dzmax2_inv_bh + dr2 * drmax2_inv_bh < 1.0
f)
239 if (dz2 * dzmax2_inv_bl + dr2 * drmax2_inv_bl < 1.0
f)
243 if (
pt1 > ptmin_hpt) {
244 if (dz2 * dzmax2_inv_eh + dr2 * drmax2_inv_eh < 1.0
f)
247 if (dz2 * dzmax2_inv_el + dr2 * drmax2_inv_el < 1.0
f)
256 if (
d0[tss] >
d0[ts])
257 writetrack[tss] =
false;
259 writetrack[ts] =
false;
270 float fakeChi2 = 0.0;
292 if (n_ovlp_hits_added > 0)
299 if (writetrack[ts]) {
300 cleanSeedTracks.emplace_back(
seeds[ts]);
304 seeds.swap(cleanSeedTracks);
308 const int ns2 =
seeds.size();
309 printf(
"Number of CMS seeds before %d --> after %d cleaning\n", ns, ns2);
311 for (
int it = 0; it < ns2; it++) {
313 printf(
" %3i q=%+i pT=%7.3f eta=% 7.3f nHits=%i label=% i\n",
337 float eta1, phi1,
pt1, deta, dphi, dr2;
342 for (
auto itrack = 0
U; itrack <
ntracks - 1; itrack++) {
349 phi1 =
track.momPhi();
351 for (
auto jtrack = itrack + 1; jtrack <
ntracks; jtrack++) {
352 auto &track2 =
tracks[jtrack];
353 if (
track.label() == track2.label())
355 if (
track.algoint() != track2.algoint())
369 maxdRSquared *= 16.0f;
371 maxdRSquared *= 9.0f;
372 dr2 = dphi * dphi + deta * deta;
373 if (dr2 < maxdRSquared) {
375 if (
track.score() > track2.score())
376 track2.setDuplicateValue(
true);
378 track.setDuplicateValue(
true);
383 if (track2.pT() == 0)
388 float numHitsShared = 0;
389 for (
int ihit2 = 0; ihit2 < track2.nTotalHits(); ihit2++) {
390 const int hitidx2 = track2.getHitIdx(ihit2);
391 const int hitlyr2 = track2.getHitLyr(ihit2);
393 auto const it = std::find_if(
track.beginHitsOnTrack(),
394 track.endHitsOnTrack(),
395 [&hitidx2, &hitlyr2](
const HitOnTrack &element) {
396 return (element.index == hitidx2 && element.layer == hitlyr2);
398 if (it !=
track.endHitsOnTrack())
403 float fracHitsShared = numHitsShared /
std::min(
track.nFoundHits(), track2.nFoundHits());
409 if (
track.score() > track2.score())
410 track2.setDuplicateValue(
true);
412 track.setDuplicateValue(
true);
431 std::vector<float> ctheta(
ntracks);
432 std::multimap<int, int> hitMap;
434 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
435 auto &trk =
tracks[itrack];
436 ctheta[itrack] = 1.f /
std::tan(trk.theta());
437 for (
int i = 0;
i < trk.nTotalHits(); ++
i) {
438 if (trk.getHitIdx(
i) < 0)
440 int a = trk.getHitLyr(
i);
441 int b = trk.getHitIdx(
i);
442 hitMap.insert(std::make_pair(
b * 1000 +
a,
i > 0 ? itrack : -itrack));
446 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
447 auto &trk =
tracks[itrack];
448 auto phi1 = trk.momPhi();
449 auto ctheta1 = ctheta[itrack];
451 std::map<int, int> sharingMap;
452 for (
int i = 0;
i < trk.nTotalHits(); ++
i) {
453 if (trk.getHitIdx(
i) < 0)
455 int a = trk.getHitLyr(
i);
456 int b = trk.getHitIdx(
i);
457 auto range = hitMap.equal_range(
b * 1000 +
a);
458 for (
auto it =
range.first; it !=
range.second; ++it) {
459 if (
std::abs(it->second) >= (
int)itrack)
461 if (
i == 0 && it->second < 0)
467 for (
const auto &elem : sharingMap) {
468 auto &track2 =
tracks[elem.first];
471 auto dctheta =
std::abs(ctheta[elem.first] - ctheta1);
479 if (elem.second >=
std::min(trk.nFoundHits(), track2.nFoundHits()) *
fraction) {
480 if (trk.score() > track2.score())
481 track2.setDuplicateValue(
true);
483 trk.setDuplicateValue(
true);
494 const float drth_central,
495 const float drth_obarrel,
496 const float drth_forward) {
499 std::vector<float> ctheta(
ntracks);
500 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
501 auto &trk =
tracks[itrack];
502 ctheta[itrack] = 1.f /
std::tan(trk.theta());
505 float phi1, invpt1, dctheta, ctheta1, dphi, dr2;
506 for (
auto itrack = 0
U; itrack <
ntracks; itrack++) {
507 auto &trk =
tracks[itrack];
509 invpt1 = trk.invpT();
510 ctheta1 = ctheta[itrack];
511 for (
auto jtrack = itrack + 1; jtrack <
ntracks; jtrack++) {
512 auto &track2 =
tracks[jtrack];
513 if (trk.label() == track2.label())
516 dctheta =
std::abs(ctheta[jtrack] - ctheta1);
526 float maxdRSquared = drth_central * drth_central;
528 maxdRSquared = drth_forward * drth_forward;
530 maxdRSquared = drth_obarrel * drth_obarrel;
531 dr2 = dphi * dphi + dctheta * dctheta;
532 if (dr2 < maxdRSquared) {
534 if (trk.score() > track2.score())
535 track2.setDuplicateValue(
true);
537 trk.setDuplicateValue(
true);
544 auto sharedCount = 0;
545 auto sharedFirst = 0;
546 const auto minFoundHits =
std::min(trk.nFoundHits(), track2.nFoundHits());
548 for (
int i = 0;
i < trk.nTotalHits(); ++
i) {
549 if (trk.getHitIdx(
i) < 0)
551 const int a = trk.getHitLyr(
i);
552 const int b = trk.getHitIdx(
i);
553 for (
int j = 0;
j < track2.nTotalHits(); ++
j) {
554 if (track2.getHitIdx(
j) < 0)
556 const int c = track2.getHitLyr(
j);
557 const int d = track2.getHitIdx(
j);
560 if (
a ==
c &&
b ==
d)
562 if (
j == 0 &&
i == 0 &&
a ==
c &&
b ==
d)
565 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction))
568 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction))
573 if ((sharedCount - sharedFirst) >= ((minFoundHits - sharedFirst) *
fraction)) {
574 if (trk.score() > track2.score())
575 track2.setDuplicateValue(
true);
577 trk.setDuplicateValue(
true);
593 std::cout <<
" find_and_remove_duplicates: input track size " <<
tracks.size() << std::endl;
609 std::cout <<
" find_and_remove_duplicates: output track size " <<
tracks.size() << std::endl;
610 for (
auto const &tk :
tracks) {
611 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