24 #include "messagefacility/MessageLogger/MessageLogger.h"
25 #include "fhiclcpp/ParameterSet.h"
36 : fCaloAlg(pset.
get<fhicl::ParameterSet>(
"CaloAlg")), fMVAReader(
"Silent")
40 bool badinput =
false;
47 if (pset.has_key(
"Mode")) userMode = pset.get<
short>(
"Mode");
49 if (pset.has_key(
"DoForecast"))
tcc.
doForecast = pset.get<
bool>(
"DoForecast");
50 if (pset.has_key(
"UseChannelStatus"))
tcc.
useChannelStatus = pset.get<
bool>(
"UseChannelStatus");
51 if (pset.has_key(
"StudyMode")) {
52 std::cout <<
"StudyMode is not valid anymore. Try Study: 1 or Study: 2, etc/n";
54 if (pset.has_key(
"Study")) {
55 userMode = pset.get<
short>(
"Study");
61 if (pset.has_key(
"SaveShowerTree"))
65 std::vector<std::string> skipAlgsVec;
66 if (pset.has_key(
"SkipAlgs")) skipAlgsVec = pset.get<std::vector<std::string>>(
"SkipAlgs");
67 std::vector<std::string> debugConfigVec;
68 if (pset.has_key(
"DebugConfig"))
69 debugConfigVec = pset.get<std::vector<std::string>>(
"DebugConfig");
73 std::vector<float> aveHitRMS;
74 if (pset.has_key(
"AveHitRMS")) aveHitRMS = pset.get<std::vector<float>>(
"AveHitRMS");
76 if (!aveHitRMS.empty()) {
82 tcc.
minPtsFit = pset.get<std::vector<unsigned short>>(
"MinPtsFit");
83 tcc.
minPts = pset.get<std::vector<unsigned short>>(
"MinPts");
84 tcc.
maxAngleCode = pset.get<std::vector<unsigned short>>(
"MaxAngleCode");
85 tcc.
minMCSMom = pset.get<std::vector<short>>(
"MinMCSMom");
86 tcc.
maxChi = pset.get<
float>(
"MaxChi", 10);
87 tcc.
chargeCuts = pset.get<std::vector<float>>(
"ChargeCuts", {3, 0.15, 0.25});
89 tcc.
kinkCuts = pset.get<std::vector<float>>(
"KinkCuts");
90 tcc.
qualityCuts = pset.get<std::vector<float>>(
"QualityCuts", {0.8, 3});
96 tcc.
deltaRayTag = pset.get<std::vector<short>>(
"DeltaRayTag", {-1, -1, -1});
97 tcc.
muonTag = pset.get<std::vector<short>>(
"MuonTag", {-1, -1, -1, -1});
98 if (pset.has_key(
"ElectronTag"))
tcc.
electronTag = pset.get<std::vector<float>>(
"ElectronTag");
99 tcc.
showerTag = pset.get<std::vector<float>>(
"ShowerTag", {-1, -1, -1, -1, -1, -1});
100 std::string fMVAShowerParentWeights =
"NA";
101 pset.get_if_present<std::string>(
"MVAShowerParentWeights", fMVAShowerParentWeights);
102 tcc.
chkStopCuts = pset.get<std::vector<float>>(
"ChkStopCuts", {-1, -1, -1});
103 if (pset.has_key(
"MatchTruth")) {
104 std::cout <<
"MatchTruth is not used. Use ClusterAnaV2 or DebugConfig to configure\n";
106 tcc.
vtx2DCuts = pset.get<std::vector<float>>(
"Vertex2DCuts", {-1, -1, -1, -1, -1, -1, -1});
107 tcc.
vtx3DCuts = pset.get<std::vector<float>>(
"Vertex3DCuts", {-1, -1});
109 tcc.
match3DCuts = pset.get<std::vector<float>>(
"Match3DCuts", {-1, -1, -1, -1, -1});
113 pset.get_if_present<std::vector<float>>(
"NeutralVxCuts",
tcc.
neutralVxCuts);
121 throw art::Exception(art::errors::Configuration)
122 <<
"Bad input from fcl file. Vector lengths for MinPtsFit, MaxAngleRange and MinMCSMom "
123 "should be defined for each reconstruction pass";
126 throw art::Exception(art::errors::Configuration)
127 <<
"Vertex2DCuts must be size 11\n 0 = Max length definition for short TJs\n 1 = Max "
128 "vtx-TJ sep short TJs\n 2 = Max vtx-TJ sep long TJs\n 3 = Max position pull for >2 "
129 "TJs\n 4 = Max vtx position error\n 5 = Min MCSMom for one of two TJs\n 6 = Min "
130 "fraction of wires hit btw vtx and Tjs\n 7 = Min Score\n 8 = min ChgFrac at a vtx or "
131 "merge point\n 9 = max MCSMom asymmetry, 10 = require chg on wires btw vtx and tjs in "
139 throw art::Exception(art::errors::Configuration)
140 <<
"Vertex3DCuts must be size > 2\n 0 = 2D Vtx max dX (cm)\n 1 = 2D Vtx max pull\n 2 = max "
141 "3D separation (cm) btw PFP and vertex";
143 std::cout <<
"WARNING: Vertex3DCuts is size 2 but should be size 3, where Vertex3DCuts[2] = "
144 "max 3D separation (cm) btw a PFP and a 3D vertex. Setting it to 3 cm\n";
148 throw art::Exception(art::errors::Configuration)
149 <<
"KinkCuts must be size 3\n 0 = Number of points to fit at the end of the trajectory\n 1 "
150 "= Minimum kink significance\n 2 = Use charge in significance calculation? (yes if > "
151 "0)\n 3 = 3D kink fit length (cm). \nYou are using an out-of-date specification?\n";
156 throw art::Exception(art::errors::Configuration)
157 <<
"Are you using an out-of-date specification for KinkCuts? KinkCuts[0] is the number of "
162 throw art::Exception(art::errors::Configuration)
163 <<
"ChargeCuts must be size 3\n 0 = Charge pull cut\n 1 = Min allowed fractional chg RMS\n "
164 "2 = Max allowed fractional chg RMS";
167 throw art::Exception(art::errors::Configuration)
168 <<
"MuonTag must be size 4\n 0 = minPtsFit\n 1 = minMCSMom\n 2= maxWireSkipNoSignal\n 3 = "
169 "min delta ray length for tagging\n 4 = dress muon window size (optional)";
171 throw art::Exception(art::errors::Configuration)
172 <<
"DeltaRayTag must be size 3\n 0 = Max endpoint sep\n 1 = min MCSMom\n 2 = max MCSMom";
174 throw art::Exception(art::errors::Configuration)
175 <<
"ChkStopCuts must be size 3\n 0 = Min Charge ratio\n 1 = Charge slope pull cut\n 2 = "
176 "Charge fit chisq cut\n 3 = BraggSplit FOM (optional)";
179 <<
"ShowerTag must be size 13\n 0 = Mode\n 1 = max MCSMom\n 2 = max separation (WSE "
180 "units)\n 3 = Max angle diff\n 4 = Factor * rms width\n 5 = Min half width\n 6 = min "
181 "total Tps\n 7 = Min Tjs\n 8 = max parent FOM\n 9 = max direction FOM 10 = max "
182 "AspectRatio\n 11 = min Score to preserve a vertex\n 12 = Debug showers in CTP\n";
191 throw art::Exception(art::errors::Configuration)
192 <<
"Match3DCuts must be size 5\n 0 = dx (cm) matching cut\n 1 = max number of 3D "
193 "combinations\n 2 = min length for 2-view match\n 3 = number of TP3Ds in each plane to "
194 "fit in each PFP section\n 4 = max pull for accepting TP3Ds in sections\n 5 = max "
195 "ChiDOF for a SectionFit";
199 mf::LogVerbatim(
"TC") <<
"Last element of AngleRange != 90 degrees. Fixing it\n";
215 for (
auto strng : debugConfigVec) {
219 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib) {
228 std::cout <<
"DecodeDebugString failed: " << strng <<
"\n";
236 if (range < 0 || range > 90)
237 throw art::Exception(art::errors::Configuration)
238 <<
"Invalid angle range " << range <<
" Must be 0 - 90 degrees";
244 throw art::Exception(art::errors::Configuration)
247 throw art::Exception(art::errors::Configuration)
248 <<
"Increase the size of UseAlgs to at least " <<
kAlgBitSize;
252 throw art::Exception(art::errors::Configuration)
256 throw art::Exception(art::errors::Configuration)
257 <<
"Increase the size of EndFlag to at least " <<
kFlagBitSize;
260 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
267 for (
auto strng : skipAlgsVec) {
269 if (strng ==
"All") {
271 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
276 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib) {
284 std::cout <<
"******* Unknown SkipAlgs input string '" << strng <<
"'\n";
293 std::cout <<
"Or specify All to turn all algs off\n";
296 if (fMVAShowerParentWeights !=
"NA" &&
tcc.
showerTag[0] > 0)
317 tcc.
geom = lar::providerFrom<geo::Geometry>();
340 thr = {UINT_MAX, UINT_MAX};
343 unsigned int tpc =
hit.WireID().TPC;
354 std::vector<unsigned int>& hitsInSlice,
360 if (hitsInSlice.size() < 2)
return;
363 if (!
CreateSlice(clockData, detProp, hitsInSlice, sliceID))
return;
375 throw art::Exception(art::errors::Configuration)
376 <<
" AveHitRMS vector size != the number of planes ";
378 std::cout <<
"Reconstruct " << hitsInSlice.size() <<
" hits in Slice " << sliceID
379 <<
" in TPC " << slc.TPCID.TPC <<
"\n";
380 for (
unsigned short plane = 0; plane < slc.nPlanes; ++plane) {
381 CTP_t inCTP =
EncodeCTP(slc.TPCID.Cryostat, slc.TPCID.TPC, plane);
383 if (!slc.isValid)
return;
392 for (
unsigned short plane = 0; plane < slc.nPlanes; ++plane) {
393 CTP_t inCTP =
EncodeCTP(slc.TPCID.Cryostat, slc.TPCID.TPC, plane);
395 std::cout <<
"RTC: ChkVtxAssociations found an error\n";
414 mf::LogVerbatim(
"TC") <<
"RunTrajCluster failed in MakeAllTrajClusters";
424 for (
auto& tj : slc.tjs) {
425 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
430 slc.mallTraj.resize(0);
445 if (nwires > slc.
nWires[plane])
return;
451 for (
unsigned short pass = 0; pass <
tcc.
minPtsFit.size(); ++pass) {
452 for (
unsigned int ii = 0; ii < nwires; ++ii) {
454 unsigned int iwire = 0;
455 unsigned int jwire = 0;
463 iwire = slc.
lastWire[plane] - ii - 1;
466 if (iwire > slc.
wireHitRange[plane].size() - 1)
continue;
467 if (jwire > slc.
wireHitRange[plane].size() - 1)
continue;
469 if (slc.
wireHitRange[plane][iwire].first == UINT_MAX)
continue;
470 if (slc.
wireHitRange[plane][jwire].first == UINT_MAX)
continue;
471 unsigned int ifirsthit = slc.
wireHitRange[plane][iwire].first;
472 unsigned int ilasthit = slc.
wireHitRange[plane][iwire].second;
473 unsigned int jfirsthit = slc.
wireHitRange[plane][jwire].first;
474 unsigned int jlasthit = slc.
wireHitRange[plane][jwire].second;
475 if (ifirsthit > slc.
slHits.size() || ilasthit > slc.
slHits.size()) {
476 std::cout <<
"RAT: bad hit range " << ifirsthit <<
" " << ilasthit <<
" size "
477 << slc.
slHits.size() <<
" inCTP " << inCTP <<
"\n";
480 for (
unsigned int iht = ifirsthit; iht <= ilasthit; ++iht) {
483 mf::LogVerbatim(
"TC") <<
"+++++++ Pass " << pass <<
" Found debug hit "
488 if (slc.
slHits[iht].InTraj != 0)
continue;
497 unsigned int fromWire = iHit.WireID().Wire;
498 float fromTick = iHit.PeakTime();
499 float iqtot = iHit.Integral();
500 float hitsRMSTick = iHit.RMS();
501 std::vector<unsigned int> iHitsInMultiplet;
504 iHitsInMultiplet.resize(1);
505 iHitsInMultiplet[0] = iht;
509 if (iHitsInMultiplet.empty())
continue;
511 if (iHitsInMultiplet.size() > 4)
continue;
513 if (iHitsInMultiplet.size() > 1) {
517 if (hitsRMSTick == 0)
continue;
518 bool fatIHit = (hitsRMSTick > maxHitsRMS);
520 mf::LogVerbatim(
"TC") <<
" hit RMS " << iHit.RMS() <<
" BB Multiplicity "
521 << iHitsInMultiplet.size() <<
" AveHitRMS[" << plane <<
"] "
522 <<
evt.
aveHitRMS[plane] <<
" HitsRMSTick " << hitsRMSTick
523 <<
" fatIHit " << fatIHit;
524 for (
unsigned int jht = jfirsthit; jht <= jlasthit; ++jht) {
526 if (slc.
slHits[iht].InTraj != 0)
break;
527 if (slc.
slHits[jht].InTraj != 0)
continue;
529 for (
auto& slHit : slc.
slHits) {
530 if (slHit.InTraj < 0) {
536 unsigned int toWire = jwire;
539 float toTick = jHit.PeakTime();
540 float jqtot = jHit.Integral();
541 std::vector<unsigned int> jHitsInMultiplet;
544 jHitsInMultiplet.resize(1);
545 jHitsInMultiplet[0] = jht;
549 if (jHitsInMultiplet.empty())
continue;
551 if (jHitsInMultiplet.size() > 4)
continue;
554 if (hitsRMSTick == 0)
continue;
555 bool fatJHit = (hitsRMSTick > maxHitsRMS);
558 if ((fatIHit && !fatJHit) || (!fatIHit && fatJHit)) {
continue; }
562 if (jHitsInMultiplet.size() > 1)
565 bool hitsOK =
TrajHitsOK(slc, iHitsInMultiplet, jHitsInMultiplet);
567 if (!hitsOK)
continue;
570 if (!
StartTraj(slc, work, fromWire, fromTick, toWire, toTick, inCTP, pass))
continue;
573 std::cout <<
"RAT: StartTraj major failure\n";
576 if (work.
Pts.empty()) {
577 if (
tcc.
dbgStp) mf::LogVerbatim(
"TC") <<
"ReconstructAllTraj: StartTraj failed";
589 std::cout <<
"RAT: AddHits major failure\n";
592 if (!sigOK || work.
Pts[0].Chg == 0) {
593 if (
tcc.
dbgStp) mf::LogVerbatim(
"TC") <<
" No hits at initial trajectory point ";
598 work.
Pts[0].Pos = work.
Pts[0].HitPos;
607 std::cout <<
"RAT: StepAway major failure\n";
611 mf::LogVerbatim(
"TC") <<
" After first StepAway. IsGood " << work.
IsGood;
616 std::cout <<
"RAT: CheckTraj major failure\n";
620 mf::LogVerbatim(
"TC") <<
"ReconstructAllTraj: After CheckTraj EndPt " << work.
EndPt[0]
621 <<
"-" << work.
EndPt[1] <<
" IsGood " << work.
IsGood;
623 mf::LogVerbatim(
"TC")
624 <<
"StepAway done: IsGood " << work.
IsGood <<
" NumPtsWithCharge "
629 mf::LogVerbatim(
"TC")
637 auto& tj = slc.
tjs[slc.
tjs.size() - 1];
640 std::cout <<
"RAT: InTrajOK major failure. " << tj.ID <<
"\n";
653 for (
auto tp :
seeds) {
654 unsigned short nAvailable = 0;
655 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
656 if (!tp.UseHit[ii])
continue;
657 unsigned int iht = tp.Hits[ii];
658 if (slc.
slHits[iht].InTraj == 0) ++nAvailable;
661 mf::LogVerbatim(
"TC") <<
"+++++++ Seed debug hit " <<
slices.size() - 1 <<
":"
665 if (nAvailable == 0)
continue;
668 for (
unsigned short ii = 0; ii < tp.Hits.size(); ++ii) {
669 if (!tp.UseHit[ii])
continue;
670 unsigned int iht = tp.Hits[ii];
671 if (slc.
slHits[iht].InTraj == 0) slc.
slHits[iht].InTraj = work.
ID;
675 if (tp.Dir[0] < 0) work.
StepDir = -1;
682 work.
Pts.push_back(tp);
687 std::cout <<
"RAT: CheckTraj major failure\n";
693 mf::LogVerbatim(
"TC") <<
" xxxxxxx Not enough points "
701 auto& tj = slc.
tjs[slc.
tjs.size() - 1];
702 mf::LogVerbatim(
"TC") <<
"TRP RAT Stored T" << tj.ID <<
" using seed TP "
727 for (
auto& tj : slc.
tjs) {
728 if (tj.AlgMod[
kKilled])
continue;
729 if (tj.PDGCode != 13)
continue;
744 std::cout <<
"RAT: MakeJunkVertices major failure\n";
749 for (
unsigned short ivx = 0; ivx < slc.
vtxs.size(); ++ivx) {
750 auto& vx2 = slc.
vtxs[ivx];
751 if (vx2.ID == 0)
continue;
752 if (vx2.CTP != inCTP)
continue;
764 std::cout <<
"RAT: ChkVtxAssociations found an error. Events processed "
782 for (
auto& slHit : slc.
slHits)
783 if (slHit.InTraj < 0) slHit.InTraj = 0;
787 std::vector<unsigned int> tHits;
789 for (
unsigned int iwire = slc.
firstWire[plane]; iwire < slc.
lastWire[plane] - 3; ++iwire) {
793 unsigned int jwire = iwire + 1;
796 unsigned int ifirsthit = slc.
wireHitRange[plane][iwire].first;
797 unsigned int ilasthit = slc.
wireHitRange[plane][iwire].second;
798 unsigned int jfirsthit = slc.
wireHitRange[plane][jwire].first;
799 unsigned int jlasthit = slc.
wireHitRange[plane][jwire].second;
800 for (
unsigned int iht = ifirsthit; iht <= ilasthit; ++iht) {
801 if(iht >= slc.
slHits.size())
break;
802 auto& islHit = slc.
slHits[iht];
803 if (islHit.InTraj != 0)
continue;
804 std::vector<unsigned int> iHits;
808 if (prt) mf::LogVerbatim(
"TC") <<
"FJT: debug iht multiplet size " << iHits.size();
809 if (iHits.empty())
continue;
810 for (
unsigned int jht = jfirsthit; jht <= jlasthit; ++jht) {
811 if(jht >= slc.
slHits.size())
break;
812 auto& jslHit = slc.
slHits[jht];
813 if (jslHit.InTraj != 0)
continue;
814 if (prt &&
HitSep2(slc, iht, jht) < 100)
815 mf::LogVerbatim(
"TC") <<
" use " <<
PrintHit(jslHit) <<
" hitSep2 "
818 std::vector<unsigned int> jHits;
820 if (jHits.empty())
continue;
825 for (
auto iht : iHits)
826 if (slc.
slHits[iht].InTraj == 0) tHits.push_back(iht);
827 for (
auto jht : jHits)
828 if (slc.
slHits[jht].InTraj == 0) tHits.push_back(jht);
829 for (
auto tht : tHits)
830 slc.
slHits[tht].InTraj = -4;
832 if (iwire != 0) { loWire = iwire - 1; }
836 unsigned int hiWire = jwire + 1;
837 if (hiWire > slc.
nWires[plane])
break;
838 unsigned short nit = 0;
840 bool hitsAdded =
false;
841 for (
unsigned int kwire = loWire; kwire <= hiWire; ++kwire) {
842 if (slc.
wireHitRange[plane][kwire].first == UINT_MAX)
continue;
843 if (slc.
wireHitRange[plane][kwire].second == UINT_MAX)
continue;
844 unsigned int kfirsthit = slc.
wireHitRange[plane][kwire].first;
845 unsigned int klasthit = slc.
wireHitRange[plane][kwire].second;
846 for (
unsigned int kht = kfirsthit; kht <= klasthit; ++kht) {
847 if(kht >= slc.
slHits.size())
continue;
848 if (slc.
slHits[kht].InTraj != 0)
continue;
850 if (std::find(tHits.begin(), tHits.end(), kht) != tHits.end())
continue;
855 for (
auto jht : jHits) {
856 if (slc.
slHits[jht].InTraj != 0)
continue;
857 tHits.push_back(jht);
858 slc.
slHits[jht].InTraj = -4;
859 if (kwire > hiWire) hiWire = kwire;
860 if (kwire < loWire) loWire = kwire;
865 if (!hitsAdded)
break;
868 if (hiWire >= slc.
nWires[plane])
break;
871 for (
auto iht : tHits)
872 slc.
slHits[iht].InTraj = 0;
873 if (tHits.size() < 3)
continue;
875 mf::LogVerbatim myprt(
"TC");
876 myprt <<
"FJT: tHits";
877 for (
auto tht : tHits)
882 if (
IsGhost(slc, tHits))
break;
884 if (prt) mf::LogVerbatim() <<
"FJT: MakeJunkTraj failed";
887 if (slc.
slHits[jht].InTraj > 0)
break;
905 unsigned short itj = 0;
906 std::vector<unsigned int> tHits;
907 std::vector<unsigned int> atHits;
908 for (
auto& tj : slc.
tjs) {
910 if (tj.AlgMod[
kKilled])
continue;
912 for (
auto& tp : tj.Pts) {
913 if (tp.Hits.size() > 16) {
915 mf::LogVerbatim(
"TC")
916 <<
"ChkInTraj: More than 16 hits created a UseHit bitset overflow\n";
918 std::cout <<
"ChkInTraj major failure\n";
923 std::cout << someText <<
" ChkInTraj hit size mis-match in tj ID " << tj.ID
925 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
931 if (tHits.size() < 2) {
932 mf::LogVerbatim(
"TC") << someText <<
" ChkInTraj: Insufficient hits in traj " << tj.ID;
937 std::sort(tHits.begin(), tHits.end());
939 for (iht = 0; iht < slc.
slHits.size(); ++iht) {
940 if (slc.
slHits[iht].InTraj == tID) atHits.push_back(iht);
942 if (atHits.size() < 2) {
943 mf::LogVerbatim(
"TC") << someText <<
" ChkInTraj: Insufficient hits in atHits in traj "
944 << tj.ID <<
" Killing it";
948 if (!
std::equal(tHits.begin(), tHits.end(), atHits.begin())) {
949 mf::LogVerbatim myprt(
"TC");
950 myprt << someText <<
" ChkInTraj failed: inTraj - UseHit mis-match for tj ID " << tID
951 <<
" tj.WorkID " << tj.WorkID <<
" atHits size " << atHits.size() <<
" tHits size "
952 << tHits.size() <<
" in CTP " << tj.CTP <<
"\n";
953 myprt <<
"AlgMods: ";
954 for (
unsigned short ib = 0; ib <
AlgBitNames.size(); ++ib)
955 if (tj.AlgMod[ib]) myprt <<
" " <<
AlgBitNames[ib];
957 myprt <<
"index inTraj UseHit \n";
958 for (iht = 0; iht < atHits.size(); ++iht) {
959 myprt <<
"iht " << iht <<
" " <<
PrintHit(slc.
slHits[atHits[iht]]);
960 if (iht < tHits.size()) myprt <<
" " <<
PrintHit(slc.
slHits[tHits[iht]]);
961 if (atHits[iht] != tHits[iht]) myprt <<
" <<< " << atHits[iht] <<
" != " << tHits[iht];
965 if (tHits.size() > atHits.size()) {
966 for (iht = atHits.size(); iht < atHits.size(); ++iht) {
967 myprt <<
"atHits " << iht <<
" " <<
PrintHit(slc.
slHits[atHits[iht]]) <<
"\n";
973 for (
unsigned short end = 0;
end < 2; ++
end) {
974 if (tj.VtxID[
end] > slc.
vtxs.size()) {
975 mf::LogVerbatim(
"TC") << someText <<
" ChkInTraj: Bad VtxID " << tj.ID;
976 std::cout << someText <<
" ChkInTraj: Bad VtxID " << tj.ID <<
" vtx size "
977 << slc.
vtxs.size() <<
"\n";
993 std::vector<recob::Hit>& newHitCol,
994 std::vector<unsigned int>& newHitAssns)
const
999 if (tpHits.empty())
return;
1002 if (tpHits.size() == 1) {
1004 std::cout <<
"MergeTPHits Bad input hit index " << tpHits[0] <<
" allHits size "
1009 newHitAssns[tpHits[0]] = newHitCol.size() - 1;
1014 std::vector<unsigned int> wires;
1015 std::vector<std::vector<unsigned int>> wireHits;
1017 wires.push_back(firstHit.WireID().Wire);
1018 std::vector<unsigned int> tmp(1, tpHits[0]);
1019 wireHits.push_back(tmp);
1020 for (
unsigned short ii = 1; ii < tpHits.size(); ++ii) {
1022 unsigned int wire =
hit.WireID().Wire;
1023 unsigned short indx = 0;
1024 for (indx = 0; indx < wires.size(); ++indx)
1025 if (wires[indx] == wire)
break;
1026 if (indx == wires.size()) {
1027 wires.push_back(wire);
1028 wireHits.resize(wireHits.size() + 1);
1030 wireHits[indx].push_back(tpHits[ii]);
1034 for (
unsigned short indx = 0; indx < wireHits.size(); ++indx) {
1035 auto& hitsOnWire = wireHits[indx];
1037 for (
unsigned short ii = 0; ii < hitsOnWire.size(); ++ii) {
1038 newHitAssns[hitsOnWire[ii]] = newHitCol.size() - 1;
1055 if (tpHits.size() == 1) {
1057 std::cout <<
"MergeTPHits Bad input hit index " << tpHits[0] <<
" allHits size "
1069 oldHit.SigmaPeakTime(),
1071 oldHit.PeakAmplitude(),
1072 oldHit.SigmaPeakAmplitude(),
1075 oldHit.SigmaIntegral(),
1081 oldHit.SignalType(),
1085 double integral = 0;
1086 double sIntegral = 0;
1087 double peakTime = 0;
1088 double sPeakTime = 0;
1090 double sPeakAmp = 0;
1094 for (
auto allHitsIndex : tpHits) {
1097 if (
hit.StartTick() < startTick) startTick =
hit.StartTick();
1098 if (
hit.EndTick() > endTick) endTick =
hit.EndTick();
1099 double intgrl =
hit.Integral();
1100 sPeakTime += intgrl *
hit.SigmaPeakTime();
1101 sPeakAmp += intgrl *
hit.SigmaPeakAmplitude();
1102 sumADC +=
hit.SummedADC();
1104 sIntegral += intgrl *
hit.SigmaIntegral();
1107 if (integral <= 0) {
1108 std::cout <<
"MergeTPHits found bad hit integral " << integral <<
"\n";
1113 std::vector<double> shape(endTick - startTick + 1, 0.);
1114 for (
auto allHitsIndex : tpHits) {
1116 double peakTick =
hit.PeakTime();
1117 double rms =
hit.RMS();
1118 double peakAmp =
hit.PeakAmplitude();
1120 double arg = ((double)
tick - peakTick) / rms;
1121 unsigned short indx =
tick - startTick;
1122 shape[indx] += peakAmp *
exp(-0.5 * arg * arg);
1130 unsigned short indx =
tick - startTick;
1131 sigsum += shape[indx];
1132 sigsumt += shape[indx] *
tick;
1135 peakTime = sigsumt / sigsum;
1137 sPeakTime /= integral;
1142 double dTick =
tick - peakTime;
1143 unsigned short indx =
tick - startTick;
1144 sigsumt += shape[indx] * dTick * dTick;
1146 double rms = std::sqrt(sigsumt / sigsum);
1149 double chgNorm = 2.507 * firstHit.PeakAmplitude() * firstHit.RMS() / firstHit.Integral();
1151 peakAmp = (float)(integral * chgNorm / (2.507 * rms));
1153 sPeakAmp /= integral;
1155 startTick = peakTime - 3 * rms;
1156 endTick = peakTime + 3 * rms;
1175 firstHit.SignalType(),
1226 std::vector<unsigned int>& hitsInSlice,
1232 if (hitsInSlice.size() < 2)
return false;
1236 slc.
slHits.resize(hitsInSlice.size());
1238 unsigned int cstat = 0;
1239 unsigned int tpc = UINT_MAX;
1240 unsigned int cnt = 0;
1241 std::vector<unsigned int> nHitsInPln;
1242 for (
auto iht : hitsInSlice) {
1243 if (iht >= (*
evt.
allHits).size())
return false;
1246 cstat =
hit.WireID().Cryostat;
1247 tpc =
hit.WireID().TPC;
1252 if (
hit.WireID().Cryostat != cstat ||
hit.WireID().TPC != tpc)
return false;
1253 slc.
slHits[cnt].allHitsIndex = iht;
1254 ++nHitsInPln[
hit.WireID().Plane];
1258 for (
auto hip : nHitsInPln)
1259 if (hip < 2)
return false;
1277 for (
unsigned int iht = 0; iht < slc.
slHits.size(); ++iht) {
1278 unsigned int ahi = slc.
slHits[iht].allHitsIndex;
1296 for (
auto& slc :
slices) {
1297 if (!slc.isValid)
continue;
1299 for (
auto& pfp : slc.pfps) {
1300 if (pfp.ID <= 0)
continue;
1301 pfp.TjUIDs.resize(pfp.TjIDs.size());
1302 for (
unsigned short ii = 0; ii < pfp.TjIDs.size(); ++ii) {
1304 if (pfp.TjIDs[ii] <= 0 || pfp.TjIDs[ii] > (
int)slc.tjs.size()) {
1305 std::cout <<
"FinishEvent found an invalid T" << pfp.TjIDs[ii] <<
" in P" << pfp.UID
1307 slc.isValid =
false;
1310 auto& tj = slc.tjs[pfp.TjIDs[ii] - 1];
1311 pfp.TjUIDs[ii] = tj.UID;
1318 for (
auto& slc : slices)
Expect tracks entering from the front face. Don't create neutrino PFParticles.
calo::CalorimetryAlg * caloAlg
void ClearResults()
Deletes all the results.
void CheckTrajBeginChg(TCSlice &slc, unsigned short itj)
float AveChg
Calculated using ALL hits.
void ReleaseHits(TCSlice &slc, Trajectory &tj)
std::vector< int > EnvStage
std::vector< int > IsShowerParent
std::vector< Trajectory > tjs
vector of all trajectories in each plane
void StepAway(TCSlice &slc, Trajectory &tj)
void ConfigureMVA(TCConfig &tcc, std::string fMVAShowerParentWeights)
then if[["$THISISATEST"==1]]
bool TrajHitsOK(TCSlice &slc, const std::vector< unsigned int > &iHitsInMultiplet, const std::vector< unsigned int > &jHitsInMultiplet)
std::vector< float > kinkCuts
kink finder algorithm
bool IsGhost(TCSlice &slc, Trajectory &tj)
Utilities related to art service access.
bool InTrajOK(TCSlice &slc, std::string someText)
std::vector< float > EndWir
std::vector< float > EndAng
std::vector< unsigned int > PutTrajHitsInVector(const Trajectory &tj, HitStatus_t hitRequest)
const std::vector< std::string > AlgBitNames
short recoTPC
only reconstruct in the seleted TPC
std::vector< unsigned short > minPtsFit
Reconstruct in several passes.
std::vector< float > vtx3DCuts
2D vtx -> 3D vtx matching cuts
std::vector< float > qualityCuts
Min points/wire, min consecutive pts after a gap.
void Find3DVertices(detinfo::DetectorPropertiesData const &detProp, TCSlice &slc)
std::vector< float > BeginTim
void AddHits(TCSlice &slc, Trajectory &tj, unsigned short ipt, bool &sigOK)
std::vector< float > BeginAng
void PrintTrajectory(std::string someText, const TCSlice &slc, const Trajectory &tj, unsigned short tPoint)
void SplitTrajCrossingVertices(TCSlice &slc, CTP_t inCTP)
std::vector< std::vector< std::pair< unsigned int, unsigned int > > > wireHitRange
void Reconcile2Vs(TCSlice &slc)
int ParentID
ID of the parent, or the ID of the Tj this one was merged with if it is killed.
step from US -> DS (true) or DS -> US (false)
bool StoreTraj(TCSlice &slc, Trajectory &tj)
void RunTrajClusterAlg(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< unsigned int > &hitsInSlice, int sliceID)
calo::CalorimetryAlg fCaloAlg
float maxWireSkipWithSignal
max number of wires to skip with a signal on them
call study functions to develop cuts, etc
std::string PrintPos(const TCSlice &slc, const TrajPoint &tp)
std::size_t size(FixedBins< T, C > const &) noexcept
void FillWireHitRange(geo::TPCID inTPCID)
bool AttachAnyTrajToVertex(TCSlice &slc, unsigned short ivx, bool prt)
std::vector< std::pair< unsigned int, unsigned int > > tpcSrcHitRange
bool MakeJunkTraj(TCSlice &slc, std::vector< unsigned int > tHits)
std::vector< float > electronTag
bool FindShowers3D(detinfo::DetectorPropertiesData const &detProp, TCSlice &slc)
bool dbgSlc
debug only in the user-defined slice? default is all slices
bool StartTraj(TCSlice &slc, Trajectory &tj, unsigned int fromhit, unsigned int tohit, unsigned short pass)
std::vector< unsigned int > lastWire
the last wire with a hit
bool CreateSlice(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< unsigned int > &hitsInSlice, int sliceID)
bool LongPulseHit(const recob::Hit &hit)
unsigned int eventsProcessed
bool IsGood
set false if there is a failure or the Tj fails quality cuts
bool doForecast
See TCMode_t above.
void MakePFPTjs(TCSlice &slc)
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
int TDCtick_t
Type representing a TDC tick.
std::vector< float > EndTim
std::vector< int > ShowerID
std::vector< unsigned short > maxAngleCode
max allowed angle code for each pass
bool SetInputHits(std::vector< recob::Hit > const &inputHits, unsigned int run, unsigned int event)
void DefineShTree(TTree *t)
std::vector< unsigned int > fAlgModCount
float projectionErrFactor
unsigned int Hit
set to the hit index in evt.allHits if a Plane:Wire:Tick match is found
std::vector< std::string > StageName
float HitSep2(const TCSlice &slc, unsigned int iht, unsigned int jht)
int Cryostat
Select Cryostat.
float HitsRMSTick(const TCSlice &slc, const std::vector< unsigned int > &hitsInMultiplet, HitStatus_t hitRequest)
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
short nPtsAve
dump trajectory points
void PFPVertexCheck(TCSlice &slc)
bool dbgStp
debug stepping using debug.Cryostat, debug.TPC, etc
recob::Hit MergeTPHitsOnWire(std::vector< unsigned int > &tpHits) const
don't mess with this line
float unitsPerTick
scale factor from Tick to WSE equivalent units
std::vector< short > minMCSMom
Min MCSMom for each pass.
bool BraggSplit(TCSlice &slc, unsigned short itj)
std::vector< short > BeginVtx
CTP_t CTP
Cryostat, TPC, Plane code.
bool dbg2V
debug 2D vertex finding
void GetHitMultiplet(const TCSlice &slc, unsigned int theHit, std::vector< unsigned int > &hitsInMultiplet, bool useLongPulseHits)
std::vector< float > aveHitRMS
average RMS of an isolated hit
void TagShowerLike(std::string inFcnLabel, TCSlice &slc, const CTP_t &inCTP)
std::vector< TrajPoint > Pts
Trajectory points.
TMVA::Reader * showerParentReader
bool ChkVtxAssociations(TCSlice &slc, const CTP_t &inCTP)
for($it=0;$it< $RaceTrack_number;$it++)
std::vector< float > neutralVxCuts
void MakeHaloTj(TCSlice &slc, Trajectory &muTj, bool prt)
std::vector< short > EndVtx
auto end(FixedBins< T, C > const &) noexcept
std::vector< VtxStore > vtxs
2D vertices
std::array< unsigned short, 2 > EndPt
First and last point in the trajectory that has charge.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
std::vector< float > match3DCuts
3D matching cuts
void ScoreVertices(TCSlice &slc)
std::string PrintHit(const TCHit &tch)
std::vector< float > Envelope
call study functions to develop cuts, etc
const geo::GeometryCore * geom
std::vector< unsigned short > minPts
min number of Pts required to make a trajectory
PlaneID_t Plane
Index of the plane within its TPC.
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
std::vector< float > BeginChg
int ID
ID that is local to one slice.
std::vector< TCSlice > slices
std::bitset< 16 > modes
number of points to find AveChg
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
std::vector< TCHit > slHits
std::vector< float > chargeCuts
bool aveHitRMSValid
set true when the average hit RMS is well-known
bool equal(double a, double b)
Comparison tolerance, in centimeters.
std::vector< int > EnvPlane
std::vector< TrajPoint > seeds
float maxWireSkipNoSignal
max number of wires to skip w/o a signal on them
std::vector< short > MCSMom
void CheckTraj(TCSlice &slc, Trajectory &tj)
std::vector< float > vtxScoreWeights
bool DecodeDebugString(std::string strng)
std::vector< int > StageNum
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.
std::vector< float > pfpStitchCuts
cuts for stitching between TPCs
std::vector< short > deltaRayTag
short StepDir
-1 = going US (-> small wire#), 1 = going DS (-> large wire#)
std::bitset< 128 > AlgMod
Bit set if algorithm AlgBit_t modifed the trajectory.
call study functions to develop cuts, etc
void LastEndMerge(TCSlice &slc, CTP_t inCTP)
std::vector< short > muonTag
void UpdateVxEnvironment(TCSlice &slc)
std::vector< float > BeginWir
geo::PlaneID DecodeCTP(CTP_t CTP)
std::vector< float > EndChg
TrajClusterAlg(fhicl::ParameterSet const &pset)
std::bitset< 128 > dbgAlg
Allow user to turn on debug printing in algorithms (that print...)
std::vector< recob::Hit > const * allHits
CTP_t EncodeCTP(unsigned int cryo, unsigned int tpc, unsigned int plane)
std::vector< unsigned int > nWires
void KillPoorVertices(TCSlice &slc)
std::vector< float > chkStopCuts
Bragg peak finder configuration.
int ID
ID of the recob::Slice (not the sub-slice)
void EndMerge(TCSlice &slc, CTP_t inCTP, bool lastPass)
void MergeTPHits(std::vector< unsigned int > &tpHits, std::vector< recob::Hit > &newHitCol, std::vector< unsigned int > &newHitAssns) const
void DefinePFPParents(TCSlice &slc, bool prt)
std::vector< float > vtx2DCuts
Max position pull, max Position error rms.
std::bitset< 8 > Strategy
void Finish3DShowers(TCSlice &slc)
IDparameter< geo::TPCID > TPCID
Member type of validated geo::TPCID parameter.
void SetSourceHits(std::vector< recob::Hit > const &srcHits)
void FindPFParticles(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, TCSlice &slc)
float multHitSep
preferentially "merge" hits with < this separation
2D representation of charge deposited in the TDC/wire plane
void ChkInTraj(std::string someText, TCSlice &slc)
void ReconstructAllTraj(detinfo::DetectorPropertiesData const &detProp, TCSlice &slc, CTP_t inCTP)
unsigned short NumPtsWithCharge(const TCSlice &slc, const Trajectory &tj, bool includeDeadWires)
std::vector< int > EnvShowerID
void MakeJunkVertices(TCSlice &slc, const CTP_t &inCTP)
call study functions to develop cuts, etc (see TCTruth.cxx)
void Find2DVertices(detinfo::DetectorPropertiesData const &detProp, TCSlice &slc, const CTP_t &inCTP, unsigned short pass)
std::vector< int > IsShowerTj
std::vector< short > PlaneNum
short recoSlice
only reconstruct the slice with ID (0 = all)
master switch for turning on debug mode
don't mess with this line
art framework interface to geometry description
BEGIN_PROLOG could also be cout
CTP_t CTP
set to an invalid CTP
void SetTPEnvironment(TCSlice &slc, CTP_t inCTP)
void FindJunkTraj(TCSlice &slc, CTP_t inCTP)