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 <
NN; ++itrack) {
243 if (itrack < N_proc && hit_cnt <
m_XHitSize[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 const 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 const 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) {
379 if (itrack >= N_proc)
383 float min_dq = ILC.
min_dq();
384 float max_dq = ILC.
max_dq();
388 const float invpt =
m_Par[iI].At(itrack, 3, 0);
392 const float x =
m_Par[iI].constAt(itrack, 0, 0);
393 const float y =
m_Par[iI].constAt(itrack, 1, 0);
394 const float r2 =
x *
x + y * y;
395 const float dphidx = -y /
r2, dphidy =
x /
r2;
396 const float dphi2 = calcdphi2(itrack, dphidx, dphidy);
401 const float phi =
getPhi(
x, y);
402 float dphi = calcdphi(dphi2, min_dphi);
404 const float z =
m_Par[iI].constAt(itrack, 2, 0);
406 const float edgeCorr =
411 assignbins(itrack, z,
dz, phi, dphi, min_dq, max_dq, min_dphi, max_dphi);
421 const float layerD =
std::abs(
L.layer_info().zmax() -
L.layer_info().zmin()) * 0.5
f *
424 #if !defined(__clang__) 427 for (
int itrack = 0; itrack <
NN; ++itrack) {
430 float min_dq = ILC.
min_dq();
431 float max_dq = ILC.
max_dq();
435 const float invpt =
m_Par[iI].At(itrack, 3, 0);
439 const float x =
m_Par[iI].constAt(itrack, 0, 0);
440 const float y =
m_Par[iI].constAt(itrack, 1, 0);
441 const float r2 =
x *
x + y * y;
442 const float r2Inv = 1.f /
r2;
443 const float dphidx = -y * r2Inv, dphidy =
x * r2Inv;
444 const float phi =
getPhi(
x, y);
446 calcdphi2(itrack, dphidx, dphidy)
454 float dphi = calcdphi(dphi2, min_dphi);
458 y * y *
m_Err[iI].constAt(itrack, 1, 1) +
459 2 *
x * y *
m_Err[iI].constAt(itrack, 0, 1)) /
461 const float edgeCorr =
std::abs(0.5
f * (
L.layer_info().zmax() -
L.layer_info().zmin()) *
465 assignbins(itrack, r, dr, phi, dphi, min_dq, max_dq, min_dphi, max_dphi);
469 #ifdef RNT_DUMP_MkF_SelHitIdcs 470 if (fill_binsearch_only) {
472 for (
auto i : rnt_shi.f_h_idcs) {
473 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[
i]];
492 for (
int itrack = 0; itrack <
NN; ++itrack) {
493 if (itrack >= N_proc) {
507 const bidx_t qb = qbv[itrack];
508 const bidx_t qb1 = qb1v[itrack];
509 const bidx_t qb2 = qb2v[itrack];
510 const bidx_t pb1 = pb1v[itrack];
511 const bidx_t pb2 = pb2v[itrack];
513 const float q = qv[itrack];
514 const float phi = phiv[itrack];
515 const float dphi = dphiv[itrack];
516 const float dq = dqv[itrack];
519 dprintf(
" %2d/%2d: %6.3f %6.3f %6.6f %7.5f %3u %3u %4u %4u\n",
520 L.layer_id(), itrack,
q, phi, dq, dphi,
524 #if defined(DUMPHITWINDOW) && defined(MKFIT_STANDALONE) 525 const auto ngr = [](
float f) {
return isFinite(
f) ?
f : -999.0f; };
532 for (bidx_t qi = qb1; qi != qb2; ++qi) {
533 for (bidx_t
pi = pb1;
pi != pb2;
pi =
L.phiMaskApply(
pi + 1)) {
535 if (qi == qb &&
L.isBinDead(
pi, qi) ==
true) {
536 dprint(
"dead module for track in layer=" <<
L.layer_id() <<
" qb=" << qi <<
" pi=" <<
pi <<
" q=" <<
q 549 auto pbi =
L.phiQBinContent(
pi, qi);
550 for (bcnt_t
hi = pbi.begin();
hi < pbi.end(); ++
hi) {
553 const unsigned int hi_orig =
L.getOriginalHitIndex(
hi);
557 "Yay, denying masked hit on layer %u, hi %u, orig idx %u\n",
L.layer_info().layer_id(),
hi, hi_orig);
569 dprintf(
" SHI %3u %4u %5u %6.3f %6.3f %6.4f %7.5f %s\n",
571 ddq, ddphi, (ddq < dq && ddphi < dphi) ?
"PASS" :
"FAIL");
574 #if defined(DUMPHITWINDOW) && defined(MKFIT_STANDALONE) 580 int st_isfindable = 0;
581 int st_label = -999999;
588 float st_eta = -999.;
589 float st_phi = -999.;
593 st_label = simtrack.
label();
595 st_pt = simtrack.
pT();
596 st_eta = simtrack.
momEta();
597 st_phi = simtrack.
momPhi();
599 st_charge = simtrack.
charge();
600 st_r = simtrack.
posR();
604 const Hit &thishit =
L.refHit(hi_orig);
623 float hx = thishit.
x();
624 float hy = thishit.
y();
625 float hz = thishit.
z();
627 float hphi = std::atan2(hy, hx);
632 (hx * hx * thishit.
exx() + hy * hy * thishit.
eyy() + 2.0f * hx * hy *
m_msErr.At(itrack, 0, 1)) /
635 float hchi2 = ngr( thisOutChi2[itrack] );
636 float tx =
m_Par[iI].At(itrack, 0, 0);
637 float ty =
m_Par[iI].At(itrack, 1, 0);
638 float tz =
m_Par[iI].At(itrack, 2, 0);
640 float tphi = std::atan2(ty, tx);
646 (tx * tx *
tex *
tex + ty * ty * tey * tey + 2.0
f * tx * ty *
m_Err[iI].At(itrack, 0, 1)) /
649 (ty * ty *
tex *
tex + tx * tx * tey * tey - 2.0
f * tx * ty *
m_Err[iI].At(itrack, 0, 1)) /
650 (tr * tr * tr * tr)) );
652 float ht_dz = hz - tz;
655 static bool first =
true;
659 "evt_id/I:track_algo/I:" 660 "lyr_id/I:lyr_isbrl/I:hit_idx/I:" 661 "trk_cnt/I:trk_idx/I:trk_label/I:" 662 "trk_pt/F:trk_eta/F:trk_mphi/F:trk_chi2/F:" 664 "seed_idx/I:seed_label/I:seed_mcid/I:" 666 "st_isfindable/I:st_prodtype/I:st_label/I:" 667 "st_pt/F:st_eta/F:st_phi/F:" 668 "st_nhits/I:st_charge/I:st_r/F:st_z/F:" 669 "trk_q/F:hit_q/F:dq_trkhit/F:dq_cut/F:trk_phi/F:hit_phi/F:dphi_trkhit/F:dphi_cut/F:" 670 "t_x/F:t_y/F:t_r/F:t_phi/F:t_z/F:" 671 "t_ex/F:t_ey/F:t_er/F:t_ephi/F:t_ez/F:" 672 "h_x/F:h_y/F:h_r/F:h_phi/F:h_z/F:" 673 "h_ex/F:h_ey/F:h_er/F:h_ephi/F:h_ez/F:" 674 "ht_dxy/F:ht_dz/F:ht_dphi/F:" 682 printf(
"HITWINDOWSEL " 686 "%6.3f %6.3f %6.3f %6.3f " 693 "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f " 694 "%6.3f %6.3f %6.3f %6.3f %6.3f " 695 "%6.6f %6.6f %6.6f %6.6f %6.6f " 696 "%6.3f %6.3f %6.3f %6.3f %6.3f " 697 "%6.6f %6.6f %6.6f %6.6f %6.6f " 702 L.layer_id(),
L.is_barrel(), hi_orig,
704 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),
708 st_isfindable, st_prodtype, st_label,
709 st_pt, st_eta, st_phi,
710 st_nhits, st_charge, st_r, st_z,
711 q,
L.hit_q(
hi), ddq, dq, phi,
L.hit_phi(
hi), ddphi, dphi,
712 tx, ty, tr, tphi, tz,
713 tex, tey, ter, tephi, tez,
714 hx, hy, hr, hphi, hz,
715 hex, hey, her, hephi, hez,
716 ht_dxy, ht_dz, ht_dphi,
740 assert(
false &&
"this code has not been used in a while -- see comments in code");
765 dprintf(
"LayerOfHits::SelectHitIndicesV2 %s layer=%d N_proc=%d\n",
766 L.is_barrel() ?
"barrel" :
"endcap",
770 #ifdef RNT_DUMP_MkF_SelHitIdcs 771 rnt_shi.InnerIdcsReset(N_proc);
773 for (
int i = 0;
i < N_proc; ++
i) {
777 }
else if (sim_lbls[
i].is_set()) {
791 constexpr float PHI_BIN_EXTRA_FAC = 2.75f;
794 namespace mp = mini_propagators;
797 mp::InitialStatePlex isp;
798 mp::StatePlex sp1, sp2;
809 void prop_to_limits(
const LayerInfo &li) {
835 phi_c = 0.5f * (pmax +
pmin);
850 return x *
x *
err.ReduceFixedIJ(0, 0) + y * y *
err.ReduceFixedIJ(1, 1) +
851 2.0f *
x * y *
err.ReduceFixedIJ(0, 1);
855 MPlexQF r2_c = isp.x * isp.x + isp.y * isp.y;
857 MPlexQF dphidx_c = -isp.y * r2inv_c;
858 MPlexQF dphidy_c = isp.x * r2inv_c;
859 dphi_track = 3.0f * calc_err_xy(dphidx_c, dphidy_c).abs().sqrt();
865 dq_track = 3.0f *
err.ReduceFixedIJ(2, 2).abs().sqrt();
869 dq_track = 3.0f * (r2inv_c * calc_err_xy(isp.x, isp.y).abs()).
sqrt();
872 for (
int i = 0;
i <
p1.kTotSize; ++
i) {
888 B.prop_to_limits(LI);
889 B.find_bin_ranges(LI,
L,
m_Err[iI]);
891 for (
int i = 0;
i <
NN; ++
i) {
913 #ifdef RNT_DUMP_MkF_SelHitIdcs 914 for (
auto i : rnt_shi.f_h_idcs) {
915 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[
i]];
919 0.5f * (
B.q2[
i] -
B.q1[
i]),
934 unsigned int hit_index;
936 auto pqe_cmp = [](
const PQE &
a,
const PQE &
b) {
return a.score <
b.score; };
937 std::priority_queue<PQE, std::vector<PQE>, decltype(pqe_cmp)> pqueue(pqe_cmp);
942 for (
int itrack = 0; itrack <
NN; ++itrack) {
943 if (itrack >= N_proc) {
958 const bidx_t qb =
B.q0[itrack];
959 const bidx_t qb1 =
B.q1[itrack];
960 const bidx_t qb2 =
B.q2[itrack];
961 const bidx_t pb1 =
B.p1[itrack];
962 const bidx_t pb2 =
B.p2[itrack];
965 dprintf(
" %2d/%2d: %6.3f %6.3f %6.6f %7.5f %3u %3u %4u %4u\n",
966 L.layer_id(), itrack,
B.q_c[itrack],
B.phi_c[itrack],
967 B.qmax[itrack] -
B.qmin[itrack],
B.dphi[itrack],
969 #ifdef RNT_DUMP_MkF_SelHitIdcs 972 struct pos_match {
float dphi, dq;
int idx;
bool matched; };
973 std::vector<pos_match> pos_match_vec;
977 mp::InitialState mp_is(
m_Par[iI],
m_Chg, itrack);
980 for (bidx_t qi = qb1; qi != qb2; ++qi) {
981 for (bidx_t
pi = pb1;
pi != pb2;
pi =
L.phiMaskApply(
pi + 1)) {
983 if (qi == qb &&
L.isBinDead(
pi, qi) ==
true) {
984 dprint(
"dead module for track in layer=" <<
L.layer_id() <<
" qb=" << qi <<
" pi=" <<
pi 985 <<
" q=" <<
B.q_c[itrack] <<
" phi=" <<
B.phi_c[itrack]);
995 auto pbi =
L.phiQBinContent(
pi, qi);
996 for (bcnt_t
hi = pbi.begin();
hi < pbi.end(); ++
hi) {
999 const unsigned int hi_orig =
L.getOriginalHitIndex(
hi);
1003 "Yay, denying masked hit on layer %u, hi %u, orig idx %u\n",
L.layer_info().layer_id(),
hi, hi_orig);
1007 float new_q, new_phi, new_ddphi, new_ddq;
1010 if (
L.is_barrel()) {
1011 prop_fail = mp_is.propagate_to_r(
mp::PA_Exact,
L.hit_qbar(
hi), mp_s,
true);
1014 prop_fail = mp_is.propagate_to_z(
mp::PA_Exact,
L.hit_qbar(
hi), mp_s,
true);
1018 new_phi = vdt::fast_atan2f(mp_s.y, mp_s.x);
1022 bool dqdphi_presel = new_ddq <
B.dq_track[itrack] + DDQ_PRESEL_FAC *
L.hit_q_half_length(
hi) &&
1023 new_ddphi <
B.dphi_track[itrack] + DDPHI_PRESEL_FAC * 0.0123f;
1026 dprintf(
" SHI %3u %4u %5u %6.3f %6.3f %6.4f %7.5f PROP-%s %s\n",
1028 new_ddq, new_ddphi, prop_fail ?
"FAIL" :
"OK", dqdphi_presel ?
"PASS" :
"REJECT");
1029 #ifdef RNT_DUMP_MkF_SelHitIdcs 1030 if (rnt_shi.f_h_remap[itrack] >= 0) {
1031 int sim_lbl = sim_lbls[itrack].
label;
1032 const Hit &thishit =
L.refHit(hi_orig);
1042 thisOutChi2, tmpPropPar, propFail, N_proc,
1045 float hchi2 = thisOutChi2[itrack];
1047 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[itrack]];
1050 int hit_lbl = mchinfo.mcTrackID();
1053 new_q,
L.hit_q_half_length(
hi),
L.hit_qbar(
hi), new_phi,
1056 new_ddq, new_ddphi, hchi2, (
int) hi_orig,
1057 (sim_lbl == hit_lbl), dqdphi_presel, !prop_fail
1060 bool new_dec = dqdphi_presel && !prop_fail;
1062 if (sim_lbl == hit_lbl) {
1068 pos_match_vec.emplace_back(pos_match{ new_ddphi, new_ddq, hit_out_idx++,
1069 sim_lbl == hit_lbl });
1074 if (prop_fail || !dqdphi_presel)
1076 if (pqueue_size < NEW_MAX_HIT) {
1077 pqueue.push({new_ddphi, hi_orig});
1079 }
else if (new_ddphi < pqueue.top().score) {
1081 pqueue.push({new_ddphi, hi_orig});
1087 dprintf(
" PQUEUE (%d)", pqueue_size);
1088 #ifdef RNT_DUMP_MkF_SelHitIdcs 1090 if (sim_lbls[itrack].is_set()) {
1092 std::sort(pos_match_vec.begin(), pos_match_vec.end(),
1093 [](
auto &
a,
auto &
b){
return a.dphi <
b.dphi;});
1094 int pmvs = pos_match_vec.size();
1096 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[itrack]];
1097 for (
int i = 0;
i < pmvs; ++
i) {
1110 while (pqueue_size) {
1112 m_XHitArr.At(itrack, pqueue_size, 0) = pqueue.top().hit_index;
1113 dprintf(
" %d: %f %d", pqueue_size, pqueue.top().score, pqueue.top().hit_index);
1146 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1152 for (
int itrack = 0; itrack <
NN; ++itrack) {
1153 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1154 mhp.addInputAt(itrack, layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)));
1178 for (
int itrack = 0; itrack <
NN; ++itrack) {
1179 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1184 bestHit[itrack] =
m_XHitArr.At(itrack, hit_cnt, 0);
1191 for (
int itrack = 0; itrack <
NN; ++itrack) {
1192 if (itrack >= N_proc) {
1198 m_msErr.setDiagonal3x3(itrack, 666);
1213 if (bestHit[itrack] >= 0) {
1214 const Hit &
hit = layer_of_hits.
refHit(bestHit[itrack]);
1217 dprint(
"ADD BEST HIT FOR TRACK #" 1218 << itrack << std::endl
1219 <<
"prop x=" <<
m_Par[
iP].constAt(itrack, 0, 0) <<
" y=" <<
m_Par[
iP].constAt(itrack, 1, 0) << std::endl
1220 <<
"copy in hit #" << bestHit[itrack] <<
" x=" <<
hit.position()[0] <<
" y=" <<
hit.position()[1]);
1240 m_msErr.setDiagonal3x3(itrack, 666);
1253 dprint(
"update parameters");
1267 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));
1277 const float res =
std::abs(msPar.constAt(itrack, 2, 0) - pPar.constAt(itrack, 2, 0));
1278 const float hitHL =
sqrt(msErr.constAt(itrack, 2, 2) * 3.f);
1279 const float qErr =
sqrt(pErr.constAt(itrack, 2, 2));
1280 dprint(
"qCompat " << hitHL <<
" + " << 3.
f * qErr <<
" vs " <<
res);
1283 const float res[2]{msPar.constAt(itrack, 0, 0) - pPar.constAt(itrack, 0, 0),
1284 msPar.constAt(itrack, 1, 0) - pPar.constAt(itrack, 1, 0)};
1285 const float hitT2 = msErr.constAt(itrack, 0, 0) + msErr.constAt(itrack, 1, 1);
1286 const float hitT2inv = 1.f / hitT2;
1287 const float proj[3] = {msErr.constAt(itrack, 0, 0) * hitT2inv,
1288 msErr.constAt(itrack, 0, 1) * hitT2inv,
1289 msErr.constAt(itrack, 1, 1) * hitT2inv};
1291 sqrt(
std::abs(pErr.constAt(itrack, 0, 0) *
proj[0] + 2.f * pErr.constAt(itrack, 0, 1) *
proj[1] +
1292 pErr.constAt(itrack, 1, 1) *
proj[2]));
1293 const float resProj =
1295 dprint(
"qCompat " <<
sqrt(hitT2 * 3.
f) <<
" + " << 3.
f * qErr <<
" vs " << resProj);
1306 int itrack,
bool isBarrel,
unsigned int pcm,
unsigned int pcmMin,
const MPlexLV &pPar,
const MPlexHS &msErr) {
1313 const float hitT2 = msErr.constAt(itrack, 0, 0) + msErr.constAt(itrack, 1, 1);
1314 const float hitT2inv = 1.f / hitT2;
1315 const float proj[3] = {msErr.constAt(itrack, 0, 0) * hitT2inv,
1316 msErr.constAt(itrack, 0, 1) * hitT2inv,
1317 msErr.constAt(itrack, 1, 1) * hitT2inv};
1318 const bool detXY_OK =
1320 const float cosP =
cos(pPar.constAt(itrack, 4, 0));
1321 const float sinP =
sin(pPar.constAt(itrack, 4, 0));
1322 const float sinT =
std::abs(
sin(pPar.constAt(itrack, 5, 0)));
1325 2.
f * cosP * sinP *
proj[1]))
1332 const float qCorr = pcm * qSF;
1333 dprint(
"pcm " << pcm <<
" * " << qSF <<
" = " << qCorr <<
" vs " << pcmMin);
1334 return qCorr > pcmMin;
1342 std::vector<std::vector<TrackCand>> &tmp_candidates,
1363 int nHitsAdded[
NN]{};
1364 bool isTooLargeCluster[
NN]{
false};
1366 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1372 for (
int itrack = 0; itrack <
NN; ++itrack) {
1373 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1375 mhp.addInputAt(itrack,
hit);
1376 charge_pcm[itrack] =
hit.chargePerCM();
1424 bool oneCandPassCut =
false;
1425 for (
int itrack = 0; itrack <
NN; ++itrack) {
1426 if (itrack >= N_proc) {
1434 if (
chi2 < max_c2) {
1435 bool isCompatible =
true;
1447 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1449 isTooLargeCluster[itrack] =
true;
1450 isCompatible =
false;
1455 oneCandPassCut =
true;
1462 if (oneCandPassCut) {
1477 dprint(
"update parameters" << std::endl
1478 <<
"propagated track parameters x=" <<
m_Par[
iP].constAt(0, 0, 0)
1479 <<
" y=" <<
m_Par[
iP].constAt(0, 1, 0) << std::endl
1480 <<
" hit position x=" <<
m_msPar.constAt(0, 0, 0)
1481 <<
" y=" <<
m_msPar.constAt(0, 1, 0) << std::endl
1482 <<
" updated track parameters x=" <<
m_Par[
iC].constAt(0, 0, 0)
1483 <<
" y=" <<
m_Par[
iC].constAt(0, 1, 0));
1487 for (
int itrack = 0; itrack <
NN; ++itrack) {
1488 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1492 if (
chi2 < max_c2) {
1493 bool isCompatible =
true;
1496 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1499 isCompatible =
false;
1513 bool hitExists =
false;
1528 nHitsAdded[itrack]++;
1529 dprint(
"chi2 cut passed, creating new candidate");
1533 const int hit_idx =
m_XHitArr.At(itrack, hit_cnt, 0);
1537 newcand.
setCharge(tmpChg(itrack, 0, 0));
1546 if (
chi2 < max_c2) {
1548 ccand[
m_CandIdx(itrack, 0, 0)].considerHitForOverlap(
1556 tmp_candidates[
m_SeedIdx(itrack, 0, 0) -
offset].emplace_back(newcand);
1567 for (
int itrack = 0; itrack <
NN; ++itrack) {
1584 else if (
m_XWsrResult[itrack].m_in_gap ==
true && nHitsAdded[itrack] == 0) {
1588 else if (isTooLargeCluster[itrack] ==
true && nHitsAdded[itrack] == 0) {
1603 tmp_candidates[
m_SeedIdx(itrack, 0, 0) -
offset].emplace_back(newcand);
1632 dprintf(
"FindCandidatesCloneEngine max hits to process=%d\n",
maxSize);
1634 int nHitsAdded[
NN]{};
1635 bool isTooLargeCluster[
NN]{
false};
1637 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1643 for (
int itrack = 0; itrack <
NN; ++itrack) {
1644 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1646 mhp.addInputAt(itrack,
hit);
1647 charge_pcm[itrack] =
hit.chargePerCM();
1690 for (
int itrack = 0; itrack <
NN; ++itrack) {
1696 if ( itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1702 dprintf(
" chi2=%.3f (%.3f) trkIdx=%d hitIdx=%d\n",
chi2, max_c2, itrack,
m_XHitArr.At(itrack, hit_cnt, 0));
1703 if (
chi2 < max_c2) {
1704 bool isCompatible =
true;
1707 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1709 isTooLargeCluster[itrack] =
true;
1710 isCompatible =
false;
1725 bool hitExists =
false;
1740 nHitsAdded[itrack]++;
1741 const int hit_idx =
m_XHitArr.At(itrack, hit_cnt, 0);
1745 if (
chi2 < max_c2) {
1746 ccand[
m_CandIdx(itrack, 0, 0)].considerHitForOverlap(
1752 tmpList.
hitIdx = hit_idx;
1764 dprint(
" adding hit with hit_cnt=" << hit_cnt <<
" for trkIdx=" << tmpList.
trkIdx 1765 <<
" orig Seed=" <<
m_Label(itrack, 0, 0));
1767 #ifdef RNT_DUMP_MkF_SelHitIdcs 1768 if (rnt_shi.f_h_remap[itrack] >= 0) {
1769 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[itrack]];
1781 for (
int itrack = 0; itrack <
NN; ++itrack) {
1800 else if (
m_XWsrResult[itrack].m_in_gap ==
true && nHitsAdded[itrack] == 0) {
1804 else if (isTooLargeCluster[itrack] ==
true && nHitsAdded[itrack] == 0) {
1817 tmpList.
hitIdx = fake_hit_idx;
1829 dprint(
"adding invalid hit " << fake_hit_idx);
1907 const int iO = outputProp ?
iP :
iC;
1909 for (
int i = 0;
i <
NN; ++
i) {
1914 m_Err[iO].copyOut(
i,
cand.errors_nc().Array());
1915 m_Par[iO].copyOut(
i,
cand.parameters_nc().Array());
1918 dprint((outputProp ?
"propagated" :
"updated")
1919 <<
" track parameters x=" <<
cand.parameters()[0] <<
" y=" <<
cand.parameters()[1]
1920 <<
" z=" <<
cand.parameters()[2] <<
" pt=" << 1. /
cand.parameters()[3] <<
" posEta=" <<
cand.posEta());
1936 for (
int i = beg;
i < end; ++
i, ++itrack) {
1963 for (
int i = beg;
i < end; ++
i, ++itrack) {
1989 const int iO = outputProp ?
iP :
iC;
1992 for (
int i = beg;
i < end; ++
i, ++itrack) {
2010 const int iO = outputProp ?
iP :
iC;
2013 for (
int i = beg;
i < end; ++
i, ++itrack) {
2028 #if defined(DEBUG_BACKWARD_FIT) || defined(DEBUG_BACKWARD_FIT_BH) 2045 float tmp_err[6] = {666, 0, 666, 0, 0, 666};
2049 const int layer = lp_iter->m_layer;
2055 for (
int i = 0;
i < N_proc; ++
i) {
2113 for (
int n = 0;
n <
NN; ++
n) {
2114 if (
n < N_proc &&
m_Par[
iC].At(
n, 3, 0) < 0) {
2120 #ifdef DEBUG_BACKWARD_FIT_BH 2122 for (
int i = 0;
i < N_proc; ++
i) {
2131 "CHIHIT %3d %10g %10g %10g %10g %10g %11.5g %11.5g %11.5g %10g %10g %10g %10g %11.5g %11.5g %11.5g %10g " 2132 "%10g %10g %10g %10g %11.5g %11.5g\n",
2146 e2s(
m_Err[ti].At(
i, 0, 0)),
2147 e2s(
m_Err[ti].At(
i, 1, 1)),
2148 e2s(
m_Err[ti].At(
i, 2, 2)),
2149 1.0f /
m_Par[ti].At(
i, 3, 0),
2153 std::atan2(
m_Par[ti].At(
i, 1, 0),
m_Par[ti].At(
i, 0, 0)),
2173 printf(
"Parameters:\n");
2174 for (
int i = 0;
i < 6; ++
i) {
2175 printf(
" %12.4g",
m_Par[corp].constAt(mslot,
i, 0));
2177 printf(
"\nError matrix\n");
2178 for (
int i = 0;
i < 6; ++
i) {
2179 for (
int j = 0;
j < 6; ++
j) {
2180 printf(
" %12.4g",
m_Err[corp].constAt(mslot,
i,
j));
2201 float tmp_err[6] = {666, 0, 666, 0, 0, 666};
2204 #if defined(DEBUG_PROP_UPDATE) 2205 const int DSLOT = 0;
2206 printf(
"bkfit entry, track in slot %d\n", DSLOT);
2211 const int layer = lp_iter.layer();
2216 #if defined(DEBUG_BACKWARD_FIT) 2217 const Hit *last_hit_ptr[
NN];
2220 no_mat_effs.setVal(0);
2223 for (
int i = 0;
i < N_proc; ++
i) {
2243 #ifdef DEBUG_BACKWARD_FIT 2244 last_hit_ptr[
i] = &
hit;
2252 #ifdef DEBUG_BACKWARD_FIT 2253 last_hit_ptr[
i] =
nullptr;
2264 if (done_count == N_proc)
2266 if (here_count == 0)
2301 #if defined(DEBUG_PROP_UPDATE) 2302 printf(
"\nbkfit at layer %d, track in slot %d -- fail=%d, had hit=%d (%g, %g, %g)\n",
2306 1 - no_mat_effs[DSLOT],
2310 printf(
"Propagated:\n");
2312 printf(
"Updated:\n");
2317 for (
int i = 0;
i <
NN; ++
i) {
2353 if (
i < N_proc &&
m_Par[
iC].At(
i, 3, 0) < 0) {
2359 #if defined(DEBUG_BACKWARD_FIT) 2362 const char beg_cur_sep =
'/';
2363 for (
int i = 0;
i < N_proc; ++
i) {
2364 if (chiDebug && last_hit_ptr[
i]) {
2367 float chi = tmp_chi2.At(
i, 0, 0);
2368 float chi_prnt = std::isfinite(chi) ? chi : -9;
2370 #if defined(MKFIT_STANDALONE) 2373 dprintf(
"BKF_OVERLAP %d %d %d %d %d %d %d " 2374 "%f%c%f %f %f%c%f %f %f %f %d %d %d %d " 2378 dprintf(
"BKF_OVERLAP %d %d %d %d %d %d " 2379 "%f%c%f %f %f%c%f %f %f %f %d %d %d " 2383 layer,
L.is_stereo(),
L.is_barrel(),
2384 bb.
pT(), beg_cur_sep, 1.0f /
m_Par[ti].At(
i, 3, 0),
2390 std::isnan(chi), std::isfinite(chi), chi > 0,
2391 #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
RVec state2mom(const miprops::State &s)
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)
PropState statep2propstate(const miprops::StatePlex &s, int i)
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)
RVec state2pos(const miprops::State &s)
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)
RVec hit2pos(const Hit &h)
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
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)
std::vector< HitMatchInfo > hmi
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]
const LayerInfo & layer_info() const
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
bool assignIdxChi2List(const mkfit::IdxChi2List &ic2l)
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)