4 #include <boost/algorithm/string/classification.hpp> 5 #include <boost/algorithm/string/split.hpp> 17 #include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h" 18 #include "larevt/CalibrationDBI/Interface/ChannelStatusService.h" 50 using namespace detail;
66 std::vector<int> dtrs;
67 for (
auto& dtj : slc.
tjs) {
68 if (dtj.AlgMod[
kKilled])
continue;
69 if (dtj.ParentID != muTj.
ID)
continue;
70 dtrs.push_back(dtj.ID);
72 if (prt)
mf::LogVerbatim(
"TC") <<
"MakeHaloTj: Killing delta-ray T" << dtj.ID;
76 if (pfpIndex == USHRT_MAX) {
77 if (prt)
mf::LogVerbatim(
"TC") <<
" No PFP found for 3D-matched delta-ray";
80 auto& pfp = slc.
pfps[pfpIndex];
81 if (prt)
mf::LogVerbatim(
"TC") <<
" Killing delta-ray PFParticle P" << pfp.UID;
84 if (pfp.ParentUID > 0) {
86 if (parentIndx.first != USHRT_MAX) {
87 auto& parent =
slices[parentIndx.first].pfps[parentIndx.second];
88 std::vector<int> newDtrUIDs;
89 for (
auto uid : parent.DtrUIDs)
90 if (uid != dtj.UID) newDtrUIDs.push_back(uid);
91 parent.DtrUIDs = newDtrUIDs;
103 tj.
ID = slc.
tjs.size() + 1;
119 std::vector<int> closeTjs;
120 for (
unsigned short ipt = muTj.
EndPt[0]; ipt <= muTj.
EndPt[1]; ++ipt) {
121 auto tp = muTj.
Pts[ipt];
132 if (tp.Dir[0] != 0) window *=
std::abs(1 / tp.Dir[0]);
135 bool hitsAdded =
false;
136 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
137 unsigned int iht = tp.Hits[ii];
138 auto inTraj = slc.
slHits[iht].InTraj;
139 if (inTraj < 0)
continue;
141 tp.UseHit[ii] =
true;
147 if (inTraj != muTj.
ID &&
148 std::find(closeTjs.begin(), closeTjs.end(), inTraj) == closeTjs.end())
149 closeTjs.push_back(inTraj);
156 tj.
Pts.push_back(tp);
159 if (tj.
Pts.empty())
return;
163 myprt <<
"MHTj: T" << muTj.
ID <<
" npts " << tj.
Pts.size() <<
" close";
164 for (
auto tid : closeTjs)
165 myprt <<
" T" << tid;
169 slc.
tjs.push_back(tj);
206 for (
auto& tj : slc.
tjs) {
207 if (tj.AlgMod[
kKilled])
continue;
214 std::vector<int> temp;
215 for (
auto& vx3 : slc.
vtx3s) {
216 if (vx3.ID == 0)
continue;
219 temp.push_back(vx3.ID);
221 if (temp.empty())
return;
224 std::vector<int> masterlist;
225 for (
auto vx3id : temp) {
226 auto& vx3 = slc.
vtx3s[vx3id - 1];
229 for (
auto tjid : tjlist) {
230 auto& tj = slc.
tjs[tjid - 1];
231 if (tj.ParentID != 0) tj.ParentID = 0;
232 if (std::find(masterlist.begin(), masterlist.end(), tjid) == masterlist.end())
233 masterlist.push_back(tjid);
238 myprt <<
"DTP: masterlist Tjs";
239 for (
auto tjid : masterlist)
240 myprt <<
" " << tjid;
244 std::vector<SortEntry> sortVec(temp.size());
245 for (
unsigned short indx = 0; indx < temp.size(); ++indx) {
246 auto& vx3 = slc.
vtx3s[temp[indx] - 1];
247 sortVec[indx].index = indx;
248 sortVec[indx].val = vx3.Score;
250 if (sortVec.size() > 1) std::sort(sortVec.begin(), sortVec.end(),
valsDecreasing);
253 for (
unsigned short indx = 0; indx < temp.size(); ++indx)
254 vlist[indx] = temp[sortVec[indx].index];
258 auto& vx3 = slc.
vtx3s[vlist[0] - 1];
264 auto& sf = neutrinoPFP.SectionFits[0];
270 neutrinoPFP.PDGCode = 14;
271 neutrinoPFP.Vx3ID[1] = vx3.ID;
272 neutrinoPFP.Vx3ID[0] = vx3.ID;
275 if (!
StorePFP(slc, neutrinoPFP))
return;
279 std::vector<bool> lookedAt3(slc.
vtx3s.size() + 1,
false);
280 std::vector<bool> lookedAt2(slc.
vtxs.size() + 1,
false);
282 std::vector<std::pair<int, int>> pardtr;
284 for (
unsigned short indx = 0; indx < vlist.size(); ++indx) {
285 auto& vx3 = slc.
vtx3s[vlist[indx] - 1];
286 if (lookedAt3[vx3.ID])
continue;
288 lookedAt3[vx3.ID] =
true;
292 if (primTjList.empty())
continue;
294 for (
auto primTjID : primTjList) {
295 auto& primTj = slc.
tjs[primTjID - 1];
297 if (primTj.ParentID != -1)
continue;
298 if (prt)
mf::LogVerbatim(
"TC") <<
"Vx3 " << vx3.ID <<
" Primary tj " << primTj.ID;
303 for (
unsigned short end = 0;
end < 2; ++
end) {
304 if (primTj.VtxID[
end] == 0)
continue;
305 auto& vx2 = slc.
vtxs[primTj.VtxID[
end] - 1];
306 if (vx2.Vx3ID == vx3.ID)
continue;
309 for (
auto dtrID : dtrList) {
311 if (dtrID == primTjID)
continue;
312 auto& dtj = slc.
tjs[dtrID - 1];
313 if (dtj.ParentID != -1)
continue;
314 pardtr.push_back(std::make_pair(primTjID, dtrID));
315 if (prt)
mf::LogVerbatim(
"TC") <<
" primTj " << primTjID <<
" dtrID " << dtrID;
319 for (
unsigned short end = 0;
end < 2; ++
end) {
320 if (primTj.VtxID[
end] == 0)
continue;
321 auto& vx2 = slc.
vtxs[primTj.VtxID[
end] - 1];
325 if (pardtr.empty())
continue;
329 for (
auto pdtr : pardtr)
330 myprt <<
" " << pdtr.first <<
"_" << pdtr.second;
334 for (
unsigned short nit = 0; nit < 100; ++nit) {
335 auto lastPair = pardtr[pardtr.size() - 1];
336 auto& dtj = slc.
tjs[lastPair.second - 1];
337 dtj.ParentID = lastPair.first;
340 unsigned short dpt = 0, ppt = 0;
341 auto& ptj = slc.
tjs[lastPair.first - 1];
345 if (prt)
mf::LogVerbatim(
"TC") <<
"Set parent " << ptj.ID <<
" dtr " << dtj.ID;
349 for (
unsigned short end = 0;
end < 2; ++
end) {
350 if (dtj.VtxID[
end] == 0)
continue;
351 auto& vx2 = slc.
vtxs[dtj.VtxID[
end] - 1];
352 if (lookedAt2[vx2.ID])
continue;
353 lookedAt2[vx2.ID] =
true;
355 for (
auto tjid : tjlist) {
356 if (tjid == dtj.ID || tjid == ptj.ID)
continue;
357 pardtr.push_back(std::make_pair(dtj.ID, tjid));
360 myprt <<
" add par_dtr";
361 for (
auto pdtr : pardtr)
362 myprt <<
" " << pdtr.first <<
"_" << pdtr.second;
366 if (pardtr.empty())
break;
370 for (
auto tjid : masterlist) {
371 auto& tj = slc.
tjs[tjid - 1];
372 if (tj.ParentID < 0) tj.ParentID = tj.ID;
381 if (tjIDs.size() < 2)
return 1;
382 std::vector<float> plnchg(slc.
nPlanes);
383 for (
auto tjid : tjIDs) {
384 if (tjid <= 0 || tjid > (
int)slc.
tjs.size())
return 1;
385 auto& tj = slc.
tjs[tjid - 1];
388 plnchg[plane] += tj.TotChg;
392 for (
unsigned short plane = 0; plane < slc.
nPlanes; ++plane) {
393 if (plnchg[plane] == 0)
continue;
394 aveChg += plnchg[plane];
397 if (cnt < 2)
return 1;
400 for (
unsigned short plane = 0; plane < slc.
nPlanes; ++plane) {
402 if (plnchg[plane] == 0)
continue;
403 float asym =
std::abs(plnchg[plane] - aveChg) / (plnchg[plane] + aveChg);
404 if (asym > maxAsym) maxAsym = asym;
419 std::array<int, 5> codeList = {{0, 11, 13, 111, 211}};
420 unsigned short codeIndex = 0;
421 if (tjIDs.empty())
return codeList[codeIndex];
423 std::array<unsigned short, 5> cnts;
426 for (
auto tjid : tjIDs) {
427 if (tjid <= 0 || tjid > (
int)slc.
tjs.size())
continue;
428 auto& tj = slc.
tjs[tjid - 1];
429 for (
unsigned short ii = 0; ii < 5; ++ii)
430 if (tj.PDGCode == codeList[ii]) ++cnts[ii];
432 if (len > maxLen) maxLen = len;
436 for (
unsigned short ii = 1; ii < 5; ++ii) {
437 if (cnts[ii] > maxCnt) {
442 return codeList[codeIndex];
453 if (primID <= 0 || primID > (
int)slc.
tjs.size())
return -1;
456 auto& ptj = slc.
tjs[primID - 1];
457 for (
unsigned short end = 0;
end < 2; ++
end) {
458 if (ptj.VtxID[
end] == 0)
continue;
459 auto& vx2 = slc.
vtxs[ptj.VtxID[
end] - 1];
460 if (vx2.Vx3ID == 0)
continue;
461 auto& vx3 = slc.
vtx3s[vx2.Vx3ID - 1];
462 if (vx3.Neutrino)
return primID;
476 for (
unsigned short nit = 0; nit < 10; ++nit) {
477 if (parid < 1 || parid > (
int)slc.
tjs.size())
break;
478 auto& tj = slc.
tjs[parid - 1];
493 int dtruid = pfp.
UID;
494 unsigned short nit = 0;
497 auto& parent =
slices[slcIndx.first].pfps[slcIndx.second];
499 if (parent.PDGCode == 14 || parent.PDGCode == 12)
return dtruid;
501 if (parent.ParentUID == 0)
return parent.UID;
502 if (
int(parent.ParentUID) == parent.UID)
return parent.UID;
504 paruid = parent.ParentUID;
505 if (paruid < 0)
return 0;
507 if (nit == 10)
return 0;
515 if (mtjid > (
int)slc.
tjs.size())
return false;
516 auto const& mtj = slc.
tjs[mtjid - 1];
519 for (
auto tjid : pfp.
TjIDs) {
520 auto const& otj = slc.
tjs[tjid - 1];
521 if (otj.CTP == mtj.CTP) {
526 if (otjid == 0)
return false;
528 int newtjid = slc.
tjs.size();
530 mf::LogVerbatim(
"TC") <<
"MergeTjIntoPFP: merged T" << otjid <<
" with T" << mtjid
531 <<
" -> T" << newtjid;
532 std::replace(pfp.
TjIDs.begin(), pfp.
TjIDs.begin(), otjid, newtjid);
537 mf::LogVerbatim(
"TC") <<
"MergeTjIntoPFP: merge T" << otjid <<
" with T" << mtjid
549 if (tj.
AveChg <= 0)
return 100;
551 unsigned short closePt = USHRT_MAX;
553 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
554 auto& tp = tj.
Pts[ipt];
555 float sep2 =
PosSep2(pos, tp.Pos);
556 if (sep2 > close)
continue;
560 if (closePt == USHRT_MAX)
return 100;
562 auto& tp = tj.
Pts[closePt];
565 float posErr = tp.DeltaRMS;
566 if (tp.AngErr > 0 && close > 10) posErr += sqrt(tp.AngErr * sqrt(close));
567 if (posErr < 0.1) posErr = 0.1;
568 float posPull = delta / posErr;
570 if (chgErr < 0.15) chgErr = 0.15;
573 return 0.5 * (posPull + chgPull);
591 if (tjIDs.size() < 2)
return false;
592 unsigned short lasttj = tjIDs[tjIDs.size() - 1] - 1;
593 auto const& mtj = slc.
tjs[lasttj];
594 bool mtjIsShort = (mtj.Pts.size() < 5);
596 std::array<float, 2> minsep2{{1000, 1000}};
598 std::array<int, 2> minsepTj{{0, 0}};
600 std::array<unsigned short, 2> minsepPt;
603 std::array<unsigned short, 2> minsepEnd;
604 for (
auto tjid : tjIDs) {
605 auto& tj = slc.
tjs[tjid - 1];
606 if (tj.CTP != mtj.CTP)
continue;
607 if (tj.ID == mtj.ID)
continue;
608 for (
unsigned short mend = 0; mend < 2; ++mend) {
609 Point2_t mendPos = mtj.Pts[mtj.EndPt[mend]].Pos;
610 float sep2 = minsep2[mend];
611 unsigned short closePt = 0;
613 minsep2[mend] = sep2;
614 minsepTj[mend] = tjid;
615 minsepPt[mend] = closePt;
618 short dend0 =
abs((
short)closePt - tj.EndPt[0]);
619 short dend1 =
abs((
short)closePt - tj.EndPt[1]);
620 if (dend0 < dend1 && dend0 < 3) minsepEnd[mend] = 0;
621 if (dend1 < dend0 && dend1 < 3) minsepEnd[mend] = 1;
627 bool isCompatible = (minsepEnd[0] != 2 && minsepEnd[1] != 2);
629 if (isCompatible && mtjIsShort) {
630 float minminsep = minsep2[0];
631 if (minsep2[1] < minminsep) minminsep = minsep2[1];
633 isCompatible = minminsep < 5;
637 myprt <<
"CompatibleMerge: T" << mtj.ID <<
" end";
638 for (
unsigned short end = 0;
end < 2; ++
end)
639 myprt <<
" T" << minsepTj[
end] <<
"_I" << minsepPt[
end] <<
"_E" << minsepEnd[
end]
640 <<
" minsep " << sqrt(minsep2[
end]);
641 myprt <<
" Compatible? " << isCompatible;
654 if (tj1.
CTP != tj2.
CTP)
return false;
655 unsigned short end1 = -1, end2 = 0;
658 if (len2 < minLen) minLen = len2;
660 if (minLen > 10) minLen = 10;
661 for (
unsigned short e1 = 0; e1 < 2; ++e1) {
663 for (
unsigned short e2 = 0; e2 < 2; ++e2) {
665 float sep =
PosSep(tp1.Pos, tp2.Pos);
674 if (end2 != 1 - end1)
return false;
677 if (overlapFraction > 0.25) {
680 << overlapFraction <<
" > 0.25 ";
684 auto& tp1 = tj1.
Pts[tj1.
EndPt[end1]];
685 auto& tp2 = tj2.
Pts[tj2.
EndPt[end2]];
688 if (doca1 > 2 && doca2 > 2) {
711 float maxWire = -1E6;
714 for (
auto& tp : tj1.
Pts) {
715 if (tp.Chg == 0)
continue;
716 if (tp.Pos[0] < 0)
continue;
717 if (tp.Pos[0] < minWire) minWire = tp.Pos[0];
718 if (tp.Pos[0] > maxWire) maxWire = tp.Pos[0];
721 if (cnt1 == 0)
return 0;
723 for (
auto& tp : tj2.
Pts) {
724 if (tp.Chg == 0)
continue;
725 if (tp.Pos[0] < 0)
continue;
726 if (tp.Pos[0] < minWire) minWire = tp.Pos[0];
727 if (tp.Pos[0] > maxWire) maxWire = tp.Pos[0];
730 if (cnt2 == 0)
return 0;
731 int span = maxWire - minWire;
732 if (span <= 0)
return 0;
733 std::vector<unsigned short> wcnt(span);
734 for (
auto& tp : tj1.
Pts) {
735 if (tp.Chg == 0)
continue;
736 if (tp.Pos[0] < -0.4)
continue;
737 int indx = std::nearbyint(tp.Pos[0] - minWire);
738 if (indx < 0 || indx > span - 1)
continue;
741 for (
auto& tp : tj2.
Pts) {
742 if (tp.Chg == 0)
continue;
743 if (tp.Pos[0] < -0.4)
continue;
744 int indx = std::nearbyint(tp.Pos[0] - minWire);
745 if (indx < 0 || indx > span - 1)
continue;
748 float cntOverlap = 0;
749 for (
auto cnt : wcnt)
750 if (cnt > 1) ++cntOverlap;
751 if (cnt1 < cnt2) {
return cntOverlap / cnt1; }
753 return cntOverlap / cnt2;
787 if (angle > M_PI) angle = M_PI;
788 if (angle < -M_PI) angle = M_PI;
789 if (angle < 0) angle = -angle;
790 if (angle > M_PI / 2) angle = M_PI - angle;
801 unsigned short originPt = tj.
EndPt[1];
802 unsigned short npts = tj.
Pts[originPt].NTPsFit;
804 unsigned short fitDir = -1;
805 FitTraj(slc, tj, originPt, npts, fitDir, tpFit);
806 tj.
Pts[originPt] = tpFit;
813 unsigned short originPt,
833 if (originPt > tj.
Pts.size() - 1) {
834 mf::LogWarning(
"TC") <<
"FitTraj: Requesting fit of invalid TP " << originPt;
839 tpFit = tj.
Pts[originPt];
842 if (fitDir < -1 || fitDir > 1)
return;
844 std::vector<double>
x,
y;
847 if (tj.
Pts[originPt].Chg == 0) origin = tj.
Pts[originPt].Pos;
851 for (
unsigned short ipt = tj.
EndPt[0]; ipt < tj.
EndPt[1]; ++ipt) {
852 if (tj.
Pts[ipt].Chg <= 0)
continue;
853 double xx = tj.
Pts[ipt].HitPos[0] - origin[0];
854 double yy = tj.
Pts[ipt].HitPos[1] - origin[1];
858 if (x.size() != 2)
return;
861 tpFit.
Ang = M_PI / 2;
862 if (y[1] < y[0]) tpFit.
Ang = -tpFit.
Ang;
865 double dx = x[1] - x[0];
866 double dy = y[1] - y[0];
867 tpFit.
Ang = atan2(dy, dx);
869 tpFit.
Dir[0] = cos(tpFit.
Ang);
870 tpFit.
Dir[1] = sin(tpFit.
Ang);
871 tpFit.
Pos[0] += origin[0];
872 tpFit.
Pos[1] += origin[1];
879 std::vector<double>
w, q;
880 std::array<double, 2>
dir;
881 double xx, yy, xr, yr;
886 double rotAngle = tj.
Pts[originPt].Ang;
887 double cs = cos(-rotAngle);
888 double sn = sin(-rotAngle);
891 if (tj.
Pts[originPt].Chg > 0) {
892 xx = tj.
Pts[originPt].HitPos[0] - origin[0];
893 yy = tj.
Pts[originPt].HitPos[1] - origin[1];
894 xr = cs * xx - sn * yy;
895 yr = sn * xx + cs * yy;
898 chgWt = tj.
Pts[originPt].ChgPull;
899 if (chgWt < 1) chgWt = 1;
901 w.push_back(chgWt * tj.
Pts[originPt].HitPosErr2);
905 if (fitDir != 0) --npts;
909 unsigned short cnt = 0;
910 for (
unsigned short ipt = originPt + 1; ipt < tj.
Pts.size(); ++ipt) {
911 if (tj.
Pts[ipt].Chg <= 0)
continue;
912 xx = tj.
Pts[ipt].HitPos[0] - origin[0];
913 yy = tj.
Pts[ipt].HitPos[1] - origin[1];
914 xr = cs * xx - sn * yy;
915 yr = sn * xx + cs * yy;
918 chgWt = tj.
Pts[ipt].ChgPull;
919 if (chgWt < 1) chgWt = 1;
921 w.push_back(chgWt * tj.
Pts[ipt].HitPosErr2);
923 if (cnt == npts)
break;
928 if (fitDir != 1 && originPt > 0) {
929 unsigned short cnt = 0;
930 for (
unsigned short ii = 1; ii < tj.
Pts.size(); ++ii) {
931 unsigned short ipt = originPt - ii;
932 if (ipt > tj.
Pts.size() - 1)
continue;
933 if (tj.
Pts[ipt].Chg == 0)
continue;
934 xx = tj.
Pts[ipt].HitPos[0] - origin[0];
935 yy = tj.
Pts[ipt].HitPos[1] - origin[1];
936 xr = cs * xx - sn * yy;
937 yr = sn * xx + cs * yy;
940 chgWt = tj.
Pts[ipt].ChgPull;
941 if (chgWt < 1) chgWt = 1;
943 w.push_back(chgWt * tj.
Pts[ipt].HitPosErr2);
945 if (cnt == npts)
break;
951 if (x.size() < 2)
return;
962 for (
unsigned short ipt = 0; ipt < x.size(); ++ipt) {
963 if (w[ipt] < 0.00001) w[ipt] = 0.00001;
966 sumx += wght * x[ipt];
967 sumy += wght * y[ipt];
968 sumx2 += wght * x[ipt] * x[ipt];
969 sumy2 += wght * y[ipt] * y[ipt];
970 sumxy += wght * x[ipt] * y[ipt];
973 double delta = sum * sumx2 - sumx * sumx;
974 if (delta == 0)
return;
976 double A = (sumx2 * sumy - sumx * sumxy) / delta;
978 double B = (sumxy * sum - sumx * sumy) / delta;
983 double newang = atan(B);
984 dir[0] = cos(newang);
985 dir[1] = sin(newang);
989 tpFit.
Dir[0] = cs * dir[0] - sn * dir[1];
990 tpFit.
Dir[1] = sn * dir[0] + cs * dir[1];
992 bool flipDir =
false;
994 flipDir = std::signbit(tpFit.
Dir[1]) != std::signbit(tj.
Pts[originPt].Dir[1]);
997 flipDir = std::signbit(tpFit.
Dir[0]) != std::signbit(tj.
Pts[originPt].Dir[0]);
1000 tpFit.
Dir[0] = -tpFit.
Dir[0];
1001 tpFit.
Dir[1] = -tpFit.
Dir[1];
1003 tpFit.
Ang = atan2(tpFit.
Dir[1], tpFit.
Dir[0]);
1007 tpFit.
Pos[0] = -sn * A + origin[0];
1008 tpFit.
Pos[1] = cs * A + origin[1];
1012 if (x.size() < 3)
return;
1015 double ndof = x.size() - 2;
1017 (sumy2 + A * A * sum + B * B * sumx2 - 2 * (A * sumy + B * sumxy - A * B * sumx)) / ndof;
1021 double slopeError = sqrt(varnce * sum / delta);
1030 for (
unsigned short ii = 0; ii < y.size(); ++ii) {
1031 arg = y[ii] - A - B * x[ii];
1032 sum += arg * arg / w[ii];
1034 tpFit.
FitChi = sum / ndof;
1040 if (slc.
pfps.empty())
return USHRT_MAX;
1041 for (
unsigned int ipfp = 0; ipfp < slc.
pfps.size(); ++ipfp) {
1042 const auto& pfp = slc.
pfps[ipfp];
1043 if (std::find(pfp.TjIDs.begin(), pfp.TjIDs.end(), tjID) != pfp.TjIDs.end())
return ipfp;
1052 for (
auto const& tp : tj.
Pts) {
1053 for (
auto iht : tp.Hits) {
1064 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
1077 for (
auto& tp : tj.
Pts) {
1078 if (tp.Hits.size() > 16)
return false;
1091 unsigned short npts = tj.
EndPt[1] - tj.
EndPt[0] + 1;
1092 if (npts < 2)
return false;
1094 auto& endTp0 = tj.
Pts[tj.
EndPt[0]];
1095 auto& endTp1 = tj.
Pts[tj.
EndPt[1]];
1099 if (endTp0.AngErr == 0.1 && endTp1.AngErr != 0.1) { endTp0.AngErr = endTp1.AngErr; }
1100 else if (endTp0.AngErr != 0.1 && endTp1.AngErr == 0.1) {
1101 endTp1.AngErr = endTp0.AngErr;
1107 if (endTp0.AveChg <= 0) {
1108 unsigned short cnt = 0;
1110 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
1111 if (tj.
Pts[ipt].Chg == 0)
continue;
1112 sum += tj.
Pts[ipt].Chg;
1114 if (cnt == 4)
break;
1116 tj.
Pts[tj.
EndPt[0]].AveChg = sum / (float)cnt;
1118 if (endTp1.AveChg <= 0 && npts < 5) endTp1.AveChg = endTp0.AveChg;
1119 if (endTp1.AveChg <= 0) {
1121 unsigned short cnt = 0;
1122 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
1123 short ipt = tj.
EndPt[1] - ii;
1125 if (tj.
Pts[ipt].Chg == 0)
continue;
1126 sum += tj.
Pts[ipt].Chg;
1128 if (cnt == 4)
break;
1129 if (ipt == 0)
break;
1131 tj.
Pts[tj.
EndPt[1]].AveChg = sum / (float)cnt;
1138 if (npts > 2 * nPtsFit) {
1139 for (
unsigned short ipt = tj.
EndPt[0] + nPtsFit; ipt < tj.
EndPt[1] - nPtsFit; ++ipt) {
1140 auto& tp = tj.
Pts[ipt];
1141 if (tp.KinkSig < 0) tp.KinkSig =
KinkSignificance(slc, tj, ipt, nPtsFit, useChg,
false);
1148 int trID = slc.
tjs.size() + 1;
1150 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
1151 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
1152 if (tj.
Pts[ipt].UseHit[ii]) {
1153 unsigned int iht = tj.
Pts[ipt].Hits[ii];
1154 if (iht > slc.
slHits.size() - 1) {
1158 if (slc.
slHits[iht].InTraj > 0) {
1162 slc.
slHits[iht].InTraj = trID;
1168 for (
unsigned int iht = 0; iht < slc.
slHits.size(); ++iht) {
1169 if (slc.
slHits[iht].InTraj == tj.
ID) {
1171 <<
" thinks it belongs to T" << tj.
ID <<
" but it isn't in the Tj\n";
1183 slc.
tjs.push_back(tj);
1186 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
1187 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
1188 unsigned int iht = tj.
Pts[ipt].Hits[ii];
1190 std::cout <<
"Debug hit appears in trajectory w WorkID " << tj.
WorkID <<
" UseHit " 1191 << tj.
Pts[ipt].UseHit[ii] <<
"\n";
1203 unsigned short originPt,
1204 unsigned short npts,
1207 unsigned short usePar)
1214 if (originPt > tj.
Pts.size() - 1)
return;
1215 if (fitDir != 1 && fitDir != -1)
return;
1219 Fit2D(0, inPt, pErr, outVec, outVecErr, chiDOF);
1220 unsigned short cnt = 0;
1221 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
1222 unsigned short ipt = originPt + ii * fitDir;
1223 if (ipt < tj.
EndPt[0] || ipt > tj.
EndPt[1])
break;
1224 auto& tp = tj.
Pts[ipt];
1225 if (tp.Chg <= 0)
continue;
1227 inPt[0] =
std::abs(tp.Pos[0] - tj.
Pts[originPt].Pos[0]);
1228 float parVal = tp.Chg;
1230 pErr = 0.1 * parVal;
1234 pErr = sqrt(tp.HitPosErr2);
1238 if (!
Fit2D(2, inPt, pErr, outVec, outVecErr, chiDOF))
break;
1240 if (cnt == npts)
break;
1242 if (cnt < npts)
return;
1244 if (!
Fit2D(-1, inPt, pErr, outVec, outVecErr, chiDOF))
return;
1245 pFit.
Pos = tj.
Pts[originPt].Pos;
1246 pFit.
Par0 = outVec[0];
1247 pFit.
AvePar /= (float)cnt;
1248 pFit.
ParErr = outVecErr[0];
1249 pFit.
Pos = tj.
Pts[originPt].Pos;
1263 unsigned short itj = 0;
1264 std::vector<unsigned int> tHits;
1265 std::vector<unsigned int> atHits;
1266 for (
auto& tj : slc.
tjs) {
1268 if (tj.AlgMod[
kKilled])
continue;
1271 if (tHits.size() < 2)
continue;
1272 std::sort(tHits.begin(), tHits.end());
1274 for (iht = 0; iht < slc.
slHits.size(); ++iht) {
1275 if (slc.
slHits[iht].InTraj == tID) atHits.push_back(iht);
1277 if (atHits.size() < 2)
continue;
1278 if (!std::equal(tHits.begin(), tHits.end(), atHits.begin())) {
1280 myprt << someText <<
" ChkInTraj failed: inTraj - UseHit mis-match for T" << tID
1281 <<
" tj.WorkID " << tj.WorkID <<
" atHits size " << atHits.size() <<
" tHits size " 1282 << tHits.size() <<
" in CTP " << tj.CTP <<
"\n";
1283 myprt <<
"AlgMods: ";
1284 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
1285 if (tj.AlgMod[ib]) myprt <<
" " <<
AlgBitNames[ib];
1287 myprt <<
"index inTraj UseHit \n";
1288 for (iht = 0; iht < atHits.size(); ++iht) {
1289 myprt <<
"iht " << iht <<
" " <<
PrintHit(slc.
slHits[atHits[iht]]);
1290 if (iht < tHits.size()) myprt <<
" " <<
PrintHit(slc.
slHits[tHits[iht]]);
1291 if (atHits[iht] != tHits[iht]) myprt <<
" <<< " << atHits[iht] <<
" != " << tHits[iht];
1294 if (tHits.size() > atHits.size()) {
1295 for (iht = atHits.size(); iht < atHits.size(); ++iht) {
1296 myprt <<
"atHits " << iht <<
" " <<
PrintHit(slc.
slHits[atHits[iht]]) <<
"\n";
1303 for (
unsigned short end = 0;
end < 2; ++
end) {
1304 if (tj.VtxID[
end] > slc.
vtxs.size()) {
1305 mf::LogVerbatim(
"TC") << someText <<
" ChkInTraj: Bad VtxID " << tj.ID;
1329 if (itj > slc.
tjs.size() - 1)
return;
1330 auto& tj = slc.
tjs[itj];
1333 if (tj.EndFlag[0][
kBragg])
return;
1336 if (tj.Pts.size() < 20)
return;
1341 float chg2 = tj.Pts[tj.EndPt[0] + 2].AveChg;
1343 float chg15 = tj.Pts[tj.EndPt[0] + 15].AveChg;
1344 if (chg2 < 3 * chg15)
return;
1347 float midChg = 0.5 * (chg2 + chg15);
1349 unsigned short breakPt = USHRT_MAX;
1350 for (
unsigned short ipt = tj.EndPt[0] + 3; ipt < 15; ++ipt) {
1351 float chgm2 = tj.Pts[ipt - 2].Chg;
1352 if (chgm2 == 0)
continue;
1353 float chgm1 = tj.Pts[ipt - 1].Chg;
1354 if (chgm1 == 0)
continue;
1355 float chgp1 = tj.Pts[ipt + 1].Chg;
1356 if (chgp1 == 0)
continue;
1357 float chgp2 = tj.Pts[ipt + 2].Chg;
1358 if (chgp2 == 0)
continue;
1359 if (chgm2 > midChg && chgm1 > midChg && chgp1 < midChg && chgp2 < midChg) {
1364 if (breakPt == USHRT_MAX)
return;
1366 std::array<double, 2> cnt,
sum, sum2;
1367 for (
unsigned short ipt = tj.EndPt[0]; ipt <= tj.EndPt[1]; ++ipt) {
1368 auto& tp = tj.Pts[ipt];
1369 if (tp.Chg <= 0)
continue;
1370 unsigned short end = 0;
1371 if (ipt > breakPt) end = 1;
1374 sum2[
end] += tp.Chg * tp.Chg;
1376 for (
unsigned short end = 0;
end < 2; ++
end) {
1377 if (cnt[
end] < 3)
return;
1378 double ave = sum[
end] / cnt[
end];
1379 double arg = sum2[
end] - cnt[
end] * ave * ave;
1380 if (arg <= 0)
return;
1381 sum2[
end] = sqrt(arg / (cnt[
end] - 1));
1385 bool doSplit =
true;
1388 if (tj.ChgRMS > 0.5 && sum2[0] > 0.3 && sum2[1] > 0.3) doSplit =
false;
1391 myprt <<
"CTBC: T" << tj.ID <<
" chgRMS " << tj.ChgRMS;
1392 myprt <<
" AveChg before split point " << (int)sum[0] <<
" rms " << sum2[0];
1393 myprt <<
" after " << (int)sum[1] <<
" rms " << sum2[1] <<
" doSplit? " << doSplit;
1395 if (!doSplit)
return;
1398 aVtx.
Pos = tj.Pts[breakPt].Pos;
1400 aVtx.
Pass = tj.Pass;
1404 aVtx.
ID = slc.
vtxs.size() + 1;
1406 unsigned short ivx = slc.
vtxs.size();
1408 if (!
SplitTraj(slc, itj, breakPt, ivx, prt)) {
1427 if (itj > slc.
tjs.size() - 1)
return false;
1431 auto& tj = slc.
tjs[itj];
1433 if (npwc < 4)
return false;
1434 if (npwc < nPtsToCheck) nPtsToCheck = npwc;
1437 unsigned short maxPullPt = USHRT_MAX;
1438 for (
unsigned short ipt = tj.EndPt[0]; ipt < tj.EndPt[1]; ++ipt) {
1439 auto& tp = tj.Pts[ipt];
1440 if (tp.ChgPull < maxPull)
continue;
1441 maxPull = tp.ChgPull;
1444 if (maxPullPt == USHRT_MAX)
return false;
1446 if (maxPullPt < 0.5 * (tj.EndPt[0] + tj.EndPt[1])) { dpt = maxPullPt - tj.EndPt[0]; }
1448 dpt = tj.EndPt[1] - maxPullPt;
1450 if (dpt < 3)
return false;
1453 mf::LogVerbatim(
"TC") <<
"BS: T" << tj.ID <<
" maxPull " << maxPull <<
" at " 1454 <<
PrintPos(tj.Pts[maxPullPt]) <<
" dpt " << dpt;
1455 unsigned short breakPt = USHRT_MAX;
1457 unsigned short bestBragg = 0;
1461 for (
unsigned short ipt = maxPullPt - 2; ipt <= maxPullPt + 2; ++ipt) {
1462 FitTraj(slc, tj, ipt - 1, nPtsFit, -1, tp1);
1463 if (tp1.
FitChi > 10)
continue;
1464 FitTraj(slc, tj, ipt + 1, nPtsFit, 1, tp2);
1465 if (tp2.
FitChi > 10)
continue;
1467 FitPar(tj, ipt - 1, nPtsToCheck, -1, chgFit1, 1);
1468 if (chgFit1.
ChiDOF > 100)
continue;
1470 FitPar(tj, ipt + 1, nPtsToCheck, 1, chgFit2, 1);
1471 if (chgFit2.
ChiDOF > 100)
continue;
1476 unsigned short bragg = 1;
1477 float bchi = chgFit1.
ChiDOF;
1484 if (bchi < 1) bchi = 1;
1485 float fom = 10 * dang * chgAsym * slpAsym / bchi;
1488 myprt <<
"pt " <<
PrintPos(tj.Pts[ipt]) <<
" " << std::setprecision(2) << dang;
1489 myprt <<
" chg1 " << (int)chgFit1.
Par0 <<
" slp " << chgFit1.
ParSlp <<
" chi " 1491 myprt <<
" chg2 " << (
int)chgFit2.
Par0 <<
" slp " << chgFit2.
ParSlp <<
" chi " 1493 myprt <<
" chgAsym " << chgAsym;
1494 myprt <<
" slpAsym " << slpAsym;
1495 myprt <<
" fom " << fom;
1496 myprt <<
" bragg " << bragg;
1498 if (fom < bestFOM)
continue;
1503 if (breakPt == USHRT_MAX)
return false;
1508 aVtx.
Pos = tj.Pts[breakPt].Pos;
1510 aVtx.
Pass = tj.Pass;
1514 aVtx.
ID = slc.
vtxs.size() + 1;
1516 unsigned short ivx = slc.
vtxs.size();
1518 if (!
SplitTraj(slc, itj, breakPt, ivx, prt)) {
1525 unsigned short otj = slc.
tjs.size() - 1;
1526 if (bestBragg == 2) std::swap(itj, otj);
1527 slc.
tjs[itj].PDGCode = 211;
1529 slc.
tjs[otj].PDGCode = 13;
1539 if (tj.
PDGCode == 111)
return;
1542 if (npwc < 50)
return;
1548 if (nPtsMax > 8) nPtsMax = 8;
1553 unsigned short firstBad = USHRT_MAX;
1554 for (
unsigned short ii = 0; ii < nPtsMax; ++ii) {
1555 unsigned short ipt = tj.
EndPt[1] - nPtsMax + ii;
1556 auto& tp = tj.
Pts[ipt];
1557 if (tp.Chg <= 0)
continue;
1558 if (tp.ChgPull < 3)
continue;
1560 if (firstBad == USHRT_MAX) firstBad = ipt;
1562 if (firstBad == USHRT_MAX)
return;
1564 float cntTot = tj.
EndPt[1] - firstBad;
1566 float fracBad = cntBad / cntTot;
1567 if (fracBad < 0.5)
return;
1570 for (
unsigned short ipt = firstBad; ipt <= tj.
EndPt[1]; ++ipt)
1579 const std::vector<float>& fQualityCuts,
1592 if (tj.
PDGCode == 111)
return;
1596 short minPts = fQualityCuts[1];
1597 if (minPts < 1)
return;
1598 if (npwc < minPts)
return;
1600 if (npwc < 8)
return;
1603 if (npwc == minPts + 1) {
1604 unsigned short endPt1 = tj.
EndPt[1];
1605 auto& tp = tj.
Pts[endPt1];
1606 auto& ptp = tj.
Pts[endPt1 - 1];
1609 float dwire =
std::abs(ptp.Pos[0] - tp.Pos[0]);
1610 if (ptp.Chg == 0 || dwire > 1.1) {
1620 for (lastPt = tj.
EndPt[1]; lastPt >= minPts; --lastPt) {
1622 if (lastPt == 1)
break;
1623 if (tj.
Pts[lastPt].Chg == 0)
continue;
1625 unsigned short nadj = 0;
1626 unsigned short npwc = 0;
1627 for (
short ipt = lastPt - minPts; ipt < lastPt; ++ipt) {
1630 auto& tp = tj.
Pts[ipt];
1632 auto& ptp = tj.
Pts[ipt - 1];
1633 if (tp.Chg > 0 && ptp.Chg > 0) {
1635 if (
std::abs(tp.Pos[0] - ptp.Pos[0]) < 1.5) ++nadj;
1640 float hitFrac = ntpwc / nwires;
1642 mf::LogVerbatim(
"TC") << fcnLabel <<
"-TEP: T" << tj.
ID <<
" lastPt " << lastPt <<
" npwc " 1643 << npwc <<
" ntpwc " << ntpwc <<
" nadj " << nadj <<
" hitFrac " 1645 if (hitFrac > fQualityCuts[0] && npwc == minPts && nadj >= minPts - 1)
break;
1650 if (tj.
Pts[lastPt].Pos[0] > -0.4) {
1651 unsigned int prevWire = std::nearbyint(tj.
Pts[lastPt].Pos[0]);
1652 if (tj.
StepDir > 0) { --prevWire; }
1657 mf::LogVerbatim(
"TC") << fcnLabel <<
"-TEP: is prevWire " << prevWire <<
" dead? ";
1664 if (lastPt == tj.
EndPt[1]) {
1670 for (
unsigned short ipt = lastPt + 1; ipt <= tj.
EndPt[1]; ++ipt)
1675 fcnLabel +=
"-TEPo";
1686 if (tj.
PDGCode == 111)
return;
1692 unsigned short withNptsFit = 0;
1695 for (
unsigned short nptsf = 3; nptsf < nPtsFit; ++nptsf) {
1696 unsigned short ipt = tj.
EndPt[1] - nptsf;
1700 withNptsFit = nptsf;
1703 if (withNptsFit > 0) {
1704 unsigned short ipt = tj.
EndPt[1] - withNptsFit;
1705 std::cout <<
"CEK: T" << tj.
ID <<
" ipt " << ipt;
1707 auto& tp = tj.
Pts[ipt];
1708 std::cout <<
" " <<
PrintPos(tp) <<
" withNptsFit " << withNptsFit <<
" ks " << ks <<
"\n";
1721 if (tj.
PDGCode == 111)
return;
1722 unsigned short npts = tj.
EndPt[1] - tj.
EndPt[0];
1725 if (npts > 50)
return;
1727 if (npts < 8)
return;
1730 unsigned short atPt = 0;
1732 for (
unsigned short ipt = tj.
EndPt[0] + 2; ipt <= tj.
EndPt[1] - 2; ++ipt) {
1733 auto& tp = tj.
Pts[ipt];
1734 if (tp.ChgPull > bigPull) {
1735 bigPull = tp.ChgPull;
1739 if (atPt == 0)
return;
1741 if ((atPt - tj.
EndPt[0]) < 0.5 * npts)
return;
1744 <<
". Check charge asymmetry around it.";
1745 unsigned short nchk = 0;
1746 unsigned short npos = 0;
1747 unsigned short nneg = 0;
1748 for (
short ii = 1; ii < 5; ++ii) {
1749 short iplu = atPt + ii;
1750 if (iplu > tj.
EndPt[1])
break;
1751 short ineg = atPt - ii;
1752 if (ineg < tj.
EndPt[0])
break;
1753 if (tj.
Pts[iplu].Chg == 0)
continue;
1754 if (tj.
Pts[ineg].Chg == 0)
continue;
1755 float asym = (tj.
Pts[iplu].Chg - tj.
Pts[ineg].Chg) / (tj.
Pts[iplu].Chg + tj.
Pts[ineg].Chg);
1757 if (asym > 0.5) ++npos;
1758 if (asym < -0.5) ++nneg;
1760 mf::LogVerbatim(
"TC") <<
" ineg " << ineg <<
" iplu " << iplu <<
" asym " << asym
1761 <<
" nchk " << nchk;
1763 if (nchk < 3)
return;
1766 bool doTrim = (nneg > nchk) || (npos > nchk);
1767 if (!doTrim)
return;
1769 auto& prevTP = tj.
Pts[atPt - 1];
1770 if (
std::abs(prevTP.ChgPull) > 2) --atPt;
1771 for (
unsigned short ipt = atPt; ipt <= tj.
EndPt[1]; ++ipt)
1782 if (MinWireSignalFraction == 0)
return true;
1784 if (tp1.
Pos[0] < -0.4 || tp2.
Pos[0] < -0.4)
return false;
1785 int fromWire = std::nearbyint(tp1.
Pos[0]);
1786 int toWire = std::nearbyint(tp2.
Pos[0]);
1788 if (fromWire == toWire) {
1791 tp.
Pos[1] = 0.5 * (tp1.
Pos[1] + tp2.
Pos[1]);
1813 if (tp.
Pos[0] < -0.4 || toPos0 < -0.4)
return 0;
1814 int fromWire = std::nearbyint(tp.
Pos[0]);
1815 int toWire = std::nearbyint(toPos0);
1817 if (fromWire == toWire)
return SignalAtTp(tp);
1819 int nWires =
abs(toWire - fromWire) + 1;
1824 if (toWire > fromWire && tp.
Dir[0] < 0) stepSize = -stepSize;
1825 if (toWire < fromWire && tp.
Dir[0] > 0) stepSize = -stepSize;
1828 for (
unsigned short cnt = 0; cnt < nWires; ++cnt) {
1831 tp.
Pos[0] += tp.
Dir[0] * stepSize;
1832 tp.
Pos[1] += tp.
Dir[1] * stepSize;
1834 float sigFrac = nsig / num;
1840 const std::vector<unsigned int>& iHitsInMultiplet,
1841 const std::vector<unsigned int>& jHitsInMultiplet)
1845 if (iHitsInMultiplet.empty() || jHitsInMultiplet.empty())
return false;
1849 if (cvI < 0)
return false;
1852 for (
auto& iht : iHitsInMultiplet) {
1854 float cv =
hit.PeakTime();
1855 float rms =
hit.RMS();
1856 float arg = cv - 3.1 * rms;
1857 if (arg < minI) minI = arg;
1858 arg = cv + 3.1 * rms;
1859 if (arg > maxI) maxI = arg;
1863 if (cvJ < 0)
return false;
1866 for (
auto& jht : jHitsInMultiplet) {
1868 float cv =
hit.PeakTime();
1869 float rms =
hit.RMS();
1870 float arg = cv - 3.1 * rms;
1871 if (arg < minJ) minJ = arg;
1872 arg = cv + 3.1 * rms;
1873 if (arg > maxJ) maxJ = arg;
1877 if (maxI > minJ)
return true;
1880 if (minI < maxJ)
return true;
1889 if (iht > slc.
slHits.size() - 1)
return false;
1890 if (jht > slc.
slHits.size() - 1)
return false;
1894 int iwire = ihit.WireID().Wire;
1895 int jwire = jhit.WireID().Wire;
1896 if (
std::abs(iwire - jwire) > 1)
return false;
1897 if (ihit.PeakTime() > jhit.PeakTime()) {
1898 float minISignal = ihit.PeakTime() - 3 * ihit.RMS();
1899 float maxJSignal = jhit.PeakTime() + 3 * ihit.RMS();
1900 if (maxJSignal > minISignal)
return true;
1903 float maxISignal = ihit.PeakTime() + 3 * ihit.RMS();
1904 float minJSignal = jhit.PeakTime() - 3 * ihit.RMS();
1905 if (minJSignal > maxISignal)
return true;
1927 if (tp.
Pos[0] < -0.4)
return false;
1929 unsigned short pln = planeID.
Plane;
1930 unsigned int wire = std::nearbyint(tp.
Pos[0]);
1931 if (wire >
evt.
goodWire[pln].size() - 1)
return false;
1935 if (slc.
wireHitRange[pln][wire].first == UINT_MAX)
return false;
1938 float tickRange = 0;
1942 if (tickRange > 40) tickRange = 40;
1944 float loTpTick = projTick - tickRange;
1945 float hiTpTick = projTick + tickRange;
1946 for (
unsigned int iht = slc.
wireHitRange[pln][wire].first;
1949 unsigned int ahi = slc.
slHits[iht].allHitsIndex;
1951 if (projTick <
hit.PeakTime()) {
1952 float loHitTick =
hit.PeakTime() - 3 *
hit.RMS();
1953 if (hiTpTick > loHitTick)
return true;
1956 float hiHitTick =
hit.PeakTime() + 3 *
hit.RMS();
1957 if (loTpTick < hiHitTick)
return true;
1977 if (tp.
Pos[0] < -0.4)
return false;
1979 unsigned short pln = planeID.
Plane;
1980 unsigned int wire = std::nearbyint(tp.
Pos[0]);
1981 if (wire >
evt.
goodWire[pln].size() - 1)
return false;
1987 float tickRange = 0;
1991 if (tickRange > 40) tickRange = 40;
1993 float loTpTick = projTick - tickRange;
1994 float hiTpTick = projTick + tickRange;
2004 const auto& wid =
hit.WireID();
2005 if (wid.Cryostat != planeID.
Cryostat)
continue;
2006 if (wid.TPC != planeID.
TPC)
continue;
2007 if (wid.Plane != planeID.
Plane)
continue;
2008 if (projTick <
hit.PeakTime()) {
2009 float loHitTick =
hit.PeakTime() - 3 *
hit.RMS();
2010 if (hiTpTick > loHitTick)
return true;
2013 float hiHitTick =
hit.PeakTime() + 3 *
hit.RMS();
2014 if (loTpTick < hiHitTick)
return true;
2035 unsigned int pln = plnID.
Plane;
2036 if (pln == 2)
return false;
2038 unsigned int tpc = plnID.
TPC;
2043 float atTick = 0.5 * (loTick + hiTick);
2047 if (
hit.Channel() != chan)
continue;
2048 if (atTick <
hit.PeakTime()) {
2049 float loHitTick =
hit.PeakTime() - 3 *
hit.RMS();
2050 if (hiTick > loHitTick)
return true;
2053 float hiHitTick =
hit.PeakTime() + 3 *
hit.RMS();
2054 if (loTick < hiHitTick)
return true;
2064 for (
size_t i = 0; i < tp.
Hits.size(); ++i) {
2065 if (!tp.
UseHit[i])
continue;
2074 unsigned short firstPt = tj.
EndPt[0];
2075 unsigned short lastPt = tj.
EndPt[1];
2082 bool includeDeadWires,
2083 unsigned short firstPt,
2084 unsigned short lastPt)
2086 unsigned short ntp = 0;
2087 for (
unsigned short ipt = firstPt; ipt <= lastPt; ++ipt)
2088 if (tj.
Pts[ipt].Chg > 0) ++ntp;
2102 const float& inWirePos1,
2103 const float& inWirePos2,
2106 if (inWirePos1 < -0.4 || inWirePos2 < -0.4)
return 0;
2107 unsigned int inWire1 = std::nearbyint(inWirePos1);
2108 unsigned int inWire2 = std::nearbyint(inWirePos2);
2110 unsigned short plane = planeID.
Plane;
2111 if (inWire1 > slc.
nWires[plane] || inWire2 > slc.
nWires[plane])
return 0;
2112 if (inWire1 > inWire2) {
2114 unsigned int tmp = inWire1;
2119 unsigned int wire, ndead = 0;
2120 for (wire = inWire1; wire < inWire2; ++wire)
2128 unsigned short pdg =
abs(PDGCode);
2129 if (pdg == 11)
return 0;
2130 if (pdg == 13)
return 1;
2131 if (pdg == 211)
return 2;
2132 if (pdg == 321)
return 3;
2133 if (pdg == 2212)
return 4;
2142 if (itj > slc.
tjs.size() - 1)
return;
2143 int killTjID = slc.
tjs[itj].ID;
2145 if (
hit.InTraj == killTjID)
hit.InTraj = 0;
2152 if (itj > slc.
tjs.size() - 1)
return;
2155 <<
"RestoreObsoleteTrajectory: Trying to restore not-obsolete trajectory " 2160 for (
auto& tp : slc.
tjs[itj].Pts) {
2161 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
2162 if (tp.UseHit[ii]) {
2164 if (slc.
slHits[iht].InTraj == 0) { slc.
slHits[iht].InTraj = slc.
tjs[itj].ID; }
2177 for (
auto& shortTj : slc.
tjs) {
2178 if (shortTj.AlgMod[
kKilled] || shortTj.AlgMod[
kHaloTj])
continue;
2179 if (shortTj.CTP != inCTP)
continue;
2180 unsigned short spts = shortTj.EndPt[1] - shortTj.EndPt[0];
2181 if (spts > 20)
continue;
2183 if (shortTj.PDGCode == 11)
continue;
2185 if (shortTj.SSID > 0)
continue;
2187 if (tjhits.empty())
continue;
2188 std::vector<int> tids;
2189 std::vector<unsigned short> tcnt;
2190 for (
auto iht : tjhits) {
2192 if (
hit.InTraj <= 0)
continue;
2193 if ((
unsigned int)
hit.InTraj > slc.
tjs.size())
continue;
2194 if (
hit.InTraj == shortTj.ID)
continue;
2195 unsigned short indx = 0;
2196 for (indx = 0; indx < tids.size(); ++indx)
2197 if (
hit.InTraj == tids[indx])
break;
2198 if (indx == tids.size()) {
2199 tids.push_back(
hit.InTraj);
2206 if (tids.empty())
continue;
2208 unsigned short maxcnt = 0;
2209 for (
unsigned short indx = 0; indx < tids.size(); ++indx) {
2210 if (tcnt[indx] > maxcnt) {
2211 auto& ltj = slc.
tjs[tids[indx] - 1];
2212 unsigned short lpts = ltj.EndPt[1] - ltj.EndPt[0];
2213 if (lpts < spts)
continue;
2214 maxcnt = tcnt[indx];
2217 float hitFrac = (float)maxcnt / (
float)tjhits.size();
2218 if (hitFrac < 0.1)
continue;
2232 if (itj > slc.
tjs.size() - 1)
return false;
2234 auto& tj = slc.
tjs[itj];
2237 unsigned short atPt = USHRT_MAX;
2238 for (
unsigned short ipt = tj.EndPt[0] + 1; ipt <= tj.EndPt[1]; ++ipt) {
2239 if (tj.Pts[ipt].Pos[1] > tj.Pts[ipt - 1].Pos[1]) {
2241 if (tj.Pts[ipt - 1].Pos[1] < atPos1 && tj.Pts[ipt].Pos[1] >= atPos1) {
2248 if (tj.Pts[ipt - 1].Pos[1] >= atPos1 && tj.Pts[ipt].Pos[1] < atPos1) {
2254 if (atPt == USHRT_MAX)
return false;
2255 unsigned short vx2Index = USHRT_MAX;
2258 newVx2.
CTP = tj.CTP;
2259 newVx2.
Pos[0] = 0.5 * (tj.Pts[atPt - 1].Pos[0] + tj.Pts[atPt].Pos[0]);
2260 newVx2.
Pos[1] = 0.5 * (tj.Pts[atPt - 1].Pos[1] + tj.Pts[atPt].Pos[1]);
2265 return SplitTraj(slc, itj, atPt, vx2Index, prt);
2269 bool SplitTraj(
TCSlice& slc,
unsigned short itj,
unsigned short pos,
unsigned short ivx,
bool prt)
2276 if (itj > slc.
tjs.size() - 1)
return false;
2277 if (pos < slc.
tjs[itj].EndPt[0] + 1 || pos > slc.
tjs[itj].EndPt[1] - 1)
return false;
2278 if (ivx != USHRT_MAX && ivx > slc.
vtxs.size() - 1)
return false;
2283 bool splittingMuon = (tj.
PDGCode == 13);
2284 if (splittingMuon) tj.
PDGCode = 0;
2288 myprt <<
"SplitTraj: Split T" << tj.
ID <<
" at point " <<
PrintPos(tj.
Pts[pos]);
2289 if (ivx < slc.
vtxs.size()) myprt <<
" with Vtx 2V" << slc.
vtxs[ivx].ID;
2293 unsigned short ntp = 0;
2294 for (
unsigned short ipt = 0; ipt <= pos; ++ipt) {
2295 if (tj.
Pts[ipt].Chg > 0) ++ntp;
2299 if (prt)
mf::LogVerbatim(
"TC") <<
" Split point to small at begin " << ntp <<
" pos " << pos;
2303 for (
unsigned short ipt = pos + 1; ipt <= tj.
EndPt[1]; ++ipt) {
2304 if (tj.
Pts[ipt].Chg > 0) ++ntp;
2309 mf::LogVerbatim(
"TC") <<
" Split point too small at end " << ntp <<
" pos " << pos
2310 <<
" EndPt " << tj.
EndPt[1];
2316 newTj.
ID = slc.
tjs.size() + 1;
2325 for (
unsigned short ipt = pos + 1; ipt <= tj.
EndPt[1]; ++ipt) {
2326 tj.
Pts[ipt].Chg = 0;
2327 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
2328 if (!tj.
Pts[ipt].UseHit[ii])
continue;
2329 iht = tj.
Pts[ipt].Hits[ii];
2331 if (slc.
slHits[iht].InTraj != tj.
ID)
continue;
2333 tj.
Pts[ipt].UseHit[ii] =
false;
2345 unsigned short eraseSize = pos - 2;
2346 if (eraseSize > newTj.
Pts.size() - 1) {
2359 newTj.
Pts.erase(newTj.
Pts.begin(), newTj.
Pts.begin() + eraseSize);
2361 for (
unsigned short ipt = 0; ipt < 3; ++ipt) {
2362 for (
unsigned short ii = 0; ii < newTj.
Pts[ipt].Hits.size(); ++ii)
2363 newTj.
Pts[ipt].UseHit[ii] =
false;
2364 newTj.
Pts[ipt].Chg = 0;
2370 if (ivx < slc.
vtxs.size()) newTj.
VtxID[0] = slc.
vtxs[ivx].ID;
2373 slc.
tjs.push_back(newTj);
2386 unsigned short& closePt,
2390 float best = minSep * minSep;
2391 closePt = USHRT_MAX;
2394 for (ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
2395 dw = tj.
Pts[ipt].Pos[0] - tp.
Pos[0];
2396 dt = tj.
Pts[ipt].Pos[1] - tp.
Pos[1];
2397 dp2 = dw * dw + dt * dt;
2403 minSep = sqrt(best);
2410 unsigned short& ipt1,
2411 unsigned short& ipt2,
2414 return TrajTrajDOCA(slc, tj1, tj2, ipt1, ipt2, minSep,
false);
2421 unsigned short& ipt1,
2422 unsigned short& ipt2,
2424 bool considerDeadWires)
2429 for (
unsigned short iwt = 0; iwt < 2; ++iwt) {
2432 float wt0 = tj1.
Pts[tj1.
EndPt[0]].Pos[iwt];
2433 float wt1 = tj1.
Pts[tj1.
EndPt[1]].Pos[iwt];
2441 wt0 = tj2.
Pts[tj2.
EndPt[0]].Pos[iwt];
2442 wt1 = tj2.
Pts[tj2.
EndPt[1]].Pos[iwt];
2452 if (lowt2 > hiwt1 + minSep)
return false;
2454 if (lowt1 > hiwt2 + minSep)
return false;
2457 float best = minSep * minSep;
2461 bool isClose =
false;
2462 for (
unsigned short i1 = tj1.
EndPt[0]; i1 < tj1.
EndPt[1] + 1; ++i1) {
2463 for (
unsigned short i2 = tj2.
EndPt[0]; i2 < tj2.
EndPt[1] + 1; ++i2) {
2465 float dw = tj1.
Pts[i1].Pos[0] - tj2.
Pts[i2].Pos[0] - dwc;
2466 if (
std::abs(dw) > minSep)
continue;
2467 float dt = tj1.
Pts[i1].Pos[1] - tj2.
Pts[i2].Pos[1];
2468 if (
std::abs(dt) > minSep)
continue;
2469 float dp2 = dw * dw + dt * dt;
2478 minSep = sqrt(best);
2486 if (iht > slc.
slHits.size() - 1 || jht > slc.
slHits.size() - 1)
return 1E6;
2489 float dw = (float)ihit.WireID().Wire - (float)jhit.WireID().Wire;
2491 return dw * dw + dt * dt;
2497 unsigned short endPt = tj.
EndPt[0];
2498 auto& tp0 = tj.
Pts[endPt];
2499 endPt = tj.
EndPt[1];
2500 auto& tp1 = tj.
Pts[endPt];
2508 float dw = wire - tp.
Pos[0];
2509 float dt = time - tp.
Pos[1];
2510 return dw * dw + dt * dt;
2516 if (iht > slc.
slHits.size() - 1)
return 1E6;
2518 float wire =
hit.WireID().Wire;
2535 double t = (double)(wire - tp.
Pos[0]) * tp.
Dir[0] + (double)(time - tp.
Pos[1]) * tp.
Dir[1];
2536 double dw = tp.
Pos[0] + t * tp.
Dir[0] - wire;
2537 double dt = tp.
Pos[1] + t * tp.
Dir[1] - time;
2538 return (
float)(dw * dw + dt * dt);
2555 double arg1 = tp1.
Pos[0] * tp1.
Dir[1] - tp1.
Pos[1] * tp1.
Dir[0];
2556 double arg2 = tp2.
Pos[0] * tp1.
Dir[1] - tp2.
Pos[1] * tp1.
Dir[0];
2557 double arg3 = tp2.
Dir[0] * tp1.
Dir[1] - tp2.
Dir[1] * tp1.
Dir[0];
2558 if (arg3 == 0)
return;
2559 double s = (arg1 - arg2) / arg3;
2561 x = (float)(tp2.
Pos[0] + s * tp2.
Dir[0]);
2562 y = (float)(tp2.
Pos[1] + s * tp2.
Dir[1]);
2570 if (tjIDs.empty())
return 0;
2572 for (
auto tjid : tjIDs) {
2573 if (tjid < 1 || tjid > (
int)slc.
tjs.size())
continue;
2574 auto& tj = slc.
tjs[tjid - 1];
2575 float sep2 =
PosSep2(tj.Pts[tj.EndPt[0]].Pos, tj.Pts[tj.EndPt[1]].Pos);
2576 if (sep2 > maxLen) maxLen = sep2;
2578 return sqrt(maxLen);
2584 float len = 0, dx, dy;
2586 unsigned short prevPt = tj.
EndPt[0];
2587 for (ipt = tj.
EndPt[0] + 1; ipt < tj.
EndPt[1] + 1; ++ipt) {
2588 if (tj.
Pts[ipt].Chg == 0)
continue;
2589 dx = tj.
Pts[ipt].Pos[0] - tj.
Pts[prevPt].Pos[0];
2590 dy = tj.
Pts[ipt].Pos[1] - tj.
Pts[prevPt].Pos[1];
2591 len += sqrt(dx * dx + dy * dy);
2600 return sqrt(
PosSep2(pos1, pos2));
2607 float d0 = pos1[0] - pos2[0];
2608 float d1 = pos1[1] - pos2[1];
2609 return d0 * d0 + d1 * d1;
2616 float dx = tp1.
Pos[0] - tp2.
Pos[0];
2617 float dy = tp1.
Pos[1] - tp2.
Pos[1];
2618 return sqrt(dx * dx + dy * dy);
2625 unsigned short& closePt,
2632 float close2 = DOCA * DOCA;
2634 bool foundClose =
false;
2636 for (
unsigned short ipt = tj.
EndPt[0]; ipt < tj.
EndPt[1] + 1; ++ipt) {
2637 if (tj.
Pts[ipt].Chg == 0)
continue;
2638 float dx = tj.
Pts[ipt].Pos[0] -
x;
2640 float dy = tj.
Pts[ipt].Pos[1] -
y;
2642 float sep2 = dx * dx + dy * dy;
2643 if (sep2 < close2) {
2650 DOCA = sqrt(close2);
2659 float dw = tp2.
Pos[0] - tp1.
Pos[0];
2660 float dt = tp2.
Pos[1] - tp1.
Pos[1];
2661 return atan2(dw, dt);
2670 std::vector<unsigned int> hitVec;
2671 if (pfp.
TP3Ds.empty())
return hitVec;
2673 for (
auto& tp3d : pfp.
TP3Ds) {
2674 if (tp3d.Flags[
kTP3DBad])
continue;
2675 if (tp3d.TjID <= 0)
continue;
2676 auto& tp = slc.
tjs[tp3d.TjID - 1].Pts[tp3d.TPIndex];
2677 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
2678 unsigned int iht = tp.Hits[ii];
2679 bool useit = (hitRequest ==
kAllHits);
2680 if (tp.UseHit[ii] && hitRequest ==
kUsedHits) useit =
true;
2681 if (!tp.UseHit[ii] && hitRequest ==
kUnusedHits) useit =
true;
2682 if (useit) hitVec.push_back(iht);
2692 std::vector<unsigned int> hitVec;
2696 for (
auto& tp : tj.
Pts)
2697 hitVec.insert(hitVec.end(), tp.Hits.begin(), tp.Hits.end());
2702 hitVec.reserve(tj.
Pts.size());
2703 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
2704 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
2705 unsigned int iht = tj.
Pts[ipt].Hits[ii];
2706 bool useit = (hitRequest ==
kAllHits);
2707 if (tj.
Pts[ipt].UseHit[ii] && hitRequest ==
kUsedHits) useit =
true;
2708 if (!tj.
Pts[ipt].UseHit[ii] && hitRequest ==
kUnusedHits) useit =
true;
2709 if (useit) hitVec.push_back(iht);
2723 if (tj.
Pts.size() > 10)
return;
2724 if (tj.
PDGCode == 111)
return;
2726 unsigned short nhm = 0;
2727 unsigned short npwc = 0;
2728 for (
auto& tp : tj.
Pts) {
2729 if (tp.Chg == 0)
continue;
2731 unsigned short nused = 0;
2732 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
2733 if (tp.UseHit[ii]) ++nused;
2735 if (nused > 3) ++nhm;
2740 mf::LogVerbatim(
"TC") <<
"TGT: T" << tj.
ID <<
" npwc " << npwc <<
" nhm " << nhm <<
" junk? " 2749 for (
unsigned short ii = 0; ii < tjHits.size() - 1; ++ii) {
2750 for (
unsigned short jj = ii + 1; jj < tjHits.size(); ++jj) {
2751 if (tjHits[ii] == tjHits[jj]) {
2766 if (tp.
Dir[0] == 0)
return;
2767 float dw = wire - tp.
Pos[0];
2770 tp.
Pos[1] += dw * tp.
Dir[1] / tp.
Dir[0];
2775 std::array<int, 2>
const& wireWindow,
2777 const unsigned short plane,
2796 std::vector<unsigned int> closeHits;
2797 if (plane > slc.
firstWire.size() - 1)
return closeHits;
2799 int loWire = wireWindow[0];
2801 int hiWire = wireWindow[1];
2806 for (
int wire = loWire; wire <= hiWire; ++wire) {
2809 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
continue;
2810 unsigned int firstHit = slc.
wireHitRange[plane][wire].first;
2811 unsigned int lastHit = slc.
wireHitRange[plane][wire].second;
2812 for (
unsigned int iht = firstHit; iht <= lastHit; ++iht) {
2815 if (
hit.PeakTime() < minTick)
continue;
2816 if (
hit.PeakTime() > maxTick)
break;
2820 if (
hit.StartTick() > hiLo) hiLo =
hit.StartTick();
2822 if (
hit.EndTick() < loHi) loHi =
hit.EndTick();
2823 if (loHi < hiLo)
continue;
2824 if (hiLo > loHi)
break;
2827 bool takeit = (hitRequest ==
kAllHits);
2828 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) takeit =
true;
2830 if (takeit) closeHits.push_back(iht);
2839 float const maxDelta,
2850 if (tp.
Pos[0] < -0.4)
return false;
2852 unsigned int wire = std::nearbyint(tp.
Pos[0]);
2853 if (wire < slc.
firstWire[plane])
return false;
2854 if (wire > slc.
lastWire[plane] - 1)
return false;
2863 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
return false;
2865 unsigned int firstHit = slc.
wireHitRange[plane][wire].first;
2866 unsigned int lastHit = slc.
wireHitRange[plane][wire].second;
2869 for (
unsigned int iht = firstHit; iht <= lastHit; ++iht) {
2870 if ((
unsigned int)slc.
slHits[iht].InTraj > slc.
tjs.size())
continue;
2871 bool useit = (hitRequest ==
kAllHits);
2872 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) useit =
true;
2874 if (!useit)
continue;
2878 if (delta < maxDelta) tp.
Hits.push_back(iht);
2880 if (tp.
Hits.size() > 16) { tp.
Hits.resize(16); }
2883 return (!tp.
Hits.empty());
2895 if (end > 1)
return USHRT_MAX;
2897 if (end == 1) dir = -1;
2898 for (
short ii = 0; ii < (short)tj.
Pts.size(); ++ii) {
2899 short ipt = tj.
EndPt[
end] + dir * ii;
2900 if (ipt < 0 || ipt >= (
short)tj.
Pts.size())
return USHRT_MAX;
2901 auto& tp = tj.
Pts[ipt];
2911 const float& maxDelta)
2929 std::vector<int>
tmp;
2930 if (fromTp.
Pos[0] < -0.4 || toTp.
Pos[0] < -0.4)
return tmp;
2934 unsigned int firstWire, lastWire;
2935 if (toTp.
Pos[0] > fromTp.
Pos[0]) {
2937 firstWire = std::nearbyint(fromTp.
Pos[0]);
2938 lastWire = std::nearbyint(toTp.
Pos[0]);
2940 else if (toTp.
Pos[0] < fromTp.
Pos[0]) {
2942 firstWire = std::nearbyint(toTp.
Pos[0]);
2943 lastWire = std::nearbyint(fromTp.
Pos[0]);
2947 float tmp = fromTp.
Pos[0] - maxDelta;
2948 if (tmp < 0) tmp = 0;
2949 firstWire = std::nearbyint(tmp);
2950 tmp = fromTp.
Pos[0] + maxDelta;
2951 lastWire = std::nearbyint(tmp);
2957 if (firstWire > slc.
lastWire[plane] - 1)
return tmp;
2959 if (lastWire > slc.
lastWire[plane] - 1) lastWire = slc.
lastWire[plane] - 1;
2961 for (
unsigned int wire = firstWire; wire <= lastWire; ++wire) {
2962 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
continue;
2967 unsigned int firstHit = slc.
wireHitRange[plane][wire].first;
2968 unsigned int lastHit = slc.
wireHitRange[plane][wire].second;
2969 for (
unsigned int iht = firstHit; iht <= lastHit; ++iht) {
2970 if (slc.
slHits[iht].InTraj <= 0)
continue;
2971 if ((
unsigned int)slc.
slHits[iht].InTraj > slc.
tjs.size())
continue;
2973 if (
hit.PeakTime() < minTick)
continue;
2975 if (
hit.PeakTime() > maxTick)
break;
2976 if (std::find(tmp.begin(), tmp.end(), slc.
slHits[iht].InTraj) != tmp.end())
continue;
2977 tmp.push_back(slc.
slHits[iht].InTraj);
2988 unsigned short end1,
2990 unsigned short end2,
2991 unsigned short nPtsFit,
2998 if (tj1.
CTP != tj2.
CTP)
return -1;
2999 if (end1 > 1 || end2 > 1)
return -1;
3007 if (end1 == 1) dir = -1;
3008 unsigned short cnt = 0;
3010 for (
short ii = 0; ii < (short)tj1.
Pts.size(); ++ii) {
3011 short ipt = tj1.
EndPt[end1] + dir * ii;
3013 if (ipt >= (
short)tj1.
Pts.size())
break;
3014 auto& tp = tj1.
Pts[ipt];
3015 if (tp.Chg <= 0)
continue;
3016 tj.
Pts.push_back(tp);
3018 if (cnt == nPtsFit + 1)
break;
3020 if (cnt < nPtsFit)
return -1;
3023 if (end2 == 1) dir = -1;
3025 for (
short ii = 0; ii < (short)tj2.
Pts.size(); ++ii) {
3026 short ipt = tj2.
EndPt[end2] + dir * ii;
3028 if (ipt >= (
short)tj2.
Pts.size())
break;
3029 auto& tp = tj2.
Pts[ipt];
3030 if (tp.Chg <= 0)
continue;
3031 tj.
Pts.push_back(tp);
3033 if (cnt == nPtsFit + 1)
break;
3043 unsigned short kinkPt,
3044 unsigned short nPtsFit,
3053 if (kinkPt < tj.
EndPt[0] + 2)
return -1;
3054 if (kinkPt > tj.
EndPt[1] - 2)
return -1;
3057 if (nPtsFit < 3)
return -1;
3060 if (npwc < 2 * nPtsFit + 1)
return -1;
3065 double chgRMS = 0.07;
3069 double tFactor = 1 + 0.3 / double(nPtsFit - 2);
3075 FitTraj(slc, tj, kinkPt, nPtsFit, fitDir, tpPos);
3076 if (tpPos.
FitChi > 900)
return -1;
3080 FitTraj(slc, tj, kinkPt, nPtsFit, fitDir, tpNeg);
3081 if (tpNeg.
FitChi > 900)
return -1;
3082 double angErr = tpNeg.
AngErr;
3086 double dangSig = dang / angErr;
3093 unsigned short cntNeg = 0;
3094 for (
unsigned short ipt = kinkPt - 1; ipt >= tj.
EndPt[0]; --ipt) {
3095 auto& tp = tj.
Pts[ipt];
3096 if (tp.Chg <= 0)
continue;
3099 if (cntNeg == nPtsFit)
break;
3100 if (ipt == 0)
break;
3102 if (cntNeg != nPtsFit) {
3103 if (prt)
mf::LogVerbatim(
"TC") <<
" KL: Bad cntNeg " << cntNeg <<
" != " << nPtsFit;
3108 unsigned short cntPos = 0;
3109 for (
unsigned short ipt = kinkPt + 1; ipt <= tj.
EndPt[1]; ++ipt) {
3110 auto& tp = tj.
Pts[ipt];
3111 if (tp.Chg <= 0)
continue;
3114 if (cntPos == nPtsFit)
break;
3116 if (cntPos != nPtsFit) {
3117 if (prt)
mf::LogVerbatim(
"TC") <<
" KL: Bad cntPos " << cntPos <<
" != " << nPtsFit;
3120 chgNeg /= (float)nPtsFit;
3121 chgPos /= (float)nPtsFit;
3123 chgAsym =
std::abs(chgPos - chgNeg) / (chgPos + chgNeg);
3125 chgSig = chgAsym / chgRMS;
3127 double kinkSig = sqrt(dangSig * dangSig + chgSig * chgSig);
3131 myprt <<
"KL: T" << tj.
ID <<
" kinkPt " <<
PrintPos(tj.
Pts[kinkPt]);
3132 myprt <<
" nPtsFit " << nPtsFit;
3133 myprt <<
" dang " << std::fixed << std::setprecision(3) << dang;
3134 myprt << std::fixed << std::setprecision(3) <<
" angErr " << angErr;
3135 myprt << std::setprecision(2) <<
" sig " << dangSig;
3136 myprt <<
" chgAsym " << chgAsym;
3137 myprt <<
" chgSig " << chgSig;
3138 myprt <<
" kinkSig " << kinkSig;
3140 return (
float)kinkSig;
3150 unsigned short midPt = 0.5 * (tj.
EndPt[0] + tj.
EndPt[1]);
3151 double rms0 = 0, rms1 = 0;
3155 float asym =
std::abs(rms0 - rms1) / (rms0 + rms1);
3156 float chgFact = (tj.
ChgRMS - 0.1) * 5;
3157 float elh = 5 * asym * chgFact;
3158 if (elh > 1) elh = 1;
3167 if (tjIDs.empty())
return 0;
3168 std::array<int, 2> wireWindow;
3171 constexpr
float NNDelta = 5;
3172 wireWindow[0] = pos[0] - NNDelta;
3173 wireWindow[1] = pos[0] + NNDelta;
3174 timeWindow[0] = pos[1] - NNDelta;
3175 timeWindow[1] = pos[1] + NNDelta;
3177 for (
auto& tjID : tjIDs)
3178 if (tjID <= 0 || tjID > (
int)slc.
tjs.size())
return 0;
3183 std::vector<unsigned int> closeHits =
3185 if (closeHits.empty())
return 0;
3190 for (
auto& iht : closeHits) {
3192 chg +=
hit.Integral();
3193 if (slc.
slHits[iht].InTraj == 0)
continue;
3194 if (std::find(tjIDs.begin(), tjIDs.end(), slc.
slHits[iht].InTraj) != tjIDs.end())
3195 tchg +=
hit.Integral();
3197 if (chg == 0)
return 0;
3204 float delta, md = 0;
3207 for (
auto& tp : tj.
Pts) {
3208 for (ii = 0; ii < tp.Hits.size(); ++ii) {
3209 if (!tp.UseHit[ii])
continue;
3212 if (delta > md) md = delta;
3222 if (tj.
Pts.empty())
return;
3228 std::reverse(tj.
Pts.begin(), tj.
Pts.end());
3233 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
3234 if (tj.
Pts[ipt].Dir[0] != 0) tj.
Pts[ipt].Dir[0] = -tj.
Pts[ipt].Dir[0];
3235 if (tj.
Pts[ipt].Dir[1] != 0) tj.
Pts[ipt].Dir[1] = -tj.
Pts[ipt].Dir[1];
3236 if (tj.
Pts[ipt].Ang > 0) { tj.
Pts[ipt].Ang -= M_PI; }
3238 tj.
Pts[ipt].Ang += M_PI;
3254 unsigned short nvx = Envelope.size();
3255 double angleSum = 0;
3256 for (
unsigned short ii = 0; ii < Envelope.size(); ++ii) {
3257 p1[0] = Envelope[ii][0] - Point[0];
3258 p1[1] = Envelope[ii][1] - Point[1];
3259 p2[0] = Envelope[(ii + 1) % nvx][0] - Point[0];
3260 p2[1] = Envelope[(ii + 1) % nvx][1] - Point[1];
3263 if (
abs(angleSum) < M_PI)
return false;
3271 double den = v1[0] * v1[0] + v1[1] * v1[1];
3272 if (den == 0)
return false;
3286 if (pos1[0] == pos2[0] && pos1[1] == pos2[1])
return;
3287 pos1[0] = pos2[0] - pos1[0];
3288 pos1[1] = pos2[1] - pos1[1];
3289 double sep = sqrt(pos1[0] * pos1[0] + pos1[1] * pos1[1]);
3290 if (sep < 1
E-6)
return;
3292 ptDir[0] = pos1[0] / sep;
3293 ptDir[1] = pos1[1] / sep;
3295 double costh =
DotProd(dir1, ptDir);
3296 if (costh > 1.0 || costh < -1.0)
return;
3297 alongTrans[0] = costh * sep;
3298 double sinth = sqrt(1 - costh * costh);
3299 alongTrans[1] = sinth * sep;
3306 double ang1 = atan2(p1[1], p1[0]);
3307 double ang2 = atan2(p2[1], p2[0]);
3314 constexpr
double twopi = 2 * M_PI;
3315 double dang = Ang1 - Ang2;
3318 while (dang < -M_PI)
3326 return std::abs(std::remainder(Ang1 - Ang2, M_PI));
3339 if (tj.
Pts.size() == 0)
return;
3342 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
3343 if (tj.
Pts[ipt].Chg != 0) {
3348 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
3349 unsigned short ipt = tj.
Pts.size() - 1 - ii;
3350 if (tj.
Pts[ipt].Chg != 0) {
3362 unsigned short nUsed = 0;
3363 unsigned short nTotHits = 0;
3364 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
3366 nTotHits += tp.
Hits.size();
3367 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
3368 if (tp.
UseHit[ii]) ++nUsed;
3371 if (nTotHits == 0)
return false;
3372 float fracUsed = (float)nUsed / (
float)nTotHits;
3374 mf::LogVerbatim(
"TC") <<
"TrajIsClean: nTotHits " << nTotHits <<
" nUsed " << nUsed
3375 <<
" fracUsed " << fracUsed;
3377 return fracUsed > 0.9;
3384 if (tjIDs.empty())
return 0;
3387 for (
auto tjid : tjIDs) {
3388 auto& tj = slc.
tjs[tjid - 1];
3389 float npts = tj.EndPt[1] - tj.EndPt[0] + 1;
3390 summ += npts * tj.MCSMom;
3393 return (
short)(summ / suml);
3405 unsigned short firstPt,
3406 unsigned short lastPt)
3410 if (firstPt == lastPt)
return 0;
3411 if (firstPt > lastPt) std::swap(firstPt, lastPt);
3415 if (firstPt >= lastPt)
return 0;
3417 if (firstPt < tj.
EndPt[0])
return 0;
3418 if (lastPt > tj.
EndPt[1])
return 0;
3425 if (tjLen < 1)
return 0;
3427 double thetaRMS =
MCSThetaRMS(tj, firstPt, lastPt);
3428 if (thetaRMS < 0.001)
return 999;
3429 double mom = 13.8 * sqrt(tjLen / 14) / thetaRMS;
3430 if (mom > 999) mom = 999;
3438 if (thePt > tj.
EndPt[1])
return thePt;
3439 if (tj.
Pts[thePt].Chg > 0)
return thePt;
3441 short endPt0 = tj.
EndPt[0];
3442 short endPt1 = tj.
EndPt[1];
3443 for (
short off = 1; off < 10; ++off) {
3444 short ipt = thePt + off;
3445 if (ipt <= endPt1 && tj.
Pts[ipt].Chg > 0)
return (
unsigned short)ipt;
3447 if (ipt >= endPt0 && tj.
Pts[ipt].Chg > 0)
return (
unsigned short)ipt;
3460 if (tps < 1)
return 1;
3472 if (firstPt < tj.
EndPt[0])
return 1;
3473 if (lastPt > tj.
EndPt[1])
return 1;
3477 if (firstPt >= lastPt)
return 1;
3481 TjDeltaRMS(tj, firstPt, lastPt, sigmaS, cnt);
3482 if (sigmaS < 0)
return 1;
3484 if (tjLen < 1)
return 1;
3486 return (6.8 * sigmaS / tjLen);
3492 unsigned short firstPt,
3493 unsigned short lastPt,
3495 unsigned short& cnt)
3500 if (firstPt < tj.
EndPt[0])
return;
3501 if (lastPt > tj.
EndPt[1])
return;
3505 if (firstPt >= lastPt)
return;
3518 for (
unsigned short ipt = firstPt + 1; ipt < lastPt; ++ipt) {
3519 if (tj.
Pts[ipt].Chg == 0)
continue;
3521 if (tj.
Pts[ipt].HitPosErr2 > 4)
continue;
3525 if (cnt < 2)
return;
3526 rms = sqrt(dsum / (
double)cnt);
3537 std::array<int, 2> wireWindow;
3543 for (
auto& mutj : slc.
tjs) {
3544 if (mutj.AlgMod[
kKilled])
continue;
3545 if (mutj.CTP != inCTP)
continue;
3546 if (mutj.PDGCode != 13)
continue;
3547 unsigned short nnear = 0;
3548 for (
unsigned short ipt = mutj.EndPt[0]; ipt <= mutj.EndPt[1]; ++ipt) {
3549 auto& tp = mutj.Pts[ipt];
3550 wireWindow[0] = tp.Pos[0];
3551 wireWindow[1] = tp.Pos[0];
3552 timeWindow[0] = tp.Pos[1] - delta;
3553 timeWindow[1] = tp.Pos[1] + delta;
3558 if (closeHits.empty())
continue;
3559 for (
auto iht : closeHits) {
3560 auto inTraj = slc.
slHits[iht].InTraj;
3561 if (inTraj <= 0)
continue;
3562 if (inTraj == mutj.ID)
continue;
3563 auto& dtj = slc.
tjs[inTraj - 1];
3564 if (dtj.PDGCode == 13)
continue;
3565 for (
unsigned short jpt = dtj.EndPt[0]; jpt <= dtj.EndPt[1]; ++jpt) {
3566 auto& dtp = dtj.Pts[jpt];
3567 if (std::find(dtp.Hits.begin(), dtp.Hits.end(), iht) == dtp.Hits.end())
continue;
3586 for (
auto& tp : tj.
Pts) {
3587 if (tp.Chg <= 0)
continue;
3589 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
3590 if (tp.UseHit[ii])
continue;
3591 unsigned int iht = tp.Hits[ii];
3617 for (
unsigned short ipt = tj.
EndPt[0] + 1; ipt < tj.
EndPt[1]; ++ipt) {
3618 auto& tp = tj.
Pts[ipt];
3619 if (tp.Chg > bigChg) bigChg = tp.Chg;
3626 for (
unsigned short ipt = tj.
EndPt[0] + 1; ipt < tj.
EndPt[1]; ++ipt) {
3627 auto& tp = tj.
Pts[ipt];
3628 if (tp.Chg <= 0)
continue;
3630 if (tp.Chg == bigChg)
continue;
3635 bsum2 += tp.Chg * tp.Chg;
3636 if (tp.Chg > bigChg) bigChg = tp.Chg;
3642 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
3643 if (!tp.UseHit[ii])
continue;
3644 unsigned int iht = tp.Hits[ii];
3648 vsum2 += tpchg * tpchg;
3651 if (bcnt == 0)
return;
3659 if (arg > 0) tj.
ChgRMS = sqrt(arg / (bcnt - 1));
3661 for (
auto& tp : tj.
Pts)
3664 mf::LogVerbatim(
"TC") << inFcnLabel <<
".UpdateTjChgProperties: backup sum Set tj.AveChg " 3669 double nWires = tj.
EndPt[1] - tj.
EndPt[0] + 1;
3670 if (nWires < 2)
return;
3675 for (
unsigned short end = 0;
end < 2; ++
end) {
3679 int dw =
std::abs(tp.Pos[0] - vx2.Pos[0]);
3691 if (arg > 0) rms = sqrt(arg / (vcnt - 1));
3694 if (rms < 0.1) rms = 0.1;
3698 double defFrac = 1 / vcnt;
3699 rms = defFrac * 0.5 + (1 - defFrac) * rms;
3703 mf::LogVerbatim(
"TC") << inFcnLabel <<
".UpdateTjChgProperties: Set tj.AveChg " 3710 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
3711 auto& tp = tj.
Pts[ipt];
3712 if (tp.Chg <= 0)
continue;
3719 for (
auto& tp : tj.
Pts)
3725 for (
auto& tp : tj.
Pts)
3729 unsigned short minPt = tj.
EndPt[0] + nptsave;
3731 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
3732 unsigned short ipt = tj.
EndPt[1] - ii;
3733 if (ipt < minPt)
break;
3736 for (
unsigned short iii = 0; iii < nptsave; ++iii) {
3737 unsigned short iipt = ipt - iii;
3739 if (iipt == tj.
EndPt[0])
break;
3740 auto& tp = tj.
Pts[iipt];
3741 if (tp.Chg <= 0)
continue;
3746 tj.
Pts[ipt].AveChg = sum / cnt;
3747 lastAve = tj.
Pts[ipt].AveChg;
3751 for (
unsigned short ii = tj.
EndPt[0]; ii <= tj.
EndPt[1]; ++ii) {
3752 unsigned short ipt = tj.
EndPt[1] - ii;
3753 auto& tp = tj.
Pts[ipt];
3754 if (tp.AveChg == 0) { tp.AveChg = lastAve; }
3756 lastAve = tp.AveChg;
3773 for (
auto& tj : slc.
tjs) {
3774 if (tj.AlgMod[
kKilled])
continue;
3775 for (
auto& tp : tj.Pts)
3779 for (
auto& vx : slc.
vtxs) {
3780 if (vx.ID <= 0)
continue;
3791 if (vx2.
ID == 0)
return;
3794 if (prt)
mf::LogVerbatim(
"TC") <<
"UpdateVxEnvironment check Tjs attached to vx2 " << vx2.
ID;
3796 std::vector<int> tjlist;
3797 std::vector<unsigned short> tjends;
3798 if (vx2.
Pos[0] < -0.4)
return;
3799 unsigned int vxWire = std::nearbyint(vx2.
Pos[0]);
3800 unsigned int loWire = vxWire;
3801 unsigned int hiWire = vxWire;
3802 for (
auto& tj : slc.
tjs) {
3804 if (tj.CTP != vx2.
CTP)
continue;
3806 if (tj.AlgMod[
kPhoton])
continue;
3807 for (
unsigned short end = 0;
end < 2; ++
end) {
3808 if (tj.VtxID[
end] != vx2.
ID)
continue;
3809 tjlist.push_back(tj.ID);
3810 tjends.push_back(
end);
3811 if (tj.Pts[tj.EndPt[
end]].Pos[0] < -0.4)
return;
3812 unsigned int endWire = std::nearbyint(tj.Pts[tj.EndPt[
end]].Pos[0]);
3813 if (endWire < loWire) loWire = endWire;
3814 if (endWire > hiWire) hiWire = endWire;
3817 if (tjlist.size() < 2)
return;
3818 if (hiWire < loWire + 1)
return;
3820 mf::LogVerbatim(
"TC") <<
" check Tjs on wires in the range " << loWire <<
" to " << hiWire;
3824 std::vector<std::vector<TrajPoint>> wire_tjpt;
3826 std::vector<int> tjids;
3828 unsigned short nwires = hiWire - loWire + 1;
3829 for (
unsigned short itj = 0; itj < tjlist.size(); ++itj) {
3830 auto& tj = slc.
tjs[tjlist[itj] - 1];
3831 unsigned short end = tjends[itj];
3832 std::vector<TrajPoint> tjpt(nwires);
3834 for (
unsigned short ii = 0; ii < tj.Pts.size(); ++ii) {
3836 if (end == 0) { ipt = tj.EndPt[0] + ii; }
3838 ipt = tj.EndPt[1] - ii;
3840 if (ipt > tj.Pts.size() - 1)
break;
3842 auto tp = tj.Pts[ipt];
3843 if (tp.Chg <= 0)
continue;
3846 if (tp.Pos[0] < -0.4)
continue;
3847 unsigned int wire = std::nearbyint(tp.Pos[0]);
3848 unsigned short indx = wire - loWire;
3849 if (indx > nwires - 1)
break;
3859 if (ltp.
Dir[0] == 0)
continue;
3860 if (ltp.
Pos[0] < -0.4)
continue;
3861 unsigned int wire = std::nearbyint(ltp.
Pos[0]);
3863 unsigned short indx = wire - loWire;
3865 if (tjpt[indx].Chg == 0) tjpt[indx] = ltp;
3867 for (
unsigned short ii = 0; ii < nwires; ++ii) {
3869 for (
unsigned short iwt = 0; iwt < 2; ++iwt)
3870 ltp.
Pos[iwt] += ltp.
Dir[iwt] * stepSize;
3871 if (ltp.
Pos[0] < -0.4)
break;
3872 wire = std::nearbyint(ltp.
Pos[0]);
3873 if (wire < loWire || wire > hiWire)
break;
3874 indx = wire - loWire;
3875 if (tjpt[indx].Chg > 0)
continue;
3880 myprt <<
" T" << tj.ID;
3881 for (
auto& tp : tjpt)
3882 myprt <<
" " <<
PrintPos(tp.Pos) <<
"_" << tp.Step <<
"_" << (int)tp.Chg;
3884 wire_tjpt.push_back(tjpt);
3885 tjids.push_back(tj.ID);
3889 for (
unsigned short indx = 0; indx < nwires; ++indx) {
3891 unsigned short npts = 0;
3893 unsigned short npwc = 0;
3894 for (
unsigned short itj = 0; itj < wire_tjpt.size(); ++itj) {
3895 if (wire_tjpt[itj][indx].Pos[0] == 0)
continue;
3898 if (wire_tjpt[itj][indx].Chg > 0) ++npwc;
3901 if (npts == 0)
continue;
3903 if (npwc == npts)
continue;
3905 for (
unsigned short itj = 0; itj < wire_tjpt.size(); ++itj) {
3906 if (wire_tjpt[itj][indx].Pos[0] == 0)
continue;
3907 if (wire_tjpt[itj][indx].Chg == 0)
continue;
3908 auto& tj = slc.
tjs[tjids[itj] - 1];
3909 unsigned short ipt = wire_tjpt[itj][indx].Step;
3911 tj.NeedsUpdate =
true;
3912 if (prt)
mf::LogVerbatim(
"TC") <<
" Set kEnvOverlap bit on T" << tj.ID <<
" ipt " << ipt;
3918 for (
auto tjid : tjids) {
3919 auto& tj = slc.
tjs[tjid - 1];
3920 if (!tj.NeedsUpdate)
continue;
3921 if (tj.CTP != vx2.
CTP)
continue;
3965 if (dir[0] == 0 && dir[1] == 0 && dir[2] == 0)
return tp;
3969 Point3_t pos3 = {{100 * dir[0], 100 * dir[1], 100 * dir[2]}};
3971 std::array<double, 2> ori2;
3972 std::array<double, 2> pos2;
3973 std::array<double, 2> dir2;
3976 ori2[0] = plane.WireCoordinate(
geo::Point_t{0, ori3[1], ori3[2]});
3977 pos2[0] = plane.WireCoordinate(
geo::Point_t{0, pos3[1], pos3[2]});
3982 dir2[0] = pos2[0] - ori2[0];
3983 dir2[1] = pos2[1] - ori2[1];
3985 double norm = sqrt(dir2[0] * dir2[0] + dir2[1] * dir2[1]);
3988 tp.
Ang = atan2(dir2[1], dir2[0]);
3989 tp.
Delta = norm / 100;
3992 double w0 = plane.WireCoordinate(
geo::Point_t{0, 0, 0});
3994 double cs = plane.WireCoordinate(
geo::Point_t{0, 1, 0}) - w0;
3997 norm = sqrt(cs * cs + sn * sn);
4002 tp.
DeltaRMS = 100 / (pos2[0] - ori2[0]);
4009 unsigned int fromHit,
4013 if (fromHit > slc.
slHits.size() - 1)
return false;
4014 if (toHit > slc.
slHits.size() - 1)
return false;
4020 (float)thit.WireID().Wire,
4036 tp.
Pos[0] = fromWire;
4038 tp.
Dir[0] = toWire - fromWire;
4041 if (norm == 0)
return false;
4051 tpOut.
Pos = fromPos;
4053 tpOut.
Ang = atan2(tpOut.
Dir[1], tpOut.
Dir[0]);
4064 tpOut.
Ang = atan2(tpOut.
Dir[1], tpOut.
Dir[0]);
4072 if (tj.
ID == 0)
return 0;
4082 for (
unsigned short xyz = 0; xyz < 2; ++xyz)
4083 dir[xyz] = p2[xyz] - p1[xyz];
4084 if (dir[0] == 0 && dir[1] == 0)
return dir;
4085 double norm = sqrt(dir[0] * dir[0] + dir[1] * dir[1]);
4103 if (tp.
Hits.empty())
return 0;
4104 float minVal = 9999;
4106 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
4107 bool useit = (hitRequest ==
kAllHits);
4110 if (!useit)
continue;
4111 unsigned int iht = tp.
Hits[ii];
4113 float cv =
hit.PeakTime();
4114 float rms =
hit.RMS();
4115 float arg = cv - rms;
4116 if (arg < minVal) minVal = arg;
4118 if (arg > maxVal) maxVal = arg;
4120 if (maxVal == 0)
return 0;
4121 return (maxVal - minVal) / 2;
4126 const std::vector<unsigned int>& hitsInMultiplet,
4134 const std::vector<unsigned int>& hitsInMultiplet,
4137 if (hitsInMultiplet.empty())
return 0;
4139 if (hitsInMultiplet.size() == 1) {
4144 float minVal = 9999;
4146 for (
unsigned short ii = 0; ii < hitsInMultiplet.size(); ++ii) {
4147 unsigned int iht = hitsInMultiplet[ii];
4148 bool useit = (hitRequest ==
kAllHits);
4149 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) useit =
true;
4151 if (!useit)
continue;
4153 float cv =
hit.PeakTime();
4154 float rms =
hit.RMS();
4155 float arg = cv - rms;
4156 if (arg < minVal) minVal = arg;
4158 if (arg > maxVal) maxVal = arg;
4160 if (maxVal == 0)
return 0;
4161 return (maxVal - minVal) / 2;
4166 const std::vector<unsigned int>& hitsInMultiplet,
4175 const std::vector<unsigned int>& hitsInMultiplet,
4182 for (
unsigned short ii = 0; ii < hitsInMultiplet.size(); ++ii) {
4183 unsigned int iht = hitsInMultiplet[ii];
4184 bool useit = (hitRequest ==
kAllHits);
4185 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) useit =
true;
4187 if (!useit)
continue;
4189 float chg =
hit.Integral();
4190 pos += chg *
hit.PeakTime();
4193 if (sum <= 0)
return -1;
4201 if (tp.
Hits.empty())
return 0;
4205 unsigned short nhits = 0;
4206 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
4208 if (tp.
UseHit[ii]) ++nhits;
4212 if (!tp.
UseHit[ii]) ++nhits;
4221 if (itj > slc.
tjs.size() - 1)
return;
4255 if (npwc > 500) isAMuon =
true;
4274 std::vector<float> cnt(nplanes, 0);
4275 for (
unsigned short iht = 0; iht < (*
evt.
allHits).
size(); ++iht) {
4277 unsigned short plane =
hit.WireID().Plane;
4278 if (plane > nplanes - 1)
return false;
4279 if (cnt[plane] > 200)
continue;
4281 if (
hit.Multiplicity() != 1)
continue;
4283 if (
hit.GoodnessOfFit() < 0 ||
hit.GoodnessOfFit() > 500)
continue;
4285 if (
hit.PeakAmplitude() < 1)
continue;
4289 bool allDone =
true;
4290 for (
unsigned short plane = 0; plane < nplanes; ++plane)
4291 if (cnt[plane] < 200) allDone =
false;
4297 for (
unsigned short plane = 0; plane < nplanes; ++plane) {
4298 if (cnt[plane] > 4) {
evt.
aveHitRMS[plane] /= cnt[plane]; }
4306 std::cout <<
"Analyze hits aveHitRMS";
4307 std::cout << std::fixed << std::setprecision(1);
4309 std::cout <<
" " << rms;
4338 lariov::ChannelStatusProvider
const& channelStatus =
4345 for (
unsigned int wire = 0; wire < nwires; ++wire) {
4347 evt.
goodWire[
id.Plane][wire] = channelStatus.IsGood(chan);
4369 for (
unsigned int wire = 0; wire < nwires; ++wire)
4374 unsigned int nBadWireFix = 0;
4377 auto const& wid =
hit.WireID();
4379 if (static_cast<geo::TPCID const&>(wid) != inTPCID)
continue;
4380 unsigned short pln = wid.Plane;
4381 unsigned int wire = wid.Wire;
4391 std::cout <<
"FillWireHitRange found hits on " << nBadWireFix
4392 <<
" wires that were declared not-good by the ChannelStatus service. Fixed it...\n";
4410 if (nplanes > 3)
return false;
4413 auto const world = tpcgeom.GetCenter();
4416 slc.
xLo = world.X() - tpcgeom.HalfWidth() + 1;
4417 slc.
xHi = world.X() + tpcgeom.HalfWidth() - 1;
4418 slc.
yLo = world.Y() - tpcgeom.HalfHeight() + 1;
4419 slc.
yHi = world.Y() + tpcgeom.HalfHeight() - 1;
4420 slc.
zLo = world.Z() - tpcgeom.Length() / 2 + 1;
4421 slc.
zHi = world.Z() + tpcgeom.Length() / 2 - 1;
4427 slc.
nWires.resize(nplanes);
4432 std::pair<unsigned int, unsigned int> flag{UINT_MAX, UINT_MAX};
4447 for (
unsigned short plane = 0; plane < nplanes; ++plane) {
4456 unsigned int lastWire = 0, lastPlane = 0;
4457 for (
unsigned int iht = 0; iht < slc.
slHits.size(); ++iht) {
4458 unsigned int ahi = slc.
slHits[iht].allHitsIndex;
4459 if (ahi > (*
evt.
allHits).size() - 1)
return false;
4461 if (
hit.WireID().Cryostat != cstat)
continue;
4462 if (
hit.WireID().TPC != tpc)
continue;
4463 unsigned short plane =
hit.WireID().Plane;
4464 unsigned int wire =
hit.WireID().Wire;
4465 if (wire > slc.
nWires[plane] - 1) {
4466 mf::LogWarning(
"TC") <<
"FillWireHitRange: Invalid wire number " << wire <<
" > " 4467 << slc.
nWires[plane] - 1 <<
" in plane " << plane <<
" Quitting";
4470 if (plane == lastPlane && wire < lastWire) {
4472 <<
"FillWireHitRange: Hits are not in increasing wire order. Quitting ";
4484 unsigned int slhitsSize = slc.
slHits.size();
4485 for (
unsigned short plane = 0; plane < nplanes; ++plane) {
4486 for (
unsigned int wire = slc.
firstWire[plane]; wire < slc.
lastWire[plane]; ++wire) {
4487 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
continue;
4488 if (slc.
wireHitRange[plane][wire].first > slhitsSize - 1 &&
4498 std::cout <<
"Slice ID/Index " << slc.
ID <<
"/" <<
slices.size() <<
" tpc " << tpc
4500 std::cout <<
" Active volume (";
4501 std::cout << std::fixed << std::setprecision(1) << slc.
xLo <<
" < X < " << slc.
xHi <<
") (";
4502 std::cout << std::fixed << std::setprecision(1) << slc.
yLo <<
" < Y < " << slc.
yHi <<
") (";
4503 std::cout << std::fixed << std::setprecision(1) << slc.
zLo <<
" < Z < " << slc.
zHi <<
")\n";
4528 if (itj1 > slc.
tjs.size() - 1)
return false;
4529 if (itj2 > slc.
tjs.size() - 1)
return false;
4540 if (pfp1 != USHRT_MAX || pfp2 != USHRT_MAX) {
4541 if (pfp1 != USHRT_MAX && pfp2 != USHRT_MAX)
return false;
4543 if (pfp1 == USHRT_MAX) std::swap(itj1, itj2);
4565 std::swap(tj1, tj2);
4566 std::swap(tp1e0, tp2e0);
4567 std::swap(tp1e1, tp2e1);
4585 if (tp2e0[0] > tp1e0[0] && tp2e1[0] < tp1e1[0])
return false;
4589 if (tp1e0[0] > tp2e0[0] && tp1e1[0] < tp2e1[0])
return false;
4593 if (tp2e1[0] > tp1e1[0] && tp2e0[0] < tp1e0[0])
return false;
4594 if (tp1e1[0] > tp2e1[0] && tp1e0[0] < tp2e0[0])
return false;
4609 mf::LogVerbatim(
"TC") <<
"MergeAndStore: You are merging the end of trajectory T" << tj1.
ID 4610 <<
" with a Bragg peak. Not merging\n";
4621 float minSep = 1000;
4622 unsigned short tj2ClosePt = 0;
4627 << tj2ClosePt <<
" Pos " <<
PrintPos(tj2.
Pts[tj2ClosePt]);
4629 if (tj2ClosePt > tj2.
EndPt[1])
return false;
4638 std::vector<unsigned int> tj1Hits;
4639 for (
unsigned short ii = 0; ii < tj1.
Pts.size(); ++ii) {
4642 unsigned short ipt = tj1.
Pts.size() - 1 - ii;
4643 tj1Hits.insert(tj1Hits.end(), tj1.
Pts[ipt].Hits.begin(), tj1.
Pts[ipt].Hits.end());
4644 if (ipt == 0)
break;
4647 bool bumpedPt =
true;
4650 for (
unsigned short ii = 0; ii < tj2.
Pts[tj2ClosePt].Hits.size(); ++ii) {
4651 unsigned int iht = tj2.
Pts[tj2ClosePt].Hits[ii];
4652 if (std::find(tj1Hits.begin(), tj1Hits.end(), iht) != tj1Hits.end()) bumpedPt =
true;
4654 if (bumpedPt && tj2ClosePt < tj2.
EndPt[1]) { ++tj2ClosePt; }
4659 if (doPrt)
mf::LogVerbatim(
"TC") <<
" revised tj2ClosePt " << tj2ClosePt;
4662 tj1.
Pts.insert(tj1.
Pts.end(), tj2.
Pts.begin() + tj2ClosePt, tj2.
Pts.end());
4669 if (tj2.
VtxID[1] > 0) {
4690 int newTjID = slc.
tjs.size();
4694 if (doPrt)
mf::LogVerbatim(
"TC") <<
" MAS success. Created T" << newTjID;
4696 for (
auto& tj : slc.
tjs)
4697 if (tj.ParentID == tj1ID || tj.ParentID == tj2ID) tj.ParentID = newTjID;
4705 std::string type1Name,
4707 std::string type2Name)
4712 std::vector<int>
tmp;
4713 if (
id <= 0)
return tmp;
4714 unsigned int uid = id;
4716 if (type1Name ==
"T" && uid <= slc.
tjs.size() && type2Name ==
"P") {
4718 for (
auto& pfp : slc.
pfps) {
4719 if (pfp.ID <= 0)
continue;
4720 if (std::find(pfp.TjIDs.begin(), pfp.TjIDs.end(), id) != pfp.TjIDs.end())
4721 tmp.push_back(pfp.ID);
4726 if (type1Name ==
"P" && uid <= slc.
pfps.size() && (type2Name ==
"2S" || type2Name ==
"3S")) {
4728 auto& pfp = slc.
pfps[uid - 1];
4730 std::vector<int> ssid;
4731 for (
auto& ss : slc.
cots) {
4732 if (ss.ID <= 0)
continue;
4734 if (!shared.empty() && std::find(ssid.begin(), ssid.end(), ss.ID) == ssid.end())
4735 ssid.push_back(ss.ID);
4737 if (type2Name ==
"2S")
return ssid;
4738 for (
auto& ss3 : slc.
showers) {
4739 if (ss3.ID <= 0)
continue;
4741 if (!shared.empty() && std::find(tmp.begin(), tmp.end(), ss3.ID) == tmp.end())
4742 tmp.push_back(ss3.ID);
4747 if (type1Name ==
"2V" && uid <= slc.
vtxs.size() && type2Name ==
"T") {
4749 for (
auto& tj : slc.
tjs) {
4751 for (
unsigned short end = 0;
end < 2; ++
end) {
4752 if (tj.VtxID[
end] !=
id)
continue;
4753 if (std::find(tmp.begin(), tmp.end(), tj.ID) == tmp.end()) tmp.push_back(tj.ID);
4759 if (type1Name ==
"3V" && uid <= slc.
vtx3s.size() && type2Name ==
"P") {
4760 for (
auto& pfp : slc.
pfps) {
4761 if (pfp.ID == 0)
continue;
4762 for (
unsigned short end = 0;
end < 2; ++
end) {
4763 if (pfp.Vx3ID[
end] !=
id)
continue;
4765 if (std::find(tmp.begin(), tmp.end(), pfp.ID) == tmp.end()) tmp.push_back(pfp.ID);
4771 if (type1Name ==
"3V" && uid <= slc.
vtx3s.size() && type2Name ==
"T") {
4773 for (
auto& tj : slc.
tjs) {
4775 for (
unsigned short end = 0;
end < 2; ++
end) {
4776 if (tj.VtxID[
end] > 0 && tj.VtxID[
end] <= slc.
vtxs.size()) {
4777 auto& vx2 = slc.
vtxs[tj.VtxID[
end] - 1];
4778 if (vx2.Vx3ID !=
id)
continue;
4779 if (std::find(tmp.begin(), tmp.end(), tj.ID) == tmp.end()) tmp.push_back(tj.ID);
4786 if (type1Name ==
"3V" && uid <= slc.
vtx3s.size() && type2Name ==
"2V") {
4788 for (
auto& vx2 : slc.
vtxs) {
4789 if (vx2.ID == 0)
continue;
4790 if (vx2.Vx3ID ==
id) tmp.push_back(vx2.ID);
4795 if (type1Name ==
"3S" && uid <= slc.
showers.size() && type2Name ==
"T") {
4797 auto& ss3 = slc.
showers[uid - 1];
4798 if (ss3.ID == 0)
return tmp;
4799 for (
auto cid : ss3.CotIDs) {
4800 auto& ss = slc.
cots[cid - 1];
4801 if (ss.ID == 0)
continue;
4802 tmp.insert(tmp.end(), ss.TjIDs.begin(), ss.TjIDs.end());
4808 if (type1Name ==
"2S" && uid <= slc.
cots.size() && type2Name ==
"T") {
4810 auto& ss = slc.
cots[uid - 1];
4814 if (type1Name ==
"3S" && uid <= slc.
showers.size() && type2Name ==
"P") {
4816 auto& ss3 = slc.
showers[uid - 1];
4817 if (ss3.ID == 0)
return tmp;
4818 for (
auto cid : ss3.CotIDs) {
4819 auto& ss = slc.
cots[cid - 1];
4820 if (ss.ID == 0)
continue;
4821 for (
auto tid : ss.TjIDs) {
4822 auto& tj = slc.
tjs[tid - 1];
4824 if (!tj.AlgMod[
kMat3D])
continue;
4825 for (
auto& pfp : slc.
pfps) {
4826 if (pfp.ID <= 0)
continue;
4827 if (std::find(pfp.TjIDs.begin(), pfp.TjIDs.end(), tj.ID) == pfp.TjIDs.end())
continue;
4828 if (std::find(tmp.begin(), tmp.end(), pfp.ID) == tmp.end()) tmp.push_back(pfp.ID);
4835 if (type1Name ==
"T" && uid <= slc.
tjs.size() && type2Name ==
"2S") {
4837 for (
auto& ss : slc.
cots) {
4838 if (ss.ID == 0)
continue;
4839 if (std::find(ss.TjIDs.begin(), ss.TjIDs.end(), id) != ss.TjIDs.end()) tmp.push_back(ss.ID);
4844 if (type1Name ==
"T" && uid <= slc.
tjs.size() && type2Name ==
"3S") {
4846 for (
auto& ss : slc.
cots) {
4847 if (ss.ID == 0)
continue;
4848 if (std::find(ss.TjIDs.begin(), ss.TjIDs.end(), id) == ss.TjIDs.end())
continue;
4849 if (ss.SS3ID > 0) tmp.push_back(ss.SS3ID);
4860 unsigned int fromhit,
4862 unsigned short pass)
4868 float fromWire = fromHit.WireID().Wire;
4869 float fromTick = fromHit.PeakTime();
4870 float toWire = toHit.WireID().Wire;
4871 float toTick = toHit.PeakTime();
4873 bool success =
StartTraj(tj, fromWire, fromTick, toWire, toTick, tCTP, pass);
4874 if (!success)
return false;
4879 auto& tp = tj.
Pts[0];
4880 mf::LogVerbatim(
"TC") <<
"StartTraj T" << tj.
ID <<
" from " << (int)fromWire <<
":" 4881 << (
int)fromTick <<
" -> " << (int)toWire <<
":" << (
int)toTick
4882 <<
" StepDir " << tj.
StepDir <<
" dir " << tp.Dir[0] <<
" " << tp.Dir[1]
4883 <<
" ang " << tp.Ang <<
" AngleCode " << tp.AngleCode <<
" angErr " 4896 unsigned short pass)
4907 int fWire = std::nearbyint(fromWire);
4908 int tWire = std::nearbyint(toWire);
4909 if (tWire < fWire) { stepdir = -1; }
4910 else if (tWire == fWire) {
4912 if (toTick < fromTick) stepdir = -1;
4922 if (!
MakeBareTrajPoint(fromWire, fromTick, toWire, toTick, tCTP, tp))
return false;
4925 tj.
Pts.push_back(tp);
4930 auto& tp = tj.
Pts[0];
4931 mf::LogVerbatim(
"TC") <<
"StartTraj T" << tj.
ID <<
" from " << (int)fromWire <<
":" 4932 << (
int)fromTick <<
" -> " << (int)toWire <<
":" << (
int)toTick
4933 <<
" StepDir " << tj.
StepDir <<
" dir " << tp.
Dir[0] <<
" " << tp.
Dir[1]
4934 <<
" ang " << tp.
Ang <<
" AngleCode " << tp.
AngleCode <<
" angErr " 4942 std::pair<unsigned short, unsigned short>
GetSliceIndex(std::string typeName,
int uID)
4945 for (
unsigned short isl = 0; isl <
slices.size(); ++isl) {
4947 if (typeName ==
"T") {
4948 for (
unsigned short indx = 0; indx < slc.tjs.size(); ++indx) {
4949 if (slc.tjs[indx].UID == uID) {
return std::make_pair(isl, indx); }
4952 if (typeName ==
"P") {
4953 for (
unsigned short indx = 0; indx < slc.pfps.size(); ++indx) {
4954 if (slc.pfps[indx].UID == uID) {
return std::make_pair(isl, indx); }
4957 if (typeName ==
"2V") {
4958 for (
unsigned short indx = 0; indx < slc.vtxs.size(); ++indx) {
4959 if (slc.vtxs[indx].UID == uID) {
return std::make_pair(isl, indx); }
4962 if (typeName ==
"3V") {
4963 for (
unsigned short indx = 0; indx < slc.vtx3s.size(); ++indx) {
4964 if (slc.vtx3s[indx].UID == uID) {
return std::make_pair(isl, indx); }
4967 if (typeName ==
"2S") {
4968 for (
unsigned short indx = 0; indx < slc.cots.size(); ++indx) {
4969 if (slc.cots[indx].UID == uID) {
return std::make_pair(isl, indx); }
4972 if (typeName ==
"3S") {
4973 for (
unsigned short indx = 0; indx < slc.showers.size(); ++indx) {
4974 if (slc.showers[indx].UID == uID) {
return std::make_pair(isl, indx); }
4978 return std::make_pair(USHRT_MAX, USHRT_MAX);
4995 static double sum, sumx, sumy, sumx2, sumy2, sumxy;
4996 static unsigned short cnt;
4997 static std::vector<Point2_t> fitPts;
4998 static std::vector<double> fitWghts;
5015 if (inPtErr <= 0.)
return false;
5017 double wght = 1 / (inPtErr * inPtErr);
5019 sumx += wght * inPt[0];
5020 sumx2 += wght * inPt[0] * inPt[0];
5021 sumy += wght * inPt[1];
5022 sumy2 += wght * inPt[1] * inPt[1];
5023 sumxy += wght * inPt[0] * inPt[1];
5024 if (mode == 1)
return true;
5025 fitPts.push_back(inPt);
5026 fitWghts.push_back(wght);
5030 if (cnt < 2)
return false;
5032 double delta = sum * sumx2 - sumx * sumx;
5033 if (delta == 0.)
return false;
5034 double A = (sumx2 * sumy - sumx * sumxy) / delta;
5035 double B = (sumxy * sum - sumx * sumy) / delta;
5039 if (cnt == 2 || fitPts.empty())
return true;
5042 if (fitPts.size() != cnt)
return false;
5043 double ndof = cnt - 2;
5045 (sumy2 + A * A * sum + B * B * sumx2 - 2 * (A * sumy + B * sumxy - A * B * sumx)) / ndof;
5047 outVecErr[0] = sqrt(varnce * sumx2 / delta);
5048 outVecErr[1] = sqrt(varnce * sum / delta);
5056 for (
unsigned short ii = 0; ii < fitPts.size(); ++ii) {
5057 double arg = fitPts[ii][1] - A - B * fitPts[ii][0];
5058 sum += fitWghts[ii] * arg * arg;
5060 chiDOF = sum / ndof;
5073 if (strng ==
"instruct") {
5074 std::cout <<
"****** Unrecognized DebugConfig. Here are your options\n";
5075 std::cout <<
" 'C:T:P:W:Tick' where C = cryostat, T = TPC, W = wire, Tick (+/-5) to debug " 5076 "stepping (DUNE)\n";
5077 std::cout <<
" 'P:W:Tick' for single cryostat/TPC detectors (uB, LArIAT, etc)\n";
5078 std::cout <<
" 'WorkID <id> <slice index>' where <id> is a tj work ID (< 0) in slice <slice " 5079 "index> (default = 0)\n";
5080 std::cout <<
" 'Merge <CTP>' to debug trajectory merging\n";
5081 std::cout <<
" '2V <CTP>' to debug 2D vertex finding\n";
5082 std::cout <<
" '3V' to debug 3D vertex finding\n";
5083 std::cout <<
" 'VxMerge' to debug 2D vertex merging\n";
5084 std::cout <<
" 'JunkVx' to debug 2D junk vertex finder\n";
5085 std::cout <<
" 'PFP' to debug 3D matching and PFParticles\n";
5086 std::cout <<
" 'MVI <MVI> <MVI Iteration>' for detailed debugging of one PFP MatchVecIndex\n";
5087 std::cout <<
" 'DeltaRay' to debug delta ray tagging\n";
5088 std::cout <<
" 'Muon' to debug muon tagging\n";
5089 std::cout <<
" '2S <CTP>' to debug a 2D shower in CTP\n";
5090 std::cout <<
" 'Reco TPC <TPC>' to only reconstruct hits in the specified TPC\n";
5091 std::cout <<
" 'Reco Slice <ID>' to reconstruct all sub-slices in the recob::Slice with the " 5093 std::cout <<
" 'SubSlice <sub-slice index>' where <slice index> restricts output to the " 5094 "specified sub-slice index\n";
5095 std::cout <<
" 'Stitch' to debug PFParticle stitching between TPCs\n";
5096 std::cout <<
" 'Sum' or 'Summary' to print a debug summary report\n";
5097 std::cout <<
" 'Dump <WorkID>' or 'Dump <UID>' to print all TPs in the trajectory to " 5098 "tcdump<UID>.csv\n";
5099 std::cout <<
" Note: Algs with debug printing include HamVx, HamVx2, SplitTjCVx, Comp3DVx, " 5100 "Comp3DVxIG, VtxHitsSwap\n";
5101 std::cout <<
" Set SkipAlgs: [\"bogusText\"] to print a list of algorithm names\n";
5106 if (strng.find(
"3V") != std::string::npos) {
5111 if (strng.find(
"3S") != std::string::npos) {
5116 if (strng.find(
"VxMerge") != std::string::npos) {
5121 if (strng.find(
"JunkVx") != std::string::npos) {
5126 if (strng.find(
"DeltaRay") != std::string::npos) {
5131 if (strng.find(
"Muon") != std::string::npos) {
5136 if (strng.find(
"Stitch") != std::string::npos) {
5141 if (strng.find(
"HamVx") != std::string::npos) {
5146 if (strng.find(
"HamVx2") != std::string::npos) {
5151 if (strng.find(
"Sum") != std::string::npos) {
5157 std::vector<std::string> words;
5158 boost::split(words, strng, boost::is_any_of(
" :"), boost::token_compress_on);
5159 if (words.size() == 5) {
5172 if (words[0] ==
"PFP" || words[0] ==
"MVI") {
5176 if (words.size() > 2) {
5178 if (words.size() == 3)
debug.
MVI_Iter = std::stoi(words[2]);
5182 if (words.size() == 2 && words[0] ==
"Dump") {
5189 if (words.size() > 1 && words[0] ==
"WorkID") {
5194 if (words.size() > 2)
debug.
Slice = std::stoi(words[2]);
5200 if (words.size() == 3 && words[0] ==
"Reco" && words[1] ==
"TPC") {
5203 std::cout <<
"Reconstructing only in TPC " <<
tcc.
recoTPC <<
"\n";
5206 if (words.size() == 3 && words[0] ==
"Reco" && words[1] ==
"Slice") {
5208 std::cout <<
"Reconstructing Slice " <<
tcc.
recoSlice <<
"\n";
5211 if (words.size() == 3) {
5223 if (words.size() == 2 && words[0] ==
"Merge") {
5229 if (words.size() == 2 && words[0] ==
"2V") {
5235 if (words.size() == 2 && words[0] ==
"2S") {
5242 if (words.size() == 2 && words[0] ==
"SubSlice") {
5257 for (
auto const& slc :
slices) {
5258 for (
auto& tj : slc.tjs) {
5261 std::ofstream outfile;
5263 outfile.open(fname, std::ios::out | std::ios::trunc);
5264 outfile <<
"Dump trajectory T" << tj.UID <<
" WorkID " << tj.WorkID;
5265 outfile <<
" ChgRMS " << std::setprecision(2) << tj.ChgRMS;
5267 outfile <<
"Wire, Chg T" << tj.UID
5268 <<
", totChg, Tick, Delta, NTPsFit, Ang, ChiDOF, KinkSig, HitPosErr\n";
5269 for (
unsigned short ipt = tj.EndPt[0]; ipt <= tj.EndPt[1]; ++ipt) {
5270 auto& tp = tj.Pts[ipt];
5271 outfile << std::fixed;
5272 outfile << std::setprecision(0) << std::nearbyint(tp.Pos[0]);
5273 outfile <<
"," << (int)tp.Chg;
5276 for (
auto iht : tp.Hits) {
5278 totChg +=
hit.Integral();
5280 outfile <<
"," << (int)totChg;
5281 outfile <<
"," << std::setprecision(0) << std::nearbyint(tp.Pos[1] /
tcc.
unitsPerTick);
5282 outfile <<
"," << std::setprecision(2) << tp.Delta;
5283 outfile <<
"," << tp.NTPsFit;
5284 outfile <<
"," << std::setprecision(3) << tp.Ang;
5285 outfile <<
"," << std::setprecision(2) << tp.FitChi;
5286 outfile <<
"," << std::setprecision(2) << tp.KinkSig;
5287 outfile <<
"," << std::setprecision(2) << sqrt(tp.HitPosErr2);
5291 std::cout <<
"Points on T" << tj.UID <<
" dumped to " << fname <<
"\n";
5303 std::cout <<
"*** TrajCluster debug mode configuration in";
5304 std::cout <<
" CTP=";
5305 if (
debug.
CTP == UINT_MAX) { std::cout <<
"NA"; }
5314 std::cout <<
" Hit=";
5315 if (
debug.
Hit == UINT_MAX) { std::cout <<
"NA"; }
5319 std::cout <<
" WorkID=";
5324 std::cout <<
" Slice=";
5325 if (
debug.
Slice == -1) { std::cout <<
"All"; }
5330 std::cout <<
"*** tcc.dbg modes:";
5334 if (
tcc.
dbg2V) std::cout <<
" dbg2V";
5335 if (
tcc.
dbg2S) std::cout <<
" dbg2S";
5339 if (
tcc.
dbg3V) std::cout <<
" dbg3V";
5347 std::cout <<
"*** Using algs:";
5348 unsigned short cnt = 0;
5349 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib) {
5352 if (cnt % 10 == 0) std::cout <<
"\n ";
5357 std::cout <<
"*** Skipping algs:";
5359 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib) {
5362 if (cnt % 10 == 0) std::cout <<
"\n ";
5378 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5380 auto const& slc =
slices[isl];
5381 if (!slc.vtx3s.empty()) prt3V =
true;
5382 if (!slc.vtxs.empty()) prt2V =
true;
5383 if (!slc.tjs.empty()) prtT =
true;
5384 if (!slc.pfps.empty()) prtP =
true;
5385 if (!slc.showers.empty()) prtS3 =
true;
5388 myprt <<
"Debug report from caller " << someText <<
"\n";
5389 myprt <<
" 'prodID' = <sliceID>:<subSliceIndex>:<productID>/<productUID>\n";
5391 myprt <<
"************ Showers ************\n";
5392 myprt <<
" prodID Vtx parUID ___ChgPos____ ______Dir_____ ____posInPln____ " 5393 "___projInPln____ 2D shower UIDs\n";
5394 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5396 auto const& slc =
slices[isl];
5397 if (slc.showers.empty())
continue;
5398 for (
auto& ss3 : slc.showers)
5403 bool printHeader =
true;
5404 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5406 auto const& slc =
slices[isl];
5407 if (slc.pfps.empty())
continue;
5408 for (
auto& pfp : slc.pfps)
5409 PrintP(myprt, pfp, printHeader);
5413 bool printHeader =
true;
5414 myprt <<
"****** 3D vertices " 5415 "******************************************__2DVtx_UID__*******\n";
5416 myprt <<
" prodID Cstat TPC X Y Z XEr YEr " 5417 "ZEr pln0 pln1 pln2 Wire score Prim? Nu? nTru";
5418 myprt <<
" ___________2D_Pos____________ _____Tj UIDs________\n";
5419 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5421 auto const& slc =
slices[isl];
5422 if (slc.vtx3s.empty())
continue;
5423 for (
auto& vx3 : slc.vtx3s)
5424 Print3V(detProp, myprt, vx3, printHeader);
5428 bool printHeader =
true;
5429 myprt <<
"************ 2D vertices ************\n";
5430 myprt <<
" prodID CTP wire err tick err ChiDOF NTj Pass " 5431 " Topo ChgFrac Score v3D Tj UIDs\n";
5432 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5434 auto const& slc =
slices[isl];
5435 if (slc.vtxs.empty())
continue;
5436 for (
auto& vx2 : slc.vtxs)
5437 Print2V(myprt, vx2, printHeader);
5441 bool printHeader =
true;
5442 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5444 auto const& slc =
slices[isl];
5445 if (slc.tjs.empty())
continue;
5446 for (
auto& tj : slc.tjs)
5447 PrintT(myprt, tj, printHeader);
5455 if (pfp.
ID <= 0)
return;
5457 myprt <<
"************ PFParticles ************\n";
5458 myprt <<
" prodID sVx _____sPos____ CS _______sDir______ ____sdEdx_____ eVx " 5459 "_____ePos____ CS ____edEdx_____ MVI MCSMom Len nTP3 nSec SLk? PDG Par \n";
5460 printHeader =
false;
5463 if (sIndx.first == USHRT_MAX)
return;
5464 auto const& slc =
slices[sIndx.first];
5468 myprt << std::setw(12) << str;
5470 for (
unsigned short end = 0;
end < 2; ++
end) {
5473 myprt << std::setw(6) << str;
5474 myprt << std::fixed <<
std::right << std::setprecision(0);
5476 myprt << std::setw(5) << pos[0];
5477 myprt << std::setw(5) << pos[1];
5478 myprt << std::setw(5) << pos[2];
5486 myprt << std::fixed <<
std::right << std::setprecision(2);
5488 myprt << std::setw(6) <<
dir[0];
5489 myprt << std::setw(6) << dir[1];
5490 myprt << std::setw(6) << dir[2];
5492 for (
auto& dedx : pfp.
dEdx[
end]) {
5493 if (dedx < 50) { myprt << std::setw(5) << std::setprecision(1) << dedx; }
5495 myprt << std::setw(5) << std::setprecision(0) << dedx;
5498 if (pfp.
dEdx[end].size() < 3) {
5499 for (
size_t i = 0; i < 3 - pfp.
dEdx[
end].size(); ++i) {
5500 myprt << std::setw(6) <<
' ';
5504 myprt << std::setw(6) << pfp.
MVI;
5507 float length =
Length(pfp);
5508 if (length < 100) { myprt << std::setw(5) << std::setprecision(1) << length; }
5510 myprt << std::setw(5) << std::setprecision(0) << length;
5512 myprt << std::setw(5) << pfp.
TP3Ds.size();
5515 myprt << std::setw(5) << pfp.
PDGCode;
5517 if (!pfp.
TjIDs.empty()) {
5518 if (pfp.
TjUIDs.empty()) {
5520 for (
auto tjid : pfp.
TjIDs)
5521 myprt <<
" TU" << slc.tjs[tjid - 1].UID;
5525 for (
auto tjuid : pfp.
TjUIDs)
5526 myprt <<
" TU" << tjuid;
5531 for (
auto dtruid : pfp.
DtrUIDs)
5532 myprt <<
" PU" << dtruid;
5544 if (vx3.
ID <= 0)
return;
5546 if (sIndx.first == USHRT_MAX)
return;
5547 auto const& slc =
slices[sIndx.first];
5550 <<
"****** 3D vertices ******************************************__2DVtx_UID__*******\n";
5551 myprt <<
" prodID Cstat TPC X Y Z pln0 pln1 pln2 Wire score " 5553 myprt <<
" ___________2D_Pos____________ _____Tj UIDs________\n";
5554 printHeader =
false;
5557 myprt <<
std::right << std::setw(12) << std::fixed << str;
5558 myprt << std::setprecision(0);
5564 for (
auto vx2id : vx3.
Vx2ID) {
5574 unsigned short nTruMatch = 0;
5575 for (
unsigned short ipl = 0; ipl < slc.nPlanes; ++ipl) {
5576 if (vx3.
Vx2ID[ipl] == 0)
continue;
5577 unsigned short iv2 = vx3.
Vx2ID[ipl] - 1;
5580 myprt <<
std::right << std::setw(6) << std::setprecision(1) << vx3.
Score;
5581 myprt << std::setw(6) << vx3.
Primary;
5582 myprt << std::setw(4) << vx3.
Neutrino;
5583 myprt <<
std::right << std::setw(5) << nTruMatch;
5585 for (
unsigned short plane = 0; plane < slc.nPlanes; ++plane) {
5589 if (vx3.
Wire == -2) {
5591 for (
unsigned short end = 0;
end < 2; ++
end) {
5592 for (
auto& pfp : slc.pfps) {
5593 if (pfp.Vx3ID[
end] == vx3.
ID) {
5594 for (
auto tjID : pfp.TjIDs) {
5595 auto& tj = slc.tjs[tjID - 1];
5596 myprt <<
" T" << tj.UID;
5603 auto vxtjs =
GetAssns(slc,
"3V", vx3.
ID,
"T");
5604 for (
auto tjid : vxtjs) {
5605 auto& tj = slc.tjs[tjid - 1];
5606 myprt <<
" TU" << tj.UID;
5616 if (vx2.
ID <= 0)
return;
5619 if (sIndx.first == USHRT_MAX)
return;
5620 auto const& slc =
slices[sIndx.first];
5622 myprt <<
"************ 2D vertices ************\n";
5623 myprt <<
" prodID CTP wire err tick err ChiDOF NTj Pass Topo ChgFrac Score " 5625 printHeader =
false;
5628 myprt <<
std::right << std::setw(12) << std::fixed << str;
5630 myprt <<
std::right << std::setw(8) << std::setprecision(0) << std::nearbyint(vx2.
Pos[0]);
5631 myprt <<
std::right << std::setw(5) << std::setprecision(1) << vx2.
PosErr[0];
5632 myprt <<
std::right << std::setw(8) << std::setprecision(0)
5640 myprt <<
std::right << std::setw(6) << std::setprecision(1) << vx2.
Score;
5642 if (vx2.
Vx3ID > 0) v3id = slc.vtx3s[vx2.
Vx3ID - 1].UID;
5646 for (
unsigned short ii = 0; ii < slc.tjs.size(); ++ii) {
5647 auto const& tj = slc.tjs[ii];
5648 if (tj.AlgMod[
kKilled])
continue;
5649 for (
unsigned short end = 0;
end < 2; ++
end) {
5650 if (tj.VtxID[
end] != (
short)vx2.
ID)
continue;
5657 for (
unsigned short ib = 1; ib <
VtxBitNames.size(); ++ib)
5667 if (ss3.
ID <= 0)
return;
5669 if (sIndx.first == USHRT_MAX)
return;
5670 auto const& slc =
slices[sIndx.first];
5674 myprt << std::fixed << std::setw(12) << str;
5677 myprt << std::setw(6) << str;
5678 for (
unsigned short xyz = 0; xyz < 3; ++xyz)
5679 myprt << std::setprecision(0) << std::setw(5) << ss3.
ChgPos[xyz];
5680 for (
unsigned short xyz = 0; xyz < 3; ++xyz)
5681 myprt << std::setprecision(2) << std::setw(5) << ss3.
Dir[xyz];
5682 std::vector<float> projInPlane(slc.nPlanes);
5683 for (
unsigned short plane = 0; plane < slc.nPlanes; ++plane) {
5687 projInPlane[plane] = tp.Delta;
5689 for (
unsigned short plane = 0; plane < slc.nPlanes; ++plane) {
5690 myprt << std::setprecision(2) << std::setw(5) << projInPlane[plane];
5692 for (
auto cid : ss3.
CotIDs) {
5693 auto& ss = slc.cots[cid - 1];
5695 myprt << std::setw(5) << str;
5697 if (ss3.
NeedsUpdate) myprt <<
" *** Needs update";
5705 if (tj.
ID <= 0)
return;
5708 myprt <<
"************ Trajectories ************\n";
5709 myprt <<
"Tj AngleCode-EndFlag decoder (EF): <AngleCode> + <reason for stopping>";
5710 myprt <<
" (B=Bragg Peak, V=Vertex, A=AngleKink, C=ChargeKink, T=Trajectory)\n";
5711 myprt <<
" prodID CTP Pass Pts W:T Ang EF AveQ W:T Ang EF AveQ " 5712 "Chg(k) chgRMS Mom __Vtx__ PDG eLike Par Pri NuPar WorkID \n";
5713 printHeader =
false;
5716 if (sIndx.first == USHRT_MAX)
return;
5717 auto const& slc =
slices[sIndx.first];
5719 myprt << std::fixed << std::setw(12) << str;
5720 myprt << std::setw(6) << tj.
CTP;
5721 myprt << std::setw(5) << tj.
Pass;
5722 myprt << std::setw(5) << tj.
EndPt[1] - tj.
EndPt[0] + 1;
5723 unsigned short endPt0 = tj.
EndPt[0];
5724 auto& tp0 = tj.
Pts[endPt0];
5726 if (itick < 0) itick = 0;
5727 myprt << std::setw(6) << (int)(tp0.Pos[0] + 0.5) <<
":" << itick;
5728 if (itick < 10) { myprt <<
" "; }
5729 if (itick < 100) { myprt <<
" "; }
5730 if (itick < 1000) { myprt <<
" "; }
5731 myprt << std::setw(6) << std::setprecision(2) << tp0.Ang;
5732 myprt << std::setw(2) << tp0.AngleCode;
5746 myprt << std::setw(5) << (int)tp0.AveChg;
5747 unsigned short endPt1 = tj.
EndPt[1];
5748 auto& tp1 = tj.
Pts[endPt1];
5750 myprt << std::setw(6) << (int)(tp1.Pos[0] + 0.5) <<
":" << itick;
5751 if (itick < 10) { myprt <<
" "; }
5752 if (itick < 100) { myprt <<
" "; }
5753 if (itick < 1000) { myprt <<
" "; }
5754 myprt << std::setw(6) << std::setprecision(2) << tp1.Ang;
5755 myprt << std::setw(2) << tp1.AngleCode;
5769 myprt << std::setw(5) << (int)tp1.AveChg;
5770 myprt << std::setw(7) << std::setprecision(1) << tj.
TotChg / 1000;
5771 myprt << std::setw(7) << std::setprecision(2) << tj.
ChgRMS;
5772 myprt << std::setw(5) << tj.
MCSMom;
5774 if (tj.
VtxID[0] > 0) vxid = slc.vtxs[tj.
VtxID[0] - 1].UID;
5775 myprt << std::setw(4) << vxid;
5777 if (tj.
VtxID[1] > 0) vxid = slc.vtxs[tj.
VtxID[1] - 1].UID;
5778 myprt << std::setw(4) << vxid;
5779 myprt << std::setw(5) << tj.
PDGCode;
5781 myprt << std::setw(5) << tj.
ParentID;
5782 myprt << std::setw(5) <<
PrimaryID(slc, tj);
5784 myprt << std::setw(7) << tj.
WorkID;
5785 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
5794 std::string someText,
5804 if (!slc.
vtx3s.empty()) {
5808 <<
"****** 3D vertices ******************************************__2DVtx_ID__*******\n";
5810 <<
" Vtx Cstat TPC X Y Z XEr YEr ZEr pln0 pln1 pln2 Wire " 5811 "score Prim? Nu? nTru";
5812 myprt <<
" ___________2D_Pos____________ _____Tjs________\n";
5813 for (
unsigned short iv = 0; iv < slc.
vtx3s.size(); ++iv) {
5814 if (slc.
vtx3s[iv].ID == 0)
continue;
5818 myprt <<
std::right << std::setw(5) << std::fixed << vid;
5819 myprt << std::setprecision(1);
5832 unsigned short nTruMatch = 0;
5833 for (
unsigned short ipl = 0; ipl < slc.
nPlanes; ++ipl) {
5834 if (vx3.
Vx2ID[ipl] == 0)
continue;
5835 unsigned short iv2 = vx3.
Vx2ID[ipl] - 1;
5838 myprt <<
std::right << std::setw(6) << std::setprecision(1) << vx3.
Score;
5839 myprt << std::setw(6) << vx3.
Primary;
5840 myprt << std::setw(4) << vx3.
Neutrino;
5841 myprt <<
std::right << std::setw(5) << nTruMatch;
5843 for (
unsigned short plane = 0; plane < slc.
nPlanes; ++plane) {
5847 if (vx3.
Wire == -2) {
5849 for (
auto& pfp : slc.
pfps) {
5850 if (pfp.Vx3ID[0] == slc.
vtx3s[iv].ID) {
5851 for (
auto& tjID : pfp.TjIDs)
5852 myprt <<
" t" << tjID;
5854 if (pfp.Vx3ID[1] == slc.
vtx3s[iv].ID) {
5855 for (
auto& tjID : pfp.TjIDs)
5856 myprt <<
" t" << tjID;
5861 auto vxtjs =
GetAssns(slc,
"3V", vx3.
ID,
"T");
5862 for (
auto tjid : vxtjs)
5863 myprt <<
" t" << tjid;
5868 if (!slc.
vtxs.empty()) {
5869 bool foundOne =
false;
5870 for (
unsigned short iv = 0; iv < slc.
vtxs.size(); ++iv) {
5871 auto& vx2 = slc.
vtxs[iv];
5873 if (vx2.NTraj == 0)
continue;
5878 myprt << someText <<
"************ 2D vertices ************\n";
5880 <<
" ID CTP wire err tick err ChiDOF NTj Pass Topo ChgFrac Score v3D " 5882 for (
auto& vx2 : slc.
vtxs) {
5883 if (vx2.ID == 0)
continue;
5887 myprt <<
std::right << std::setw(5) << std::fixed << vid;
5888 myprt <<
std::right << std::setw(6) << vx2.CTP;
5889 myprt <<
std::right << std::setw(8) << std::setprecision(0)
5890 << std::nearbyint(vx2.Pos[0]);
5891 myprt <<
std::right << std::setw(5) << std::setprecision(1) << vx2.PosErr[0];
5892 myprt <<
std::right << std::setw(8) << std::setprecision(0)
5894 myprt <<
std::right << std::setw(5) << std::setprecision(1)
5896 myprt <<
std::right << std::setw(7) << vx2.ChiDOF;
5897 myprt <<
std::right << std::setw(5) << vx2.NTraj;
5898 myprt <<
std::right << std::setw(5) << vx2.Pass;
5899 myprt <<
std::right << std::setw(6) << vx2.Topo;
5900 myprt <<
std::right << std::setw(9) << std::setprecision(2) << vx2.TjChgFrac;
5901 myprt <<
std::right << std::setw(6) << std::setprecision(1) << vx2.Score;
5902 myprt <<
std::right << std::setw(5) << vx2.Vx3ID;
5905 for (
unsigned short ii = 0; ii < slc.
tjs.size(); ++ii) {
5906 auto const& aTj = slc.
tjs[ii];
5908 if (aTj.AlgMod[
kKilled])
continue;
5909 for (
unsigned short end = 0;
end < 2; ++
end) {
5910 if (aTj.VtxID[
end] != (
short)vx2.ID)
continue;
5916 for (
unsigned short ib = 1; ib <
VtxBitNames.size(); ++ib)
5917 if (vx2.Stat[ib]) myprt <<
" " <<
VtxBitNames[ib];
5924 if (slc.
tjs.empty()) {
5925 mf::LogVerbatim(
"TC") << someText <<
" No allTraj trajectories to print";
5931 if (itj == USHRT_MAX) {
5933 myprt <<
"Tj AngleCode-EndFlag (EF) decoder: <AngleCode> + <reason for stopping>";
5934 myprt <<
" (B=Bragg Peak, V=Vertex, A=AngleKink, C=ChargeKink, T=Trajectory)\n";
5935 std::vector<unsigned int>
tmp;
5937 <<
" UID CTP Pass Pts W:T Ang EF AveQ W:T Ang EF AveQ Chg(k) " 5938 "chgRMS Mom SDr __Vtx__ PDG Par Pri NuPar WorkID \n";
5939 for (
unsigned short ii = 0; ii < slc.
tjs.size(); ++ii) {
5940 auto& aTj = slc.
tjs[ii];
5942 myprt << someText <<
" ";
5948 myprt << std::fixed << std::setw(5) << tid;
5949 myprt << std::setw(6) << aTj.CTP;
5950 myprt << std::setw(5) << aTj.Pass;
5951 myprt << std::setw(5) << aTj.EndPt[1] - aTj.EndPt[0] + 1;
5952 unsigned short endPt0 = aTj.EndPt[0];
5953 auto& tp0 = aTj.Pts[endPt0];
5955 if (itick < 0) itick = 0;
5956 myprt << std::setw(6) << (int)(tp0.Pos[0] + 0.5) <<
":" << itick;
5957 if (itick < 10) { myprt <<
" "; }
5958 if (itick < 100) { myprt <<
" "; }
5959 if (itick < 1000) { myprt <<
" "; }
5960 myprt << std::setw(6) << std::setprecision(2) << tp0.Ang;
5961 myprt << std::setw(2) << tp0.AngleCode;
5962 if (aTj.EndFlag[0][
kBragg]) { myprt <<
"B"; }
5963 else if (aTj.EndFlag[0][
kAtVtx]) {
5966 else if (aTj.EndFlag[0][
kAtKink]) {
5969 else if (aTj.EndFlag[0][
kAtTj]) {
5975 myprt << std::setw(5) << (int)tp0.AveChg;
5976 unsigned short endPt1 = aTj.EndPt[1];
5977 auto& tp1 = aTj.Pts[endPt1];
5979 myprt << std::setw(6) << (int)(tp1.Pos[0] + 0.5) <<
":" << itick;
5980 if (itick < 10) { myprt <<
" "; }
5981 if (itick < 100) { myprt <<
" "; }
5982 if (itick < 1000) { myprt <<
" "; }
5983 myprt << std::setw(6) << std::setprecision(2) << tp1.Ang;
5984 myprt << std::setw(2) << tp1.AngleCode;
5985 if (aTj.EndFlag[1][
kBragg]) { myprt <<
"B"; }
5986 else if (aTj.EndFlag[1][
kAtVtx]) {
5992 myprt << std::setw(5) << (int)tp1.AveChg;
5993 myprt << std::setw(7) << std::setprecision(1) << aTj.TotChg / 1000;
5994 myprt << std::setw(7) << std::setprecision(2) << aTj.ChgRMS;
5995 myprt << std::setw(5) << aTj.MCSMom;
5996 myprt << std::setw(4) << aTj.StepDir;
5997 myprt << std::setw(4) << aTj.VtxID[0];
5998 myprt << std::setw(4) << aTj.VtxID[1];
5999 myprt << std::setw(5) << aTj.PDGCode;
6000 myprt << std::setw(5) << aTj.ParentID;
6001 myprt << std::setw(5) <<
PrimaryID(slc, aTj);
6003 myprt << std::setw(7) << aTj.WorkID;
6004 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6005 if (aTj.AlgMod[ib]) myprt <<
" " <<
AlgBitNames[ib];
6011 if (itj > slc.
tjs.size() - 1)
return;
6013 auto const& aTj = slc.
tjs[itj];
6015 mf::LogVerbatim(
"TC") <<
"Print slc.tjs[" << itj <<
"] Vtx[0] " << aTj.VtxID[0] <<
" Vtx[1] " 6018 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6019 if (aTj.AlgMod[ib]) myprt <<
" " <<
AlgBitNames[ib];
6023 if (ipt == USHRT_MAX) {
6025 for (
unsigned short ii = 0; ii < aTj.Pts.size(); ++ii)
6026 PrintTP(someText, slc, ii, aTj.StepDir, aTj.Pass, aTj.Pts[ii]);
6030 PrintTP(someText, slc, ipt, aTj.StepDir, aTj.Pass, aTj.Pts[ipt]);
6038 unsigned short tPoint)
6042 if (tPoint == USHRT_MAX) {
6045 myprt << someText <<
" ";
6046 myprt <<
"Work: UID " << tj.
UID <<
" CTP " << tj.
CTP <<
" StepDir " << tj.
StepDir 6048 <<
" nPts " << tj.
Pts.size() <<
" EndPts " << tj.
EndPt[0] <<
" " << tj.
EndPt[1];
6049 myprt <<
" MCSMom " << tj.
MCSMom;
6051 myprt <<
" AlgMods:";
6052 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6057 myprt << someText <<
" ";
6058 myprt <<
"slcID " << slc.
ID <<
" T" << tj.
ID <<
" uT" << tj.
UID <<
" WorkID " << tj.
WorkID 6060 <<
" " << tj.
VtxID[1] <<
" nPts " << tj.
Pts.size() <<
" EndPts " << tj.
EndPt[0] <<
" " 6062 myprt <<
" MCSMom " << tj.
MCSMom;
6064 myprt <<
" AlgMods:";
6065 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6069 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt)
6073 for (
unsigned short ic = 0; ic < slc.
cots.size(); ++ic) {
6074 if (slc.
cots[ic].TjIDs.empty())
continue;
6076 if (slc.
cots[ic].ShowerTjID != tj.
ID)
continue;
6079 myprt <<
"cots index " << ic <<
" ";
6080 myprt << someText <<
" Envelope";
6081 if (ss.
Envelope.empty()) { myprt <<
" NA"; }
6084 myprt <<
" " << (int)vtx[0] <<
":" << (
int)(vtx[1] /
tcc.
unitsPerTick);
6086 myprt <<
" Energy " << (int)ss.
Energy;
6087 myprt <<
" Area " << std::fixed << std::setprecision(1) << (int)ss.
EnvelopeArea 6089 myprt <<
"\nInShower TjIDs";
6091 myprt <<
" " << tjID;
6095 myprt <<
"NearTjIDs";
6097 myprt <<
" " << tjID;
6101 myprt <<
"Angle " << std::fixed << std::setprecision(2) << ss.
Angle <<
" +/- " 6103 myprt <<
" AspectRatio " << std::fixed << std::setprecision(2) << ss.
AspectRatio;
6104 myprt <<
" DirectionFOM " << std::fixed << std::setprecision(2) << ss.
DirectionFOM;
6107 myprt <<
" No parent";
6109 myprt <<
" TruParentID " << ss.
TruParentID <<
" SS3ID " << ss.
SS3ID <<
"\n";
6110 if (ss.
NeedsUpdate) myprt <<
"*********** This shower needs to be updated ***********";
6111 myprt <<
"................................................";
6117 if (tPoint > tj.
Pts.size() - 1) {
6118 mf::LogVerbatim(
"TC") <<
"Can't print non-existent traj point " << tPoint;
6129 <<
" TRP CTP Ind Stp Delta RMS Ang C Err Dir0 Dir1 Q " 6130 " AveQ Pull FitChi NTPF KinkSig Hits ";
6138 unsigned short pass,
6142 myprt << someText <<
" TRP" << std::fixed;
6144 if (dir > 0) { myprt <<
"+"; }
6148 myprt << std::setw(6) << tp.
CTP;
6149 myprt << std::setw(5) << ipt;
6150 myprt << std::setw(5) << tp.
Step;
6151 myprt << std::setw(6) << std::setprecision(2) << tp.
Delta;
6152 myprt << std::setw(6) << std::setprecision(2) << tp.
DeltaRMS;
6153 myprt << std::setw(6) << std::setprecision(2) << tp.
Ang;
6155 myprt << std::setw(6) << std::setprecision(2) << tp.
AngErr;
6156 myprt << std::setw(6) << std::setprecision(2) << tp.
Dir[0];
6157 myprt << std::setw(6) << std::setprecision(2) << tp.
Dir[1];
6158 myprt << std::setw(7) << (int)tp.
Chg;
6159 myprt << std::setw(8) << (int)tp.
AveChg;
6160 myprt << std::setw(6) << std::setprecision(1) << tp.
ChgPull;
6161 myprt << std::setw(7) << tp.
FitChi;
6162 myprt << std::setw(6) << tp.
NTPsFit;
6163 myprt << std::setw(7) << std::setprecision(3) << tp.
KinkSig;
6165 if (tp.
Hits.size() > 16) {
6167 myprt <<
" " << tp.
Hits.size() <<
" shower hits";
6170 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
6171 unsigned int iht = tp.
Hits[ii];
6173 myprt <<
" " <<
hit.WireID().Wire <<
":" << (int)
hit.PeakTime();
6181 myprt <<
"T" << slc.
slHits[iht].InTraj;
6183 if (tp.
InPFP > 0) myprt <<
" inP" << tp.
InPFP;
6193 std::string str =
"";
6194 for (
unsigned short ib = 0; ib < 8; ++ib) {
6203 if (ib ==
kEnvFlag) str +=
" Flag";
6214 myprt <<
" PFP sVx ________sPos_______ EF _______sDir______ ____sdEdx_____ eVx " 6215 "________ePos_______ EF _______eDir______ ____edEdx____ Len nTp3 MCSMom ShLike? " 6220 myprt << std::setw(5) << pid;
6222 for (
unsigned short end = 0;
end < 2; ++
end) {
6223 myprt << std::setw(4) << pfp.
Vx3ID[
end];
6224 myprt << std::fixed <<
std::right << std::setprecision(1);
6226 myprt << std::setw(7) << pos[0];
6227 myprt << std::setw(7) << pos[1];
6228 myprt << std::setw(7) << pos[2];
6236 myprt << std::setw(6) << ef;
6237 myprt << std::fixed <<
std::right << std::setprecision(2);
6239 myprt << std::setw(6) <<
dir[0];
6240 myprt << std::setw(6) << dir[1];
6241 myprt << std::setw(6) << dir[2];
6242 for (
auto& dedx : pfp.
dEdx[
end]) {
6243 if (dedx < 50) { myprt << std::setw(5) << std::setprecision(1) << dedx; }
6245 myprt << std::setw(5) << std::setprecision(0) << dedx;
6248 if (pfp.
dEdx[end].size() < 3) {
6249 for (
size_t i = 0; i < 3 - pfp.
dEdx[
end].size(); ++i) {
6250 myprt << std::setw(6) <<
' ';
6255 float length =
Length(pfp);
6256 if (length < 100) { myprt << std::setw(5) << std::setprecision(1) << length; }
6258 myprt << std::setw(5) << std::setprecision(0) << length;
6260 myprt << std::setw(5) << std::setprecision(2) << pfp.
TP3Ds.size();
6263 myprt << std::setw(5) << pfp.
PDGCode;
6267 if (!pfp.
TjIDs.empty()) {
6268 for (
auto& tjID : pfp.
TjIDs)
6269 myprt <<
" T" << tjID;
6273 for (
auto& dtrUID : pfp.
DtrUIDs)
6274 myprt <<
" P" << dtrUID;
6281 if (slc.
pfps.empty())
return;
6286 <<
" PFP sVx ________sPos_______ ______sDir______ ______sdEdx_____ eVx " 6287 "________ePos_______ ______eDir______ ______edEdx_____ BstPln PDG TruPDG Par Prim E*P\n";
6288 bool printHeader =
true;
6289 for (
auto& pfp : slc.
pfps) {
6290 PrintPFP(someText, slc, pfp, printHeader);
6291 printHeader =
false;
6299 if (end > 1)
return "Invalid end";
6302 for (
unsigned short ib = 0; ib <
EndFlagNames.size(); ++ib) {
6313 if (first) tmp =
" none";
6320 if (end > 1)
return "Invalid end";
6323 for (
unsigned short ib = 0; ib <
EndFlagNames.size(); ++ib) {
6364 unsigned int wire = 0;
6365 if (pos[0] > -0.4) wire = std::nearbyint(pos[0]);
Expect tracks entering from the front face. Don't create neutrino PFParticles.
void PrintAll(detinfo::DetectorPropertiesData const &detProp, std::string someText)
float HitsPosTime(const TCSlice &slc, const std::vector< unsigned int > &hitsInMultiplet, float &sum, HitStatus_t hitRequest)
void CheckTrajBeginChg(TCSlice &slc, unsigned short itj)
float AveChg
Calculated using ALL hits.
short MCSMom(const TCSlice &slc, const std::vector< int > &tjIDs)
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::vector< Trajectory > tjs
vector of all trajectories in each plane
void FitTraj(TCSlice const &slc, Trajectory &tj)
Point2_t dEdx
dE/dx for 3D matched trajectories
float Length(const PFPStruct &pfp)
bool dbgStitch
debug PFParticle stitching
void SetEndPoints(Trajectory &tj)
bool TrajHitsOK(TCSlice const &slc, const std::vector< unsigned int > &iHitsInMultiplet, const std::vector< unsigned int > &jHitsInMultiplet)
bool MakeVertexObsolete(std::string fcnLabel, TCSlice &slc, VtxStore &vx2, bool forceKill)
std::vector< float > kinkCuts
kink finder algorithm
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
bool InTrajOK(TCSlice &slc, std::string someText)
unsigned int Nwires(PlaneID const &planeid) const
Returns the total number of wires in the specified plane.
bool InsideFV(const TCSlice &slc, const PFPStruct &pfp, unsigned short end)
struct of temporary 2D vertices (end points)
std::vector< unsigned int > PutTrajHitsInVector(const Trajectory &tj, HitStatus_t hitRequest)
const std::vector< std::string > AlgBitNames
std::vector< ShowerStruct > cots
bool AttachAnyVertexToTraj(TCSlice &slc, int tjID, bool prt)
CTP_t CTP
Cryostat, TPC, Plane code.
std::vector< float > maxPos0
short recoTPC
only reconstruct in the seleted TPC
const geo::WireReadoutGeom * wireReadoutGeom
std::vector< int > NearTjIDs
std::array< double, 3 > Point3_t
std::vector< ShowerStruct3D > showers
bool SignalAtTp(TrajPoint &tp)
void SetPDGCode(TCSlice &slc, unsigned short itj)
double WireCoordinate(Point_t const &point) const
Returns the coordinate of the point on the plane, in wire units.
std::vector< Point2_t > Envelope
tagged as a vertex between Tjs that are matched to MC truth neutrino interaction particles ...
vertex position fixed manually - no fitting done
Declaration of signal hit object.
void FindAlongTrans(Point3_t pos1, Vector3_t dir1, Point3_t pos2, Point2_t &alongTrans)
void PrintTrajectory(std::string someText, const TCSlice &slc, const Trajectory &tj, unsigned short tPoint)
bool StartTraj(TCSlice const &slc, Trajectory &tj, unsigned int fromhit, unsigned int tohit, unsigned short pass)
void PrintTP(std::string someText, const TCSlice &slc, unsigned short ipt, short dir, unsigned short pass, const TrajPoint &tp)
std::vector< std::vector< std::pair< unsigned int, unsigned int > > > wireHitRange
The data type to uniquely identify a Plane.
void UnsetUsedHits(TCSlice &slc, TrajPoint &tp)
int ParentID
ID of the parent, or the ID of the Tj this one was merged with if it is killed.
std::vector< unsigned int > Hits
std::string PrintEndFlag(const PFPStruct &pfp, unsigned short end)
bool StoreTraj(TCSlice &slc, Trajectory &tj)
float TotChg
Total including an estimate for dead wires.
double Temperature() const
In kelvin.
short MCSMom
Normalized RMS using ALL hits. Assume it is 50% to start.
bool IsShowerLike(TCSlice const &slc, std::vector< int > const &TjIDs)
float TpSumHitChg(const TCSlice &slc, TrajPoint const &tp)
constexpr auto abs(T v)
Returns the absolute value of the argument.
void ChkChgAsymmetry(TCSlice &slc, Trajectory &tj, bool prt)
CryostatID_t Cryostat
Index of cryostat.
for(Int_t i=0;i< nentries;i++)
bool TrajClosestApproach(Trajectory const &tj, float x, float y, unsigned short &closePt, float &DOCA)
void FillWireHitRange(geo::TPCID inTPCID)
float TrajPointSeparation(const TrajPoint &tp1, const TrajPoint &tp2)
std::vector< std::pair< unsigned int, unsigned int > > tpcSrcHitRange
bool CompatibleMerge(const TCSlice &slc, std::vector< int > const &tjIDs, bool prt)
void SetAngleCode(TrajPoint &tp)
PFPStruct CreatePFP(const TCSlice &slc)
Point3_t PosAtEnd(const PFPStruct &pfp, unsigned short end)
float PointTrajDOCA(const TCSlice &slc, unsigned int iht, TrajPoint const &tp)
double DeltaAngle(const Vector3_t v1, const Vector3_t v2)
a general purpose flag bit used in 3D matching
bool dbgSlc
debug only in the user-defined slice? default is all slices
bool MakeBareTrajPoint(const TCSlice &slc, unsigned int fromHit, unsigned int toHit, TrajPoint &tp)
void Print2V(mf::LogVerbatim &myprt, VtxStore const &vx2, bool &printHeader)
std::vector< unsigned int > lastWire
the last wire with a hit
float GoodnessOfFit() const
Degrees of freedom in the determination of the hit signal shape (-1 by default)
bool LongPulseHit(const recob::Hit &hit)
std::array< int, 2 > Vx3ID
bool expectSlicedHits
info passed from the module - used to (not) define wireHitRange
void PrintPFPs(std::string someText, TCSlice const &slc)
short int Multiplicity() const
How many hits could this one be shared with.
float TPHitsRMSTime(const TCSlice &slc, const TrajPoint &tp, HitStatus_t hitRequest)
unsigned int MVI
MatchVec Index for detailed 3D matching.
std::string TPEnvString(const TrajPoint &tp)
pure virtual base interface for detector clocks
std::vector< int > CotIDs
std::string PrintPos(const TrajPoint &tp)
bool StoreVertex(TCSlice &slc, VtxStore &vx)
float MaxTjLen(const TCSlice &slc, std::vector< int > &tjIDs)
bool MergeTjIntoPFP(TCSlice &slc, int mtjid, PFPStruct &pfp, bool prt)
void Print3S(detinfo::DetectorPropertiesData const &detProp, mf::LogVerbatim &myprt, ShowerStruct3D const &ss3)
double DeltaAngle2(double Ang1, double Ang2)
std::vector< T > SetIntersection(const std::vector< T > &set1, const std::vector< T > &set2)
std::vector< float > angleRanges
list of max angles for each angle range
const std::vector< std::string > EndFlagNames
std::vector< float > showerTag
shower-like trajectory tagging + shower reconstruction
unsigned short Pass
the pass on which it was created
bool dbg3V
debug 3D vertex finding
double Efield(unsigned int planegap=0) const
kV/cm
bool SignalBetween(const TrajPoint &tp1, const TrajPoint &tp2, const float MinWireSignalFraction)
float MaxChargeAsymmetry(TCSlice &slc, std::vector< int > const &tjIDs)
span(IterB &&b, IterE &&e, Adaptor &&adaptor) -> span< std::invoke_result_t< Adaptor, IterB >, std::invoke_result_t< Adaptor, IterE >>
float OverlapFraction(const Trajectory &tj1, const Trajectory &tj2)
std::string PrintHitShort(const TCHit &tch)
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
float HitsRMSTime(const TCSlice &slc, const std::vector< unsigned int > &hitsInMultiplet, HitStatus_t hitRequest)
Access the description of the physical detector geometry.
unsigned int Hit
set to the hit index in evt.allHits if a Plane:Wire:Tick match is found
std::vector< int > TjUIDs
void FitPar(const Trajectory &tj, unsigned short originPt, unsigned short npts, short fitDir, ParFit &pFit, unsigned short usePar)
std::vector< unsigned int > PutHitsInVector(const TCSlice &slc, PFPStruct const &pfp, HitStatus_t hitRequest)
const std::vector< std::string > StrategyBitNames
float HitSep2(const TCSlice &slc, unsigned int iht, unsigned int jht)
int Cryostat
Select Cryostat.
int NeutrinoPrimaryTjID(const TCSlice &slc, const Trajectory &tj)
float HitsRMSTick(const TCSlice &slc, const std::vector< unsigned int > &hitsInMultiplet, HitStatus_t hitRequest)
struct of temporary 3D vertices
short nPtsAve
dump trajectory points
int PrimaryID(const TCSlice &slc, const Trajectory &tj)
unsigned short NearestPtWithChg(const Trajectory &tj, unsigned short thePt)
bool dbgStp
debug stepping using debug.Cryostat, debug.TPC, etc
int Wire
Select hit Wire for debugging.
std::array< float, 2 > Point2_t
std::vector< float > maxPos1
int PDGCodeVote(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, PFPStruct &pfp)
float unitsPerTick
scale factor from Tick to WSE equivalent units
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
int WorkID
Select the StartWorkID for debugging.
float DeadWireCount(const TCSlice &slc, const TrajPoint &tp1, const TrajPoint &tp2)
bool BraggSplit(TCSlice &slc, unsigned short itj)
void DefineHitPos(TCSlice &slc, TrajPoint &tp)
Vector3_t PointDirection(const Point3_t p1, const Point3_t p2)
float PointTrajDOCA2(float wire, float time, TrajPoint const &tp)
TP is near a hit in the srcHit collection but no allHit hit exists (DUNE disambiguation error) ...
CTP_t CTP
Cryostat, TPC, Plane code.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
bool MergeShowerTjsAndStore(TCSlice &slc, unsigned short istj, unsigned short jstj, bool prt)
bool dbg2V
debug 2D vertex finding
std::vector< float > aveHitRMS
average RMS of an isolated hit
std::vector< TrajPoint > Pts
Trajectory points.
float ElectronLikelihood(const TCSlice &slc, const Trajectory &tj)
float TwoTPAngle(const TrajPoint &tp1, const TrajPoint &tp2)
void TjDeltaRMS(const Trajectory &tj, unsigned short firstPt, unsigned short lastPt, double &rms, unsigned short &cnt)
std::vector< std::vector< bool > > goodWire
float ChgFracNearPos(const TCSlice &slc, const Point2_t &pos, const std::vector< int > &tjIDs)
std::vector< unsigned int > FindCloseHits(const TCSlice &slc, std::array< int, 2 > const &wireWindow, Point2_t const &timeWindow, const unsigned short plane, HitStatus_t hitRequest, bool usePeakTime, bool &hitsNear)
float ChgFracBetween(detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, Point3_t pos1, Point3_t pos2)
void MakeHaloTj(TCSlice &slc, Trajectory &muTj, bool prt)
TrajPoint MakeBareTP(detinfo::DetectorPropertiesData const &detProp, const Point3_t &pos, CTP_t inCTP)
void PrintT(mf::LogVerbatim &myprt, Trajectory const &tj, bool &printHeader)
std::vector< VtxStore > vtxs
2D vertices
std::array< unsigned short, 2 > EndPt
First and last point in the trajectory that has charge.
unsigned short PDGCode
shower-like or track-like {default is track-like}
double ConvertXToTicks(double X, int p, int t, int c) const
bool PointInsideEnvelope(const Point2_t &Point, const std::vector< Point2_t > &Envelope)
virtual raw::ChannelID_t PlaneWireToChannel(WireID const &wireID) const =0
Returns the channel ID a wire is connected to.
std::vector< float > match3DCuts
3D matching cuts
std::vector< SectionFit > SectionFits
unsigned int NumberTimeSamples() const
void MakeTrajectoryObsolete(TCSlice &slc, unsigned int itj)
short StartEnd
The starting end (-1 = don't know)
double PosSep2(const Point3_t &pos1, const Point3_t &pos2)
unsigned short GetPFPIndex(const TCSlice &slc, int tjID)
std::string PrintHit(const TCHit &tch)
bool Fit2D(short mode, Point2_t inPt, float &inPtErr, Vector2_t &outVec, Vector2_t &outVecErr, float &chiDOF)
bool SplitTraj(detinfo::DetectorPropertiesData const &detProp, TCSlice &slc, unsigned short itj, float XPos, bool makeVx2, bool prt)
const geo::GeometryCore * geom
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
int UID
a unique ID for all slices
The data type to uniquely identify a TPC.
PlaneID_t Plane
Index of the plane within its TPC.
void PrintP(mf::LogVerbatim &myprt, PFPStruct const &pfp, bool &printHeader)
float ExpectedHitsRMS(const TrajPoint &tp)
bool valsIncreasing(const SortEntry &c1, const SortEntry &c2)
void ReleaseHits(TCSlice &slc, Trajectory const &tj)
bool SetMag(Vector3_t &v1, double mag)
std::array< double, 2 > Vector2_t
Definition of data types for geometry description.
unsigned short NumHitsInTP(const TrajPoint &tp, HitStatus_t hitRequest)
void TrimEndPts(std::string fcnLabel, TCSlice &slc, Trajectory &tj, const std::vector< float > &fQualityCuts, bool prt)
unsigned short FarEnd(const PFPStruct &pfp, const Point3_t &pos)
void DefineTjParents(TCSlice &slc, bool prt)
float HitsPosTick(const TCSlice &slc, const std::vector< unsigned int > &hitsInMultiplet, float &sum, HitStatus_t hitRequest)
std::vector< unsigned int > firstWire
the first wire with a hit
int ID
ID that is local to one slice.
std::vector< TCSlice > slices
std::array< unsigned short, 2 > VtxID
ID of 2D vertex.
Detector simulation of raw signals on wires.
float MCSThetaRMS(const Trajectory &tj)
unsigned int Nplanes(TPCID const &tpcid=details::tpc_zero) const
Returns the total number of planes in the specified TPC.
std::bitset< 16 > modes
number of points to find AveChg
std::vector< TCHit > slHits
unsigned short NearbyCleanPt(const Trajectory &tj, unsigned short end)
bool MergeAndStore(TCSlice &slc, unsigned int itj1, unsigned int itj2, bool doPrt)
void RestoreObsoleteTrajectory(TCSlice &slc, unsigned int itj)
bool aveHitRMSValid
set true when the average hit RMS is well-known
std::bitset< 16 > Stat
Vertex status bits using kVtxBit_t.
void PrintPFP(std::string someText, TCSlice const &slc, const PFPStruct &pfp, bool printHeader)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
std::vector< int > GetAssns(TCSlice const &slc, std::string type1Name, int id, std::string type2Name)
int Tick
Select hit PeakTime for debugging (< 0 for vertex finding)
void TrajIntersection(TrajPoint const &tp1, TrajPoint const &tp2, Point2_t &pos)
const std::vector< std::string > VtxBitNames
int PrimaryUID(const PFPStruct &pfp)
double DotProd(const Vector3_t &v1, const Vector3_t &v2)
void UpdateTjChgProperties(std::string inFcnLabel, TCSlice const &slc, Trajectory &tj, bool prt)
std::vector< Vtx3Store > vtx3s
3D vertices
float KinkSignificance(TCSlice const &slc, Trajectory const &tj1, unsigned short end1, Trajectory const &tj2, unsigned short end2, unsigned short nPtsFit, bool useChg, bool prt)
void Print3V(detinfo::DetectorPropertiesData const &detProp, mf::LogVerbatim &myprt, Vtx3Store const &vx3, bool &printHeader)
bool DecodeDebugString(std::string strng)
std::vector< recob::Hit > const * srcHits
std::bitset< 128 > useAlg
Max hit separation for making junk trajectories. < 0 to turn off.
Contains all timing reference information for the detector.
View_t View(raw::ChannelID_t const channel) const
Returns the view (wire orientation) on the specified TPC channel.
short StepDir
-1 = going US (-> small wire#), 1 = going DS (-> large wire#)
float MaxHitDelta(TCSlice &slc, Trajectory &tj)
float TrajLength(const Trajectory &tj)
std::bitset< 128 > AlgMod
Bit set if algorithm AlgBit_t modifed the trajectory.
std::vector< short > muonTag
void UpdateVxEnvironment(TCSlice &slc)
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
geo::PlaneID DecodeCTP(CTP_t CTP)
void TagJunkTj(Trajectory &tj, bool prt)
std::vector< int > GetVtxTjIDs(const TCSlice &slc, const VtxStore &vx2)
double PosSep(const Point3_t &pos1, const Point3_t &pos2)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
range_type< T > Iterate() const
void TrimHiChgEndPts(TCSlice &slc, Trajectory &tj, bool prt)
std::bitset< 128 > dbgAlg
Allow user to turn on debug printing in algorithms (that print...)
unsigned short PDGCodeIndex(int PDGCode)
float PointPull(const TP3D &tp3d)
std::bitset< 8 > Environment
std::vector< recob::Hit > const * allHits
bool valsDecreasing(const SortEntry &c1, const SortEntry &c2)
CTP_t EncodeCTP(unsigned int cryo, unsigned int tpc, unsigned int plane)
std::pair< unsigned short, unsigned short > GetSliceIndex(std::string typeName, int uID)
unsigned short MVI_Iter
MVI iteration - see FindPFParticles.
std::vector< unsigned int > nWires
use the stiff electron strategy
std::array< std::bitset< 8 >, 2 > EndFlag
float PointTrajSep2(float wire, float time, TrajPoint const &tp)
std::array< double, 3 > Vector3_t
std::vector< float > chkStopCuts
Bragg peak finder configuration.
bool SignalAtTpInSlc(const TCSlice &slc, const TrajPoint &tp)
std::vector< TP3D > TP3Ds
int ID
ID of the recob::Slice (not the sub-slice)
std::array< std::vector< float >, 2 > dEdx
void SetVx2Score(TCSlice &slc)
std::vector< float > vtx2DCuts
Max position pull, max Position error rms.
std::bitset< 8 > Strategy
bool NearbySrcHit(geo::PlaneID plnID, unsigned int wire, float loTick, float hiTick)
std::vector< PFPStruct > pfps
std::vector< int > FindCloseTjs(const TCSlice &slc, const TrajPoint &fromTp, const TrajPoint &toTp, const float &maxDelta)
2D representation of charge deposited in the TDC/wire plane
void PrintAllTraj(detinfo::DetectorPropertiesData const &detProp, std::string someText, TCSlice const &slc, unsigned short itj, unsigned short ipt, bool prtVtx)
void MoveTPToWire(TrajPoint &tp, float wire)
unsigned short NumPtsWithCharge(const TCSlice &slc, const Trajectory &tj, bool includeDeadWires)
unsigned short CloseEnd(const Trajectory &tj, const Point2_t &pos)
PlaneGeo const & Plane(TPCID const &tpcid, View_t view) const
Returns the specified wire.
void MergeGhostTjs(TCSlice &slc, CTP_t inCTP)
bool TrajIsClean(Trajectory const &tj, bool prt)
unsigned int ChannelID_t
Type representing the ID of a readout channel.
unsigned int allHitsIndex
TPCID_t TPC
Index of the TPC within its cryostat.
TPCGeo const & TPC(TPCID const &tpcid=details::tpc_zero) const
Returns the specified TPC.
bool StorePFP(TCSlice &slc, PFPStruct &pfp)
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
bool TrajTrajDOCA(const TCSlice &slc, const Trajectory &tj1, const Trajectory &tj2, unsigned short &ipt1, unsigned short &ipt2, float &minSep)
std::vector< std::vector< std::pair< unsigned int, unsigned int > > > wireHitRange
Vector3_t DirAtEnd(const PFPStruct &pfp, unsigned short end)
short recoSlice
only reconstruct the slice with ID (0 = all)
float TjChgFrac
Fraction of charge near the vertex that is from hits on the vertex Tjs.
bool dbgSummary
print a summary report
bool NeedsUpdate
Set true when the Tj needs to be updated.
bool WireHitRangeOK(TCSlice const &slc, const CTP_t &inCTP)
void TrajPointTrajDOCA(TrajPoint const &tp, Trajectory const &tj, unsigned short &closePt, float &minSep)
master switch for turning on debug mode
float TPHitsRMSTick(const TCSlice &slc, const TrajPoint &tp, HitStatus_t hitRequest)
Interface to geometry for wire readouts .
void PrintTPHeader(std::string someText)
void ChkEndKink(TCSlice const &slc, Trajectory &tj, bool prt)
CTP_t CTP
set to an invalid CTP
std::vector< int > DtrUIDs
constexpr Point origin()
Returns a origin position with a point of the specified type.
unsigned short AngleRange(TrajPoint const &tp)
use the stiff muon strategy
void PosInPlane(detinfo::DetectorPropertiesData const &detProp, const Vtx3Store &vx3, unsigned short plane, Point2_t &pos)
Encapsulate the construction of a single detector plane .
std::array< std::bitset< 8 >, 2 > EndFlag
void SetTPEnvironment(TCSlice &slc, CTP_t inCTP)
bool HasDuplicateHits(const TCSlice &slc, Trajectory const &tj, bool prt)
void ReverseTraj(Trajectory &tj)