StitchAlg.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // StitchAlg.cxx
4 //
5 // echurch@fnal.gov
6 //
7 // This alg is called by TrackStich_module.cc in order to stitch together
8 // tracks which point at each other and have gaps to within user-set
9 // tolerances.
10 ////////////////////////////////////////////////////////////////////////
11 
12 
14 
15 // C/C++ standard libraries
16 #include <cmath>
17 #include <cstdlib>
18 #include <vector>
19 
20 //Framework includes:
22 #include "fhiclcpp/ParameterSet.h"
26 
28 {
29  ftNo = 0;
31  this->reconfigure(pset);
32 }
33 
34 //----------------------------------------------------------
35 
36 //----------------------------------------------------------
38 {
39 
40  fCosAngTol = pset.get< double >("CosAngTolerance", 0.95);
41  fSepTol = pset.get< double >("SpptSepTolerance", 10.0); //cm
42 }
43 
44 
45 void trkf::StitchAlg::FindHeadsAndTails( const art::Event& EvtArg, const std::string& trackModuleLabelArg )
46 {
47 
48  fTrackVec.clear();
49  fTrackComposite.clear();
50  fHT.clear();
51 
52  EvtArg.getByLabel(trackModuleLabelArg,ftListHandle);
53 
54  // 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.
55  ft.clear();
56  fh.clear();
57 
58  int ntrack = ftListHandle->size();
59  // std::cout << "StitchAlg.FindHeadsAndTails: Number of tracks in " << ntrack << std::endl;
60  for(int ii = 0; ii < ntrack; ++ii) {
62  const recob::Track& track1 = *ptrack1;
63  const TVector3 start1(track1.Vertex<TVector3>());
64  const TVector3 end1(track1.End<TVector3>());
65  const TVector3 start1Dir(track1.VertexDirection<TVector3>());
66  const TVector3 end1Dir(track1.EndDirection<TVector3>());
67  // 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.
68  std::vector< std::tuple< std::string, int, int, double, double> > headvv;
69  std::vector< std::tuple< std::string, int, int, double, double> > tailvv;
70 
71  // For head/tail keep a vector of candidate (cos,sep)
72  std::vector< std::vector<std::pair< double, double>> > matchhead;
73  std::vector< std::vector<std::pair< double, double>> > matchtail;
74  // Neither end of track1 is yet matched:
75  bool head(false);
76  bool tail(false);
77 
78  for(int jj = ii+1; jj < ntrack; ++jj) {
80  const recob::Track& track2 = *ptrack2;
81  const TVector3& start2(track2.Vertex<TVector3>());
82  const TVector3& end2(track2.End<TVector3>());
83  const TVector3& start2Dir(track2.VertexDirection<TVector3>());
84  const TVector3& end2Dir(track2.EndDirection<TVector3>());
85  std::string sHT2("NA"); // track2 (receptor track) H or T is tagged as matched
86 
87 
88  bool c12((std::abs(start1Dir.Dot(end2Dir))>fCosAngTol) && ((start1-end2).Mag()<fSepTol));
89  bool c21((std::abs(end1Dir.Dot(start2Dir))>fCosAngTol) && ((start2-end1).Mag()<fSepTol));
90  bool c11((std::abs(start1Dir.Dot(start2Dir))>fCosAngTol) && ((start1-start2).Mag()<fSepTol));
91  bool c22((std::abs(end1Dir.Dot(end2Dir))>fCosAngTol) && ((end1-end2).Mag()<fSepTol));
92 
93  if ( c12 || c21 || c11 || c22 )
94  {
95 
96  sHT2 = "NA";
97  if (c12||c11) { head=true; }
98  if (c11) { sHT2 = "H"; } else if (c12) { sHT2 = "T"; }
99  if (c21||c22) { tail=true; }
100  if (c21) { sHT2 = "H"; } else if (c22) { sHT2 = "T"; }
101 
102  if (head && tail) // split the tie by distance
103  {
104  head = false; tail = false;
105  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()) )
106  { head = true; tail = false; }
107  else
108  { head = false; tail = true; }
109  }
110 
111  if (head)
112  {
113  // 2-deep vector, for head and tail of 2nd track
114  std::vector< std::pair <double,double> > headv;
115  headv.push_back(std::pair<double,double>(abs(start1Dir.Dot(start2Dir)), (start1-start2).Mag()) );
116  headv.push_back(std::pair<double,double>(abs(start1Dir.Dot(end2Dir)), (start1-end2).Mag()) );
117 
118  matchhead.push_back( headv );
119  // if inferior, drop the new elements; if superior, replace the old
120  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 )
121  {
122  if (matchhead.size()>1) matchhead.erase(matchhead.begin());
123  if (headvv.size()>1) headvv.erase(headvv.begin());
124  if (!sHT2.compare("H"))
125  {
126  auto tupTmp =std::make_tuple(sHT2,ii,jj,matchhead.back().at(0).first,matchhead.back().at(0).second);
127  headvv.push_back (tupTmp);
128  }
129  else
130  {
131  auto tupTmp = std::make_tuple(sHT2,ii,jj,matchhead.back().at(1).first,matchhead.back().at(1).second);
132  headvv.push_back (tupTmp);
133  }
134  }
135  else
136  matchhead.pop_back();
137 
138 
139 
140  // std::cout << "TrackStitcher: satisfied head. " << std::endl;
141  } // head
142 
143  else if (tail) // else if to prevent same stitching candidate being
144  // allowed at both head and tail
145  {
146  // 2-deep vector, for head and tail of 2nd track
147  std::vector< std::pair <double,double> > tailv;
148  tailv.push_back(std::pair<double,double>( abs(end1Dir.Dot(start2Dir)),(start2-end1).Mag() ) );
149  tailv.push_back(std::pair<double,double>( abs(end1Dir.Dot(end2Dir)),(end1-end2).Mag() ) );
150  matchtail.push_back( tailv );
151  // if inferior, drop the new elements; if superior, replace the old
152  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 )
153  {
154  if (matchtail.size()>1) matchtail.erase(matchtail.begin());
155  if (tailvv.size()>1) tailvv.erase(tailvv.begin());
156  if (!sHT2.compare("T"))
157  {
158  auto tupTmp = std::make_tuple(sHT2,ii,jj,matchtail.back().at(0).first,matchtail.back().at(0).second);
159  tailvv.push_back(tupTmp);
160  }
161  else
162  {
163  auto tupTmp = std::make_tuple(sHT2,ii,jj,matchtail.back().at(1).first,matchtail.back().at(1).second);
164  tailvv.push_back(tupTmp);
165  }
166  }
167  else
168  matchtail.pop_back();
169 
170  // std::cout << "TrackStitcher: satisfied tail. " << std::endl;
171  } //tail
172  /*
173  std::cout << "abs(start1Dir.Dot(end2Dir)) " << std::abs(start1Dir.Dot(end2Dir)) << ", start1-end2.Mag(): " << (start1-end2).Mag() << std::endl;
174  std::cout << "abs(end1Dir.Dot(start2Dir)) " << std::abs(end1Dir.Dot(start2Dir)) << ", start2-end1.Mag(): " << (start2-end1).Mag() << std::endl;
175  std::cout << "abs(start1Dir.Dot(start2Dir)) " << std::abs(start1Dir.Dot(start2Dir)) << ", start1-start2.Mag(): " << (start1-start2).Mag() << std::endl;
176  std::cout << "abs(end1Dir.Dot(end2Dir)) " << std::abs(end1Dir.Dot(end2Dir)) << ", end1-end2.Mag(): " << (end1-end2).Mag() << std::endl;
177  std::cout << "sHT2 " << sHT2 << std::endl;
178  */
179  } // end c11||c12||c21||c22
180 
181  // We've been careful to pick the best jj match for this iith track head and tail.
182  // Now we need to be sure that for the jjth track head/tail we don't have two ii trks.
183  if (headvv.size())
184  {
185  int otrk = std::get<2>(headvv.back()); // jj'th track for this iith trk
186  // H or T of this jj'th trk we're matched to.
187  std::string sotrkht(std::get<0>(headvv.back()));
188  for (int kk=0;kk<ii;++kk)
189  {
190  if (std::get<2>(fh.at(kk)) == otrk && !sotrkht.compare(std::get<0>(fh.at(kk)) ) )
191  {
192  // check matching sep and pick the best one. Either erase this
193  // headvv (and it'll get null settings later below) or null out
194  // the parameters in fh.
195  if (std::get<4>(headvv.back()) < std::get<4>(fh.at(kk)) && std::get<4>(headvv.back())!=0.0)
196  {
197  auto tupTmp2 = std::make_tuple(std::string("NA"),kk,-12,0.0,0.0);
198  fh.at(kk) = tupTmp2;
199  }
200  else if (std::get<4>(headvv.back())!=0.0)
201  {
202  headvv.pop_back();
203  break;
204  }
205  }
206  }
207  }
208  if (tailvv.size())
209  {
210  int otrk = std::get<2>(tailvv.back()); // jj'th track for this iith trk
211  // H or T of this jj'th trk we're matched to.
212  std::string sotrkht(std::get<0>(tailvv.back()));
213  for (int kk=0;kk<ii;++kk)
214  {
215  if (std::get<2>(ft.at(kk)) == otrk && !sotrkht.compare(std::get<0>(ft.at(kk)) ) )
216  {
217  // check matching sep and pick the best one. erase either this
218  // tailvv or null out the parameters in ft.
219  if (std::get<4>(tailvv.back()) < std::get<4>(ft.at(kk)) && std::get<4>(tailvv.back())!=0.0)
220  {
221  auto tupTmp2 = std::make_tuple(std::string("NA"),kk,-12,0.0,0.0);
222  ft.at(kk) = tupTmp2;
223  }
224  else if (std::get<4>(tailvv.back())!=0.0)
225  {
226  tailvv.pop_back();
227  break;
228  }
229  }
230  }
231  }
232 
233 
234  } // jj
235 
236 
237  auto tupTmp2 = std::make_tuple(std::string("NA"),ii,-12,0.0,0.0);
238  // We always have our best 1-element tailvv and headvv for trk o at this point
239  if (!headvv.size()) headvv.push_back(tupTmp2);
240  if (!tailvv.size()) tailvv.push_back(tupTmp2);
241  // std::cout << "StitchAlg::FindHeadsAndTails: headvv, tailvv .get<0> is " << std::get<0>(headvv.back()) << ", " << std::get<0>(tailvv.back()) << std::endl;
242  fh.push_back(headvv.back());
243  ft.push_back(tailvv.back());
244 
245  } // ii
246 
247  // std::cout << "fh.size, ft.size are " << fh.size() << ", " << ft.size() << std::endl;
248 
249 }
250 
252 {
253  // take the vector of tracks, walk through each track's vectors of xyz, dxdydz, etc
254  // and concatenate them into longer vectors. Use those to instantiate one new
255  // Stitched-together track.
256  std::vector<recob::tracking::Point_t> xyz;
257  std::vector<recob::tracking::Vector_t> dxdydz;
258  std::vector<recob::tracking::SMatrixSym55> cov;
259  std::vector<recob::TrackTrajectory::PointFlags_t> flgs;
260  //art::PtrVector<recob::Track>::const_iterator
261 
262  bool hasMomentum = true; //true only if all tracks have momentum
263  for (auto it = (*itvvArg).begin(); it!=(*itvvArg).end(); ++it)
264  {
265  if ((*it).get()->HasMomentum()==false) {
266  hasMomentum = false;
267  break;
268  }
269  }
270 
271  size_t cnt(0);
272  for (auto it = (*itvvArg).begin(); it!=(*itvvArg).end(); ++it)
273  {
274 
275  cnt++;
276  // std::cout << "Stitching track cnt is: " << cnt << std::endl;
277  for (size_t pt = 0; pt!=(*it).get()->NumberTrajectoryPoints(); pt++)
278  {
279  size_t ptHere(pt);
280  // ask if 1st character of 2-character string is an H. If so, reverse order
281  // of the concatenation. Note however that I've had my notion of head & tail backwards
282  // throughout this whole class! start1, end1 are really T, H, not H, T as I've labeled 'em till now.
283  // hence flip the direction if this character is a T/H, when expecting H/T! -- EC, 29-June-2014.
284 
285  auto itvfHT = fHT.begin() + size_t (itvArg - fTrackVec.begin());
286  if ( (*itvfHT).size() &&
287  (
288  // was fHT.back()
289  (cnt==1 && !(*itvfHT).at(cnt-1).compare(0,1,"H")) ||
290  (cnt>1 && !(*itvfHT).at(cnt-2).compare(1,1,"T"))
291  )
292  )
293  ptHere = (*it).get()->NumberTrajectoryPoints() - pt - 1;
294 
295  try
296  {
297  xyz.push_back((*it).get()->LocationAtPoint(ptHere));
298  // 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;
299  dxdydz.push_back( (hasMomentum ? (*it).get()->MomentumVectorAtPoint(ptHere) : (*it).get()->DirectionAtPoint(ptHere)) );
300  flgs.push_back((*it).get()->FlagsAtPoint(ptHere));
301  cov.push_back( (ptHere==0 ? (*it).get()->VertexCovariance() : (*it).get()->EndCovariance()));
302  }
303  catch (cet::exception &e)
304  {
305  mf::LogVerbatim("TrackStitcher bailing. ") << " One or more of xyz, dxdydz, cov, mom, dQdx elements from original Track is out of range..." << e.what() << __LINE__;
306  break;
307  }
308  }
309  }
310 
311  /// TODO: sort according to spacepoint distance separation.
312  /// As is, we're not sure we're not forming a stitched track with a (some)
313  /// jump(s) and a reversal(s) of direction in it.
314 
315  //const recob::Track t(xyz,dxdydz,cov,dQdx,mom,ftNo++);
316  const recob::Track t(recob::TrackTrajectory(std::move(xyz), std::move(dxdydz), std::move(flgs), hasMomentum),
317  0, -1., 0, cov.front(), cov.back(), ftNo++);
318  //const art::Ptr<recob::Track> t(xyz,dxdydz,cov,dQdx,mom,ftNo++);
319  fTrackVec.insert(itvArg,t);
320 
321 }
322 
324 {
325 
327  std::vector <std::string> trackStatus (fh.size(),"NotDone"); // H or T
328  std::vector <std::string> HT2 ; // H or T
329 
330 
331  for (unsigned int ii=0; ii<fh.size(); ++ii) // same as t.size()
332 
333  {
334  if (!trackStatus.at(ii).compare("Done")) continue;
335 
336  const art::Ptr<recob::Track> th(ftListHandle, ii);
337  compTrack.push_back(th);
338  // Should there not be an HT.push_back here??
339 
340  // start with track 1: see if head goes anywhere, walk with it. Add to compTrack.
341  // Go until the other tuple's other vtx string says "NA." Then change status string
342  // of vtxsJoined to "Done" for that track.
343  bool chain(true);
344  int walk(ii);
345  std::string sh(std::get<0>(fh.at(walk)));
346  std::string st("NA");
347  while (chain)
348  {
349  int hInd = -12;
350  int tInd = -12;
351  if (walk!=(int)ii)
352  {
353  sh = std::get<0>(fh.at(walk));
354  st = std::get<0>(ft.at(walk));
355  }
356 
357  // 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;
358  if (!sh.compare("H") || !sh.compare("T"))
359  {
360 
361  hInd = std::get<2>(fh.at(walk)); // index of track that walk is connected to.
362  // std::cout << "WalkStitch(): hInd is " << hInd << std::endl;
363 
364  const art::Ptr<recob::Track> th2( ftListHandle, hInd );
365  compTrack.push_back(th2);
366  HT2.push_back("H"+sh);
367  }
368 
369  if ((!st.compare("H") || !st.compare("T")))
370  {
371  tInd = std::get<2>(ft.at(walk));
372  // std::cout << "WalkStitch(): tInd is " << tInd << std::endl;
373  const art::Ptr<recob::Track> th2( ftListHandle, tInd );
374  compTrack.push_back(th2);
375  HT2.push_back("T"+st); // since we will eventually read from 0th element forward
376  }
377  if (hInd!=-12) walk = hInd;
378  if (tInd!=-12) walk = tInd;
379  if (!sh.compare("NA") && !st.compare("NA"))
380  chain = false;
381 
382  trackStatus.at(walk) = "Done";
383  } // while
384 
385  // It is possible that our first (ii'th) track had a head _and_ a tail match. Thus, we must
386  // see if tail goes anywhere. walk with it. Insert, don't push_back, to compTrack.
387  chain = true;
388  walk = ii;
389  sh = "NA";
390  st = std::get<0>(ft.at(walk));
391  while (chain)
392  {
393  int hInd = -12;
394  int tInd = -12;
395  if (walk!=(int)ii)
396  {
397  sh = std::get<0>(fh.at(walk));
398  st = std::get<0>(ft.at(walk));
399  }
400 
401  // 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;
402  if (!sh.compare("H") || !sh.compare("T"))
403  {
404 
405  hInd = std::get<2>(fh.at(walk)); // index of track that walk is connected to.
406  // std::cout << "WalkStitch(): hInd is " << hInd << std::endl;
407 
408  const art::Ptr<recob::Track> th2( ftListHandle, hInd );
409  compTrack.insert(compTrack.begin(),th2);
410  HT2.insert(HT2.begin(),sh+"H");
411  }
412 
413  if ((!st.compare("H") || !st.compare("T")))
414  {
415  tInd = std::get<2>(ft.at(walk));
416  // std::cout << "WalkStitch(): tInd is " << tInd << std::endl;
417  const art::Ptr<recob::Track> th2( ftListHandle, tInd );
418  compTrack.insert(compTrack.begin(),th2);
419  HT2.insert(HT2.begin(),st+"T"); // since we will eventually read from 0th element forward
420  }
421  if (hInd!=-12) walk = hInd;
422  if (tInd!=-12) walk = tInd;
423  if (!sh.compare("NA") && !st.compare("NA"))
424  chain = false;
425 
426  trackStatus.at(walk) = "Done";
427  } // while
428 
429 
430  // inside FirstStitch() push_back onto the vec<vec> of components and the vec of stitched composite.
431  if (compTrack.size())
432  {
433  // protect against stitching a component twice, as when somehow the same track has been matched to a
434  // head and a tail of another track. remove the repeat appearances of that track.
435  for (auto iit = compTrack.begin(); iit!=compTrack.end();++iit)
436  {
437  int cjit(0);
438  for (auto jit = iit+1; jit!=compTrack.end();++jit)
439  {
440  // std::cout<< " cjit is ." << cjit << std::endl;
441  if (*iit==*jit)
442  {
443  // std::cout<< " About to do cjit erase." << std::endl;
444  compTrack.erase(jit); //std::cout<< "Survived the compTrack jit erase." << std::endl;
445  HT2.erase(HT2.begin()+cjit); //std::cout<< "Survived the HT2 cjit erase." << std::endl;
446  break;
447  }
448  cjit++;
449  }
450  }
451  fTrackComposite.push_back(compTrack);
452  fHT.push_back(HT2);
453  // std::cout << "WalkStitch:: calling FirstStitch(). fTrackComposite.size(), fHT.size() " << fTrackComposite.size()<< ", " << fHT.size() << std::endl;
454  //std::cout << "WalkStitch:: calling FirstStitch(). fTrackComposite.back().size(), fHT.back().size() " << fTrackComposite.back().size()<< ", " << fHT.back().size() << std::endl;
455  /*
456  for (unsigned int ll=0; ll<fHT.back().size() ; ++ll)
457  {
458  std::cout << fHT.back().at(ll); std::cout << ", ";
459  }
460  std::cout << "." << std::endl;
461  */
462  // want the last vector of fTrackComposite, and will want to insert on fTrackVec, hence
463  // -1 and not -1, respectively.
464  FirstStitch(fTrackComposite.end()-1, fTrackVec.end());
465  }
466  compTrack.clear();
467  HT2.clear();
468 
469 
470  } // end ii loop on head/tail vector of tuples.
471 
472 }
473 
474  // This method will join separate composite tracks in which one common component is joined by its head in one
475  // and by its tail in another. This can happen if the common component has a higher track index than either of
476  // the the two it is separately stitched to. e.g., ____(1) -------(4) ___________(3).
477  //
479 {
480  // "os" for outer scope.
481  int osciit(-12), oscjit(-12);
482  std::vector < art::PtrVector<recob::Track> >::iterator osiComposite, osjComposite;
484 
485 
486  bool match(false);
487  int ciit(0);
488  for (auto iit = fTrackComposite.begin(); iit!=fTrackComposite.end()&&!match; ++iit)
489  {
490  ciit++;
491  int cjit(ciit);
492  for (auto jit = iit+1; jit!=fTrackComposite.end()&&!match; ++jit)
493  {
494  cjit++;
495  for (auto iiit = iit->begin(); iiit!=iit->end()&&!match; ++iiit)
496  {
497  for (auto jjit = jit->begin(); jjit!=jit->end()&&!match; ++jjit)
498  {
499  if (*iiit == *jjit) // 2 components from 2 different composites are the same
500  {
501  // head is attached to one trk and tail to another.
502  // std::cout << "StitchAlg::CommonComponentStitch: We have two aggregate tracks that have a common component and need to be further stitched. " << std::endl;
503 
504  match = true;
505  osiComposite = iit;
506  osjComposite = jit;
507  osciit = ciit;
508  oscjit = cjit;
509  osiAgg = iiit;
510  osjAgg = jjit; // yes, unneeded, but we keep it for notational clarity
511 
512  }
513  }
514 
515  }
516  }
517  }
518  if (!match) return match;
519 
520  // Proceed to stitch 'em all together, dropping the one redundant component. Then
521  // erase the first occurence of the composite and the matching aggregate trk.
522 
523 
524  // std::cout << "StitchAlg::CommonComponentStitch: pre erase: " << osiComposite->size() << std::endl;
525  (*osiComposite).erase(osiAgg); // erase redundant component track
526  // do not erase this fHT element, however
527 
528  // std::cout << "StitchAlg::CommonComponentStitch: post erase: " << osiComposite->size() << std::endl;
529  // std::cout << "StitchAlg::CommonComponentStitch: fHT.size(): " << fHT.size() << std::endl;
530 
531  // Next is a loop over all remaining components in osiComposite.
532  // insert the non-redundant osciit tracks onto front (back) of osjit
533  // insert the non-redundant osciit vtx links onto front (back) of fHT.begin()+oscjit-1
534 
535  std::vector< std::vector<std::string> >::iterator siit(fHT.begin()+osciit-1);
536  std::vector< std::vector<std::string> >::iterator sjit(fHT.begin()+oscjit-1);
537  size_t itdiff(osiComposite->end()-osiComposite->begin());
538  if (osjAgg == osjComposite->begin())
539  {
540 
541  // std::cout << "StitchAlg::begin insert starting: " << std::endl;
542  // std::cout << "StitchAlg::CommonComponentStitch: itdiff: " << itdiff << std::endl;
543  //std::cout << "StitchAlg::CommonComponentStitch: osiComposite.end-begin: " << osiComposite->end()-osiComposite->begin()<< std::endl;
544  //std::cout << "StitchAlg::CommonComponentStitch: osjComposite.end-begin: " << osjComposite->end()-osjComposite->begin()<< std::endl;
545  (*osjComposite).insert(osjComposite->begin(),osiComposite->begin(),osiComposite->begin()+itdiff);
546  //std::cout << "StitchAlg::CommonComponentStitch: siit.end-begin: " << siit->end()-siit->begin()<< std::endl;
547  //std::cout << "StitchAlg::CommonComponentStitch: sjit.end-begin: " << sjit->end()-sjit->begin()<< std::endl;
548  (*sjit).insert(sjit->begin(),siit->begin(),siit->begin()+itdiff);
549  //std::cout << "StitchAlg::begin insert done: " << std::endl;
550  }
551  else if (osjAgg == (osjComposite->end()-1))
552  {
553  // std::cout << "StitchAlg::end insert starting: " << std::endl;
554  (*osjComposite).insert(osjComposite->end(),osiComposite->begin(),osiComposite->begin()+itdiff);
555  (*sjit).insert(sjit->end(),siit->begin(),siit->begin()+itdiff);
556  // std::cout << "StitchAlg::end insert done: " << std::endl;
557  }
558 
559  // std::cout << "StitchAlg:: 1: " << std::endl;
560  fTrackVec.erase(fTrackVec.begin()+oscjit-1); // erase old Stitched Track, which we'll recreate now...
561 
562  // std::cout << "StitchAlg:: 2: " << std::endl;
563  FirstStitch(osjComposite,fTrackVec.begin()+oscjit-1); // Create new Stitched Track
564  // fTrackComposite.insert(fTrackComposite.begin()+oscjit-1-1,*osjComposite); // erase old composite Track
565  // std::cout << "StitchAlg:: 3: " << std::endl;
566  fTrackVec.erase(fTrackVec.begin()+osciit-1); // erase old Stitched Track
567  // std::cout << "StitchAlg:: 6: " << std::endl;
568  fTrackComposite.erase(osiComposite); // erase old composite Track
569  // std::cout << "StitchAlg:: 4: " << std::endl;
570  fHT.erase(fHT.begin()+osciit-1); // erase old vec of vtx links
571  // std::cout << "StitchAlg:: 5: " << std::endl;
572 
573  return match;
574 
575 } // end of bool CommonComponentStitch()
std::vector< std::tuple< std::string, int, int, double, double > > fh
Definition: StitchAlg.h:47
intermediate_table::iterator iterator
StitchAlg(fhicl::ParameterSet const &pset)
Definition: StitchAlg.cxx:27
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
typename data_t::iterator iterator
Definition: PtrVector.h:54
art::Handle< std::vector< recob::Track > > ftListHandle
Definition: StitchAlg.h:43
std::vector< recob::Track > fTrackVec
Definition: StitchAlg.h:55
void FindHeadsAndTails(const art::Event &e, const std::string &t)
Definition: StitchAlg.cxx:45
std::string string
Definition: nybbler.cc:12
bool CommonComponentStitch()
Definition: StitchAlg.cxx:478
iterator begin()
Definition: PtrVector.h:217
iterator erase(iterator position)
Definition: PtrVector.h:504
struct vector vector
Vector_t VertexDirection() const
Definition: Track.h:132
void FirstStitch(const std::vector< art::PtrVector< recob::Track >>::iterator itvvArg, const std::vector< recob::Track >::iterator itvArg)
Definition: StitchAlg.cxx:251
T abs(T value)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
std::vector< std::vector< std::string > > fHT
Definition: StitchAlg.h:56
double fSepTol
Definition: StitchAlg.h:51
const double e
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
A trajectory in space reconstructed from hits.
def move(depos, offset)
Definition: depos.py:107
T get(std::string const &key) const
Definition: ParameterSet.h:271
Point_t const & Vertex() const
Definition: Track.h:124
iterator end()
Definition: PtrVector.h:231
def walk(top, topdown=True)
void reconfigure(fhicl::ParameterSet const &pset)
Definition: StitchAlg.cxx:37
size_type size() const
Definition: PtrVector.h:302
double fCosAngTol
Definition: StitchAlg.h:50
iterator insert(iterator position, Ptr< U > const &p)
Vector_t EndDirection() const
Definition: Track.h:133
void clear()
Definition: Handle.h:236
std::vector< std::tuple< std::string, int, int, double, double > > ft
Definition: StitchAlg.h:48
Point_t const & End() const
Definition: Track.h:125
std::vector< art::PtrVector< recob::Track > > fTrackComposite
Definition: StitchAlg.h:54
void clear()
Definition: PtrVector.h:533
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