LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
trkf::StitchAlg Class Reference

#include "StitchAlg.h"

Public Member Functions

 StitchAlg (fhicl::ParameterSet const &pset)
 
virtual ~StitchAlg ()
 
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)
 
void GetTracks (std::vector< recob::Track > &t)
 

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 27 of file StitchAlg.h.

Constructor & Destructor Documentation

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

Definition at line 36 of file StitchAlg.cxx.

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

37 {
38  ftNo = 0;
40  this->reconfigure(pset);
41 }
art::Handle< std::vector< recob::Track > > ftListHandle
Definition: StitchAlg.h:43
void reconfigure(fhicl::ParameterSet const &pset)
Definition: StitchAlg.cxx:46
void clear()
Definition: Handle.h:237
virtual trkf::StitchAlg::~StitchAlg ( )
inlinevirtual

Definition at line 33 of file StitchAlg.h.

References e, and lar::dump::vector().

33 {};

Member Function Documentation

bool trkf::StitchAlg::CommonComponentStitch ( )

Definition at line 488 of file StitchAlg.cxx.

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

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

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

Definition at line 54 of file StitchAlg.cxx.

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

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

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

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

Referenced by CommonComponentStitch(), and WalkStitch().

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

Definition at line 42 of file StitchAlg.h.

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

42 { c = fTrackComposite;};
std::vector< art::PtrVector< recob::Track > > fTrackComposite
Definition: StitchAlg.h:56
void trkf::StitchAlg::GetTracks ( std::vector< recob::Track > &  t)
inline

Definition at line 43 of file StitchAlg.h.

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

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

Definition at line 46 of file StitchAlg.cxx.

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

Referenced by trkf::TrackStitcher::reconfigure(), and StitchAlg().

47 {
48 
49  fCosAngTol = pset.get< double >("CosAngTolerance", 0.95);
50  fSepTol = pset.get< double >("SpptSepTolerance", 10.0); //cm
51 }
double fSepTol
Definition: StitchAlg.h:53
double fCosAngTol
Definition: StitchAlg.h:52
void trkf::StitchAlg::WalkStitch ( )

Definition at line 333 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().

334 {
335 
337  std::vector <std::string> trackStatus (fh.size(),"NotDone"); // H or T
338  std::vector <std::string> HT2 ; // H or T
339 
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  {
359  int hInd = -12;
360  int tInd = -12;
361  if (walk!=(int)ii)
362  {
363  sh = std::get<0>(fh.at(walk));
364  st = std::get<0>(ft.at(walk));
365  }
366 
367  // 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;
368  if (!sh.compare("H") || !sh.compare("T"))
369  {
370 
371  hInd = std::get<2>(fh.at(walk)); // index of track that walk is connected to.
372  // std::cout << "WalkStitch(): hInd is " << hInd << std::endl;
373 
374  const art::Ptr<recob::Track> th2( ftListHandle, hInd );
375  compTrack.push_back(th2);
376  HT2.push_back("H"+sh);
377  }
378 
379  if ((!st.compare("H") || !st.compare("T")))
380  {
381  tInd = std::get<2>(ft.at(walk));
382  // std::cout << "WalkStitch(): tInd is " << tInd << std::endl;
383  const art::Ptr<recob::Track> th2( ftListHandle, tInd );
384  compTrack.push_back(th2);
385  HT2.push_back("T"+st); // since we will eventually read from 0th element forward
386  }
387  if (hInd!=-12) walk = hInd;
388  if (tInd!=-12) walk = tInd;
389  if (!sh.compare("NA") && !st.compare("NA"))
390  chain = false;
391 
392  trackStatus.at(walk) = "Done";
393  } // while
394 
395  // It is possible that our first (ii'th) track had a head _and_ a tail match. Thus, we must
396  // see if tail goes anywhere. walk with it. Insert, don't push_back, to compTrack.
397  chain = true;
398  walk = ii;
399  sh = "NA";
400  st = std::get<0>(ft.at(walk));
401  while (chain)
402  {
403  int hInd = -12;
404  int tInd = -12;
405  if (walk!=(int)ii)
406  {
407  sh = std::get<0>(fh.at(walk));
408  st = std::get<0>(ft.at(walk));
409  }
410 
411  // 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;
412  if (!sh.compare("H") || !sh.compare("T"))
413  {
414 
415  hInd = std::get<2>(fh.at(walk)); // index of track that walk is connected to.
416  // std::cout << "WalkStitch(): hInd is " << hInd << std::endl;
417 
418  const art::Ptr<recob::Track> th2( ftListHandle, hInd );
419  compTrack.insert(compTrack.begin(),th2);
420  HT2.insert(HT2.begin(),sh+"H");
421  }
422 
423  if ((!st.compare("H") || !st.compare("T")))
424  {
425  tInd = std::get<2>(ft.at(walk));
426  // std::cout << "WalkStitch(): tInd is " << tInd << std::endl;
427  const art::Ptr<recob::Track> th2( ftListHandle, tInd );
428  compTrack.insert(compTrack.begin(),th2);
429  HT2.insert(HT2.begin(),st+"T"); // since we will eventually read from 0th element forward
430  }
431  if (hInd!=-12) walk = hInd;
432  if (tInd!=-12) walk = tInd;
433  if (!sh.compare("NA") && !st.compare("NA"))
434  chain = false;
435 
436  trackStatus.at(walk) = "Done";
437  } // while
438 
439 
440  // inside FirstStitch() push_back onto the vec<vec> of components and the vec of stitched composite.
441  if (compTrack.size())
442  {
443  // protect against stitching a component twice, as when somehow the same track has been matched to a
444  // head and a tail of another track. remove the repeat appearances of that track.
445  for (auto iit = compTrack.begin(); iit!=compTrack.end();++iit)
446  {
447  int cjit(0);
448  for (auto jit = iit+1; jit!=compTrack.end();++jit)
449  {
450  // std::cout<< " cjit is ." << cjit << std::endl;
451  if (*iit==*jit)
452  {
453  // std::cout<< " About to do cjit erase." << std::endl;
454  compTrack.erase(jit); //std::cout<< "Survived the compTrack jit erase." << std::endl;
455  HT2.erase(HT2.begin()+cjit); //std::cout<< "Survived the HT2 cjit erase." << std::endl;
456  break;
457  }
458  cjit++;
459  }
460  }
461  fTrackComposite.push_back(compTrack);
462  fHT.push_back(HT2);
463  // std::cout << "WalkStitch:: calling FirstStitch(). fTrackComposite.size(), fHT.size() " << fTrackComposite.size()<< ", " << fHT.size() << std::endl;
464  //std::cout << "WalkStitch:: calling FirstStitch(). fTrackComposite.back().size(), fHT.back().size() " << fTrackComposite.back().size()<< ", " << fHT.back().size() << std::endl;
465  /*
466  for (unsigned int ll=0; ll<fHT.back().size() ; ++ll)
467  {
468  std::cout << fHT.back().at(ll); std::cout << ", ";
469  }
470  std::cout << "." << std::endl;
471  */
472  // want the last vector of fTrackComposite, and will want to insert on fTrackVec, hence
473  // -1 and not -1, respectively.
474  FirstStitch(fTrackComposite.end()-1, fTrackVec.end());
475  }
476  compTrack.clear();
477  HT2.clear();
478 
479 
480  } // end ii loop on head/tail vector of tuples.
481 
482 }
std::vector< std::tuple< std::string, int, int, double, double > > fh
Definition: StitchAlg.h:49
art::Handle< std::vector< recob::Track > > ftListHandle
Definition: StitchAlg.h:43
std::vector< recob::Track > fTrackVec
Definition: StitchAlg.h:57
iterator begin()
Definition: PtrVector.h:223
iterator erase(iterator position)
Definition: PtrVector.h:508
void FirstStitch(const std::vector< art::PtrVector< recob::Track >>::iterator itvvArg, const std::vector< recob::Track >::iterator itvArg)
Definition: StitchAlg.cxx:261
std::vector< std::vector< std::string > > fHT
Definition: StitchAlg.h:58
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
iterator end()
Definition: PtrVector.h:237
size_type size() const
Definition: PtrVector.h:308
iterator insert(iterator position, Ptr< U > const &p)
std::vector< std::tuple< std::string, int, int, double, double > > ft
Definition: StitchAlg.h:50
std::vector< art::PtrVector< recob::Track > > fTrackComposite
Definition: StitchAlg.h:56
void clear()
Definition: PtrVector.h:537

Member Data Documentation

double trkf::StitchAlg::fCosAngTol
private

Definition at line 52 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 49 of file StitchAlg.h.

Referenced by FindHeadsAndTails(), and WalkStitch().

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

Definition at line 58 of file StitchAlg.h.

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

double trkf::StitchAlg::fSepTol
private

Definition at line 53 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 50 of file StitchAlg.h.

Referenced by FindHeadsAndTails(), and WalkStitch().

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

Definition at line 43 of file StitchAlg.h.

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

int trkf::StitchAlg::ftNo
private

Definition at line 51 of file StitchAlg.h.

Referenced by FirstStitch(), and StitchAlg().

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

Definition at line 56 of file StitchAlg.h.

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

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

Definition at line 57 of file StitchAlg.h.

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


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