All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
trkf::TrackStitcher Class Reference
Inheritance diagram for trkf::TrackStitcher:

Public Member Functions

 TrackStitcher (fhicl::ParameterSet const &pset)
 

Private Member Functions

void produce (art::Event &evt) override
 
art::PtrVector< recob::HitGetHitsFromComponentTracks (const art::PtrVector< recob::Track > &, const art::Event &evt)
 
art::PtrVector< recob::SpacePointGetSpacePointsFromComponentTracks (const art::PtrVector< recob::Track > &, const art::Event &evt)
 
std::vector< art::Ptr
< recob::Hit > > 
GetHitsFromAssdSpacePoints (const art::PtrVector< recob::SpacePoint > &, const art::Event &evt, std::vector< std::pair< std::vector< art::Ptr< recob::Hit > >::const_iterator, std::vector< art::Ptr< recob::Hit > >::const_iterator > > &vpi)
 

Private Attributes

std::string fTrackModuleLabel
 
std::string fSpptModuleLabel
 
bool fStizatch
 
StitchAlg fStitchAlg
 

Detailed Description

Definition at line 41 of file TrackStitcher_module.cc.

Constructor & Destructor Documentation

trkf::TrackStitcher::TrackStitcher ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 63 of file TrackStitcher_module.cc.

63  :
64  EDProducer{pset},
65  fStitchAlg(pset.get< fhicl::ParameterSet >("StitchAlg"))
66  {
67  fTrackModuleLabel = pset.get< std::string >("TrackModuleLabel");
68  fSpptModuleLabel = pset.get< std::string >("SpptModuleLabel");
69  fStizatch = pset.get< bool > ("CommonComponentStitch",true);
70 
71  produces< std::vector<recob::Track> >();
72  produces<std::vector<art::PtrVector<recob::Track> > >();
73  produces<art::Assns<recob::Track, recob::Hit> >();
74  produces<art::Assns<recob::Track, recob::SpacePoint> >();
75  produces<art::Assns<recob::SpacePoint, recob::Hit> >();
76 
77  }

Member Function Documentation

std::vector< art::Ptr< recob::Hit > > trkf::TrackStitcher::GetHitsFromAssdSpacePoints ( const art::PtrVector< recob::SpacePoint > &  sppts,
const art::Event &  evt,
std::vector< std::pair< std::vector< art::Ptr< recob::Hit > >::const_iterator, std::vector< art::Ptr< recob::Hit > >::const_iterator > > &  vpi 
)
private

Definition at line 247 of file TrackStitcher_module.cc.

248  {
249 
250  std::vector<art::Ptr<recob::Hit>> hits;
251  art::FindManyP<recob::Hit> hitAssns(sppts, evtGHFCT, fSpptModuleLabel);
252 
253  size_t start(0), finish(0);
254  for (unsigned int ii=0; ii < sppts.size(); ++ii )
255  {
256  hits.insert(hits.end(),hitAssns.at(ii).begin(), hitAssns.at(ii).end());
257  finish = start+(size_t)(hitAssns.at(ii).end() - hitAssns.at(ii).begin());
258  std::pair< std::vector<art::Ptr<recob::Hit> >::const_iterator, std::vector<art::Ptr<recob::Hit> >::const_iterator > pithittmp(hitAssns.at(ii).begin(),hitAssns.at(ii).end());
259  pithit.push_back(pithittmp);
260  start += (finish+1);
261  }
262 
263  return hits;
264  }
art::PtrVector< recob::Hit > trkf::TrackStitcher::GetHitsFromComponentTracks ( const art::PtrVector< recob::Track > &  tcomp,
const art::Event &  evt 
)
private

Definition at line 217 of file TrackStitcher_module.cc.

218  {
219 
220  art::PtrVector<recob::Hit> hits;
221  art::FindManyP<recob::Hit> hitAssns(tcomp, evtGHFCT, fTrackModuleLabel);
222 
223  for (unsigned int ii=0; ii < tcomp.size(); ++ii )
224  {
225  hits.insert(hits.end(),hitAssns.at(ii).begin(), hitAssns.at(ii).end());
226  }
227 
228 
229  // const art::PtrVector<recob::Hit> chits(hits);
230  return hits;
231  }
art::PtrVector< recob::SpacePoint > trkf::TrackStitcher::GetSpacePointsFromComponentTracks ( const art::PtrVector< recob::Track > &  tcomp,
const art::Event &  evt 
)
private

Definition at line 233 of file TrackStitcher_module.cc.

234  {
235 
236  art::PtrVector<recob::SpacePoint> sppts;
237  art::FindManyP<recob::SpacePoint> spptAssns(tcomp, evtGHFCT, fTrackModuleLabel);
238  for (unsigned int ii=0; ii < tcomp.size(); ++ii )
239  {
240  sppts.insert(sppts.end(),spptAssns.at(ii).begin(), spptAssns.at(ii).end());
241  }
242 
243  // const art::PtrVector<recob::Hit> chits(hits);
244  return sppts;
245  }
void trkf::TrackStitcher::produce ( art::Event &  evt)
overrideprivate

Definition at line 80 of file TrackStitcher_module.cc.

81  {
82 
83  // get services
84  art::ServiceHandle<geo::Geometry const> geom;
85 
86  //////////////////////////////////////////////////////
87  // Make a std::unique_ptr<> for the thing you want to put into the event
88  //////////////////////////////////////////////////////
89  // tcol is the collection of new tracks
90  std::unique_ptr<std::vector<recob::Track> > tcol(new std::vector<recob::Track>);
91  std::unique_ptr<art::PtrVector<recob::SpacePoint> > scol(new art::PtrVector<recob::SpacePoint>);
92  // tvcol is the collection of vectors that comprise each tcol
93  std::unique_ptr<std::vector< art::PtrVector<recob::Track> > > tvcol(new std::vector< art::PtrVector<recob::Track> >);
94  std::unique_ptr< art::Assns<recob::Track, recob::Hit> > thassn(new art::Assns<recob::Track, recob::Hit>);
95  std::unique_ptr< art::Assns<recob::Track, recob::SpacePoint> > tsptassn(new art::Assns<recob::Track, recob::SpacePoint>);
96  std::unique_ptr< art::Assns<recob::SpacePoint, recob::Hit > > spthassn(new art::Assns<recob::SpacePoint, recob::Hit>);
97 
98 
99  // Get the original Spacepoints. Trackers other than CosmicTracker wrote the
100  // SpacePoints as a PtrVec of vecs. If they look like that, flatten into one vec.
101 
102  art::Handle< std::vector < recob::SpacePoint > > sppth;
103  try
104  {
105  mf::LogWarning("TrackStitcher") << "Trying to read Track3DKalmanXYZ-style PtrVector of std::vector of SpacePoints" << std::endl;
106  art::Handle< std::vector < art::PtrVector <recob::SpacePoint> > > sppth;
107  evt.getByLabel(fSpptModuleLabel, sppth);
108  for (size_t ii=0; ii<sppth->size() ;ii++)
109  for (size_t jj=0; jj<sppth->at(ii).size() ;ii++)
110  {
111  art::Ptr<recob::SpacePoint> sptmp(sppth->at(ii).at(jj));
112  scol->push_back(sptmp );
113  }
114  }
115  catch(...)
116  {
117  mf::LogWarning("TrackStitcher") << "Trying instead to read CosmicTracker-style already-flattened vector of SpacePoints" << std::endl;
118  art::Handle< std::vector < recob::SpacePoint > > sppthf;
119  evt.getByLabel(fSpptModuleLabel, sppthf);
120  for (size_t ii=0; ii<sppthf->size() ;ii++)
121  {
122  art::Ptr<recob::SpacePoint> sptmpf(sppthf,ii);
123  scol->push_back(sptmpf);
124  }
125 
126  }
127 
128 
129  // Find the best match for each track's Head and Tail.
131  // walk through each vertex of one track to its match on another, and so on and stitch 'em.
133  // search composite tracks and stitch further if there are components in common. Do it until all are stitched.
134  bool stizatch(fStizatch);
135  while (stizatch)
136  {
137  stizatch = fStitchAlg.CommonComponentStitch();
138  }
139  mf::LogVerbatim("TrackStitcher.beginning") << "There are " << fStitchAlg.ftListHandle->size() << " Tracks in this event before stitching.";
140 
141  fStitchAlg.GetTracks(*tcol);
143 
144  if (tcol->size()!=tvcol->size())
145  throw cet::exception("TrackStitcher") << "Tracks and TrackComposites do not match: "<<tcol->size()<<" vs "<<tvcol->size()<<"\n";
146 
147  std::vector<size_t> spIndices(scol->size());
148  // create spIndices, index array for searching into original scol SpacePoints.
149  for ( size_t ii=0; ii<scol->size(); ii++ )
150  {spIndices[ii]=ii;}
151 
152  for (size_t ii=0; ii<tvcol->size(); ii++)
153  {
154  const art::PtrVector<recob::Hit>& hits(GetHitsFromComponentTracks(tvcol->at(ii), evt));
155  // Now make the Assns of relevant Hits to stitched Track
156  util::CreateAssn(*this, evt, *tcol, hits, *thassn, ii);
157  const art::PtrVector<recob::SpacePoint>& sppts(GetSpacePointsFromComponentTracks(tvcol->at(ii), evt));
158  // Now make the Assns of relevant Sppts to stitched Track
159  util::CreateAssn(*this, evt, *tcol, sppts, *tsptassn, ii);
160 
161  // Now Assns of sppts to hits. For this Sppt
162  // I call the function to bring back the vec of associated Hits and the vector of
163  // pairs of iterators that allow to pull those Hits needed from each Sppt.
164  std::vector<std::pair<std::vector<art::Ptr<recob::Hit> >::const_iterator, std::vector<art::Ptr<recob::Hit> >::const_iterator > > pits;
165 
166  std::vector<art::Ptr<recob::Hit>> hitsFromSppts;
167  art::FindManyP<recob::Hit> hitAssns(sppts, evt, fSpptModuleLabel);
168 
169  size_t start(0), finish(0);
170  for (unsigned int ii=0; ii < sppts.size(); ++ii )
171  {
172  hitsFromSppts.insert(hitsFromSppts.end(),hitAssns.at(ii).begin(), hitAssns.at(ii).end());
173  finish = start+(size_t)(hitAssns.at(ii).end() - hitAssns.at(ii).begin());
174  std::pair< std::vector<art::Ptr<recob::Hit> >::const_iterator, std::vector<art::Ptr<recob::Hit> >::const_iterator > pithittmp(hitAssns.at(ii).begin(),hitAssns.at(ii).end());
175  pits.push_back(pithittmp);
176  start += (finish+1);
177  }
178  // std::cout << "TrackStitcher_module: scol->size() is " << scol->size() << std::endl;
179  // std::cout << "TrackStitcher_module: sppts.size() is " << sppts.size() << std::endl;
180  for ( size_t jj=0; jj<sppts.size(); jj++ )
181  {
182  // find jjth sppt in the list of scol. Meaning, find kkth element of sppth.
183  size_t ll(scol->size());
184  // this gives indices into the vector of original spacepoints in which
185  // to look for our sppts.
186  size_t off(0);
187  for ( auto& kk : spIndices )
188  {
189  const art::Ptr<recob::SpacePoint> spptnc(scol->at(kk));
190  if ( spptnc != sppts.at(jj)) { off++; continue;}
191  ll = kk;
192  // std::cout << "TrackStitcher_module: index into spacepoints for which to write out sppt-hit Assns is " << ll << std::endl;
193  // drop this one for future searches, since we've used it.
194 
195  break;
196  }
197  if (ll<scol->size())
198  {
199  std::vector <art::Ptr <recob::Hit> > hitsThisSppt;
200  hitsThisSppt.insert(hitsThisSppt.begin(),pits.at(jj).first,pits.at(jj).second);
201  util::CreateAssn(*this, evt, scol->at(ll), hitsThisSppt, *spthassn);
202  }
203  }
204  }
205 
206 
207  mf::LogVerbatim("TrackStitcher.end") << "There are " << tvcol->size() << " Tracks in this event after stitching.";
208  evt.put(std::move(tcol));
209  evt.put(std::move(tvcol));
210  // Add Hit-to-Track and Sppt-to-Track Assns.
211  evt.put(std::move(thassn));
212  evt.put(std::move(tsptassn));
213  evt.put(std::move(spthassn));
214 
215  }
void GetTracks(std::vector< recob::Track > &t) const
Definition: StitchAlg.h:43
art::Handle< std::vector< recob::Track > > ftListHandle
Definition: StitchAlg.h:45
void FindHeadsAndTails(const art::Event &e, const std::string &t)
Definition: StitchAlg.cxx:45
bool CommonComponentStitch()
Definition: StitchAlg.cxx:478
art::PtrVector< recob::Hit > GetHitsFromComponentTracks(const art::PtrVector< recob::Track > &, const art::Event &evt)
void GetTrackComposites(std::vector< art::PtrVector< recob::Track > > &c) const
Definition: StitchAlg.h:42
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
art::PtrVector< recob::SpacePoint > GetSpacePointsFromComponentTracks(const art::PtrVector< recob::Track > &, const art::Event &evt)
TCEvent evt
Definition: DataStructs.cxx:8

Member Data Documentation

std::string trkf::TrackStitcher::fSpptModuleLabel
private

Definition at line 52 of file TrackStitcher_module.cc.

StitchAlg trkf::TrackStitcher::fStitchAlg
private

Definition at line 54 of file TrackStitcher_module.cc.

bool trkf::TrackStitcher::fStizatch
private

Definition at line 53 of file TrackStitcher_module.cc.

std::string trkf::TrackStitcher::fTrackModuleLabel
private

Definition at line 51 of file TrackStitcher_module.cc.


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