14 #if defined(MKFIT_STANDALONE) 18 #ifdef RNT_DUMP_MkF_SelHitIdcs 20 #include "RecoTracker/MkFitCore/standalone/RntDumper/MkFinder_selectHitIndices.icc" 23 #include "vdt/atan2.h" 35 const std::vector<bool> *ihm,
69 #ifdef RNT_DUMP_MkF_SelHitIdcs 79 L.is_barrel() ? LI.
rin() : LI.
zmin(),
84 *rnt_shi.f = *rnt_shi.h;
89 #ifdef RNT_DUMP_MkF_SelHitIdcs 105 const int iI = inputProp ?
iP :
iC;
107 for (
int i = beg, imp = 0;
i < end; ++
i, ++imp) {
113 const std::vector<Track> &
tracks,
const std::vector<int> &idxs,
int beg,
int end,
bool inputProp,
int mp_offset) {
119 const int iI = inputProp ?
iP :
iC;
121 for (
int i = beg, imp = mp_offset;
i < end; ++
i, ++imp) {
136 const int iI = inputProp ?
iP :
iC;
138 for (
int i = beg, imp = 0;
i < end; ++
i, ++imp) {
151 const std::vector<UpdateIndices> &idxs,
160 const int iI = inputProp ?
iP :
iC;
162 for (
int i = beg, imp = 0;
i < end; ++
i, ++imp) {
182 const std::vector<UpdateIndices> &idxs,
187 for (
int i = beg, imp = 0;
i < end; ++
i, ++imp) {
195 const std::vector<std::pair<int, IdxChi2List>> &idxs,
204 const int iI = inputProp ?
iP :
iC;
206 for (
int i = beg, imp = 0;
i < end; ++
i, ++imp) {
221 const int iO = outputProp ?
iP :
iC;
223 for (
int i = beg, imp = 0;
i < end; ++
i, ++imp) {
229 std::vector<Track> &
tracks,
const std::vector<int> &idxs,
int beg,
int end,
bool outputProp)
const {
233 const int iO = outputProp ?
iP :
iC;
235 for (
int i = beg, imp = 0;
i < end; ++
i, ++imp) {
242 for (
int itrack = 0; itrack < N_proc; ++itrack) {
245 unsigned int mid =
hit.detIDinLayer();
247 norm.At(itrack, 0, 0) = mi.
zdir[0];
248 norm.At(itrack, 1, 0) = mi.
zdir[1];
249 norm.At(itrack, 2, 0) = mi.
zdir[2];
250 dir.At(itrack, 0, 0) = mi.
xdir[0];
251 dir.At(itrack, 1, 0) = mi.
xdir[1];
252 dir.At(itrack, 2, 0) = mi.
xdir[2];
263 const float invpt,
const float theta,
float &min_dq,
float &max_dq,
float &min_dphi,
float &max_dphi) {
264 float max_invpt =
std::min(invpt, 10.0
f);
266 enum SelWinParameters_e { dp_sf = 0, dp_0, dp_1, dp_2, dq_sf, dq_0, dq_1, dq_2 };
271 float this_dq =
v[dq_sf] * (
v[dq_0] * max_invpt +
v[dq_1] *
theta +
v[dq_2]);
275 max_dq = 2.0f * min_dq;
279 float this_dphi =
v[dp_sf] * (
v[dp_0] * max_invpt +
v[dp_1] *
theta +
v[dp_2]);
281 if (this_dphi > min_dphi) {
282 min_dphi = this_dphi;
283 max_dphi = 2.0f * min_dphi;
295 const float invpt =
m_Par[ipar].At(itrk, 3, 0);
298 float max_invpt =
std::min(invpt, 10.0
f);
300 enum SelWinParameters_e { c2_sf = 8, c2_0, c2_1, c2_2 };
304 float this_c2 =
v[c2_sf] * (
v[c2_0] * max_invpt +
v[c2_1] *
theta +
v[c2_2]);
306 if (this_c2 > minChi2Cut)
326 const float nSigmaR = 3;
328 dprintf(
"LayerOfHits::SelectHitIndices %s layer=%d N_proc=%d\n",
329 L.is_barrel() ?
"barrel" :
"endcap",
333 float dqv[
NN], dphiv[
NN], qv[
NN], phiv[
NN];
334 bidx_t qb1v[
NN], qb2v[
NN], qbv[
NN], pb1v[
NN], pb2v[
NN];
336 const auto assignbins = [&](
int itrack,
345 dphi = std::clamp(
std::abs(dphi), min_dphi, max_dphi);
346 dq = std::clamp(dq, min_dq, max_dq);
350 dphiv[itrack] = dphi;
353 qbv[itrack] =
L.qBinChecked(
q);
354 qb1v[itrack] =
L.qBinChecked(
q - dq);
355 qb2v[itrack] =
L.qBinChecked(
q + dq) + 1;
356 pb1v[itrack] =
L.phiBinChecked(phi - dphi);
357 pb2v[itrack] =
L.phiMaskApply(
L.phiBin(phi + dphi) + 1);
360 const auto calcdphi2 = [&](
int itrack,
float dphidx,
float dphidy) {
361 return dphidx * dphidx *
m_Err[iI].constAt(itrack, 0, 0) + dphidy * dphidy *
m_Err[iI].constAt(itrack, 1, 1) +
362 2 * dphidx * dphidy *
m_Err[iI].constAt(itrack, 0, 1);
365 const auto calcdphi = [&](
float dphi2,
float min_dphi) {
375 #if !defined(__clang__) 378 for (
int itrack = 0; itrack <
NN; ++itrack) {
381 float min_dq = ILC.
min_dq();
382 float max_dq = ILC.
max_dq();
386 const float invpt =
m_Par[iI].At(itrack, 3, 0);
390 const float x =
m_Par[iI].constAt(itrack, 0, 0);
391 const float y =
m_Par[iI].constAt(itrack, 1, 0);
392 const float r2 =
x *
x + y * y;
393 const float dphidx = -y /
r2, dphidy =
x /
r2;
394 const float dphi2 = calcdphi2(itrack, dphidx, dphidy);
399 const float phi =
getPhi(
x, y);
400 float dphi = calcdphi(dphi2, min_dphi);
402 const float z =
m_Par[iI].constAt(itrack, 2, 0);
404 const float edgeCorr =
std::abs(0.5
f * (
L.layer_info()->rout() -
L.layer_info()->rin()) /
409 assignbins(itrack, z,
dz, phi, dphi, min_dq, max_dq, min_dphi, max_dphi);
419 const float layerD =
std::abs(
L.layer_info()->zmax() -
L.layer_info()->zmin()) * 0.5
f *
422 #if !defined(__clang__) 425 for (
int itrack = 0; itrack <
NN; ++itrack) {
428 float min_dq = ILC.
min_dq();
429 float max_dq = ILC.
max_dq();
433 const float invpt =
m_Par[iI].At(itrack, 3, 0);
437 const float x =
m_Par[iI].constAt(itrack, 0, 0);
438 const float y =
m_Par[iI].constAt(itrack, 1, 0);
439 const float r2 =
x *
x + y * y;
440 const float r2Inv = 1.f /
r2;
441 const float dphidx = -y * r2Inv, dphidy =
x * r2Inv;
442 const float phi =
getPhi(
x, y);
444 calcdphi2(itrack, dphidx, dphidy)
452 float dphi = calcdphi(dphi2, min_dphi);
456 y * y *
m_Err[iI].constAt(itrack, 1, 1) +
457 2 *
x * y *
m_Err[iI].constAt(itrack, 0, 1)) /
459 const float edgeCorr =
std::abs(0.5
f * (
L.layer_info()->zmax() -
L.layer_info()->zmin()) *
463 assignbins(itrack, r, dr, phi, dphi, min_dq, max_dq, min_dphi, max_dphi);
467 #ifdef RNT_DUMP_MkF_SelHitIdcs 468 if (fill_binsearch_only) {
470 for (
auto i : rnt_shi.f_h_idcs) {
471 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[
i]];
490 for (
int itrack = 0; itrack < N_proc; ++itrack) {
502 const bidx_t qb = qbv[itrack];
503 const bidx_t qb1 = qb1v[itrack];
504 const bidx_t qb2 = qb2v[itrack];
505 const bidx_t pb1 = pb1v[itrack];
506 const bidx_t pb2 = pb2v[itrack];
508 const float q = qv[itrack];
509 const float phi = phiv[itrack];
510 const float dphi = dphiv[itrack];
511 const float dq = dqv[itrack];
514 dprintf(
" %2d/%2d: %6.3f %6.3f %6.6f %7.5f %3u %3u %4u %4u\n",
515 L.layer_id(), itrack,
q, phi, dq, dphi,
519 #if defined(DUMPHITWINDOW) && defined(MKFIT_STANDALONE) 520 const auto ngr = [](
float f) {
return isFinite(
f) ?
f : -999.0f; };
527 for (bidx_t qi = qb1; qi != qb2; ++qi) {
528 for (bidx_t
pi = pb1;
pi != pb2;
pi =
L.phiMaskApply(
pi + 1)) {
530 if (qi == qb &&
L.isBinDead(
pi, qi) ==
true) {
531 dprint(
"dead module for track in layer=" <<
L.layer_id() <<
" qb=" << qi <<
" pi=" <<
pi <<
" q=" <<
q 544 auto pbi =
L.phiQBinContent(
pi, qi);
545 for (bcnt_t
hi = pbi.begin();
hi < pbi.end(); ++
hi) {
548 const unsigned int hi_orig =
L.getOriginalHitIndex(
hi);
552 "Yay, denying masked hit on layer %u, hi %u, orig idx %u\n",
L.layer_info()->layer_id(),
hi, hi_orig);
564 dprintf(
" SHI %3u %4u %5u %6.3f %6.3f %6.4f %7.5f %s\n",
566 ddq, ddphi, (ddq < dq && ddphi < dphi) ?
"PASS" :
"FAIL");
569 #if defined(DUMPHITWINDOW) && defined(MKFIT_STANDALONE) 575 int st_isfindable = 0;
576 int st_label = -999999;
583 float st_eta = -999.;
584 float st_phi = -999.;
588 st_label = simtrack.
label();
590 st_pt = simtrack.
pT();
591 st_eta = simtrack.
momEta();
592 st_phi = simtrack.
momPhi();
594 st_charge = simtrack.
charge();
595 st_r = simtrack.
posR();
599 const Hit &thishit =
L.refHit(hi_orig);
618 float hx = thishit.
x();
619 float hy = thishit.
y();
620 float hz = thishit.
z();
622 float hphi = std::atan2(hy, hx);
627 (hx * hx * thishit.
exx() + hy * hy * thishit.
eyy() + 2.0f * hx * hy *
m_msErr.At(itrack, 0, 1)) /
630 float hchi2 = ngr( thisOutChi2[itrack] );
631 float tx =
m_Par[iI].At(itrack, 0, 0);
632 float ty =
m_Par[iI].At(itrack, 1, 0);
633 float tz =
m_Par[iI].At(itrack, 2, 0);
635 float tphi = std::atan2(ty, tx);
641 (tx * tx *
tex *
tex + ty * ty * tey * tey + 2.0
f * tx * ty *
m_Err[iI].At(itrack, 0, 1)) /
644 (ty * ty *
tex *
tex + tx * tx * tey * tey - 2.0
f * tx * ty *
m_Err[iI].At(itrack, 0, 1)) /
645 (tr * tr * tr * tr)) );
647 float ht_dz = hz - tz;
650 static bool first =
true;
654 "evt_id/I:track_algo/I:" 655 "lyr_id/I:lyr_isbrl/I:hit_idx/I:" 656 "trk_cnt/I:trk_idx/I:trk_label/I:" 657 "trk_pt/F:trk_eta/F:trk_mphi/F:trk_chi2/F:" 659 "seed_idx/I:seed_label/I:seed_mcid/I:" 661 "st_isfindable/I:st_prodtype/I:st_label/I:" 662 "st_pt/F:st_eta/F:st_phi/F:" 663 "st_nhits/I:st_charge/I:st_r/F:st_z/F:" 664 "trk_q/F:hit_q/F:dq_trkhit/F:dq_cut/F:trk_phi/F:hit_phi/F:dphi_trkhit/F:dphi_cut/F:" 665 "t_x/F:t_y/F:t_r/F:t_phi/F:t_z/F:" 666 "t_ex/F:t_ey/F:t_er/F:t_ephi/F:t_ez/F:" 667 "h_x/F:h_y/F:h_r/F:h_phi/F:h_z/F:" 668 "h_ex/F:h_ey/F:h_er/F:h_ephi/F:h_ez/F:" 669 "ht_dxy/F:ht_dz/F:ht_dphi/F:" 677 printf(
"HITWINDOWSEL " 681 "%6.3f %6.3f %6.3f %6.3f " 688 "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f " 689 "%6.3f %6.3f %6.3f %6.3f %6.3f " 690 "%6.6f %6.6f %6.6f %6.6f %6.6f " 691 "%6.3f %6.3f %6.3f %6.3f %6.3f " 692 "%6.6f %6.6f %6.6f %6.6f %6.6f " 697 L.layer_id(),
L.is_barrel(), hi_orig,
699 1.0f /
m_Par[iI].At(itrack, 3, 0),
getEta(
m_Par[iI].At(itrack, 5, 0)),
m_Par[iI].At(itrack, 4, 0),
m_Chi2(itrack, 0, 0),
703 st_isfindable, st_prodtype, st_label,
704 st_pt, st_eta, st_phi,
705 st_nhits, st_charge, st_r, st_z,
706 q,
L.hit_q(
hi), ddq, dq, phi,
L.hit_phi(
hi), ddphi, dphi,
707 tx, ty, tr, tphi, tz,
708 tex, tey, ter, tephi, tez,
709 hx, hy, hr, hphi, hz,
710 hex, hey, her, hephi, hez,
711 ht_dxy, ht_dz, ht_dphi,
735 assert(
false &&
"this code has not been used in a while -- see comments in code");
760 dprintf(
"LayerOfHits::SelectHitIndicesV2 %s layer=%d N_proc=%d\n",
761 L.is_barrel() ?
"barrel" :
"endcap",
765 #ifdef RNT_DUMP_MkF_SelHitIdcs 766 rnt_shi.InnerIdcsReset(N_proc);
767 for (
int i = 0;
i < N_proc; ++
i) {
771 }
else if (slfh.is_set()) {
779 constexpr
int NEW_MAX_HIT = 6;
780 constexpr
float DDPHI_PRESEL_FAC = 2.0f;
781 constexpr
float DDQ_PRESEL_FAC = 1.2f;
782 constexpr
float PHI_BIN_EXTRA_FAC = 2.75f;
783 constexpr
float Q_BIN_EXTRA_FAC = 1.6f;
785 namespace mp = mini_propagators;
788 mp::InitialStatePlex isp;
789 mp::StatePlex sp1, sp2;
800 void prop_to_limits(
const LayerInfo &li) {
826 phi_c = 0.5f * (pmax +
pmin);
827 for (
int ii = 0;
ii < n_proc; ++
ii) {
839 return x *
x *
err.ReduceFixedIJ(0, 0) + y * y *
err.ReduceFixedIJ(1, 1) +
840 2.0f *
x * y *
err.ReduceFixedIJ(0, 1);
844 MPlexQF r2_c = isp.x * isp.x + isp.y * isp.y;
846 MPlexQF dphidx_c = -isp.y * r2inv_c;
847 MPlexQF dphidy_c = isp.x * r2inv_c;
848 dphi_track = 3.0f * calc_err_xy(dphidx_c, dphidy_c).abs().sqrt();
854 dq_track = 3.0f *
err.ReduceFixedIJ(2, 2).abs().sqrt();
858 dq_track = 3.0f * (r2inv_c * calc_err_xy(isp.x, isp.y).abs()).
sqrt();
861 for (
int i = 0;
i <
p1.kTotSize; ++
i) {
877 B.prop_to_limits(LI);
878 B.find_bin_ranges(LI,
L,
m_Err[iI]);
880 for (
int i = 0;
i < N_proc; ++
i) {
900 #ifdef RNT_DUMP_MkF_SelHitIdcs 901 for (
auto i : rnt_shi.f_h_idcs) {
902 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[
i]];
906 0.5f * (
B.q2[
i] -
B.q1[
i]),
914 ci.
ps_min = statep2propstate(
B.sp1,
i);
915 ci.
ps_max = statep2propstate(
B.sp2,
i);
921 unsigned int hit_index;
923 auto pqe_cmp = [](
const PQE &
a,
const PQE &
b) {
return a.score <
b.score; };
924 std::priority_queue<PQE, std::vector<PQE>, decltype(pqe_cmp)> pqueue(pqe_cmp);
929 for (
int itrack = 0; itrack < N_proc; ++itrack) {
941 const bidx_t qb =
B.q0[itrack];
942 const bidx_t qb1 =
B.q1[itrack];
943 const bidx_t qb2 =
B.q2[itrack];
944 const bidx_t pb1 =
B.p1[itrack];
945 const bidx_t pb2 =
B.p2[itrack];
948 dprintf(
" %2d/%2d: %6.3f %6.3f %6.6f %7.5f %3u %3u %4u %4u\n",
949 L.layer_id(), itrack, qv[itrack], phi[itrack], dqv[itrack], dphiv[itrack],
953 mp::InitialState mp_is(
m_Par[iI],
m_Chg, itrack);
956 for (bidx_t qi = qb1; qi != qb2; ++qi) {
957 for (bidx_t
pi = pb1;
pi != pb2;
pi =
L.phiMaskApply(
pi + 1)) {
959 if (qi == qb &&
L.isBinDead(
pi, qi) ==
true) {
960 dprint(
"dead module for track in layer=" <<
L.layer_id() <<
" qb=" << qi <<
" pi=" <<
pi <<
" q=" <<
q 971 auto pbi =
L.phiQBinContent(
pi, qi);
972 for (bcnt_t
hi = pbi.begin();
hi < pbi.end(); ++
hi) {
975 const unsigned int hi_orig =
L.getOriginalHitIndex(
hi);
979 "Yay, denying masked hit on layer %u, hi %u, orig idx %u\n",
L.layer_info()->layer_id(),
hi, hi_orig);
986 float new_q, new_phi, new_ddphi, new_ddq;
990 prop_fail = mp_is.propagate_to_r(
mp::PA_Exact,
L.hit_qbar(
hi), mp_s,
true);
993 prop_fail = mp_is.propagate_to_z(
mp::PA_Exact,
L.hit_qbar(
hi), mp_s,
true);
997 new_phi = vdt::fast_atan2f(mp_s.y, mp_s.x);
1001 bool dqdphi_presel = new_ddq <
B.dq_track[itrack] + DDQ_PRESEL_FAC *
L.hit_q_half_length(
hi) &&
1002 new_ddphi <
B.dphi_track[itrack] + DDPHI_PRESEL_FAC * 0.0123f;
1005 dprintf(
" SHI %3u %4u %5u %6.3f %6.3f %6.4f %7.5f PROP-%s %s\n",
1007 ddq, ddphi, prop_fail ?
"FAIL" :
"OK", dqdphi_presel ?
"PASS" :
"REJECT");
1010 if (prop_fail || !dqdphi_presel)
1012 if (pqueue_size < NEW_MAX_HIT) {
1013 pqueue.push({new_ddphi, hi_orig});
1015 }
else if (new_ddphi < pqueue.top().score) {
1017 pqueue.push({new_ddphi, hi_orig});
1023 dprintf(
" PQUEUE (%d)", pqueue_size);
1026 while (pqueue_size) {
1028 m_XHitArr.At(itrack, pqueue_size, 0) = pqueue.top().hit_index;
1029 dprintf(
" %d: %f %d", pqueue_size, pqueue.top().score, pqueue.top().hit_index);
1051 for (
int it = 0; it <
NN; ++it) {
1062 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1068 for (
int itrack = 0; itrack < N_proc; ++itrack) {
1070 mhp.addInputAt(itrack, layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)));
1094 for (
int itrack = 0; itrack < N_proc; ++itrack) {
1100 bestHit[itrack] =
m_XHitArr.At(itrack, hit_cnt, 0);
1107 for (
int itrack = 0; itrack < N_proc; ++itrack) {
1110 m_msErr.setDiagonal3x3(itrack, 666);
1125 if (bestHit[itrack] >= 0) {
1126 const Hit &
hit = layer_of_hits.
refHit(bestHit[itrack]);
1129 dprint(
"ADD BEST HIT FOR TRACK #" 1130 << itrack << std::endl
1131 <<
"prop x=" <<
m_Par[
iP].constAt(itrack, 0, 0) <<
" y=" <<
m_Par[
iP].constAt(itrack, 1, 0) << std::endl
1132 <<
"copy in hit #" << bestHit[itrack] <<
" x=" <<
hit.position()[0] <<
" y=" <<
hit.position()[1]);
1152 m_msErr.setDiagonal3x3(itrack, 666);
1165 dprint(
"update parameters");
1179 dprint(
"m_Par[iP](0,0,0)=" <<
m_Par[
iP](0, 0, 0) <<
" m_Par[iC](0,0,0)=" <<
m_Par[
iC](0, 0, 0));
1189 const float res =
std::abs(msPar.constAt(itrack, 2, 0) - pPar.constAt(itrack, 2, 0));
1190 const float hitHL =
sqrt(msErr.constAt(itrack, 2, 2) * 3.f);
1191 const float qErr =
sqrt(pErr.constAt(itrack, 2, 2));
1192 dprint(
"qCompat " << hitHL <<
" + " << 3.
f * qErr <<
" vs " <<
res);
1195 const float res[2]{msPar.constAt(itrack, 0, 0) - pPar.constAt(itrack, 0, 0),
1196 msPar.constAt(itrack, 1, 0) - pPar.constAt(itrack, 1, 0)};
1197 const float hitT2 = msErr.constAt(itrack, 0, 0) + msErr.constAt(itrack, 1, 1);
1198 const float hitT2inv = 1.f / hitT2;
1199 const float proj[3] = {msErr.constAt(itrack, 0, 0) * hitT2inv,
1200 msErr.constAt(itrack, 0, 1) * hitT2inv,
1201 msErr.constAt(itrack, 1, 1) * hitT2inv};
1203 sqrt(
std::abs(pErr.constAt(itrack, 0, 0) *
proj[0] + 2.f * pErr.constAt(itrack, 0, 1) *
proj[1] +
1204 pErr.constAt(itrack, 1, 1) *
proj[2]));
1205 const float resProj =
1207 dprint(
"qCompat " <<
sqrt(hitT2 * 3.
f) <<
" + " << 3.
f * qErr <<
" vs " << resProj);
1218 int itrack,
bool isBarrel,
unsigned int pcm,
unsigned int pcmMin,
const MPlexLV &pPar,
const MPlexHS &msErr) {
1225 const float hitT2 = msErr.constAt(itrack, 0, 0) + msErr.constAt(itrack, 1, 1);
1226 const float hitT2inv = 1.f / hitT2;
1227 const float proj[3] = {msErr.constAt(itrack, 0, 0) * hitT2inv,
1228 msErr.constAt(itrack, 0, 1) * hitT2inv,
1229 msErr.constAt(itrack, 1, 1) * hitT2inv};
1230 const bool detXY_OK =
1232 const float cosP =
cos(pPar.constAt(itrack, 4, 0));
1233 const float sinP =
sin(pPar.constAt(itrack, 4, 0));
1234 const float sinT =
std::abs(
sin(pPar.constAt(itrack, 5, 0)));
1237 2.
f * cosP * sinP *
proj[1]))
1244 const float qCorr = pcm * qSF;
1245 dprint(
"pcm " << pcm <<
" * " << qSF <<
" = " << qCorr <<
" vs " << pcmMin);
1246 return qCorr > pcmMin;
1254 std::vector<std::vector<TrackCand>> &tmp_candidates,
1265 for (
int it = 0; it <
NN; ++it) {
1275 int nHitsAdded[
NN]{};
1276 bool isTooLargeCluster[
NN]{
false};
1278 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1284 for (
int itrack = 0; itrack < N_proc; ++itrack) {
1287 mhp.addInputAt(itrack,
hit);
1288 charge_pcm[itrack] =
hit.chargePerCM();
1336 bool oneCandPassCut =
false;
1337 for (
int itrack = 0; itrack < N_proc; ++itrack) {
1343 if (
chi2 < max_c2) {
1344 bool isCompatible =
true;
1356 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1358 isTooLargeCluster[itrack] =
true;
1359 isCompatible =
false;
1364 oneCandPassCut =
true;
1371 if (oneCandPassCut) {
1386 dprint(
"update parameters" << std::endl
1387 <<
"propagated track parameters x=" <<
m_Par[
iP].constAt(0, 0, 0)
1388 <<
" y=" <<
m_Par[
iP].constAt(0, 1, 0) << std::endl
1389 <<
" hit position x=" <<
m_msPar.constAt(0, 0, 0)
1390 <<
" y=" <<
m_msPar.constAt(0, 1, 0) << std::endl
1391 <<
" updated track parameters x=" <<
m_Par[
iC].constAt(0, 0, 0)
1392 <<
" y=" <<
m_Par[
iC].constAt(0, 1, 0));
1396 for (
int itrack = 0; itrack < N_proc; ++itrack) {
1402 if (
chi2 < max_c2) {
1403 bool isCompatible =
true;
1415 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1417 isCompatible =
false;
1421 bool hitExists =
false;
1436 nHitsAdded[itrack]++;
1437 dprint(
"chi2 cut passed, creating new candidate");
1441 const int hit_idx =
m_XHitArr.At(itrack, hit_cnt, 0);
1445 newcand.
setCharge(tmpChg(itrack, 0, 0));
1454 if (
chi2 < max_c2) {
1456 ccand[
m_CandIdx(itrack, 0, 0)].considerHitForOverlap(
1464 tmp_candidates[
m_SeedIdx(itrack, 0, 0) -
offset].emplace_back(newcand);
1475 for (
int itrack = 0; itrack < N_proc; ++itrack) {
1492 else if (
m_XWsrResult[itrack].m_in_gap ==
true && nHitsAdded[itrack] == 0) {
1496 else if (isTooLargeCluster[itrack] ==
true && nHitsAdded[itrack] == 0) {
1511 tmp_candidates[
m_SeedIdx(itrack, 0, 0) -
offset].emplace_back(newcand);
1532 for (
int it = 0; it <
NN; ++it) {
1540 dprintf(
"FindCandidatesCloneEngine max hits to process=%d\n",
maxSize);
1542 int nHitsAdded[
NN]{};
1543 bool isTooLargeCluster[
NN]{
false};
1545 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1551 for (
int itrack = 0; itrack < N_proc; ++itrack) {
1554 mhp.addInputAt(itrack,
hit);
1555 charge_pcm[itrack] =
hit.chargePerCM();
1598 for (
int itrack = 0; itrack < N_proc; ++itrack) {
1610 dprint(
"chi2=" <<
chi2 <<
" for trkIdx=" << itrack <<
" hitIdx=" <<
m_XHitArr.At(itrack, hit_cnt, 0));
1611 if (
chi2 < max_c2) {
1612 bool isCompatible =
true;
1625 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1627 isTooLargeCluster[itrack] =
true;
1628 isCompatible =
false;
1634 bool hitExists =
false;
1649 nHitsAdded[itrack]++;
1650 const int hit_idx =
m_XHitArr.At(itrack, hit_cnt, 0);
1654 if (
chi2 < max_c2) {
1655 ccand[
m_CandIdx(itrack, 0, 0)].considerHitForOverlap(
1661 tmpList.
hitIdx = hit_idx;
1673 dprint(
" adding hit with hit_cnt=" << hit_cnt <<
" for trkIdx=" << tmpList.
trkIdx 1674 <<
" orig Seed=" <<
m_Label(itrack, 0, 0));
1683 for (
int itrack = 0; itrack < N_proc; ++itrack) {
1702 else if (
m_XWsrResult[itrack].m_in_gap ==
true && nHitsAdded[itrack] == 0) {
1706 else if (isTooLargeCluster[itrack] ==
true && nHitsAdded[itrack] == 0) {
1719 tmpList.
hitIdx = fake_hit_idx;
1731 dprint(
"adding invalid hit " << fake_hit_idx);
1809 const int iO = outputProp ?
iP :
iC;
1811 for (
int i = 0;
i < N_proc; ++
i) {
1815 m_Err[iO].copyOut(
i,
cand.errors_nc().Array());
1816 m_Par[iO].copyOut(
i,
cand.parameters_nc().Array());
1819 dprint((outputProp ?
"propagated" :
"updated")
1820 <<
" track parameters x=" <<
cand.parameters()[0] <<
" y=" <<
cand.parameters()[1]
1821 <<
" z=" <<
cand.parameters()[2] <<
" pt=" << 1. /
cand.parameters()[3] <<
" posEta=" <<
cand.posEta());
1836 for (
int i = beg;
i < end; ++
i, ++itrack) {
1863 for (
int i = beg;
i < end; ++
i, ++itrack) {
1889 const int iO = outputProp ?
iP :
iC;
1892 for (
int i = beg;
i < end; ++
i, ++itrack) {
1910 const int iO = outputProp ?
iP :
iC;
1913 for (
int i = beg;
i < end; ++
i, ++itrack) {
1928 #if defined(DEBUG_BACKWARD_FIT) || defined(DEBUG_BACKWARD_FIT_BH) 1945 float tmp_err[6] = {666, 0, 666, 0, 0, 666};
1949 const int layer = lp_iter->m_layer;
1955 for (
int i = 0;
i < N_proc; ++
i) {
2013 for (
int n = 0;
n < N_proc; ++
n) {
2020 #ifdef DEBUG_BACKWARD_FIT_BH 2022 for (
int i = 0;
i < N_proc; ++
i) {
2031 "CHIHIT %3d %10g %10g %10g %10g %10g %11.5g %11.5g %11.5g %10g %10g %10g %10g %11.5g %11.5g %11.5g %10g " 2032 "%10g %10g %10g %10g %11.5g %11.5g\n",
2046 e2s(
m_Err[ti].At(
i, 0, 0)),
2047 e2s(
m_Err[ti].At(
i, 1, 1)),
2048 e2s(
m_Err[ti].At(
i, 2, 2)),
2049 1.0f /
m_Par[ti].At(
i, 3, 0),
2053 std::atan2(
m_Par[ti].At(
i, 1, 0),
m_Par[ti].At(
i, 0, 0)),
2073 printf(
"Parameters:\n");
2074 for (
int i = 0;
i < 6; ++
i) {
2075 printf(
" %12.4g",
m_Par[corp].constAt(mslot,
i, 0));
2077 printf(
"\nError matrix\n");
2078 for (
int i = 0;
i < 6; ++
i) {
2079 for (
int j = 0;
j < 6; ++
j) {
2080 printf(
" %12.4g",
m_Err[corp].constAt(mslot,
i,
j));
2101 float tmp_err[6] = {666, 0, 666, 0, 0, 666};
2104 #if defined(DEBUG_PROP_UPDATE) 2105 const int DSLOT = 0;
2106 printf(
"bkfit entry, track in slot %d\n", DSLOT);
2111 const int layer = lp_iter.layer();
2116 #if defined(DEBUG_BACKWARD_FIT) 2117 const Hit *last_hit_ptr[
NN];
2120 no_mat_effs.setVal(0);
2123 for (
int i = 0;
i < N_proc; ++
i) {
2143 #ifdef DEBUG_BACKWARD_FIT 2144 last_hit_ptr[
i] = &
hit;
2152 #ifdef DEBUG_BACKWARD_FIT 2153 last_hit_ptr[
i] =
nullptr;
2164 if (done_count == N_proc)
2166 if (here_count == 0)
2201 #if defined(DEBUG_PROP_UPDATE) 2202 printf(
"\nbkfit at layer %d, track in slot %d -- fail=%d, had hit=%d (%g, %g, %g)\n",
2206 1 - no_mat_effs[DSLOT],
2210 printf(
"Propagated:\n");
2212 printf(
"Updated:\n");
2217 for (
int i = 0;
i < N_proc; ++
i) {
2259 #if defined(DEBUG_BACKWARD_FIT) 2262 const char beg_cur_sep =
'/';
2263 for (
int i = 0;
i < N_proc; ++
i) {
2264 if (chiDebug && last_hit_ptr[
i]) {
2267 float chi = tmp_chi2.At(
i, 0, 0);
2268 float chi_prnt = std::isfinite(chi) ? chi : -9;
2270 #if defined(MKFIT_STANDALONE) 2273 dprintf(
"BKF_OVERLAP %d %d %d %d %d %d %d " 2274 "%f%c%f %f %f%c%f %f %f %f %d %d %d %d " 2278 dprintf(
"BKF_OVERLAP %d %d %d %d %d %d " 2279 "%f%c%f %f %f%c%f %f %f %f %d %d %d " 2283 layer,
L.is_stereo(),
L.is_barrel(),
2284 bb.
pT(), beg_cur_sep, 1.0f /
m_Par[ti].At(
i, 3, 0),
2290 std::isnan(chi), std::isfinite(chi), chi > 0,
2291 #if defined(MKFIT_STANDALONE)
void(* m_compute_chi2_foo)(const MPlexLS &, const MPlexLV &, const MPlexQI &, const MPlexHS &, const MPlexHV &, MPlexQF &, MPlexLV &, MPlexQI &, const int, const PropagationFlags &, const bool)
void setOriginIndex(int oi)
float getScoreCand(const track_score_func &score_func, const Track &cand1, bool penalizeTailMissHits=false, bool inFindCandidates=false)
void addHitIdx(int hitIdx, int hitLyr, float chi2)
unsigned int maxClusterSize
void copy_in(const Track &trk, const int mslot, const int tslot)
static constexpr int MPlexHitIdxMax
const SVector6 & parameters() const
MPlex< T, D1, D2, N > hypot(const MPlex< T, D1, D2, N > &a, const MPlex< T, D1, D2, N > &b)
const IterationLayerConfig * m_iteration_layer_config
void chi2OfLoadedHit(int N_proc, const FindingFoos &fnd_foos)
const HitOnTrack * m_HoTArr[NN]
void inputOverlapHits(const LayerOfHits &layer_of_hits, const std::vector< UpdateIndices > &idxs, int beg, int end)
void kalmanOperationEndcap(const int kfOp, const MPlexLS &psErr, const MPlexLV &psPar, const MPlexHS &msErr, const MPlexHV &msPar, MPlexLS &outErr, MPlexLV &outPar, MPlexQF &outChi2, const int N_proc)
void copy_out(Track &trk, const int mslot, const int tslot) const
void packModuleNormDir(const LayerOfHits &layer_of_hits, int hit_cnt, MPlexHV &norm, MPlexHV &dir, int N_proc) const
void outputTracksAndHitIdx(std::vector< Track > &tracks, int beg, int end, bool outputProp) const
void propagateTracksToHitZ(const MPlexHV &par, const int N_proc, const PropagationFlags &pf, const MPlexQI *noMatEffPtr=nullptr)
HitOnTrack m_HoTArrs[NN][Config::nMaxTrkHits]
bin_index_t qBinChecked(float q) const
const Hit * hitArray() const
void inputTracksAndHitIdx(const std::vector< Track > &tracks, int beg, int end, bool inputProp)
void bkFitInputTracks(TrackVec &cands, int beg, int end)
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
Matriplex::Matriplex< float, HH, 1, NN > MPlexHV
Matriplex::Matriplex< unsigned short, 1, 1, NN > MPlexQUH
Sin< T >::type sin(const T &t)
PropagationFlags backward_fit_pflags
void addInput(const T &item)
ProdType prodType() const
void selectHitIndices(const LayerOfHits &layer_of_hits, const int N_proc, bool fill_binsearch_only=false)
void setup(const PropagationConfig &pc, const IterationConfig &ic, const IterationParams &ip, const IterationLayerConfig &ilc, const SteeringParams &sp, const std::vector< bool > *ihm, const Event *ev, int region, bool infwd)
void bkFitPropTracksToPCA(const int N_proc)
SMatrixSym66 & errors_nc()
const IterationConfig * m_iteration_config
void inputTracksAndHits(const std::vector< CombCandidate > &tracks, const LayerOfHits &layer_of_hits, const std::vector< UpdateIndices > &idxs, int beg, int end, bool inputProp)
void add_hit(const int mslot, int index, int layer)
Matriplex::Matriplex< float, LL, 1, NN > MPlexLV
float getEta(float r, float z)
void swap(Association< C > &lhs, Association< C > &rhs)
const float * posArray() const
static unsigned int maxChargePerCM()
static constexpr int kHitStopIdx
const IterationParams * m_iteration_params
void kalmanOperation(const int kfOp, const MPlexLS &psErr, const MPlexLV &psPar, const MPlexHS &msErr, const MPlexHV &msPar, MPlexLS &outErr, MPlexLV &outPar, MPlexQF &outChi2, const int N_proc)
void findCandidates(const LayerOfHits &layer_of_hits, std::vector< std::vector< TrackCand >> &tmp_candidates, const int offset, const int N_proc, const FindingFoos &fnd_foos)
static constexpr int kHitInGapIdx
track_score_func m_track_scorer
constexpr bool usePhiQArrays
const HoTNode * hotsData() const
PropagationFlags finding_inter_layer_pflags
bool isStripQCompatible(int itrack, bool isBarrel, const MPlexLS &pErr, const MPlexLV &pPar, const MPlexHS &msErr, const MPlexHV &msPar)
float getScoreStruct(const track_score_func &score_func, const IdxChi2List &cand1)
const PropagationConfig * m_prop_config
iterator make_iterator(IterationType_e type) const
int num_all_minus_one_hits(const int mslot) const
unsigned int detIDinLayer() const
bin_index_t phiBinChecked(float phi) const
const ModuleInfo & module_info(unsigned int sid) const
void(* m_update_param_foo)(const MPlexLS &, const MPlexLV &, MPlexQI &, const MPlexHS &, const MPlexHV &, MPlexLS &, MPlexLV &, MPlexQI &, const int, const PropagationFlags &, const bool)
const float * errArray() const
constexpr Matriplex::idx_t NN
unsigned int bin_content_t
Cos< T >::type cos(const T &t)
void setup_bkfit(const PropagationConfig &pc, const SteeringParams &sp, const Event *ev)
CombCandidate * combCandidate() const
Tan< T >::type tan(const T &t)
void kalmanPropagateAndUpdatePlane(const MPlexLS &psErr, const MPlexLV &psPar, MPlexQI &Chg, const MPlexHS &msErr, const MPlexHV &msPar, const MPlexHV &plNrm, const MPlexHV &plDir, MPlexLS &outErr, MPlexLV &outPar, MPlexQI &outFailFlag, const int N_proc, const PropagationFlags &propFlags, const bool propToHit)
Abs< T >::type abs(const T &t)
void propagateTracksToHitR(const MPlexHV &par, const int N_proc, const PropagationFlags &pf, const MPlexQI *noMatEffPtr=nullptr)
MPlexQI m_NTailMinusOneHits
void min_max(const MPlex< T, D1, D2, N > &a, const MPlex< T, D1, D2, N > &b, MPlex< T, D1, D2, N > &min, MPlex< T, D1, D2, N > &max)
const HitOnTrack * getHitsOnTrackArray() const
MCHitInfoVec simHitsInfo_
PropagationFlags pca_prop_pflags
bool finding_requires_propagation_to_hit_pos
constexpr float nSigmaPhi
void begin_layer(const LayerOfHits &layer_of_hits)
void kalmanPropagateAndComputeChi2Plane(const MPlexLS &psErr, const MPlexLV &psPar, const MPlexQI &inChg, const MPlexHS &msErr, const MPlexHV &msPar, const MPlexHV &plNrm, const MPlexHV &plDir, MPlexQF &outChi2, MPlexLV &propPar, MPlexQI &outFailFlag, const int N_proc, const PropagationFlags &propFlags, const bool propToHit)
void propagateTracksToPCAZ(const int N_proc, const PropagationFlags &pf)
Matriplex::Matriplex< int, 1, 1, NN > MPlexQI
const LayerInfo * layer_info() const
TrackCand * m_TrkCand[NN]
void updateWithLoadedHit(int N_proc, const LayerOfHits &layer_of_hits, const FindingFoos &fnd_foos)
void selectHitIndicesV2(const LayerOfHits &layer_of_hits, const int N_proc)
std::vector< Track > TrackVec
SimLabelFromHits simLabelForCurrentSeed(int i) const
Matriplex::Matriplex< float, 1, 1, NN > MPlexQF
WithinSensitiveRegion_e m_wsr
void pack(TMerr &err, TMpar &par)
void bkFitFitTracks(const EventOfHits &eventofhits, const SteeringParams &st_par, const int N_proc, bool chiDebug=false)
const SteeringParams * m_steering_params
static const FindingFoos & get_finding_foos(bool is_barrel)
std::vector< LayerControl > m_layer_plan
bool passStripChargePCMfromTrack(int itrack, bool isBarrel, unsigned int pcm, unsigned int pcmMin, const MPlexLV &pPar, const MPlexHS &msErr)
float getPhi(float x, float y)
const Track & currentSeed(int i) const
Matriplex::MatriplexSym< float, HH, NN > MPlexHS
static constexpr int kHitMaxClusterIdx
void bkFitOutputTracks(TrackVec &cands, int beg, int end, bool outputProp)
void bkFitFitTracksBH(const EventOfHits &eventofhits, const SteeringParams &st_par, const int N_proc, bool chiDebug=false)
const std::vector< float > & get_window_params(bool forward, bool fallback_to_other) const
HitOnTrack hot(int i) const
void copyOutParErr(std::vector< CombCandidate > &seed_cand_vec, int N_proc, bool outputProp) const
int num_inside_minus_one_hits(const int mslot) const
void findCandidatesCloneEngine(const LayerOfHits &layer_of_hits, CandCloner &cloner, const int offset, const int N_proc, const FindingFoos &fnd_foos)
Matriplex::MatriplexSym< float, LL, NN > MPlexLS
const std::vector< bool > * m_iteration_hit_mask
PropagationFlags finding_intra_layer_pflags
constexpr bool usePropToPlane
void add_cand(int idx, const IdxChi2List &cand_info)
float getHitSelDynamicChi2Cut(const int itrk, const int ipar)
MPF fast_atan2(const MPF &y, const MPF &x)
static constexpr int kHitMissIdx
const HoTNode * m_HoTNodeArr[NN]
unsigned short bin_index_t
WSR_Result m_XWsrResult[NN]
void getHitSelDynamicWindows(const float invpt, const float theta, float &min_dq, float &max_dq, float &min_dphi, float &max_dphi)
Geom::Theta< T > theta() const
static constexpr int kHitEdgeIdx
CombCandidate & combCandWithOriginalIndex(int idx)
static unsigned int minChargePerCM()
SVector6 & parameters_nc()
Power< A, B >::type pow(const A &a, const B &b)
const Hit & refHit(int i) const
MPlex< T, D1, D2, N > sqrt(const MPlex< T, D1, D2, N > &a)
void print_par_err(int corp, int mslot) const
void addBestHit(const LayerOfHits &layer_of_hits, const int N_proc, const FindingFoos &fnd_foos)
constexpr bool isFinite(float x)