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];
253 pnt.At(itrack, 0, 0) = mi.
pos[0];
254 pnt.At(itrack, 1, 0) = mi.
pos[1];
255 pnt.At(itrack, 2, 0) = mi.
pos[2];
267 const float invpt,
const float theta,
float &min_dq,
float &max_dq,
float &min_dphi,
float &max_dphi) {
268 float max_invpt =
std::min(invpt, 10.0
f);
270 enum SelWinParameters_e { dp_sf = 0, dp_0, dp_1, dp_2, dq_sf, dq_0, dq_1, dq_2 };
275 const float this_dq =
v[dq_sf] * (
v[dq_0] * max_invpt +
v[dq_1] *
theta +
v[dq_2]);
279 max_dq = 2.0f * min_dq;
283 const float this_dphi =
v[dp_sf] * (
v[dp_0] * max_invpt +
v[dp_1] *
theta +
v[dp_2]);
285 if (this_dphi > min_dphi) {
286 min_dphi = this_dphi;
287 max_dphi = 2.0f * min_dphi;
299 const float invpt =
m_Par[ipar].At(itrk, 3, 0);
302 float max_invpt =
std::min(invpt, 10.0
f);
304 enum SelWinParameters_e { c2_sf = 8, c2_0, c2_1, c2_2 };
308 float this_c2 =
v[c2_sf] * (
v[c2_0] * max_invpt +
v[c2_1] *
theta +
v[c2_2]);
310 if (this_c2 > minChi2Cut)
330 const float nSigmaR = 3;
332 dprintf(
"LayerOfHits::SelectHitIndices %s layer=%d N_proc=%d\n",
333 L.is_barrel() ?
"barrel" :
"endcap",
337 float dqv[
NN], dphiv[
NN], qv[
NN], phiv[
NN];
338 bidx_t qb1v[
NN], qb2v[
NN], qbv[
NN], pb1v[
NN], pb2v[
NN];
340 const auto assignbins = [&](
int itrack,
349 dphi = std::clamp(
std::abs(dphi), min_dphi, max_dphi);
350 dq = std::clamp(dq, min_dq, max_dq);
354 dphiv[itrack] = dphi;
357 qbv[itrack] =
L.qBinChecked(
q);
358 qb1v[itrack] =
L.qBinChecked(
q - dq);
359 qb2v[itrack] =
L.qBinChecked(
q + dq) + 1;
360 pb1v[itrack] =
L.phiBinChecked(phi - dphi);
361 pb2v[itrack] =
L.phiMaskApply(
L.phiBin(phi + dphi) + 1);
364 const auto calcdphi2 = [&](
int itrack,
float dphidx,
float dphidy) {
365 return dphidx * dphidx *
m_Err[iI].constAt(itrack, 0, 0) + dphidy * dphidy *
m_Err[iI].constAt(itrack, 1, 1) +
366 2 * dphidx * dphidy *
m_Err[iI].constAt(itrack, 0, 1);
369 const auto calcdphi = [&](
float dphi2,
float min_dphi) {
379 #if !defined(__clang__) 382 for (
int itrack = 0; itrack <
NN; ++itrack) {
383 if (itrack >= N_proc)
387 float min_dq = ILC.
min_dq();
388 float max_dq = ILC.
max_dq();
392 const float invpt =
m_Par[iI].At(itrack, 3, 0);
396 const float x =
m_Par[iI].constAt(itrack, 0, 0);
397 const float y =
m_Par[iI].constAt(itrack, 1, 0);
398 const float r2 =
x *
x + y * y;
399 const float dphidx = -y /
r2, dphidy =
x /
r2;
400 const float dphi2 = calcdphi2(itrack, dphidx, dphidy);
405 const float phi =
getPhi(
x, y);
406 float dphi = calcdphi(dphi2, min_dphi);
408 const float z =
m_Par[iI].constAt(itrack, 2, 0);
410 const float edgeCorr =
415 assignbins(itrack, z,
dz, phi, dphi, min_dq, max_dq, min_dphi, max_dphi);
425 const float layerD =
std::abs(
L.layer_info().zmax() -
L.layer_info().zmin()) * 0.5
f *
428 #if !defined(__clang__) 431 for (
int itrack = 0; itrack <
NN; ++itrack) {
434 float min_dq = ILC.
min_dq();
435 float max_dq = ILC.
max_dq();
439 const float invpt =
m_Par[iI].At(itrack, 3, 0);
443 const float x =
m_Par[iI].constAt(itrack, 0, 0);
444 const float y =
m_Par[iI].constAt(itrack, 1, 0);
445 const float r2 =
x *
x + y * y;
446 const float r2Inv = 1.f /
r2;
447 const float dphidx = -y * r2Inv, dphidy =
x * r2Inv;
448 const float phi =
getPhi(
x, y);
450 calcdphi2(itrack, dphidx, dphidy)
458 float dphi = calcdphi(dphi2, min_dphi);
462 y * y *
m_Err[iI].constAt(itrack, 1, 1) +
463 2 *
x * y *
m_Err[iI].constAt(itrack, 0, 1)) /
465 const float edgeCorr =
std::abs(0.5
f * (
L.layer_info().zmax() -
L.layer_info().zmin()) *
469 assignbins(itrack, r, dr, phi, dphi, min_dq, max_dq, min_dphi, max_dphi);
473 #ifdef RNT_DUMP_MkF_SelHitIdcs 474 if (fill_binsearch_only) {
476 for (
auto i : rnt_shi.f_h_idcs) {
477 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[
i]];
496 for (
int itrack = 0; itrack <
NN; ++itrack) {
497 if (itrack >= N_proc) {
511 const bidx_t qb = qbv[itrack];
512 const bidx_t qb1 = qb1v[itrack];
513 const bidx_t qb2 = qb2v[itrack];
514 const bidx_t pb1 = pb1v[itrack];
515 const bidx_t pb2 = pb2v[itrack];
517 const float q = qv[itrack];
518 const float phi = phiv[itrack];
519 const float dphi = dphiv[itrack];
520 const float dq = dqv[itrack];
523 dprintf(
" %2d/%2d: %6.3f %6.3f %6.6f %7.5f %3u %3u %4u %4u\n",
524 L.layer_id(), itrack,
q, phi, dq, dphi,
528 #if defined(DUMPHITWINDOW) && defined(MKFIT_STANDALONE) 529 const auto ngr = [](
float f) {
return isFinite(
f) ?
f : -999.0f; };
536 for (bidx_t qi = qb1; qi != qb2; ++qi) {
537 for (bidx_t
pi = pb1;
pi != pb2;
pi =
L.phiMaskApply(
pi + 1)) {
539 if (qi == qb &&
L.isBinDead(
pi, qi) ==
true) {
540 dprint(
"dead module for track in layer=" <<
L.layer_id() <<
" qb=" << qi <<
" pi=" <<
pi <<
" q=" <<
q 553 auto pbi =
L.phiQBinContent(
pi, qi);
554 for (bcnt_t
hi = pbi.begin();
hi < pbi.end(); ++
hi) {
557 const unsigned int hi_orig =
L.getOriginalHitIndex(
hi);
561 "Yay, denying masked hit on layer %u, hi %u, orig idx %u\n",
L.layer_info().layer_id(),
hi, hi_orig);
573 dprintf(
" SHI %3u %4u %5u %6.3f %6.3f %6.4f %7.5f %s\n",
575 ddq, ddphi, (ddq < dq && ddphi < dphi) ?
"PASS" :
"FAIL");
578 #if defined(DUMPHITWINDOW) && defined(MKFIT_STANDALONE) 584 int st_isfindable = 0;
585 int st_label = -999999;
592 float st_eta = -999.;
593 float st_phi = -999.;
597 st_label = simtrack.
label();
599 st_pt = simtrack.
pT();
600 st_eta = simtrack.
momEta();
601 st_phi = simtrack.
momPhi();
603 st_charge = simtrack.
charge();
604 st_r = simtrack.
posR();
608 const Hit &thishit =
L.refHit(hi_orig);
627 float hx = thishit.
x();
628 float hy = thishit.
y();
629 float hz = thishit.
z();
636 (hx * hx * thishit.
exx() + hy * hy * thishit.
eyy() + 2.0f * hx * hy *
m_msErr.At(itrack, 0, 1)) /
639 float hchi2 = ngr( thisOutChi2[itrack] );
640 float tx =
m_Par[iI].At(itrack, 0, 0);
641 float ty =
m_Par[iI].At(itrack, 1, 0);
642 float tz =
m_Par[iI].At(itrack, 2, 0);
650 (tx * tx *
tex *
tex + ty * ty * tey * tey + 2.0
f * tx * ty *
m_Err[iI].At(itrack, 0, 1)) /
653 (ty * ty *
tex *
tex + tx * tx * tey * tey - 2.0
f * tx * ty *
m_Err[iI].At(itrack, 0, 1)) /
654 (tr * tr * tr * tr)) );
656 float ht_dz = hz - tz;
659 static bool first =
true;
663 "evt_id/I:track_algo/I:" 664 "lyr_id/I:lyr_isbrl/I:hit_idx/I:" 665 "trk_cnt/I:trk_idx/I:trk_label/I:" 666 "trk_pt/F:trk_eta/F:trk_mphi/F:trk_chi2/F:" 668 "seed_idx/I:seed_label/I:seed_mcid/I:" 670 "st_isfindable/I:st_prodtype/I:st_label/I:" 671 "st_pt/F:st_eta/F:st_phi/F:" 672 "st_nhits/I:st_charge/I:st_r/F:st_z/F:" 673 "trk_q/F:hit_q/F:dq_trkhit/F:dq_cut/F:trk_phi/F:hit_phi/F:dphi_trkhit/F:dphi_cut/F:" 674 "t_x/F:t_y/F:t_r/F:t_phi/F:t_z/F:" 675 "t_ex/F:t_ey/F:t_er/F:t_ephi/F:t_ez/F:" 676 "h_x/F:h_y/F:h_r/F:h_phi/F:h_z/F:" 677 "h_ex/F:h_ey/F:h_er/F:h_ephi/F:h_ez/F:" 678 "ht_dxy/F:ht_dz/F:ht_dphi/F:" 686 printf(
"HITWINDOWSEL " 690 "%6.3f %6.3f %6.3f %6.3f " 697 "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f " 698 "%6.3f %6.3f %6.3f %6.3f %6.3f " 699 "%6.6f %6.6f %6.6f %6.6f %6.6f " 700 "%6.3f %6.3f %6.3f %6.3f %6.3f " 701 "%6.6f %6.6f %6.6f %6.6f %6.6f " 706 L.layer_id(),
L.is_barrel(), hi_orig,
708 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),
712 st_isfindable, st_prodtype, st_label,
713 st_pt, st_eta, st_phi,
714 st_nhits, st_charge, st_r, st_z,
715 q,
L.hit_q(
hi), ddq, dq, phi,
L.hit_phi(
hi), ddphi, dphi,
716 tx, ty, tr, tphi, tz,
717 tex, tey, ter, tephi, tez,
718 hx, hy, hr, hphi, hz,
719 hex, hey, her, hephi, hez,
720 ht_dxy, ht_dz, ht_dphi,
744 assert(
false &&
"this code has not been used in a while -- see comments in code");
769 dprintf(
"LayerOfHits::SelectHitIndicesV2 %s layer=%d N_proc=%d\n",
770 L.is_barrel() ?
"barrel" :
"endcap",
774 #ifdef RNT_DUMP_MkF_SelHitIdcs 775 rnt_shi.InnerIdcsReset(N_proc);
777 for (
int i = 0;
i < N_proc; ++
i) {
781 }
else if (sim_lbls[
i].is_set()) {
794 constexpr float PHI_BIN_EXTRA_FAC = 2.75f;
797 namespace mp = mini_propagators;
800 mp::InitialStatePlex isp;
801 mp::StatePlex sp1, sp2;
812 void prop_to_limits(
const LayerInfo &li) {
838 phi_c = 0.5f * (pmax +
pmin);
853 return x *
x *
err.ReduceFixedIJ(0, 0) + y * y *
err.ReduceFixedIJ(1, 1) +
854 2.0f *
x * y *
err.ReduceFixedIJ(0, 1);
858 MPlexQF r2_c = isp.x * isp.x + isp.y * isp.y;
860 MPlexQF dphidx_c = -isp.y * r2inv_c;
861 MPlexQF dphidy_c = isp.x * r2inv_c;
862 dphi_track = 3.0f * calc_err_xy(dphidx_c, dphidy_c).abs().sqrt();
868 dq_track = 3.0f *
err.ReduceFixedIJ(2, 2).abs().sqrt();
872 dq_track = 3.0f * (r2inv_c * calc_err_xy(isp.x, isp.y).abs()).
sqrt();
875 for (
int i = 0;
i <
p1.kTotSize; ++
i) {
891 B.prop_to_limits(LI);
892 B.find_bin_ranges(LI,
L,
m_Err[iI]);
894 for (
int i = 0;
i <
NN; ++
i) {
916 #ifdef RNT_DUMP_MkF_SelHitIdcs 917 for (
auto i : rnt_shi.f_h_idcs) {
918 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[
i]];
922 0.5f * (
B.q2[
i] -
B.q1[
i]),
937 unsigned int hit_index;
939 auto pqe_cmp = [](
const PQE &
a,
const PQE &
b) {
return a.score <
b.score; };
940 std::priority_queue<PQE, std::vector<PQE>, decltype(pqe_cmp)> pqueue(pqe_cmp);
945 for (
int itrack = 0; itrack <
NN; ++itrack) {
946 if (itrack >= N_proc) {
961 const bidx_t qb =
B.q0[itrack];
962 const bidx_t qb1 =
B.q1[itrack];
963 const bidx_t qb2 =
B.q2[itrack];
964 const bidx_t pb1 =
B.p1[itrack];
965 const bidx_t pb2 =
B.p2[itrack];
968 dprintf(
" %2d/%2d: %6.3f %6.3f %6.6f %7.5f %3u %3u %4u %4u\n",
969 L.layer_id(), itrack,
B.q_c[itrack],
B.phi_c[itrack],
970 B.qmax[itrack] -
B.qmin[itrack],
B.dphi[itrack],
972 #ifdef RNT_DUMP_MkF_SelHitIdcs 975 struct pos_match {
float dphi, dq;
int idx;
bool matched; };
976 std::vector<pos_match> pos_match_vec;
980 mp::InitialState mp_is(
m_Par[iI],
m_Chg, itrack);
983 for (bidx_t qi = qb1; qi != qb2; ++qi) {
984 for (bidx_t
pi = pb1;
pi != pb2;
pi =
L.phiMaskApply(
pi + 1)) {
986 if (qi == qb &&
L.isBinDead(
pi, qi) ==
true) {
987 dprint(
"dead module for track in layer=" <<
L.layer_id() <<
" qb=" << qi <<
" pi=" <<
pi 988 <<
" q=" <<
B.q_c[itrack] <<
" phi=" <<
B.phi_c[itrack]);
998 auto pbi =
L.phiQBinContent(
pi, qi);
999 for (bcnt_t
hi = pbi.begin();
hi < pbi.end(); ++
hi) {
1002 const unsigned int hi_orig =
L.getOriginalHitIndex(
hi);
1006 "Yay, denying masked hit on layer %u, hi %u, orig idx %u\n",
L.layer_info().layer_id(),
hi, hi_orig);
1010 float new_q, new_phi, new_ddphi, new_ddq;
1013 if (
L.is_barrel()) {
1014 const Hit &
hit =
L.refHit(hi_orig);
1015 unsigned int mid =
hit.detIDinLayer();
1023 prop_fail = mp_is.propagate_to_plane(
mp::PA_Line, mi, mp_s,
true);
1038 prop_fail = mp_is.propagate_to_r(
mp::PA_Exact,
L.hit_qbar(
hi), mp_s,
true);
1043 prop_fail = mp_is.propagate_to_z(
mp::PA_Exact,
L.hit_qbar(
hi), mp_s,
true);
1048 new_phi = vdt::fast_atan2f(mp_s.y, mp_s.x);
1050 bool dqdphi_presel = new_ddq <
B.dq_track[itrack] + DDQ_PRESEL_FAC *
L.hit_q_half_length(
hi) &&
1051 new_ddphi <
B.dphi_track[itrack] + DDPHI_PRESEL_FAC * 0.0123f;
1054 dprintf(
" SHI %3u %4u %5u %6.3f %6.3f %6.4f %7.5f PROP-%s %s\n",
1056 new_ddq, new_ddphi, prop_fail ?
"FAIL" :
"OK", dqdphi_presel ?
"PASS" :
"REJECT");
1057 #ifdef RNT_DUMP_MkF_SelHitIdcs 1058 if (rnt_shi.f_h_remap[itrack] >= 0) {
1059 int sim_lbl = sim_lbls[itrack].
label;
1060 const Hit &thishit =
L.refHit(hi_orig);
1070 thisOutChi2, tmpPropPar, propFail, N_proc,
1073 float hchi2 = thisOutChi2[itrack];
1075 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[itrack]];
1078 int hit_lbl = mchinfo.mcTrackID();
1081 new_q,
L.hit_q_half_length(
hi),
L.hit_qbar(
hi), new_phi,
1084 new_ddq, new_ddphi, hchi2, (
int) hi_orig,
1085 (sim_lbl == hit_lbl), dqdphi_presel, !prop_fail,
1088 ci.
hmi.back().ic2list.reset();
1090 bool new_dec = dqdphi_presel && !prop_fail;
1092 if (sim_lbl == hit_lbl) {
1098 pos_match_vec.emplace_back(pos_match{ new_ddphi, new_ddq, hit_out_idx++,
1099 sim_lbl == hit_lbl });
1104 if (prop_fail || !dqdphi_presel)
1106 if (pqueue_size < NEW_MAX_HIT) {
1107 pqueue.push({new_ddphi, hi_orig});
1109 }
else if (new_ddphi < pqueue.top().score) {
1111 pqueue.push({new_ddphi, hi_orig});
1117 dprintf(
" PQUEUE (%d)", pqueue_size);
1118 #ifdef RNT_DUMP_MkF_SelHitIdcs 1120 if (sim_lbls[itrack].is_set()) {
1122 std::sort(pos_match_vec.begin(), pos_match_vec.end(),
1123 [](
auto &
a,
auto &
b){
return a.dphi <
b.dphi;});
1124 int pmvs = pos_match_vec.size();
1126 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[itrack]];
1127 for (
int i = 0;
i < pmvs; ++
i) {
1140 while (pqueue_size) {
1142 m_XHitArr.At(itrack, pqueue_size, 0) = pqueue.top().hit_index;
1143 dprintf(
" %d: %f %d", pqueue_size, pqueue.top().score, pqueue.top().hit_index);
1176 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1182 for (
int itrack = 0; itrack <
NN; ++itrack) {
1183 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1184 mhp.addInputAt(itrack, layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)));
1208 for (
int itrack = 0; itrack <
NN; ++itrack) {
1209 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1214 bestHit[itrack] =
m_XHitArr.At(itrack, hit_cnt, 0);
1221 for (
int itrack = 0; itrack <
NN; ++itrack) {
1222 if (itrack >= N_proc) {
1228 m_msErr.setDiagonal3x3(itrack, 666);
1243 if (bestHit[itrack] >= 0) {
1244 const Hit &
hit = layer_of_hits.
refHit(bestHit[itrack]);
1247 dprint(
"ADD BEST HIT FOR TRACK #" 1248 << itrack << std::endl
1249 <<
"prop x=" <<
m_Par[
iP].constAt(itrack, 0, 0) <<
" y=" <<
m_Par[
iP].constAt(itrack, 1, 0) << std::endl
1250 <<
"copy in hit #" << bestHit[itrack] <<
" x=" <<
hit.position()[0] <<
" y=" <<
hit.position()[1]);
1270 m_msErr.setDiagonal3x3(itrack, 666);
1283 dprint(
"update parameters");
1297 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));
1307 const float res =
std::abs(msPar.constAt(itrack, 2, 0) - pPar.constAt(itrack, 2, 0));
1308 const float hitHL =
sqrt(msErr.constAt(itrack, 2, 2) * 3.f);
1309 const float qErr =
sqrt(pErr.constAt(itrack, 2, 2));
1310 dprint(
"qCompat " << hitHL <<
" + " << 3.
f * qErr <<
" vs " <<
res);
1313 const float res[2]{msPar.constAt(itrack, 0, 0) - pPar.constAt(itrack, 0, 0),
1314 msPar.constAt(itrack, 1, 0) - pPar.constAt(itrack, 1, 0)};
1315 const float hitT2 = msErr.constAt(itrack, 0, 0) + msErr.constAt(itrack, 1, 1);
1316 const float hitT2inv = 1.f / hitT2;
1317 const float proj[3] = {msErr.constAt(itrack, 0, 0) * hitT2inv,
1318 msErr.constAt(itrack, 0, 1) * hitT2inv,
1319 msErr.constAt(itrack, 1, 1) * hitT2inv};
1321 sqrt(
std::abs(pErr.constAt(itrack, 0, 0) *
proj[0] + 2.f * pErr.constAt(itrack, 0, 1) *
proj[1] +
1322 pErr.constAt(itrack, 1, 1) *
proj[2]));
1323 const float resProj =
1325 dprint(
"qCompat " <<
sqrt(hitT2 * 3.
f) <<
" + " << 3.
f * qErr <<
" vs " << resProj);
1336 int itrack,
bool isBarrel,
unsigned int pcm,
unsigned int pcmMin,
const MPlexLV &pPar,
const MPlexHS &msErr) {
1343 const float hitT2 = msErr.constAt(itrack, 0, 0) + msErr.constAt(itrack, 1, 1);
1344 const float hitT2inv = 1.f / hitT2;
1345 const float proj[3] = {msErr.constAt(itrack, 0, 0) * hitT2inv,
1346 msErr.constAt(itrack, 0, 1) * hitT2inv,
1347 msErr.constAt(itrack, 1, 1) * hitT2inv};
1348 const bool detXY_OK =
1350 const float cosP =
cos(pPar.constAt(itrack, 4, 0));
1351 const float sinP =
sin(pPar.constAt(itrack, 4, 0));
1352 const float sinT =
std::abs(
sin(pPar.constAt(itrack, 5, 0)));
1355 2.
f * cosP * sinP *
proj[1]))
1362 const float qCorr = pcm * qSF;
1363 dprint(
"pcm " << pcm <<
" * " << qSF <<
" = " << qCorr <<
" vs " << pcmMin);
1364 return qCorr > pcmMin;
1372 std::vector<std::vector<TrackCand>> &tmp_candidates,
1393 int nHitsAdded[
NN]{};
1394 bool isTooLargeCluster[
NN]{
false};
1396 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1402 for (
int itrack = 0; itrack <
NN; ++itrack) {
1403 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1405 mhp.addInputAt(itrack,
hit);
1406 charge_pcm[itrack] =
hit.chargePerCM();
1455 bool oneCandPassCut =
false;
1456 for (
int itrack = 0; itrack <
NN; ++itrack) {
1457 if (itrack >= N_proc) {
1465 if (
chi2 < max_c2) {
1466 bool isCompatible =
true;
1480 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1482 isTooLargeCluster[itrack] =
true;
1483 isCompatible =
false;
1488 oneCandPassCut =
true;
1495 if (oneCandPassCut) {
1510 dprint(
"update parameters" << std::endl
1511 <<
"propagated track parameters x=" <<
m_Par[
iP].constAt(0, 0, 0)
1512 <<
" y=" <<
m_Par[
iP].constAt(0, 1, 0) << std::endl
1513 <<
" hit position x=" <<
m_msPar.constAt(0, 0, 0)
1514 <<
" y=" <<
m_msPar.constAt(0, 1, 0) << std::endl
1515 <<
" updated track parameters x=" <<
m_Par[
iC].constAt(0, 0, 0)
1516 <<
" y=" <<
m_Par[
iC].constAt(0, 1, 0));
1520 for (
int itrack = 0; itrack <
NN; ++itrack) {
1521 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1525 if (
chi2 < max_c2) {
1526 bool isCompatible =
true;
1529 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1532 isCompatible =
false;
1546 bool hitExists =
false;
1561 nHitsAdded[itrack]++;
1562 dprint(
"chi2 cut passed, creating new candidate");
1566 const int hit_idx =
m_XHitArr.At(itrack, hit_cnt, 0);
1570 newcand.
setCharge(tmpChg(itrack, 0, 0));
1579 if (
chi2 < max_c2) {
1581 ccand[
m_CandIdx(itrack, 0, 0)].considerHitForOverlap(
1589 tmp_candidates[
m_SeedIdx(itrack, 0, 0) -
offset].emplace_back(newcand);
1600 for (
int itrack = 0; itrack <
NN; ++itrack) {
1617 else if (
m_XWsrResult[itrack].m_in_gap ==
true && nHitsAdded[itrack] == 0) {
1621 else if (isTooLargeCluster[itrack] ==
true && nHitsAdded[itrack] == 0) {
1636 tmp_candidates[
m_SeedIdx(itrack, 0, 0) -
offset].emplace_back(newcand);
1665 dprintf(
"FindCandidatesCloneEngine max hits to process=%d\n",
maxSize);
1667 int nHitsAdded[
NN]{};
1668 bool isTooLargeCluster[
NN]{
false};
1670 for (
int hit_cnt = 0; hit_cnt <
maxSize; ++hit_cnt) {
1676 for (
int itrack = 0; itrack <
NN; ++itrack) {
1677 if (itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1679 mhp.addInputAt(itrack,
hit);
1680 charge_pcm[itrack] =
hit.chargePerCM();
1722 for (
int itrack = 0; itrack <
NN; ++itrack) {
1728 if ( itrack < N_proc && hit_cnt <
m_XHitSize[itrack]) {
1734 dprintf(
" chi2=%.3f (%.3f) trkIdx=%d hitIdx=%d\n",
chi2, max_c2, itrack,
m_XHitArr.At(itrack, hit_cnt, 0));
1735 if (
chi2 < max_c2) {
1736 bool isCompatible =
true;
1739 if (layer_of_hits.
refHit(
m_XHitArr.At(itrack, hit_cnt, 0)).spanRows() >=
1741 isTooLargeCluster[itrack] =
true;
1742 isCompatible =
false;
1757 bool hitExists =
false;
1772 nHitsAdded[itrack]++;
1773 const int hit_idx =
m_XHitArr.At(itrack, hit_cnt, 0);
1777 if (
chi2 < max_c2) {
1778 ccand[
m_CandIdx(itrack, 0, 0)].considerHitForOverlap(
1784 tmpList.
hitIdx = hit_idx;
1796 dprint(
" adding hit with hit_cnt=" << hit_cnt <<
" for trkIdx=" << tmpList.
trkIdx 1797 <<
" orig Seed=" <<
m_Label(itrack, 0, 0));
1799 #ifdef RNT_DUMP_MkF_SelHitIdcs 1800 if (rnt_shi.f_h_remap[itrack] >= 0) {
1801 CandInfo &ci = (*rnt_shi.ci)[rnt_shi.f_h_remap[itrack]];
1813 for (
int itrack = 0; itrack <
NN; ++itrack) {
1832 else if (
m_XWsrResult[itrack].m_in_gap ==
true && nHitsAdded[itrack] == 0) {
1836 else if (isTooLargeCluster[itrack] ==
true && nHitsAdded[itrack] == 0) {
1849 tmpList.
hitIdx = fake_hit_idx;
1861 dprint(
"adding invalid hit " << fake_hit_idx);
1938 const int iO = outputProp ?
iP :
iC;
1940 for (
int i = 0;
i <
NN; ++
i) {
1945 m_Err[iO].copyOut(
i,
cand.errors_nc().Array());
1946 m_Par[iO].copyOut(
i,
cand.parameters_nc().Array());
1949 dprint((outputProp ?
"propagated" :
"updated")
1950 <<
" track parameters x=" <<
cand.parameters()[0] <<
" y=" <<
cand.parameters()[1]
1951 <<
" z=" <<
cand.parameters()[2] <<
" pt=" << 1. /
cand.parameters()[3] <<
" posEta=" <<
cand.posEta());
1967 for (
int i = beg;
i < end; ++
i, ++itrack) {
1970 m_Chg(itrack, 0, 0) =
trk.charge();
1994 for (
int i = beg;
i < end; ++
i, ++itrack) {
1997 m_Chg(itrack, 0, 0) =
trk.charge();
2020 const int iO = outputProp ?
iP :
iC;
2023 for (
int i = beg;
i < end; ++
i, ++itrack) {
2026 m_Err[iO].copyOut(itrack,
trk.errors_nc().Array());
2027 m_Par[iO].copyOut(itrack,
trk.parameters_nc().Array());
2041 const int iO = outputProp ?
iP :
iC;
2044 for (
int i = beg;
i < end; ++
i, ++itrack) {
2047 m_Err[iO].copyOut(itrack,
trk.errors_nc().Array());
2048 m_Par[iO].copyOut(itrack,
trk.parameters_nc().Array());
2059 #if defined(DEBUG_BACKWARD_FIT) || defined(DEBUG_BACKWARD_FIT_BH) 2076 float tmp_err[6] = {666, 0, 666, 0, 0, 666};
2080 const int layer = lp_iter->m_layer;
2086 for (
int i = 0;
i < N_proc; ++
i) {
2144 for (
int n = 0;
n <
NN; ++
n) {
2145 if (
n < N_proc &&
m_Par[
iC].At(
n, 3, 0) < 0) {
2151 #ifdef DEBUG_BACKWARD_FIT_BH 2153 for (
int i = 0;
i < N_proc; ++
i) {
2162 "CHIHIT %3d %10g %10g %10g %10g %10g %11.5g %11.5g %11.5g %10g %10g %10g %10g %11.5g %11.5g %11.5g %10g " 2163 "%10g %10g %10g %10g %11.5g %11.5g\n",
2177 e2s(
m_Err[ti].At(
i, 0, 0)),
2178 e2s(
m_Err[ti].At(
i, 1, 1)),
2179 e2s(
m_Err[ti].At(
i, 2, 2)),
2180 1.0f /
m_Par[ti].At(
i, 3, 0),
2204 printf(
"Parameters:\n");
2205 for (
int i = 0;
i < 6; ++
i) {
2206 printf(
" %12.4g",
m_Par[corp].constAt(mslot,
i, 0));
2208 printf(
"\nError matrix\n");
2209 for (
int i = 0;
i < 6; ++
i) {
2210 for (
int j = 0;
j < 6; ++
j) {
2211 printf(
" %12.4g",
m_Err[corp].constAt(mslot,
i,
j));
2232 float tmp_err[6] = {666, 0, 666, 0, 0, 666};
2235 #if defined(DEBUG_PROP_UPDATE) 2236 const int DSLOT = 0;
2237 printf(
"bkfit entry, track in slot %d\n", DSLOT);
2242 const int layer = lp_iter.layer();
2247 #if defined(DEBUG_BACKWARD_FIT) 2248 const Hit *last_hit_ptr[
NN];
2251 no_mat_effs.setVal(0);
2254 for (
int i = 0;
i < N_proc; ++
i) {
2274 #ifdef DEBUG_BACKWARD_FIT 2275 last_hit_ptr[
i] = &
hit;
2283 #ifdef DEBUG_BACKWARD_FIT 2284 last_hit_ptr[
i] =
nullptr;
2295 if (done_count == N_proc)
2297 if (here_count == 0)
2332 #if defined(DEBUG_PROP_UPDATE) 2333 printf(
"\nbkfit at layer %d, track in slot %d -- fail=%d, had hit=%d (%g, %g, %g)\n",
2337 1 - no_mat_effs[DSLOT],
2341 printf(
"Propagated:\n");
2343 printf(
"Updated:\n");
2348 for (
int i = 0;
i <
NN; ++
i) {
2384 if (
i < N_proc &&
m_Par[
iC].At(
i, 3, 0) < 0) {
2390 #if defined(DEBUG_BACKWARD_FIT) 2393 const char beg_cur_sep =
'/';
2394 for (
int i = 0;
i < N_proc; ++
i) {
2395 if (chiDebug && last_hit_ptr[
i]) {
2398 float chi = tmp_chi2.At(
i, 0, 0);
2399 float chi_prnt = std::isfinite(chi) ? chi : -9;
2401 #if defined(MKFIT_STANDALONE) 2404 dprintf(
"BKF_OVERLAP %d %d %d %d %d %d %d " 2405 "%f%c%f %f %f%c%f %f %f %f %d %d %d %d " 2409 dprintf(
"BKF_OVERLAP %d %d %d %d %d %d " 2410 "%f%c%f %f %f%c%f %f %f %f %d %d %d " 2414 layer,
L.is_stereo(),
L.is_barrel(),
2415 bb.
pT(), beg_cur_sep, 1.0f /
m_Par[ti].At(
i, 3, 0),
2421 std::isnan(chi), std::isfinite(chi), chi > 0,
2422 #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 packModuleNormDirPnt(const LayerOfHits &layer_of_hits, int hit_cnt, MPlexHV &norm, MPlexHV &dir, MPlexHV &pnt, 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)
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
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)
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)
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 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)
void kalmanPropagateAndComputeChi2Plane(const MPlexLS &psErr, const MPlexLV &psPar, const MPlexQI &inChg, const MPlexHS &msErr, const MPlexHV &msPar, const MPlexHV &plNrm, const MPlexHV &plDir, const MPlexHV &plPnt, MPlexQF &outChi2, MPlexLV &propPar, MPlexQI &outFailFlag, const int N_proc, const PropagationFlags &propFlags, const bool propToHit)
Matriplex::MatriplexSym< float, LL, NN > MPlexLS
const std::vector< bool > * m_iteration_hit_mask
PropagationFlags finding_intra_layer_pflags
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)
static constexpr int kHitEdgeIdx
bool assignIdxChi2List(const mkfit::IdxChi2List &ic2l)
CombCandidate & combCandWithOriginalIndex(int idx)
static unsigned int minChargePerCM()
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
MPlex< T, D1, D2, N > atan2(const MPlex< T, D1, D2, N > &y, const MPlex< T, D1, D2, N > &x)
void addBestHit(const LayerOfHits &layer_of_hits, const int N_proc, const FindingFoos &fnd_foos)
constexpr bool isFinite(float x)
void kalmanPropagateAndUpdatePlane(const MPlexLS &psErr, const MPlexLV &psPar, MPlexQI &Chg, const MPlexHS &msErr, const MPlexHV &msPar, const MPlexHV &plNrm, const MPlexHV &plDir, const MPlexHV &plPnt, MPlexLS &outErr, MPlexLV &outPar, MPlexQI &outFailFlag, const int N_proc, const PropagationFlags &propFlags, const bool propToHit)