12 #include <sys/types.h> 32 std::vector<TVector3>& TrajPos, std::vector<TVector3>& TrajDir)
65 unsigned short minLen = 9999;
66 unsigned short maxLen = 0;
67 unsigned short nPlnsWithHits = 0;
68 unsigned short ipl, aPlane = 3;
69 for(ipl = 0; ipl < 3; ++ipl) {
70 if(trkX[ipl].size() == 0)
continue;
72 if(trkX[ipl].size() < minLen) {
73 minLen = trkX[ipl].size();
75 if(trkX[ipl].size() > maxLen) {
76 maxLen = trkX[ipl].size();
80 if(
prt)
mf::LogVerbatim(
"TTA")<<
"trkX sizes "<<trkX[0].size()<<
" "<<trkX[1].size()<<
" "<<trkX[2].size()<<
" "<<
" nPlnsWithHits "<<nPlnsWithHits;
81 if(nPlnsWithHits < 2)
return;
82 if(aPlane > 2)
return;
92 iht = trkX[aPlane].size() - 1;
93 if(trkX[aPlane][0] > trkX[aPlane][iht]) {
95 for(ipl = 0; ipl < 3; ++ipl) {
96 if(trkX[ipl].size() == 0)
continue;
97 std::reverse(trkWID[ipl].
begin(), trkWID[ipl].
end());
98 std::reverse(trkX[ipl].
begin(), trkX[ipl].
end());
99 std::reverse(trkXErr[ipl].
begin(), trkXErr[ipl].
end());
107 for(ipl = 0; ipl < 3; ++ipl) {
108 if(trkX[ipl].size() == 0)
continue;
109 myprt<<
" "<<trkX[ipl][0];
113 for(ipl = 0; ipl < 3; ++ipl) {
114 if(trkX[ipl].size() == 0)
continue;
115 iht = trkX[ipl].size() - 1;
116 myprt<<
" "<<trkX[ipl][iht];
127 for(
unsigned short ipl = 0; ipl < 3; ++ipl) {
128 if(trkX[ipl].size() == 0)
continue;
129 if(trkX[ipl][0] <
minX) {
133 iht = trkX[ipl].size() - 1;
134 if(trkX[ipl][iht] >
maxX) {
135 maxX = trkX[ipl][iht];
144 double aveHitXErr = 0;
145 unsigned short nHit = 0;
146 for(ipl = 0; ipl < 3; ++ipl) {
147 for(iht = 0; iht < trkXErr[ipl].size(); ++iht) {
148 aveHitXErr += trkXErr[ipl][iht];
152 aveHitXErr /= (double)nHit;
154 unsigned short npt = (
maxX -
minX) / (1 * aveHitXErr);
156 if(npt > maxLen) npt = maxLen;
158 if(
prt)
mf::LogVerbatim(
"TTA")<<
" aveHitXErr "<<aveHitXErr<<
" number of traj points ";
160 double maxBinX = (
maxX -
minX) / (
double)(npt - 1);
161 double binX = maxBinX;
162 double xOrigin =
minX;
166 std::vector<geo::WireID> hitWID;
167 std::vector<double> hitX;
168 std::vector<double> hitXErr;
172 std::vector<TVector3> STPos;
173 std::vector<TVector3> STDir;
176 if(STPos.size() != 2 || STDir.size() != STPos.size()) {
180 for(ipl = 0; ipl < 3; ++ipl) {
181 if(trkX[ipl].size() == 0)
continue;
182 std::reverse(trkWID[ipl].
begin(), trkWID[ipl].
end());
183 std::reverse(trkX[ipl].
begin(), trkX[ipl].
end());
184 std::reverse(trkXErr[ipl].
begin(), trkXErr[ipl].
end());
192 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);
195 if(maxLen < 4 || npt < 2) {
200 std::reverse(TrajPos.begin(), TrajPos.end());
201 std::reverse(TrajDir.begin(), TrajDir.end());
202 for(ipl = 0; ipl < 3; ++ipl) {
203 if(trkX[ipl].size() == 0)
continue;
204 std::reverse(trkWID[ipl].
begin(), trkWID[ipl].
end());
205 std::reverse(trkX[ipl].
begin(), trkX[ipl].
end());
206 std::reverse(trkXErr[ipl].
begin(), trkXErr[ipl].
end());
213 std::array<unsigned short, 3> hStart;
214 for(ipl = 0; ipl < 3; ++ipl) hStart[ipl] = 0;
216 bool gotLastPoint =
false;
217 for(
unsigned short ipt = 0; ipt < npt + 1; ++ipt) {
221 for(ipl = 0; ipl < 3; ++ipl) {
222 for(iht = hStart[ipl]; iht < trkX[ipl].size(); ++iht) {
223 if(trkX[ipl][iht] < xOrigin - binX)
continue;
224 if(trkX[ipl][iht] > xOrigin + binX)
break;
225 hitWID.push_back(trkWID[ipl][iht]);
226 hitX.push_back(trkX[ipl][iht]);
227 hitXErr.push_back(trkXErr[ipl][iht]);
231 if(
prt)
mf::LogVerbatim(
"TTA")<<
"ipt "<<ipt<<
" xOrigin "<<xOrigin<<
" binX "<<binX<<
" hitX size "<<hitX.size();
232 if(hitX.size() > 3) {
234 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();
235 }
else if(ipt == 0 && STPos.size() == 2) {
241 if(xOrigin >=
maxX)
break;
243 if(
maxX - xOrigin < binX) {
248 if(ChiDOF < 0 || ChiDOF > 100)
continue;
249 TrajPos.push_back(xyz);
250 TrajDir.push_back(dir);
251 if(ipt == npt) gotLastPoint =
true;
255 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);
258 if(!gotLastPoint && STPos.size() == 2) {
260 TrajPos.push_back(STPos[1]);
261 TrajDir.push_back(STDir[1]);
264 if(TrajPos.size() < 2) {
271 std::reverse(TrajPos.begin(), TrajPos.end());
272 std::reverse(TrajDir.begin(), TrajDir.end());
273 for(ipl = 0; ipl < 3; ++ipl) {
274 if(trkX[ipl].size() == 0)
continue;
275 std::reverse(trkWID[ipl].
begin(), trkWID[ipl].
end());
276 std::reverse(trkX[ipl].
begin(), trkX[ipl].
end());
277 std::reverse(trkXErr[ipl].
begin(), trkXErr[ipl].
end());
283 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);
292 std::vector<TVector3>& TrajPos, std::vector<TVector3>& TrajDir)
296 std::vector<unsigned short> usePlns;
297 double y,
z, endX, endY, endZ;
298 unsigned short ipl, iht, nend, jpl, iPlane, jPlane;
299 unsigned int iWire, jWire;
303 for(
unsigned short nit = 0; nit < 5; ++nit) {
305 for(ipl = 0; ipl < 3; ++ipl) {
306 if(trkX[ipl].size() == 0)
continue;
307 if(trkX[ipl][0] < xCut) usePlns.push_back(ipl);
309 if(usePlns.size() >= 2)
break;
313 if(
prt)
mf::LogVerbatim(
"TTA")<<
"ShortTrack minX end "<<xCut<<
" usePlns size "<<usePlns.size();
314 if(usePlns.size() < 2)
return;
315 endY = 0; endZ = 0; nend = 0;
318 endX = trkX[ipl][iht];
319 iPlane = trkWID[ipl][iht].Plane;
320 iWire = trkWID[ipl][iht].Wire;
321 unsigned int cstat = trkWID[ipl][iht].Cryostat;
322 unsigned int tpc = trkWID[ipl][iht].TPC;
323 for(
unsigned short jj = 1; jj < usePlns.size(); ++jj) {
325 endX += trkX[jpl][iht];
326 jPlane = trkWID[jpl][iht].Plane;
327 jWire = trkWID[jpl][iht].Wire;
335 xyz(0) = endX / (float)(nend + 1);
336 xyz(1) = endY / (float)nend;
337 xyz(2) = endZ / (float)nend;
339 TrajPos.push_back(xyz);
345 for(
unsigned short nit = 0; nit < 5; ++nit) {
347 for(ipl = 0; ipl < 3; ++ipl) {
348 if(trkX[ipl].size() == 0)
continue;
349 iht = trkX[ipl].size() - 1;
350 if(trkX[ipl][iht] > xCut) usePlns.push_back(ipl);
352 if(usePlns.size() >= 2)
break;
356 if(
prt)
mf::LogVerbatim(
"TTA")<<
"ShortTrack maxX end "<<xCut<<
" usePlns size "<<usePlns.size();
357 if(usePlns.size() < 2) {
362 endY = 0; endZ = 0; nend = 0;
364 iht = trkX[ipl].size() - 1;
365 endX = trkX[ipl][iht];
366 iPlane = trkWID[ipl][iht].Plane;
367 iWire = trkWID[ipl][iht].Wire;
368 for(
unsigned short jj = 1; jj < usePlns.size(); ++jj) {
370 iht = trkX[jpl].size() - 1;
371 endX += trkX[jpl][iht];
372 jPlane = trkWID[jpl][iht].Plane;
373 jWire = trkWID[jpl][iht].Wire;
380 xyz(0) = endX / (float)(nend + 1);
381 xyz(1) = endY / (float)nend;
382 xyz(2) = endZ / (float)nend;
384 TrajPos.push_back(xyz);
385 TVector3
dir = TrajPos[1] - TrajPos[0];
387 TrajDir.push_back(dir);
388 TrajDir.push_back(dir);
390 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)<<
")";
art::ServiceHandle< geo::Geometry > geom
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
TrackLineFitAlg fTrackLineFitAlg
void TrkLineFit(std::vector< geo::WireID > &hitWID, std::vector< double > &hitX, std::vector< double > &hitXErr, double XOrigin, TVector3 &Pos, TVector3 &Dir, float &ChiDOF)
virtual ~TrackTrajectoryAlg()
unsigned short fMaxTrajPoints
auto array(Array const &a)
Returns a manipulator which will print the specified array.
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
bool IntersectionPoint(geo::WireID const &wid1, geo::WireID const &wid2, double &y, double &z) const
Returns the intersection point of two wires.
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)
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)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)