4 #include <boost/algorithm/string/classification.hpp> 5 #include <boost/algorithm/string/split.hpp> 58 std::vector<int> dtrs;
59 for (
auto& dtj : slc.
tjs) {
60 if (dtj.AlgMod[
kKilled])
continue;
61 if (dtj.ParentID != muTj.
ID)
continue;
62 dtrs.push_back(dtj.ID);
64 if (prt)
mf::LogVerbatim(
"TC") <<
"MakeHaloTj: Killing delta-ray T" << dtj.ID;
68 if (pfpIndex == USHRT_MAX) {
69 if (prt)
mf::LogVerbatim(
"TC") <<
" No PFP found for 3D-matched delta-ray";
72 auto& pfp = slc.
pfps[pfpIndex];
73 if (prt)
mf::LogVerbatim(
"TC") <<
" Killing delta-ray PFParticle P" << pfp.UID;
76 if (pfp.ParentUID > 0) {
78 if (parentIndx.first != USHRT_MAX) {
79 auto&
parent =
slices[parentIndx.first].pfps[parentIndx.second];
80 std::vector<int> newDtrUIDs;
81 for (
auto uid :
parent.DtrUIDs)
82 if (uid != dtj.UID) newDtrUIDs.push_back(uid);
83 parent.DtrUIDs = newDtrUIDs;
95 tj.
ID = slc.
tjs.size() + 1;
111 std::vector<int> closeTjs;
112 for (
unsigned short ipt = muTj.
EndPt[0]; ipt <= muTj.
EndPt[1]; ++ipt) {
113 auto tp = muTj.
Pts[ipt];
124 if (tp.Dir[0] != 0) window *=
std::abs(1 / tp.Dir[0]);
127 bool hitsAdded =
false;
128 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
129 unsigned int iht = tp.Hits[ii];
130 auto inTraj = slc.
slHits[iht].InTraj;
131 if (inTraj < 0)
continue;
133 tp.UseHit[ii] =
true;
139 if (inTraj != muTj.
ID &&
140 std::find(closeTjs.begin(), closeTjs.end(), inTraj) == closeTjs.end())
141 closeTjs.push_back(inTraj);
146 tp.Delta =
PointTrajDOCA(slc, tp.HitPos[0], tp.HitPos[1], tp);
148 tj.
Pts.push_back(tp);
151 if (tj.
Pts.empty())
return;
155 myprt <<
"MHTj: T" << muTj.
ID <<
" npts " << tj.
Pts.size() <<
" close";
156 for (
auto tid : closeTjs)
157 myprt <<
" T" << tid;
161 slc.
tjs.push_back(tj);
199 for (
auto& tj : slc.
tjs) {
200 if (tj.AlgMod[
kKilled])
continue;
207 std::vector<int>
temp;
208 for (
auto& vx3 : slc.
vtx3s) {
209 if (vx3.ID == 0)
continue;
212 temp.push_back(vx3.ID);
214 if (temp.empty())
return;
217 std::vector<int> masterlist;
218 for (
auto vx3id : temp) {
219 auto& vx3 = slc.
vtx3s[vx3id - 1];
222 for (
auto tjid : tjlist) {
223 auto& tj = slc.
tjs[tjid - 1];
224 if (tj.ParentID != 0) tj.ParentID = 0;
225 if (std::find(masterlist.begin(), masterlist.end(), tjid) == masterlist.end())
226 masterlist.push_back(tjid);
231 myprt <<
"DTP: masterlist Tjs";
232 for (
auto tjid : masterlist)
233 myprt <<
" " << tjid;
237 std::vector<SortEntry> sortVec(temp.size());
238 for (
unsigned short indx = 0; indx < temp.size(); ++indx) {
239 auto& vx3 = slc.
vtx3s[temp[indx] - 1];
240 sortVec[indx].index = indx;
241 sortVec[indx].val = vx3.Score;
243 if (sortVec.size() > 1) std::sort(sortVec.begin(), sortVec.end(),
valsDecreasing);
246 for (
unsigned short indx = 0; indx < temp.size(); ++indx)
247 vlist[indx] = temp[sortVec[indx].
index];
251 auto& vx3 = slc.
vtx3s[vlist[0] - 1];
257 auto& sf = neutrinoPFP.SectionFits[0];
263 neutrinoPFP.PDGCode = 14;
264 neutrinoPFP.Vx3ID[1] = vx3.ID;
265 neutrinoPFP.Vx3ID[0] = vx3.ID;
268 if (!
StorePFP(slc, neutrinoPFP))
return;
272 std::vector<bool> lookedAt3(slc.
vtx3s.size() + 1,
false);
273 std::vector<bool> lookedAt2(slc.
vtxs.size() + 1,
false);
275 std::vector<std::pair<int, int>> pardtr;
277 for (
unsigned short indx = 0; indx < vlist.size(); ++indx) {
278 auto& vx3 = slc.
vtx3s[vlist[indx] - 1];
279 if (lookedAt3[vx3.ID])
continue;
281 lookedAt3[vx3.ID] =
true;
285 if (primTjList.empty())
continue;
287 for (
auto primTjID : primTjList) {
288 auto& primTj = slc.
tjs[primTjID - 1];
290 if (primTj.ParentID != -1)
continue;
291 if (prt)
mf::LogVerbatim(
"TC") <<
"Vx3 " << vx3.ID <<
" Primary tj " << primTj.ID;
296 for (
unsigned short end = 0;
end < 2; ++
end) {
297 if (primTj.VtxID[
end] == 0)
continue;
298 auto& vx2 = slc.
vtxs[primTj.VtxID[
end] - 1];
299 if (vx2.Vx3ID == vx3.ID)
continue;
302 for (
auto dtrID : dtrList) {
304 if (dtrID == primTjID)
continue;
305 auto& dtj = slc.
tjs[dtrID - 1];
306 if (dtj.ParentID != -1)
continue;
307 pardtr.push_back(std::make_pair(primTjID, dtrID));
308 if (prt)
mf::LogVerbatim(
"TC") <<
" primTj " << primTjID <<
" dtrID " << dtrID;
312 for (
unsigned short end = 0;
end < 2; ++
end) {
313 if (primTj.VtxID[
end] == 0)
continue;
314 auto& vx2 = slc.
vtxs[primTj.VtxID[
end] - 1];
318 if (pardtr.empty())
continue;
322 for (
auto pdtr : pardtr)
323 myprt <<
" " << pdtr.first <<
"_" << pdtr.second;
327 for (
unsigned short nit = 0; nit < 100; ++nit) {
328 auto lastPair = pardtr[pardtr.size() - 1];
329 auto& dtj = slc.
tjs[lastPair.second - 1];
330 dtj.ParentID = lastPair.first;
333 unsigned short dpt = 0, ppt = 0;
334 auto& ptj = slc.
tjs[lastPair.first - 1];
338 if (prt)
mf::LogVerbatim(
"TC") <<
"Set parent " << ptj.ID <<
" dtr " << dtj.ID;
342 for (
unsigned short end = 0;
end < 2; ++
end) {
343 if (dtj.VtxID[
end] == 0)
continue;
344 auto& vx2 = slc.
vtxs[dtj.VtxID[
end] - 1];
345 if (lookedAt2[vx2.ID])
continue;
346 lookedAt2[vx2.ID] =
true;
348 for (
auto tjid : tjlist) {
349 if (tjid == dtj.ID || tjid == ptj.ID)
continue;
350 pardtr.push_back(std::make_pair(dtj.ID, tjid));
353 myprt <<
" add par_dtr";
354 for (
auto pdtr : pardtr)
355 myprt <<
" " << pdtr.first <<
"_" << pdtr.second;
359 if (pardtr.empty())
break;
363 for (
auto tjid : masterlist) {
364 auto& tj = slc.
tjs[tjid - 1];
365 if (tj.ParentID < 0) tj.ParentID = tj.ID;
375 if (tjIDs.size() < 2)
return 1;
376 std::vector<float> plnchg(slc.
nPlanes);
377 for (
auto tjid : tjIDs) {
378 if (tjid <= 0 || tjid > (
int)slc.
tjs.size())
return 1;
379 auto& tj = slc.
tjs[tjid - 1];
382 plnchg[plane] += tj.TotChg;
386 for (
unsigned short plane = 0; plane < slc.
nPlanes; ++plane) {
387 if (plnchg[plane] == 0)
continue;
388 aveChg += plnchg[plane];
391 if (cnt < 2)
return 1;
394 for (
unsigned short plane = 0; plane < slc.
nPlanes; ++plane) {
396 if (plnchg[plane] == 0)
continue;
397 float asym =
std::abs(plnchg[plane] - aveChg) / (plnchg[plane] + aveChg);
398 if (asym > maxAsym) maxAsym = asym;
414 std::array<int, 5> codeList = {{0, 11, 13, 111, 211}};
415 unsigned short codeIndex = 0;
416 if (tjIDs.empty())
return codeList[codeIndex];
418 std::array<unsigned short, 5> cnts;
421 for (
auto tjid : tjIDs) {
422 if (tjid <= 0 || tjid > (
int)slc.
tjs.size())
continue;
423 auto& tj = slc.
tjs[tjid - 1];
424 for (
unsigned short ii = 0; ii < 5; ++ii)
425 if (tj.PDGCode == codeList[ii]) ++cnts[ii];
427 if (len > maxLen) maxLen = len;
431 for (
unsigned short ii = 1; ii < 5; ++ii) {
432 if (cnts[ii] > maxCnt) {
437 return codeList[codeIndex];
449 if (primID <= 0 || primID > (
int)slc.
tjs.size())
return -1;
452 auto& ptj = slc.
tjs[primID - 1];
453 for (
unsigned short end = 0;
end < 2; ++
end) {
454 if (ptj.VtxID[
end] == 0)
continue;
455 auto& vx2 = slc.
vtxs[ptj.VtxID[
end] - 1];
456 if (vx2.Vx3ID == 0)
continue;
457 auto& vx3 = slc.
vtx3s[vx2.Vx3ID - 1];
458 if (vx3.Neutrino)
return primID;
473 for (
unsigned short nit = 0; nit < 10; ++nit) {
474 if (parid < 1 || parid > (
int)slc.
tjs.size())
break;
475 auto& tj = slc.
tjs[parid - 1];
491 int dtruid = pfp.
UID;
492 unsigned short nit = 0;
495 auto&
parent =
slices[slcIndx.first].pfps[slcIndx.second];
497 if (
parent.PDGCode == 14 ||
parent.PDGCode == 12)
return dtruid;
502 paruid =
parent.ParentUID;
503 if (paruid < 0)
return 0;
505 if (nit == 10)
return 0;
514 if (mtjid > (
int)slc.
tjs.size())
return false;
515 auto& mtj = slc.
tjs[mtjid - 1];
518 for (
auto tjid : pfp.
TjIDs) {
519 auto& otj = slc.
tjs[tjid - 1];
520 if (otj.CTP == mtj.CTP) {
525 if (otjid == 0)
return false;
527 int newtjid = slc.
tjs.size();
529 mf::LogVerbatim(
"TC") <<
"MergeTjIntoPFP: merged T" << otjid <<
" with T" << mtjid
530 <<
" -> T" << newtjid;
531 std::replace(pfp.
TjIDs.begin(), pfp.
TjIDs.begin(), otjid, newtjid);
536 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);
592 if (tjIDs.size() < 2)
return false;
593 unsigned short lasttj = tjIDs[tjIDs.size() - 1] - 1;
594 auto& mtj = slc.
tjs[lasttj];
595 bool mtjIsShort = (mtj.Pts.size() < 5);
597 std::array<float, 2> minsep2{{1000, 1000}};
599 std::array<int, 2> minsepTj{{0, 0}};
601 std::array<unsigned short, 2> minsepPt;
604 std::array<unsigned short, 2> minsepEnd;
605 for (
auto tjid : tjIDs) {
606 auto& tj = slc.
tjs[tjid - 1];
607 if (tj.CTP != mtj.CTP)
continue;
608 if (tj.ID == mtj.ID)
continue;
609 for (
unsigned short mend = 0; mend < 2; ++mend) {
610 Point2_t mendPos = mtj.Pts[mtj.EndPt[mend]].Pos;
611 float sep2 = minsep2[mend];
612 unsigned short closePt = 0;
614 minsep2[mend] = sep2;
615 minsepTj[mend] = tjid;
616 minsepPt[mend] = closePt;
619 short dend0 =
abs((
short)closePt - tj.EndPt[0]);
620 short dend1 =
abs((
short)closePt - tj.EndPt[1]);
621 if (dend0 < dend1 && dend0 < 3) minsepEnd[mend] = 0;
622 if (dend1 < dend0 && dend1 < 3) minsepEnd[mend] = 1;
628 bool isCompatible = (minsepEnd[0] != 2 && minsepEnd[1] != 2);
630 if (isCompatible && mtjIsShort) {
631 float minminsep = minsep2[0];
632 if (minsep2[1] < minminsep) minminsep = minsep2[1];
634 isCompatible = minminsep < 5;
638 myprt <<
"CompatibleMerge: T" << mtj.ID <<
" end";
639 for (
unsigned short end = 0;
end < 2; ++
end)
640 myprt <<
" T" << minsepTj[
end] <<
"_I" << minsepPt[
end] <<
"_E" << minsepEnd[
end]
641 <<
" minsep " << sqrt(minsep2[
end]);
642 myprt <<
" Compatible? " << isCompatible;
656 if (tj1.
CTP != tj2.
CTP)
return false;
657 unsigned short end1 = -1, end2 = 0;
660 if (len2 < minLen) minLen = len2;
662 if (minLen > 10) minLen = 10;
663 for (
unsigned short e1 = 0; e1 < 2; ++e1) {
665 for (
unsigned short e2 = 0; e2 < 2; ++e2) {
667 float sep =
PosSep(tp1.Pos, tp2.Pos);
675 if (end1 < 0)
return false;
677 if (end2 != 1 - end1)
return false;
680 if (overlapFraction > 0.25) {
683 << overlapFraction <<
" > 0.25 ";
687 auto& tp1 = tj1.
Pts[tj1.
EndPt[end1]];
688 auto& tp2 = tj2.
Pts[tj2.
EndPt[end2]];
689 float doca1 =
PointTrajDOCA(slc, tp1.Pos[0], tp1.Pos[1], tp2);
690 float doca2 =
PointTrajDOCA(slc, tp2.Pos[0], tp2.Pos[1], tp1);
691 if (doca1 > 2 && doca2 > 2) {
715 float maxWire = -1E6;
718 for (
auto& tp : tj1.
Pts) {
719 if (tp.Chg == 0)
continue;
720 if (tp.Pos[0] < 0)
continue;
721 if (tp.Pos[0] < minWire) minWire = tp.Pos[0];
722 if (tp.Pos[0] > maxWire) maxWire = tp.Pos[0];
725 if (cnt1 == 0)
return 0;
727 for (
auto& tp : tj2.
Pts) {
728 if (tp.Chg == 0)
continue;
729 if (tp.Pos[0] < 0)
continue;
730 if (tp.Pos[0] < minWire) minWire = tp.Pos[0];
731 if (tp.Pos[0] > maxWire) maxWire = tp.Pos[0];
734 if (cnt2 == 0)
return 0;
735 int span = maxWire - minWire;
736 if (span <= 0)
return 0;
737 std::vector<unsigned short> wcnt(span);
738 for (
auto& tp : tj1.
Pts) {
739 if (tp.Chg == 0)
continue;
740 if (tp.Pos[0] < -0.4)
continue;
741 int indx = std::nearbyint(tp.Pos[0] - minWire);
742 if (indx < 0 || indx > span - 1)
continue;
745 for (
auto& tp : tj2.
Pts) {
746 if (tp.Chg == 0)
continue;
747 if (tp.Pos[0] < -0.4)
continue;
748 int indx = std::nearbyint(tp.Pos[0] - minWire);
749 if (indx < 0 || indx > span - 1)
continue;
752 float cntOverlap = 0;
753 for (
auto cnt : wcnt)
754 if (cnt > 1) ++cntOverlap;
755 if (cnt1 < cnt2) {
return cntOverlap / cnt1; }
757 return cntOverlap / cnt2;
796 if (angle < 0) angle = -angle;
797 if (angle >
M_PI / 2) angle =
M_PI - angle;
809 unsigned short originPt = tj.
EndPt[1];
810 unsigned short npts = tj.
Pts[originPt].NTPsFit;
812 unsigned short fitDir = -1;
813 FitTraj(slc, tj, originPt, npts, fitDir, tpFit);
814 tj.
Pts[originPt] = tpFit;
822 unsigned short originPt,
842 if (originPt > tj.
Pts.size() - 1) {
843 mf::LogWarning(
"TC") <<
"FitTraj: Requesting fit of invalid TP " << originPt;
848 tpFit = tj.
Pts[originPt];
851 if (fitDir < -1 || fitDir > 1)
return;
853 std::vector<double>
x,
y;
856 if (tj.
Pts[originPt].Chg == 0) origin = tj.
Pts[originPt].Pos;
860 for (
unsigned short ipt = tj.
EndPt[0]; ipt < tj.
EndPt[1]; ++ipt) {
861 if (tj.
Pts[ipt].Chg <= 0)
continue;
862 double xx = tj.
Pts[ipt].HitPos[0] - origin[0];
863 double yy = tj.
Pts[ipt].HitPos[1] - origin[1];
867 if (x.size() != 2)
return;
871 if (y[1] < y[0]) tpFit.
Ang = -tpFit.
Ang;
874 double dx = x[1] - x[0];
875 double dy = y[1] - y[0];
876 tpFit.
Ang = atan2(dy, dx);
878 tpFit.
Dir[0] = cos(tpFit.
Ang);
879 tpFit.
Dir[1] = sin(tpFit.
Ang);
880 tpFit.
Pos[0] += origin[0];
881 tpFit.
Pos[1] += origin[1];
888 std::vector<double>
w, q;
889 std::array<double, 2>
dir;
890 double xx, yy, xr, yr;
895 double rotAngle = tj.
Pts[originPt].Ang;
896 double cs = cos(-rotAngle);
897 double sn = sin(-rotAngle);
900 if (tj.
Pts[originPt].Chg > 0) {
901 xx = tj.
Pts[originPt].HitPos[0] - origin[0];
902 yy = tj.
Pts[originPt].HitPos[1] - origin[1];
903 xr = cs * xx - sn * yy;
904 yr = sn * xx + cs * yy;
907 chgWt = tj.
Pts[originPt].ChgPull;
908 if (chgWt < 1) chgWt = 1;
910 w.push_back(chgWt * tj.
Pts[originPt].HitPosErr2);
914 if (fitDir != 0) --npts;
918 unsigned short cnt = 0;
919 for (
unsigned short ipt = originPt + 1; ipt < tj.
Pts.size(); ++ipt) {
920 if (tj.
Pts[ipt].Chg <= 0)
continue;
921 xx = tj.
Pts[ipt].HitPos[0] - origin[0];
922 yy = tj.
Pts[ipt].HitPos[1] - origin[1];
923 xr = cs * xx - sn * yy;
924 yr = sn * xx + cs * yy;
927 chgWt = tj.
Pts[ipt].ChgPull;
928 if (chgWt < 1) chgWt = 1;
930 w.push_back(chgWt * tj.
Pts[ipt].HitPosErr2);
932 if (cnt == npts)
break;
937 if (fitDir != 1 && originPt > 0) {
938 unsigned short cnt = 0;
939 for (
unsigned short ii = 1; ii < tj.
Pts.size(); ++ii) {
940 unsigned short ipt = originPt - ii;
941 if (ipt > tj.
Pts.size() - 1)
continue;
942 if (tj.
Pts[ipt].Chg == 0)
continue;
943 xx = tj.
Pts[ipt].HitPos[0] - origin[0];
944 yy = tj.
Pts[ipt].HitPos[1] - origin[1];
945 xr = cs * xx - sn * yy;
946 yr = sn * xx + cs * yy;
949 chgWt = tj.
Pts[ipt].ChgPull;
950 if (chgWt < 1) chgWt = 1;
952 w.push_back(chgWt * tj.
Pts[ipt].HitPosErr2);
954 if (cnt == npts)
break;
960 if (x.size() < 2)
return;
971 for (
unsigned short ipt = 0; ipt < x.size(); ++ipt) {
972 if (w[ipt] < 0.00001) w[ipt] = 0.00001;
975 sumx += wght * x[ipt];
976 sumy += wght * y[ipt];
977 sumx2 += wght * x[ipt] * x[ipt];
978 sumy2 += wght * y[ipt] * y[ipt];
979 sumxy += wght * x[ipt] * y[ipt];
982 double delta = sum * sumx2 - sumx * sumx;
983 if (delta == 0)
return;
985 double A = (sumx2 * sumy - sumx * sumxy) / delta;
987 double B = (sumxy * sum - sumx * sumy) / delta;
992 double newang = atan(B);
993 dir[0] = cos(newang);
994 dir[1] = sin(newang);
998 tpFit.
Dir[0] = cs * dir[0] - sn * dir[1];
999 tpFit.
Dir[1] = sn * dir[0] + cs * dir[1];
1001 bool flipDir =
false;
1003 flipDir = std::signbit(tpFit.
Dir[1]) != std::signbit(tj.
Pts[originPt].Dir[1]);
1006 flipDir = std::signbit(tpFit.
Dir[0]) != std::signbit(tj.
Pts[originPt].Dir[0]);
1009 tpFit.
Dir[0] = -tpFit.
Dir[0];
1010 tpFit.
Dir[1] = -tpFit.
Dir[1];
1012 tpFit.
Ang = atan2(tpFit.
Dir[1], tpFit.
Dir[0]);
1016 tpFit.
Pos[0] = -sn * A + origin[0];
1017 tpFit.
Pos[1] = cs * A + origin[1];
1021 if (x.size() < 3)
return;
1024 double ndof = x.size() - 2;
1026 (sumy2 + A * A * sum + B * B * sumx2 - 2 * (A * sumy + B * sumxy - A * B * sumx)) / ndof;
1030 double slopeError = sqrt(varnce * sum / delta);
1039 for (
unsigned short ii = 0; ii < y.size(); ++ii) {
1040 arg = y[ii] - A - B * x[ii];
1041 sum += arg * arg / w[ii];
1043 tpFit.
FitChi = sum / ndof;
1050 if (slc.
pfps.empty())
return USHRT_MAX;
1051 for (
unsigned int ipfp = 0; ipfp < slc.
pfps.size(); ++ipfp) {
1052 const auto& pfp = slc.
pfps[ipfp];
1053 if (std::find(pfp.TjIDs.begin(), pfp.TjIDs.end(), tjID) != pfp.TjIDs.end())
return ipfp;
1063 for (
auto& tp : tj.
Pts) {
1064 for (
auto iht : tp.Hits) {
1076 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
1091 for (
auto& tp : tj.
Pts) {
1092 if (tp.Hits.size() > 16)
return false;
1105 unsigned short npts = tj.
EndPt[1] - tj.
EndPt[0] + 1;
1106 if (npts < 2)
return false;
1108 auto& endTp0 = tj.
Pts[tj.
EndPt[0]];
1109 auto& endTp1 = tj.
Pts[tj.
EndPt[1]];
1113 if (endTp0.AngErr == 0.1 && endTp1.AngErr != 0.1) { endTp0.AngErr = endTp1.AngErr; }
1114 else if (endTp0.AngErr != 0.1 && endTp1.AngErr == 0.1) {
1115 endTp1.AngErr = endTp0.AngErr;
1121 if (endTp0.AveChg <= 0) {
1122 unsigned short cnt = 0;
1124 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
1125 if (tj.
Pts[ipt].Chg == 0)
continue;
1126 sum += tj.
Pts[ipt].Chg;
1128 if (cnt == 4)
break;
1132 if (endTp1.AveChg <= 0 && npts < 5) endTp1.AveChg = endTp0.AveChg;
1133 if (endTp1.AveChg <= 0) {
1135 unsigned short cnt = 0;
1136 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
1137 short ipt = tj.
EndPt[1] - ii;
1139 if (tj.
Pts[ipt].Chg == 0)
continue;
1140 sum += tj.
Pts[ipt].Chg;
1142 if (cnt == 4)
break;
1143 if (ipt == 0)
break;
1152 if (npts > 2 * nPtsFit) {
1153 for (
unsigned short ipt = tj.
EndPt[0] + nPtsFit; ipt < tj.
EndPt[1] - nPtsFit; ++ipt) {
1154 auto& tp = tj.
Pts[ipt];
1155 if (tp.KinkSig < 0) tp.KinkSig =
KinkSignificance(slc, tj, ipt, nPtsFit, useChg,
false);
1162 int trID = slc.
tjs.size() + 1;
1164 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
1165 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
1166 if (tj.
Pts[ipt].UseHit[ii]) {
1167 unsigned int iht = tj.
Pts[ipt].Hits[ii];
1168 if (iht > slc.
slHits.size() - 1) {
1172 if (slc.
slHits[iht].InTraj > 0) {
1176 slc.
slHits[iht].InTraj = trID;
1182 for (
unsigned int iht = 0; iht < slc.
slHits.size(); ++iht) {
1183 if (slc.
slHits[iht].InTraj == tj.
ID) {
1185 <<
" thinks it belongs to T" << tj.
ID <<
" but it isn't in the Tj\n";
1197 slc.
tjs.push_back(tj);
1200 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
1201 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
1202 unsigned int iht = tj.
Pts[ipt].Hits[ii];
1204 std::cout <<
"Debug hit appears in trajectory w WorkID " << tj.
WorkID <<
" UseHit " 1205 << tj.
Pts[ipt].UseHit[ii] <<
"\n";
1219 unsigned short originPt,
1220 unsigned short npts,
1223 unsigned short usePar)
1230 if (originPt > tj.
Pts.size() - 1)
return;
1231 if (fitDir != 1 && fitDir != -1)
return;
1235 Fit2D(0, inPt, pErr, outVec, outVecErr, chiDOF);
1236 unsigned short cnt = 0;
1237 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
1238 unsigned short ipt = originPt + ii * fitDir;
1239 if (ipt < tj.
EndPt[0] || ipt > tj.
EndPt[1])
break;
1240 auto& tp = tj.
Pts[ipt];
1241 if (tp.Chg <= 0)
continue;
1243 inPt[0] =
std::abs(tp.Pos[0] - tj.
Pts[originPt].Pos[0]);
1244 float parVal = tp.Chg;
1246 pErr = 0.1 * parVal;
1250 pErr = sqrt(tp.HitPosErr2);
1254 if (!
Fit2D(2, inPt, pErr, outVec, outVecErr, chiDOF))
break;
1256 if (cnt == npts)
break;
1258 if (cnt < npts)
return;
1260 if (!
Fit2D(-1, inPt, pErr, outVec, outVecErr, chiDOF))
return;
1261 pFit.
Pos = tj.
Pts[originPt].Pos;
1262 pFit.
Par0 = outVec[0];
1264 pFit.
ParErr = outVecErr[0];
1265 pFit.
Pos = tj.
Pts[originPt].Pos;
1280 unsigned short itj = 0;
1281 std::vector<unsigned int> tHits;
1282 std::vector<unsigned int> atHits;
1283 for (
auto& tj : slc.
tjs) {
1285 if (tj.AlgMod[
kKilled])
continue;
1288 if (tHits.size() < 2)
continue;
1289 std::sort(tHits.begin(), tHits.end());
1291 for (iht = 0; iht < slc.
slHits.size(); ++iht) {
1292 if (slc.
slHits[iht].InTraj == tID) atHits.push_back(iht);
1294 if (atHits.size() < 2)
continue;
1295 if (!std::equal(tHits.begin(), tHits.end(), atHits.begin())) {
1297 myprt << someText <<
" ChkInTraj failed: inTraj - UseHit mis-match for T" << tID
1298 <<
" tj.WorkID " << tj.WorkID <<
" atHits size " << atHits.size() <<
" tHits size " 1299 << tHits.size() <<
" in CTP " << tj.CTP <<
"\n";
1300 myprt <<
"AlgMods: ";
1301 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
1302 if (tj.AlgMod[ib]) myprt <<
" " <<
AlgBitNames[ib];
1304 myprt <<
"index inTraj UseHit \n";
1305 for (iht = 0; iht < atHits.size(); ++iht) {
1306 myprt <<
"iht " << iht <<
" " <<
PrintHit(slc.
slHits[atHits[iht]]);
1307 if (iht < tHits.size()) myprt <<
" " <<
PrintHit(slc.
slHits[tHits[iht]]);
1308 if (atHits[iht] != tHits[iht]) myprt <<
" <<< " << atHits[iht] <<
" != " << tHits[iht];
1311 if (tHits.size() > atHits.size()) {
1312 for (iht = atHits.size(); iht < atHits.size(); ++iht) {
1313 myprt <<
"atHits " << iht <<
" " <<
PrintHit(slc.
slHits[atHits[iht]]) <<
"\n";
1320 for (
unsigned short end = 0;
end < 2; ++
end) {
1321 if (tj.VtxID[
end] > slc.
vtxs.size()) {
1322 mf::LogVerbatim(
"TC") << someText <<
" ChkInTraj: Bad VtxID " << tj.ID;
1347 if (itj > slc.
tjs.size() - 1)
return;
1348 auto& tj = slc.
tjs[itj];
1351 if (tj.EndFlag[0][
kBragg])
return;
1354 if (tj.Pts.size() < 20)
return;
1359 float chg2 = tj.Pts[tj.EndPt[0] + 2].AveChg;
1361 float chg15 = tj.Pts[tj.EndPt[0] + 15].AveChg;
1362 if (chg2 < 3 * chg15)
return;
1365 float midChg = 0.5 * (chg2 + chg15);
1367 unsigned short breakPt = USHRT_MAX;
1368 for (
unsigned short ipt = tj.EndPt[0] + 3; ipt < 15; ++ipt) {
1369 float chgm2 = tj.Pts[ipt - 2].Chg;
1370 if (chgm2 == 0)
continue;
1371 float chgm1 = tj.Pts[ipt - 1].Chg;
1372 if (chgm1 == 0)
continue;
1373 float chgp1 = tj.Pts[ipt + 1].Chg;
1374 if (chgp1 == 0)
continue;
1375 float chgp2 = tj.Pts[ipt + 2].Chg;
1376 if (chgp2 == 0)
continue;
1377 if (chgm2 > midChg && chgm1 > midChg && chgp1 < midChg && chgp2 < midChg) {
1382 if (breakPt == USHRT_MAX)
return;
1384 std::array<double, 2> cnt, sum, sum2;
1385 for (
unsigned short ipt = tj.EndPt[0]; ipt <= tj.EndPt[1]; ++ipt) {
1386 auto& tp = tj.Pts[ipt];
1387 if (tp.Chg <= 0)
continue;
1388 unsigned short end = 0;
1389 if (ipt > breakPt) end = 1;
1392 sum2[
end] += tp.Chg * tp.Chg;
1394 for (
unsigned short end = 0;
end < 2; ++
end) {
1395 if (cnt[
end] < 3)
return;
1396 double ave = sum[
end] / cnt[
end];
1397 double arg = sum2[
end] - cnt[
end] * ave * ave;
1398 if (arg <= 0)
return;
1399 sum2[
end] = sqrt(arg / (cnt[
end] - 1));
1403 bool doSplit =
true;
1406 if (tj.ChgRMS > 0.5 && sum2[0] > 0.3 && sum2[1] > 0.3) doSplit =
false;
1409 myprt <<
"CTBC: T" << tj.ID <<
" chgRMS " << tj.ChgRMS;
1410 myprt <<
" AveChg before split point " << (
int)sum[0] <<
" rms " << sum2[0];
1411 myprt <<
" after " << (
int)sum[1] <<
" rms " << sum2[1] <<
" doSplit? " << doSplit;
1413 if (!doSplit)
return;
1416 aVtx.
Pos = tj.Pts[breakPt].Pos;
1418 aVtx.
Pass = tj.Pass;
1422 aVtx.
ID = slc.
vtxs.size() + 1;
1424 unsigned short ivx = slc.
vtxs.size();
1426 if (!
SplitTraj(slc, itj, breakPt, ivx, prt)) {
1436 <<
PrintPos(slc, tj.Pts[breakPt].Pos) <<
"\n";
1446 if (itj > slc.
tjs.size() - 1)
return false;
1450 auto& tj = slc.
tjs[itj];
1452 if (npwc < 4)
return false;
1453 if (npwc < nPtsToCheck) nPtsToCheck = npwc;
1456 unsigned short maxPullPt = USHRT_MAX;
1457 for (
unsigned short ipt = tj.EndPt[0]; ipt < tj.EndPt[1]; ++ipt) {
1458 auto& tp = tj.Pts[ipt];
1459 if (tp.ChgPull < maxPull)
continue;
1460 maxPull = tp.ChgPull;
1463 if (maxPullPt == USHRT_MAX)
return false;
1465 if (maxPullPt < 0.5 * (tj.EndPt[0] + tj.EndPt[1])) { dpt = maxPullPt - tj.EndPt[0]; }
1467 dpt = tj.EndPt[1] - maxPullPt;
1469 if (dpt < 3)
return false;
1472 mf::LogVerbatim(
"TC") <<
"BS: T" << tj.ID <<
" maxPull " << maxPull <<
" at " 1473 <<
PrintPos(slc, tj.Pts[maxPullPt]) <<
" dpt " << dpt;
1474 unsigned short breakPt = USHRT_MAX;
1476 unsigned short bestBragg = 0;
1480 for (
unsigned short ipt = maxPullPt - 2; ipt <= maxPullPt + 2; ++ipt) {
1481 FitTraj(slc, tj, ipt - 1, nPtsFit, -1, tp1);
1482 if (tp1.
FitChi > 10)
continue;
1483 FitTraj(slc, tj, ipt + 1, nPtsFit, 1, tp2);
1484 if (tp2.
FitChi > 10)
continue;
1486 FitPar(slc, tj, ipt - 1, nPtsToCheck, -1, chgFit1, 1);
1487 if (chgFit1.
ChiDOF > 100)
continue;
1489 FitPar(slc, tj, ipt + 1, nPtsToCheck, 1, chgFit2, 1);
1490 if (chgFit2.
ChiDOF > 100)
continue;
1495 unsigned short bragg = 1;
1496 float bchi = chgFit1.
ChiDOF;
1503 if (bchi < 1) bchi = 1;
1504 float fom = 10 * dang * chgAsym * slpAsym / bchi;
1508 myprt <<
" chg1 " << (
int)chgFit1.
Par0 <<
" slp " << chgFit1.
ParSlp <<
" chi " 1510 myprt <<
" chg2 " << (
int)chgFit2.
Par0 <<
" slp " << chgFit2.
ParSlp <<
" chi " 1512 myprt <<
" chgAsym " << chgAsym;
1513 myprt <<
" slpAsym " << slpAsym;
1514 myprt <<
" fom " << fom;
1515 myprt <<
" bragg " << bragg;
1517 if (fom < bestFOM)
continue;
1522 if (breakPt == USHRT_MAX)
return false;
1528 aVtx.
Pos = tj.Pts[breakPt].Pos;
1530 aVtx.
Pass = tj.Pass;
1534 aVtx.
ID = slc.
vtxs.size() + 1;
1536 unsigned short ivx = slc.
vtxs.size();
1538 if (!
SplitTraj(slc, itj, breakPt, ivx, prt)) {
1545 unsigned short otj = slc.
tjs.size() - 1;
1546 if (bestBragg == 2)
std::swap(itj, otj);
1547 slc.
tjs[itj].PDGCode = 211;
1549 slc.
tjs[otj].PDGCode = 13;
1560 if (tj.
PDGCode == 111)
return;
1563 if (npwc < 50)
return;
1569 if (nPtsMax > 8) nPtsMax = 8;
1574 unsigned short firstBad = USHRT_MAX;
1575 for (
unsigned short ii = 0; ii < nPtsMax; ++ii) {
1576 unsigned short ipt = tj.
EndPt[1] - nPtsMax + ii;
1577 auto& tp = tj.
Pts[ipt];
1578 if (tp.Chg <= 0)
continue;
1579 if (tp.ChgPull < 3)
continue;
1581 if (firstBad == USHRT_MAX) firstBad = ipt;
1583 if (firstBad == USHRT_MAX)
return;
1585 float cntTot = tj.
EndPt[1] - firstBad;
1587 float fracBad = cntBad / cntTot;
1588 if (fracBad < 0.5)
return;
1591 for (
unsigned short ipt = firstBad; ipt <= tj.
EndPt[1]; ++ipt)
1601 const std::vector<float>& fQualityCuts,
1614 if (tj.
PDGCode == 111)
return;
1618 short minPts = fQualityCuts[1];
1619 if (minPts < 1)
return;
1620 if (npwc < minPts)
return;
1622 if (npwc < 8)
return;
1625 if (npwc == minPts + 1) {
1626 unsigned short endPt1 = tj.
EndPt[1];
1627 auto& tp = tj.
Pts[endPt1];
1628 auto& ptp = tj.
Pts[endPt1 - 1];
1631 float dwire =
std::abs(ptp.Pos[0] - tp.Pos[0]);
1632 if (ptp.Chg == 0 || dwire > 1.1) {
1642 for (lastPt = tj.
EndPt[1]; lastPt >= minPts; --lastPt) {
1644 if (lastPt == 1)
break;
1645 if (tj.
Pts[lastPt].Chg == 0)
continue;
1647 unsigned short nadj = 0;
1648 unsigned short npwc = 0;
1649 for (
short ipt = lastPt - minPts; ipt < lastPt; ++ipt) {
1652 auto& tp = tj.
Pts[ipt];
1654 auto& ptp = tj.
Pts[ipt - 1];
1655 if (tp.Chg > 0 && ptp.Chg > 0) {
1657 if (
std::abs(tp.Pos[0] - ptp.Pos[0]) < 1.5) ++nadj;
1662 float hitFrac = ntpwc /
nwires;
1664 mf::LogVerbatim(
"TC") << fcnLabel <<
"-TEP: T" << tj.
ID <<
" lastPt " << lastPt <<
" npwc " 1665 << npwc <<
" ntpwc " << ntpwc <<
" nadj " << nadj <<
" hitFrac " 1667 if (hitFrac > fQualityCuts[0] && npwc == minPts && nadj >= minPts - 1)
break;
1672 if (tj.
Pts[lastPt].Pos[0] > -0.4) {
1673 unsigned int prevWire = std::nearbyint(tj.
Pts[lastPt].Pos[0]);
1674 if (tj.
StepDir > 0) { --prevWire; }
1679 mf::LogVerbatim(
"TC") << fcnLabel <<
"-TEP: is prevWire " << prevWire <<
" dead? ";
1686 if (lastPt == tj.
EndPt[1]) {
1692 for (
unsigned short ipt = lastPt + 1; ipt <= tj.
EndPt[1]; ++ipt)
1697 fcnLabel +=
"-TEPo";
1709 if (tj.
PDGCode == 111)
return;
1715 unsigned short withNptsFit = 0;
1718 for (
unsigned short nptsf = 3; nptsf < nPtsFit; ++nptsf) {
1719 unsigned short ipt = tj.
EndPt[1] - nptsf;
1723 withNptsFit = nptsf;
1726 if (withNptsFit > 0) {
1727 unsigned short ipt = tj.
EndPt[1] - withNptsFit;
1728 std::cout <<
"CEK: T" << tj.
ID <<
" ipt " << ipt;
1730 auto& tp = tj.
Pts[ipt];
1731 std::cout <<
" " <<
PrintPos(slc, tp) <<
" withNptsFit " << withNptsFit <<
" ks " << ks
1746 if (tj.
PDGCode == 111)
return;
1747 unsigned short npts = tj.
EndPt[1] - tj.
EndPt[0];
1750 if (npts > 50)
return;
1752 if (npts < 8)
return;
1755 unsigned short atPt = 0;
1757 for (
unsigned short ipt = tj.
EndPt[0] + 2; ipt <= tj.
EndPt[1] - 2; ++ipt) {
1758 auto& tp = tj.
Pts[ipt];
1759 if (tp.ChgPull > bigPull) {
1760 bigPull = tp.ChgPull;
1764 if (atPt == 0)
return;
1766 if ((atPt - tj.
EndPt[0]) < 0.5 * npts)
return;
1769 <<
". Check charge asymmetry around it.";
1770 unsigned short nchk = 0;
1771 unsigned short npos = 0;
1772 unsigned short nneg = 0;
1773 for (
short ii = 1; ii < 5; ++ii) {
1774 short iplu = atPt + ii;
1775 if (iplu > tj.
EndPt[1])
break;
1776 short ineg = atPt - ii;
1777 if (ineg < tj.
EndPt[0])
break;
1778 if (tj.
Pts[iplu].Chg == 0)
continue;
1779 if (tj.
Pts[ineg].Chg == 0)
continue;
1780 float asym = (tj.
Pts[iplu].Chg - tj.
Pts[ineg].Chg) / (tj.
Pts[iplu].Chg + tj.
Pts[ineg].Chg);
1782 if (asym > 0.5) ++npos;
1783 if (asym < -0.5) ++nneg;
1785 mf::LogVerbatim(
"TC") <<
" ineg " << ineg <<
" iplu " << iplu <<
" asym " << asym
1786 <<
" nchk " << nchk;
1788 if (nchk < 3)
return;
1791 bool doTrim = (nneg > nchk) || (npos > nchk);
1792 if (!doTrim)
return;
1794 auto& prevTP = tj.
Pts[atPt - 1];
1795 if (
std::abs(prevTP.ChgPull) > 2) --atPt;
1796 for (
unsigned short ipt = atPt; ipt <= tj.
EndPt[1]; ++ipt)
1808 const float& MinWireSignalFraction)
1811 if (MinWireSignalFraction == 0)
return true;
1813 if (tp1.
Pos[0] < -0.4 || tp2.
Pos[0] < -0.4)
return false;
1814 int fromWire = std::nearbyint(tp1.
Pos[0]);
1815 int toWire = std::nearbyint(tp2.
Pos[0]);
1817 if (fromWire == toWire) {
1820 tp.
Pos[1] = 0.5 * (tp1.
Pos[1] + tp2.
Pos[1]);
1826 return SignalBetween(slc, tp, toWire, MinWireSignalFraction);
1844 if (tp.
Pos[0] < -0.4 || toPos0 < -0.4)
return 0;
1845 int fromWire = std::nearbyint(tp.
Pos[0]);
1846 int toWire = std::nearbyint(toPos0);
1848 if (fromWire == toWire)
return SignalAtTp(tp);
1850 int nWires =
abs(toWire - fromWire) + 1;
1855 if (toWire > fromWire && tp.
Dir[0] < 0) stepSize = -stepSize;
1856 if (toWire < fromWire && tp.
Dir[0] > 0) stepSize = -stepSize;
1859 for (
unsigned short cnt = 0; cnt < nWires; ++cnt) {
1862 tp.
Pos[0] += tp.
Dir[0] * stepSize;
1863 tp.
Pos[1] += tp.
Dir[1] * stepSize;
1865 float sigFrac = nsig /
num;
1872 const std::vector<unsigned int>& iHitsInMultiplet,
1873 const std::vector<unsigned int>& jHitsInMultiplet)
1877 if (iHitsInMultiplet.empty() || jHitsInMultiplet.empty())
return false;
1881 if (cvI < 0)
return false;
1884 for (
auto& iht : iHitsInMultiplet) {
1886 float cv =
hit.PeakTime();
1888 float arg = cv - 3.1 *
rms;
1889 if (arg < minI) minI = arg;
1890 arg = cv + 3.1 *
rms;
1891 if (arg > maxI) maxI = arg;
1895 if (cvJ < 0)
return false;
1898 for (
auto& jht : jHitsInMultiplet) {
1900 float cv =
hit.PeakTime();
1902 float arg = cv - 3.1 *
rms;
1903 if (arg < minJ) minJ = arg;
1904 arg = cv + 3.1 *
rms;
1905 if (arg > maxJ) maxJ = arg;
1909 if (maxI > minJ)
return true;
1912 if (minI < maxJ)
return true;
1922 if (iht > slc.
slHits.size() - 1)
return false;
1923 if (jht > slc.
slHits.size() - 1)
return false;
1927 int iwire = ihit.WireID().Wire;
1928 int jwire = jhit.WireID().Wire;
1929 if (
std::abs(iwire - jwire) > 1)
return false;
1930 if (ihit.PeakTime() > jhit.PeakTime()) {
1931 float minISignal = ihit.PeakTime() - 3 * ihit.RMS();
1932 float maxJSignal = jhit.PeakTime() + 3 * ihit.RMS();
1933 if (maxJSignal > minISignal)
return true;
1936 float maxISignal = ihit.PeakTime() + 3 * ihit.RMS();
1937 float minJSignal = jhit.PeakTime() - 3 * ihit.RMS();
1938 if (minJSignal > maxISignal)
return true;
1964 if (tp.
Pos[0] < -0.4)
return false;
1966 unsigned short pln = planeID.
Plane;
1967 unsigned int wire = std::nearbyint(tp.
Pos[0]);
1968 if (wire >
evt.
goodWire[pln].size() - 1)
return false;
1972 if (slc.
wireHitRange[pln][wire].first == UINT_MAX)
return false;
1975 float tickRange = 0;
1979 if (tickRange > 40) tickRange = 40;
1981 float loTpTick = projTick - tickRange;
1982 float hiTpTick = projTick + tickRange;
1983 for (
unsigned int iht = slc.
wireHitRange[pln][wire].first;
1986 unsigned int ahi = slc.
slHits[iht].allHitsIndex;
1988 if (projTick <
hit.PeakTime()) {
1989 float loHitTick =
hit.PeakTime() - 3 *
hit.RMS();
1990 if (hiTpTick > loHitTick)
return true;
1993 float hiHitTick =
hit.PeakTime() + 3 *
hit.RMS();
1994 if (loTpTick < hiHitTick)
return true;
2015 if (tp.
Pos[0] < -0.4)
return false;
2017 unsigned short pln = planeID.
Plane;
2018 unsigned int wire = std::nearbyint(tp.
Pos[0]);
2019 if (wire >
evt.
goodWire[pln].size() - 1)
return false;
2025 float tickRange = 0;
2029 if (tickRange > 40) tickRange = 40;
2031 float loTpTick = projTick - tickRange;
2032 float hiTpTick = projTick + tickRange;
2042 const auto& wid =
hit.WireID();
2043 if (wid.Cryostat != planeID.
Cryostat)
continue;
2044 if (wid.TPC != planeID.
TPC)
continue;
2045 if (wid.Plane != planeID.
Plane)
continue;
2046 if (projTick <
hit.PeakTime()) {
2047 float loHitTick =
hit.PeakTime() - 3 *
hit.RMS();
2048 if (hiTpTick > loHitTick)
return true;
2051 float hiHitTick =
hit.PeakTime() + 3 *
hit.RMS();
2052 if (loTpTick < hiHitTick)
return true;
2074 unsigned int pln = plnID.
Plane;
2075 if (pln == 2)
return false;
2077 unsigned int cstat = plnID.
Cryostat;
2078 unsigned int tpc = plnID.
TPC;
2083 float atTick = 0.5 * (loTick + hiTick);
2087 if (
hit.Channel() != chan)
continue;
2088 if (atTick <
hit.PeakTime()) {
2089 float loHitTick =
hit.PeakTime() - 3 *
hit.RMS();
2090 if (hiTick > loHitTick)
return true;
2093 float hiHitTick =
hit.PeakTime() + 3 *
hit.RMS();
2094 if (loTick < hiHitTick)
return true;
2105 for (
size_t i = 0; i < tp.
Hits.size(); ++i) {
2106 if (!tp.
UseHit[i])
continue;
2116 unsigned short firstPt = tj.
EndPt[0];
2117 unsigned short lastPt = tj.
EndPt[1];
2125 bool includeDeadWires,
2126 unsigned short firstPt,
2127 unsigned short lastPt)
2129 unsigned short ntp = 0;
2130 for (
unsigned short ipt = firstPt; ipt <= lastPt; ++ipt)
2131 if (tj.
Pts[ipt].Chg > 0) ++ntp;
2148 if (inWirePos1 < -0.4 || inWirePos2 < -0.4)
return 0;
2149 unsigned int inWire1 = std::nearbyint(inWirePos1);
2150 unsigned int inWire2 = std::nearbyint(inWirePos2);
2152 unsigned short plane = planeID.
Plane;
2153 if (inWire1 > slc.
nWires[plane] || inWire2 > slc.
nWires[plane])
return 0;
2154 if (inWire1 > inWire2) {
2156 unsigned int tmp = inWire1;
2161 unsigned int wire, ndead = 0;
2162 for (wire = inWire1; wire < inWire2; ++wire)
2171 unsigned short pdg =
abs(PDGCode);
2172 if (pdg == 11)
return 0;
2173 if (pdg == 13)
return 1;
2174 if (pdg == 211)
return 2;
2175 if (pdg == 321)
return 3;
2176 if (pdg == 2212)
return 4;
2186 if (itj > slc.
tjs.size() - 1)
return;
2187 int killTjID = slc.
tjs[itj].ID;
2189 if (
hit.InTraj == killTjID)
hit.InTraj = 0;
2197 if (itj > slc.
tjs.size() - 1)
return;
2200 <<
"RestoreObsoleteTrajectory: Trying to restore not-obsolete trajectory " 2205 for (
auto& tp : slc.
tjs[itj].Pts) {
2206 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
2207 if (tp.UseHit[ii]) {
2209 if (slc.
slHits[iht].InTraj == 0) { slc.
slHits[iht].InTraj = slc.
tjs[itj].ID; }
2223 for (
auto& shortTj : slc.
tjs) {
2224 if (shortTj.AlgMod[
kKilled] || shortTj.AlgMod[
kHaloTj])
continue;
2225 if (shortTj.CTP != inCTP)
continue;
2226 unsigned short spts = shortTj.EndPt[1] - shortTj.EndPt[0];
2227 if (spts > 20)
continue;
2229 if (shortTj.PDGCode == 11)
continue;
2231 if (shortTj.SSID > 0)
continue;
2233 if (tjhits.empty())
continue;
2234 std::vector<int> tids;
2235 std::vector<unsigned short> tcnt;
2236 for (
auto iht : tjhits) {
2238 if (
hit.InTraj <= 0)
continue;
2239 if ((
unsigned int)
hit.InTraj > slc.
tjs.size())
continue;
2240 if (
hit.InTraj == shortTj.ID)
continue;
2241 unsigned short indx = 0;
2242 for (indx = 0; indx < tids.size(); ++indx)
2243 if (
hit.InTraj == tids[indx])
break;
2244 if (indx == tids.size()) {
2245 tids.push_back(
hit.InTraj);
2252 if (tids.empty())
continue;
2254 unsigned short maxcnt = 0;
2255 for (
unsigned short indx = 0; indx < tids.size(); ++indx) {
2256 if (tcnt[indx] > maxcnt) {
2257 auto& ltj = slc.
tjs[tids[indx] - 1];
2258 unsigned short lpts = ltj.EndPt[1] - ltj.EndPt[0];
2259 if (lpts < spts)
continue;
2260 maxcnt = tcnt[indx];
2263 float hitFrac = (
float)maxcnt / (
float)tjhits.size();
2264 if (hitFrac < 0.1)
continue;
2279 if (itj > slc.
tjs.size() - 1)
return false;
2281 auto& tj = slc.
tjs[itj];
2284 unsigned short atPt = USHRT_MAX;
2285 for (
unsigned short ipt = tj.EndPt[0] + 1; ipt <= tj.EndPt[1]; ++ipt) {
2286 if (tj.Pts[ipt].Pos[1] > tj.Pts[ipt - 1].Pos[1]) {
2288 if (tj.Pts[ipt - 1].Pos[1] < atPos1 && tj.Pts[ipt].Pos[1] >= atPos1) {
2295 if (tj.Pts[ipt - 1].Pos[1] >= atPos1 && tj.Pts[ipt].Pos[1] < atPos1) {
2301 if (atPt == USHRT_MAX)
return false;
2302 unsigned short vx2Index = USHRT_MAX;
2305 newVx2.
CTP = tj.CTP;
2306 newVx2.
Pos[0] = 0.5 * (tj.Pts[atPt - 1].Pos[0] + tj.Pts[atPt].Pos[0]);
2307 newVx2.
Pos[1] = 0.5 * (tj.Pts[atPt - 1].Pos[1] + tj.Pts[atPt].Pos[1]);
2312 return SplitTraj(slc, itj, atPt, vx2Index, prt);
2324 if (itj > slc.
tjs.size() - 1)
return false;
2325 if (pos < slc.
tjs[itj].EndPt[0] + 1 || pos > slc.
tjs[itj].EndPt[1] - 1)
return false;
2326 if (ivx != USHRT_MAX && ivx > slc.
vtxs.size() - 1)
return false;
2331 bool splittingMuon = (tj.
PDGCode == 13);
2332 if (splittingMuon) tj.
PDGCode = 0;
2336 myprt <<
"SplitTraj: Split T" << tj.
ID <<
" at point " <<
PrintPos(slc, tj.
Pts[pos]);
2337 if (ivx < slc.
vtxs.size()) myprt <<
" with Vtx 2V" << slc.
vtxs[ivx].ID;
2341 unsigned short ntp = 0;
2342 for (
unsigned short ipt = 0; ipt <=
pos; ++ipt) {
2343 if (tj.
Pts[ipt].Chg > 0) ++ntp;
2347 if (prt)
mf::LogVerbatim(
"TC") <<
" Split point to small at begin " << ntp <<
" pos " <<
pos;
2351 for (
unsigned short ipt = pos + 1; ipt <= tj.
EndPt[1]; ++ipt) {
2352 if (tj.
Pts[ipt].Chg > 0) ++ntp;
2357 mf::LogVerbatim(
"TC") <<
" Split point too small at end " << ntp <<
" pos " << pos
2358 <<
" EndPt " << tj.
EndPt[1];
2364 newTj.
ID = slc.
tjs.size() + 1;
2373 for (
unsigned short ipt = pos + 1; ipt <= tj.
EndPt[1]; ++ipt) {
2374 tj.
Pts[ipt].Chg = 0;
2375 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
2376 if (!tj.
Pts[ipt].UseHit[ii])
continue;
2377 iht = tj.
Pts[ipt].Hits[ii];
2379 if (slc.
slHits[iht].InTraj != tj.
ID)
continue;
2381 tj.
Pts[ipt].UseHit[ii] =
false;
2393 unsigned short eraseSize = pos - 2;
2394 if (eraseSize > newTj.
Pts.size() - 1) {
2407 newTj.
Pts.erase(newTj.
Pts.begin(), newTj.
Pts.begin() + eraseSize);
2409 for (
unsigned short ipt = 0; ipt < 3; ++ipt) {
2410 for (
unsigned short ii = 0; ii < newTj.
Pts[ipt].Hits.size(); ++ii)
2411 newTj.
Pts[ipt].UseHit[ii] =
false;
2412 newTj.
Pts[ipt].Chg = 0;
2418 if (ivx < slc.
vtxs.size()) newTj.
VtxID[0] = slc.
vtxs[ivx].ID;
2421 slc.
tjs.push_back(newTj);
2436 unsigned short& closePt,
2440 float best = minSep * minSep;
2441 closePt = USHRT_MAX;
2444 for (ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
2445 dw = tj.
Pts[ipt].Pos[0] - tp.
Pos[0];
2446 dt = tj.
Pts[ipt].Pos[1] - tp.
Pos[1];
2447 dp2 = dw * dw + dt * dt;
2453 minSep = sqrt(best);
2461 unsigned short& ipt1,
2462 unsigned short& ipt2,
2465 return TrajTrajDOCA(slc, tj1, tj2, ipt1, ipt2, minSep,
false);
2473 unsigned short& ipt1,
2474 unsigned short& ipt2,
2476 bool considerDeadWires)
2481 for (
unsigned short iwt = 0; iwt < 2; ++iwt) {
2484 float wt0 = tj1.
Pts[tj1.
EndPt[0]].Pos[iwt];
2485 float wt1 = tj1.
Pts[tj1.
EndPt[1]].Pos[iwt];
2493 wt0 = tj2.
Pts[tj2.
EndPt[0]].Pos[iwt];
2494 wt1 = tj2.
Pts[tj2.
EndPt[1]].Pos[iwt];
2504 if (lowt2 > hiwt1 + minSep)
return false;
2506 if (lowt1 > hiwt2 + minSep)
return false;
2509 float best = minSep * minSep;
2513 bool isClose =
false;
2514 for (
unsigned short i1 = tj1.
EndPt[0]; i1 < tj1.
EndPt[1] + 1; ++i1) {
2515 for (
unsigned short i2 = tj2.
EndPt[0]; i2 < tj2.
EndPt[1] + 1; ++i2) {
2517 float dw = tj1.
Pts[i1].Pos[0] - tj2.
Pts[i2].Pos[0] - dwc;
2518 if (
std::abs(dw) > minSep)
continue;
2519 float dt = tj1.
Pts[i1].Pos[1] - tj2.
Pts[i2].Pos[1];
2520 if (
std::abs(dt) > minSep)
continue;
2521 float dp2 = dw * dw + dt * dt;
2530 minSep = sqrt(best);
2539 if (iht > slc.
slHits.size() - 1 || jht > slc.
slHits.size() - 1)
return 1E6;
2542 float dw = (
float)ihit.WireID().Wire - (
float)jhit.WireID().Wire;
2544 return dw * dw + dt * dt;
2551 unsigned short endPt = tj.
EndPt[0];
2552 auto& tp0 = tj.
Pts[endPt];
2553 endPt = tj.
EndPt[1];
2554 auto& tp1 = tj.
Pts[endPt];
2563 float dw = wire - tp.
Pos[0];
2564 float dt = time - tp.
Pos[1];
2565 return dw * dw + dt * dt;
2572 if (iht > slc.
slHits.size() - 1)
return 1E6;
2574 float wire =
hit.WireID().Wire;
2593 double t = (double)(wire - tp.
Pos[0]) * tp.
Dir[0] + (double)(time - tp.
Pos[1]) * tp.
Dir[1];
2594 double dw = tp.
Pos[0] + t * tp.
Dir[0] - wire;
2595 double dt = tp.
Pos[1] + t * tp.
Dir[1] - time;
2596 return (
float)(dw * dw + dt * dt);
2615 double arg1 = tp1.
Pos[0] * tp1.
Dir[1] - tp1.
Pos[1] * tp1.
Dir[0];
2616 double arg2 = tp2.
Pos[0] * tp1.
Dir[1] - tp2.
Pos[1] * tp1.
Dir[0];
2617 double arg3 = tp2.
Dir[0] * tp1.
Dir[1] - tp2.
Dir[1] * tp1.
Dir[0];
2618 if (arg3 == 0)
return;
2619 double s = (arg1 - arg2) / arg3;
2631 if (tjIDs.empty())
return 0;
2633 for (
auto tjid : tjIDs) {
2634 if (tjid < 1 || tjid > (
int)slc.
tjs.size())
continue;
2635 auto& tj = slc.
tjs[tjid - 1];
2636 float sep2 =
PosSep2(tj.Pts[tj.EndPt[0]].Pos, tj.Pts[tj.EndPt[1]].Pos);
2637 if (sep2 > maxLen) maxLen = sep2;
2639 return sqrt(maxLen);
2646 float len = 0, dx, dy;
2648 unsigned short prevPt = tj.
EndPt[0];
2649 for (ipt = tj.
EndPt[0] + 1; ipt < tj.
EndPt[1] + 1; ++ipt) {
2650 if (tj.
Pts[ipt].Chg == 0)
continue;
2651 dx = tj.
Pts[ipt].Pos[0] - tj.
Pts[prevPt].Pos[0];
2652 dy = tj.
Pts[ipt].Pos[1] - tj.
Pts[prevPt].Pos[1];
2653 len += sqrt(dx * dx + dy * dy);
2663 return sqrt(
PosSep2(pos1, pos2));
2671 float d0 = pos1[0] - pos2[0];
2672 float d1 = pos1[1] - pos2[1];
2673 return d0 * d0 + d1 * d1;
2681 float dx = tp1.
Pos[0] - tp2.
Pos[0];
2682 float dy = tp1.
Pos[1] - tp2.
Pos[1];
2683 return sqrt(dx * dx + dy * dy);
2694 float close2 = DOCA * DOCA;
2696 bool foundClose =
false;
2698 for (
unsigned short ipt = tj.
EndPt[0]; ipt < tj.
EndPt[1] + 1; ++ipt) {
2699 if (tj.
Pts[ipt].Chg == 0)
continue;
2700 float dx = tj.
Pts[ipt].Pos[0] -
x;
2702 float dy = tj.
Pts[ipt].Pos[1] -
y;
2704 float sep2 = dx * dx + dy * dy;
2705 if (sep2 < close2) {
2712 DOCA = sqrt(close2);
2722 float dw = tp2.
Pos[0] - tp1.
Pos[0];
2723 float dt = tp2.
Pos[1] - tp1.
Pos[1];
2724 return atan2(dw, dt);
2728 std::vector<unsigned int>
2732 std::vector<unsigned int> hitVec;
2733 if (pfp.
TP3Ds.empty())
return hitVec;
2735 for (
auto& tp3d : pfp.
TP3Ds) {
2736 if (tp3d.Flags[
kTP3DBad])
continue;
2737 if (tp3d.TjID <= 0)
continue;
2738 auto& tp = slc.
tjs[tp3d.TjID - 1].Pts[tp3d.TPIndex];
2739 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
2740 unsigned int iht = tp.Hits[ii];
2741 bool useit = (hitRequest ==
kAllHits);
2742 if (tp.UseHit[ii] && hitRequest ==
kUsedHits) useit =
true;
2743 if (!tp.UseHit[ii] && hitRequest ==
kUnusedHits) useit =
true;
2744 if (useit) hitVec.push_back(iht);
2751 std::vector<unsigned int>
2755 std::vector<unsigned int> hitVec;
2759 for (
auto& tp : tj.
Pts)
2760 hitVec.insert(hitVec.end(), tp.Hits.begin(), tp.Hits.end());
2765 hitVec.reserve(tj.
Pts.size());
2766 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
2767 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
2768 unsigned int iht = tj.
Pts[ipt].Hits[ii];
2769 bool useit = (hitRequest ==
kAllHits);
2770 if (tj.
Pts[ipt].UseHit[ii] && hitRequest ==
kUsedHits) useit =
true;
2771 if (!tj.
Pts[ipt].UseHit[ii] && hitRequest ==
kUnusedHits) useit =
true;
2772 if (useit) hitVec.push_back(iht);
2787 if (tj.
Pts.size() > 10)
return;
2788 if (tj.
PDGCode == 111)
return;
2790 unsigned short nhm = 0;
2791 unsigned short npwc = 0;
2792 for (
auto& tp : tj.
Pts) {
2793 if (tp.Chg == 0)
continue;
2795 unsigned short nused = 0;
2796 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
2797 if (tp.UseHit[ii]) ++nused;
2799 if (nused > 3) ++nhm;
2804 mf::LogVerbatim(
"TC") <<
"TGT: T" << tj.
ID <<
" npwc " << npwc <<
" nhm " << nhm <<
" junk? " 2814 for (
unsigned short ii = 0; ii < tjHits.size() - 1; ++ii) {
2815 for (
unsigned short jj = ii + 1; jj < tjHits.size(); ++jj) {
2816 if (tjHits[ii] == tjHits[jj]) {
2832 if (tp.
Dir[0] == 0)
return;
2833 float dw = wire - tp.
Pos[0];
2836 tp.
Pos[1] += dw * tp.
Dir[1] / tp.
Dir[0];
2840 std::vector<unsigned int>
2842 std::array<int, 2>
const& wireWindow,
2844 const unsigned short plane,
2863 std::vector<unsigned int> closeHits;
2864 if (plane > slc.
firstWire.size() - 1)
return closeHits;
2866 int loWire = wireWindow[0];
2868 int hiWire = wireWindow[1];
2873 for (
int wire = loWire; wire <= hiWire; ++wire) {
2876 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
continue;
2877 unsigned int firstHit = slc.
wireHitRange[plane][wire].first;
2878 unsigned int lastHit = slc.
wireHitRange[plane][wire].second;
2879 for (
unsigned int iht = firstHit; iht <= lastHit; ++iht) {
2882 if (
hit.PeakTime() < minTick)
continue;
2883 if (
hit.PeakTime() > maxTick)
break;
2887 if (
hit.StartTick() > hiLo) hiLo =
hit.StartTick();
2889 if (
hit.EndTick() < loHi) loHi =
hit.EndTick();
2890 if (loHi < hiLo)
continue;
2891 if (hiLo > loHi)
break;
2894 bool takeit = (hitRequest ==
kAllHits);
2895 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) takeit =
true;
2897 if (takeit) closeHits.push_back(iht);
2915 if (tp.
Pos[0] < -0.4)
return false;
2917 unsigned int wire = std::nearbyint(tp.
Pos[0]);
2918 if (wire < slc.
firstWire[plane])
return false;
2919 if (wire > slc.
lastWire[plane] - 1)
return false;
2928 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
return false;
2930 unsigned int firstHit = slc.
wireHitRange[plane][wire].first;
2931 unsigned int lastHit = slc.
wireHitRange[plane][wire].second;
2934 for (
unsigned int iht = firstHit; iht <= lastHit; ++iht) {
2935 if ((
unsigned int)slc.
slHits[iht].InTraj > slc.
tjs.size())
continue;
2936 bool useit = (hitRequest ==
kAllHits);
2937 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) useit =
true;
2939 if (!useit)
continue;
2943 if (delta < maxDelta) tp.
Hits.push_back(iht);
2945 if (tp.
Hits.size() > 16) { tp.
Hits.resize(16); }
2948 return (!tp.
Hits.empty());
2961 if (end > 1)
return USHRT_MAX;
2963 if (end == 1) dir = -1;
2964 for (
short ii = 0; ii < (short)tj.
Pts.size(); ++ii) {
2965 short ipt = tj.
EndPt[
end] + dir * ii;
2966 if (ipt < 0 || ipt >= (
short)tj.
Pts.size())
return USHRT_MAX;
2967 auto& tp = tj.
Pts[ipt];
2978 const float& maxDelta)
2996 std::vector<int>
tmp;
2997 if (fromTp.
Pos[0] < -0.4 || toTp.
Pos[0] < -0.4)
return tmp;
3001 unsigned int firstWire, lastWire;
3002 if (toTp.
Pos[0] > fromTp.
Pos[0]) {
3004 firstWire = std::nearbyint(fromTp.
Pos[0]);
3005 lastWire = std::nearbyint(toTp.
Pos[0]);
3007 else if (toTp.
Pos[0] < fromTp.
Pos[0]) {
3009 firstWire = std::nearbyint(toTp.
Pos[0]);
3010 lastWire = std::nearbyint(fromTp.
Pos[0]);
3014 float tmp = fromTp.
Pos[0] - maxDelta;
3015 if (tmp < 0) tmp = 0;
3016 firstWire = std::nearbyint(tmp);
3017 tmp = fromTp.
Pos[0] + maxDelta;
3018 lastWire = std::nearbyint(tmp);
3024 if (firstWire > slc.
lastWire[plane] - 1)
return tmp;
3026 if (lastWire > slc.
lastWire[plane] - 1) lastWire = slc.
lastWire[plane] - 1;
3028 for (
unsigned int wire = firstWire; wire <= lastWire; ++wire) {
3029 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
continue;
3034 unsigned int firstHit = slc.
wireHitRange[plane][wire].first;
3035 unsigned int lastHit = slc.
wireHitRange[plane][wire].second;
3036 for (
unsigned int iht = firstHit; iht <= lastHit; ++iht) {
3037 if (slc.
slHits[iht].InTraj <= 0)
continue;
3038 if ((
unsigned int)slc.
slHits[iht].InTraj > slc.
tjs.size())
continue;
3040 if (
hit.PeakTime() < minTick)
continue;
3042 if (
hit.PeakTime() > maxTick)
break;
3043 if (std::find(tmp.begin(), tmp.end(), slc.
slHits[iht].InTraj) != tmp.end())
continue;
3044 tmp.push_back(slc.
slHits[iht].InTraj);
3056 unsigned short end1,
3058 unsigned short end2,
3059 unsigned short nPtsFit,
3066 if (tj1.
CTP != tj2.
CTP)
return -1;
3067 if (end1 > 1 || end2 > 1)
return -1;
3075 if (end1 == 1) dir = -1;
3076 unsigned short cnt = 0;
3078 for (
short ii = 0; ii < (short)tj1.
Pts.size(); ++ii) {
3079 short ipt = tj1.
EndPt[end1] + dir * ii;
3081 if (ipt >= (
short)tj1.
Pts.size())
break;
3082 auto& tp = tj1.
Pts[ipt];
3083 if (tp.Chg <= 0)
continue;
3084 tj.
Pts.push_back(tp);
3086 if (cnt == nPtsFit + 1)
break;
3088 if (cnt < nPtsFit)
return -1;
3091 if (end2 == 1) dir = -1;
3093 for (
short ii = 0; ii < (short)tj2.
Pts.size(); ++ii) {
3094 short ipt = tj2.
EndPt[end2] + dir * ii;
3096 if (ipt >= (
short)tj2.
Pts.size())
break;
3097 auto& tp = tj2.
Pts[ipt];
3098 if (tp.Chg <= 0)
continue;
3099 tj.
Pts.push_back(tp);
3101 if (cnt == nPtsFit + 1)
break;
3112 unsigned short kinkPt,
3113 unsigned short nPtsFit,
3122 if (kinkPt < tj.
EndPt[0] + 2)
return -1;
3123 if (kinkPt > tj.
EndPt[1] - 2)
return -1;
3126 if (nPtsFit < 3)
return -1;
3129 if (npwc < 2 * nPtsFit + 1)
return -1;
3134 double chgRMS = 0.07;
3138 double tFactor = 1 + 0.3 / double(nPtsFit - 2);
3144 FitTraj(slc, tj, kinkPt, nPtsFit, fitDir, tpPos);
3145 if (tpPos.
FitChi > 900)
return -1;
3149 FitTraj(slc, tj, kinkPt, nPtsFit, fitDir, tpNeg);
3150 if (tpNeg.
FitChi > 900)
return -1;
3151 double angErr = tpNeg.
AngErr;
3155 double dangSig = dang / angErr;
3162 unsigned short cntNeg = 0;
3163 for (
unsigned short ipt = kinkPt - 1; ipt >= tj.
EndPt[0]; --ipt) {
3164 auto& tp = tj.
Pts[ipt];
3165 if (tp.Chg <= 0)
continue;
3168 if (cntNeg == nPtsFit)
break;
3169 if (ipt == 0)
break;
3171 if (cntNeg != nPtsFit) {
3172 if (prt)
mf::LogVerbatim(
"TC") <<
" KL: Bad cntNeg " << cntNeg <<
" != " << nPtsFit;
3177 unsigned short cntPos = 0;
3178 for (
unsigned short ipt = kinkPt + 1; ipt <= tj.
EndPt[1]; ++ipt) {
3179 auto& tp = tj.
Pts[ipt];
3180 if (tp.Chg <= 0)
continue;
3183 if (cntPos == nPtsFit)
break;
3185 if (cntPos != nPtsFit) {
3186 if (prt)
mf::LogVerbatim(
"TC") <<
" KL: Bad cntPos " << cntPos <<
" != " << nPtsFit;
3189 chgNeg /= (
float)nPtsFit;
3190 chgPos /= (
float)nPtsFit;
3192 chgAsym =
std::abs(chgPos - chgNeg) / (chgPos + chgNeg);
3194 chgSig = chgAsym / chgRMS;
3196 double kinkSig = sqrt(dangSig * dangSig + chgSig * chgSig);
3200 myprt <<
"KL: T" << tj.
ID <<
" kinkPt " <<
PrintPos(slc, tj.
Pts[kinkPt]);
3201 myprt <<
" nPtsFit " << nPtsFit;
3205 myprt <<
" chgAsym " << chgAsym;
3206 myprt <<
" chgSig " << chgSig;
3207 myprt <<
" kinkSig " << kinkSig;
3209 return (
float)kinkSig;
3220 unsigned short midPt = 0.5 * (tj.
EndPt[0] + tj.
EndPt[1]);
3221 double rms0 = 0, rms1 = 0;
3225 float asym =
std::abs(rms0 - rms1) / (rms0 + rms1);
3226 float chgFact = (tj.
ChgRMS - 0.1) * 5;
3227 float elh = 5 * asym * chgFact;
3228 if (elh > 1) elh = 1;
3238 if (tjIDs.empty())
return 0;
3239 std::array<int, 2> wireWindow;
3242 constexpr
float NNDelta = 5;
3243 wireWindow[0] = pos[0] - NNDelta;
3244 wireWindow[1] = pos[0] + NNDelta;
3245 timeWindow[0] = pos[1] - NNDelta;
3246 timeWindow[1] = pos[1] + NNDelta;
3248 for (
auto& tjID : tjIDs)
3249 if (tjID <= 0 || tjID > (
int)slc.
tjs.size())
return 0;
3254 std::vector<unsigned int> closeHits =
3256 if (closeHits.empty())
return 0;
3261 for (
auto& iht : closeHits) {
3263 chg +=
hit.Integral();
3264 if (slc.
slHits[iht].InTraj == 0)
continue;
3265 if (std::find(tjIDs.begin(), tjIDs.end(), slc.
slHits[iht].InTraj) != tjIDs.end())
3266 tchg +=
hit.Integral();
3268 if (chg == 0)
return 0;
3276 float delta,
md = 0;
3279 for (
auto& tp : tj.
Pts) {
3280 for (ii = 0; ii < tp.Hits.size(); ++ii) {
3281 if (!tp.UseHit[ii])
continue;
3284 if (delta > md) md = delta;
3295 if (tj.
Pts.empty())
return;
3306 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
3307 if (tj.
Pts[ipt].Dir[0] != 0) tj.
Pts[ipt].Dir[0] = -tj.
Pts[ipt].Dir[0];
3308 if (tj.
Pts[ipt].Dir[1] != 0) tj.
Pts[ipt].Dir[1] = -tj.
Pts[ipt].Dir[1];
3309 if (tj.
Pts[ipt].Ang > 0) { tj.
Pts[ipt].Ang -=
M_PI; }
3329 unsigned short nvx = Envelope.size();
3330 double angleSum = 0;
3331 for (
unsigned short ii = 0; ii < Envelope.size(); ++ii) {
3332 p1[0] = Envelope[ii][0] - Point[0];
3333 p1[1] = Envelope[ii][1] - Point[1];
3334 p2[0] = Envelope[(ii + 1) % nvx][0] - Point[0];
3335 p2[1] = Envelope[(ii + 1) % nvx][1] - Point[1];
3338 if (
abs(angleSum) <
M_PI)
return false;
3347 double den = v1[0] * v1[0] + v1[1] * v1[1];
3348 if (den == 0)
return false;
3363 if (pos1[0] == pos2[0] && pos1[1] == pos2[1])
return;
3364 pos1[0] = pos2[0] - pos1[0];
3365 pos1[1] = pos2[1] - pos1[1];
3366 double sep = sqrt(pos1[0] * pos1[0] + pos1[1] * pos1[1]);
3367 if (sep < 1
E-6)
return;
3369 ptDir[0] = pos1[0] / sep;
3370 ptDir[1] = pos1[1] / sep;
3372 double costh =
DotProd(dir1, ptDir);
3373 if (costh > 1.0 || costh < -1.0)
return;
3374 alongTrans[0] = costh * sep;
3375 double sinth = sqrt(1 - costh * costh);
3376 alongTrans[1] = sinth * sep;
3384 double ang1 = atan2(p1[1], p1[0]);
3385 double ang2 = atan2(p2[1], p2[0]);
3394 double dang = Ang1 - Ang2;
3397 while (dang < -
M_PI)
3420 if (tj.
Pts.size() == 0)
return;
3423 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
3424 if (tj.
Pts[ipt].Chg != 0) {
3429 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
3430 unsigned short ipt = tj.
Pts.size() - 1 - ii;
3431 if (tj.
Pts[ipt].Chg != 0) {
3444 unsigned short nUsed = 0;
3445 unsigned short nTotHits = 0;
3446 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
3448 nTotHits += tp.
Hits.size();
3449 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
3450 if (tp.
UseHit[ii]) ++nUsed;
3453 if (nTotHits == 0)
return false;
3454 float fracUsed = (
float)nUsed / (
float)nTotHits;
3456 mf::LogVerbatim(
"TC") <<
"TrajIsClean: nTotHits " << nTotHits <<
" nUsed " << nUsed
3457 <<
" fracUsed " << fracUsed;
3459 if (fracUsed > 0.9)
return true;
3469 if (tjIDs.empty())
return 0;
3472 for (
auto tjid : tjIDs) {
3473 auto& tj = slc.
tjs[tjid - 1];
3474 float npts = tj.EndPt[1] - tj.EndPt[0] + 1;
3475 summ += npts * tj.MCSMom;
3478 return (
short)(summ / suml);
3494 if (firstPt == lastPt)
return 0;
3495 if (firstPt > lastPt)
std::swap(firstPt, lastPt);
3499 if (firstPt >= lastPt)
return 0;
3501 if (firstPt < tj.
EndPt[0])
return 0;
3502 if (lastPt > tj.
EndPt[1])
return 0;
3509 if (tjLen < 1)
return 0;
3511 double thetaRMS =
MCSThetaRMS(slc, tj, firstPt, lastPt);
3512 if (thetaRMS < 0.001)
return 999;
3513 double mom = 13.8 * sqrt(tjLen / 14) / thetaRMS;
3514 if (mom > 999) mom = 999;
3523 if (thePt > tj.
EndPt[1])
return thePt;
3524 if (tj.
Pts[thePt].Chg > 0)
return thePt;
3526 short endPt0 = tj.
EndPt[0];
3527 short endPt1 = tj.
EndPt[1];
3528 for (
short off = 1; off < 10; ++off) {
3529 short ipt = thePt + off;
3530 if (ipt <= endPt1 && tj.
Pts[ipt].Chg > 0)
return (
unsigned short)ipt;
3532 if (ipt >= endPt0 && tj.
Pts[ipt].Chg > 0)
return (
unsigned short)ipt;
3546 if (tps < 1)
return 1;
3556 unsigned short firstPt,
3557 unsigned short lastPt)
3562 if (firstPt < tj.
EndPt[0])
return 1;
3563 if (lastPt > tj.
EndPt[1])
return 1;
3567 if (firstPt >= lastPt)
return 1;
3571 TjDeltaRMS(slc, tj, firstPt, lastPt, sigmaS, cnt);
3572 if (sigmaS < 0)
return 1;
3574 if (tjLen < 1)
return 1;
3576 return (6.8 * sigmaS / tjLen);
3584 unsigned short firstPt,
3585 unsigned short lastPt,
3587 unsigned short& cnt)
3592 if (firstPt < tj.
EndPt[0])
return;
3593 if (lastPt > tj.
EndPt[1])
return;
3597 if (firstPt >= lastPt)
return;
3610 for (
unsigned short ipt = firstPt + 1; ipt < lastPt; ++ipt) {
3611 if (tj.
Pts[ipt].Chg == 0)
continue;
3613 if (tj.
Pts[ipt].HitPosErr2 > 4)
continue;
3617 if (cnt < 2)
return;
3618 rms = sqrt(dsum / (
double)cnt);
3630 std::array<int, 2> wireWindow;
3636 for (
auto& mutj : slc.
tjs) {
3637 if (mutj.AlgMod[
kKilled])
continue;
3638 if (mutj.CTP != inCTP)
continue;
3639 if (mutj.PDGCode != 13)
continue;
3640 unsigned short nnear = 0;
3641 for (
unsigned short ipt = mutj.EndPt[0]; ipt <= mutj.EndPt[1]; ++ipt) {
3642 auto& tp = mutj.Pts[ipt];
3643 wireWindow[0] = tp.Pos[0];
3644 wireWindow[1] = tp.Pos[0];
3645 timeWindow[0] = tp.Pos[1] - delta;
3646 timeWindow[1] = tp.Pos[1] + delta;
3651 if (closeHits.empty())
continue;
3652 for (
auto iht : closeHits) {
3653 auto inTraj = slc.
slHits[iht].InTraj;
3654 if (inTraj <= 0)
continue;
3655 if (inTraj == mutj.ID)
continue;
3656 auto& dtj = slc.
tjs[inTraj - 1];
3657 if (dtj.PDGCode == 13)
continue;
3658 for (
unsigned short jpt = dtj.EndPt[0]; jpt <= dtj.EndPt[1]; ++jpt) {
3659 auto& dtp = dtj.Pts[jpt];
3660 if (std::find(dtp.Hits.begin(), dtp.Hits.end(), iht) == dtp.Hits.end())
continue;
3680 for (
auto& tp : tj.
Pts) {
3681 if (tp.Chg <= 0)
continue;
3683 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
3684 if (tp.UseHit[ii])
continue;
3685 unsigned int iht = tp.Hits[ii];
3711 for (
unsigned short ipt = tj.
EndPt[0] + 1; ipt < tj.
EndPt[1]; ++ipt) {
3712 auto& tp = tj.
Pts[ipt];
3713 if (tp.Chg > bigChg) bigChg = tp.Chg;
3720 for (
unsigned short ipt = tj.
EndPt[0] + 1; ipt < tj.
EndPt[1]; ++ipt) {
3721 auto& tp = tj.
Pts[ipt];
3722 if (tp.Chg <= 0)
continue;
3724 if (tp.Chg == bigChg)
continue;
3729 bsum2 += tp.Chg * tp.Chg;
3730 if (tp.Chg > bigChg) bigChg = tp.Chg;
3736 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
3737 if (!tp.UseHit[ii])
continue;
3738 unsigned int iht = tp.Hits[ii];
3742 vsum2 += tpchg * tpchg;
3745 if (bcnt == 0)
return;
3753 if (arg > 0) tj.
ChgRMS = sqrt(arg / (bcnt - 1));
3755 for (
auto& tp : tj.
Pts)
3758 mf::LogVerbatim(
"TC") << inFcnLabel <<
".UpdateTjChgProperties: backup sum Set tj.AveChg " 3763 double nWires = tj.
EndPt[1] - tj.
EndPt[0] + 1;
3764 if (nWires < 2)
return;
3769 for (
unsigned short end = 0;
end < 2; ++
end) {
3773 int dw =
std::abs(tp.Pos[0] - vx2.Pos[0]);
3785 if (arg > 0) rms = sqrt(arg / (vcnt - 1));
3788 if (rms < 0.1) rms = 0.1;
3792 double defFrac = 1 / vcnt;
3793 rms = defFrac * 0.5 + (1 - defFrac) * rms;
3797 mf::LogVerbatim(
"TC") << inFcnLabel <<
".UpdateTjChgProperties: Set tj.AveChg " 3804 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
3805 auto& tp = tj.
Pts[ipt];
3806 if (tp.Chg <= 0)
continue;
3813 for (
auto& tp : tj.
Pts)
3819 for (
auto& tp : tj.
Pts)
3823 unsigned short minPt = tj.
EndPt[0] + nptsave;
3825 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
3826 unsigned short ipt = tj.
EndPt[1] - ii;
3827 if (ipt < minPt)
break;
3830 for (
unsigned short iii = 0; iii < nptsave; ++iii) {
3831 unsigned short iipt = ipt - iii;
3833 if (iipt == tj.
EndPt[0])
break;
3834 auto& tp = tj.
Pts[iipt];
3835 if (tp.Chg <= 0)
continue;
3840 tj.
Pts[ipt].AveChg = sum / cnt;
3841 lastAve = tj.
Pts[ipt].AveChg;
3845 for (
unsigned short ii = tj.
EndPt[0]; ii <= tj.
EndPt[1]; ++ii) {
3846 unsigned short ipt = tj.
EndPt[1] - ii;
3847 auto& tp = tj.
Pts[ipt];
3848 if (tp.AveChg == 0) { tp.AveChg = lastAve; }
3850 lastAve = tp.AveChg;
3868 for (
auto& tj : slc.
tjs) {
3869 if (tj.AlgMod[
kKilled])
continue;
3870 for (
auto& tp : tj.Pts)
3874 for (
auto& vx : slc.
vtxs) {
3875 if (vx.ID <= 0)
continue;
3887 if (vx2.
ID == 0)
return;
3890 if (prt)
mf::LogVerbatim(
"TC") <<
"UpdateVxEnvironment check Tjs attached to vx2 " << vx2.
ID;
3892 std::vector<int> tjlist;
3893 std::vector<unsigned short> tjends;
3894 if (vx2.
Pos[0] < -0.4)
return;
3895 unsigned int vxWire = std::nearbyint(vx2.
Pos[0]);
3896 unsigned int loWire = vxWire;
3897 unsigned int hiWire = vxWire;
3898 for (
auto& tj : slc.
tjs) {
3900 if (tj.CTP != vx2.
CTP)
continue;
3902 if (tj.AlgMod[
kPhoton])
continue;
3903 for (
unsigned short end = 0;
end < 2; ++
end) {
3904 if (tj.VtxID[
end] != vx2.
ID)
continue;
3905 tjlist.push_back(tj.ID);
3906 tjends.push_back(
end);
3907 if (tj.Pts[tj.EndPt[
end]].Pos[0] < -0.4)
return;
3908 unsigned int endWire = std::nearbyint(tj.Pts[tj.EndPt[
end]].Pos[0]);
3909 if (endWire < loWire) loWire = endWire;
3910 if (endWire > hiWire) hiWire = endWire;
3913 if (tjlist.size() < 2)
return;
3914 if (hiWire < loWire + 1)
return;
3916 mf::LogVerbatim(
"TC") <<
" check Tjs on wires in the range " << loWire <<
" to " << hiWire;
3920 std::vector<std::vector<TrajPoint>> wire_tjpt;
3922 std::vector<int> tjids;
3924 unsigned short nwires = hiWire - loWire + 1;
3925 for (
unsigned short itj = 0; itj < tjlist.size(); ++itj) {
3926 auto& tj = slc.
tjs[tjlist[itj] - 1];
3927 unsigned short end = tjends[itj];
3928 std::vector<TrajPoint> tjpt(nwires);
3930 for (
unsigned short ii = 0; ii < tj.Pts.size(); ++ii) {
3932 if (end == 0) { ipt = tj.EndPt[0] + ii; }
3934 ipt = tj.EndPt[1] - ii;
3936 if (ipt > tj.Pts.size() - 1)
break;
3938 auto tp = tj.Pts[ipt];
3939 if (tp.Chg <= 0)
continue;
3942 if (tp.Pos[0] < -0.4)
continue;
3943 unsigned int wire = std::nearbyint(tp.Pos[0]);
3944 unsigned short indx = wire - loWire;
3945 if (indx > nwires - 1)
break;
3955 if (ltp.
Dir[0] == 0)
continue;
3956 if (ltp.
Pos[0] < -0.4)
continue;
3957 unsigned int wire = std::nearbyint(ltp.
Pos[0]);
3959 unsigned short indx = wire - loWire;
3961 if (tjpt[indx].Chg == 0) tjpt[indx] = ltp;
3963 for (
unsigned short ii = 0; ii <
nwires; ++ii) {
3965 for (
unsigned short iwt = 0; iwt < 2; ++iwt)
3966 ltp.
Pos[iwt] += ltp.
Dir[iwt] * stepSize;
3967 if (ltp.
Pos[0] < -0.4)
break;
3968 wire = std::nearbyint(ltp.
Pos[0]);
3969 if (wire < loWire || wire > hiWire)
break;
3970 indx = wire - loWire;
3971 if (tjpt[indx].Chg > 0)
continue;
3976 myprt <<
" T" << tj.ID;
3977 for (
auto& tp : tjpt)
3978 myprt <<
" " <<
PrintPos(slc, tp.Pos) <<
"_" << tp.Step <<
"_" << (
int)tp.Chg;
3980 wire_tjpt.push_back(tjpt);
3981 tjids.push_back(tj.ID);
3985 for (
unsigned short indx = 0; indx <
nwires; ++indx) {
3987 unsigned short npts = 0;
3989 unsigned short npwc = 0;
3990 for (
unsigned short itj = 0; itj < wire_tjpt.size(); ++itj) {
3991 if (wire_tjpt[itj][indx].Pos[0] == 0)
continue;
3994 if (wire_tjpt[itj][indx].Chg > 0) ++npwc;
3997 if (npts == 0)
continue;
3999 if (npwc == npts)
continue;
4001 for (
unsigned short itj = 0; itj < wire_tjpt.size(); ++itj) {
4002 if (wire_tjpt[itj][indx].Pos[0] == 0)
continue;
4003 if (wire_tjpt[itj][indx].Chg == 0)
continue;
4004 auto& tj = slc.
tjs[tjids[itj] - 1];
4005 unsigned short ipt = wire_tjpt[itj][indx].Step;
4007 tj.NeedsUpdate =
true;
4008 if (prt)
mf::LogVerbatim(
"TC") <<
" Set kEnvOverlap bit on T" << tj.ID <<
" ipt " << ipt;
4014 for (
auto tjid : tjids) {
4015 auto& tj = slc.
tjs[tjid - 1];
4016 if (!tj.NeedsUpdate)
continue;
4017 if (tj.CTP != vx2.
CTP)
continue;
4065 if (dir[0] == 0 && dir[1] == 0 && dir[2] == 0)
return tp;
4069 Point3_t pos3 = {{100 * dir[0], 100 * dir[1], 100 * dir[2]}};
4071 std::array<double, 2> ori2;
4072 std::array<double, 2> pos2;
4073 std::array<double, 2> dir2;
4081 dir2[0] = pos2[0] - ori2[0];
4082 dir2[1] = pos2[1] - ori2[1];
4084 double norm = sqrt(dir2[0] * dir2[0] + dir2[1] * dir2[1]);
4087 tp.
Ang = atan2(dir2[1], dir2[0]);
4088 tp.
Delta = norm / 100;
4096 norm = sqrt(cs * cs + sn * sn);
4101 tp.
DeltaRMS = 100 / (pos2[0] - ori2[0]);
4110 if (fromHit > slc.
slHits.size() - 1)
return false;
4111 if (toHit > slc.
slHits.size() - 1)
return false;
4116 (
float)fhit.WireID().Wire,
4118 (
float)thit.WireID().Wire,
4136 tp.
Pos[0] = fromWire;
4138 tp.
Dir[0] = toWire - fromWire;
4141 if (norm == 0)
return false;
4152 tpOut.
Pos = fromPos;
4154 tpOut.
Ang = atan2(tpOut.
Dir[1], tpOut.
Dir[0]);
4169 tpOut.
Ang = atan2(tpOut.
Dir[1], tpOut.
Dir[0]);
4178 if (tj.
ID == 0)
return 0;
4189 for (
unsigned short xyz = 0; xyz < 2; ++xyz)
4190 dir[xyz] = p2[xyz] - p1[xyz];
4191 if (dir[0] == 0 && dir[1] == 0)
return dir;
4192 double norm = sqrt(dir[0] * dir[0] + dir[1] * dir[1]);
4212 if (tp.
Hits.empty())
return 0;
4213 float minVal = 9999;
4215 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
4216 bool useit = (hitRequest ==
kAllHits);
4219 if (!useit)
continue;
4220 unsigned int iht = tp.
Hits[ii];
4222 float cv =
hit.PeakTime();
4224 float arg = cv -
rms;
4225 if (arg < minVal) minVal = arg;
4227 if (arg > maxVal) maxVal = arg;
4229 if (maxVal == 0)
return 0;
4230 return (maxVal - minVal) / 2;
4236 const std::vector<unsigned int>& hitsInMultiplet,
4245 const std::vector<unsigned int>& hitsInMultiplet,
4248 if (hitsInMultiplet.empty())
return 0;
4250 if (hitsInMultiplet.size() == 1) {
4255 float minVal = 9999;
4257 for (
unsigned short ii = 0; ii < hitsInMultiplet.size(); ++ii) {
4258 unsigned int iht = hitsInMultiplet[ii];
4259 bool useit = (hitRequest ==
kAllHits);
4260 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) useit =
true;
4262 if (!useit)
continue;
4264 float cv =
hit.PeakTime();
4266 float arg = cv -
rms;
4267 if (arg < minVal) minVal = arg;
4269 if (arg > maxVal) maxVal = arg;
4271 if (maxVal == 0)
return 0;
4272 return (maxVal - minVal) / 2;
4278 const std::vector<unsigned int>& hitsInMultiplet,
4288 const std::vector<unsigned int>& hitsInMultiplet,
4295 for (
unsigned short ii = 0; ii < hitsInMultiplet.size(); ++ii) {
4296 unsigned int iht = hitsInMultiplet[ii];
4297 bool useit = (hitRequest ==
kAllHits);
4298 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) useit =
true;
4300 if (!useit)
continue;
4302 float chg =
hit.Integral();
4303 pos += chg *
hit.PeakTime();
4306 if (sum <= 0)
return -1;
4315 if (tj.
Pts.empty())
return 0;
4316 unsigned short nhits = 0;
4317 for (
auto& tp : tj.
Pts) {
4318 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii)
4319 if (tp.UseHit[ii]) ++nhits;
4329 if (tp.
Hits.empty())
return 0;
4333 unsigned short nhits = 0;
4334 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
4336 if (tp.
UseHit[ii]) ++nhits;
4340 if (!tp.
UseHit[ii]) ++nhits;
4350 if (itj > slc.
tjs.size() - 1)
return;
4385 if (npwc > 500) isAMuon =
true;
4406 std::vector<float> cnt(nplanes, 0);
4407 for (
unsigned short iht = 0; iht < (*
evt.
allHits).
size(); ++iht) {
4409 unsigned short plane =
hit.WireID().Plane;
4410 if (plane > nplanes - 1)
return false;
4411 if (cnt[plane] > 200)
continue;
4413 if (
hit.Multiplicity() != 1)
continue;
4415 if (
hit.GoodnessOfFit() < 0 ||
hit.GoodnessOfFit() > 500)
continue;
4417 if (
hit.PeakAmplitude() < 1)
continue;
4421 bool allDone =
true;
4422 for (
unsigned short plane = 0; plane < nplanes; ++plane)
4423 if (cnt[plane] < 200) allDone =
false;
4429 for (
unsigned short plane = 0; plane < nplanes; ++plane) {
4430 if (cnt[plane] > 4) {
evt.
aveHitRMS[plane] /= cnt[plane]; }
4438 std::cout <<
"Analyze hits aveHitRMS";
4441 std::cout <<
" " <<
rms;
4471 unsigned int cstat = inTPCID.
Cryostat;
4472 unsigned int tpc = inTPCID.
TPC;
4477 for (
unsigned short pln = 0; pln < nplanes; ++pln) {
4481 for (
unsigned int wire = 0; wire <
nwires; ++wire) {
4491 for (
unsigned short pln = 0; pln < nplanes; ++pln) {
4503 for (
unsigned short pln = 0; pln < nplanes; ++pln) {
4506 for (
unsigned int wire = 0; wire <
nwires; ++wire)
4511 unsigned int nBadWireFix = 0;
4514 auto wid =
hit.WireID();
4515 if (wid.Cryostat != cstat)
continue;
4516 if (wid.TPC != tpc)
continue;
4517 unsigned short pln = wid.Plane;
4518 unsigned int wire = wid.Wire;
4528 std::cout <<
"FillWireHitRange found hits on " << nBadWireFix
4529 <<
" wires that were declared not-good by the ChannelStatus service. Fixed it...\n";
4547 if (nplanes > 3)
return false;
4550 double local[3] = {0., 0., 0.};
4551 double world[3] = {0., 0., 0.};
4566 slc.
nWires.resize(nplanes);
4571 std::pair<unsigned int, unsigned int> flag;
4572 flag.first = UINT_MAX;
4573 flag.second = UINT_MAX;
4586 for (
unsigned short plane = 0; plane < nplanes; ++plane) {
4595 unsigned int lastWire = 0, lastPlane = 0;
4596 for (
unsigned int iht = 0; iht < slc.
slHits.size(); ++iht) {
4597 unsigned int ahi = slc.
slHits[iht].allHitsIndex;
4598 if (ahi > (*
evt.
allHits).size() - 1)
return false;
4600 if (
hit.WireID().Cryostat != cstat)
continue;
4601 if (
hit.WireID().TPC != tpc)
continue;
4602 unsigned short plane =
hit.WireID().Plane;
4603 unsigned int wire =
hit.WireID().Wire;
4604 if (wire > slc.
nWires[plane] - 1) {
4605 mf::LogWarning(
"TC") <<
"FillWireHitRange: Invalid wire number " << wire <<
" > " 4606 << slc.
nWires[plane] - 1 <<
" in plane " << plane <<
" Quitting";
4609 if (plane == lastPlane && wire < lastWire) {
4611 <<
"FillWireHitRange: Hits are not in increasing wire order. Quitting ";
4623 unsigned int slhitsSize = slc.
slHits.size();
4624 for (
unsigned short plane = 0; plane < nplanes; ++plane) {
4625 for (
unsigned int wire = slc.
firstWire[plane]; wire < slc.
lastWire[plane]; ++wire) {
4626 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
continue;
4627 if (slc.
wireHitRange[plane][wire].first > slhitsSize - 1 &&
4637 std::cout <<
"Slice ID/Index " << slc.
ID <<
"/" <<
slices.size() <<
" tpc " << tpc
4639 std::cout <<
" Active volume (";
4669 if (itj1 > slc.
tjs.size() - 1)
return false;
4670 if (itj2 > slc.
tjs.size() - 1)
return false;
4681 if (pfp1 != USHRT_MAX || pfp2 != USHRT_MAX) {
4682 if (pfp1 != USHRT_MAX && pfp2 != USHRT_MAX)
return false;
4684 if (pfp1 == USHRT_MAX)
std::swap(itj1, itj2);
4701 <<
" at merge points " <<
PrintPos(slc, tp1e1) <<
" " 4727 if (tp2e0[0] > tp1e0[0] && tp2e1[0] < tp1e1[0])
return false;
4731 if (tp1e0[0] > tp2e0[0] && tp1e1[0] < tp2e1[0])
return false;
4735 if (tp2e1[0] > tp1e1[0] && tp2e0[0] < tp1e0[0])
return false;
4736 if (tp1e1[0] > tp2e1[0] && tp1e0[0] < tp2e0[0])
return false;
4751 mf::LogVerbatim(
"TC") <<
"MergeAndStore: You are merging the end of trajectory T" << tj1.
ID 4752 <<
" with a Bragg peak. Not merging\n";
4763 float minSep = 1000;
4764 unsigned short tj2ClosePt = 0;
4769 << tj2ClosePt <<
" Pos " <<
PrintPos(slc, tj2.
Pts[tj2ClosePt]);
4771 if (tj2ClosePt > tj2.
EndPt[1])
return false;
4780 std::vector<unsigned int> tj1Hits;
4781 for (
unsigned short ii = 0; ii < tj1.
Pts.size(); ++ii) {
4784 unsigned short ipt = tj1.
Pts.size() - 1 - ii;
4785 tj1Hits.insert(tj1Hits.end(), tj1.
Pts[ipt].Hits.begin(), tj1.
Pts[ipt].Hits.end());
4786 if (ipt == 0)
break;
4789 bool bumpedPt =
true;
4792 for (
unsigned short ii = 0; ii < tj2.
Pts[tj2ClosePt].Hits.size(); ++ii) {
4793 unsigned int iht = tj2.
Pts[tj2ClosePt].Hits[ii];
4794 if (std::find(tj1Hits.begin(), tj1Hits.end(), iht) != tj1Hits.end()) bumpedPt =
true;
4796 if (bumpedPt && tj2ClosePt < tj2.
EndPt[1]) { ++tj2ClosePt; }
4801 if (doPrt)
mf::LogVerbatim(
"TC") <<
" revised tj2ClosePt " << tj2ClosePt;
4804 tj1.
Pts.insert(tj1.
Pts.end(), tj2.
Pts.begin() + tj2ClosePt, tj2.
Pts.end());
4811 if (tj2.
VtxID[1] > 0) {
4832 int newTjID = slc.
tjs.size();
4836 if (doPrt)
mf::LogVerbatim(
"TC") <<
" MAS success. Created T" << newTjID;
4838 for (
auto& tj : slc.
tjs)
4839 if (tj.ParentID == tj1ID || tj.ParentID == tj2ID) tj.ParentID = newTjID;
4852 std::vector<int>
tmp;
4853 if (
id <= 0)
return tmp;
4854 unsigned int uid = id;
4856 if (type1Name ==
"T" && uid <= slc.
tjs.size() && type2Name ==
"P") {
4858 for (
auto& pfp : slc.
pfps) {
4859 if (pfp.ID <= 0)
continue;
4860 if (std::find(pfp.TjIDs.begin(), pfp.TjIDs.end(), id) != pfp.TjIDs.end())
4861 tmp.push_back(pfp.ID);
4866 if (type1Name ==
"P" && uid <= slc.
pfps.size() && (type2Name ==
"2S" || type2Name ==
"3S")) {
4868 auto& pfp = slc.
pfps[uid - 1];
4870 std::vector<int> ssid;
4871 for (
auto& ss : slc.
cots) {
4872 if (ss.ID <= 0)
continue;
4874 if (!shared.empty() && std::find(ssid.begin(), ssid.end(), ss.ID) == ssid.end())
4875 ssid.push_back(ss.ID);
4877 if (type2Name ==
"2S")
return ssid;
4878 for (
auto& ss3 : slc.
showers) {
4879 if (ss3.ID <= 0)
continue;
4881 if (!shared.empty() && std::find(tmp.begin(), tmp.end(), ss3.ID) == tmp.end())
4882 tmp.push_back(ss3.ID);
4887 if (type1Name ==
"2V" && uid <= slc.
vtxs.size() && type2Name ==
"T") {
4889 for (
auto& tj : slc.
tjs) {
4891 for (
unsigned short end = 0;
end < 2; ++
end) {
4892 if (tj.VtxID[
end] !=
id)
continue;
4893 if (std::find(tmp.begin(), tmp.end(), tj.ID) == tmp.end()) tmp.push_back(tj.ID);
4899 if (type1Name ==
"3V" && uid <= slc.
vtx3s.size() && type2Name ==
"P") {
4900 for (
auto& pfp : slc.
pfps) {
4901 if (pfp.ID == 0)
continue;
4902 for (
unsigned short end = 0;
end < 2; ++
end) {
4903 if (pfp.Vx3ID[
end] !=
id)
continue;
4905 if (std::find(tmp.begin(), tmp.end(), pfp.ID) == tmp.end()) tmp.push_back(pfp.ID);
4911 if (type1Name ==
"3V" && uid <= slc.
vtx3s.size() && type2Name ==
"T") {
4913 for (
auto& tj : slc.
tjs) {
4915 for (
unsigned short end = 0;
end < 2; ++
end) {
4916 if (tj.VtxID[
end] > 0 && tj.VtxID[
end] <= slc.
vtxs.size()) {
4917 auto& vx2 = slc.
vtxs[tj.VtxID[
end] - 1];
4918 if (vx2.Vx3ID !=
id)
continue;
4919 if (std::find(tmp.begin(), tmp.end(), tj.ID) == tmp.end()) tmp.push_back(tj.ID);
4926 if (type1Name ==
"3V" && uid <= slc.
vtx3s.size() && type2Name ==
"2V") {
4928 for (
auto& vx2 : slc.
vtxs) {
4929 if (vx2.ID == 0)
continue;
4930 if (vx2.Vx3ID ==
id) tmp.push_back(vx2.ID);
4935 if (type1Name ==
"3S" && uid <= slc.
showers.size() && type2Name ==
"T") {
4937 auto& ss3 = slc.
showers[uid - 1];
4938 if (ss3.ID == 0)
return tmp;
4939 for (
auto cid : ss3.CotIDs) {
4940 auto& ss = slc.
cots[cid - 1];
4941 if (ss.ID == 0)
continue;
4942 tmp.insert(tmp.end(), ss.TjIDs.begin(), ss.TjIDs.end());
4948 if (type1Name ==
"2S" && uid <= slc.
cots.size() && type2Name ==
"T") {
4950 auto& ss = slc.
cots[uid - 1];
4954 if (type1Name ==
"3S" && uid <= slc.
showers.size() && type2Name ==
"P") {
4956 auto& ss3 = slc.
showers[uid - 1];
4957 if (ss3.ID == 0)
return tmp;
4958 for (
auto cid : ss3.CotIDs) {
4959 auto& ss = slc.
cots[cid - 1];
4960 if (ss.ID == 0)
continue;
4961 for (
auto tid : ss.TjIDs) {
4962 auto& tj = slc.
tjs[tid - 1];
4964 if (!tj.AlgMod[
kMat3D])
continue;
4965 for (
auto& pfp : slc.
pfps) {
4966 if (pfp.ID <= 0)
continue;
4967 if (std::find(pfp.TjIDs.begin(), pfp.TjIDs.end(), tj.ID) == pfp.TjIDs.end())
continue;
4968 if (std::find(tmp.begin(), tmp.end(), pfp.ID) == tmp.end()) tmp.push_back(pfp.ID);
4975 if (type1Name ==
"T" && uid <= slc.
tjs.size() && type2Name ==
"2S") {
4977 for (
auto& ss : slc.
cots) {
4978 if (ss.ID == 0)
continue;
4979 if (std::find(ss.TjIDs.begin(), ss.TjIDs.end(), id) != ss.TjIDs.end()) tmp.push_back(ss.ID);
4984 if (type1Name ==
"T" && uid <= slc.
tjs.size() && type2Name ==
"3S") {
4986 for (
auto& ss : slc.
cots) {
4987 if (ss.ID == 0)
continue;
4988 if (std::find(ss.TjIDs.begin(), ss.TjIDs.end(), id) == ss.TjIDs.end())
continue;
4989 if (ss.SS3ID > 0) tmp.push_back(ss.SS3ID);
5001 unsigned int fromhit,
5003 unsigned short pass)
5009 float fromWire = fromHit.WireID().Wire;
5010 float fromTick = fromHit.PeakTime();
5011 float toWire = toHit.WireID().Wire;
5012 float toTick = toHit.PeakTime();
5014 bool success =
StartTraj(slc, tj, fromWire, fromTick, toWire, toTick, tCTP, pass);
5015 if (!success)
return false;
5020 auto& tp = tj.
Pts[0];
5022 << (
int)fromTick <<
" -> " << (
int)toWire <<
":" << (
int)toTick
5023 <<
" StepDir " << tj.
StepDir <<
" dir " << tp.Dir[0] <<
" " << tp.Dir[1]
5024 <<
" ang " << tp.Ang <<
" AngleCode " << tp.AngleCode <<
" angErr " 5039 unsigned short pass)
5050 int fWire = std::nearbyint(fromWire);
5051 int tWire = std::nearbyint(toWire);
5052 if (tWire < fWire) { stepdir = -1; }
5053 else if (tWire == fWire) {
5055 if (toTick < fromTick) stepdir = -1;
5065 if (!
MakeBareTrajPoint(slc, fromWire, fromTick, toWire, toTick, tCTP, tp))
return false;
5068 tj.
Pts.push_back(tp);
5073 auto& tp = tj.
Pts[0];
5075 << (
int)fromTick <<
" -> " << (
int)toWire <<
":" << (
int)toTick
5076 <<
" StepDir " << tj.
StepDir <<
" dir " << tp.
Dir[0] <<
" " << tp.
Dir[1]
5077 <<
" ang " << tp.
Ang <<
" AngleCode " << tp.
AngleCode <<
" angErr " 5085 std::pair<unsigned short, unsigned short>
5089 for (
unsigned short isl = 0; isl <
slices.size(); ++isl) {
5091 if (typeName ==
"T") {
5092 for (
unsigned short indx = 0; indx < slc.tjs.size(); ++indx) {
5093 if (slc.tjs[indx].UID == uID) {
return std::make_pair(isl, indx); }
5096 if (typeName ==
"P") {
5097 for (
unsigned short indx = 0; indx < slc.pfps.size(); ++indx) {
5098 if (slc.pfps[indx].UID == uID) {
return std::make_pair(isl, indx); }
5101 if (typeName ==
"2V") {
5102 for (
unsigned short indx = 0; indx < slc.vtxs.size(); ++indx) {
5103 if (slc.vtxs[indx].UID == uID) {
return std::make_pair(isl, indx); }
5106 if (typeName ==
"3V") {
5107 for (
unsigned short indx = 0; indx < slc.vtx3s.size(); ++indx) {
5108 if (slc.vtx3s[indx].UID == uID) {
return std::make_pair(isl, indx); }
5111 if (typeName ==
"2S") {
5112 for (
unsigned short indx = 0; indx < slc.cots.size(); ++indx) {
5113 if (slc.cots[indx].UID == uID) {
return std::make_pair(isl, indx); }
5116 if (typeName ==
"3S") {
5117 for (
unsigned short indx = 0; indx < slc.showers.size(); ++indx) {
5118 if (slc.showers[indx].UID == uID) {
return std::make_pair(isl, indx); }
5122 return std::make_pair(USHRT_MAX, USHRT_MAX);
5140 static double sum, sumx, sumy, sumx2, sumy2, sumxy;
5141 static unsigned short cnt;
5142 static std::vector<Point2_t> fitPts;
5143 static std::vector<double> fitWghts;
5160 if (inPtErr <= 0.)
return false;
5162 double wght = 1 / (inPtErr * inPtErr);
5164 sumx += wght * inPt[0];
5165 sumx2 += wght * inPt[0] * inPt[0];
5166 sumy += wght * inPt[1];
5167 sumy2 += wght * inPt[1] * inPt[1];
5168 sumxy += wght * inPt[0] * inPt[1];
5169 if (mode == 1)
return true;
5170 fitPts.push_back(inPt);
5171 fitWghts.push_back(wght);
5175 if (cnt < 2)
return false;
5177 double delta = sum * sumx2 - sumx * sumx;
5178 if (delta == 0.)
return false;
5179 double A = (sumx2 * sumy - sumx * sumxy) / delta;
5180 double B = (sumxy * sum - sumx * sumy) / delta;
5184 if (cnt == 2 || fitPts.empty())
return true;
5187 if (fitPts.size() != cnt)
return false;
5188 double ndof = cnt - 2;
5190 (sumy2 + A * A * sum + B * B * sumx2 - 2 * (A * sumy + B * sumxy - A * B * sumx)) / ndof;
5192 outVecErr[0] = sqrt(varnce * sumx2 / delta);
5193 outVecErr[1] = sqrt(varnce * sum / delta);
5201 for (
unsigned short ii = 0; ii < fitPts.size(); ++ii) {
5202 double arg = fitPts[ii][1] - A - B * fitPts[ii][0];
5203 sum += fitWghts[ii] * arg * arg;
5205 chiDOF = sum / ndof;
5219 if (strng ==
"instruct") {
5220 std::cout <<
"****** Unrecognized DebugConfig. Here are your options\n";
5221 std::cout <<
" 'C:T:P:W:Tick' where C = cryostat, T = TPC, W = wire, Tick (+/-5) to debug " 5222 "stepping (DUNE)\n";
5223 std::cout <<
" 'P:W:Tick' for single cryostat/TPC detectors (uB, LArIAT, etc)\n";
5224 std::cout <<
" 'WorkID <id> <slice index>' where <id> is a tj work ID (< 0) in slice <slice " 5225 "index> (default = 0)\n";
5226 std::cout <<
" 'Merge <CTP>' to debug trajectory merging\n";
5227 std::cout <<
" '2V <CTP>' to debug 2D vertex finding\n";
5228 std::cout <<
" '3V' to debug 3D vertex finding\n";
5229 std::cout <<
" 'VxMerge' to debug 2D vertex merging\n";
5230 std::cout <<
" 'JunkVx' to debug 2D junk vertex finder\n";
5231 std::cout <<
" 'PFP' to debug 3D matching and PFParticles\n";
5232 std::cout <<
" 'MVI <MVI> <MVI Iteration>' for detailed debugging of one PFP MatchVecIndex\n";
5233 std::cout <<
" 'DeltaRay' to debug delta ray tagging\n";
5234 std::cout <<
" 'Muon' to debug muon tagging\n";
5235 std::cout <<
" '2S <CTP>' to debug a 2D shower in CTP\n";
5236 std::cout <<
" 'Reco TPC <TPC>' to only reconstruct hits in the specified TPC\n";
5237 std::cout <<
" 'Reco Slice <ID>' to reconstruct all sub-slices in the recob::Slice with the " 5239 std::cout <<
" 'SubSlice <sub-slice index>' where <slice index> restricts output to the " 5240 "specified sub-slice index\n";
5241 std::cout <<
" 'Stitch' to debug PFParticle stitching between TPCs\n";
5242 std::cout <<
" 'Sum' or 'Summary' to print a debug summary report\n";
5243 std::cout <<
" 'Dump <WorkID>' or 'Dump <UID>' to print all TPs in the trajectory to " 5244 "tcdump<UID>.csv\n";
5245 std::cout <<
" Note: Algs with debug printing include HamVx, HamVx2, SplitTjCVx, Comp3DVx, " 5246 "Comp3DVxIG, VtxHitsSwap\n";
5247 std::cout <<
" Set SkipAlgs: [\"bogusText\"] to print a list of algorithm names\n";
5252 if (strng.find(
"3V") != std::string::npos) {
5257 if (strng.find(
"3S") != std::string::npos) {
5262 if (strng.find(
"VxMerge") != std::string::npos) {
5267 if (strng.find(
"JunkVx") != std::string::npos) {
5272 if (strng.find(
"DeltaRay") != std::string::npos) {
5277 if (strng.find(
"Muon") != std::string::npos) {
5282 if (strng.find(
"Stitch") != std::string::npos) {
5287 if (strng.find(
"HamVx") != std::string::npos) {
5292 if (strng.find(
"HamVx2") != std::string::npos) {
5297 if (strng.find(
"Sum") != std::string::npos) {
5303 std::vector<std::string> words;
5304 boost::split(words, strng, boost::is_any_of(
" :"), boost::token_compress_on);
5305 if (words.size() == 5) {
5318 if (words[0] ==
"PFP" || words[0] ==
"MVI") {
5322 if (words.size() > 2) {
5324 if (words.size() == 3)
debug.
MVI_Iter = std::stoi(words[2]);
5328 if (words.size() == 2 && words[0] ==
"Dump") {
5335 if (words.size() > 1 && words[0] ==
"WorkID") {
5340 if (words.size() > 2)
debug.
Slice = std::stoi(words[2]);
5346 if (words.size() == 3 && words[0] ==
"Reco" && words[1] ==
"TPC") {
5349 std::cout <<
"Reconstructing only in TPC " <<
tcc.
recoTPC <<
"\n";
5352 if (words.size() == 3 && words[0] ==
"Reco" && words[1] ==
"Slice") {
5354 std::cout <<
"Reconstructing Slice " <<
tcc.
recoSlice <<
"\n";
5357 if (words.size() == 3) {
5369 if (words.size() == 2 && words[0] ==
"Merge") {
5375 if (words.size() == 2 && words[0] ==
"2V") {
5381 if (words.size() == 2 && words[0] ==
"2S") {
5388 if (words.size() == 2 && words[0] ==
"SubSlice") {
5404 for (
auto& slc :
slices) {
5405 for (
auto& tj : slc.tjs) {
5410 outfile.open(fname, std::ios::out | std::ios::trunc);
5411 outfile <<
"Dump trajectory T" << tj.UID <<
" WorkID " << tj.WorkID;
5414 outfile <<
"Wire, Chg T" << tj.UID
5415 <<
", totChg, Tick, Delta, NTPsFit, Ang, ChiDOF, KinkSig, HitPosErr\n";
5416 for (
unsigned short ipt = tj.EndPt[0]; ipt <= tj.EndPt[1]; ++ipt) {
5417 auto& tp = tj.Pts[ipt];
5418 outfile << std::fixed;
5420 outfile <<
"," << (
int)tp.Chg;
5423 for (
auto iht : tp.Hits) {
5425 totChg +=
hit.Integral();
5427 outfile <<
"," << (
int)totChg;
5430 outfile <<
"," << tp.NTPsFit;
5438 std::cout <<
"Points on T" << tj.UID <<
" dumped to " << fname <<
"\n";
5451 std::cout <<
"*** TrajCluster debug mode configuration in";
5452 std::cout <<
" CTP=";
5453 if (
debug.
CTP == UINT_MAX) { std::cout <<
"NA"; }
5462 std::cout <<
" Hit=";
5463 if (
debug.
Hit == UINT_MAX) { std::cout <<
"NA"; }
5467 std::cout <<
" WorkID=";
5472 std::cout <<
" Slice=";
5473 if (
debug.
Slice == -1) { std::cout <<
"All"; }
5478 std::cout <<
"*** tcc.dbg modes:";
5482 if (
tcc.
dbg2V) std::cout <<
" dbg2V";
5483 if (
tcc.
dbg2S) std::cout <<
" dbg2S";
5487 if (
tcc.
dbg3V) std::cout <<
" dbg3V";
5495 std::cout <<
"*** Using algs:";
5496 unsigned short cnt = 0;
5497 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib) {
5500 if (cnt % 10 == 0) std::cout <<
"\n ";
5505 std::cout <<
"*** Skipping algs:";
5507 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib) {
5510 if (cnt % 10 == 0) std::cout <<
"\n ";
5527 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5530 if (!slc.vtx3s.empty()) prt3V =
true;
5531 if (!slc.vtxs.empty()) prt2V =
true;
5532 if (!slc.tjs.empty()) prtT =
true;
5533 if (!slc.pfps.empty()) prtP =
true;
5534 if (!slc.showers.empty()) prtS3 =
true;
5537 myprt <<
"Debug report from caller " << someText <<
"\n";
5538 myprt <<
" 'prodID' = <sliceID>:<subSliceIndex>:<productID>/<productUID>\n";
5540 myprt <<
"************ Showers ************\n";
5541 myprt <<
" prodID Vtx parUID ___ChgPos____ ______Dir_____ ____posInPln____ " 5542 "___projInPln____ 2D shower UIDs\n";
5543 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5546 if (slc.showers.empty())
continue;
5547 for (
auto& ss3 : slc.showers)
5548 Print3S(detProp, someText, myprt, ss3);
5552 bool printHeader =
true;
5553 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5556 if (slc.pfps.empty())
continue;
5557 for (
auto& pfp : slc.pfps)
5558 PrintP(someText, myprt, pfp, printHeader);
5562 bool printHeader =
true;
5563 myprt <<
"****** 3D vertices " 5564 "******************************************__2DVtx_UID__*******\n";
5565 myprt <<
" prodID Cstat TPC X Y Z XEr YEr " 5566 "ZEr pln0 pln1 pln2 Wire score Prim? Nu? nTru";
5567 myprt <<
" ___________2D_Pos____________ _____Tj UIDs________\n";
5568 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5571 if (slc.vtx3s.empty())
continue;
5572 for (
auto& vx3 : slc.vtx3s)
5573 Print3V(detProp, someText, myprt, vx3, printHeader);
5577 bool printHeader =
true;
5578 myprt <<
"************ 2D vertices ************\n";
5579 myprt <<
" prodID CTP wire err tick err ChiDOF NTj Pass " 5580 " Topo ChgFrac Score v3D Tj UIDs\n";
5581 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5584 if (slc.vtxs.empty())
continue;
5585 for (
auto& vx2 : slc.vtxs)
5586 Print2V(someText, myprt, vx2, printHeader);
5590 bool printHeader =
true;
5591 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5594 if (slc.tjs.empty())
continue;
5595 for (
auto& tj : slc.tjs)
5596 PrintT(someText, myprt, tj, printHeader);
5605 if (pfp.
ID <= 0)
return;
5607 myprt <<
"************ PFParticles ************\n";
5608 myprt <<
" prodID sVx _____sPos____ CS _______sDir______ ____sdEdx_____ eVx " 5609 "_____ePos____ CS ____edEdx_____ MVI MCSMom Len nTP3 nSec SLk? PDG Par \n";
5610 printHeader =
false;
5613 if (sIndx.first == USHRT_MAX)
return;
5614 auto& slc =
slices[sIndx.first];
5620 for (
unsigned short end = 0;
end < 2; ++
end) {
5642 for (
auto& dedx : pfp.
dEdx[
end]) {
5648 if (pfp.
dEdx[end].size() < 3) {
5649 for (
size_t i = 0; i < 3 - pfp.
dEdx[
end].size(); ++i) {
5657 float length =
Length(pfp);
5667 if (!pfp.
TjIDs.empty()) {
5668 if (pfp.
TjUIDs.empty()) {
5670 for (
auto tjid : pfp.
TjIDs)
5671 myprt <<
" TU" << slc.tjs[tjid - 1].UID;
5675 for (
auto tjuid : pfp.
TjUIDs)
5676 myprt <<
" TU" << tjuid;
5681 for (
auto dtruid : pfp.
DtrUIDs)
5682 myprt <<
" PU" << dtruid;
5696 if (vx3.
ID <= 0)
return;
5698 if (sIndx.first == USHRT_MAX)
return;
5699 auto& slc =
slices[sIndx.first];
5702 <<
"****** 3D vertices ******************************************__2DVtx_UID__*******\n";
5703 myprt <<
" prodID Cstat TPC X Y Z pln0 pln1 pln2 Wire score " 5705 myprt <<
" ___________2D_Pos____________ _____Tj UIDs________\n";
5706 printHeader =
false;
5716 for (
auto vx2id : vx3.
Vx2ID) {
5726 unsigned short nTruMatch = 0;
5727 for (
unsigned short ipl = 0; ipl < slc.nPlanes; ++ipl) {
5728 if (vx3.
Vx2ID[ipl] == 0)
continue;
5729 unsigned short iv2 = vx3.
Vx2ID[ipl] - 1;
5737 for (
unsigned short plane = 0; plane < slc.nPlanes; ++plane) {
5739 myprt <<
" " <<
PrintPos(slc, pos);
5741 if (vx3.
Wire == -2) {
5743 for (
unsigned short end = 0;
end < 2; ++
end) {
5744 for (
auto& pfp : slc.pfps) {
5745 if (pfp.Vx3ID[
end] == vx3.
ID) {
5746 for (
auto tjID : pfp.TjIDs) {
5747 auto& tj = slc.tjs[tjID - 1];
5748 myprt <<
" T" << tj.UID;
5755 auto vxtjs =
GetAssns(slc,
"3V", vx3.
ID,
"T");
5756 for (
auto tjid : vxtjs) {
5757 auto& tj = slc.tjs[tjid - 1];
5758 myprt <<
" TU" << tj.UID;
5769 if (vx2.
ID <= 0)
return;
5772 if (sIndx.first == USHRT_MAX)
return;
5773 auto& slc =
slices[sIndx.first];
5775 myprt <<
"************ 2D vertices ************\n";
5776 myprt <<
" prodID CTP wire err tick err ChiDOF NTj Pass Topo ChgFrac Score " 5778 printHeader =
false;
5795 if (vx2.
Vx3ID > 0) v3id = slc.vtx3s[vx2.
Vx3ID - 1].UID;
5799 for (
unsigned short ii = 0; ii < slc.tjs.size(); ++ii) {
5800 auto const& tj = slc.tjs[ii];
5801 if (tj.AlgMod[
kKilled])
continue;
5802 for (
unsigned short end = 0;
end < 2; ++
end) {
5803 if (tj.VtxID[
end] != (
short)vx2.
ID)
continue;
5810 for (
unsigned short ib = 1; ib <
VtxBitNames.size(); ++ib)
5822 if (ss3.
ID <= 0)
return;
5824 if (sIndx.first == USHRT_MAX)
return;
5825 auto& slc =
slices[sIndx.first];
5833 for (
unsigned short xyz = 0; xyz < 3; ++xyz)
5835 for (
unsigned short xyz = 0; xyz < 3; ++xyz)
5837 std::vector<float> projInPlane(slc.nPlanes);
5838 for (
unsigned short plane = 0; plane < slc.nPlanes; ++plane) {
5841 myprt <<
" " <<
PrintPos(slc, tp.Pos);
5842 projInPlane[plane] = tp.Delta;
5844 for (
unsigned short plane = 0; plane < slc.nPlanes; ++plane) {
5847 for (
auto cid : ss3.
CotIDs) {
5848 auto& ss = slc.cots[cid - 1];
5852 if (ss3.
NeedsUpdate) myprt <<
" *** Needs update";
5861 if (tj.
ID <= 0)
return;
5864 myprt <<
"************ Trajectories ************\n";
5865 myprt <<
"Tj AngleCode-EndFlag decoder (EF): <AngleCode> + <reason for stopping>";
5866 myprt <<
" (B=Bragg Peak, V=Vertex, A=AngleKink, C=ChargeKink, T=Trajectory)\n";
5867 myprt <<
" prodID CTP Pass Pts W:T Ang EF AveQ W:T Ang EF AveQ " 5868 "Chg(k) chgRMS Mom __Vtx__ PDG eLike Par Pri NuPar WorkID \n";
5869 printHeader =
false;
5872 if (sIndx.first == USHRT_MAX)
return;
5873 auto& slc =
slices[sIndx.first];
5879 unsigned short endPt0 = tj.
EndPt[0];
5880 auto& tp0 = tj.
Pts[endPt0];
5882 if (itick < 0) itick = 0;
5883 myprt <<
std::setw(6) << (
int)(tp0.Pos[0] + 0.5) <<
":" << itick;
5884 if (itick < 10) { myprt <<
" "; }
5885 if (itick < 100) { myprt <<
" "; }
5886 if (itick < 1000) { myprt <<
" "; }
5903 unsigned short endPt1 = tj.
EndPt[1];
5904 auto& tp1 = tj.
Pts[endPt1];
5906 myprt <<
std::setw(6) << (
int)(tp1.Pos[0] + 0.5) <<
":" << itick;
5907 if (itick < 10) { myprt <<
" "; }
5908 if (itick < 100) { myprt <<
" "; }
5909 if (itick < 1000) { myprt <<
" "; }
5930 if (tj.
VtxID[0] > 0) vxid = slc.vtxs[tj.
VtxID[0] - 1].UID;
5933 if (tj.
VtxID[1] > 0) vxid = slc.vtxs[tj.
VtxID[1] - 1].UID;
5941 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
5961 if (!slc.
vtx3s.empty()) {
5965 <<
"****** 3D vertices ******************************************__2DVtx_ID__*******\n";
5967 <<
" Vtx Cstat TPC X Y Z XEr YEr ZEr pln0 pln1 pln2 Wire " 5968 "score Prim? Nu? nTru";
5969 myprt <<
" ___________2D_Pos____________ _____Tjs________\n";
5970 for (
unsigned short iv = 0; iv < slc.
vtx3s.size(); ++iv) {
5971 if (slc.
vtx3s[iv].ID == 0)
continue;
5989 unsigned short nTruMatch = 0;
5990 for (
unsigned short ipl = 0; ipl < slc.
nPlanes; ++ipl) {
5991 if (vx3.
Vx2ID[ipl] == 0)
continue;
5992 unsigned short iv2 = vx3.
Vx2ID[ipl] - 1;
6000 for (
unsigned short plane = 0; plane < slc.
nPlanes; ++plane) {
6002 myprt <<
" " <<
PrintPos(slc, pos);
6004 if (vx3.
Wire == -2) {
6006 for (
auto& pfp : slc.
pfps) {
6007 if (pfp.Vx3ID[0] == slc.
vtx3s[iv].ID) {
6008 for (
auto& tjID : pfp.TjIDs)
6009 myprt <<
" t" << tjID;
6011 if (pfp.Vx3ID[1] == slc.
vtx3s[iv].ID) {
6012 for (
auto& tjID : pfp.TjIDs)
6013 myprt <<
" t" << tjID;
6018 auto vxtjs =
GetAssns(slc,
"3V", vx3.
ID,
"T");
6019 for (
auto tjid : vxtjs)
6020 myprt <<
" t" << tjid;
6025 if (!slc.
vtxs.empty()) {
6026 bool foundOne =
false;
6027 for (
unsigned short iv = 0; iv < slc.
vtxs.size(); ++iv) {
6028 auto& vx2 = slc.
vtxs[iv];
6030 if (vx2.NTraj == 0)
continue;
6035 myprt << someText <<
"************ 2D vertices ************\n";
6037 <<
" ID CTP wire err tick err ChiDOF NTj Pass Topo ChgFrac Score v3D " 6039 for (
auto& vx2 : slc.
vtxs) {
6040 if (vx2.ID == 0)
continue;
6047 << std::nearbyint(vx2.Pos[0]);
6062 for (
unsigned short ii = 0; ii < slc.
tjs.size(); ++ii) {
6063 auto const& aTj = slc.
tjs[ii];
6065 if (aTj.AlgMod[
kKilled])
continue;
6066 for (
unsigned short end = 0;
end < 2; ++
end) {
6067 if (aTj.VtxID[
end] != (
short)vx2.ID)
continue;
6073 for (
unsigned short ib = 1; ib <
VtxBitNames.size(); ++ib)
6074 if (vx2.Stat[ib]) myprt <<
" " <<
VtxBitNames[ib];
6081 if (slc.
tjs.empty()) {
6082 mf::LogVerbatim(
"TC") << someText <<
" No allTraj trajectories to print";
6088 if (itj == USHRT_MAX) {
6090 myprt <<
"Tj AngleCode-EndFlag (EF) decoder: <AngleCode> + <reason for stopping>";
6091 myprt <<
" (B=Bragg Peak, V=Vertex, A=AngleKink, C=ChargeKink, T=Trajectory)\n";
6092 std::vector<unsigned int>
tmp;
6094 <<
" UID CTP Pass Pts W:T Ang EF AveQ W:T Ang EF AveQ Chg(k) " 6095 "chgRMS Mom SDr __Vtx__ PDG Par Pri NuPar WorkID \n";
6096 for (
unsigned short ii = 0; ii < slc.
tjs.size(); ++ii) {
6097 auto& aTj = slc.
tjs[ii];
6099 myprt << someText <<
" ";
6105 myprt << std::fixed <<
std::setw(5) << tid;
6108 myprt <<
std::setw(5) << aTj.EndPt[1] - aTj.EndPt[0] + 1;
6109 unsigned short endPt0 = aTj.EndPt[0];
6110 auto& tp0 = aTj.Pts[endPt0];
6112 if (itick < 0) itick = 0;
6113 myprt <<
std::setw(6) << (
int)(tp0.Pos[0] + 0.5) <<
":" << itick;
6114 if (itick < 10) { myprt <<
" "; }
6115 if (itick < 100) { myprt <<
" "; }
6116 if (itick < 1000) { myprt <<
" "; }
6119 if (aTj.EndFlag[0][
kBragg]) { myprt <<
"B"; }
6120 else if (aTj.EndFlag[0][
kAtVtx]) {
6123 else if (aTj.EndFlag[0][
kAtKink]) {
6126 else if (aTj.EndFlag[0][
kAtTj]) {
6133 unsigned short endPt1 = aTj.EndPt[1];
6134 auto& tp1 = aTj.Pts[endPt1];
6136 myprt <<
std::setw(6) << (
int)(tp1.Pos[0] + 0.5) <<
":" << itick;
6137 if (itick < 10) { myprt <<
" "; }
6138 if (itick < 100) { myprt <<
" "; }
6139 if (itick < 1000) { myprt <<
" "; }
6142 if (aTj.EndFlag[1][
kBragg]) { myprt <<
"B"; }
6143 else if (aTj.EndFlag[1][
kAtVtx]) {
6161 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6162 if (aTj.AlgMod[ib]) myprt <<
" " <<
AlgBitNames[ib];
6168 if (itj > slc.
tjs.size() - 1)
return;
6170 auto const& aTj = slc.
tjs[itj];
6172 mf::LogVerbatim(
"TC") <<
"Print slc.tjs[" << itj <<
"] Vtx[0] " << aTj.VtxID[0] <<
" Vtx[1] " 6175 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6176 if (aTj.AlgMod[ib]) myprt <<
" " <<
AlgBitNames[ib];
6180 if (ipt == USHRT_MAX) {
6182 for (
unsigned short ii = 0; ii < aTj.Pts.size(); ++ii)
6183 PrintTP(someText, slc, ii, aTj.StepDir, aTj.Pass, aTj.Pts[ii]);
6187 PrintTP(someText, slc, ipt, aTj.StepDir, aTj.Pass, aTj.Pts[ipt]);
6196 unsigned short tPoint)
6200 if (tPoint == USHRT_MAX) {
6203 myprt << someText <<
" ";
6204 myprt <<
"Work: UID " << tj.
UID <<
" CTP " << tj.
CTP <<
" StepDir " << tj.
StepDir 6206 <<
" nPts " << tj.
Pts.size() <<
" EndPts " << tj.
EndPt[0] <<
" " << tj.
EndPt[1];
6207 myprt <<
" MCSMom " << tj.
MCSMom;
6209 myprt <<
" AlgMods:";
6210 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6215 myprt << someText <<
" ";
6216 myprt <<
"slcID " << slc.
ID <<
" T" << tj.
ID <<
" uT" << tj.
UID <<
" WorkID " << tj.
WorkID 6218 <<
" " << tj.
VtxID[1] <<
" nPts " << tj.
Pts.size() <<
" EndPts " << tj.
EndPt[0] <<
" " 6220 myprt <<
" MCSMom " << tj.
MCSMom;
6222 myprt <<
" AlgMods:";
6223 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6227 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt)
6231 for (
unsigned short ic = 0; ic < slc.
cots.size(); ++ic) {
6232 if (slc.
cots[ic].TjIDs.empty())
continue;
6234 if (slc.
cots[ic].ShowerTjID != tj.
ID)
continue;
6237 myprt <<
"cots index " << ic <<
" ";
6238 myprt << someText <<
" Envelope";
6239 if (ss.
Envelope.empty()) { myprt <<
" NA"; }
6247 myprt <<
"\nInShower TjIDs";
6249 myprt <<
" " << tjID;
6253 myprt <<
"NearTjIDs";
6255 myprt <<
" " << tjID;
6265 myprt <<
" No parent";
6267 myprt <<
" TruParentID " << ss.
TruParentID <<
" SS3ID " << ss.
SS3ID <<
"\n";
6268 if (ss.
NeedsUpdate) myprt <<
"*********** This shower needs to be updated ***********";
6269 myprt <<
"................................................";
6275 if (tPoint > tj.
Pts.size() - 1) {
6276 mf::LogVerbatim(
"TC") <<
"Can't print non-existent traj point " << tPoint;
6288 <<
" TRP CTP Ind Stp Delta RMS Ang C Err Dir0 Dir1 Q " 6289 " AveQ Pull FitChi NTPF KinkSig Hits ";
6298 unsigned short pass,
6302 myprt << someText <<
" TRP" << std::fixed;
6304 if (dir > 0) { myprt <<
"+"; }
6325 if (tp.
Hits.size() > 16) {
6327 myprt <<
" " << tp.
Hits.size() <<
" shower hits";
6330 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
6331 unsigned int iht = tp.
Hits[ii];
6333 myprt <<
" " <<
hit.WireID().Wire <<
":" << (
int)
hit.PeakTime();
6341 myprt <<
"T" << slc.
slHits[iht].InTraj;
6343 if (tp.
InPFP > 0) myprt <<
" inP" << tp.
InPFP;
6355 for (
unsigned short ib = 0; ib < 8; ++ib) {
6364 if (ib ==
kEnvFlag) str +=
" Flag";
6376 myprt <<
" PFP sVx ________sPos_______ EF _______sDir______ ____sdEdx_____ eVx " 6377 "________ePos_______ EF _______eDir______ ____edEdx____ Len nTp3 MCSMom ShLike? " 6384 for (
unsigned short end = 0;
end < 2; ++
end) {
6404 for (
auto& dedx : pfp.
dEdx[
end]) {
6410 if (pfp.
dEdx[end].size() < 3) {
6411 for (
size_t i = 0; i < 3 - pfp.
dEdx[
end].size(); ++i) {
6417 float length =
Length(pfp);
6429 if (!pfp.
TjIDs.empty()) {
6430 for (
auto& tjID : pfp.
TjIDs)
6431 myprt <<
" T" << tjID;
6435 for (
auto& dtrUID : pfp.
DtrUIDs)
6436 myprt <<
" P" << dtrUID;
6444 if (slc.
pfps.empty())
return;
6449 <<
" PFP sVx ________sPos_______ ______sDir______ ______sdEdx_____ eVx " 6450 "________ePos_______ ______eDir______ ______edEdx_____ BstPln PDG TruPDG Par Prim E*P\n";
6451 bool printHeader =
true;
6452 for (
auto& pfp : slc.
pfps) {
6453 PrintPFP(someText, slc, pfp, printHeader);
6454 printHeader =
false;
6463 if (end > 1)
return "Invalid end";
6466 for (
unsigned short ib = 0; ib <
EndFlagNames.size(); ++ib) {
6477 if (first) tmp =
" none";
6485 if (end > 1)
return "Invalid end";
6488 for (
unsigned short ib = 0; ib <
EndFlagNames.size(); ++ib) {
6533 unsigned int wire = 0;
6534 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)
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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.
void ReleaseHits(TCSlice &slc, Trajectory &tj)
short MCSMom(const TCSlice &slc, const std::vector< int > &tjIDs)
span(IterB &&b, IterE &&e, Adaptor &&adaptor) -> span< decltype(adaptor(std::forward< IterB >(b))), decltype(adaptor(std::forward< IterE >(e))) >
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::vector< Trajectory > tjs
vector of all trajectories in each plane
unsigned short FarEnd(const TCSlice &slc, const PFPStruct &pfp, const Point3_t &pos)
Point2_t dEdx
dE/dx for 3D matched trajectories
float Length(const PFPStruct &pfp)
bool dbgStitch
debug PFParticle stitching
void SetEndPoints(Trajectory &tj)
void FitPar(const TCSlice &slc, const Trajectory &tj, unsigned short originPt, unsigned short npts, short fitDir, ParFit &pFit, unsigned short usePar)
bool MakeVertexObsolete(std::string fcnLabel, TCSlice &slc, VtxStore &vx2, bool forceKill)
bool TrajHitsOK(TCSlice &slc, const std::vector< unsigned int > &iHitsInMultiplet, const std::vector< unsigned int > &jHitsInMultiplet)
std::vector< float > kinkCuts
kink finder algorithm
bool InTrajOK(TCSlice &slc, std::string someText)
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
bool InsideFV(const TCSlice &slc, const PFPStruct &pfp, unsigned short end)
unsigned short CloseEnd(const TCSlice &slc, const Trajectory &tj, const Point2_t &pos)
struct of temporary 2D vertices (end points)
std::vector< int > GetAssns(TCSlice &slc, std::string type1Name, int id, std::string type2Name)
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.
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
std::vector< float > maxPos0
short recoTPC
only reconstruct in the seleted TPC
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)
std::vector< Point2_t > Envelope
void Print2V(std::string someText, mf::LogVerbatim &myprt, VtxStore &vx2, bool &printHeader)
tagged as a vertex between Tjs that are matched to MC truth neutrino interaction particles ...
void Print3V(detinfo::DetectorPropertiesData const &detProp, std::string someText, mf::LogVerbatim &myprt, Vtx3Store &vx3, bool &printHeader)
void PrintPFP(std::string someText, TCSlice &slc, const PFPStruct &pfp, bool printHeader)
vertex position fixed manually - no fitting done
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)
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.
Geometry information for a single TPC.
bool WireHitRangeOK(TCSlice &slc, const CTP_t &inCTP)
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)
void PrintT(std::string someText, mf::LogVerbatim &myprt, Trajectory &tj, bool &printHeader)
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.
float TpSumHitChg(const TCSlice &slc, TrajPoint const &tp)
std::string PrintPos(const TCSlice &slc, const TrajPoint &tp)
void ChkChgAsymmetry(TCSlice &slc, Trajectory &tj, bool prt)
CryostatID_t Cryostat
Index of cryostat.
float ExpectedHitsRMS(TCSlice &slc, const TrajPoint &tp)
bool TrajClosestApproach(Trajectory const &tj, float x, float y, unsigned short &closePt, float &DOCA)
void PosInPlane(detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, const Vtx3Store &vx3, unsigned short plane, Point2_t &pos)
void FillWireHitRange(geo::TPCID inTPCID)
float TrajPointSeparation(const TrajPoint &tp1, const TrajPoint &tp2)
std::vector< std::pair< unsigned int, unsigned int > > tpcSrcHitRange
void SetAngleCode(TrajPoint &tp)
void PrintP(std::string someText, mf::LogVerbatim &myprt, PFPStruct &pfp, bool &printHeader)
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 StartTraj(TCSlice &slc, Trajectory &tj, unsigned int fromhit, unsigned int tohit, unsigned short pass)
bool MakeBareTrajPoint(const TCSlice &slc, unsigned int fromHit, unsigned int toHit, TrajPoint &tp)
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)
float MCSThetaRMS(const TCSlice &slc, const Trajectory &tj)
std::array< int, 2 > Vx3ID
bool expectSlicedHits
info passed from the module - used to (not) define wireHitRange
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.
bool IsShowerLike(TCSlice &slc, const std::vector< int > TjIDs)
unsigned short NumUsedHitsInTj(const TCSlice &slc, const Trajectory &tj)
std::string TPEnvString(const TrajPoint &tp)
std::vector< int > CotIDs
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
bool StoreVertex(TCSlice &slc, VtxStore &vx)
void PrintPFPs(std::string someText, TCSlice &slc)
Q_EXPORT QTSManip setprecision(int p)
float MaxTjLen(const TCSlice &slc, std::vector< int > &tjIDs)
void Print3S(detinfo::DetectorPropertiesData const &detProp, std::string someText, mf::LogVerbatim &myprt, ShowerStruct3D &ss3)
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
bool MergeTjIntoPFP(TCSlice &slc, int mtjid, PFPStruct &pfp, bool prt)
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
std::string PrintHitShort(const TCHit &tch)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
TrajPoint MakeBareTP(detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, const Point3_t &pos, CTP_t inCTP)
float OverlapFraction(const TCSlice &slc, const Trajectory &tj1, const Trajectory &tj2)
float HitsRMSTime(const TCSlice &slc, const std::vector< unsigned int > &hitsInMultiplet, HitStatus_t hitRequest)
unsigned int Hit
set to the hit index in evt.allHits if a Plane:Wire:Tick match is found
bool CompatibleMerge(const TCSlice &slc, std::vector< int > &tjIDs, bool prt)
std::vector< int > TjUIDs
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 close(int)
Closes the file descriptor fd.
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
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
void PrintAllTraj(detinfo::DetectorPropertiesData const &detProp, std::string someText, TCSlice &slc, unsigned short itj, unsigned short ipt, bool prtVtx)
short nPtsAve
dump trajectory points
int PrimaryID(const TCSlice &slc, const Trajectory &tj)
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
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.
bool TrajIsClean(TCSlice &slc, Trajectory &tj, bool prt)
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)
unsigned short NearbyCleanPt(const TCSlice &slc, const Trajectory &tj, unsigned short end)
Vector3_t PointDirection(const Point3_t p1, const Point3_t p2)
void swap(Handle< T > &a, Handle< T > &b)
TP is near a hit in the srcHit collection but no allHit hit exists (DUNE disambiguation error) ...
CTP_t CTP
Cryostat, TPC, Plane code.
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)
float KinkSignificance(TCSlice &slc, Trajectory &tj1, unsigned short end1, Trajectory &tj2, unsigned short end2, unsigned short nPtsFit, bool useChg, bool prt)
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)
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)
void ChkEndKink(TCSlice &slc, Trajectory &tj, bool prt)
std::vector< float > match3DCuts
3D matching cuts
std::vector< SectionFit > SectionFits
void TagJunkTj(TCSlice &slc, Trajectory &tj, bool prt)
unsigned int NumberTimeSamples() const
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
virtual bool IsGood(raw::ChannelID_t channel) const
Returns whether the specified channel is physical and good.
void MakeTrajectoryObsolete(TCSlice &slc, unsigned int itj)
short StartEnd
The starting end (-1 = don't know)
float PointTrajDOCA2(const TCSlice &slc, float wire, float time, TrajPoint const &tp)
double PosSep2(const Point3_t &pos1, const Point3_t &pos2)
unsigned short GetPFPIndex(const TCSlice &slc, int tjID)
void FitTraj(TCSlice &slc, Trajectory &tj)
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)
void TrajPointTrajDOCA(const TCSlice &slc, TrajPoint const &tp, Trajectory const &tj, unsigned short &closePt, float &minSep)
const geo::GeometryCore * geom
Class providing information about the quality of channels.
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.
float MaxChargeAsymmetry(TCSlice &slc, std::vector< int > &tjIDs)
unsigned short NearestPtWithChg(const TCSlice &slc, const Trajectory &tj, unsigned short thePt)
bool SetMag(Vector3_t &v1, double mag)
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
std::array< double, 2 > Vector2_t
Definition of data types for geometry description.
void ReverseTraj(TCSlice &slc, Trajectory &tj)
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)
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
bool valsIncreasing(const SortEntry &c1, const SortEntry &c2)
auto norm(Vector const &v)
Return norm of the specified vector.
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.
Q_EXPORT QTSManip setw(int w)
void UpdateTjChgProperties(std::string inFcnLabel, TCSlice &slc, Trajectory &tj, bool prt)
std::bitset< 16 > modes
number of points to find AveChg
std::vector< TCHit > slHits
float PointPull(const PFPStruct &pfp, const TP3D &tp3d)
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.
int Tick
Select hit PeakTime for debugging (< 0 for vertex finding)
void TrajIntersection(TrajPoint const &tp1, TrajPoint const &tp2, Point2_t &pos)
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
const std::vector< std::string > VtxBitNames
Declaration of signal hit object.
double DotProd(const Vector3_t &v1, const Vector3_t &v2)
std::vector< Vtx3Store > vtx3s
3D vertices
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.
short StepDir
-1 = going US (-> small wire#), 1 = going DS (-> large wire#)
for(std::string line;std::getline(inFile, line);)
float MaxHitDelta(TCSlice &slc, Trajectory &tj)
float TrajLength(const Trajectory &tj)
std::bitset< 128 > AlgMod
Bit set if algorithm AlgBit_t modifed the trajectory.
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
std::vector< short > muonTag
void UpdateVxEnvironment(TCSlice &slc)
geo::PlaneID DecodeCTP(CTP_t CTP)
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
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)
std::bitset< 8 > Environment
std::vector< recob::Hit > const * allHits
CTP_t EncodeCTP(unsigned int cryo, unsigned int tpc, unsigned int plane)
Interface for experiment-specific channel quality info provider.
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)
Access the description of detector geometry.
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)
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
void TjDeltaRMS(const TCSlice &slc, const Trajectory &tj, unsigned short firstPt, unsigned short lastPt, double &rms, unsigned short &cnt)
void split(std::string const &s, char c, OutIter dest)
std::vector< PFPStruct > pfps
std::vector< int > FindCloseTjs(const TCSlice &slc, const TrajPoint &fromTp, const TrajPoint &toTp, const float &maxDelta)
bool SignalBetween(const TCSlice &slc, const TrajPoint &tp1, const TrajPoint &tp2, const float &MinWireSignalFraction)
2D representation of charge deposited in the TDC/wire plane
void MoveTPToWire(TrajPoint &tp, float wire)
unsigned short NumPtsWithCharge(const TCSlice &slc, const Trajectory &tj, bool includeDeadWires)
void MergeGhostTjs(TCSlice &slc, CTP_t inCTP)
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.
Interface for experiment-specific service for channel quality info.
bool StorePFP(TCSlice &slc, PFPStruct &pfp)
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
int PrimaryUID(const TCSlice &slc, const PFPStruct &pfp)
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.
master switch for turning on debug mode
std::string to_string(ModuleType const mt)
void LocalToWorld(const double *tpc, double *world) const
Transform point from local TPC frame to world frame.
float TPHitsRMSTick(const TCSlice &slc, const TrajPoint &tp, HitStatus_t hitRequest)
def parent(G, child, parent_type)
void PrintTPHeader(std::string someText)
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
pure virtual base interface for detector clocks
Encapsulate the construction of a single detector plane.
std::array< std::bitset< 8 >, 2 > EndFlag
void SetTPEnvironment(TCSlice &slc, CTP_t inCTP)
bool valsDecreasing(const SortEntry &c1, const SortEntry &c2)
bool HasDuplicateHits(const TCSlice &slc, Trajectory const &tj, bool prt)