15 #include "messagefacility/MessageLogger/MessageLogger.h"
26 std::vector<TVector3>& TrajPos, std::vector<TVector3>& TrajDir)
59 unsigned short minLen = 9999;
60 unsigned short maxLen = 0;
61 unsigned short nPlnsWithHits = 0;
62 unsigned short ipl, aPlane = 3;
63 for(ipl = 0; ipl < 3; ++ipl) {
64 if(trkX[ipl].
size() == 0)
continue;
66 if(trkX[ipl].
size() < minLen) {
67 minLen = trkX[ipl].size();
69 if(trkX[ipl].
size() > maxLen) {
70 maxLen = trkX[ipl].size();
74 if(
prt) mf::LogVerbatim(
"TTA")<<
"trkX sizes "<<trkX[0].size()<<
" "<<trkX[1].size()<<
" "<<trkX[2].size()<<
" "<<
" 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());
95 if(
prt) mf::LogVerbatim(
"TTA")<<
"Swapped order";
99 mf::LogVerbatim myprt(
"TTA");
101 for(ipl = 0; ipl < 3; ++ipl) {
102 if(trkX[ipl].
size() == 0)
continue;
103 myprt<<
" "<<trkX[ipl][0];
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];
138 double aveHitXErr = 0;
139 unsigned short nHit = 0;
140 for(ipl = 0; ipl < 3; ++ipl) {
141 for(iht = 0; iht < trkXErr[ipl].size(); ++iht) {
142 aveHitXErr += trkXErr[ipl][iht];
146 aveHitXErr /= (double)nHit;
148 unsigned short npt = (
maxX -
minX) / (1 * aveHitXErr);
150 if(npt > maxLen) npt = maxLen;
152 if(
prt) mf::LogVerbatim(
"TTA")<<
" aveHitXErr "<<aveHitXErr<<
" number of traj points ";
154 double maxBinX = (
maxX -
minX) / (
double)(npt - 1);
155 double binX = maxBinX;
156 double xOrigin =
minX;
160 std::vector<geo::WireID> hitWID;
161 std::vector<double> hitX;
162 std::vector<double> hitXErr;
166 std::vector<TVector3> STPos;
167 std::vector<TVector3> STDir;
170 if(STPos.size() != 2 || STDir.size() != STPos.size()) {
174 for(ipl = 0; ipl < 3; ++ipl) {
175 if(trkX[ipl].
size() == 0)
continue;
176 std::reverse(trkWID[ipl].
begin(), trkWID[ipl].
end());
177 std::reverse(trkX[ipl].
begin(), trkX[ipl].
end());
178 std::reverse(trkXErr[ipl].
begin(), trkXErr[ipl].
end());
185 mf::LogVerbatim(
"TTA")<<
"STPos";
186 for(
unsigned short ii = 0; ii < STPos.size(); ++ii) mf::LogVerbatim(
"TTA")<<ii<<
" "<<std::fixed<<std::setprecision(1)<<STPos[ii](0)<<
" "<<STPos[ii](1)<<
" "<<STPos[ii](2);
189 if(maxLen < 4 || npt < 2) {
194 std::reverse(TrajPos.begin(), TrajPos.end());
195 std::reverse(TrajDir.begin(), TrajDir.end());
196 for(ipl = 0; ipl < 3; ++ipl) {
197 if(trkX[ipl].
size() == 0)
continue;
198 std::reverse(trkWID[ipl].
begin(), trkWID[ipl].
end());
199 std::reverse(trkX[ipl].
begin(), trkX[ipl].
end());
200 std::reverse(trkXErr[ipl].
begin(), trkXErr[ipl].
end());
207 std::array<unsigned short, 3> hStart;
208 for(ipl = 0; ipl < 3; ++ipl) hStart[ipl] = 0;
210 bool gotLastPoint =
false;
211 for(
unsigned short ipt = 0; ipt < npt + 1; ++ipt) {
215 for(ipl = 0; ipl < 3; ++ipl) {
216 for(iht = hStart[ipl]; iht < trkX[ipl].size(); ++iht) {
217 if(trkX[ipl][iht] < xOrigin - binX)
continue;
218 if(trkX[ipl][iht] > xOrigin + binX)
break;
219 hitWID.push_back(trkWID[ipl][iht]);
220 hitX.push_back(trkX[ipl][iht]);
221 hitXErr.push_back(trkXErr[ipl][iht]);
225 if(
prt) mf::LogVerbatim(
"TTA")<<
"ipt "<<ipt<<
" xOrigin "<<xOrigin<<
" binX "<<binX<<
" hitX size "<<hitX.size();
226 if(hitX.size() > 3) {
228 if(
prt) mf::LogVerbatim(
"TTA")<<
" xyz "<<xyz(0)<<
" "<<xyz(1)<<
" "<<xyz(2)<<
" dir "<<
dir(0)<<
" "<<
dir(1)<<
" "<<
dir(2)<<
" ChiDOF "<<ChiDOF<<
" hitX size "<<hitX.size();
229 }
else if(ipt == 0 && STPos.size() == 2) {
234 if(
prt && hitX.size() < 4) mf::LogVerbatim(
"TTA")<<
"\n";
235 if(xOrigin >=
maxX)
break;
237 if(
maxX - xOrigin < binX) {
242 if(ChiDOF < 0 || ChiDOF > 100)
continue;
243 TrajPos.push_back(xyz);
244 TrajDir.push_back(dir);
245 if(ipt == npt) gotLastPoint =
true;
248 mf::LogVerbatim(
"TTA")<<
"gotLastPoint "<<gotLastPoint<<
" TTA Traj \n";
249 for(
unsigned short ii = 0; ii < TrajPos.size(); ++ii) mf::LogVerbatim(
"TTA")<<ii<<
" "<<std::fixed<<std::setprecision(1)<<TrajPos[ii](0)<<
" "<<TrajPos[ii](1)<<
" "<<TrajPos[ii](2);
252 if(!gotLastPoint && STPos.size() == 2) {
254 TrajPos.push_back(STPos[1]);
255 TrajDir.push_back(STDir[1]);
258 if(TrajPos.size() < 2) {
265 std::reverse(TrajPos.begin(), TrajPos.end());
266 std::reverse(TrajDir.begin(), TrajDir.end());
267 for(ipl = 0; ipl < 3; ++ipl) {
268 if(trkX[ipl].
size() == 0)
continue;
269 std::reverse(trkWID[ipl].
begin(), trkWID[ipl].
end());
270 std::reverse(trkX[ipl].
begin(), trkX[ipl].
end());
271 std::reverse(trkXErr[ipl].
begin(), trkXErr[ipl].
end());
276 mf::LogVerbatim(
"TTA")<<
"TTA Traj2\n";
277 for(
unsigned short ii = 0; ii < TrajPos.size(); ++ii) mf::LogVerbatim(
"TTA")<<ii<<
" "<<std::fixed<<std::setprecision(1)<<TrajPos[ii](0)<<
" "<<TrajPos[ii](1)<<
" "<<TrajPos[ii](2);
286 std::vector<TVector3>& TrajPos, std::vector<TVector3>& TrajDir)
290 std::vector<unsigned short> usePlns;
291 double y,
z, endX, endY, endZ;
292 unsigned short ipl, iht, nend, jpl, iPlane, jPlane;
293 unsigned int iWire, jWire;
297 for(
unsigned short nit = 0; nit < 5; ++nit) {
299 for(ipl = 0; ipl < 3; ++ipl) {
300 if(trkX[ipl].
size() == 0)
continue;
301 if(trkX[ipl][0] < xCut) usePlns.push_back(ipl);
303 if(usePlns.size() >= 2)
break;
307 if(
prt) mf::LogVerbatim(
"TTA")<<
"ShortTrack minX end "<<xCut<<
" usePlns size "<<usePlns.size();
308 if(usePlns.size() < 2)
return;
309 endY = 0; endZ = 0; nend = 0;
312 endX = trkX[ipl][iht];
313 iPlane = trkWID[ipl][iht].Plane;
314 iWire = trkWID[ipl][iht].Wire;
315 unsigned int cstat = trkWID[ipl][iht].Cryostat;
316 unsigned int tpc = trkWID[ipl][iht].TPC;
317 for(
unsigned short jj = 1; jj < usePlns.size(); ++jj) {
319 endX += trkX[jpl][iht];
320 jPlane = trkWID[jpl][iht].Plane;
321 jWire = trkWID[jpl][iht].Wire;
322 geom->IntersectionPoint(iWire, jWire, iPlane, jPlane, cstat, tpc, y, z);
329 xyz(0) = endX / (float)(nend + 1);
330 xyz(1) = endY / (float)nend;
331 xyz(2) = endZ / (float)nend;
332 if(
prt) mf::LogVerbatim(
"TTA")<<
" xyz "<<xyz(0)<<
" "<<xyz(1)<<
" "<<xyz(2);
333 TrajPos.push_back(xyz);
339 for(
unsigned short nit = 0; nit < 5; ++nit) {
341 for(ipl = 0; ipl < 3; ++ipl) {
342 if(trkX[ipl].
size() == 0)
continue;
343 iht = trkX[ipl].size() - 1;
344 if(trkX[ipl][iht] > xCut) usePlns.push_back(ipl);
346 if(usePlns.size() >= 2)
break;
350 if(
prt) mf::LogVerbatim(
"TTA")<<
"ShortTrack maxX end "<<xCut<<
" usePlns size "<<usePlns.size();
351 if(usePlns.size() < 2) {
356 endY = 0; endZ = 0; nend = 0;
358 iht = trkX[ipl].size() - 1;
359 endX = trkX[ipl][iht];
360 iPlane = trkWID[ipl][iht].Plane;
361 iWire = trkWID[ipl][iht].Wire;
362 for(
unsigned short jj = 1; jj < usePlns.size(); ++jj) {
364 iht = trkX[jpl].size() - 1;
365 endX += trkX[jpl][iht];
366 jPlane = trkWID[jpl][iht].Plane;
367 jWire = trkWID[jpl][iht].Wire;
368 geom->IntersectionPoint(iWire, jWire, iPlane, jPlane, cstat, tpc, y, z);
374 xyz(0) = endX / (float)(nend + 1);
375 xyz(1) = endY / (float)nend;
376 xyz(2) = endZ / (float)nend;
377 if(
prt) mf::LogVerbatim(
"TTA")<<
" xyz "<<xyz(0)<<
" "<<xyz(1)<<
" "<<xyz(2);
378 TrajPos.push_back(xyz);
379 TVector3
dir = TrajPos[1] - TrajPos[0];
381 TrajDir.push_back(dir);
382 TrajDir.push_back(dir);
384 if(
prt) mf::LogVerbatim(
"TTA")<<
">>>> Short track ("<<TrajPos[0](0)<<
", "<<TrajPos[0](1)<<
", "<<TrajPos[0](2)<<
") to ("<<TrajPos[1](0)<<
", "<<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
process_name opflash particleana ie ie ie z
TrackLineFitAlg fTrackLineFitAlg
unsigned short fMaxTrajPoints
std::size_t size(FixedBins< T, C > const &) noexcept
process_name opflash particleana ie ie y
then echo ***************************************echo array
auto end(FixedBins< T, C > const &) noexcept
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)
auto begin(FixedBins< T, C > const &) noexcept
art::ServiceHandle< geo::Geometry const > geom