LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
trkf::StitchAlg Class Reference

#include "StitchAlg.h"

Public Member Functions

 StitchAlg (fhicl::ParameterSet const &pset)
 
void reconfigure (fhicl::ParameterSet const &pset)
 
void FindHeadsAndTails (const art::Event &e, const std::string &t)
 
void FirstStitch (const std::vector< art::PtrVector< recob::Track >>::iterator itvvArg, const std::vector< recob::Track >::iterator itvArg)
 
void WalkStitch ()
 
bool CommonComponentStitch ()
 
void GetTrackComposites (std::vector< art::PtrVector< recob::Track >> &c) const
 
void GetTracks (std::vector< recob::Track > &t) const
 

Public Attributes

art::Handle< std::vector< recob::Track > > ftListHandle
 

Private Attributes

std::vector< std::tuple< std::string, int, int, double, double > > fh
 
std::vector< std::tuple< std::string, int, int, double, double > > ft
 
int ftNo
 
double fCosAngTol
 
double fSepTol
 
std::vector< art::PtrVector< recob::Track > > fTrackComposite
 
std::vector< recob::TrackfTrackVec
 
std::vector< std::vector< std::string > > fHT
 

Detailed Description

Definition at line 30 of file StitchAlg.h.

Constructor & Destructor Documentation

trkf::StitchAlg::StitchAlg ( fhicl::ParameterSet const &  pset)

Definition at line 26 of file StitchAlg.cxx.

References art::Handle< T >::clear(), ftListHandle, ftNo, and reconfigure().

27 {
28  ftNo = 0;
30  this->reconfigure(pset);
31 }
art::Handle< std::vector< recob::Track > > ftListHandle
Definition: StitchAlg.h:49
void reconfigure(fhicl::ParameterSet const &pset)
Definition: StitchAlg.cxx:36
void clear()
Definition: Handle.h:255

Member Function Documentation

bool trkf::StitchAlg::CommonComponentStitch ( )

Definition at line 472 of file StitchAlg.cxx.

References art::PtrVector< T >::erase(), fHT, FirstStitch(), fTrackComposite, and fTrackVec.

Referenced by trkf::TrackStitcher::produce().

473 {
474  // "os" for outer scope.
475  int osciit(-12), oscjit(-12);
476  std::vector<art::PtrVector<recob::Track>>::iterator osiComposite, osjComposite;
478 
479  bool match(false);
480  int ciit(0);
481  for (auto iit = fTrackComposite.begin(); iit != fTrackComposite.end() && !match; ++iit) {
482  ciit++;
483  int cjit(ciit);
484  for (auto jit = iit + 1; jit != fTrackComposite.end() && !match; ++jit) {
485  cjit++;
486  for (auto iiit = iit->begin(); iiit != iit->end() && !match; ++iiit) {
487  for (auto jjit = jit->begin(); jjit != jit->end() && !match; ++jjit) {
488  if (*iiit == *jjit) // 2 components from 2 different composites are the same
489  {
490  // head is attached to one trk and tail to another.
491  // std::cout << "StitchAlg::CommonComponentStitch: We have two aggregate tracks that have a common component and need to be further stitched. " << std::endl;
492 
493  match = true;
494  osiComposite = iit;
495  osjComposite = jit;
496  osciit = ciit;
497  oscjit = cjit;
498  osiAgg = iiit;
499  osjAgg = jjit; // yes, unneeded, but we keep it for notational clarity
500  }
501  }
502  }
503  }
504  }
505  if (!match) return match;
506 
507  // Proceed to stitch 'em all together, dropping the one redundant component. Then
508  // erase the first occurence of the composite and the matching aggregate trk.
509 
510  // std::cout << "StitchAlg::CommonComponentStitch: pre erase: " << osiComposite->size() << std::endl;
511  (*osiComposite).erase(osiAgg); // erase redundant component track
512  // do not erase this fHT element, however
513 
514  // std::cout << "StitchAlg::CommonComponentStitch: post erase: " << osiComposite->size() << std::endl;
515  // std::cout << "StitchAlg::CommonComponentStitch: fHT.size(): " << fHT.size() << std::endl;
516 
517  // Next is a loop over all remaining components in osiComposite.
518  // insert the non-redundant osciit tracks onto front (back) of osjit
519  // insert the non-redundant osciit vtx links onto front (back) of fHT.begin()+oscjit-1
520 
521  std::vector<std::vector<std::string>>::iterator siit(fHT.begin() + osciit - 1);
522  std::vector<std::vector<std::string>>::iterator sjit(fHT.begin() + oscjit - 1);
523  size_t itdiff(osiComposite->end() - osiComposite->begin());
524  if (osjAgg == osjComposite->begin()) {
525 
526  // std::cout << "StitchAlg::begin insert starting: " << std::endl;
527  // std::cout << "StitchAlg::CommonComponentStitch: itdiff: " << itdiff << std::endl;
528  //std::cout << "StitchAlg::CommonComponentStitch: osiComposite.end-begin: " << osiComposite->end()-osiComposite->begin()<< std::endl;
529  //std::cout << "StitchAlg::CommonComponentStitch: osjComposite.end-begin: " << osjComposite->end()-osjComposite->begin()<< std::endl;
530  (*osjComposite)
531  .insert(osjComposite->begin(), osiComposite->begin(), osiComposite->begin() + itdiff);
532  //std::cout << "StitchAlg::CommonComponentStitch: siit.end-begin: " << siit->end()-siit->begin()<< std::endl;
533  //std::cout << "StitchAlg::CommonComponentStitch: sjit.end-begin: " << sjit->end()-sjit->begin()<< std::endl;
534  (*sjit).insert(sjit->begin(), siit->begin(), siit->begin() + itdiff);
535  //std::cout << "StitchAlg::begin insert done: " << std::endl;
536  }
537  else if (osjAgg == (osjComposite->end() - 1)) {
538  // std::cout << "StitchAlg::end insert starting: " << std::endl;
539  (*osjComposite)
540  .insert(osjComposite->end(), osiComposite->begin(), osiComposite->begin() + itdiff);
541  (*sjit).insert(sjit->end(), siit->begin(), siit->begin() + itdiff);
542  // std::cout << "StitchAlg::end insert done: " << std::endl;
543  }
544 
545  // std::cout << "StitchAlg:: 1: " << std::endl;
546  fTrackVec.erase(fTrackVec.begin() + oscjit -
547  1); // erase old Stitched Track, which we'll recreate now...
548 
549  // std::cout << "StitchAlg:: 2: " << std::endl;
550  FirstStitch(osjComposite, fTrackVec.begin() + oscjit - 1); // Create new Stitched Track
551  // fTrackComposite.insert(fTrackComposite.begin()+oscjit-1-1,*osjComposite); // erase old composite Track
552  // std::cout << "StitchAlg:: 3: " << std::endl;
553  fTrackVec.erase(fTrackVec.begin() + osciit - 1); // erase old Stitched Track
554  // std::cout << "StitchAlg:: 6: " << std::endl;
555  fTrackComposite.erase(osiComposite); // erase old composite Track
556  // std::cout << "StitchAlg:: 4: " << std::endl;
557  fHT.erase(fHT.begin() + osciit - 1); // erase old vec of vtx links
558  // std::cout << "StitchAlg:: 5: " << std::endl;
559 
560  return match;
561 
562 } // end of bool CommonComponentStitch()
typename data_t::iterator iterator
Definition: PtrVector.h:54
std::vector< recob::Track > fTrackVec
Definition: StitchAlg.h:59
iterator erase(iterator position)
Definition: PtrVector.h:504
void FirstStitch(const std::vector< art::PtrVector< recob::Track >>::iterator itvvArg, const std::vector< recob::Track >::iterator itvArg)
Definition: StitchAlg.cxx:259
std::vector< art::PtrVector< recob::Track > > fTrackComposite
Definition: StitchAlg.h:58
std::vector< std::vector< std::string > > fHT
Definition: StitchAlg.h:60
void trkf::StitchAlg::FindHeadsAndTails ( const art::Event e,
const std::string &  t 
)

Definition at line 43 of file StitchAlg.cxx.

References util::abs(), recob::Track::End(), recob::Track::EndDirection(), fCosAngTol, fh, fHT, fSepTol, ft, ftListHandle, fTrackComposite, fTrackVec, art::ProductRetriever::getByLabel(), recob::Track::Vertex(), and recob::Track::VertexDirection().

Referenced by trkf::TrackStitcher::produce().

45 {
46 
47  fTrackVec.clear();
48  fTrackComposite.clear();
49  fHT.clear();
50 
51  EvtArg.getByLabel(trackModuleLabelArg, ftListHandle);
52 
53  // An element of fh and ft for each outer track. Keep the cos and sep parameters of the match and a string that indicates whether it's the second track's head or tail that gives the match, along with ii, jj, the indices of the outer and inner tracks.
54  ft.clear();
55  fh.clear();
56 
57  int ntrack = ftListHandle->size();
58  // std::cout << "StitchAlg.FindHeadsAndTails: Number of tracks in " << ntrack << std::endl;
59  for (int ii = 0; ii < ntrack; ++ii) {
61  const recob::Track& track1 = *ptrack1;
62  const TVector3 start1(track1.Vertex<TVector3>());
63  const TVector3 end1(track1.End<TVector3>());
64  const TVector3 start1Dir(track1.VertexDirection<TVector3>());
65  const TVector3 end1Dir(track1.EndDirection<TVector3>());
66  // For each outer track, make a vector of 1 candidate track. Doesn't need to be a vector except for desire to have a 2-iteration history.
67  std::vector<std::tuple<std::string, int, int, double, double>> headvv;
68  std::vector<std::tuple<std::string, int, int, double, double>> tailvv;
69 
70  // For head/tail keep a vector of candidate (cos,sep)
71  std::vector<std::vector<std::pair<double, double>>> matchhead;
72  std::vector<std::vector<std::pair<double, double>>> matchtail;
73  // Neither end of track1 is yet matched:
74  bool head(false);
75  bool tail(false);
76 
77  for (int jj = ii + 1; jj < ntrack; ++jj) {
79  const recob::Track& track2 = *ptrack2;
80  const TVector3& start2(track2.Vertex<TVector3>());
81  const TVector3& end2(track2.End<TVector3>());
82  const TVector3& start2Dir(track2.VertexDirection<TVector3>());
83  const TVector3& end2Dir(track2.EndDirection<TVector3>());
84  std::string sHT2("NA"); // track2 (receptor track) H or T is tagged as matched
85 
86  bool c12((std::abs(start1Dir.Dot(end2Dir)) > fCosAngTol) &&
87  ((start1 - end2).Mag() < fSepTol));
88  bool c21((std::abs(end1Dir.Dot(start2Dir)) > fCosAngTol) &&
89  ((start2 - end1).Mag() < fSepTol));
90  bool c11((std::abs(start1Dir.Dot(start2Dir)) > fCosAngTol) &&
91  ((start1 - start2).Mag() < fSepTol));
92  bool c22((std::abs(end1Dir.Dot(end2Dir)) > fCosAngTol) && ((end1 - end2).Mag() < fSepTol));
93 
94  if (c12 || c21 || c11 || c22) {
95 
96  sHT2 = "NA";
97  if (c12 || c11) { head = true; }
98  if (c11) { sHT2 = "H"; }
99  else if (c12) {
100  sHT2 = "T";
101  }
102  if (c21 || c22) { tail = true; }
103  if (c21) { sHT2 = "H"; }
104  else if (c22) {
105  sHT2 = "T";
106  }
107 
108  if (head && tail) // split the tie by distance
109  {
110  head = false;
111  tail = false;
112  if (((start1 - end2).Mag() < (start2 - end1).Mag()) ||
113  ((start1 - end2).Mag() < (start2 - end2).Mag()) ||
114  ((start1 - start2).Mag() < (start2 - end1).Mag()) ||
115  ((start1 - start2).Mag() < (start2 - end2).Mag())) {
116  head = true;
117  tail = false;
118  }
119  else {
120  head = false;
121  tail = true;
122  }
123  }
124 
125  if (head) {
126  // 2-deep vector, for head and tail of 2nd track
127  std::vector<std::pair<double, double>> headv;
128  headv.push_back(
129  std::pair<double, double>(abs(start1Dir.Dot(start2Dir)), (start1 - start2).Mag()));
130  headv.push_back(
131  std::pair<double, double>(abs(start1Dir.Dot(end2Dir)), (start1 - end2).Mag()));
132 
133  matchhead.push_back(headv);
134  // if inferior, drop the new elements; if superior, replace the old
135  if (((matchhead.size() > 1) &&
136  ((matchhead.back().at(0).second < matchhead.front().at(0).second) ||
137  (matchhead.back().at(1).second < matchhead.front().at(1).second))) ||
138  matchhead.size() == 1) {
139  if (matchhead.size() > 1) matchhead.erase(matchhead.begin());
140  if (headvv.size() > 1) headvv.erase(headvv.begin());
141  if (!sHT2.compare("H")) {
142  auto tupTmp = std::make_tuple(
143  sHT2, ii, jj, matchhead.back().at(0).first, matchhead.back().at(0).second);
144  headvv.push_back(tupTmp);
145  }
146  else {
147  auto tupTmp = std::make_tuple(
148  sHT2, ii, jj, matchhead.back().at(1).first, matchhead.back().at(1).second);
149  headvv.push_back(tupTmp);
150  }
151  }
152  else
153  matchhead.pop_back();
154 
155  // std::cout << "TrackStitcher: satisfied head. " << std::endl;
156  } // head
157 
158  else if (tail) // else if to prevent same stitching candidate being
159  // allowed at both head and tail
160  {
161  // 2-deep vector, for head and tail of 2nd track
162  std::vector<std::pair<double, double>> tailv;
163  tailv.push_back(
164  std::pair<double, double>(abs(end1Dir.Dot(start2Dir)), (start2 - end1).Mag()));
165  tailv.push_back(
166  std::pair<double, double>(abs(end1Dir.Dot(end2Dir)), (end1 - end2).Mag()));
167  matchtail.push_back(tailv);
168  // if inferior, drop the new elements; if superior, replace the old
169  if (((matchtail.size() > 1) &&
170  ((matchtail.back().at(0).second < matchtail.front().at(0).second) ||
171  (matchtail.back().at(1).second < matchtail.front().at(1).second))) ||
172  matchtail.size() == 1) {
173  if (matchtail.size() > 1) matchtail.erase(matchtail.begin());
174  if (tailvv.size() > 1) tailvv.erase(tailvv.begin());
175  if (!sHT2.compare("T")) {
176  auto tupTmp = std::make_tuple(
177  sHT2, ii, jj, matchtail.back().at(0).first, matchtail.back().at(0).second);
178  tailvv.push_back(tupTmp);
179  }
180  else {
181  auto tupTmp = std::make_tuple(
182  sHT2, ii, jj, matchtail.back().at(1).first, matchtail.back().at(1).second);
183  tailvv.push_back(tupTmp);
184  }
185  }
186  else
187  matchtail.pop_back();
188 
189  // std::cout << "TrackStitcher: satisfied tail. " << std::endl;
190  } //tail
191  /*
192  std::cout << "abs(start1Dir.Dot(end2Dir)) " << std::abs(start1Dir.Dot(end2Dir)) << ", start1-end2.Mag(): " << (start1-end2).Mag() << std::endl;
193  std::cout << "abs(end1Dir.Dot(start2Dir)) " << std::abs(end1Dir.Dot(start2Dir)) << ", start2-end1.Mag(): " << (start2-end1).Mag() << std::endl;
194  std::cout << "abs(start1Dir.Dot(start2Dir)) " << std::abs(start1Dir.Dot(start2Dir)) << ", start1-start2.Mag(): " << (start1-start2).Mag() << std::endl;
195  std::cout << "abs(end1Dir.Dot(end2Dir)) " << std::abs(end1Dir.Dot(end2Dir)) << ", end1-end2.Mag(): " << (end1-end2).Mag() << std::endl;
196  std::cout << "sHT2 " << sHT2 << std::endl;
197  */
198  } // end c11||c12||c21||c22
199 
200  // We've been careful to pick the best jj match for this iith track head and tail.
201  // Now we need to be sure that for the jjth track head/tail we don't have two ii trks.
202  if (headvv.size()) {
203  int otrk = std::get<2>(headvv.back()); // jj'th track for this iith trk
204  // H or T of this jj'th trk we're matched to.
205  std::string sotrkht(std::get<0>(headvv.back()));
206  for (int kk = 0; kk < ii; ++kk) {
207  if (std::get<2>(fh.at(kk)) == otrk && !sotrkht.compare(std::get<0>(fh.at(kk)))) {
208  // check matching sep and pick the best one. Either erase this
209  // headvv (and it'll get null settings later below) or null out
210  // the parameters in fh.
211  if (std::get<4>(headvv.back()) < std::get<4>(fh.at(kk)) &&
212  std::get<4>(headvv.back()) != 0.0) {
213  auto tupTmp2 = std::make_tuple(std::string("NA"), kk, -12, 0.0, 0.0);
214  fh.at(kk) = tupTmp2;
215  }
216  else if (std::get<4>(headvv.back()) != 0.0) {
217  headvv.pop_back();
218  break;
219  }
220  }
221  }
222  }
223  if (tailvv.size()) {
224  int otrk = std::get<2>(tailvv.back()); // jj'th track for this iith trk
225  // H or T of this jj'th trk we're matched to.
226  std::string sotrkht(std::get<0>(tailvv.back()));
227  for (int kk = 0; kk < ii; ++kk) {
228  if (std::get<2>(ft.at(kk)) == otrk && !sotrkht.compare(std::get<0>(ft.at(kk)))) {
229  // check matching sep and pick the best one. erase either this
230  // tailvv or null out the parameters in ft.
231  if (std::get<4>(tailvv.back()) < std::get<4>(ft.at(kk)) &&
232  std::get<4>(tailvv.back()) != 0.0) {
233  auto tupTmp2 = std::make_tuple(std::string("NA"), kk, -12, 0.0, 0.0);
234  ft.at(kk) = tupTmp2;
235  }
236  else if (std::get<4>(tailvv.back()) != 0.0) {
237  tailvv.pop_back();
238  break;
239  }
240  }
241  }
242  }
243 
244  } // jj
245 
246  auto tupTmp2 = std::make_tuple(std::string("NA"), ii, -12, 0.0, 0.0);
247  // We always have our best 1-element tailvv and headvv for trk o at this point
248  if (!headvv.size()) headvv.push_back(tupTmp2);
249  if (!tailvv.size()) tailvv.push_back(tupTmp2);
250  // std::cout << "StitchAlg::FindHeadsAndTails: headvv, tailvv .get<0> is " << std::get<0>(headvv.back()) << ", " << std::get<0>(tailvv.back()) << std::endl;
251  fh.push_back(headvv.back());
252  ft.push_back(tailvv.back());
253 
254  } // ii
255 
256  // std::cout << "fh.size, ft.size are " << fh.size() << ", " << ft.size() << std::endl;
257 }
art::Handle< std::vector< recob::Track > > ftListHandle
Definition: StitchAlg.h:49
std::vector< recob::Track > fTrackVec
Definition: StitchAlg.h:59
std::vector< std::tuple< std::string, int, int, double, double > > fh
Definition: StitchAlg.h:52
constexpr auto abs(T v)
Returns the absolute value of the argument.
Vector_t VertexDirection() const
Access to track direction at different points.
Definition: Track.h:166
double fSepTol
Definition: StitchAlg.h:56
Point_t const & Vertex() const
Access to track position at different points.
Definition: Track.h:158
double fCosAngTol
Definition: StitchAlg.h:55
std::vector< art::PtrVector< recob::Track > > fTrackComposite
Definition: StitchAlg.h:58
Vector_t EndDirection() const
Access to track direction at different points.
Definition: Track.h:167
Point_t const & End() const
Access to track position at different points.
Definition: Track.h:159
std::vector< std::vector< std::string > > fHT
Definition: StitchAlg.h:60
std::vector< std::tuple< std::string, int, int, double, double > > ft
Definition: StitchAlg.h:53
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
void trkf::StitchAlg::FirstStitch ( const std::vector< art::PtrVector< recob::Track >>::iterator  itvvArg,
const std::vector< recob::Track >::iterator  itvArg 
)

TODO: sort according to spacepoint distance separation. As is, we're not sure we're not forming a stitched track with a (some) jump(s) and a reversal(s) of direction in it.

Definition at line 259 of file StitchAlg.cxx.

References e, fHT, ftNo, fTrackVec, and pt.

Referenced by CommonComponentStitch(), and WalkStitch().

261 {
262  // take the vector of tracks, walk through each track's vectors of xyz, dxdydz, etc
263  // and concatenate them into longer vectors. Use those to instantiate one new
264  // Stitched-together track.
265  std::vector<recob::tracking::Point_t> xyz;
266  std::vector<recob::tracking::Vector_t> dxdydz;
267  std::vector<recob::tracking::SMatrixSym55> cov;
268  std::vector<recob::TrackTrajectory::PointFlags_t> flgs;
269  //art::PtrVector<recob::Track>::const_iterator
270 
271  bool hasMomentum = true; //true only if all tracks have momentum
272  for (auto it = (*itvvArg).begin(); it != (*itvvArg).end(); ++it) {
273  if ((*it).get()->HasMomentum() == false) {
274  hasMomentum = false;
275  break;
276  }
277  }
278 
279  size_t cnt(0);
280  for (auto it = (*itvvArg).begin(); it != (*itvvArg).end(); ++it) {
281 
282  cnt++;
283  // std::cout << "Stitching track cnt is: " << cnt << std::endl;
284  for (size_t pt = 0; pt != (*it).get()->NumberTrajectoryPoints(); pt++) {
285  size_t ptHere(pt);
286  // ask if 1st character of 2-character string is an H. If so, reverse order
287  // of the concatenation. Note however that I've had my notion of head & tail backwards
288  // throughout this whole class! start1, end1 are really T, H, not H, T as I've labeled 'em till now.
289  // hence flip the direction if this character is a T/H, when expecting H/T! -- EC, 29-June-2014.
290 
291  auto itvfHT = fHT.begin() + size_t(itvArg - fTrackVec.begin());
292  if ((*itvfHT).size() && (
293  // was fHT.back()
294  (cnt == 1 && !(*itvfHT).at(cnt - 1).compare(0, 1, "H")) ||
295  (cnt > 1 && !(*itvfHT).at(cnt - 2).compare(1, 1, "T"))))
296  ptHere = (*it).get()->NumberTrajectoryPoints() - pt - 1;
297 
298  try {
299  xyz.push_back((*it).get()->LocationAtPoint(ptHere));
300  // std::cout << "Stitching track number " << cnt << " with TrajPt at ptHere " << ptHere << " at x,y,z: " << xyz.back().X() << ", " << xyz.back().Y() << ", " << xyz.back().Z() << std::endl;
301  dxdydz.push_back((hasMomentum ? (*it).get()->MomentumVectorAtPoint(ptHere) :
302  (*it).get()->DirectionAtPoint(ptHere)));
303  flgs.push_back((*it).get()->FlagsAtPoint(ptHere));
304  cov.push_back(
305  (ptHere == 0 ? (*it).get()->VertexCovariance() : (*it).get()->EndCovariance()));
306  }
307  catch (cet::exception& e) {
308  mf::LogVerbatim("TrackStitcher bailing. ")
309  << " One or more of xyz, dxdydz, cov, mom, dQdx elements from original Track is out of "
310  "range..."
311  << e.what() << __LINE__;
312  break;
313  }
314  }
315  }
316 
320 
321  //const recob::Track t(xyz,dxdydz,cov,dQdx,mom,ftNo++);
322  const recob::Track t(
323  recob::TrackTrajectory(std::move(xyz), std::move(dxdydz), std::move(flgs), hasMomentum),
324  0,
325  -1.,
326  0,
327  cov.front(),
328  cov.back(),
329  ftNo++);
330  //const art::Ptr<recob::Track> t(xyz,dxdydz,cov,dQdx,mom,ftNo++);
331  fTrackVec.insert(itvArg, t);
332 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::vector< recob::Track > fTrackVec
Definition: StitchAlg.h:59
A trajectory in space reconstructed from hits.
TMarker * pt
Definition: egs.C:25
std::vector< std::vector< std::string > > fHT
Definition: StitchAlg.h:60
Float_t e
Definition: plot.C:35
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void trkf::StitchAlg::GetTrackComposites ( std::vector< art::PtrVector< recob::Track >> &  c) const
inline

Definition at line 43 of file StitchAlg.h.

Referenced by trkf::TrackStitcher::produce().

44  {
45  c = fTrackComposite;
46  }
std::vector< art::PtrVector< recob::Track > > fTrackComposite
Definition: StitchAlg.h:58
void trkf::StitchAlg::GetTracks ( std::vector< recob::Track > &  t) const
inline

Definition at line 47 of file StitchAlg.h.

Referenced by trkf::TrackStitcher::produce().

47 { t = fTrackVec; }
std::vector< recob::Track > fTrackVec
Definition: StitchAlg.h:59
void trkf::StitchAlg::reconfigure ( fhicl::ParameterSet const &  pset)

Definition at line 36 of file StitchAlg.cxx.

References fCosAngTol, fSepTol, and fhicl::ParameterSet::get().

Referenced by StitchAlg().

37 {
38 
39  fCosAngTol = pset.get<double>("CosAngTolerance", 0.95);
40  fSepTol = pset.get<double>("SpptSepTolerance", 10.0); //cm
41 }
double fSepTol
Definition: StitchAlg.h:56
double fCosAngTol
Definition: StitchAlg.h:55
void trkf::StitchAlg::WalkStitch ( )

Definition at line 334 of file StitchAlg.cxx.

References art::PtrVector< T >::begin(), art::PtrVector< T >::clear(), art::PtrVector< T >::end(), art::PtrVector< T >::erase(), fh, fHT, FirstStitch(), ft, ftListHandle, fTrackComposite, fTrackVec, art::PtrVector< T >::insert(), art::PtrVector< T >::push_back(), and art::PtrVector< T >::size().

Referenced by trkf::TrackStitcher::produce().

335 {
336 
338  std::vector<std::string> trackStatus(fh.size(), "NotDone"); // H or T
339  std::vector<std::string> HT2; // H or T
340 
341  for (unsigned int ii = 0; ii < fh.size(); ++ii) // same as t.size()
342 
343  {
344  if (!trackStatus.at(ii).compare("Done")) continue;
345 
346  const art::Ptr<recob::Track> th(ftListHandle, ii);
347  compTrack.push_back(th);
348  // Should there not be an HT.push_back here??
349 
350  // start with track 1: see if head goes anywhere, walk with it. Add to compTrack.
351  // Go until the other tuple's other vtx string says "NA." Then change status string
352  // of vtxsJoined to "Done" for that track.
353  bool chain(true);
354  int walk(ii);
355  std::string sh(std::get<0>(fh.at(walk)));
356  std::string st("NA");
357  while (chain) {
358  int hInd = -12;
359  int tInd = -12;
360  if (walk != (int)ii) {
361  sh = std::get<0>(fh.at(walk));
362  st = std::get<0>(ft.at(walk));
363  }
364 
365  // std::cout << "StichAlg::WalkStitch(): Inside head chain. walk(track), sh, st, " << walk << ", " << sh << ", "<<st <<", connected to tracks: " << std::get<2>(fh.at(walk))<<", " << std::get<2>(ft.at(walk)) <<std::endl;
366  if (!sh.compare("H") || !sh.compare("T")) {
367 
368  hInd = std::get<2>(fh.at(walk)); // index of track that walk is connected to.
369  // std::cout << "WalkStitch(): hInd is " << hInd << std::endl;
370 
371  const art::Ptr<recob::Track> th2(ftListHandle, hInd);
372  compTrack.push_back(th2);
373  HT2.push_back("H" + sh);
374  }
375 
376  if ((!st.compare("H") || !st.compare("T"))) {
377  tInd = std::get<2>(ft.at(walk));
378  // std::cout << "WalkStitch(): tInd is " << tInd << std::endl;
379  const art::Ptr<recob::Track> th2(ftListHandle, tInd);
380  compTrack.push_back(th2);
381  HT2.push_back("T" + st); // since we will eventually read from 0th element forward
382  }
383  if (hInd != -12) walk = hInd;
384  if (tInd != -12) walk = tInd;
385  if (!sh.compare("NA") && !st.compare("NA")) chain = false;
386 
387  trackStatus.at(walk) = "Done";
388  } // while
389 
390  // It is possible that our first (ii'th) track had a head _and_ a tail match. Thus, we must
391  // see if tail goes anywhere. walk with it. Insert, don't push_back, to compTrack.
392  chain = true;
393  walk = ii;
394  sh = "NA";
395  st = std::get<0>(ft.at(walk));
396  while (chain) {
397  int hInd = -12;
398  int tInd = -12;
399  if (walk != (int)ii) {
400  sh = std::get<0>(fh.at(walk));
401  st = std::get<0>(ft.at(walk));
402  }
403 
404  // std::cout << "StichAlg::WalkStitch(): Inside tail chain. walk(track), sh, st, " << walk << ", " << sh << ", "<<st <<", connected to tracks: " << std::get<2>(fh.at(walk))<<", " << std::get<2>(ft.at(walk)) <<std::endl;
405  if (!sh.compare("H") || !sh.compare("T")) {
406 
407  hInd = std::get<2>(fh.at(walk)); // index of track that walk is connected to.
408  // std::cout << "WalkStitch(): hInd is " << hInd << std::endl;
409 
410  const art::Ptr<recob::Track> th2(ftListHandle, hInd);
411  compTrack.insert(compTrack.begin(), th2);
412  HT2.insert(HT2.begin(), sh + "H");
413  }
414 
415  if ((!st.compare("H") || !st.compare("T"))) {
416  tInd = std::get<2>(ft.at(walk));
417  // std::cout << "WalkStitch(): tInd is " << tInd << std::endl;
418  const art::Ptr<recob::Track> th2(ftListHandle, tInd);
419  compTrack.insert(compTrack.begin(), th2);
420  HT2.insert(HT2.begin(), st + "T"); // since we will eventually read from 0th element forward
421  }
422  if (hInd != -12) walk = hInd;
423  if (tInd != -12) walk = tInd;
424  if (!sh.compare("NA") && !st.compare("NA")) chain = false;
425 
426  trackStatus.at(walk) = "Done";
427  } // while
428 
429  // inside FirstStitch() push_back onto the vec<vec> of components and the vec of stitched composite.
430  if (compTrack.size()) {
431  // protect against stitching a component twice, as when somehow the same track has been matched to a
432  // head and a tail of another track. remove the repeat appearances of that track.
433  for (auto iit = compTrack.begin(); iit != compTrack.end(); ++iit) {
434  int cjit(0);
435  for (auto jit = iit + 1; jit != compTrack.end(); ++jit) {
436  // std::cout<< " cjit is ." << cjit << std::endl;
437  if (*iit == *jit) {
438  // std::cout<< " About to do cjit erase." << std::endl;
439  compTrack.erase(jit); //std::cout<< "Survived the compTrack jit erase." << std::endl;
440  HT2.erase(HT2.begin() +
441  cjit); //std::cout<< "Survived the HT2 cjit erase." << std::endl;
442  break;
443  }
444  cjit++;
445  }
446  }
447  fTrackComposite.push_back(compTrack);
448  fHT.push_back(HT2);
449  // std::cout << "WalkStitch:: calling FirstStitch(). fTrackComposite.size(), fHT.size() " << fTrackComposite.size()<< ", " << fHT.size() << std::endl;
450  //std::cout << "WalkStitch:: calling FirstStitch(). fTrackComposite.back().size(), fHT.back().size() " << fTrackComposite.back().size()<< ", " << fHT.back().size() << std::endl;
451  /*
452  for (unsigned int ll=0; ll<fHT.back().size() ; ++ll)
453  {
454  std::cout << fHT.back().at(ll); std::cout << ", ";
455  }
456  std::cout << "." << std::endl;
457  */
458  // want the last vector of fTrackComposite, and will want to insert on fTrackVec, hence
459  // -1 and not -1, respectively.
460  FirstStitch(fTrackComposite.end() - 1, fTrackVec.end());
461  }
462  compTrack.clear();
463  HT2.clear();
464 
465  } // end ii loop on head/tail vector of tuples.
466 }
art::Handle< std::vector< recob::Track > > ftListHandle
Definition: StitchAlg.h:49
std::vector< recob::Track > fTrackVec
Definition: StitchAlg.h:59
std::vector< std::tuple< std::string, int, int, double, double > > fh
Definition: StitchAlg.h:52
iterator begin()
Definition: PtrVector.h:217
iterator erase(iterator position)
Definition: PtrVector.h:504
void FirstStitch(const std::vector< art::PtrVector< recob::Track >>::iterator itvvArg, const std::vector< recob::Track >::iterator itvArg)
Definition: StitchAlg.cxx:259
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
iterator end()
Definition: PtrVector.h:231
size_type size() const
Definition: PtrVector.h:302
iterator insert(iterator position, Ptr< U > const &p)
std::vector< art::PtrVector< recob::Track > > fTrackComposite
Definition: StitchAlg.h:58
std::vector< std::vector< std::string > > fHT
Definition: StitchAlg.h:60
void clear()
Definition: PtrVector.h:533
std::vector< std::tuple< std::string, int, int, double, double > > ft
Definition: StitchAlg.h:53

Member Data Documentation

double trkf::StitchAlg::fCosAngTol
private

Definition at line 55 of file StitchAlg.h.

Referenced by FindHeadsAndTails(), and reconfigure().

std::vector<std::tuple<std::string, int, int, double, double> > trkf::StitchAlg::fh
private

Definition at line 52 of file StitchAlg.h.

Referenced by FindHeadsAndTails(), and WalkStitch().

std::vector<std::vector<std::string> > trkf::StitchAlg::fHT
private

Definition at line 60 of file StitchAlg.h.

Referenced by CommonComponentStitch(), FindHeadsAndTails(), FirstStitch(), and WalkStitch().

double trkf::StitchAlg::fSepTol
private

Definition at line 56 of file StitchAlg.h.

Referenced by FindHeadsAndTails(), and reconfigure().

std::vector<std::tuple<std::string, int, int, double, double> > trkf::StitchAlg::ft
private

Definition at line 53 of file StitchAlg.h.

Referenced by FindHeadsAndTails(), and WalkStitch().

art::Handle<std::vector<recob::Track> > trkf::StitchAlg::ftListHandle

Definition at line 49 of file StitchAlg.h.

Referenced by FindHeadsAndTails(), trkf::TrackStitcher::produce(), StitchAlg(), and WalkStitch().

int trkf::StitchAlg::ftNo
private

Definition at line 54 of file StitchAlg.h.

Referenced by FirstStitch(), and StitchAlg().

std::vector<art::PtrVector<recob::Track> > trkf::StitchAlg::fTrackComposite
private

Definition at line 58 of file StitchAlg.h.

Referenced by CommonComponentStitch(), FindHeadsAndTails(), and WalkStitch().

std::vector<recob::Track> trkf::StitchAlg::fTrackVec
private

Definition at line 59 of file StitchAlg.h.

Referenced by CommonComponentStitch(), FindHeadsAndTails(), FirstStitch(), and WalkStitch().


The documentation for this class was generated from the following files: