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 =
std::abs(0.5
f * (
L.layer_info()->rout() -
L.layer_info()->rin()) /
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);
772 for (
int i = 0;
i < N_proc; ++
i) {
776 }
else if (slfh.is_set()) {
787 constexpr float PHI_BIN_EXTRA_FAC = 2.75f;
790 namespace mp = mini_propagators;
793 mp::InitialStatePlex isp;
794 mp::StatePlex sp1, sp2;
805 void prop_to_limits(
const LayerInfo &li) {
831 phi_c = 0.5f * (pmax +
pmin);
846 return x *
x *
err.ReduceFixedIJ(0, 0) + y * y *
err.ReduceFixedIJ(1, 1) +
847 2.0f *
x * y *
err.ReduceFixedIJ(0, 1);
851 MPlexQF r2_c = isp.x * isp.x + isp.y * isp.y;
853 MPlexQF dphidx_c = -isp.y * r2inv_c;
854 MPlexQF dphidy_c = isp.x * r2inv_c;
855 dphi_track = 3.0f * calc_err_xy(dphidx_c, dphidy_c).abs().sqrt();
861 dq_track = 3.0f *
err.ReduceFixedIJ(2, 2).abs().sqrt();
865 dq_track = 3.0f * (r2inv_c * calc_err_xy(isp.x, isp.y).abs()).
sqrt();
868 for (
int i = 0;
i <
p1.kTotSize; ++
i) {
884 B.prop_to_limits(LI);
885 B.find_bin_ranges(LI,
L,
m_Err[iI]);
887 for (
int i = 0;
i <
NN; ++
i) {
909 #ifdef RNT_DUMP_MkF_SelHitIdcs 910 for (
auto i : rnt_shi.f_h_idcs) {
911 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[
i]];
915 0.5f * (
B.q2[
i] -
B.q1[
i]),
923 ci.
ps_min = statep2propstate(
B.sp1,
i);
924 ci.
ps_max = statep2propstate(
B.sp2,
i);
930 unsigned int hit_index;
932 auto pqe_cmp = [](
const PQE &
a,
const PQE &
b) {
return a.score <
b.score; };
933 std::priority_queue<PQE, std::vector<PQE>, decltype(pqe_cmp)> pqueue(pqe_cmp);
938 for (
int itrack = 0; itrack <
NN; ++itrack) {
939 if (itrack >= N_proc) {
954 const bidx_t qb =
B.q0[itrack];
955 const bidx_t qb1 =
B.q1[itrack];
956 const bidx_t qb2 =
B.q2[itrack];
957 const bidx_t pb1 =
B.p1[itrack];
958 const bidx_t pb2 =
B.p2[itrack];
961 dprintf(
" %2d/%2d: %6.3f %6.3f %6.6f %7.5f %3u %3u %4u %4u\n",
962 L.layer_id(), itrack, qv[itrack], phi[itrack], dqv[itrack], dphiv[itrack],
966 mp::InitialState mp_is(
m_Par[iI],
m_Chg, itrack);
969 for (bidx_t qi = qb1; qi != qb2; ++qi) {
970 for (bidx_t
pi = pb1;
pi != pb2;
pi =
L.phiMaskApply(
pi + 1)) {
972 if (qi == qb &&
L.isBinDead(
pi, qi) ==
true) {
973 dprint(
"dead module for track in layer=" <<
L.layer_id() <<
" qb=" << qi <<
" pi=" <<
pi <<
" q=" <<
q 984 auto pbi =
L.phiQBinContent(
pi, qi);
985 for (bcnt_t
hi = pbi.begin();
hi < pbi.end(); ++
hi) {
988 const unsigned int hi_orig =
L.getOriginalHitIndex(
hi);
992 "Yay, denying masked hit on layer %u, hi %u, orig idx %u\n",
L.layer_info()->layer_id(),
hi, hi_orig);
999 float new_q, new_phi, new_ddphi, new_ddq;
1002 if (
L.is_barrel()) {
1003 prop_fail = mp_is.propagate_to_r(
mp::PA_Exact,
L.hit_qbar(
hi), mp_s,
true);
1006 prop_fail = mp_is.propagate_to_z(
mp::PA_Exact,
L.hit_qbar(
hi), mp_s,
true);
1010 new_phi = vdt::fast_atan2f(mp_s.y, mp_s.x);
1014 bool dqdphi_presel = new_ddq <
B.dq_track[itrack] + DDQ_PRESEL_FAC *
L.hit_q_half_length(
hi) &&
1015 new_ddphi <
B.dphi_track[itrack] + DDPHI_PRESEL_FAC * 0.0123f;
1018 dprintf(
" SHI %3u %4u %5u %6.3f %6.3f %6.4f %7.5f PROP-%s %s\n",
1020 ddq, ddphi, prop_fail ?
"FAIL" :
"OK", dqdphi_presel ?
"PASS" :
"REJECT");
1023 if (prop_fail || !dqdphi_presel)
1025 if (pqueue_size < NEW_MAX_HIT) {
1026 pqueue.push({new_ddphi, hi_orig});
1028 }
else if (new_ddphi < pqueue.top().score) {
1030 pqueue.push({new_ddphi, hi_orig});
1036 dprintf(
" PQUEUE (%d)", pqueue_size);
1039 while (pqueue_size) {
1041 m_XHitArr.At(itrack, pqueue_size, 0) = pqueue.top().hit_index;
1042 dprintf(
" %d: %f %d", pqueue_size, pqueue.top().score, pqueue.top().hit_index);
1075 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1081 for (
int itrack = 0; itrack <
NN; ++itrack) {
1082 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1083 mhp.addInputAt(itrack, layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)));
1107 for (
int itrack = 0; itrack <
NN; ++itrack) {
1108 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1113 bestHit[itrack] =
m_XHitArr.At(itrack, hit_cnt, 0);
1120 for (
int itrack = 0; itrack <
NN; ++itrack) {
1121 if (itrack >= N_proc) {
1127 m_msErr.setDiagonal3x3(itrack, 666);
1142 if (bestHit[itrack] >= 0) {
1143 const Hit &
hit = layer_of_hits.
refHit(bestHit[itrack]);
1146 dprint(
"ADD BEST HIT FOR TRACK #" 1147 << itrack << std::endl
1148 <<
"prop x=" <<
m_Par[
iP].constAt(itrack, 0, 0) <<
" y=" <<
m_Par[
iP].constAt(itrack, 1, 0) << std::endl
1149 <<
"copy in hit #" << bestHit[itrack] <<
" x=" <<
hit.position()[0] <<
" y=" <<
hit.position()[1]);
1169 m_msErr.setDiagonal3x3(itrack, 666);
1182 dprint(
"update parameters");
1196 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));
1206 const float res =
std::abs(msPar.constAt(itrack, 2, 0) - pPar.constAt(itrack, 2, 0));
1207 const float hitHL =
sqrt(msErr.constAt(itrack, 2, 2) * 3.f);
1208 const float qErr =
sqrt(pErr.constAt(itrack, 2, 2));
1209 dprint(
"qCompat " << hitHL <<
" + " << 3.
f * qErr <<
" vs " <<
res);
1212 const float res[2]{msPar.constAt(itrack, 0, 0) - pPar.constAt(itrack, 0, 0),
1213 msPar.constAt(itrack, 1, 0) - pPar.constAt(itrack, 1, 0)};
1214 const float hitT2 = msErr.constAt(itrack, 0, 0) + msErr.constAt(itrack, 1, 1);
1215 const float hitT2inv = 1.f / hitT2;
1216 const float proj[3] = {msErr.constAt(itrack, 0, 0) * hitT2inv,
1217 msErr.constAt(itrack, 0, 1) * hitT2inv,
1218 msErr.constAt(itrack, 1, 1) * hitT2inv};
1220 sqrt(
std::abs(pErr.constAt(itrack, 0, 0) *
proj[0] + 2.f * pErr.constAt(itrack, 0, 1) *
proj[1] +
1221 pErr.constAt(itrack, 1, 1) *
proj[2]));
1222 const float resProj =
1224 dprint(
"qCompat " <<
sqrt(hitT2 * 3.
f) <<
" + " << 3.
f * qErr <<
" vs " << resProj);
1235 int itrack,
bool isBarrel,
unsigned int pcm,
unsigned int pcmMin,
const MPlexLV &pPar,
const MPlexHS &msErr) {
1242 const float hitT2 = msErr.constAt(itrack, 0, 0) + msErr.constAt(itrack, 1, 1);
1243 const float hitT2inv = 1.f / hitT2;
1244 const float proj[3] = {msErr.constAt(itrack, 0, 0) * hitT2inv,
1245 msErr.constAt(itrack, 0, 1) * hitT2inv,
1246 msErr.constAt(itrack, 1, 1) * hitT2inv};
1247 const bool detXY_OK =
1249 const float cosP =
cos(pPar.constAt(itrack, 4, 0));
1250 const float sinP =
sin(pPar.constAt(itrack, 4, 0));
1251 const float sinT =
std::abs(
sin(pPar.constAt(itrack, 5, 0)));
1254 2.
f * cosP * sinP *
proj[1]))
1261 const float qCorr = pcm * qSF;
1262 dprint(
"pcm " << pcm <<
" * " << qSF <<
" = " << qCorr <<
" vs " << pcmMin);
1263 return qCorr > pcmMin;
1271 std::vector<std::vector<TrackCand>> &tmp_candidates,
1292 int nHitsAdded[
NN]{};
1293 bool isTooLargeCluster[
NN]{
false};
1295 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1301 for (
int itrack = 0; itrack <
NN; ++itrack) {
1302 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1304 mhp.addInputAt(itrack,
hit);
1305 charge_pcm[itrack] =
hit.chargePerCM();
1353 bool oneCandPassCut =
false;
1354 for (
int itrack = 0; itrack <
NN; ++itrack) {
1355 if (itrack >= N_proc) {
1363 if (
chi2 < max_c2) {
1364 bool isCompatible =
true;
1376 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1378 isTooLargeCluster[itrack] =
true;
1379 isCompatible =
false;
1384 oneCandPassCut =
true;
1391 if (oneCandPassCut) {
1406 dprint(
"update parameters" << std::endl
1407 <<
"propagated track parameters x=" <<
m_Par[
iP].constAt(0, 0, 0)
1408 <<
" y=" <<
m_Par[
iP].constAt(0, 1, 0) << std::endl
1409 <<
" hit position x=" <<
m_msPar.constAt(0, 0, 0)
1410 <<
" y=" <<
m_msPar.constAt(0, 1, 0) << std::endl
1411 <<
" updated track parameters x=" <<
m_Par[
iC].constAt(0, 0, 0)
1412 <<
" y=" <<
m_Par[
iC].constAt(0, 1, 0));
1416 for (
int itrack = 0; itrack <
NN; ++itrack) {
1417 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1421 if (
chi2 < max_c2) {
1422 bool isCompatible =
true;
1434 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1436 isCompatible =
false;
1440 bool hitExists =
false;
1455 nHitsAdded[itrack]++;
1456 dprint(
"chi2 cut passed, creating new candidate");
1460 const int hit_idx =
m_XHitArr.At(itrack, hit_cnt, 0);
1464 newcand.
setCharge(tmpChg(itrack, 0, 0));
1473 if (
chi2 < max_c2) {
1475 ccand[
m_CandIdx(itrack, 0, 0)].considerHitForOverlap(
1483 tmp_candidates[
m_SeedIdx(itrack, 0, 0) -
offset].emplace_back(newcand);
1494 for (
int itrack = 0; itrack <
NN; ++itrack) {
1511 else if (
m_XWsrResult[itrack].m_in_gap ==
true && nHitsAdded[itrack] == 0) {
1515 else if (isTooLargeCluster[itrack] ==
true && nHitsAdded[itrack] == 0) {
1530 tmp_candidates[
m_SeedIdx(itrack, 0, 0) -
offset].emplace_back(newcand);
1559 dprintf(
"FindCandidatesCloneEngine max hits to process=%d\n",
maxSize);
1561 int nHitsAdded[
NN]{};
1562 bool isTooLargeCluster[
NN]{
false};
1564 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1570 for (
int itrack = 0; itrack <
NN; ++itrack) {
1571 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1573 mhp.addInputAt(itrack,
hit);
1574 charge_pcm[itrack] =
hit.chargePerCM();
1617 for (
int itrack = 0; itrack <
NN; ++itrack) {
1623 if ( itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1629 dprint(
"chi2=" <<
chi2 <<
" for trkIdx=" << itrack <<
" hitIdx=" <<
m_XHitArr.At(itrack, hit_cnt, 0));
1630 if (
chi2 < max_c2) {
1631 bool isCompatible =
true;
1644 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1646 isTooLargeCluster[itrack] =
true;
1647 isCompatible =
false;
1653 bool hitExists =
false;
1668 nHitsAdded[itrack]++;
1669 const int hit_idx =
m_XHitArr.At(itrack, hit_cnt, 0);
1673 if (
chi2 < max_c2) {
1674 ccand[
m_CandIdx(itrack, 0, 0)].considerHitForOverlap(
1680 tmpList.
hitIdx = hit_idx;
1692 dprint(
" adding hit with hit_cnt=" << hit_cnt <<
" for trkIdx=" << tmpList.
trkIdx 1693 <<
" orig Seed=" <<
m_Label(itrack, 0, 0));
1702 for (
int itrack = 0; itrack <
NN; ++itrack) {
1721 else if (
m_XWsrResult[itrack].m_in_gap ==
true && nHitsAdded[itrack] == 0) {
1725 else if (isTooLargeCluster[itrack] ==
true && nHitsAdded[itrack] == 0) {
1738 tmpList.
hitIdx = fake_hit_idx;
1750 dprint(
"adding invalid hit " << fake_hit_idx);
1828 const int iO = outputProp ?
iP :
iC;
1830 for (
int i = 0;
i <
NN; ++
i) {
1835 m_Err[iO].copyOut(
i,
cand.errors_nc().Array());
1836 m_Par[iO].copyOut(
i,
cand.parameters_nc().Array());
1839 dprint((outputProp ?
"propagated" :
"updated")
1840 <<
" track parameters x=" <<
cand.parameters()[0] <<
" y=" <<
cand.parameters()[1]
1841 <<
" z=" <<
cand.parameters()[2] <<
" pt=" << 1. /
cand.parameters()[3] <<
" posEta=" <<
cand.posEta());
1857 for (
int i = beg;
i < end; ++
i, ++itrack) {
1884 for (
int i = beg;
i < end; ++
i, ++itrack) {
1910 const int iO = outputProp ?
iP :
iC;
1913 for (
int i = beg;
i < end; ++
i, ++itrack) {
1931 const int iO = outputProp ?
iP :
iC;
1934 for (
int i = beg;
i < end; ++
i, ++itrack) {
1949 #if defined(DEBUG_BACKWARD_FIT) || defined(DEBUG_BACKWARD_FIT_BH) 1966 float tmp_err[6] = {666, 0, 666, 0, 0, 666};
1970 const int layer = lp_iter->m_layer;
1976 for (
int i = 0;
i < N_proc; ++
i) {
2034 for (
int n = 0;
n <
NN; ++
n) {
2035 if (
n < N_proc &&
m_Par[
iC].At(
n, 3, 0) < 0) {
2041 #ifdef DEBUG_BACKWARD_FIT_BH 2043 for (
int i = 0;
i < N_proc; ++
i) {
2052 "CHIHIT %3d %10g %10g %10g %10g %10g %11.5g %11.5g %11.5g %10g %10g %10g %10g %11.5g %11.5g %11.5g %10g " 2053 "%10g %10g %10g %10g %11.5g %11.5g\n",
2067 e2s(
m_Err[ti].At(
i, 0, 0)),
2068 e2s(
m_Err[ti].At(
i, 1, 1)),
2069 e2s(
m_Err[ti].At(
i, 2, 2)),
2070 1.0f /
m_Par[ti].At(
i, 3, 0),
2074 std::atan2(
m_Par[ti].At(
i, 1, 0),
m_Par[ti].At(
i, 0, 0)),
2094 printf(
"Parameters:\n");
2095 for (
int i = 0;
i < 6; ++
i) {
2096 printf(
" %12.4g",
m_Par[corp].constAt(mslot,
i, 0));
2098 printf(
"\nError matrix\n");
2099 for (
int i = 0;
i < 6; ++
i) {
2100 for (
int j = 0;
j < 6; ++
j) {
2101 printf(
" %12.4g",
m_Err[corp].constAt(mslot,
i,
j));
2122 float tmp_err[6] = {666, 0, 666, 0, 0, 666};
2125 #if defined(DEBUG_PROP_UPDATE) 2126 const int DSLOT = 0;
2127 printf(
"bkfit entry, track in slot %d\n", DSLOT);
2132 const int layer = lp_iter.layer();
2137 #if defined(DEBUG_BACKWARD_FIT) 2138 const Hit *last_hit_ptr[
NN];
2141 no_mat_effs.setVal(0);
2144 for (
int i = 0;
i < N_proc; ++
i) {
2164 #ifdef DEBUG_BACKWARD_FIT 2165 last_hit_ptr[
i] = &
hit;
2173 #ifdef DEBUG_BACKWARD_FIT 2174 last_hit_ptr[
i] =
nullptr;
2185 if (done_count == N_proc)
2187 if (here_count == 0)
2222 #if defined(DEBUG_PROP_UPDATE) 2223 printf(
"\nbkfit at layer %d, track in slot %d -- fail=%d, had hit=%d (%g, %g, %g)\n",
2227 1 - no_mat_effs[DSLOT],
2231 printf(
"Propagated:\n");
2233 printf(
"Updated:\n");
2238 for (
int i = 0;
i <
NN; ++
i) {
2274 if (
i < N_proc &&
m_Par[
iC].At(
i, 3, 0) < 0) {
2280 #if defined(DEBUG_BACKWARD_FIT) 2283 const char beg_cur_sep =
'/';
2284 for (
int i = 0;
i < N_proc; ++
i) {
2285 if (chiDebug && last_hit_ptr[
i]) {
2288 float chi = tmp_chi2.At(
i, 0, 0);
2289 float chi_prnt = std::isfinite(chi) ? chi : -9;
2291 #if defined(MKFIT_STANDALONE) 2294 dprintf(
"BKF_OVERLAP %d %d %d %d %d %d %d " 2295 "%f%c%f %f %f%c%f %f %f %f %d %d %d %d " 2299 dprintf(
"BKF_OVERLAP %d %d %d %d %d %d " 2300 "%f%c%f %f %f%c%f %f %f %f %d %d %d " 2304 layer,
L.is_stereo(),
L.is_barrel(),
2305 bb.
pT(), beg_cur_sep, 1.0f /
m_Par[ti].At(
i, 3, 0),
2311 std::isnan(chi), std::isfinite(chi), chi > 0,
2312 #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)