4 #include <boost/algorithm/string/classification.hpp> 5 #include <boost/algorithm/string/split.hpp> 68 std::vector<int> dtrs;
69 for (
auto& dtj : slc.
tjs) {
70 if (dtj.AlgMod[
kKilled])
continue;
71 if (dtj.ParentID != muTj.
ID)
continue;
72 dtrs.push_back(dtj.ID);
74 if (prt)
mf::LogVerbatim(
"TC") <<
"MakeHaloTj: Killing delta-ray T" << dtj.ID;
78 if (pfpIndex == USHRT_MAX) {
79 if (prt)
mf::LogVerbatim(
"TC") <<
" No PFP found for 3D-matched delta-ray";
82 auto& pfp = slc.
pfps[pfpIndex];
83 if (prt)
mf::LogVerbatim(
"TC") <<
" Killing delta-ray PFParticle P" << pfp.UID;
86 if (pfp.ParentUID > 0) {
88 if (parentIndx.first != USHRT_MAX) {
89 auto&
parent =
slices[parentIndx.first].pfps[parentIndx.second];
90 std::vector<int> newDtrUIDs;
91 for (
auto uid :
parent.DtrUIDs)
92 if (uid != dtj.UID) newDtrUIDs.push_back(uid);
93 parent.DtrUIDs = newDtrUIDs;
105 tj.
ID = slc.
tjs.size() + 1;
121 std::vector<int> closeTjs;
122 for (
unsigned short ipt = muTj.
EndPt[0]; ipt <= muTj.
EndPt[1]; ++ipt) {
123 auto tp = muTj.
Pts[ipt];
134 if (tp.Dir[0] != 0) window *=
std::abs(1 / tp.Dir[0]);
137 bool hitsAdded =
false;
138 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
139 unsigned int iht = tp.Hits[ii];
140 auto inTraj = slc.
slHits[iht].InTraj;
141 if (inTraj < 0)
continue;
143 tp.UseHit[ii] =
true;
149 if (inTraj != muTj.
ID &&
150 std::find(closeTjs.begin(), closeTjs.end(), inTraj) == closeTjs.end())
151 closeTjs.push_back(inTraj);
156 tp.Delta =
PointTrajDOCA(slc, tp.HitPos[0], tp.HitPos[1], tp);
158 tj.
Pts.push_back(tp);
161 if (tj.
Pts.empty())
return;
165 myprt <<
"MHTj: T" << muTj.
ID <<
" npts " << tj.
Pts.size() <<
" close";
166 for (
auto tid : closeTjs)
167 myprt <<
" T" << tid;
171 slc.
tjs.push_back(tj);
209 for (
auto& tj : slc.
tjs) {
210 if (tj.AlgMod[
kKilled])
continue;
217 std::vector<int> temp;
218 for (
auto& vx3 : slc.
vtx3s) {
219 if (vx3.ID == 0)
continue;
222 temp.push_back(vx3.ID);
224 if (temp.empty())
return;
227 std::vector<int> masterlist;
228 for (
auto vx3id : temp) {
229 auto& vx3 = slc.
vtx3s[vx3id - 1];
232 for (
auto tjid : tjlist) {
233 auto& tj = slc.
tjs[tjid - 1];
234 if (tj.ParentID != 0) tj.ParentID = 0;
235 if (std::find(masterlist.begin(), masterlist.end(), tjid) == masterlist.end())
236 masterlist.push_back(tjid);
241 myprt <<
"DTP: masterlist Tjs";
242 for (
auto tjid : masterlist)
243 myprt <<
" " << tjid;
247 std::vector<SortEntry> sortVec(temp.size());
248 for (
unsigned short indx = 0; indx < temp.size(); ++indx) {
249 auto& vx3 = slc.
vtx3s[temp[indx] - 1];
250 sortVec[indx].index = indx;
251 sortVec[indx].val = vx3.Score;
253 if (sortVec.size() > 1) std::sort(sortVec.begin(), sortVec.end(),
valDecreasing);
256 for (
unsigned short indx = 0; indx < temp.size(); ++indx)
257 vlist[indx] = temp[sortVec[indx].
index];
261 auto& vx3 = slc.
vtx3s[vlist[0] - 1];
267 auto& sf = neutrinoPFP.SectionFits[0];
273 neutrinoPFP.PDGCode = 14;
274 neutrinoPFP.Vx3ID[1] = vx3.ID;
275 neutrinoPFP.Vx3ID[0] = vx3.ID;
278 if (!
StorePFP(slc, neutrinoPFP))
return;
282 std::vector<bool> lookedAt3(slc.
vtx3s.size() + 1,
false);
283 std::vector<bool> lookedAt2(slc.
vtxs.size() + 1,
false);
285 std::vector<std::pair<int, int>> pardtr;
287 for (
unsigned short indx = 0; indx < vlist.size(); ++indx) {
288 auto& vx3 = slc.
vtx3s[vlist[indx] - 1];
289 if (lookedAt3[vx3.ID])
continue;
291 lookedAt3[vx3.ID] =
true;
295 if (primTjList.empty())
continue;
297 for (
auto primTjID : primTjList) {
298 auto& primTj = slc.
tjs[primTjID - 1];
300 if (primTj.ParentID != -1)
continue;
301 if (prt)
mf::LogVerbatim(
"TC") <<
"Vx3 " << vx3.ID <<
" Primary tj " << primTj.ID;
306 for (
unsigned short end = 0;
end < 2; ++
end) {
307 if (primTj.VtxID[
end] == 0)
continue;
308 auto& vx2 = slc.
vtxs[primTj.VtxID[
end] - 1];
309 if (vx2.Vx3ID == vx3.ID)
continue;
312 for (
auto dtrID : dtrList) {
314 if (dtrID == primTjID)
continue;
315 auto& dtj = slc.
tjs[dtrID - 1];
316 if (dtj.ParentID != -1)
continue;
317 pardtr.push_back(std::make_pair(primTjID, dtrID));
318 if (prt)
mf::LogVerbatim(
"TC") <<
" primTj " << primTjID <<
" dtrID " << dtrID;
322 for (
unsigned short end = 0;
end < 2; ++
end) {
323 if (primTj.VtxID[
end] == 0)
continue;
324 auto& vx2 = slc.
vtxs[primTj.VtxID[
end] - 1];
328 if (pardtr.empty())
continue;
332 for (
auto pdtr : pardtr)
333 myprt <<
" " << pdtr.first <<
"_" << pdtr.second;
337 for (
unsigned short nit = 0; nit < 100; ++nit) {
338 auto lastPair = pardtr[pardtr.size() - 1];
339 auto& dtj = slc.
tjs[lastPair.second - 1];
340 dtj.ParentID = lastPair.first;
343 unsigned short dpt = 0, ppt = 0;
344 auto& ptj = slc.
tjs[lastPair.first - 1];
348 if (prt)
mf::LogVerbatim(
"TC") <<
"Set parent " << ptj.ID <<
" dtr " << dtj.ID;
352 for (
unsigned short end = 0;
end < 2; ++
end) {
353 if (dtj.VtxID[
end] == 0)
continue;
354 auto& vx2 = slc.
vtxs[dtj.VtxID[
end] - 1];
355 if (lookedAt2[vx2.ID])
continue;
356 lookedAt2[vx2.ID] =
true;
358 for (
auto tjid : tjlist) {
359 if (tjid == dtj.ID || tjid == ptj.ID)
continue;
360 pardtr.push_back(std::make_pair(dtj.ID, tjid));
363 myprt <<
" add par_dtr";
364 for (
auto pdtr : pardtr)
365 myprt <<
" " << pdtr.first <<
"_" << pdtr.second;
369 if (pardtr.empty())
break;
373 for (
auto tjid : masterlist) {
374 auto& tj = slc.
tjs[tjid - 1];
375 if (tj.ParentID < 0) tj.ParentID = tj.ID;
385 if (tjIDs.size() < 2)
return 1;
386 std::vector<float> plnchg(slc.
nPlanes);
387 for (
auto tjid : tjIDs) {
388 if (tjid <= 0 || tjid > (
int)slc.
tjs.size())
return 1;
389 auto& tj = slc.
tjs[tjid - 1];
392 plnchg[plane] += tj.TotChg;
396 for (
unsigned short plane = 0; plane < slc.
nPlanes; ++plane) {
397 if (plnchg[plane] == 0)
continue;
398 aveChg += plnchg[plane];
401 if (cnt < 2)
return 1;
404 for (
unsigned short plane = 0; plane < slc.
nPlanes; ++plane) {
406 if (plnchg[plane] == 0)
continue;
407 float asym =
std::abs(plnchg[plane] - aveChg) / (plnchg[plane] + aveChg);
408 if (asym > maxAsym) maxAsym = asym;
424 std::array<int, 5> codeList = {{0, 11, 13, 111, 211}};
425 unsigned short codeIndex = 0;
426 if (tjIDs.empty())
return codeList[codeIndex];
428 std::array<unsigned short, 5> cnts;
431 for (
auto tjid : tjIDs) {
432 if (tjid <= 0 || tjid > (
int)slc.
tjs.size())
continue;
433 auto& tj = slc.
tjs[tjid - 1];
434 for (
unsigned short ii = 0; ii < 5; ++ii)
435 if (tj.PDGCode == codeList[ii]) ++cnts[ii];
437 if (len > maxLen) maxLen = len;
441 for (
unsigned short ii = 1; ii < 5; ++ii) {
442 if (cnts[ii] > maxCnt) {
447 return codeList[codeIndex];
459 if (primID <= 0 || primID > (
int)slc.
tjs.size())
return -1;
462 auto& ptj = slc.
tjs[primID - 1];
463 for (
unsigned short end = 0;
end < 2; ++
end) {
464 if (ptj.VtxID[
end] == 0)
continue;
465 auto& vx2 = slc.
vtxs[ptj.VtxID[
end] - 1];
466 if (vx2.Vx3ID == 0)
continue;
467 auto& vx3 = slc.
vtx3s[vx2.Vx3ID - 1];
468 if (vx3.Neutrino)
return primID;
483 for (
unsigned short nit = 0; nit < 10; ++nit) {
484 if (parid < 1 || parid > (
int)slc.
tjs.size())
break;
485 auto& tj = slc.
tjs[parid - 1];
501 int dtruid = pfp.
UID;
502 unsigned short nit = 0;
505 auto&
parent =
slices[slcIndx.first].pfps[slcIndx.second];
507 if (
parent.PDGCode == 14 ||
parent.PDGCode == 12)
return dtruid;
512 paruid =
parent.ParentUID;
513 if (paruid < 0)
return 0;
515 if (nit == 10)
return 0;
524 if (mtjid > (
int)slc.
tjs.size())
return false;
525 auto& mtj = slc.
tjs[mtjid - 1];
528 for (
auto tjid : pfp.
TjIDs) {
529 auto& otj = slc.
tjs[tjid - 1];
530 if (otj.CTP == mtj.CTP) {
535 if (otjid == 0)
return false;
537 int newtjid = slc.
tjs.size();
539 mf::LogVerbatim(
"TC") <<
"MergeTjIntoPFP: merged T" << otjid <<
" with T" << mtjid
540 <<
" -> T" << newtjid;
541 std::replace(pfp.
TjIDs.begin(), pfp.
TjIDs.begin(), otjid, newtjid);
546 mf::LogVerbatim(
"TC") <<
"MergeTjIntoPFP: merge T" << otjid <<
" with T" << mtjid
559 if (tj.
AveChg <= 0)
return 100;
561 unsigned short closePt = USHRT_MAX;
563 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
564 auto& tp = tj.
Pts[ipt];
565 float sep2 =
PosSep2(pos, tp.Pos);
566 if (sep2 > close)
continue;
570 if (closePt == USHRT_MAX)
return 100;
572 auto& tp = tj.
Pts[closePt];
575 float posErr = tp.DeltaRMS;
576 if (tp.AngErr > 0 && close > 10) posErr += sqrt(tp.AngErr * sqrt(close));
577 if (posErr < 0.1) posErr = 0.1;
578 float posPull = delta / posErr;
580 if (chgErr < 0.15) chgErr = 0.15;
583 return 0.5 * (posPull + chgPull);
602 if (tjIDs.size() < 2)
return false;
603 unsigned short lasttj = tjIDs[tjIDs.size() - 1] - 1;
604 auto& mtj = slc.
tjs[lasttj];
605 bool mtjIsShort = (mtj.Pts.size() < 5);
607 std::array<float, 2> minsep2{{1000, 1000}};
609 std::array<int, 2> minsepTj{{0, 0}};
611 std::array<unsigned short, 2> minsepPt;
614 std::array<unsigned short, 2> minsepEnd;
615 for (
auto tjid : tjIDs) {
616 auto& tj = slc.
tjs[tjid - 1];
617 if (tj.CTP != mtj.CTP)
continue;
618 if (tj.ID == mtj.ID)
continue;
619 for (
unsigned short mend = 0; mend < 2; ++mend) {
620 Point2_t mendPos = mtj.Pts[mtj.EndPt[mend]].Pos;
621 float sep2 = minsep2[mend];
622 unsigned short closePt = 0;
624 minsep2[mend] = sep2;
625 minsepTj[mend] = tjid;
626 minsepPt[mend] = closePt;
629 short dend0 =
abs((
short)closePt - tj.EndPt[0]);
630 short dend1 =
abs((
short)closePt - tj.EndPt[1]);
631 if (dend0 < dend1 && dend0 < 3) minsepEnd[mend] = 0;
632 if (dend1 < dend0 && dend1 < 3) minsepEnd[mend] = 1;
638 bool isCompatible = (minsepEnd[0] != 2 && minsepEnd[1] != 2);
640 if (isCompatible && mtjIsShort) {
641 float minminsep = minsep2[0];
642 if (minsep2[1] < minminsep) minminsep = minsep2[1];
644 isCompatible = minminsep < 5;
648 myprt <<
"CompatibleMerge: T" << mtj.ID <<
" end";
649 for (
unsigned short end = 0;
end < 2; ++
end)
650 myprt <<
" T" << minsepTj[
end] <<
"_I" << minsepPt[
end] <<
"_E" << minsepEnd[
end]
651 <<
" minsep " << sqrt(minsep2[
end]);
652 myprt <<
" Compatible? " << isCompatible;
666 if (tj1.
CTP != tj2.
CTP)
return false;
667 unsigned short end1 = -1, end2 = 0;
670 if (len2 < minLen) minLen = len2;
672 if (minLen > 10) minLen = 10;
673 for (
unsigned short e1 = 0; e1 < 2; ++e1) {
675 for (
unsigned short e2 = 0; e2 < 2; ++e2) {
677 float sep =
PosSep(tp1.Pos, tp2.Pos);
685 if (end1 < 0)
return false;
687 if (end2 != 1 - end1)
return false;
690 if (overlapFraction > 0.25) {
693 << overlapFraction <<
" > 0.25 ";
697 auto& tp1 = tj1.
Pts[tj1.
EndPt[end1]];
698 auto& tp2 = tj2.
Pts[tj2.
EndPt[end2]];
699 float doca1 =
PointTrajDOCA(slc, tp1.Pos[0], tp1.Pos[1], tp2);
700 float doca2 =
PointTrajDOCA(slc, tp2.Pos[0], tp2.Pos[1], tp1);
701 if (doca1 > 2 && doca2 > 2) {
725 float maxWire = -1E6;
728 for (
auto& tp : tj1.
Pts) {
729 if (tp.Chg == 0)
continue;
730 if (tp.Pos[0] < 0)
continue;
731 if (tp.Pos[0] < minWire) minWire = tp.Pos[0];
732 if (tp.Pos[0] > maxWire) maxWire = tp.Pos[0];
735 if (cnt1 == 0)
return 0;
737 for (
auto& tp : tj2.
Pts) {
738 if (tp.Chg == 0)
continue;
739 if (tp.Pos[0] < 0)
continue;
740 if (tp.Pos[0] < minWire) minWire = tp.Pos[0];
741 if (tp.Pos[0] > maxWire) maxWire = tp.Pos[0];
744 if (cnt2 == 0)
return 0;
745 int span = maxWire - minWire;
746 if (span <= 0)
return 0;
747 std::vector<unsigned short> wcnt(span);
748 for (
auto& tp : tj1.
Pts) {
749 if (tp.Chg == 0)
continue;
750 if (tp.Pos[0] < -0.4)
continue;
751 int indx = std::nearbyint(tp.Pos[0] - minWire);
752 if (indx < 0 || indx > span - 1)
continue;
755 for (
auto& tp : tj2.
Pts) {
756 if (tp.Chg == 0)
continue;
757 if (tp.Pos[0] < -0.4)
continue;
758 int indx = std::nearbyint(tp.Pos[0] - minWire);
759 if (indx < 0 || indx > span - 1)
continue;
762 float cntOverlap = 0;
763 for (
auto cnt : wcnt)
764 if (cnt > 1) ++cntOverlap;
765 if (cnt1 < cnt2) {
return cntOverlap / cnt1; }
767 return cntOverlap / cnt2;
804 if (angle > M_PI) angle = M_PI;
805 if (angle < -M_PI) angle = M_PI;
806 if (angle < 0) angle = -angle;
807 if (angle > M_PI / 2) angle = M_PI - angle;
819 unsigned short originPt = tj.
EndPt[1];
820 unsigned short npts = tj.
Pts[originPt].NTPsFit;
822 unsigned short fitDir = -1;
823 FitTraj(slc, tj, originPt, npts, fitDir, tpFit);
824 tj.
Pts[originPt] = tpFit;
832 unsigned short originPt,
852 if (originPt > tj.
Pts.size() - 1) {
853 mf::LogWarning(
"TC") <<
"FitTraj: Requesting fit of invalid TP " << originPt;
858 tpFit = tj.
Pts[originPt];
861 if (fitDir < -1 || fitDir > 1)
return;
863 std::vector<double>
x,
y;
866 if (tj.
Pts[originPt].Chg == 0) origin = tj.
Pts[originPt].Pos;
870 for (
unsigned short ipt = tj.
EndPt[0]; ipt < tj.
EndPt[1]; ++ipt) {
871 if (tj.
Pts[ipt].Chg <= 0)
continue;
872 double xx = tj.
Pts[ipt].HitPos[0] - origin[0];
873 double yy = tj.
Pts[ipt].HitPos[1] - origin[1];
877 if (x.size() != 2)
return;
880 tpFit.
Ang = M_PI / 2;
881 if (y[1] < y[0]) tpFit.
Ang = -tpFit.
Ang;
884 double dx = x[1] - x[0];
885 double dy = y[1] - y[0];
886 tpFit.
Ang = atan2(dy, dx);
888 tpFit.
Dir[0] = cos(tpFit.
Ang);
889 tpFit.
Dir[1] = sin(tpFit.
Ang);
890 tpFit.
Pos[0] += origin[0];
891 tpFit.
Pos[1] += origin[1];
898 std::vector<double>
w, q;
899 std::array<double, 2>
dir;
900 double xx, yy, xr, yr;
905 double rotAngle = tj.
Pts[originPt].Ang;
906 double cs = cos(-rotAngle);
907 double sn = sin(-rotAngle);
910 if (tj.
Pts[originPt].Chg > 0) {
911 xx = tj.
Pts[originPt].HitPos[0] - origin[0];
912 yy = tj.
Pts[originPt].HitPos[1] - origin[1];
913 xr = cs * xx - sn * yy;
914 yr = sn * xx + cs * yy;
917 chgWt = tj.
Pts[originPt].ChgPull;
918 if (chgWt < 1) chgWt = 1;
920 w.push_back(chgWt * tj.
Pts[originPt].HitPosErr2);
924 if (fitDir != 0) --npts;
928 unsigned short cnt = 0;
929 for (
unsigned short ipt = originPt + 1; ipt < tj.
Pts.size(); ++ipt) {
930 if (tj.
Pts[ipt].Chg <= 0)
continue;
931 xx = tj.
Pts[ipt].HitPos[0] - origin[0];
932 yy = tj.
Pts[ipt].HitPos[1] - origin[1];
933 xr = cs * xx - sn * yy;
934 yr = sn * xx + cs * yy;
937 chgWt = tj.
Pts[ipt].ChgPull;
938 if (chgWt < 1) chgWt = 1;
940 w.push_back(chgWt * tj.
Pts[ipt].HitPosErr2);
942 if (cnt == npts)
break;
947 if (fitDir != 1 && originPt > 0) {
948 unsigned short cnt = 0;
949 for (
unsigned short ii = 1; ii < tj.
Pts.size(); ++ii) {
950 unsigned short ipt = originPt - ii;
951 if (ipt > tj.
Pts.size() - 1)
continue;
952 if (tj.
Pts[ipt].Chg == 0)
continue;
953 xx = tj.
Pts[ipt].HitPos[0] - origin[0];
954 yy = tj.
Pts[ipt].HitPos[1] - origin[1];
955 xr = cs * xx - sn * yy;
956 yr = sn * xx + cs * yy;
959 chgWt = tj.
Pts[ipt].ChgPull;
960 if (chgWt < 1) chgWt = 1;
962 w.push_back(chgWt * tj.
Pts[ipt].HitPosErr2);
964 if (cnt == npts)
break;
970 if (x.size() < 2)
return;
981 for (
unsigned short ipt = 0; ipt < x.size(); ++ipt) {
982 if (w[ipt] < 0.00001) w[ipt] = 0.00001;
985 sumx += wght * x[ipt];
986 sumy += wght * y[ipt];
987 sumx2 += wght * x[ipt] * x[ipt];
988 sumy2 += wght * y[ipt] * y[ipt];
989 sumxy += wght * x[ipt] * y[ipt];
992 double delta = sum * sumx2 - sumx * sumx;
993 if (delta == 0)
return;
995 double A = (sumx2 * sumy - sumx * sumxy) / delta;
997 double B = (sumxy * sum - sumx * sumy) / delta;
1002 double newang = atan(B);
1003 dir[0] = cos(newang);
1004 dir[1] = sin(newang);
1008 tpFit.
Dir[0] = cs * dir[0] - sn * dir[1];
1009 tpFit.
Dir[1] = sn * dir[0] + cs * dir[1];
1011 bool flipDir =
false;
1013 flipDir = std::signbit(tpFit.
Dir[1]) != std::signbit(tj.
Pts[originPt].Dir[1]);
1016 flipDir = std::signbit(tpFit.
Dir[0]) != std::signbit(tj.
Pts[originPt].Dir[0]);
1019 tpFit.
Dir[0] = -tpFit.
Dir[0];
1020 tpFit.
Dir[1] = -tpFit.
Dir[1];
1022 tpFit.
Ang = atan2(tpFit.
Dir[1], tpFit.
Dir[0]);
1026 tpFit.
Pos[0] = -sn * A + origin[0];
1027 tpFit.
Pos[1] = cs * A + origin[1];
1031 if (x.size() < 3)
return;
1034 double ndof = x.size() - 2;
1036 (sumy2 + A * A * sum + B * B * sumx2 - 2 * (A * sumy + B * sumxy - A * B * sumx)) / ndof;
1040 double slopeError = sqrt(varnce * sum / delta);
1049 for (
unsigned short ii = 0; ii < y.size(); ++ii) {
1050 arg = y[ii] - A - B * x[ii];
1051 sum += arg * arg / w[ii];
1053 tpFit.
FitChi = sum / ndof;
1060 if (slc.
pfps.empty())
return USHRT_MAX;
1061 for (
unsigned int ipfp = 0; ipfp < slc.
pfps.size(); ++ipfp) {
1062 const auto& pfp = slc.
pfps[ipfp];
1063 if (std::find(pfp.TjIDs.begin(), pfp.TjIDs.end(), tjID) != pfp.TjIDs.end())
return ipfp;
1073 for (
auto& tp : tj.
Pts) {
1074 for (
auto iht : tp.Hits) {
1086 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
1101 for (
auto& tp : tj.
Pts) {
1102 if (tp.Hits.size() > 16)
return false;
1115 unsigned short npts = tj.
EndPt[1] - tj.
EndPt[0] + 1;
1116 if (npts < 2)
return false;
1118 auto& endTp0 = tj.
Pts[tj.
EndPt[0]];
1119 auto& endTp1 = tj.
Pts[tj.
EndPt[1]];
1123 if (endTp0.AngErr == 0.1 && endTp1.AngErr != 0.1) { endTp0.AngErr = endTp1.AngErr; }
1124 else if (endTp0.AngErr != 0.1 && endTp1.AngErr == 0.1) {
1125 endTp1.AngErr = endTp0.AngErr;
1131 if (endTp0.AveChg <= 0) {
1132 unsigned short cnt = 0;
1134 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
1135 if (tj.
Pts[ipt].Chg == 0)
continue;
1136 sum += tj.
Pts[ipt].Chg;
1138 if (cnt == 4)
break;
1140 tj.
Pts[tj.
EndPt[0]].AveChg = sum / (float)cnt;
1142 if (endTp1.AveChg <= 0 && npts < 5) endTp1.AveChg = endTp0.AveChg;
1143 if (endTp1.AveChg <= 0) {
1145 unsigned short cnt = 0;
1146 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
1147 short ipt = tj.
EndPt[1] - ii;
1149 if (tj.
Pts[ipt].Chg == 0)
continue;
1150 sum += tj.
Pts[ipt].Chg;
1152 if (cnt == 4)
break;
1153 if (ipt == 0)
break;
1155 tj.
Pts[tj.
EndPt[1]].AveChg = sum / (float)cnt;
1162 if (npts > 2 * nPtsFit) {
1163 for (
unsigned short ipt = tj.
EndPt[0] + nPtsFit; ipt < tj.
EndPt[1] - nPtsFit; ++ipt) {
1164 auto& tp = tj.
Pts[ipt];
1165 if (tp.KinkSig < 0) tp.KinkSig =
KinkSignificance(slc, tj, ipt, nPtsFit, useChg,
false);
1172 int trID = slc.
tjs.size() + 1;
1174 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
1175 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
1176 if (tj.
Pts[ipt].UseHit[ii]) {
1177 unsigned int iht = tj.
Pts[ipt].Hits[ii];
1178 if (iht > slc.
slHits.size() - 1) {
1182 if (slc.
slHits[iht].InTraj > 0) {
1186 slc.
slHits[iht].InTraj = trID;
1192 for (
unsigned int iht = 0; iht < slc.
slHits.size(); ++iht) {
1193 if (slc.
slHits[iht].InTraj == tj.
ID) {
1195 <<
" thinks it belongs to T" << tj.
ID <<
" but it isn't in the Tj\n";
1207 slc.
tjs.push_back(tj);
1210 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
1211 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
1212 unsigned int iht = tj.
Pts[ipt].Hits[ii];
1214 std::cout <<
"Debug hit appears in trajectory w WorkID " << tj.
WorkID <<
" UseHit " 1215 << tj.
Pts[ipt].UseHit[ii] <<
"\n";
1229 unsigned short originPt,
1230 unsigned short npts,
1233 unsigned short usePar)
1240 if (originPt > tj.
Pts.size() - 1)
return;
1241 if (fitDir != 1 && fitDir != -1)
return;
1245 Fit2D(0, inPt, pErr, outVec, outVecErr, chiDOF);
1246 unsigned short cnt = 0;
1247 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
1248 unsigned short ipt = originPt + ii * fitDir;
1249 if (ipt < tj.
EndPt[0] || ipt > tj.
EndPt[1])
break;
1250 auto& tp = tj.
Pts[ipt];
1251 if (tp.Chg <= 0)
continue;
1253 inPt[0] =
std::abs(tp.Pos[0] - tj.
Pts[originPt].Pos[0]);
1254 float parVal = tp.Chg;
1256 pErr = 0.1 * parVal;
1260 pErr = sqrt(tp.HitPosErr2);
1264 if (!
Fit2D(2, inPt, pErr, outVec, outVecErr, chiDOF))
break;
1266 if (cnt == npts)
break;
1268 if (cnt < npts)
return;
1270 if (!
Fit2D(-1, inPt, pErr, outVec, outVecErr, chiDOF))
return;
1271 pFit.
Pos = tj.
Pts[originPt].Pos;
1272 pFit.
Par0 = outVec[0];
1273 pFit.
AvePar /= (float)cnt;
1274 pFit.
ParErr = outVecErr[0];
1275 pFit.
Pos = tj.
Pts[originPt].Pos;
1290 unsigned short itj = 0;
1291 std::vector<unsigned int> tHits;
1292 std::vector<unsigned int> atHits;
1293 for (
auto& tj : slc.
tjs) {
1295 if (tj.AlgMod[
kKilled])
continue;
1298 if (tHits.size() < 2)
continue;
1299 std::sort(tHits.begin(), tHits.end());
1301 for (iht = 0; iht < slc.
slHits.size(); ++iht) {
1302 if (slc.
slHits[iht].InTraj == tID) atHits.push_back(iht);
1304 if (atHits.size() < 2)
continue;
1305 if (!std::equal(tHits.begin(), tHits.end(), atHits.begin())) {
1307 myprt << someText <<
" ChkInTraj failed: inTraj - UseHit mis-match for T" << tID
1308 <<
" tj.WorkID " << tj.WorkID <<
" atHits size " << atHits.size() <<
" tHits size " 1309 << tHits.size() <<
" in CTP " << tj.CTP <<
"\n";
1310 myprt <<
"AlgMods: ";
1311 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
1312 if (tj.AlgMod[ib]) myprt <<
" " <<
AlgBitNames[ib];
1314 myprt <<
"index inTraj UseHit \n";
1315 for (iht = 0; iht < atHits.size(); ++iht) {
1316 myprt <<
"iht " << iht <<
" " <<
PrintHit(slc.
slHits[atHits[iht]]);
1317 if (iht < tHits.size()) myprt <<
" " <<
PrintHit(slc.
slHits[tHits[iht]]);
1318 if (atHits[iht] != tHits[iht]) myprt <<
" <<< " << atHits[iht] <<
" != " << tHits[iht];
1321 if (tHits.size() > atHits.size()) {
1322 for (iht = atHits.size(); iht < atHits.size(); ++iht) {
1323 myprt <<
"atHits " << iht <<
" " <<
PrintHit(slc.
slHits[atHits[iht]]) <<
"\n";
1330 for (
unsigned short end = 0;
end < 2; ++
end) {
1331 if (tj.VtxID[
end] > slc.
vtxs.size()) {
1332 mf::LogVerbatim(
"TC") << someText <<
" ChkInTraj: Bad VtxID " << tj.ID;
1357 if (itj > slc.
tjs.size() - 1)
return;
1358 auto& tj = slc.
tjs[itj];
1361 if (tj.EndFlag[0][
kBragg])
return;
1364 if (tj.Pts.size() < 20)
return;
1369 float chg2 = tj.Pts[tj.EndPt[0] + 2].AveChg;
1371 float chg15 = tj.Pts[tj.EndPt[0] + 15].AveChg;
1372 if (chg2 < 3 * chg15)
return;
1375 float midChg = 0.5 * (chg2 + chg15);
1377 unsigned short breakPt = USHRT_MAX;
1378 for (
unsigned short ipt = tj.EndPt[0] + 3; ipt < 15; ++ipt) {
1379 float chgm2 = tj.Pts[ipt - 2].Chg;
1380 if (chgm2 == 0)
continue;
1381 float chgm1 = tj.Pts[ipt - 1].Chg;
1382 if (chgm1 == 0)
continue;
1383 float chgp1 = tj.Pts[ipt + 1].Chg;
1384 if (chgp1 == 0)
continue;
1385 float chgp2 = tj.Pts[ipt + 2].Chg;
1386 if (chgp2 == 0)
continue;
1387 if (chgm2 > midChg && chgm1 > midChg && chgp1 < midChg && chgp2 < midChg) {
1392 if (breakPt == USHRT_MAX)
return;
1394 std::array<double, 2> cnt, sum, sum2;
1395 for (
unsigned short ipt = tj.EndPt[0]; ipt <= tj.EndPt[1]; ++ipt) {
1396 auto& tp = tj.Pts[ipt];
1397 if (tp.Chg <= 0)
continue;
1398 unsigned short end = 0;
1399 if (ipt > breakPt) end = 1;
1402 sum2[
end] += tp.Chg * tp.Chg;
1404 for (
unsigned short end = 0;
end < 2; ++
end) {
1405 if (cnt[
end] < 3)
return;
1406 double ave = sum[
end] / cnt[
end];
1407 double arg = sum2[
end] - cnt[
end] * ave * ave;
1408 if (arg <= 0)
return;
1409 sum2[
end] = sqrt(arg / (cnt[
end] - 1));
1413 bool doSplit =
true;
1416 if (tj.ChgRMS > 0.5 && sum2[0] > 0.3 && sum2[1] > 0.3) doSplit =
false;
1419 myprt <<
"CTBC: T" << tj.ID <<
" chgRMS " << tj.ChgRMS;
1420 myprt <<
" AveChg before split point " << (
int)sum[0] <<
" rms " << sum2[0];
1421 myprt <<
" after " << (
int)sum[1] <<
" rms " << sum2[1] <<
" doSplit? " << doSplit;
1423 if (!doSplit)
return;
1426 aVtx.
Pos = tj.Pts[breakPt].Pos;
1428 aVtx.
Pass = tj.Pass;
1432 aVtx.
ID = slc.
vtxs.size() + 1;
1434 unsigned short ivx = slc.
vtxs.size();
1436 if (!
SplitTraj(slc, itj, breakPt, ivx, prt)) {
1446 <<
PrintPos(slc, tj.Pts[breakPt].Pos) <<
"\n";
1456 if (itj > slc.
tjs.size() - 1)
return false;
1460 auto& tj = slc.
tjs[itj];
1462 if (npwc < 4)
return false;
1463 if (npwc < nPtsToCheck) nPtsToCheck = npwc;
1466 unsigned short maxPullPt = USHRT_MAX;
1467 for (
unsigned short ipt = tj.EndPt[0]; ipt < tj.EndPt[1]; ++ipt) {
1468 auto& tp = tj.Pts[ipt];
1469 if (tp.ChgPull < maxPull)
continue;
1470 maxPull = tp.ChgPull;
1473 if (maxPullPt == USHRT_MAX)
return false;
1475 if (maxPullPt < 0.5 * (tj.EndPt[0] + tj.EndPt[1])) { dpt = maxPullPt - tj.EndPt[0]; }
1477 dpt = tj.EndPt[1] - maxPullPt;
1479 if (dpt < 3)
return false;
1482 mf::LogVerbatim(
"TC") <<
"BS: T" << tj.ID <<
" maxPull " << maxPull <<
" at " 1483 <<
PrintPos(slc, tj.Pts[maxPullPt]) <<
" dpt " << dpt;
1484 unsigned short breakPt = USHRT_MAX;
1486 unsigned short bestBragg = 0;
1490 for (
unsigned short ipt = maxPullPt - 2; ipt <= maxPullPt + 2; ++ipt) {
1491 FitTraj(slc, tj, ipt - 1, nPtsFit, -1, tp1);
1492 if (tp1.
FitChi > 10)
continue;
1493 FitTraj(slc, tj, ipt + 1, nPtsFit, 1, tp2);
1494 if (tp2.
FitChi > 10)
continue;
1496 FitPar(slc, tj, ipt - 1, nPtsToCheck, -1, chgFit1, 1);
1497 if (chgFit1.
ChiDOF > 100)
continue;
1499 FitPar(slc, tj, ipt + 1, nPtsToCheck, 1, chgFit2, 1);
1500 if (chgFit2.
ChiDOF > 100)
continue;
1505 unsigned short bragg = 1;
1506 float bchi = chgFit1.
ChiDOF;
1513 if (bchi < 1) bchi = 1;
1514 float fom = 10 * dang * chgAsym * slpAsym / bchi;
1518 myprt <<
" chg1 " << (
int)chgFit1.
Par0 <<
" slp " << chgFit1.
ParSlp <<
" chi " 1520 myprt <<
" chg2 " << (
int)chgFit2.
Par0 <<
" slp " << chgFit2.
ParSlp <<
" chi " 1522 myprt <<
" chgAsym " << chgAsym;
1523 myprt <<
" slpAsym " << slpAsym;
1524 myprt <<
" fom " << fom;
1525 myprt <<
" bragg " << bragg;
1527 if (fom < bestFOM)
continue;
1532 if (breakPt == USHRT_MAX)
return false;
1538 aVtx.
Pos = tj.Pts[breakPt].Pos;
1540 aVtx.
Pass = tj.Pass;
1544 aVtx.
ID = slc.
vtxs.size() + 1;
1546 unsigned short ivx = slc.
vtxs.size();
1548 if (!
SplitTraj(slc, itj, breakPt, ivx, prt)) {
1555 unsigned short otj = slc.
tjs.size() - 1;
1556 if (bestBragg == 2)
std::swap(itj, otj);
1557 slc.
tjs[itj].PDGCode = 211;
1559 slc.
tjs[otj].PDGCode = 13;
1570 if (tj.
PDGCode == 111)
return;
1573 if (npwc < 50)
return;
1579 if (nPtsMax > 8) nPtsMax = 8;
1584 unsigned short firstBad = USHRT_MAX;
1585 for (
unsigned short ii = 0; ii < nPtsMax; ++ii) {
1586 unsigned short ipt = tj.
EndPt[1] - nPtsMax + ii;
1587 auto& tp = tj.
Pts[ipt];
1588 if (tp.Chg <= 0)
continue;
1589 if (tp.ChgPull < 3)
continue;
1591 if (firstBad == USHRT_MAX) firstBad = ipt;
1593 if (firstBad == USHRT_MAX)
return;
1595 float cntTot = tj.
EndPt[1] - firstBad;
1597 float fracBad = cntBad / cntTot;
1598 if (fracBad < 0.5)
return;
1601 for (
unsigned short ipt = firstBad; ipt <= tj.
EndPt[1]; ++ipt)
1611 const std::vector<float>& fQualityCuts,
1624 if (tj.
PDGCode == 111)
return;
1628 short minPts = fQualityCuts[1];
1629 if (minPts < 1)
return;
1630 if (npwc < minPts)
return;
1632 if (npwc < 8)
return;
1635 if (npwc == minPts + 1) {
1636 unsigned short endPt1 = tj.
EndPt[1];
1637 auto& tp = tj.
Pts[endPt1];
1638 auto& ptp = tj.
Pts[endPt1 - 1];
1641 float dwire =
std::abs(ptp.Pos[0] - tp.Pos[0]);
1642 if (ptp.Chg == 0 || dwire > 1.1) {
1652 for (lastPt = tj.
EndPt[1]; lastPt >= minPts; --lastPt) {
1654 if (lastPt == 1)
break;
1655 if (tj.
Pts[lastPt].Chg == 0)
continue;
1657 unsigned short nadj = 0;
1658 unsigned short npwc = 0;
1659 for (
short ipt = lastPt - minPts; ipt < lastPt; ++ipt) {
1662 auto& tp = tj.
Pts[ipt];
1664 auto& ptp = tj.
Pts[ipt - 1];
1665 if (tp.Chg > 0 && ptp.Chg > 0) {
1667 if (
std::abs(tp.Pos[0] - ptp.Pos[0]) < 1.5) ++nadj;
1672 float hitFrac = ntpwc /
nwires;
1674 mf::LogVerbatim(
"TC") << fcnLabel <<
"-TEP: T" << tj.
ID <<
" lastPt " << lastPt <<
" npwc " 1675 << npwc <<
" ntpwc " << ntpwc <<
" nadj " << nadj <<
" hitFrac " 1677 if (hitFrac > fQualityCuts[0] && npwc == minPts && nadj >= minPts - 1)
break;
1682 if (tj.
Pts[lastPt].Pos[0] > -0.4) {
1683 unsigned int prevWire = std::nearbyint(tj.
Pts[lastPt].Pos[0]);
1684 if (tj.
StepDir > 0) { --prevWire; }
1689 mf::LogVerbatim(
"TC") << fcnLabel <<
"-TEP: is prevWire " << prevWire <<
" dead? ";
1696 if (lastPt == tj.
EndPt[1]) {
1702 for (
unsigned short ipt = lastPt + 1; ipt <= tj.
EndPt[1]; ++ipt)
1707 fcnLabel +=
"-TEPo";
1719 if (tj.
PDGCode == 111)
return;
1725 unsigned short withNptsFit = 0;
1728 for (
unsigned short nptsf = 3; nptsf < nPtsFit; ++nptsf) {
1729 unsigned short ipt = tj.
EndPt[1] - nptsf;
1733 withNptsFit = nptsf;
1736 if (withNptsFit > 0) {
1737 unsigned short ipt = tj.
EndPt[1] - withNptsFit;
1738 std::cout <<
"CEK: T" << tj.
ID <<
" ipt " << ipt;
1740 auto& tp = tj.
Pts[ipt];
1741 std::cout <<
" " <<
PrintPos(slc, tp) <<
" withNptsFit " << withNptsFit <<
" ks " << ks
1756 if (tj.
PDGCode == 111)
return;
1757 unsigned short npts = tj.
EndPt[1] - tj.
EndPt[0];
1760 if (npts > 50)
return;
1762 if (npts < 8)
return;
1765 unsigned short atPt = 0;
1767 for (
unsigned short ipt = tj.
EndPt[0] + 2; ipt <= tj.
EndPt[1] - 2; ++ipt) {
1768 auto& tp = tj.
Pts[ipt];
1769 if (tp.ChgPull > bigPull) {
1770 bigPull = tp.ChgPull;
1774 if (atPt == 0)
return;
1776 if ((atPt - tj.
EndPt[0]) < 0.5 * npts)
return;
1779 <<
". Check charge asymmetry around it.";
1780 unsigned short nchk = 0;
1781 unsigned short npos = 0;
1782 unsigned short nneg = 0;
1783 for (
short ii = 1; ii < 5; ++ii) {
1784 short iplu = atPt + ii;
1785 if (iplu > tj.
EndPt[1])
break;
1786 short ineg = atPt - ii;
1787 if (ineg < tj.
EndPt[0])
break;
1788 if (tj.
Pts[iplu].Chg == 0)
continue;
1789 if (tj.
Pts[ineg].Chg == 0)
continue;
1790 float asym = (tj.
Pts[iplu].Chg - tj.
Pts[ineg].Chg) / (tj.
Pts[iplu].Chg + tj.
Pts[ineg].Chg);
1792 if (asym > 0.5) ++npos;
1793 if (asym < -0.5) ++nneg;
1795 mf::LogVerbatim(
"TC") <<
" ineg " << ineg <<
" iplu " << iplu <<
" asym " << asym
1796 <<
" nchk " << nchk;
1798 if (nchk < 3)
return;
1801 bool doTrim = (nneg > nchk) || (npos > nchk);
1802 if (!doTrim)
return;
1804 auto& prevTP = tj.
Pts[atPt - 1];
1805 if (
std::abs(prevTP.ChgPull) > 2) --atPt;
1806 for (
unsigned short ipt = atPt; ipt <= tj.
EndPt[1]; ++ipt)
1818 const float& MinWireSignalFraction)
1821 if (MinWireSignalFraction == 0)
return true;
1823 if (tp1.
Pos[0] < -0.4 || tp2.
Pos[0] < -0.4)
return false;
1824 int fromWire = std::nearbyint(tp1.
Pos[0]);
1825 int toWire = std::nearbyint(tp2.
Pos[0]);
1827 if (fromWire == toWire) {
1830 tp.
Pos[1] = 0.5 * (tp1.
Pos[1] + tp2.
Pos[1]);
1836 return SignalBetween(slc, tp, toWire, MinWireSignalFraction);
1854 if (tp.
Pos[0] < -0.4 || toPos0 < -0.4)
return 0;
1855 int fromWire = std::nearbyint(tp.
Pos[0]);
1856 int toWire = std::nearbyint(toPos0);
1858 if (fromWire == toWire)
return SignalAtTp(tp);
1860 int nWires =
abs(toWire - fromWire) + 1;
1865 if (toWire > fromWire && tp.
Dir[0] < 0) stepSize = -stepSize;
1866 if (toWire < fromWire && tp.
Dir[0] > 0) stepSize = -stepSize;
1869 for (
unsigned short cnt = 0; cnt < nWires; ++cnt) {
1872 tp.
Pos[0] += tp.
Dir[0] * stepSize;
1873 tp.
Pos[1] += tp.
Dir[1] * stepSize;
1875 float sigFrac = nsig /
num;
1882 const std::vector<unsigned int>& iHitsInMultiplet,
1883 const std::vector<unsigned int>& jHitsInMultiplet)
1887 if (iHitsInMultiplet.empty() || jHitsInMultiplet.empty())
return false;
1891 if (cvI < 0)
return false;
1894 for (
auto& iht : iHitsInMultiplet) {
1896 float cv =
hit.PeakTime();
1898 float arg = cv - 3.1 *
rms;
1899 if (arg < minI) minI = arg;
1900 arg = cv + 3.1 *
rms;
1901 if (arg > maxI) maxI = arg;
1905 if (cvJ < 0)
return false;
1908 for (
auto& jht : jHitsInMultiplet) {
1910 float cv =
hit.PeakTime();
1912 float arg = cv - 3.1 *
rms;
1913 if (arg < minJ) minJ = arg;
1914 arg = cv + 3.1 *
rms;
1915 if (arg > maxJ) maxJ = arg;
1919 if (maxI > minJ)
return true;
1922 if (minI < maxJ)
return true;
1932 if (iht > slc.
slHits.size() - 1)
return false;
1933 if (jht > slc.
slHits.size() - 1)
return false;
1937 int iwire = ihit.WireID().Wire;
1938 int jwire = jhit.WireID().Wire;
1939 if (
std::abs(iwire - jwire) > 1)
return false;
1940 if (ihit.PeakTime() > jhit.PeakTime()) {
1941 float minISignal = ihit.PeakTime() - 3 * ihit.RMS();
1942 float maxJSignal = jhit.PeakTime() + 3 * ihit.RMS();
1943 if (maxJSignal > minISignal)
return true;
1946 float maxISignal = ihit.PeakTime() + 3 * ihit.RMS();
1947 float minJSignal = jhit.PeakTime() - 3 * ihit.RMS();
1948 if (minJSignal > maxISignal)
return true;
1974 if (tp.
Pos[0] < -0.4)
return false;
1976 unsigned short pln = planeID.
Plane;
1977 unsigned int wire = std::nearbyint(tp.
Pos[0]);
1978 if (wire >
evt.
goodWire[pln].size() - 1)
return false;
1982 if (slc.
wireHitRange[pln][wire].first == UINT_MAX)
return false;
1985 float tickRange = 0;
1989 if (tickRange > 40) tickRange = 40;
1991 float loTpTick = projTick - tickRange;
1992 float hiTpTick = projTick + tickRange;
1993 for (
unsigned int iht = slc.
wireHitRange[pln][wire].first;
1996 unsigned int ahi = slc.
slHits[iht].allHitsIndex;
1998 if (projTick <
hit.PeakTime()) {
1999 float loHitTick =
hit.PeakTime() - 3 *
hit.RMS();
2000 if (hiTpTick > loHitTick)
return true;
2003 float hiHitTick =
hit.PeakTime() + 3 *
hit.RMS();
2004 if (loTpTick < hiHitTick)
return true;
2025 if (tp.
Pos[0] < -0.4)
return false;
2027 unsigned short pln = planeID.
Plane;
2028 unsigned int wire = std::nearbyint(tp.
Pos[0]);
2029 if (wire >
evt.
goodWire[pln].size() - 1)
return false;
2035 float tickRange = 0;
2039 if (tickRange > 40) tickRange = 40;
2041 float loTpTick = projTick - tickRange;
2042 float hiTpTick = projTick + tickRange;
2052 const auto& wid =
hit.WireID();
2053 if (wid.Cryostat != planeID.
Cryostat)
continue;
2054 if (wid.TPC != planeID.
TPC)
continue;
2055 if (wid.Plane != planeID.
Plane)
continue;
2056 if (projTick <
hit.PeakTime()) {
2057 float loHitTick =
hit.PeakTime() - 3 *
hit.RMS();
2058 if (hiTpTick > loHitTick)
return true;
2061 float hiHitTick =
hit.PeakTime() + 3 *
hit.RMS();
2062 if (loTpTick < hiHitTick)
return true;
2084 unsigned int pln = plnID.
Plane;
2085 if (pln == 2)
return false;
2087 unsigned int cstat = plnID.
Cryostat;
2088 unsigned int tpc = plnID.
TPC;
2093 float atTick = 0.5 * (loTick + hiTick);
2097 if (
hit.Channel() != chan)
continue;
2098 if (atTick <
hit.PeakTime()) {
2099 float loHitTick =
hit.PeakTime() - 3 *
hit.RMS();
2100 if (hiTick > loHitTick)
return true;
2103 float hiHitTick =
hit.PeakTime() + 3 *
hit.RMS();
2104 if (loTick < hiHitTick)
return true;
2115 for (
size_t i = 0; i < tp.
Hits.size(); ++i) {
2116 if (!tp.
UseHit[i])
continue;
2126 unsigned short firstPt = tj.
EndPt[0];
2127 unsigned short lastPt = tj.
EndPt[1];
2135 bool includeDeadWires,
2136 unsigned short firstPt,
2137 unsigned short lastPt)
2139 unsigned short ntp = 0;
2140 for (
unsigned short ipt = firstPt; ipt <= lastPt; ++ipt)
2141 if (tj.
Pts[ipt].Chg > 0) ++ntp;
2158 if (inWirePos1 < -0.4 || inWirePos2 < -0.4)
return 0;
2159 unsigned int inWire1 = std::nearbyint(inWirePos1);
2160 unsigned int inWire2 = std::nearbyint(inWirePos2);
2162 unsigned short plane = planeID.
Plane;
2163 if (inWire1 > slc.
nWires[plane] || inWire2 > slc.
nWires[plane])
return 0;
2164 if (inWire1 > inWire2) {
2166 unsigned int tmp = inWire1;
2171 unsigned int wire, ndead = 0;
2172 for (wire = inWire1; wire < inWire2; ++wire)
2181 unsigned short pdg =
abs(PDGCode);
2182 if (pdg == 11)
return 0;
2183 if (pdg == 13)
return 1;
2184 if (pdg == 211)
return 2;
2185 if (pdg == 321)
return 3;
2186 if (pdg == 2212)
return 4;
2196 if (itj > slc.
tjs.size() - 1)
return;
2197 int killTjID = slc.
tjs[itj].ID;
2199 if (
hit.InTraj == killTjID)
hit.InTraj = 0;
2207 if (itj > slc.
tjs.size() - 1)
return;
2210 <<
"RestoreObsoleteTrajectory: Trying to restore not-obsolete trajectory " 2215 for (
auto& tp : slc.
tjs[itj].Pts) {
2216 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
2217 if (tp.UseHit[ii]) {
2219 if (slc.
slHits[iht].InTraj == 0) { slc.
slHits[iht].InTraj = slc.
tjs[itj].ID; }
2233 for (
auto& shortTj : slc.
tjs) {
2234 if (shortTj.AlgMod[
kKilled] || shortTj.AlgMod[
kHaloTj])
continue;
2235 if (shortTj.CTP != inCTP)
continue;
2236 unsigned short spts = shortTj.EndPt[1] - shortTj.EndPt[0];
2237 if (spts > 20)
continue;
2239 if (shortTj.PDGCode == 11)
continue;
2241 if (shortTj.SSID > 0)
continue;
2243 if (tjhits.empty())
continue;
2244 std::vector<int> tids;
2245 std::vector<unsigned short> tcnt;
2246 for (
auto iht : tjhits) {
2248 if (
hit.InTraj <= 0)
continue;
2249 if ((
unsigned int)
hit.InTraj > slc.
tjs.size())
continue;
2250 if (
hit.InTraj == shortTj.ID)
continue;
2251 unsigned short indx = 0;
2252 for (indx = 0; indx < tids.size(); ++indx)
2253 if (
hit.InTraj == tids[indx])
break;
2254 if (indx == tids.size()) {
2255 tids.push_back(
hit.InTraj);
2262 if (tids.empty())
continue;
2264 unsigned short maxcnt = 0;
2265 for (
unsigned short indx = 0; indx < tids.size(); ++indx) {
2266 if (tcnt[indx] > maxcnt) {
2267 auto& ltj = slc.
tjs[tids[indx] - 1];
2268 unsigned short lpts = ltj.EndPt[1] - ltj.EndPt[0];
2269 if (lpts < spts)
continue;
2270 maxcnt = tcnt[indx];
2273 float hitFrac = (float)maxcnt / (
float)tjhits.size();
2274 if (hitFrac < 0.1)
continue;
2289 if (itj > slc.
tjs.size() - 1)
return false;
2291 auto& tj = slc.
tjs[itj];
2294 unsigned short atPt = USHRT_MAX;
2295 for (
unsigned short ipt = tj.EndPt[0] + 1; ipt <= tj.EndPt[1]; ++ipt) {
2296 if (tj.Pts[ipt].Pos[1] > tj.Pts[ipt - 1].Pos[1]) {
2298 if (tj.Pts[ipt - 1].Pos[1] < atPos1 && tj.Pts[ipt].Pos[1] >= atPos1) {
2305 if (tj.Pts[ipt - 1].Pos[1] >= atPos1 && tj.Pts[ipt].Pos[1] < atPos1) {
2311 if (atPt == USHRT_MAX)
return false;
2312 unsigned short vx2Index = USHRT_MAX;
2315 newVx2.
CTP = tj.CTP;
2316 newVx2.
Pos[0] = 0.5 * (tj.Pts[atPt - 1].Pos[0] + tj.Pts[atPt].Pos[0]);
2317 newVx2.
Pos[1] = 0.5 * (tj.Pts[atPt - 1].Pos[1] + tj.Pts[atPt].Pos[1]);
2322 return SplitTraj(slc, itj, atPt, vx2Index, prt);
2334 if (itj > slc.
tjs.size() - 1)
return false;
2335 if (pos < slc.
tjs[itj].EndPt[0] + 1 || pos > slc.
tjs[itj].EndPt[1] - 1)
return false;
2336 if (ivx != USHRT_MAX && ivx > slc.
vtxs.size() - 1)
return false;
2341 bool splittingMuon = (tj.
PDGCode == 13);
2342 if (splittingMuon) tj.
PDGCode = 0;
2346 myprt <<
"SplitTraj: Split T" << tj.
ID <<
" at point " <<
PrintPos(slc, tj.
Pts[pos]);
2347 if (ivx < slc.
vtxs.size()) myprt <<
" with Vtx 2V" << slc.
vtxs[ivx].ID;
2351 unsigned short ntp = 0;
2352 for (
unsigned short ipt = 0; ipt <=
pos; ++ipt) {
2353 if (tj.
Pts[ipt].Chg > 0) ++ntp;
2357 if (prt)
mf::LogVerbatim(
"TC") <<
" Split point to small at begin " << ntp <<
" pos " <<
pos;
2361 for (
unsigned short ipt = pos + 1; ipt <= tj.
EndPt[1]; ++ipt) {
2362 if (tj.
Pts[ipt].Chg > 0) ++ntp;
2367 mf::LogVerbatim(
"TC") <<
" Split point too small at end " << ntp <<
" pos " << pos
2368 <<
" EndPt " << tj.
EndPt[1];
2374 newTj.
ID = slc.
tjs.size() + 1;
2383 for (
unsigned short ipt = pos + 1; ipt <= tj.
EndPt[1]; ++ipt) {
2384 tj.
Pts[ipt].Chg = 0;
2385 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
2386 if (!tj.
Pts[ipt].UseHit[ii])
continue;
2387 iht = tj.
Pts[ipt].Hits[ii];
2389 if (slc.
slHits[iht].InTraj != tj.
ID)
continue;
2391 tj.
Pts[ipt].UseHit[ii] =
false;
2403 unsigned short eraseSize = pos - 2;
2404 if (eraseSize > newTj.
Pts.size() - 1) {
2417 newTj.
Pts.erase(newTj.
Pts.begin(), newTj.
Pts.begin() + eraseSize);
2419 for (
unsigned short ipt = 0; ipt < 3; ++ipt) {
2420 for (
unsigned short ii = 0; ii < newTj.
Pts[ipt].Hits.size(); ++ii)
2421 newTj.
Pts[ipt].UseHit[ii] =
false;
2422 newTj.
Pts[ipt].Chg = 0;
2428 if (ivx < slc.
vtxs.size()) newTj.
VtxID[0] = slc.
vtxs[ivx].ID;
2431 slc.
tjs.push_back(newTj);
2446 unsigned short& closePt,
2450 float best = minSep * minSep;
2451 closePt = USHRT_MAX;
2454 for (ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
2455 dw = tj.
Pts[ipt].Pos[0] - tp.
Pos[0];
2456 dt = tj.
Pts[ipt].Pos[1] - tp.
Pos[1];
2457 dp2 = dw * dw + dt * dt;
2463 minSep = sqrt(best);
2471 unsigned short& ipt1,
2472 unsigned short& ipt2,
2475 return TrajTrajDOCA(slc, tj1, tj2, ipt1, ipt2, minSep,
false);
2483 unsigned short& ipt1,
2484 unsigned short& ipt2,
2486 bool considerDeadWires)
2491 for (
unsigned short iwt = 0; iwt < 2; ++iwt) {
2494 float wt0 = tj1.
Pts[tj1.
EndPt[0]].Pos[iwt];
2495 float wt1 = tj1.
Pts[tj1.
EndPt[1]].Pos[iwt];
2503 wt0 = tj2.
Pts[tj2.
EndPt[0]].Pos[iwt];
2504 wt1 = tj2.
Pts[tj2.
EndPt[1]].Pos[iwt];
2514 if (lowt2 > hiwt1 + minSep)
return false;
2516 if (lowt1 > hiwt2 + minSep)
return false;
2519 float best = minSep * minSep;
2523 bool isClose =
false;
2524 for (
unsigned short i1 = tj1.
EndPt[0]; i1 < tj1.
EndPt[1] + 1; ++i1) {
2525 for (
unsigned short i2 = tj2.
EndPt[0]; i2 < tj2.
EndPt[1] + 1; ++i2) {
2527 float dw = tj1.
Pts[i1].Pos[0] - tj2.
Pts[i2].Pos[0] - dwc;
2528 if (
std::abs(dw) > minSep)
continue;
2529 float dt = tj1.
Pts[i1].Pos[1] - tj2.
Pts[i2].Pos[1];
2530 if (
std::abs(dt) > minSep)
continue;
2531 float dp2 = dw * dw + dt * dt;
2540 minSep = sqrt(best);
2549 if (iht > slc.
slHits.size() - 1 || jht > slc.
slHits.size() - 1)
return 1E6;
2552 float dw = (float)ihit.WireID().Wire - (float)jhit.WireID().Wire;
2554 return dw * dw + dt * dt;
2561 unsigned short endPt = tj.
EndPt[0];
2562 auto& tp0 = tj.
Pts[endPt];
2563 endPt = tj.
EndPt[1];
2564 auto& tp1 = tj.
Pts[endPt];
2573 float dw = wire - tp.
Pos[0];
2574 float dt = time - tp.
Pos[1];
2575 return dw * dw + dt * dt;
2582 if (iht > slc.
slHits.size() - 1)
return 1E6;
2584 float wire =
hit.WireID().Wire;
2603 double t = (double)(wire - tp.
Pos[0]) * tp.
Dir[0] + (double)(time - tp.
Pos[1]) * tp.
Dir[1];
2604 double dw = tp.
Pos[0] + t * tp.
Dir[0] - wire;
2605 double dt = tp.
Pos[1] + t * tp.
Dir[1] - time;
2606 return (
float)(dw * dw + dt * dt);
2625 double arg1 = tp1.
Pos[0] * tp1.
Dir[1] - tp1.
Pos[1] * tp1.
Dir[0];
2626 double arg2 = tp2.
Pos[0] * tp1.
Dir[1] - tp2.
Pos[1] * tp1.
Dir[0];
2627 double arg3 = tp2.
Dir[0] * tp1.
Dir[1] - tp2.
Dir[1] * tp1.
Dir[0];
2628 if (arg3 == 0)
return;
2629 double s = (arg1 - arg2) / arg3;
2631 x = (float)(tp2.
Pos[0] + s * tp2.
Dir[0]);
2632 y = (float)(tp2.
Pos[1] + s * tp2.
Dir[1]);
2641 if (tjIDs.empty())
return 0;
2643 for (
auto tjid : tjIDs) {
2644 if (tjid < 1 || tjid > (
int)slc.
tjs.size())
continue;
2645 auto& tj = slc.
tjs[tjid - 1];
2646 float sep2 =
PosSep2(tj.Pts[tj.EndPt[0]].Pos, tj.Pts[tj.EndPt[1]].Pos);
2647 if (sep2 > maxLen) maxLen = sep2;
2649 return sqrt(maxLen);
2656 float len = 0, dx, dy;
2658 unsigned short prevPt = tj.
EndPt[0];
2659 for (ipt = tj.
EndPt[0] + 1; ipt < tj.
EndPt[1] + 1; ++ipt) {
2660 if (tj.
Pts[ipt].Chg == 0)
continue;
2661 dx = tj.
Pts[ipt].Pos[0] - tj.
Pts[prevPt].Pos[0];
2662 dy = tj.
Pts[ipt].Pos[1] - tj.
Pts[prevPt].Pos[1];
2663 len += sqrt(dx * dx + dy * dy);
2673 return sqrt(
PosSep2(pos1, pos2));
2681 float d0 = pos1[0] - pos2[0];
2682 float d1 = pos1[1] - pos2[1];
2683 return d0 * d0 + d1 * d1;
2691 float dx = tp1.
Pos[0] - tp2.
Pos[0];
2692 float dy = tp1.
Pos[1] - tp2.
Pos[1];
2693 return sqrt(dx * dx + dy * dy);
2704 float close2 = DOCA * DOCA;
2706 bool foundClose =
false;
2708 for (
unsigned short ipt = tj.
EndPt[0]; ipt < tj.
EndPt[1] + 1; ++ipt) {
2709 if (tj.
Pts[ipt].Chg == 0)
continue;
2710 float dx = tj.
Pts[ipt].Pos[0] -
x;
2712 float dy = tj.
Pts[ipt].Pos[1] -
y;
2714 float sep2 = dx * dx + dy * dy;
2715 if (sep2 < close2) {
2722 DOCA = sqrt(close2);
2732 float dw = tp2.
Pos[0] - tp1.
Pos[0];
2733 float dt = tp2.
Pos[1] - tp1.
Pos[1];
2734 return atan2(dw, dt);
2738 std::vector<unsigned int>
2742 std::vector<unsigned int> hitVec;
2743 if (pfp.
TP3Ds.empty())
return hitVec;
2745 for (
auto& tp3d : pfp.
TP3Ds) {
2746 if (tp3d.IsBad)
continue;
2747 if (tp3d.TjID <= 0)
continue;
2748 auto& tp = slc.
tjs[tp3d.TjID - 1].Pts[tp3d.TPIndex];
2749 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
2750 unsigned int iht = tp.Hits[ii];
2751 bool useit = (hitRequest ==
kAllHits);
2752 if (tp.UseHit[ii] && hitRequest ==
kUsedHits) useit =
true;
2753 if (!tp.UseHit[ii] && hitRequest ==
kUnusedHits) useit =
true;
2754 if (useit) hitVec.push_back(iht);
2761 std::vector<unsigned int>
2765 std::vector<unsigned int> hitVec;
2769 for (
auto& tp : tj.
Pts)
2770 hitVec.insert(hitVec.end(), tp.Hits.begin(), tp.Hits.end());
2775 hitVec.reserve(tj.
Pts.size());
2776 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
2777 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
2778 unsigned int iht = tj.
Pts[ipt].Hits[ii];
2779 bool useit = (hitRequest ==
kAllHits);
2780 if (tj.
Pts[ipt].UseHit[ii] && hitRequest ==
kUsedHits) useit =
true;
2781 if (!tj.
Pts[ipt].UseHit[ii] && hitRequest ==
kUnusedHits) useit =
true;
2782 if (useit) hitVec.push_back(iht);
2797 if (tj.
Pts.size() > 10)
return;
2798 if (tj.
PDGCode == 111)
return;
2800 unsigned short nhm = 0;
2801 unsigned short npwc = 0;
2802 for (
auto& tp : tj.
Pts) {
2803 if (tp.Chg == 0)
continue;
2805 unsigned short nused = 0;
2806 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
2807 if (tp.UseHit[ii]) ++nused;
2809 if (nused > 3) ++nhm;
2814 mf::LogVerbatim(
"TC") <<
"TGT: T" << tj.
ID <<
" npwc " << npwc <<
" nhm " << nhm <<
" junk? " 2824 for (
unsigned short ii = 0; ii < tjHits.size() - 1; ++ii) {
2825 for (
unsigned short jj = ii + 1; jj < tjHits.size(); ++jj) {
2826 if (tjHits[ii] == tjHits[jj]) {
2842 if (tp.
Dir[0] == 0)
return;
2843 float dw = wire - tp.
Pos[0];
2846 tp.
Pos[1] += dw * tp.
Dir[1] / tp.
Dir[0];
2850 std::vector<unsigned int>
2852 std::array<int, 2>
const& wireWindow,
2854 const unsigned short plane,
2873 std::vector<unsigned int> closeHits;
2874 if (plane > slc.
firstWire.size() - 1)
return closeHits;
2876 int loWire = wireWindow[0];
2878 int hiWire = wireWindow[1];
2883 for (
int wire = loWire; wire <= hiWire; ++wire) {
2886 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
continue;
2887 unsigned int firstHit = slc.
wireHitRange[plane][wire].first;
2888 unsigned int lastHit = slc.
wireHitRange[plane][wire].second;
2889 for (
unsigned int iht = firstHit; iht <= lastHit; ++iht) {
2892 if (
hit.PeakTime() < minTick)
continue;
2893 if (
hit.PeakTime() > maxTick)
break;
2897 if (
hit.StartTick() > hiLo) hiLo =
hit.StartTick();
2899 if (
hit.EndTick() < loHi) loHi =
hit.EndTick();
2900 if (loHi < hiLo)
continue;
2901 if (hiLo > loHi)
break;
2904 bool takeit = (hitRequest ==
kAllHits);
2905 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) takeit =
true;
2907 if (takeit) closeHits.push_back(iht);
2925 if (tp.
Pos[0] < -0.4)
return false;
2927 unsigned int wire = std::nearbyint(tp.
Pos[0]);
2928 if (wire < slc.
firstWire[plane])
return false;
2929 if (wire > slc.
lastWire[plane] - 1)
return false;
2938 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
return false;
2940 unsigned int firstHit = slc.
wireHitRange[plane][wire].first;
2941 unsigned int lastHit = slc.
wireHitRange[plane][wire].second;
2944 for (
unsigned int iht = firstHit; iht <= lastHit; ++iht) {
2945 if ((
unsigned int)slc.
slHits[iht].InTraj > slc.
tjs.size())
continue;
2946 bool useit = (hitRequest ==
kAllHits);
2947 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) useit =
true;
2949 if (!useit)
continue;
2953 if (delta < maxDelta) tp.
Hits.push_back(iht);
2955 if (tp.
Hits.size() > 16) { tp.
Hits.resize(16); }
2958 return (!tp.
Hits.empty());
2971 if (end > 1)
return USHRT_MAX;
2973 if (end == 1) dir = -1;
2974 for (
short ii = 0; ii < (short)tj.
Pts.size(); ++ii) {
2975 short ipt = tj.
EndPt[
end] + dir * ii;
2976 if (ipt < 0 || ipt >= (
short)tj.
Pts.size())
return USHRT_MAX;
2977 auto& tp = tj.
Pts[ipt];
2988 const float& maxDelta)
3006 std::vector<int>
tmp;
3007 if (fromTp.
Pos[0] < -0.4 || toTp.
Pos[0] < -0.4)
return tmp;
3011 unsigned int firstWire, lastWire;
3012 if (toTp.
Pos[0] > fromTp.
Pos[0]) {
3014 firstWire = std::nearbyint(fromTp.
Pos[0]);
3015 lastWire = std::nearbyint(toTp.
Pos[0]);
3017 else if (toTp.
Pos[0] < fromTp.
Pos[0]) {
3019 firstWire = std::nearbyint(toTp.
Pos[0]);
3020 lastWire = std::nearbyint(fromTp.
Pos[0]);
3024 float tmp = fromTp.
Pos[0] - maxDelta;
3025 if (tmp < 0) tmp = 0;
3026 firstWire = std::nearbyint(tmp);
3027 tmp = fromTp.
Pos[0] + maxDelta;
3028 lastWire = std::nearbyint(tmp);
3034 if (firstWire > slc.
lastWire[plane] - 1)
return tmp;
3036 if (lastWire > slc.
lastWire[plane] - 1) lastWire = slc.
lastWire[plane] - 1;
3038 for (
unsigned int wire = firstWire; wire <= lastWire; ++wire) {
3039 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
continue;
3044 unsigned int firstHit = slc.
wireHitRange[plane][wire].first;
3045 unsigned int lastHit = slc.
wireHitRange[plane][wire].second;
3046 for (
unsigned int iht = firstHit; iht <= lastHit; ++iht) {
3047 if (slc.
slHits[iht].InTraj <= 0)
continue;
3048 if ((
unsigned int)slc.
slHits[iht].InTraj > slc.
tjs.size())
continue;
3050 if (
hit.PeakTime() < minTick)
continue;
3052 if (
hit.PeakTime() > maxTick)
break;
3053 if (std::find(tmp.begin(), tmp.end(), slc.
slHits[iht].InTraj) != tmp.end())
continue;
3054 tmp.push_back(slc.
slHits[iht].InTraj);
3066 unsigned short end1,
3068 unsigned short end2,
3069 unsigned short nPtsFit,
3076 if (tj1.
CTP != tj2.
CTP)
return -1;
3077 if (end1 > 1 || end2 > 1)
return -1;
3085 if (end1 == 1) dir = -1;
3086 unsigned short cnt = 0;
3088 for (
short ii = 0; ii < (short)tj1.
Pts.size(); ++ii) {
3089 short ipt = tj1.
EndPt[end1] + dir * ii;
3091 if (ipt >= (
short)tj1.
Pts.size())
break;
3092 auto& tp = tj1.
Pts[ipt];
3093 if (tp.Chg <= 0)
continue;
3094 tj.
Pts.push_back(tp);
3096 if (cnt == nPtsFit + 1)
break;
3098 if (cnt < nPtsFit)
return -1;
3101 if (end2 == 1) dir = -1;
3103 for (
short ii = 0; ii < (short)tj2.
Pts.size(); ++ii) {
3104 short ipt = tj2.
EndPt[end2] + dir * ii;
3106 if (ipt >= (
short)tj2.
Pts.size())
break;
3107 auto& tp = tj2.
Pts[ipt];
3108 if (tp.Chg <= 0)
continue;
3109 tj.
Pts.push_back(tp);
3111 if (cnt == nPtsFit + 1)
break;
3122 unsigned short kinkPt,
3123 unsigned short nPtsFit,
3132 if (kinkPt < tj.
EndPt[0] + 2)
return -1;
3133 if (kinkPt > tj.
EndPt[1] - 2)
return -1;
3136 if (nPtsFit < 3)
return -1;
3139 if (npwc < 2 * nPtsFit + 1)
return -1;
3144 double chgRMS = 0.07;
3148 double tFactor = 1 + 0.3 / double(nPtsFit - 2);
3154 FitTraj(slc, tj, kinkPt, nPtsFit, fitDir, tpPos);
3155 if (tpPos.
FitChi > 900)
return -1;
3159 FitTraj(slc, tj, kinkPt, nPtsFit, fitDir, tpNeg);
3160 if (tpNeg.
FitChi > 900)
return -1;
3161 double angErr = tpNeg.
AngErr;
3165 double dangSig = dang / angErr;
3172 unsigned short cntNeg = 0;
3173 for (
unsigned short ipt = kinkPt - 1; ipt >= tj.
EndPt[0]; --ipt) {
3174 auto& tp = tj.
Pts[ipt];
3175 if (tp.Chg <= 0)
continue;
3178 if (cntNeg == nPtsFit)
break;
3179 if (ipt == 0)
break;
3181 if (cntNeg != nPtsFit) {
3182 if (prt)
mf::LogVerbatim(
"TC") <<
" KL: Bad cntNeg " << cntNeg <<
" != " << nPtsFit;
3187 unsigned short cntPos = 0;
3188 for (
unsigned short ipt = kinkPt + 1; ipt <= tj.
EndPt[1]; ++ipt) {
3189 auto& tp = tj.
Pts[ipt];
3190 if (tp.Chg <= 0)
continue;
3193 if (cntPos == nPtsFit)
break;
3195 if (cntPos != nPtsFit) {
3196 if (prt)
mf::LogVerbatim(
"TC") <<
" KL: Bad cntPos " << cntPos <<
" != " << nPtsFit;
3199 chgNeg /= (float)nPtsFit;
3200 chgPos /= (float)nPtsFit;
3202 chgAsym =
std::abs(chgPos - chgNeg) / (chgPos + chgNeg);
3204 chgSig = chgAsym / chgRMS;
3206 double kinkSig = sqrt(dangSig * dangSig + chgSig * chgSig);
3210 myprt <<
"KL: T" << tj.
ID <<
" kinkPt " <<
PrintPos(slc, tj.
Pts[kinkPt]);
3211 myprt <<
" nPtsFit " << nPtsFit;
3215 myprt <<
" chgAsym " << chgAsym;
3216 myprt <<
" chgSig " << chgSig;
3217 myprt <<
" kinkSig " << kinkSig;
3219 return (
float)kinkSig;
3230 unsigned short midPt = 0.5 * (tj.
EndPt[0] + tj.
EndPt[1]);
3231 double rms0 = 0, rms1 = 0;
3235 float asym =
std::abs(rms0 - rms1) / (rms0 + rms1);
3236 float chgFact = (tj.
ChgRMS - 0.1) * 5;
3237 float elh = 5 * asym * chgFact;
3238 if (elh > 1) elh = 1;
3248 if (tjIDs.empty())
return 0;
3249 std::array<int, 2> wireWindow;
3252 constexpr
float NNDelta = 5;
3253 wireWindow[0] = pos[0] - NNDelta;
3254 wireWindow[1] = pos[0] + NNDelta;
3255 timeWindow[0] = pos[1] - NNDelta;
3256 timeWindow[1] = pos[1] + NNDelta;
3258 for (
auto& tjID : tjIDs)
3259 if (tjID <= 0 || tjID > (
int)slc.
tjs.size())
return 0;
3264 std::vector<unsigned int> closeHits =
3266 if (closeHits.empty())
return 0;
3271 for (
auto& iht : closeHits) {
3273 chg +=
hit.Integral();
3274 if (slc.
slHits[iht].InTraj == 0)
continue;
3275 if (std::find(tjIDs.begin(), tjIDs.end(), slc.
slHits[iht].InTraj) != tjIDs.end())
3276 tchg +=
hit.Integral();
3278 if (chg == 0)
return 0;
3286 float delta,
md = 0;
3289 for (
auto& tp : tj.
Pts) {
3290 for (ii = 0; ii < tp.Hits.size(); ++ii) {
3291 if (!tp.UseHit[ii])
continue;
3294 if (delta > md) md = delta;
3305 if (tj.
Pts.empty())
return;
3316 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
3317 if (tj.
Pts[ipt].Dir[0] != 0) tj.
Pts[ipt].Dir[0] = -tj.
Pts[ipt].Dir[0];
3318 if (tj.
Pts[ipt].Dir[1] != 0) tj.
Pts[ipt].Dir[1] = -tj.
Pts[ipt].Dir[1];
3319 if (tj.
Pts[ipt].Ang > 0) { tj.
Pts[ipt].Ang -= M_PI; }
3321 tj.
Pts[ipt].Ang += M_PI;
3339 unsigned short nvx = Envelope.size();
3340 double angleSum = 0;
3341 for (
unsigned short ii = 0; ii < Envelope.size(); ++ii) {
3342 p1[0] = Envelope[ii][0] - Point[0];
3343 p1[1] = Envelope[ii][1] - Point[1];
3344 p2[0] = Envelope[(ii + 1) % nvx][0] - Point[0];
3345 p2[1] = Envelope[(ii + 1) % nvx][1] - Point[1];
3348 if (
abs(angleSum) < M_PI)
return false;
3357 double den = v1[0] * v1[0] + v1[1] * v1[1];
3358 if (den == 0)
return false;
3373 if (pos1[0] == pos2[0] && pos1[1] == pos2[1])
return;
3374 pos1[0] = pos2[0] - pos1[0];
3375 pos1[1] = pos2[1] - pos1[1];
3376 double sep = sqrt(pos1[0] * pos1[0] + pos1[1] * pos1[1]);
3377 if (sep < 1
E-6)
return;
3379 ptDir[0] = pos1[0] / sep;
3380 ptDir[1] = pos1[1] / sep;
3382 double costh =
DotProd(dir1, ptDir);
3383 if (costh > 1.0 || costh < -1.0)
return;
3384 alongTrans[0] = costh * sep;
3385 double sinth = sqrt(1 - costh * costh);
3386 alongTrans[1] = sinth * sep;
3394 double ang1 = atan2(p1[1], p1[0]);
3395 double ang2 = atan2(p2[1], p2[0]);
3403 constexpr
double twopi = 2 * M_PI;
3404 double dang = Ang1 - Ang2;
3407 while (dang < -M_PI)
3416 return std::abs(std::remainder(Ang1 - Ang2, M_PI));
3430 if (tj.
Pts.size() == 0)
return;
3433 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt) {
3434 if (tj.
Pts[ipt].Chg != 0) {
3439 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
3440 unsigned short ipt = tj.
Pts.size() - 1 - ii;
3441 if (tj.
Pts[ipt].Chg != 0) {
3454 unsigned short nUsed = 0;
3455 unsigned short nTotHits = 0;
3456 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
3458 nTotHits += tp.
Hits.size();
3459 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
3460 if (tp.
UseHit[ii]) ++nUsed;
3463 if (nTotHits == 0)
return false;
3464 float fracUsed = (float)nUsed / (
float)nTotHits;
3466 mf::LogVerbatim(
"TC") <<
"TrajIsClean: nTotHits " << nTotHits <<
" nUsed " << nUsed
3467 <<
" fracUsed " << fracUsed;
3469 if (fracUsed > 0.9)
return true;
3479 if (tjIDs.empty())
return 0;
3482 for (
auto tjid : tjIDs) {
3483 auto& tj = slc.
tjs[tjid - 1];
3484 float npts = tj.EndPt[1] - tj.EndPt[0] + 1;
3485 summ += npts * tj.MCSMom;
3488 return (
short)(summ / suml);
3504 if (firstPt == lastPt)
return 0;
3505 if (firstPt > lastPt)
std::swap(firstPt, lastPt);
3509 if (firstPt >= lastPt)
return 0;
3511 if (firstPt < tj.
EndPt[0])
return 0;
3512 if (lastPt > tj.
EndPt[1])
return 0;
3519 if (tjLen < 1)
return 0;
3521 double thetaRMS =
MCSThetaRMS(slc, tj, firstPt, lastPt);
3522 if (thetaRMS < 0.001)
return 999;
3523 double mom = 13.8 * sqrt(tjLen / 14) / thetaRMS;
3524 if (mom > 999) mom = 999;
3533 if (thePt > tj.
EndPt[1])
return thePt;
3534 if (tj.
Pts[thePt].Chg > 0)
return thePt;
3536 short endPt0 = tj.
EndPt[0];
3537 short endPt1 = tj.
EndPt[1];
3538 for (
short off = 1; off < 10; ++off) {
3539 short ipt = thePt + off;
3540 if (ipt <= endPt1 && tj.
Pts[ipt].Chg > 0)
return (
unsigned short)ipt;
3542 if (ipt >= endPt0 && tj.
Pts[ipt].Chg > 0)
return (
unsigned short)ipt;
3556 if (tps < 1)
return 1;
3566 unsigned short firstPt,
3567 unsigned short lastPt)
3572 if (firstPt < tj.
EndPt[0])
return 1;
3573 if (lastPt > tj.
EndPt[1])
return 1;
3577 if (firstPt >= lastPt)
return 1;
3581 TjDeltaRMS(slc, tj, firstPt, lastPt, sigmaS, cnt);
3582 if (sigmaS < 0)
return 1;
3584 if (tjLen < 1)
return 1;
3586 return (6.8 * sigmaS / tjLen);
3594 unsigned short firstPt,
3595 unsigned short lastPt,
3597 unsigned short& cnt)
3602 if (firstPt < tj.
EndPt[0])
return;
3603 if (lastPt > tj.
EndPt[1])
return;
3607 if (firstPt >= lastPt)
return;
3620 for (
unsigned short ipt = firstPt + 1; ipt < lastPt; ++ipt) {
3621 if (tj.
Pts[ipt].Chg == 0)
continue;
3623 if (tj.
Pts[ipt].HitPosErr2 > 4)
continue;
3627 if (cnt < 2)
return;
3628 rms = sqrt(dsum / (
double)cnt);
3640 std::array<int, 2> wireWindow;
3646 for (
auto& mutj : slc.
tjs) {
3647 if (mutj.AlgMod[
kKilled])
continue;
3648 if (mutj.CTP != inCTP)
continue;
3649 if (mutj.PDGCode != 13)
continue;
3650 unsigned short nnear = 0;
3651 for (
unsigned short ipt = mutj.EndPt[0]; ipt <= mutj.EndPt[1]; ++ipt) {
3652 auto& tp = mutj.Pts[ipt];
3653 wireWindow[0] = tp.Pos[0];
3654 wireWindow[1] = tp.Pos[0];
3655 timeWindow[0] = tp.Pos[1] - delta;
3656 timeWindow[1] = tp.Pos[1] + delta;
3661 if (closeHits.empty())
continue;
3662 for (
auto iht : closeHits) {
3663 auto inTraj = slc.
slHits[iht].InTraj;
3664 if (inTraj <= 0)
continue;
3665 if (inTraj == mutj.ID)
continue;
3666 auto& dtj = slc.
tjs[inTraj - 1];
3667 if (dtj.PDGCode == 13)
continue;
3668 for (
unsigned short jpt = dtj.EndPt[0]; jpt <= dtj.EndPt[1]; ++jpt) {
3669 auto& dtp = dtj.Pts[jpt];
3670 if (std::find(dtp.Hits.begin(), dtp.Hits.end(), iht) == dtp.Hits.end())
continue;
3690 for (
auto& tp : tj.
Pts) {
3691 if (tp.Chg <= 0)
continue;
3693 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
3694 if (tp.UseHit[ii])
continue;
3695 unsigned int iht = tp.Hits[ii];
3721 for (
unsigned short ipt = tj.
EndPt[0] + 1; ipt < tj.
EndPt[1]; ++ipt) {
3722 auto& tp = tj.
Pts[ipt];
3723 if (tp.Chg > bigChg) bigChg = tp.Chg;
3730 for (
unsigned short ipt = tj.
EndPt[0] + 1; ipt < tj.
EndPt[1]; ++ipt) {
3731 auto& tp = tj.
Pts[ipt];
3732 if (tp.Chg <= 0)
continue;
3734 if (tp.Chg == bigChg)
continue;
3739 bsum2 += tp.Chg * tp.Chg;
3740 if (tp.Chg > bigChg) bigChg = tp.Chg;
3746 for (
unsigned short ii = 0; ii < tj.
Pts[ipt].Hits.size(); ++ii) {
3747 if (!tp.UseHit[ii])
continue;
3748 unsigned int iht = tp.Hits[ii];
3752 vsum2 += tpchg * tpchg;
3755 if (bcnt == 0)
return;
3763 if (arg > 0) tj.
ChgRMS = sqrt(arg / (bcnt - 1));
3765 for (
auto& tp : tj.
Pts)
3768 mf::LogVerbatim(
"TC") << inFcnLabel <<
".UpdateTjChgProperties: backup sum Set tj.AveChg " 3773 double nWires = tj.
EndPt[1] - tj.
EndPt[0] + 1;
3774 if (nWires < 2)
return;
3779 for (
unsigned short end = 0;
end < 2; ++
end) {
3783 int dw =
std::abs(tp.Pos[0] - vx2.Pos[0]);
3795 if (arg > 0) rms = sqrt(arg / (vcnt - 1));
3798 if (rms < 0.1) rms = 0.1;
3802 double defFrac = 1 / vcnt;
3803 rms = defFrac * 0.5 + (1 - defFrac) * rms;
3807 mf::LogVerbatim(
"TC") << inFcnLabel <<
".UpdateTjChgProperties: Set tj.AveChg " 3814 for (
unsigned short ipt = tj.
EndPt[0]; ipt <= tj.
EndPt[1]; ++ipt) {
3815 auto& tp = tj.
Pts[ipt];
3816 if (tp.Chg <= 0)
continue;
3823 for (
auto& tp : tj.
Pts)
3829 for (
auto& tp : tj.
Pts)
3833 unsigned short minPt = tj.
EndPt[0] + nptsave;
3835 for (
unsigned short ii = 0; ii < tj.
Pts.size(); ++ii) {
3836 unsigned short ipt = tj.
EndPt[1] - ii;
3837 if (ipt < minPt)
break;
3840 for (
unsigned short iii = 0; iii < nptsave; ++iii) {
3841 unsigned short iipt = ipt - iii;
3843 if (iipt == tj.
EndPt[0])
break;
3844 auto& tp = tj.
Pts[iipt];
3845 if (tp.Chg <= 0)
continue;
3850 tj.
Pts[ipt].AveChg = sum / cnt;
3851 lastAve = tj.
Pts[ipt].AveChg;
3855 for (
unsigned short ii = tj.
EndPt[0]; ii <= tj.
EndPt[1]; ++ii) {
3856 unsigned short ipt = tj.
EndPt[1] - ii;
3857 auto& tp = tj.
Pts[ipt];
3858 if (tp.AveChg == 0) { tp.AveChg = lastAve; }
3860 lastAve = tp.AveChg;
3878 for (
auto& tj : slc.
tjs) {
3879 if (tj.AlgMod[
kKilled])
continue;
3880 for (
auto& tp : tj.Pts)
3884 for (
auto& vx : slc.
vtxs) {
3885 if (vx.ID <= 0)
continue;
3897 if (vx2.
ID == 0)
return;
3900 if (prt)
mf::LogVerbatim(
"TC") <<
"UpdateVxEnvironment check Tjs attached to vx2 " << vx2.
ID;
3902 std::vector<int> tjlist;
3903 std::vector<unsigned short> tjends;
3904 if (vx2.
Pos[0] < -0.4)
return;
3905 unsigned int vxWire = std::nearbyint(vx2.
Pos[0]);
3906 unsigned int loWire = vxWire;
3907 unsigned int hiWire = vxWire;
3908 for (
auto& tj : slc.
tjs) {
3910 if (tj.CTP != vx2.
CTP)
continue;
3912 if (tj.AlgMod[
kPhoton])
continue;
3913 for (
unsigned short end = 0;
end < 2; ++
end) {
3914 if (tj.VtxID[
end] != vx2.
ID)
continue;
3915 tjlist.push_back(tj.ID);
3916 tjends.push_back(
end);
3917 if (tj.Pts[tj.EndPt[
end]].Pos[0] < -0.4)
return;
3918 unsigned int endWire = std::nearbyint(tj.Pts[tj.EndPt[
end]].Pos[0]);
3919 if (endWire < loWire) loWire = endWire;
3920 if (endWire > hiWire) hiWire = endWire;
3923 if (tjlist.size() < 2)
return;
3924 if (hiWire < loWire + 1)
return;
3926 mf::LogVerbatim(
"TC") <<
" check Tjs on wires in the range " << loWire <<
" to " << hiWire;
3930 std::vector<std::vector<TrajPoint>> wire_tjpt;
3932 std::vector<int> tjids;
3934 unsigned short nwires = hiWire - loWire + 1;
3935 for (
unsigned short itj = 0; itj < tjlist.size(); ++itj) {
3936 auto& tj = slc.
tjs[tjlist[itj] - 1];
3937 unsigned short end = tjends[itj];
3938 std::vector<TrajPoint> tjpt(nwires);
3940 for (
unsigned short ii = 0; ii < tj.Pts.size(); ++ii) {
3942 if (end == 0) { ipt = tj.EndPt[0] + ii; }
3944 ipt = tj.EndPt[1] - ii;
3946 if (ipt > tj.Pts.size() - 1)
break;
3948 auto tp = tj.Pts[ipt];
3949 if (tp.Chg <= 0)
continue;
3952 if (tp.Pos[0] < -0.4)
continue;
3953 unsigned int wire = std::nearbyint(tp.Pos[0]);
3954 unsigned short indx = wire - loWire;
3955 if (indx > nwires - 1)
break;
3965 if (ltp.
Dir[0] == 0)
continue;
3966 if (ltp.
Pos[0] < -0.4)
continue;
3967 unsigned int wire = std::nearbyint(ltp.
Pos[0]);
3969 unsigned short indx = wire - loWire;
3971 if (tjpt[indx].Chg == 0) tjpt[indx] = ltp;
3973 for (
unsigned short ii = 0; ii <
nwires; ++ii) {
3975 for (
unsigned short iwt = 0; iwt < 2; ++iwt)
3976 ltp.
Pos[iwt] += ltp.
Dir[iwt] * stepSize;
3977 if (ltp.
Pos[0] < -0.4)
break;
3978 wire = std::nearbyint(ltp.
Pos[0]);
3979 if (wire < loWire || wire > hiWire)
break;
3980 indx = wire - loWire;
3981 if (tjpt[indx].Chg > 0)
continue;
3986 myprt <<
" T" << tj.ID;
3987 for (
auto& tp : tjpt)
3988 myprt <<
" " <<
PrintPos(slc, tp.Pos) <<
"_" << tp.Step <<
"_" << (
int)tp.Chg;
3990 wire_tjpt.push_back(tjpt);
3991 tjids.push_back(tj.ID);
3995 for (
unsigned short indx = 0; indx <
nwires; ++indx) {
3997 unsigned short npts = 0;
3999 unsigned short npwc = 0;
4000 for (
unsigned short itj = 0; itj < wire_tjpt.size(); ++itj) {
4001 if (wire_tjpt[itj][indx].Pos[0] == 0)
continue;
4004 if (wire_tjpt[itj][indx].Chg > 0) ++npwc;
4007 if (npts == 0)
continue;
4009 if (npwc == npts)
continue;
4011 for (
unsigned short itj = 0; itj < wire_tjpt.size(); ++itj) {
4012 if (wire_tjpt[itj][indx].Pos[0] == 0)
continue;
4013 if (wire_tjpt[itj][indx].Chg == 0)
continue;
4014 auto& tj = slc.
tjs[tjids[itj] - 1];
4015 unsigned short ipt = wire_tjpt[itj][indx].Step;
4017 tj.NeedsUpdate =
true;
4018 if (prt)
mf::LogVerbatim(
"TC") <<
" Set kEnvOverlap bit on T" << tj.ID <<
" ipt " << ipt;
4024 for (
auto tjid : tjids) {
4025 auto& tj = slc.
tjs[tjid - 1];
4026 if (!tj.NeedsUpdate)
continue;
4027 if (tj.CTP != vx2.
CTP)
continue;
4075 if (dir[0] == 0 && dir[1] == 0 && dir[2] == 0)
return tp;
4079 Point3_t pos3 = {{100 * dir[0], 100 * dir[1], 100 * dir[2]}};
4081 std::array<double, 2> ori2;
4082 std::array<double, 2> pos2;
4083 std::array<double, 2> dir2;
4091 dir2[0] = pos2[0] - ori2[0];
4092 dir2[1] = pos2[1] - ori2[1];
4094 double norm = sqrt(dir2[0] * dir2[0] + dir2[1] * dir2[1]);
4097 tp.
Ang = atan2(dir2[1], dir2[0]);
4098 tp.
Delta = norm / 100;
4106 norm = sqrt(cs * cs + sn * sn);
4111 tp.
DeltaRMS = 100 / (pos2[0] - ori2[0]);
4120 if (fromHit > slc.
slHits.size() - 1)
return false;
4121 if (toHit > slc.
slHits.size() - 1)
return false;
4126 (
float)fhit.WireID().Wire,
4128 (float)thit.WireID().Wire,
4146 tp.
Pos[0] = fromWire;
4148 tp.
Dir[0] = toWire - fromWire;
4151 if (norm == 0)
return false;
4162 tpOut.
Pos = fromPos;
4164 tpOut.
Ang = atan2(tpOut.
Dir[1], tpOut.
Dir[0]);
4179 tpOut.
Ang = atan2(tpOut.
Dir[1], tpOut.
Dir[0]);
4188 if (tj.
ID == 0)
return 0;
4199 for (
unsigned short xyz = 0; xyz < 2; ++xyz)
4200 dir[xyz] = p2[xyz] - p1[xyz];
4201 if (dir[0] == 0 && dir[1] == 0)
return dir;
4202 double norm = sqrt(dir[0] * dir[0] + dir[1] * dir[1]);
4222 if (tp.
Hits.empty())
return 0;
4223 float minVal = 9999;
4225 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
4226 bool useit = (hitRequest ==
kAllHits);
4229 if (!useit)
continue;
4230 unsigned int iht = tp.
Hits[ii];
4232 float cv =
hit.PeakTime();
4234 float arg = cv -
rms;
4235 if (arg < minVal) minVal = arg;
4237 if (arg > maxVal) maxVal = arg;
4239 if (maxVal == 0)
return 0;
4240 return (maxVal - minVal) / 2;
4246 const std::vector<unsigned int>& hitsInMultiplet,
4255 const std::vector<unsigned int>& hitsInMultiplet,
4258 if (hitsInMultiplet.empty())
return 0;
4260 if (hitsInMultiplet.size() == 1) {
4265 float minVal = 9999;
4267 for (
unsigned short ii = 0; ii < hitsInMultiplet.size(); ++ii) {
4268 unsigned int iht = hitsInMultiplet[ii];
4269 bool useit = (hitRequest ==
kAllHits);
4270 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) useit =
true;
4272 if (!useit)
continue;
4274 float cv =
hit.PeakTime();
4276 float arg = cv -
rms;
4277 if (arg < minVal) minVal = arg;
4279 if (arg > maxVal) maxVal = arg;
4281 if (maxVal == 0)
return 0;
4282 return (maxVal - minVal) / 2;
4288 const std::vector<unsigned int>& hitsInMultiplet,
4298 const std::vector<unsigned int>& hitsInMultiplet,
4305 for (
unsigned short ii = 0; ii < hitsInMultiplet.size(); ++ii) {
4306 unsigned int iht = hitsInMultiplet[ii];
4307 bool useit = (hitRequest ==
kAllHits);
4308 if (hitRequest ==
kUsedHits && slc.
slHits[iht].InTraj > 0) useit =
true;
4310 if (!useit)
continue;
4312 float chg =
hit.Integral();
4313 pos += chg *
hit.PeakTime();
4316 if (sum <= 0)
return -1;
4325 if (tj.
Pts.empty())
return 0;
4326 unsigned short nhits = 0;
4327 for (
auto& tp : tj.
Pts) {
4328 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii)
4329 if (tp.UseHit[ii]) ++nhits;
4339 if (tp.
Hits.empty())
return 0;
4343 unsigned short nhits = 0;
4344 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
4346 if (tp.
UseHit[ii]) ++nhits;
4350 if (!tp.
UseHit[ii]) ++nhits;
4360 if (itj > slc.
tjs.size() - 1)
return;
4395 if (npwc > 500) isAMuon =
true;
4416 std::vector<float> cnt(nplanes, 0);
4417 for (
unsigned short iht = 0; iht < (*
evt.
allHits).
size(); ++iht) {
4419 unsigned short plane =
hit.WireID().Plane;
4420 if (plane > nplanes - 1)
return false;
4421 if (cnt[plane] > 200)
continue;
4423 if (
hit.Multiplicity() != 1)
continue;
4425 if (
hit.GoodnessOfFit() < 0 ||
hit.GoodnessOfFit() > 500)
continue;
4427 if (
hit.PeakAmplitude() < 1)
continue;
4431 bool allDone =
true;
4432 for (
unsigned short plane = 0; plane < nplanes; ++plane)
4433 if (cnt[plane] < 200) allDone =
false;
4439 for (
unsigned short plane = 0; plane < nplanes; ++plane) {
4440 if (cnt[plane] > 4) {
evt.
aveHitRMS[plane] /= cnt[plane]; }
4448 std::cout <<
"Analyze hits aveHitRMS";
4451 std::cout <<
" " <<
rms;
4481 unsigned int cstat = inTPCID.
Cryostat;
4482 unsigned int tpc = inTPCID.
TPC;
4487 for (
unsigned short pln = 0; pln < nplanes; ++pln) {
4491 for (
unsigned int wire = 0; wire <
nwires; ++wire) {
4501 for (
unsigned short pln = 0; pln < nplanes; ++pln) {
4513 for (
unsigned short pln = 0; pln < nplanes; ++pln) {
4516 for (
unsigned int wire = 0; wire <
nwires; ++wire)
4521 unsigned int nBadWireFix = 0;
4524 auto wid =
hit.WireID();
4525 if (wid.Cryostat != cstat)
continue;
4526 if (wid.TPC != tpc)
continue;
4527 unsigned short pln = wid.Plane;
4528 unsigned int wire = wid.Wire;
4538 std::cout <<
"FillWireHitRange found hits on " << nBadWireFix
4539 <<
" wires that were declared not-good by the ChannelStatus service. Fixed it...\n";
4557 if (nplanes > 3)
return false;
4560 double local[3] = {0., 0., 0.};
4561 double world[3] = {0., 0., 0.};
4576 slc.
nWires.resize(nplanes);
4581 std::pair<unsigned int, unsigned int> flag;
4582 flag.first = UINT_MAX;
4583 flag.second = UINT_MAX;
4596 for (
unsigned short plane = 0; plane < nplanes; ++plane) {
4605 unsigned int lastWire = 0, lastPlane = 0;
4606 for (
unsigned int iht = 0; iht < slc.
slHits.size(); ++iht) {
4607 unsigned int ahi = slc.
slHits[iht].allHitsIndex;
4608 if (ahi > (*
evt.
allHits).size() - 1)
return false;
4610 if (
hit.WireID().Cryostat != cstat)
continue;
4611 if (
hit.WireID().TPC != tpc)
continue;
4612 unsigned short plane =
hit.WireID().Plane;
4613 unsigned int wire =
hit.WireID().Wire;
4614 if (wire > slc.
nWires[plane] - 1) {
4615 mf::LogWarning(
"TC") <<
"FillWireHitRange: Invalid wire number " << wire <<
" > " 4616 << slc.
nWires[plane] - 1 <<
" in plane " << plane <<
" Quitting";
4619 if (plane == lastPlane && wire < lastWire) {
4621 <<
"FillWireHitRange: Hits are not in increasing wire order. Quitting ";
4633 unsigned int slhitsSize = slc.
slHits.size();
4634 for (
unsigned short plane = 0; plane < nplanes; ++plane) {
4635 for (
unsigned int wire = slc.
firstWire[plane]; wire < slc.
lastWire[plane]; ++wire) {
4636 if (slc.
wireHitRange[plane][wire].first == UINT_MAX)
continue;
4637 if (slc.
wireHitRange[plane][wire].first > slhitsSize - 1 &&
4647 std::cout <<
"Slice ID/Index " << slc.
ID <<
"/" <<
slices.size() <<
" tpc " << tpc
4649 std::cout <<
" Active volume (";
4679 if (itj1 > slc.
tjs.size() - 1)
return false;
4680 if (itj2 > slc.
tjs.size() - 1)
return false;
4691 if (pfp1 != USHRT_MAX || pfp2 != USHRT_MAX) {
4692 if (pfp1 != USHRT_MAX && pfp2 != USHRT_MAX)
return false;
4694 if (pfp1 == USHRT_MAX)
std::swap(itj1, itj2);
4711 <<
" at merge points " <<
PrintPos(slc, tp1e1) <<
" " 4737 if (tp2e0[0] > tp1e0[0] && tp2e1[0] < tp1e1[0])
return false;
4741 if (tp1e0[0] > tp2e0[0] && tp1e1[0] < tp2e1[0])
return false;
4745 if (tp2e1[0] > tp1e1[0] && tp2e0[0] < tp1e0[0])
return false;
4746 if (tp1e1[0] > tp2e1[0] && tp1e0[0] < tp2e0[0])
return false;
4761 mf::LogVerbatim(
"TC") <<
"MergeAndStore: You are merging the end of trajectory T" << tj1.
ID 4762 <<
" with a Bragg peak. Not merging\n";
4773 float minSep = 1000;
4774 unsigned short tj2ClosePt = 0;
4779 << tj2ClosePt <<
" Pos " <<
PrintPos(slc, tj2.
Pts[tj2ClosePt]);
4781 if (tj2ClosePt > tj2.
EndPt[1])
return false;
4790 std::vector<unsigned int> tj1Hits;
4791 for (
unsigned short ii = 0; ii < tj1.
Pts.size(); ++ii) {
4794 unsigned short ipt = tj1.
Pts.size() - 1 - ii;
4795 tj1Hits.insert(tj1Hits.end(), tj1.
Pts[ipt].Hits.begin(), tj1.
Pts[ipt].Hits.end());
4796 if (ipt == 0)
break;
4799 bool bumpedPt =
true;
4802 for (
unsigned short ii = 0; ii < tj2.
Pts[tj2ClosePt].Hits.size(); ++ii) {
4803 unsigned int iht = tj2.
Pts[tj2ClosePt].Hits[ii];
4804 if (std::find(tj1Hits.begin(), tj1Hits.end(), iht) != tj1Hits.end()) bumpedPt =
true;
4806 if (bumpedPt && tj2ClosePt < tj2.
EndPt[1]) { ++tj2ClosePt; }
4811 if (doPrt)
mf::LogVerbatim(
"TC") <<
" revised tj2ClosePt " << tj2ClosePt;
4814 tj1.
Pts.insert(tj1.
Pts.end(), tj2.
Pts.begin() + tj2ClosePt, tj2.
Pts.end());
4821 if (tj2.
VtxID[1] > 0) {
4842 int newTjID = slc.
tjs.size();
4846 if (doPrt)
mf::LogVerbatim(
"TC") <<
" MAS success. Created T" << newTjID;
4848 for (
auto& tj : slc.
tjs)
4849 if (tj.ParentID == tj1ID || tj.ParentID == tj2ID) tj.ParentID = newTjID;
4862 std::vector<int>
tmp;
4863 if (
id <= 0)
return tmp;
4864 unsigned int uid = id;
4866 if (type1Name ==
"T" && uid <= slc.
tjs.size() && type2Name ==
"P") {
4868 for (
auto& pfp : slc.
pfps) {
4869 if (pfp.ID <= 0)
continue;
4870 if (std::find(pfp.TjIDs.begin(), pfp.TjIDs.end(), id) != pfp.TjIDs.end())
4871 tmp.push_back(pfp.ID);
4876 if (type1Name ==
"P" && uid <= slc.
pfps.size() && (type2Name ==
"2S" || type2Name ==
"3S")) {
4878 auto& pfp = slc.
pfps[uid - 1];
4880 std::vector<int> ssid;
4881 for (
auto& ss : slc.
cots) {
4882 if (ss.ID <= 0)
continue;
4884 if (!shared.empty() && std::find(ssid.begin(), ssid.end(), ss.ID) == ssid.end())
4885 ssid.push_back(ss.ID);
4887 if (type2Name ==
"2S")
return ssid;
4888 for (
auto& ss3 : slc.
showers) {
4889 if (ss3.ID <= 0)
continue;
4891 if (!shared.empty() && std::find(tmp.begin(), tmp.end(), ss3.ID) == tmp.end())
4892 tmp.push_back(ss3.ID);
4897 if (type1Name ==
"2V" && uid <= slc.
vtxs.size() && type2Name ==
"T") {
4899 for (
auto& tj : slc.
tjs) {
4901 for (
unsigned short end = 0;
end < 2; ++
end) {
4902 if (tj.VtxID[
end] !=
id)
continue;
4903 if (std::find(tmp.begin(), tmp.end(), tj.ID) == tmp.end()) tmp.push_back(tj.ID);
4909 if (type1Name ==
"3V" && uid <= slc.
vtx3s.size() && type2Name ==
"P") {
4910 for (
auto& pfp : slc.
pfps) {
4911 if (pfp.ID == 0)
continue;
4912 for (
unsigned short end = 0;
end < 2; ++
end) {
4913 if (pfp.Vx3ID[
end] !=
id)
continue;
4915 if (std::find(tmp.begin(), tmp.end(), pfp.ID) == tmp.end()) tmp.push_back(pfp.ID);
4921 if (type1Name ==
"3V" && uid <= slc.
vtx3s.size() && type2Name ==
"T") {
4923 for (
auto& tj : slc.
tjs) {
4925 for (
unsigned short end = 0;
end < 2; ++
end) {
4926 if (tj.VtxID[
end] > 0 && tj.VtxID[
end] <= slc.
vtxs.size()) {
4927 auto& vx2 = slc.
vtxs[tj.VtxID[
end] - 1];
4928 if (vx2.Vx3ID !=
id)
continue;
4929 if (std::find(tmp.begin(), tmp.end(), tj.ID) == tmp.end()) tmp.push_back(tj.ID);
4936 if (type1Name ==
"3V" && uid <= slc.
vtx3s.size() && type2Name ==
"2V") {
4938 for (
auto& vx2 : slc.
vtxs) {
4939 if (vx2.ID == 0)
continue;
4940 if (vx2.Vx3ID ==
id) tmp.push_back(vx2.ID);
4945 if (type1Name ==
"3S" && uid <= slc.
showers.size() && type2Name ==
"T") {
4947 auto& ss3 = slc.
showers[uid - 1];
4948 if (ss3.ID == 0)
return tmp;
4949 for (
auto cid : ss3.CotIDs) {
4950 auto& ss = slc.
cots[cid - 1];
4951 if (ss.ID == 0)
continue;
4952 tmp.insert(tmp.end(), ss.TjIDs.begin(), ss.TjIDs.end());
4958 if (type1Name ==
"2S" && uid <= slc.
cots.size() && type2Name ==
"T") {
4960 auto& ss = slc.
cots[uid - 1];
4964 if (type1Name ==
"3S" && uid <= slc.
showers.size() && type2Name ==
"P") {
4966 auto& ss3 = slc.
showers[uid - 1];
4967 if (ss3.ID == 0)
return tmp;
4968 for (
auto cid : ss3.CotIDs) {
4969 auto& ss = slc.
cots[cid - 1];
4970 if (ss.ID == 0)
continue;
4971 for (
auto tid : ss.TjIDs) {
4972 auto& tj = slc.
tjs[tid - 1];
4974 if (!tj.AlgMod[
kMat3D])
continue;
4975 for (
auto& pfp : slc.
pfps) {
4976 if (pfp.ID <= 0)
continue;
4977 if (std::find(pfp.TjIDs.begin(), pfp.TjIDs.end(), tj.ID) == pfp.TjIDs.end())
continue;
4978 if (std::find(tmp.begin(), tmp.end(), pfp.ID) == tmp.end()) tmp.push_back(pfp.ID);
4985 if (type1Name ==
"T" && uid <= slc.
tjs.size() && type2Name ==
"2S") {
4987 for (
auto& ss : slc.
cots) {
4988 if (ss.ID == 0)
continue;
4989 if (std::find(ss.TjIDs.begin(), ss.TjIDs.end(), id) != ss.TjIDs.end()) tmp.push_back(ss.ID);
4994 if (type1Name ==
"T" && uid <= slc.
tjs.size() && type2Name ==
"3S") {
4996 for (
auto& ss : slc.
cots) {
4997 if (ss.ID == 0)
continue;
4998 if (std::find(ss.TjIDs.begin(), ss.TjIDs.end(), id) == ss.TjIDs.end())
continue;
4999 if (ss.SS3ID > 0) tmp.push_back(ss.SS3ID);
5011 unsigned int fromhit,
5013 unsigned short pass)
5019 float fromWire = fromHit.WireID().Wire;
5020 float fromTick = fromHit.PeakTime();
5021 float toWire = toHit.WireID().Wire;
5022 float toTick = toHit.PeakTime();
5024 bool success =
StartTraj(slc, tj, fromWire, fromTick, toWire, toTick, tCTP, pass);
5025 if (!success)
return false;
5030 auto& tp = tj.
Pts[0];
5032 << (
int)fromTick <<
" -> " << (
int)toWire <<
":" << (
int)toTick
5033 <<
" StepDir " << tj.
StepDir <<
" dir " << tp.Dir[0] <<
" " << tp.Dir[1]
5034 <<
" ang " << tp.Ang <<
" AngleCode " << tp.AngleCode <<
" angErr " 5049 unsigned short pass)
5060 int fWire = std::nearbyint(fromWire);
5061 int tWire = std::nearbyint(toWire);
5062 if (tWire < fWire) { stepdir = -1; }
5063 else if (tWire == fWire) {
5065 if (toTick < fromTick) stepdir = -1;
5075 if (!
MakeBareTrajPoint(slc, fromWire, fromTick, toWire, toTick, tCTP, tp))
return false;
5078 tj.
Pts.push_back(tp);
5083 auto& tp = tj.
Pts[0];
5085 << (
int)fromTick <<
" -> " << (
int)toWire <<
":" << (
int)toTick
5086 <<
" StepDir " << tj.
StepDir <<
" dir " << tp.
Dir[0] <<
" " << tp.
Dir[1]
5087 <<
" ang " << tp.
Ang <<
" AngleCode " << tp.
AngleCode <<
" angErr " 5095 std::pair<unsigned short, unsigned short>
5099 for (
unsigned short isl = 0; isl <
slices.size(); ++isl) {
5101 if (typeName ==
"T") {
5102 for (
unsigned short indx = 0; indx < slc.tjs.size(); ++indx) {
5103 if (slc.tjs[indx].UID == uID) {
return std::make_pair(isl, indx); }
5106 if (typeName ==
"P") {
5107 for (
unsigned short indx = 0; indx < slc.pfps.size(); ++indx) {
5108 if (slc.pfps[indx].UID == uID) {
return std::make_pair(isl, indx); }
5111 if (typeName ==
"2V") {
5112 for (
unsigned short indx = 0; indx < slc.vtxs.size(); ++indx) {
5113 if (slc.vtxs[indx].UID == uID) {
return std::make_pair(isl, indx); }
5116 if (typeName ==
"3V") {
5117 for (
unsigned short indx = 0; indx < slc.vtx3s.size(); ++indx) {
5118 if (slc.vtx3s[indx].UID == uID) {
return std::make_pair(isl, indx); }
5121 if (typeName ==
"2S") {
5122 for (
unsigned short indx = 0; indx < slc.cots.size(); ++indx) {
5123 if (slc.cots[indx].UID == uID) {
return std::make_pair(isl, indx); }
5126 if (typeName ==
"3S") {
5127 for (
unsigned short indx = 0; indx < slc.showers.size(); ++indx) {
5128 if (slc.showers[indx].UID == uID) {
return std::make_pair(isl, indx); }
5132 return std::make_pair(USHRT_MAX, USHRT_MAX);
5150 static double sum, sumx, sumy, sumx2, sumy2, sumxy;
5151 static unsigned short cnt;
5152 static std::vector<Point2_t> fitPts;
5153 static std::vector<double> fitWghts;
5170 if (inPtErr <= 0.)
return false;
5172 double wght = 1 / (inPtErr * inPtErr);
5174 sumx += wght * inPt[0];
5175 sumx2 += wght * inPt[0] * inPt[0];
5176 sumy += wght * inPt[1];
5177 sumy2 += wght * inPt[1] * inPt[1];
5178 sumxy += wght * inPt[0] * inPt[1];
5179 if (mode == 1)
return true;
5180 fitPts.push_back(inPt);
5181 fitWghts.push_back(wght);
5185 if (cnt < 2)
return false;
5187 double delta = sum * sumx2 - sumx * sumx;
5188 if (delta == 0.)
return false;
5189 double A = (sumx2 * sumy - sumx * sumxy) / delta;
5190 double B = (sumxy * sum - sumx * sumy) / delta;
5194 if (cnt == 2 || fitPts.empty())
return true;
5197 if (fitPts.size() != cnt)
return false;
5198 double ndof = cnt - 2;
5200 (sumy2 + A * A * sum + B * B * sumx2 - 2 * (A * sumy + B * sumxy - A * B * sumx)) / ndof;
5202 outVecErr[0] = sqrt(varnce * sumx2 / delta);
5203 outVecErr[1] = sqrt(varnce * sum / delta);
5211 for (
unsigned short ii = 0; ii < fitPts.size(); ++ii) {
5212 double arg = fitPts[ii][1] - A - B * fitPts[ii][0];
5213 sum += fitWghts[ii] * arg * arg;
5215 chiDOF = sum / ndof;
5229 if (strng ==
"instruct") {
5230 std::cout <<
"****** Unrecognized DebugConfig. Here are your options\n";
5231 std::cout <<
" 'C:T:P:W:Tick' where C = cryostat, T = TPC, W = wire, Tick (+/-5) to debug " 5232 "stepping (DUNE)\n";
5233 std::cout <<
" 'P:W:Tick' for single cryostat/TPC detectors (uB, LArIAT, etc)\n";
5234 std::cout <<
" 'WorkID <id> <slice index>' where <id> is a tj work ID (< 0) in slice <slice " 5235 "index> (default = 0)\n";
5236 std::cout <<
" 'Merge <CTP>' to debug trajectory merging\n";
5237 std::cout <<
" '2V <CTP>' to debug 2D vertex finding\n";
5238 std::cout <<
" '3V' to debug 3D vertex finding\n";
5239 std::cout <<
" 'VxMerge' to debug 2D vertex merging\n";
5240 std::cout <<
" 'JunkVx' to debug 2D junk vertex finder\n";
5241 std::cout <<
" 'PFP' to debug 3D matching and PFParticles\n";
5242 std::cout <<
" 'MVI <MVI> <MVI Iteration>' for detailed debugging of one PFP MatchVecIndex\n";
5243 std::cout <<
" 'DeltaRay' to debug delta ray tagging\n";
5244 std::cout <<
" 'Muon' to debug muon tagging\n";
5245 std::cout <<
" '2S <CTP>' to debug a 2D shower in CTP\n";
5246 std::cout <<
" 'Reco TPC <TPC>' to only reconstruct hits in the specified TPC\n";
5247 std::cout <<
" 'Reco Slice <ID>' to reconstruct all sub-slices in the recob::Slice with the " 5249 std::cout <<
" 'SubSlice <sub-slice index>' where <slice index> restricts output to the " 5250 "specified sub-slice index\n";
5251 std::cout <<
" 'Stitch' to debug PFParticle stitching between TPCs\n";
5252 std::cout <<
" 'Sum' or 'Summary' to print a debug summary report\n";
5253 std::cout <<
" 'Dump <WorkID>' or 'Dump <UID>' to print all TPs in the trajectory to " 5254 "tcdump<UID>.csv\n";
5255 std::cout <<
" Note: Algs with debug printing include HamVx, HamVx2, SplitTjCVx, Comp3DVx, " 5256 "Comp3DVxIG, VtxHitsSwap\n";
5257 std::cout <<
" Set SkipAlgs: [\"bogusText\"] to print a list of algorithm names\n";
5262 if (strng.find(
"3V") != std::string::npos) {
5267 if (strng.find(
"3S") != std::string::npos) {
5272 if (strng.find(
"VxMerge") != std::string::npos) {
5277 if (strng.find(
"JunkVx") != std::string::npos) {
5282 if (strng.find(
"DeltaRay") != std::string::npos) {
5287 if (strng.find(
"Muon") != std::string::npos) {
5292 if (strng.find(
"Stitch") != std::string::npos) {
5297 if (strng.find(
"HamVx") != std::string::npos) {
5302 if (strng.find(
"HamVx2") != std::string::npos) {
5307 if (strng.find(
"Sum") != std::string::npos) {
5313 std::vector<std::string> words;
5314 boost::split(words, strng, boost::is_any_of(
" :"), boost::token_compress_on);
5315 if (words.size() == 5) {
5317 debug.Cryostat = std::stoi(words[0]);
5318 debug.TPC = std::stoi(words[1]);
5319 debug.Plane = std::stoi(words[2]);
5320 debug.Wire = std::stoi(words[3]);
5321 debug.Tick = std::stoi(words[4]);
5328 if (words[0] ==
"PFP" || words[0] ==
"MVI") {
5332 if (words.size() > 2) {
5333 debug.MVI = std::stoi(words[1]);
5334 if (words.size() == 3)
debug.MVI_Iter = std::stoi(words[2]);
5338 if (words.size() == 2 && words[0] ==
"Dump") {
5339 debug.WorkID = std::stoi(words[1]);
5345 if (words.size() > 1 && words[0] ==
"WorkID") {
5346 debug.WorkID = std::stoi(words[1]);
5347 if (
debug.WorkID >= 0)
return false;
5350 if (words.size() > 2)
debug.Slice = std::stoi(words[2]);
5356 if (words.size() == 3 && words[0] ==
"Reco" && words[1] ==
"TPC") {
5359 std::cout <<
"Reconstructing only in TPC " <<
tcc.
recoTPC <<
"\n";
5362 if (words.size() == 3 && words[0] ==
"Reco" && words[1] ==
"Slice") {
5364 std::cout <<
"Reconstructing Slice " <<
tcc.
recoSlice <<
"\n";
5367 if (words.size() == 3) {
5371 debug.Plane = std::stoi(words[0]);
5372 debug.Wire = std::stoi(words[1]);
5373 debug.Tick = std::stoi(words[2]);
5379 if (words.size() == 2 && words[0] ==
"Merge") {
5380 debug.CTP = std::stoi(words[1]);
5385 if (words.size() == 2 && words[0] ==
"2V") {
5386 debug.CTP = std::stoi(words[1]);
5391 if (words.size() == 2 && words[0] ==
"2S") {
5392 debug.CTP = std::stoi(words[1]);
5398 if (words.size() == 2 && words[0] ==
"SubSlice") {
5399 debug.Slice = std::stoi(words[1]);
5414 for (
auto& slc :
slices) {
5415 for (
auto& tj : slc.tjs) {
5416 if (tj.WorkID !=
debug.WorkID && tj.UID !=
debug.WorkID)
continue;
5418 std::ofstream outfile;
5420 outfile.open(fname, std::ios::out | std::ios::trunc);
5421 outfile <<
"Dump trajectory T" << tj.UID <<
" WorkID " << tj.WorkID;
5424 outfile <<
"Wire, Chg T" << tj.UID
5425 <<
", totChg, Tick, Delta, NTPsFit, Ang, ChiDOF, KinkSig, HitPosErr\n";
5426 for (
unsigned short ipt = tj.EndPt[0]; ipt <= tj.EndPt[1]; ++ipt) {
5427 auto& tp = tj.Pts[ipt];
5428 outfile << std::fixed;
5430 outfile <<
"," << (
int)tp.Chg;
5433 for (
auto iht : tp.Hits) {
5435 totChg +=
hit.Integral();
5437 outfile <<
"," << (
int)totChg;
5440 outfile <<
"," << tp.NTPsFit;
5448 std::cout <<
"Points on T" << tj.UID <<
" dumped to " << fname <<
"\n";
5461 std::cout <<
"*** TrajCluster debug mode configuration in";
5462 std::cout <<
" CTP=";
5463 if (
debug.CTP == UINT_MAX) { std::cout <<
"NA"; }
5465 std::cout <<
debug.CTP;
5467 std::cout <<
" Cryostat=" <<
debug.Cryostat;
5468 std::cout <<
" TPC=" <<
debug.TPC;
5469 std::cout <<
" Plane=" <<
debug.Plane;
5470 std::cout <<
" Wire=" <<
debug.Wire;
5471 std::cout <<
" Tick=" <<
debug.Tick;
5472 std::cout <<
" Hit=";
5473 if (
debug.Hit == UINT_MAX) { std::cout <<
"NA"; }
5475 std::cout <<
debug.Hit;
5477 std::cout <<
" WorkID=";
5478 if (
debug.WorkID == 0) { std::cout <<
"NA"; }
5480 std::cout <<
debug.WorkID;
5482 std::cout <<
" Slice=";
5483 if (
debug.Slice == -1) { std::cout <<
"All"; }
5485 std::cout <<
debug.Slice;
5488 std::cout <<
"*** tcc.dbg modes:";
5492 if (
tcc.
dbg2V) std::cout <<
" dbg2V";
5493 if (
tcc.
dbg2S) std::cout <<
" dbg2S";
5497 if (
tcc.
dbg3V) std::cout <<
" dbg3V";
5505 std::cout <<
"*** Using algs:";
5506 unsigned short cnt = 0;
5507 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib) {
5510 if (cnt % 10 == 0) std::cout <<
"\n ";
5515 std::cout <<
"*** Skipping algs:";
5517 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib) {
5520 if (cnt % 10 == 0) std::cout <<
"\n ";
5537 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5538 if (
debug.Slice >= 0 &&
int(isl) !=
debug.Slice)
continue;
5540 if (!slc.vtx3s.empty()) prt3V =
true;
5541 if (!slc.vtxs.empty()) prt2V =
true;
5542 if (!slc.tjs.empty()) prtT =
true;
5543 if (!slc.pfps.empty()) prtP =
true;
5544 if (!slc.showers.empty()) prtS3 =
true;
5547 myprt <<
"Debug report from caller " << someText <<
"\n";
5548 myprt <<
" 'prodID' = <sliceID>:<subSliceIndex>:<productID>/<productUID>\n";
5550 myprt <<
"************ Showers ************\n";
5551 myprt <<
" prodID Vtx parUID ___ChgPos____ ______Dir_____ ____posInPln____ " 5552 "___projInPln____ 2D shower UIDs\n";
5553 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5554 if (
debug.Slice >= 0 &&
int(isl) !=
debug.Slice)
continue;
5556 if (slc.showers.empty())
continue;
5557 for (
auto& ss3 : slc.showers)
5558 Print3S(detProp, someText, myprt, ss3);
5562 bool printHeader =
true;
5563 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5564 if (
debug.Slice >= 0 &&
int(isl) !=
debug.Slice)
continue;
5566 if (slc.pfps.empty())
continue;
5567 for (
auto& pfp : slc.pfps)
5568 PrintP(someText, myprt, pfp, printHeader);
5572 bool printHeader =
true;
5573 myprt <<
"****** 3D vertices " 5574 "******************************************__2DVtx_UID__*******\n";
5575 myprt <<
" prodID Cstat TPC X Y Z XEr YEr " 5576 "ZEr pln0 pln1 pln2 Wire score Prim? Nu? nTru";
5577 myprt <<
" ___________2D_Pos____________ _____Tj UIDs________\n";
5578 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5579 if (
debug.Slice >= 0 &&
int(isl) !=
debug.Slice)
continue;
5581 if (slc.vtx3s.empty())
continue;
5582 for (
auto& vx3 : slc.vtx3s)
5583 Print3V(detProp, someText, myprt, vx3, printHeader);
5587 bool printHeader =
true;
5588 myprt <<
"************ 2D vertices ************\n";
5589 myprt <<
" prodID CTP wire err tick err ChiDOF NTj Pass " 5590 " Topo ChgFrac Score v3D Tj UIDs\n";
5591 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5592 if (
debug.Slice >= 0 &&
int(isl) !=
debug.Slice)
continue;
5594 if (slc.vtxs.empty())
continue;
5595 for (
auto& vx2 : slc.vtxs)
5596 Print2V(someText, myprt, vx2, printHeader);
5600 bool printHeader =
true;
5601 for (
size_t isl = 0; isl <
slices.size(); ++isl) {
5602 if (
debug.Slice >= 0 &&
int(isl) !=
debug.Slice)
continue;
5604 if (slc.tjs.empty())
continue;
5605 for (
auto& tj : slc.tjs)
5606 PrintT(someText, myprt, tj, printHeader);
5615 if (pfp.
ID <= 0)
return;
5617 myprt <<
"************ PFParticles ************\n";
5618 myprt <<
" prodID sVx _____sPos____ CS _______sDir______ ____sdEdx_____ eVx " 5619 "_____ePos____ CS ____edEdx_____ MVI MCSMom Len nTP3 nSec SLk? PDG Par \n";
5620 printHeader =
false;
5623 if (sIndx.first == USHRT_MAX)
return;
5624 auto& slc =
slices[sIndx.first];
5630 for (
unsigned short end = 0;
end < 2; ++
end) {
5652 for (
auto& dedx : pfp.
dEdx[
end]) {
5658 if (pfp.
dEdx[end].size() < 3) {
5659 for (
size_t i = 0; i < 3 - pfp.
dEdx[
end].size(); ++i) {
5677 if (!pfp.
TjIDs.empty()) {
5678 if (pfp.
TjUIDs.empty()) {
5680 for (
auto tjid : pfp.
TjIDs)
5681 myprt <<
" TU" << slc.tjs[tjid - 1].UID;
5685 for (
auto tjuid : pfp.
TjUIDs)
5686 myprt <<
" TU" << tjuid;
5691 for (
auto dtruid : pfp.
DtrUIDs)
5692 myprt <<
" PU" << dtruid;
5706 if (vx3.
ID <= 0)
return;
5708 if (sIndx.first == USHRT_MAX)
return;
5709 auto& slc =
slices[sIndx.first];
5712 <<
"****** 3D vertices ******************************************__2DVtx_UID__*******\n";
5713 myprt <<
" prodID Cstat TPC X Y Z pln0 pln1 pln2 Wire score " 5715 myprt <<
" ___________2D_Pos____________ _____Tj UIDs________\n";
5716 printHeader =
false;
5726 for (
auto vx2id : vx3.
Vx2ID) {
5736 unsigned short nTruMatch = 0;
5737 for (
unsigned short ipl = 0; ipl < slc.nPlanes; ++ipl) {
5738 if (vx3.
Vx2ID[ipl] == 0)
continue;
5739 unsigned short iv2 = vx3.
Vx2ID[ipl] - 1;
5747 for (
unsigned short plane = 0; plane < slc.nPlanes; ++plane) {
5749 myprt <<
" " <<
PrintPos(slc, pos);
5751 if (vx3.
Wire == -2) {
5753 for (
unsigned short end = 0;
end < 2; ++
end) {
5754 for (
auto& pfp : slc.pfps) {
5755 if (pfp.Vx3ID[
end] == vx3.
ID) {
5756 for (
auto tjID : pfp.TjIDs) {
5757 auto& tj = slc.tjs[tjID - 1];
5758 myprt <<
" T" << tj.UID;
5765 auto vxtjs =
GetAssns(slc,
"3V", vx3.
ID,
"T");
5766 for (
auto tjid : vxtjs) {
5767 auto& tj = slc.tjs[tjid - 1];
5768 myprt <<
" TU" << tj.UID;
5779 if (vx2.
ID <= 0)
return;
5782 if (sIndx.first == USHRT_MAX)
return;
5783 auto& slc =
slices[sIndx.first];
5785 myprt <<
"************ 2D vertices ************\n";
5786 myprt <<
" prodID CTP wire err tick err ChiDOF NTj Pass Topo ChgFrac Score " 5788 printHeader =
false;
5805 if (vx2.
Vx3ID > 0) v3id = slc.vtx3s[vx2.
Vx3ID - 1].UID;
5809 for (
unsigned short ii = 0; ii < slc.tjs.size(); ++ii) {
5810 auto const& tj = slc.tjs[ii];
5811 if (tj.AlgMod[
kKilled])
continue;
5812 for (
unsigned short end = 0;
end < 2; ++
end) {
5813 if (tj.VtxID[
end] != (
short)vx2.
ID)
continue;
5820 for (
unsigned short ib = 1; ib <
VtxBitNames.size(); ++ib)
5832 if (ss3.
ID <= 0)
return;
5834 if (sIndx.first == USHRT_MAX)
return;
5835 auto& slc =
slices[sIndx.first];
5843 for (
unsigned short xyz = 0; xyz < 3; ++xyz)
5845 for (
unsigned short xyz = 0; xyz < 3; ++xyz)
5847 std::vector<float> projInPlane(slc.nPlanes);
5848 for (
unsigned short plane = 0; plane < slc.nPlanes; ++plane) {
5851 myprt <<
" " <<
PrintPos(slc, tp.Pos);
5852 projInPlane[plane] = tp.Delta;
5854 for (
unsigned short plane = 0; plane < slc.nPlanes; ++plane) {
5857 for (
auto cid : ss3.
CotIDs) {
5858 auto& ss = slc.cots[cid - 1];
5862 if (ss3.
NeedsUpdate) myprt <<
" *** Needs update";
5871 if (tj.
ID <= 0)
return;
5874 myprt <<
"************ Trajectories ************\n";
5875 myprt <<
"Tj AngleCode-EndFlag decoder (EF): <AngleCode> + <reason for stopping>";
5876 myprt <<
" (B=Bragg Peak, V=Vertex, A=AngleKink, C=ChargeKink, T=Trajectory)\n";
5877 myprt <<
" prodID CTP Pass Pts W:T Ang EF AveQ W:T Ang EF AveQ " 5878 "Chg(k) chgRMS Mom __Vtx__ PDG eLike Par Pri NuPar WorkID \n";
5879 printHeader =
false;
5882 if (sIndx.first == USHRT_MAX)
return;
5883 auto& slc =
slices[sIndx.first];
5889 unsigned short endPt0 = tj.
EndPt[0];
5890 auto& tp0 = tj.
Pts[endPt0];
5892 if (itick < 0) itick = 0;
5893 myprt <<
std::setw(6) << (
int)(tp0.Pos[0] + 0.5) <<
":" << itick;
5894 if (itick < 10) { myprt <<
" "; }
5895 if (itick < 100) { myprt <<
" "; }
5896 if (itick < 1000) { myprt <<
" "; }
5913 unsigned short endPt1 = tj.
EndPt[1];
5914 auto& tp1 = tj.
Pts[endPt1];
5916 myprt <<
std::setw(6) << (
int)(tp1.Pos[0] + 0.5) <<
":" << itick;
5917 if (itick < 10) { myprt <<
" "; }
5918 if (itick < 100) { myprt <<
" "; }
5919 if (itick < 1000) { myprt <<
" "; }
5940 if (tj.
VtxID[0] > 0) vxid = slc.vtxs[tj.
VtxID[0] - 1].UID;
5943 if (tj.
VtxID[1] > 0) vxid = slc.vtxs[tj.
VtxID[1] - 1].UID;
5951 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
5971 if (!slc.
vtx3s.empty()) {
5975 <<
"****** 3D vertices ******************************************__2DVtx_ID__*******\n";
5977 <<
" Vtx Cstat TPC X Y Z XEr YEr ZEr pln0 pln1 pln2 Wire " 5978 "score Prim? Nu? nTru";
5979 myprt <<
" ___________2D_Pos____________ _____Tjs________\n";
5980 for (
unsigned short iv = 0; iv < slc.
vtx3s.size(); ++iv) {
5981 if (slc.
vtx3s[iv].ID == 0)
continue;
5999 unsigned short nTruMatch = 0;
6000 for (
unsigned short ipl = 0; ipl < slc.
nPlanes; ++ipl) {
6001 if (vx3.
Vx2ID[ipl] == 0)
continue;
6002 unsigned short iv2 = vx3.
Vx2ID[ipl] - 1;
6010 for (
unsigned short plane = 0; plane < slc.
nPlanes; ++plane) {
6012 myprt <<
" " <<
PrintPos(slc, pos);
6014 if (vx3.
Wire == -2) {
6016 for (
auto& pfp : slc.
pfps) {
6017 if (pfp.Vx3ID[0] == slc.
vtx3s[iv].ID) {
6018 for (
auto& tjID : pfp.TjIDs)
6019 myprt <<
" t" << tjID;
6021 if (pfp.Vx3ID[1] == slc.
vtx3s[iv].ID) {
6022 for (
auto& tjID : pfp.TjIDs)
6023 myprt <<
" t" << tjID;
6028 auto vxtjs =
GetAssns(slc,
"3V", vx3.
ID,
"T");
6029 for (
auto tjid : vxtjs)
6030 myprt <<
" t" << tjid;
6035 if (!slc.
vtxs.empty()) {
6036 bool foundOne =
false;
6037 for (
unsigned short iv = 0; iv < slc.
vtxs.size(); ++iv) {
6038 auto& vx2 = slc.
vtxs[iv];
6040 if (vx2.NTraj == 0)
continue;
6045 myprt << someText <<
"************ 2D vertices ************\n";
6047 <<
" ID CTP wire err tick err ChiDOF NTj Pass Topo ChgFrac Score v3D " 6049 for (
auto& vx2 : slc.
vtxs) {
6050 if (vx2.ID == 0)
continue;
6057 << std::nearbyint(vx2.Pos[0]);
6072 for (
unsigned short ii = 0; ii < slc.
tjs.size(); ++ii) {
6073 auto const& aTj = slc.
tjs[ii];
6075 if (aTj.AlgMod[
kKilled])
continue;
6076 for (
unsigned short end = 0;
end < 2; ++
end) {
6077 if (aTj.VtxID[
end] != (
short)vx2.ID)
continue;
6083 for (
unsigned short ib = 1; ib <
VtxBitNames.size(); ++ib)
6084 if (vx2.Stat[ib]) myprt <<
" " <<
VtxBitNames[ib];
6091 if (slc.
tjs.empty()) {
6092 mf::LogVerbatim(
"TC") << someText <<
" No allTraj trajectories to print";
6098 if (itj == USHRT_MAX) {
6100 myprt <<
"Tj AngleCode-EndFlag (EF) decoder: <AngleCode> + <reason for stopping>";
6101 myprt <<
" (B=Bragg Peak, V=Vertex, A=AngleKink, C=ChargeKink, T=Trajectory)\n";
6102 std::vector<unsigned int>
tmp;
6104 <<
" UID CTP Pass Pts W:T Ang EF AveQ W:T Ang EF AveQ Chg(k) " 6105 "chgRMS Mom SDr __Vtx__ PDG Par Pri NuPar WorkID \n";
6106 for (
unsigned short ii = 0; ii < slc.
tjs.size(); ++ii) {
6107 auto& aTj = slc.
tjs[ii];
6108 if (
debug.CTP != UINT_MAX && aTj.CTP !=
debug.CTP)
continue;
6109 myprt << someText <<
" ";
6115 myprt << std::fixed <<
std::setw(5) << tid;
6118 myprt <<
std::setw(5) << aTj.EndPt[1] - aTj.EndPt[0] + 1;
6119 unsigned short endPt0 = aTj.EndPt[0];
6120 auto& tp0 = aTj.Pts[endPt0];
6122 if (itick < 0) itick = 0;
6123 myprt <<
std::setw(6) << (
int)(tp0.Pos[0] + 0.5) <<
":" << itick;
6124 if (itick < 10) { myprt <<
" "; }
6125 if (itick < 100) { myprt <<
" "; }
6126 if (itick < 1000) { myprt <<
" "; }
6129 if (aTj.EndFlag[0][
kBragg]) { myprt <<
"B"; }
6130 else if (aTj.EndFlag[0][
kAtVtx]) {
6133 else if (aTj.EndFlag[0][
kAtKink]) {
6136 else if (aTj.EndFlag[0][
kAtTj]) {
6143 unsigned short endPt1 = aTj.EndPt[1];
6144 auto& tp1 = aTj.Pts[endPt1];
6146 myprt <<
std::setw(6) << (
int)(tp1.Pos[0] + 0.5) <<
":" << itick;
6147 if (itick < 10) { myprt <<
" "; }
6148 if (itick < 100) { myprt <<
" "; }
6149 if (itick < 1000) { myprt <<
" "; }
6152 if (aTj.EndFlag[1][
kBragg]) { myprt <<
"B"; }
6153 else if (aTj.EndFlag[1][
kAtVtx]) {
6171 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6172 if (aTj.AlgMod[ib]) myprt <<
" " <<
AlgBitNames[ib];
6178 if (itj > slc.
tjs.size() - 1)
return;
6180 auto const& aTj = slc.
tjs[itj];
6182 mf::LogVerbatim(
"TC") <<
"Print slc.tjs[" << itj <<
"] Vtx[0] " << aTj.VtxID[0] <<
" Vtx[1] " 6185 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6186 if (aTj.AlgMod[ib]) myprt <<
" " <<
AlgBitNames[ib];
6190 if (ipt == USHRT_MAX) {
6192 for (
unsigned short ii = 0; ii < aTj.Pts.size(); ++ii)
6193 PrintTP(someText, slc, ii, aTj.StepDir, aTj.Pass, aTj.Pts[ii]);
6197 PrintTP(someText, slc, ipt, aTj.StepDir, aTj.Pass, aTj.Pts[ipt]);
6206 unsigned short tPoint)
6210 if (tPoint == USHRT_MAX) {
6213 myprt << someText <<
" ";
6214 myprt <<
"Work: UID " << tj.
UID <<
" CTP " << tj.
CTP <<
" StepDir " << tj.
StepDir 6216 <<
" nPts " << tj.
Pts.size() <<
" EndPts " << tj.
EndPt[0] <<
" " << tj.
EndPt[1];
6217 myprt <<
" MCSMom " << tj.
MCSMom;
6219 myprt <<
" AlgMods:";
6220 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6225 myprt << someText <<
" ";
6226 myprt <<
"slcID " << slc.
ID <<
" T" << tj.
ID <<
" uT" << tj.
UID <<
" WorkID " << tj.
WorkID 6228 <<
" " << tj.
VtxID[1] <<
" nPts " << tj.
Pts.size() <<
" EndPts " << tj.
EndPt[0] <<
" " 6230 myprt <<
" MCSMom " << tj.
MCSMom;
6232 myprt <<
" AlgMods:";
6233 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
6237 for (
unsigned short ipt = 0; ipt < tj.
Pts.size(); ++ipt)
6241 for (
unsigned short ic = 0; ic < slc.
cots.size(); ++ic) {
6242 if (slc.
cots[ic].TjIDs.empty())
continue;
6244 if (slc.
cots[ic].ShowerTjID != tj.
ID)
continue;
6247 myprt <<
"cots index " << ic <<
" ";
6248 myprt << someText <<
" Envelope";
6249 if (ss.
Envelope.empty()) { myprt <<
" NA"; }
6257 myprt <<
"\nInShower TjIDs";
6259 myprt <<
" " << tjID;
6263 myprt <<
"NearTjIDs";
6265 myprt <<
" " << tjID;
6275 myprt <<
" No parent";
6277 myprt <<
" TruParentID " << ss.
TruParentID <<
" SS3ID " << ss.
SS3ID <<
"\n";
6278 if (ss.
NeedsUpdate) myprt <<
"*********** This shower needs to be updated ***********";
6279 myprt <<
"................................................";
6285 if (tPoint > tj.
Pts.size() - 1) {
6286 mf::LogVerbatim(
"TC") <<
"Can't print non-existent traj point " << tPoint;
6298 <<
" TRP CTP Ind Stp Delta RMS Ang C Err Dir0 Dir1 Q " 6299 " AveQ Pull FitChi NTPF KinkSig Hits ";
6308 unsigned short pass,
6312 myprt << someText <<
" TRP" << std::fixed;
6314 if (dir > 0) { myprt <<
"+"; }
6335 if (tp.
Hits.size() > 16) {
6337 myprt <<
" " << tp.
Hits.size() <<
" shower hits";
6340 for (
unsigned short ii = 0; ii < tp.
Hits.size(); ++ii) {
6341 unsigned int iht = tp.
Hits[ii];
6343 myprt <<
" " <<
hit.WireID().Wire <<
":" << (
int)
hit.PeakTime();
6351 myprt <<
"T" << slc.
slHits[iht].InTraj;
6353 if (tp.
InPFP > 0) myprt <<
" inP" << tp.
InPFP;
6365 for (
unsigned short ib = 0; ib < 8; ++ib) {
6374 if (ib ==
kEnvFlag) str +=
" Flag";
6386 myprt <<
" PFP sVx ________sPos_______ EF _______sDir______ ____sdEdx_____ eVx " 6387 "________ePos_______ EF _______eDir______ ____edEdx____ Len nTp3 MCSMom ShLike? " 6394 for (
unsigned short end = 0;
end < 2; ++
end) {
6414 for (
auto& dedx : pfp.
dEdx[
end]) {
6420 if (pfp.
dEdx[end].size() < 3) {
6421 for (
size_t i = 0; i < 3 - pfp.
dEdx[
end].size(); ++i) {
6439 if (!pfp.
TjIDs.empty()) {
6440 for (
auto& tjID : pfp.
TjIDs)
6441 myprt <<
" T" << tjID;
6445 for (
auto& dtrUID : pfp.
DtrUIDs)
6446 myprt <<
" P" << dtrUID;
6454 if (slc.
pfps.empty())
return;
6459 <<
" PFP sVx ________sPos_______ ______sDir______ ______sdEdx_____ eVx " 6460 "________ePos_______ ______eDir______ ______edEdx_____ BstPln PDG TruPDG Par Prim E*P\n";
6461 bool printHeader =
true;
6462 for (
auto& pfp : slc.
pfps) {
6463 PrintPFP(someText, slc, pfp, printHeader);
6464 printHeader =
false;
6473 if (end > 1)
return "Invalid end";
6476 for (
unsigned short ib = 0; ib <
EndFlagNames.size(); ++ib) {
6487 if (first) tmp =
" none";
6495 if (end > 1)
return "Invalid end";
6498 for (
unsigned short ib = 0; ib <
EndFlagNames.size(); ++ib) {
6543 unsigned int wire = 0;
6544 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.
bool valDecreasing(SortEntry c1, SortEntry c2)
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)
int PDGCodeVote(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
Point2_t dEdx
dE/dx for 3D matched trajectories
float Length(const PFPStruct &pfp)
bool dbgStitch
debug PFParticle stitching
void SetEndPoints(Trajectory &tj)
float PointPull(TCSlice &slc, Point2_t pos, float chg, const 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)
std::vector< float > kinkCuts
kink finder algorithm
bool InTrajOK(TCSlice &slc, std::string someText)
bool FillWireHitRange(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, TCSlice &slc)
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
unsigned short NumPtsWithCharge(const TCSlice &slc, const Trajectory &tj, bool includeDeadWires, unsigned short firstPt, unsigned short lastPt)
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
float ChgFracBetween(const TCSlice &slc, TrajPoint tp, float toPos0)
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)
float PosSep(const Point2_t &pos1, const Point2_t &pos2)
std::vector< Point2_t > Envelope
void SetPDGCode(TCSlice &slc, Trajectory &tj)
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
Declaration of signal hit object.
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
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)
bool MakeBareTrajPoint(const TCSlice &slc, const TrajPoint &tpIn1, const TrajPoint &tpIn2, TrajPoint &tpOut)
void FindAlongTrans(Point2_t pos1, Vector2_t dir1, Point2_t pos2, Point2_t &alongTrans)
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)
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)
a general purpose flag bit used in 3D matching
bool SetMag(Vector2_t &v1, double mag)
bool dbgSlc
debug only in the user-defined slice? default is all slices
float KinkSignificance(TCSlice &slc, Trajectory &tj, unsigned short kinkPt, unsigned short nPtsFit, bool useChg, bool prt)
std::vector< unsigned int > lastWire
the last wire with a hit
float GoodnessOfFit() const
Degrees of freedom in the determination of the hit signal shape (-1 by default)
bool LongPulseHit(const recob::Hit &hit)
std::array< int, 2 > Vx3ID
bool expectSlicedHits
info passed from the module - used to (not) define wireHitRange
float PointTrajDOCA(const TCSlice &slc, float wire, float time, TrajPoint const &tp)
short int Multiplicity() const
How many hits could this one be shared with.
float TPHitsRMSTime(const TCSlice &slc, const TrajPoint &tp, HitStatus_t hitRequest)
bool IsShowerLike(TCSlice &slc, const std::vector< int > TjIDs)
unsigned short NumUsedHitsInTj(const TCSlice &slc, const Trajectory &tj)
std::string TPEnvString(const TrajPoint &tp)
pure virtual base interface for detector clocks
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
bool SignalBetween(const TCSlice &slc, TrajPoint tp, float toPos0, const float &MinWireSignalFraction)
std::string PrintHitShort(const TCHit &tch)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
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)
Access the description of detector geometry.
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 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
std::array< float, 2 > Point2_t
std::vector< float > maxPos1
float unitsPerTick
scale factor from Tick to WSE equivalent units
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::string PrintEndFlag(const Trajectory &tj, unsigned short end)
bool TrajIsClean(TCSlice &slc, Trajectory &tj, bool prt)
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)
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
bool TrajHitsOK(TCSlice &slc, const unsigned int iht, const unsigned int jht)
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)
std::vector< std::vector< bool > > goodWire
float ChgFracNearPos(const TCSlice &slc, const Point2_t &pos, const std::vector< int > &tjIDs)
void MakeHaloTj(TCSlice &slc, Trajectory &muTj, bool prt)
void FitTraj(TCSlice &slc, Trajectory &tj, unsigned short originPt, unsigned short npts, short fitDir, TrajPoint &tpFit)
TrajPoint MakeBareTP(detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, const Point3_t &pos, const Vector3_t &dir, CTP_t inCTP)
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)
unsigned short GetPFPIndex(const TCSlice &slc, int tjID)
std::string PrintHit(const TCHit &tch)
bool Fit2D(short mode, Point2_t inPt, float &inPtErr, Vector2_t &outVec, Vector2_t &outVecErr, float &chiDOF)
bool StartTraj(TCSlice &slc, Trajectory &tj, float fromWire, float fromTick, float toWire, float toTick, CTP_t &tCTP, unsigned short pass)
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.
bool SplitTraj(TCSlice &slc, unsigned short itj, unsigned short pos, unsigned short ivx, bool prt)
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)
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 CompatibleMerge(const TCSlice &slc, const Trajectory &tj1, const Trajectory &tj2, bool prt)
double MCSThetaRMS(const TCSlice &slc, const Trajectory &tj, unsigned short firstPt, unsigned short lastPt)
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)
float PosSep2(const Point2_t &pos1, const Point2_t &pos2)
bool FindCloseHits(TCSlice &slc, TrajPoint &tp, float const &maxDelta, HitStatus_t hitRequest)
std::bitset< 16 > modes
number of points to find AveChg
std::vector< TCHit > slHits
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.
unsigned short FarEnd(TCSlice &slc, const Trajectory &tj, const 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
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
bool TrajTrajDOCA(const TCSlice &slc, const Trajectory &tj1, const Trajectory &tj2, unsigned short &ipt1, unsigned short &ipt2, float &minSep, bool considerDeadWires)
geo::PlaneID DecodeCTP(CTP_t CTP)
unsigned short AngleRange(float angle)
Vector2_t PointDirection(const Point2_t p1, const Point2_t p2)
std::vector< int > GetVtxTjIDs(const TCSlice &slc, const VtxStore &vx2)
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)
std::vector< unsigned int > nWires
use the stiff electron strategy
std::array< std::bitset< 8 >, 2 > EndFlag
float PointTrajSep2(float wire, float time, TrajPoint const &tp)
std::array< double, 3 > Vector3_t
std::vector< float > chkStopCuts
Bragg peak finder configuration.
bool SignalAtTpInSlc(const TCSlice &slc, const TrajPoint &tp)
std::vector< TP3D > TP3Ds
int ID
ID of the recob::Slice (not the sub-slice)
std::array< std::vector< float >, 2 > dEdx
void SetVx2Score(TCSlice &slc)
std::vector< float > vtx2DCuts
Max position pull, max Position error rms.
std::bitset< 8 > Strategy
bool NearbySrcHit(geo::PlaneID plnID, unsigned int wire, float loTick, float hiTick)
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)
2D representation of charge deposited in the TDC/wire plane
void MoveTPToWire(TrajPoint &tp, float wire)
void MergeGhostTjs(TCSlice &slc, CTP_t inCTP)
unsigned int ChannelID_t
Type representing the ID of a readout channel.
unsigned int allHitsIndex
short MCSMom(const TCSlice &slc, const Trajectory &tj, unsigned short firstPt, unsigned short lastPt)
TPCID_t TPC
Index of the TPC within its cryostat.
Interface for experiment-specific service for channel quality info.
std::string PrintPos(const TCSlice &slc, const Point2_t &pos)
void TrajIntersection(TrajPoint const &tp1, TrajPoint const &tp2, float &x, float &y)
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)
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)
double DeltaAngle(double Ang1, double Ang2)
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)
std::vector< int > DtrUIDs
constexpr Point origin()
Returns a origin position with a point of the specified type.
use the stiff muon strategy
void UpdateVxEnvironment(TCSlice &slc, VtxStore &vx2, bool prt)
Encapsulate the construction of a single detector plane.
std::array< std::bitset< 8 >, 2 > EndFlag
void SetTPEnvironment(TCSlice &slc, CTP_t inCTP)
float DeadWireCount(const TCSlice &slc, const float &inWirePos1, const float &inWirePos2, CTP_t tCTP)
bool HasDuplicateHits(const TCSlice &slc, Trajectory const &tj, bool prt)