Public Member Functions | Private Member Functions | Private Attributes | List of all members
trkf::TrackStitcher Class Reference
Inheritance diagram for trkf::TrackStitcher:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 TrackStitcher (fhicl::ParameterSet const &pset)
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

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
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

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  }
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20

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  }
intermediate_table::const_iterator const_iterator
size_type size() const
Definition: PtrVector.h:302
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 
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  }
iterator end()
Definition: PtrVector.h:231
size_type size() const
Definition: PtrVector.h:302
iterator insert(iterator position, Ptr< U > const &p)
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 
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  }
iterator end()
Definition: PtrVector.h:231
size_type size() const
Definition: PtrVector.h:302
iterator insert(iterator position, Ptr< U > const &p)
void trkf::TrackStitcher::produce ( art::Event evt)
overrideprivatevirtual

Implements art::EDProducer.

Definition at line 80 of file TrackStitcher_module.cc.

81  {
82 
83  // get services
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 
103  try
104  {
105  mf::LogWarning("TrackStitcher") << "Trying to read Track3DKalmanXYZ-style PtrVector of std::vector of SpacePoints" << std::endl;
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;
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);
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  }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
void GetTracks(std::vector< recob::Track > &t) const
Definition: StitchAlg.h:41
art::Handle< std::vector< recob::Track > > ftListHandle
Definition: StitchAlg.h:43
void FindHeadsAndTails(const art::Event &e, const std::string &t)
Definition: StitchAlg.cxx:45
bool CommonComponentStitch()
Definition: StitchAlg.cxx:478
struct vector vector
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:40
intermediate_table::const_iterator const_iterator
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
def move(depos, offset)
Definition: depos.py:107
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
art::PtrVector< recob::SpacePoint > GetSpacePointsFromComponentTracks(const art::PtrVector< recob::Track > &, const art::Event &evt)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
TCEvent evt
Definition: DataStructs.cxx:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)

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: