26 std::vector<TVector3>& TrajPos,
27 std::vector<TVector3>& TrajDir)
58 unsigned short minLen = 9999;
59 unsigned short maxLen = 0;
60 unsigned short nPlnsWithHits = 0;
61 unsigned short ipl, aPlane = 3;
62 for (ipl = 0; ipl < 3; ++ipl) {
63 if (trkX[ipl].
size() == 0)
continue;
65 if (trkX[ipl].
size() < minLen) { minLen = trkX[ipl].size(); }
66 if (trkX[ipl].
size() > maxLen) {
67 maxLen = trkX[ipl].size();
72 mf::LogVerbatim(
"TTA") <<
"trkX sizes " << trkX[0].size() <<
" " << trkX[1].size() <<
" " 73 << trkX[2].size() <<
" " 74 <<
" nPlnsWithHits " << nPlnsWithHits;
75 if (nPlnsWithHits < 2)
return;
76 if (aPlane > 2)
return;
86 iht = trkX[aPlane].size() - 1;
87 if (trkX[aPlane][0] > trkX[aPlane][iht]) {
89 for (ipl = 0; ipl < 3; ++ipl) {
90 if (trkX[ipl].
size() == 0)
continue;
91 std::reverse(trkWID[ipl].
begin(), trkWID[ipl].
end());
92 std::reverse(trkX[ipl].
begin(), trkX[ipl].
end());
93 std::reverse(trkXErr[ipl].
begin(), trkXErr[ipl].
end());
100 myprt <<
"TrkXW end0";
101 for (ipl = 0; ipl < 3; ++ipl) {
102 if (trkX[ipl].
size() == 0)
continue;
103 myprt <<
" " << trkX[ipl][0];
106 myprt <<
"TrkXW end1";
107 for (ipl = 0; ipl < 3; ++ipl) {
108 if (trkX[ipl].
size() == 0)
continue;
109 iht = trkX[ipl].size() - 1;
110 myprt <<
" " << trkX[ipl][iht];
121 for (
unsigned short ipl = 0; ipl < 3; ++ipl) {
122 if (trkX[ipl].
size() == 0)
continue;
123 if (trkX[ipl][0] <
minX) {
127 iht = trkX[ipl].size() - 1;
128 if (trkX[ipl][iht] >
maxX) {
129 maxX = trkX[ipl][iht];
140 double aveHitXErr = 0;
141 unsigned short nHit = 0;
142 for (ipl = 0; ipl < 3; ++ipl) {
143 for (iht = 0; iht < trkXErr[ipl].size(); ++iht) {
144 aveHitXErr += trkXErr[ipl][iht];
148 aveHitXErr /= (double)nHit;
150 unsigned short npt = (
maxX -
minX) / (1 * aveHitXErr);
151 if (npt < 2) npt = 2;
152 if (npt > maxLen) npt = maxLen;
154 if (
prt)
mf::LogVerbatim(
"TTA") <<
" aveHitXErr " << aveHitXErr <<
" number of traj points ";
156 double maxBinX = (
maxX -
minX) / (
double)(npt - 1);
157 double binX = maxBinX;
158 double xOrigin =
minX;
162 std::vector<geo::WireID> hitWID;
163 std::vector<double> hitX;
164 std::vector<double> hitXErr;
168 std::vector<TVector3> STPos;
169 std::vector<TVector3> STDir;
172 if (STPos.size() != 2 || STDir.size() != STPos.size()) {
176 for (ipl = 0; ipl < 3; ++ipl) {
177 if (trkX[ipl].
size() == 0)
continue;
178 std::reverse(trkWID[ipl].
begin(), trkWID[ipl].
end());
179 std::reverse(trkX[ipl].
begin(), trkX[ipl].
end());
180 std::reverse(trkXErr[ipl].
begin(), trkXErr[ipl].
end());
188 for (
unsigned short ii = 0; ii < STPos.size(); ++ii)
189 mf::LogVerbatim(
"TTA") << ii <<
" " << std::fixed << std::setprecision(1) << STPos[ii](0)
190 <<
" " << STPos[ii](1) <<
" " << STPos[ii](2);
193 if (maxLen < 4 || npt < 2) {
198 std::reverse(TrajPos.begin(), TrajPos.end());
199 std::reverse(TrajDir.begin(), TrajDir.end());
200 for (ipl = 0; ipl < 3; ++ipl) {
201 if (trkX[ipl].
size() == 0)
continue;
202 std::reverse(trkWID[ipl].
begin(), trkWID[ipl].
end());
203 std::reverse(trkX[ipl].
begin(), trkX[ipl].
end());
204 std::reverse(trkXErr[ipl].
begin(), trkXErr[ipl].
end());
211 std::array<unsigned short, 3> hStart;
212 for (ipl = 0; ipl < 3; ++ipl)
215 bool gotLastPoint =
false;
216 for (
unsigned short ipt = 0; ipt < npt + 1; ++ipt) {
220 for (ipl = 0; ipl < 3; ++ipl) {
221 for (iht = hStart[ipl]; iht < trkX[ipl].size(); ++iht) {
222 if (trkX[ipl][iht] < xOrigin - binX)
continue;
223 if (trkX[ipl][iht] > xOrigin + binX)
break;
224 hitWID.push_back(trkWID[ipl][iht]);
225 hitX.push_back(trkX[ipl][iht]);
226 hitXErr.push_back(trkXErr[ipl][iht]);
231 mf::LogVerbatim(
"TTA") <<
"ipt " << ipt <<
" xOrigin " << xOrigin <<
" binX " << binX
232 <<
" hitX size " << hitX.size();
233 if (hitX.size() > 3) {
236 mf::LogVerbatim(
"TTA") <<
" xyz " << xyz(0) <<
" " << xyz(1) <<
" " << xyz(2) <<
" dir " 237 <<
dir(0) <<
" " <<
dir(1) <<
" " <<
dir(2) <<
" ChiDOF " << ChiDOF
238 <<
" hitX size " << hitX.size();
240 else if (ipt == 0 && STPos.size() == 2) {
246 if (xOrigin >=
maxX)
break;
248 if (
maxX - xOrigin < binX) { xOrigin =
maxX; }
252 if (ChiDOF < 0 || ChiDOF > 100)
continue;
253 TrajPos.push_back(xyz);
254 TrajDir.push_back(dir);
255 if (ipt == npt) gotLastPoint =
true;
258 mf::LogVerbatim(
"TTA") <<
"gotLastPoint " << gotLastPoint <<
" TTA Traj \n";
259 for (
unsigned short ii = 0; ii < TrajPos.size(); ++ii)
260 mf::LogVerbatim(
"TTA") << ii <<
" " << std::fixed << std::setprecision(1) << TrajPos[ii](0)
261 <<
" " << TrajPos[ii](1) <<
" " << TrajPos[ii](2);
264 if (!gotLastPoint && STPos.size() == 2) {
266 TrajPos.push_back(STPos[1]);
267 TrajDir.push_back(STDir[1]);
270 if (TrajPos.size() < 2) {
277 std::reverse(TrajPos.begin(), TrajPos.end());
278 std::reverse(TrajDir.begin(), TrajDir.end());
279 for (ipl = 0; ipl < 3; ++ipl) {
280 if (trkX[ipl].
size() == 0)
continue;
281 std::reverse(trkWID[ipl].
begin(), trkWID[ipl].
end());
282 std::reverse(trkX[ipl].
begin(), trkX[ipl].
end());
283 std::reverse(trkXErr[ipl].
begin(), trkXErr[ipl].
end());
289 for (
unsigned short ii = 0; ii < TrajPos.size(); ++ii)
290 mf::LogVerbatim(
"TTA") << ii <<
" " << std::fixed << std::setprecision(1) << TrajPos[ii](0)
291 <<
" " << TrajPos[ii](1) <<
" " << TrajPos[ii](2);
300 std::vector<TVector3>& TrajPos,
301 std::vector<TVector3>& TrajDir)
305 std::vector<unsigned short> usePlns;
309 for (
unsigned short nit = 0; nit < 5; ++nit) {
310 for (
unsigned int ipl = 0; ipl < 3; ++ipl) {
311 if (trkX[ipl].
size() == 0)
continue;
312 if (trkX[ipl][0] < xCut) usePlns.push_back(ipl);
314 if (usePlns.size() >= 2)
break;
319 mf::LogVerbatim(
"TTA") <<
"ShortTrack minX end " << xCut <<
" usePlns size " 321 if (usePlns.size() < 2)
return;
324 unsigned short nend = 0;
325 unsigned short iht = 0;
326 unsigned short ipl = usePlns[0];
327 double endX = trkX[ipl][iht];
328 unsigned short iPlane = trkWID[ipl][iht].Plane;
329 unsigned int iWire = trkWID[ipl][iht].Wire;
330 unsigned int cstat = trkWID[ipl][iht].Cryostat;
331 unsigned int tpc = trkWID[ipl][iht].TPC;
332 for (
unsigned short jj = 1; jj < usePlns.size(); ++jj) {
333 unsigned short jpl = usePlns[jj];
334 endX += trkX[jpl][iht];
335 unsigned short jPlane = trkWID[jpl][iht].Plane;
336 unsigned int jWire = trkWID[jpl][iht].Wire;
341 endY += intersection.y;
342 endZ += intersection.z;
347 xyz(0) = endX / (float)(nend + 1);
348 xyz(1) = endY / (float)nend;
349 xyz(2) = endZ / (float)nend;
350 if (
prt)
mf::LogVerbatim(
"TTA") <<
" xyz " << xyz(0) <<
" " << xyz(1) <<
" " << xyz(2);
351 TrajPos.push_back(xyz);
356 for (
unsigned short nit = 0; nit < 5; ++nit) {
358 for (ipl = 0; ipl < 3; ++ipl) {
359 if (trkX[ipl].
size() == 0)
continue;
360 iht = trkX[ipl].size() - 1;
361 if (trkX[ipl][iht] > xCut) usePlns.push_back(ipl);
363 if (usePlns.size() >= 2)
break;
368 mf::LogVerbatim(
"TTA") <<
"ShortTrack maxX end " << xCut <<
" usePlns size " 370 if (usePlns.size() < 2) {
379 iht = trkX[ipl].size() - 1;
380 endX = trkX[ipl][iht];
381 iPlane = trkWID[ipl][iht].Plane;
382 iWire = trkWID[ipl][iht].Wire;
383 for (
unsigned short jj = 1; jj < usePlns.size(); ++jj) {
384 unsigned short jpl = usePlns[jj];
385 iht = trkX[jpl].size() - 1;
386 endX += trkX[jpl][iht];
387 unsigned short jPlane = trkWID[jpl][iht].Plane;
388 unsigned int jWire = trkWID[jpl][iht].Wire;
393 endY += intersection.y;
394 endZ += intersection.z;
398 xyz(0) = endX / (float)(nend + 1);
399 xyz(1) = endY / (float)nend;
400 xyz(2) = endZ / (float)nend;
401 if (
prt)
mf::LogVerbatim(
"TTA") <<
" xyz " << xyz(0) <<
" " << xyz(1) <<
" " << xyz(2);
402 TrajPos.push_back(xyz);
403 TVector3
dir = TrajPos[1] - TrajPos[0];
405 TrajDir.push_back(dir);
406 TrajDir.push_back(dir);
409 mf::LogVerbatim(
"TTA") <<
">>>> Short track (" << TrajPos[0](0) <<
", " << TrajPos[0](1)
410 <<
", " << TrajPos[0](2) <<
") to (" << TrajPos[1](0) <<
", " 411 << TrajPos[1](1) <<
", " << TrajPos[1](2) <<
")";
void TrkLineFit(std::vector< geo::WireID > &hitWID, std::vector< double > &hitX, std::vector< double > &hitXErr, double XOrigin, TVector3 &Pos, TVector3 &Dir, float &ChiDOF) const
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
TrackLineFitAlg fTrackLineFitAlg
unsigned short fMaxTrajPoints
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
auto array(Array const &a)
Returns a manipulator which will print the specified array.
void TrackTrajectory(std::array< std::vector< geo::WireID >, 3 > trkWID, std::array< std::vector< double >, 3 > trkX, std::array< std::vector< double >, 3 > trkXErr, std::vector< TVector3 > &TrajPos, std::vector< TVector3 > &TrajDir)
Definition of data types for geometry description.
void ShortTrackTrajectory(std::array< std::vector< geo::WireID >, 3 > trkWID, std::array< std::vector< double >, 3 > trkX, std::array< std::vector< double >, 3 > trkXErr, std::vector< TVector3 > &TrajPos, std::vector< TVector3 > &TrajDir)
bool WireIDsIntersect(WireID const &wid1, WireID const &wid2, Point_t &intersection) const
Computes the intersection between two wires.
geo::WireReadoutGeom const * wireReadoutGeom
static constexpr WireIDIntersection invalid()
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.