LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
trkf::CosmicTracker Class Reference
Inheritance diagram for trkf::CosmicTracker:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 CosmicTracker (fhicl::ParameterSet const &pset)
 
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)
 
void fillProductDescriptions ()
 
void registerProducts (ProductDescriptions &productsToRegister)
 
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)
 
std::unique_ptr< Worker > makeWorker (WorkerParams const &wp)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Protected Member Functions

ConsumesCollector & consumesCollector ()
 
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 ()
 

Private Member Functions

void produce (art::Event &evt)
 

Private Attributes

cluster::ClusterMatchTQ fClusterMatch
 
trkf::CosmicTrackerAlg fCTAlg
 
std::string fClusterModuleLabel
 label for input cluster collection More...
 
std::string fSortDir
 sort space points More...
 
bool fStitchTracks
 Stitch tracks from different TPCs. More...
 
double fAngCut
 Angle cut for track merging. More...
 
bool fTrajOnly
 Only use trajectory points from TrackTrajectoryAlg for debugging. More...
 

Detailed Description

Definition at line 200 of file CosmicTracker_module.cc.

Member Typedef Documentation

Definition at line 17 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::detail::Producer::Table = Modifier::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 26 of file Producer.h.

Constructor & Destructor Documentation

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

Definition at line 226 of file CosmicTracker_module.cc.

References fAngCut, fClusterMatch, fClusterModuleLabel, fCTAlg, fSortDir, fStitchTracks, and fTrajOnly.

227  : EDProducer{pset}
228  , fClusterMatch(pset.get<fhicl::ParameterSet>("ClusterMatch"))
229  , fCTAlg(pset.get<fhicl::ParameterSet>("CTAlg"))
230  {
231  fClusterModuleLabel = pset.get<std::string>("ClusterModuleLabel");
232  fSortDir = pset.get<std::string>("SortDirection", "+z");
233  fStitchTracks = pset.get<bool>("StitchTracks");
234  fAngCut = pset.get<double>("AngCut");
235  fTrajOnly = pset.get<bool>("TrajOnly");
236 
237  produces<std::vector<recob::Track>>();
238  produces<std::vector<recob::SpacePoint>>();
239  produces<art::Assns<recob::Track, recob::Cluster>>();
240  produces<art::Assns<recob::Track, recob::SpacePoint>>();
241  produces<art::Assns<recob::SpacePoint, recob::Hit>>();
242  produces<art::Assns<recob::Track, recob::Hit>>();
243  }
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
bool fTrajOnly
Only use trajectory points from TrackTrajectoryAlg for debugging.
trkf::CosmicTrackerAlg fCTAlg
bool fStitchTracks
Stitch tracks from different TPCs.
double fAngCut
Angle cut for track merging.
cluster::ClusterMatchTQ fClusterMatch
std::string fClusterModuleLabel
label for input cluster collection
std::string fSortDir
sort space points

Member Function Documentation

template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::consumes ( InputTag const &  tag)
protectedinherited

Definition at line 61 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumes().

62  {
63  return collector_.consumes<T, BT>(tag);
64  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ProductToken< T > consumes(InputTag const &)
ConsumesCollector & art::ModuleBase::consumesCollector ( )
protectedinherited

Definition at line 57 of file ModuleBase.cc.

References art::ModuleBase::collector_.

58  {
59  return collector_;
60  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename T , BranchType BT>
void art::ModuleBase::consumesMany ( )
protectedinherited

Definition at line 75 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumesMany().

76  {
77  collector_.consumesMany<T, BT>();
78  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::consumesView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::consumesView ( InputTag const &  tag)
inherited

Definition at line 68 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumesView().

69  {
70  return collector_.consumesView<T, BT>(tag);
71  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ViewToken< Element > consumesView(InputTag const &)
void art::detail::Producer::doBeginJob ( SharedResources const &  resources)
inherited

Definition at line 22 of file Producer.cc.

References art::detail::Producer::beginJobWithFrame(), and art::detail::Producer::setupQueues().

23  {
24  setupQueues(resources);
25  ProcessingFrame const frame{ScheduleID{}};
26  beginJobWithFrame(frame);
27  }
virtual void setupQueues(SharedResources const &)=0
virtual void beginJobWithFrame(ProcessingFrame const &)=0
bool art::detail::Producer::doBeginRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited

Definition at line 65 of file Producer.cc.

References art::detail::Producer::beginRunWithFrame(), art::RangeSet::forRun(), art::RunPrincipal::makeRun(), r, art::RunPrincipal::runID(), and art::ModuleContext::scheduleID().

66  {
67  auto r = rp.makeRun(mc, RangeSet::forRun(rp.runID()));
68  ProcessingFrame const frame{mc.scheduleID()};
69  beginRunWithFrame(r, frame);
70  r.commitProducts();
71  return true;
72  }
TRandom r
Definition: spectrum.C:23
virtual void beginRunWithFrame(Run &, ProcessingFrame const &)=0
static RangeSet forRun(RunID)
Definition: RangeSet.cc:51
bool art::detail::Producer::doBeginSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited

Definition at line 85 of file Producer.cc.

References art::detail::Producer::beginSubRunWithFrame(), art::RangeSet::forSubRun(), art::SubRunPrincipal::makeSubRun(), art::ModuleContext::scheduleID(), and art::SubRunPrincipal::subRunID().

86  {
87  auto sr = srp.makeSubRun(mc, RangeSet::forSubRun(srp.subRunID()));
88  ProcessingFrame const frame{mc.scheduleID()};
89  beginSubRunWithFrame(sr, frame);
90  sr.commitProducts();
91  return true;
92  }
virtual void beginSubRunWithFrame(SubRun &, ProcessingFrame const &)=0
static RangeSet forSubRun(SubRunID)
Definition: RangeSet.cc:57
void art::detail::Producer::doEndJob ( )
inherited

Definition at line 30 of file Producer.cc.

References art::detail::Producer::endJobWithFrame().

31  {
32  ProcessingFrame const frame{ScheduleID{}};
33  endJobWithFrame(frame);
34  }
virtual void endJobWithFrame(ProcessingFrame const &)=0
bool art::detail::Producer::doEndRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited

Definition at line 75 of file Producer.cc.

References art::detail::Producer::endRunWithFrame(), art::RunPrincipal::makeRun(), r, art::ModuleContext::scheduleID(), and art::Principal::seenRanges().

76  {
77  auto r = rp.makeRun(mc, rp.seenRanges());
78  ProcessingFrame const frame{mc.scheduleID()};
79  endRunWithFrame(r, frame);
80  r.commitProducts();
81  return true;
82  }
TRandom r
Definition: spectrum.C:23
virtual void endRunWithFrame(Run &, ProcessingFrame const &)=0
bool art::detail::Producer::doEndSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited

Definition at line 95 of file Producer.cc.

References art::detail::Producer::endSubRunWithFrame(), art::SubRunPrincipal::makeSubRun(), art::ModuleContext::scheduleID(), and art::Principal::seenRanges().

96  {
97  auto sr = srp.makeSubRun(mc, srp.seenRanges());
98  ProcessingFrame const frame{mc.scheduleID()};
99  endSubRunWithFrame(sr, frame);
100  sr.commitProducts();
101  return true;
102  }
virtual void endSubRunWithFrame(SubRun &, ProcessingFrame const &)=0
bool art::detail::Producer::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 
)
inherited

Definition at line 105 of file Producer.cc.

References art::detail::Producer::checkPutProducts_, e, art::EventPrincipal::makeEvent(), art::detail::Producer::produceWithFrame(), and art::ModuleContext::scheduleID().

110  {
111  auto e = ep.makeEvent(mc);
112  ++counts_run;
113  ProcessingFrame const frame{mc.scheduleID()};
114  produceWithFrame(e, frame);
115  e.commitProducts(checkPutProducts_, &expectedProducts<InEvent>());
116  ++counts_passed;
117  return true;
118  }
bool const checkPutProducts_
Definition: Producer.h:70
Float_t e
Definition: plot.C:35
virtual void produceWithFrame(Event &, ProcessingFrame const &)=0
void art::detail::Producer::doRespondToCloseInputFile ( FileBlock const &  fb)
inherited

Definition at line 44 of file Producer.cc.

References art::detail::Producer::respondToCloseInputFileWithFrame().

45  {
46  ProcessingFrame const frame{ScheduleID{}};
48  }
virtual void respondToCloseInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToCloseOutputFiles ( FileBlock const &  fb)
inherited

Definition at line 58 of file Producer.cc.

References art::detail::Producer::respondToCloseOutputFilesWithFrame().

59  {
60  ProcessingFrame const frame{ScheduleID{}};
62  }
virtual void respondToCloseOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToOpenInputFile ( FileBlock const &  fb)
inherited

Definition at line 37 of file Producer.cc.

References art::detail::Producer::respondToOpenInputFileWithFrame().

38  {
39  ProcessingFrame const frame{ScheduleID{}};
41  }
virtual void respondToOpenInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToOpenOutputFiles ( FileBlock const &  fb)
inherited

Definition at line 51 of file Producer.cc.

References art::detail::Producer::respondToOpenOutputFilesWithFrame().

52  {
53  ProcessingFrame const frame{ScheduleID{}};
55  }
virtual void respondToOpenOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::Modifier::fillProductDescriptions ( )
inherited

Definition at line 10 of file Modifier.cc.

References art::ProductRegistryHelper::fillDescriptions(), and art::ModuleBase::moduleDescription().

11  {
13  }
void fillDescriptions(ModuleDescription const &md)
ModuleDescription const & moduleDescription() const
Definition: ModuleBase.cc:13
std::array< std::vector< ProductInfo >, NumBranchTypes > const & art::ModuleBase::getConsumables ( ) const
inherited

Definition at line 43 of file ModuleBase.cc.

References art::ModuleBase::collector_, and art::ConsumesCollector::getConsumables().

44  {
45  return collector_.getConsumables();
46  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables() const
std::unique_ptr< Worker > art::ModuleBase::makeWorker ( WorkerParams const &  wp)
inherited

Definition at line 37 of file ModuleBase.cc.

References art::ModuleBase::doMakeWorker(), and art::NumBranchTypes.

38  {
39  return doMakeWorker(wp);
40  }
virtual std::unique_ptr< Worker > doMakeWorker(WorkerParams const &wp)=0
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::mayConsume ( InputTag const &  tag)
protectedinherited

Definition at line 82 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsume().

83  {
84  return collector_.mayConsume<T, BT>(tag);
85  }
ProductToken< T > mayConsume(InputTag const &)
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename T , BranchType BT>
void art::ModuleBase::mayConsumeMany ( )
protectedinherited

Definition at line 96 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsumeMany().

97  {
98  collector_.mayConsumeMany<T, BT>();
99  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::mayConsumeView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::mayConsumeView ( InputTag const &  tag)
inherited

Definition at line 89 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsumeView().

90  {
91  return collector_.mayConsumeView<T, BT>(tag);
92  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ViewToken< Element > mayConsumeView(InputTag const &)
ModuleDescription const & art::ModuleBase::moduleDescription ( ) const
inherited

Definition at line 13 of file ModuleBase.cc.

References art::errors::LogicError.

Referenced by art::OutputModule::doRespondToOpenInputFile(), art::OutputModule::doWriteEvent(), art::Modifier::fillProductDescriptions(), art::OutputModule::makePlugins_(), art::OutputWorker::OutputWorker(), reco::shower::LArPandoraModularShowerCreation::produce(), art::Modifier::registerProducts(), and art::OutputModule::registerProducts().

14  {
15  if (md_.has_value()) {
16  return *md_;
17  }
18 
20  "There was an error while calling moduleDescription().\n"}
21  << "The moduleDescription() base-class member function cannot be called\n"
22  "during module construction. To determine which module is "
23  "responsible\n"
24  "for calling it, find the '<module type>:<module "
25  "label>@Construction'\n"
26  "tag in the message prefix above. Please contact artists@fnal.gov\n"
27  "for guidance.\n";
28  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::optional< ModuleDescription > md_
Definition: ModuleBase.h:55
void trkf::CosmicTracker::produce ( art::Event evt)
privatevirtual

Implements art::EDProducer.

Definition at line 246 of file CosmicTracker_module.cc.

References util::begin(), recob::tracking::convertCollToPoint(), recob::tracking::convertCollToVector(), util::CreateAssn(), DEFINE_ART_MODULE, dir, trkPoint::dir, util::end(), fAngCut, fClusterMatch, fClusterModuleLabel, fCTAlg, art::fill_ptr_vector(), fSortDir, fStitchTracks, fTrajOnly, art::ProductRetriever::getByLabel(), trkPoint::hit, hits(), util::kBogusD, cluster::ClusterMatchTQ::MatchedClusters(), MatchTrack(), trkPoint::pos, art::PtrVector< T >::push_back(), art::Event::put(), sp_sort_x0(), sp_sort_x1(), sp_sort_y0(), sp_sort_y1(), sp_sort_z0(), sp_sort_z1(), spt_sort_x0(), spt_sort_x1(), spt_sort_y0(), spt_sort_y1(), spt_sort_z0(), spt_sort_z1(), trkf::CosmicTrackerAlg::SPTReco(), tmp, trkf::CosmicTrackerAlg::trajHit, trkf::CosmicTrackerAlg::trajPos, trkf::CosmicTrackerAlg::trkDir, and trkf::CosmicTrackerAlg::trkPos.

247  {
248 
249  // get services
251 
252  std::unique_ptr<std::vector<recob::Track>> tcol(new std::vector<recob::Track>);
253  std::unique_ptr<std::vector<recob::SpacePoint>> spcol(new std::vector<recob::SpacePoint>);
254  std::unique_ptr<art::Assns<recob::Track, recob::SpacePoint>> tspassn(
256  std::unique_ptr<art::Assns<recob::Track, recob::Cluster>> tcassn(
258  std::unique_ptr<art::Assns<recob::Track, recob::Hit>> thassn(
260  std::unique_ptr<art::Assns<recob::SpacePoint, recob::Hit>> shassn(
262 
263  //double timetick = detprop->SamplingRate()*1e-3; //time sample in us
264  //double presamplings = detprop->TriggerOffset(); // presamplings in ticks
265  //double plane_pitch = geom->PlanePitch(0,1); //wire plane pitch in cm
266  //double wire_pitch = geom->WirePitch(); //wire pitch in cm
267  //double Efield_drift = larprop->Efield(0); // Electric Field in the drift region in kV/cm
268  //double Temperature = detprop->Temperature(); // LAr Temperature in K
269 
270  //double driftvelocity = larprop->DriftVelocity(Efield_drift,Temperature); //drift velocity in the drift region (cm/us)
271  //double timepitch = driftvelocity*timetick; //time sample (cm)
272 
273  // get input Cluster object(s).
274  art::Handle<std::vector<recob::Cluster>> clusterListHandle;
275  std::vector<art::Ptr<recob::Cluster>> clusterlist;
276  if (evt.getByLabel(fClusterModuleLabel, clusterListHandle))
277  art::fill_ptr_vector(clusterlist, clusterListHandle);
278 
279  art::FindManyP<recob::Hit> fm(clusterListHandle, evt, fClusterModuleLabel);
280 
281  // find matched clusters
282  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
283  auto const detProp =
285  auto const matchedclusters = fClusterMatch.MatchedClusters(detProp, clusterlist, fm);
286 
287  // get track space points
288  std::vector<std::vector<trkPoint>> trkpts(matchedclusters.size());
289  for (size_t itrk = 0; itrk < matchedclusters.size(); ++itrk) { //loop over tracks
290 
291  std::vector<art::Ptr<recob::Hit>> hitlist;
292  for (size_t iclu = 0; iclu < matchedclusters[itrk].size(); ++iclu) { //loop over clusters
293 
294  std::vector<art::Ptr<recob::Hit>> hits = fm.at(matchedclusters[itrk][iclu]);
295  for (size_t ihit = 0; ihit < hits.size(); ++ihit) {
296  hitlist.push_back(hits[ihit]);
297  }
298  }
299  // reconstruct space points and directions
300  fCTAlg.SPTReco(clockData, detProp, hitlist);
301  if (!fTrajOnly) {
302  if (!fCTAlg.trkPos.size()) continue;
303  for (size_t i = 0; i < hitlist.size(); ++i) {
304  trkPoint trkpt;
305  trkpt.pos = fCTAlg.trkPos[i];
306  trkpt.dir = fCTAlg.trkDir[i];
307  trkpt.hit = hitlist[i];
308  trkpts[itrk].push_back(trkpt);
309  }
310  if (fSortDir == "+x") std::sort(trkpts[itrk].begin(), trkpts[itrk].end(), sp_sort_x0);
311  if (fSortDir == "-x") std::sort(trkpts[itrk].begin(), trkpts[itrk].end(), sp_sort_x1);
312  if (fSortDir == "+y") std::sort(trkpts[itrk].begin(), trkpts[itrk].end(), sp_sort_y0);
313  if (fSortDir == "-y") std::sort(trkpts[itrk].begin(), trkpts[itrk].end(), sp_sort_y1);
314  if (fSortDir == "+z") std::sort(trkpts[itrk].begin(), trkpts[itrk].end(), sp_sort_z0);
315  if (fSortDir == "-z") std::sort(trkpts[itrk].begin(), trkpts[itrk].end(), sp_sort_z1);
316  }
317 
318  if (fTrajOnly) { //debug only
319  if (!fCTAlg.trajPos.size()) continue;
320  size_t spStart = spcol->size();
321  std::vector<recob::SpacePoint> spacepoints;
322  for (size_t ipt = 0; ipt < fCTAlg.trajPos.size(); ++ipt) {
324  double hitcoord[3];
325  hitcoord[0] = fCTAlg.trajPos[ipt].X();
326  hitcoord[1] = fCTAlg.trajPos[ipt].Y();
327  hitcoord[2] = fCTAlg.trajPos[ipt].Z();
328  double err[6] = {util::kBogusD};
329  recob::SpacePoint mysp(hitcoord,
330  err,
332  spStart + spacepoints.size()); //3d point at end of track
333  spacepoints.push_back(mysp);
334  spcol->push_back(mysp);
335  util::CreateAssn(evt, *spcol, fCTAlg.trajHit[ipt], *shassn);
336  } // ihit
337  size_t spEnd = spcol->size();
338  if (fSortDir == "+x") {
339  std::sort(spacepoints.begin(), spacepoints.end(), spt_sort_x0);
340  std::sort(spcol->begin() + spStart, spcol->begin() + spEnd, spt_sort_x0);
341  }
342  if (fSortDir == "-x") {
343  std::sort(spacepoints.begin(), spacepoints.end(), spt_sort_x1);
344  std::sort(spcol->begin() + spStart, spcol->begin() + spEnd, spt_sort_x1);
345  }
346  if (fSortDir == "+y") {
347  std::sort(spacepoints.begin(), spacepoints.end(), spt_sort_y0);
348  std::sort(spcol->begin() + spStart, spcol->begin() + spEnd, spt_sort_y0);
349  }
350  if (fSortDir == "-y") {
351  std::sort(spacepoints.begin(), spacepoints.end(), spt_sort_y1);
352  std::sort(spcol->begin() + spStart, spcol->begin() + spEnd, spt_sort_y1);
353  }
354  if (fSortDir == "+z") {
355  std::sort(spacepoints.begin(), spacepoints.end(), spt_sort_z0);
356  std::sort(spcol->begin() + spStart, spcol->begin() + spEnd, spt_sort_z0);
357  }
358  if (fSortDir == "-z") {
359  std::sort(spacepoints.begin(), spacepoints.end(), spt_sort_z1);
360  std::sort(spcol->begin() + spStart, spcol->begin() + spEnd, spt_sort_z1);
361  }
362 
363  if (spacepoints.size() > 0) {
364 
365  // make a vector of the trajectory points along the track
366  std::vector<TVector3> xyz(spacepoints.size());
367  for (size_t s = 0; s < spacepoints.size(); ++s) {
368  xyz[s] = TVector3(spacepoints[s].XYZ());
369  }
370  //Calculate track direction cosines
371  TVector3 startpointVec, endpointVec, DirCos;
372  startpointVec = xyz[0];
373  endpointVec = xyz.back();
374  DirCos = endpointVec - startpointVec;
375  //SetMag casues a crash if the magnitude of the vector is zero
376  try {
377  DirCos.SetMag(1.0); //normalize vector
378  }
379  catch (...) {
380  std::cout << "The Spacepoint is infinitely small" << std::endl;
381  continue;
382  }
383  std::vector<TVector3> dircos(spacepoints.size(), DirCos);
384 
385  tcol->push_back(
388  recob::Track::Flags_t(xyz.size()),
389  false),
390  0,
391  -1.,
392  0,
395  tcol->size()));
396 
397  // make associations between the track and space points
398  util::CreateAssn(evt, *tcol, *spcol, *tspassn, spStart, spEnd);
399 
400  // and the hits and track
401  std::vector<art::Ptr<recob::Hit>> trkhits;
402  for (size_t ihit = 0; ihit < hitlist.size(); ++ihit) {
403  trkhits.push_back(hitlist[ihit]);
404  }
405  util::CreateAssn(evt, *tcol, trkhits, *thassn);
406  }
407  }
408  } //itrk
409 
410  // by default creates a spacepoint and direction for each hit
411  if (!fTrajOnly) {
412  std::vector<std::vector<unsigned int>> trkidx;
413  //stitch tracks from different TPCs
414  if (fStitchTracks) {
415  for (size_t itrk1 = 0; itrk1 < trkpts.size(); ++itrk1) {
416  for (size_t itrk2 = itrk1 + 1; itrk2 < trkpts.size(); ++itrk2) {
417  if (MatchTrack(trkpts[itrk1], trkpts[itrk2], fAngCut)) {
418  int found1 = -1;
419  int found2 = -1;
420  for (size_t i = 0; i < trkidx.size(); ++i) {
421  for (size_t j = 0; j < trkidx[i].size(); ++j) {
422  if (trkidx[i][j] == itrk1) found1 = i;
423  if (trkidx[i][j] == itrk2) found2 = i;
424  }
425  }
426  if (found1 == -1 && found2 == -1) {
427  std::vector<unsigned int> tmp;
428  tmp.push_back(itrk1);
429  tmp.push_back(itrk2);
430  trkidx.push_back(tmp);
431  }
432  else if (found1 == -1 && found2 != -1) {
433  trkidx[found2].push_back(itrk1);
434  }
435  else if (found1 != -1 && found2 == -1) {
436  trkidx[found1].push_back(itrk2);
437  }
438  else if (found1 != found2) { //merge two vectors
439  trkidx[found1].insert(
440  trkidx[found1].end(), trkidx[found2].begin(), trkidx[found2].end());
441  trkidx.erase(trkidx.begin() + found2);
442  }
443  } //found match
444  } //itrk2
445  } //itrk1
446  for (size_t itrk = 0; itrk < trkpts.size(); ++itrk) {
447  bool found = false;
448  for (size_t i = 0; i < trkidx.size(); ++i) {
449  for (size_t j = 0; j < trkidx[i].size(); ++j) {
450  if (trkidx[i][j] == itrk) found = true;
451  }
452  }
453  if (!found) {
454  std::vector<unsigned int> tmp;
455  tmp.push_back(itrk);
456  trkidx.push_back(tmp);
457  }
458  }
459  } //stitch
460  else {
461  trkidx.resize(trkpts.size());
462  for (size_t i = 0; i < trkpts.size(); ++i) {
463  trkidx[i].push_back(i);
464  }
465  }
466 
467  //make recob::track and associations
468  for (size_t i = 0; i < trkidx.size(); ++i) {
469  //all track points
470  std::vector<trkPoint> finaltrkpts;
471  //all the clusters associated with the current track
472  std::vector<art::Ptr<recob::Cluster>> clustersPerTrack;
473  //all hits
474  std::vector<art::Ptr<recob::Hit>> hitlist;
475  for (size_t j = 0; j < trkidx[i].size(); ++j) {
476  for (size_t k = 0; k < trkpts[trkidx[i][j]].size(); ++k) {
477  finaltrkpts.push_back(trkpts[trkidx[i][j]][k]);
478  hitlist.push_back(trkpts[trkidx[i][j]][k].hit);
479  } //k
480  for (size_t iclu = 0; iclu < matchedclusters[trkidx[i][j]].size(); ++iclu) {
481  art::Ptr<recob::Cluster> cluster(clusterListHandle,
482  matchedclusters[trkidx[i][j]][iclu]);
483  clustersPerTrack.push_back(cluster);
484  }
485 
486  } //j
487  if (fStitchTracks) {
488  if (fSortDir == "+x") std::sort(finaltrkpts.begin(), finaltrkpts.end(), sp_sort_x0);
489  if (fSortDir == "-x") std::sort(finaltrkpts.begin(), finaltrkpts.end(), sp_sort_x1);
490  if (fSortDir == "+y") std::sort(finaltrkpts.begin(), finaltrkpts.end(), sp_sort_y0);
491  if (fSortDir == "-y") std::sort(finaltrkpts.begin(), finaltrkpts.end(), sp_sort_y1);
492  if (fSortDir == "+z") std::sort(finaltrkpts.begin(), finaltrkpts.end(), sp_sort_z0);
493  if (fSortDir == "-z") std::sort(finaltrkpts.begin(), finaltrkpts.end(), sp_sort_z1);
494  }
495  size_t spStart = spcol->size();
496  std::vector<recob::SpacePoint> spacepoints;
497  for (size_t ipt = 0; ipt < finaltrkpts.size(); ++ipt) {
499  sp_hits.push_back(finaltrkpts[ipt].hit);
500  double hitcoord[3];
501  hitcoord[0] = finaltrkpts[ipt].pos.X();
502  hitcoord[1] = finaltrkpts[ipt].pos.Y();
503  hitcoord[2] = finaltrkpts[ipt].pos.Z();
504  double err[6] = {util::kBogusD};
505  recob::SpacePoint mysp(hitcoord,
506  err,
508  spStart + spacepoints.size()); //3d point at end of track
509  spacepoints.push_back(mysp);
510  spcol->push_back(mysp);
511  util::CreateAssn(evt, *spcol, sp_hits, *shassn);
512  } // ipt
513  size_t spEnd = spcol->size();
514  if (spacepoints.size() > 0) {
515  // make a vector of the trajectory points along the track
516  std::vector<TVector3> xyz(spacepoints.size());
517  std::vector<TVector3> dircos(spacepoints.size());
518  for (size_t s = 0; s < spacepoints.size(); ++s) {
519  xyz[s] = TVector3(spacepoints[s].XYZ());
520  dircos[s] = finaltrkpts[s].dir;
521  //flip direction if needed.
522  if (spacepoints.size() > 1) {
523  if (s == 0) {
524  TVector3 xyz1 = TVector3(spacepoints[s + 1].XYZ());
525  TVector3 dir = xyz1 - xyz[s];
526  if (dir.Angle(dircos[s]) > 0.8 * TMath::Pi()) { dircos[s] = -dircos[s]; }
527  }
528  else {
529  TVector3 dir = xyz[s] - xyz[s - 1];
530  if (dir.Angle(dircos[s]) > 0.8 * TMath::Pi()) { dircos[s] = -dircos[s]; }
531  }
532  }
533  }
534  tcol->push_back(
537  recob::Track::Flags_t(xyz.size()),
538  false),
539  0,
540  -1.,
541  0,
544  tcol->size()));
545 
546  // make associations between the track and space points
547  util::CreateAssn(evt, *tcol, *spcol, *tspassn, spStart, spEnd);
548 
549  // now the track and clusters
550  util::CreateAssn(evt, *tcol, clustersPerTrack, *tcassn);
551 
552  // and the hits and track
553  std::vector<art::Ptr<recob::Hit>> trkhits;
554  for (size_t ihit = 0; ihit < hitlist.size(); ++ihit) {
555  trkhits.push_back(hitlist[ihit]);
556  }
557  util::CreateAssn(evt, *tcol, trkhits, *thassn);
558  }
559 
560  } //i
561  }
562  mf::LogVerbatim("Summary") << std::setfill('-') << std::setw(175) << "-" << std::setfill(' ');
563  mf::LogVerbatim("Summary") << "CosmicTracker Summary:";
564  for (unsigned int i = 0; i < tcol->size(); ++i)
565  mf::LogVerbatim("Summary") << tcol->at(i);
566  mf::LogVerbatim("Summary") << "CosmicTracker Summary End:";
567 
568  evt.put(std::move(tcol));
569  evt.put(std::move(spcol));
570  evt.put(std::move(tspassn));
571  evt.put(std::move(tcassn));
572  evt.put(std::move(thassn));
573  evt.put(std::move(shassn));
574 
575  return;
576  }
bool spt_sort_x1(const recob::SpacePoint h1, const recob::SpacePoint h2)
bool sp_sort_x1(const trkPoint &tp1, const trkPoint &tp2)
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
bool sp_sort_y1(const trkPoint &tp1, const trkPoint &tp2)
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
Definition: TrackingTypes.h:78
TrackTrajectory::Flags_t Flags_t
Definition: Track.h:67
std::vector< TVector3 > trajPos
bool sp_sort_z1(const trkPoint &tp1, const trkPoint &tp2)
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 >> SMatrixSym55
art::Ptr< recob::Hit > hit
std::vector< TVector3 > trkDir
Float_t tmp
Definition: plot.C:35
bool fTrajOnly
Only use trajectory points from TrackTrajectoryAlg for debugging.
Cluster finding and building.
trkf::CosmicTrackerAlg fCTAlg
bool fStitchTracks
Stitch tracks from different TPCs.
bool MatchTrack(const std::vector< trkPoint > &trkpts1, const std::vector< trkPoint > &trkpts2, double angcut)
double fAngCut
Angle cut for track merging.
bool sp_sort_z0(const trkPoint &tp1, const trkPoint &tp2)
bool sp_sort_y0(const trkPoint &tp1, const trkPoint &tp2)
std::vector< std::vector< unsigned int > > MatchedClusters(const detinfo::DetectorPropertiesData &detProp, const std::vector< art::Ptr< recob::Cluster >> &clusterlist, const art::FindManyP< recob::Hit > &fm) const
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
bool sp_sort_x0(const trkPoint &tp1, const trkPoint &tp2)
void hits()
Definition: readHits.C:15
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
A trajectory in space reconstructed from hits.
bool spt_sort_y0(const recob::SpacePoint h1, const recob::SpacePoint h2)
bool spt_sort_z1(const recob::SpacePoint h1, const recob::SpacePoint h2)
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
Definition: TrackingTypes.h:68
cluster::ClusterMatchTQ fClusterMatch
Detector simulation of raw signals on wires.
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.
std::vector< TVector3 > trkPos
std::string fClusterModuleLabel
label for input cluster collection
bool spt_sort_z0(const recob::SpacePoint h1, const recob::SpacePoint h2)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
TDirectory * dir
Definition: macro.C:5
void SPTReco(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> &fHits)
bool spt_sort_x0(const recob::SpacePoint h1, const recob::SpacePoint h2)
bool spt_sort_y1(const recob::SpacePoint h1, const recob::SpacePoint h2)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
constexpr double kBogusD
obviously bogus double value
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
std::string fSortDir
sort space points
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
std::vector< std::vector< art::Ptr< recob::Hit > > > trajHit
void art::Modifier::registerProducts ( ProductDescriptions productsToRegister)
inherited

Definition at line 16 of file Modifier.cc.

References art::ModuleBase::moduleDescription(), and art::ProductRegistryHelper::registerProducts().

17  {
18  ProductRegistryHelper::registerProducts(productsToRegister,
20  }
void registerProducts(ProductDescriptions &productsToRegister, ModuleDescription const &md)
ModuleDescription const & moduleDescription() const
Definition: ModuleBase.cc:13
void art::ModuleBase::setModuleDescription ( ModuleDescription const &  md)
inherited

Definition at line 31 of file ModuleBase.cc.

References art::ModuleBase::md_.

32  {
33  md_ = md;
34  }
std::optional< ModuleDescription > md_
Definition: ModuleBase.h:55
void art::ModuleBase::sortConsumables ( std::string const &  current_process_name)
inherited

Definition at line 49 of file ModuleBase.cc.

References art::ModuleBase::collector_, and art::ConsumesCollector::sortConsumables().

50  {
51  // Now that we know we have seen all the consumes declarations,
52  // sort the results for fast lookup later.
53  collector_.sortConsumables(current_process_name);
54  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
void sortConsumables(std::string const &current_process_name)

Member Data Documentation

double trkf::CosmicTracker::fAngCut
private

Angle cut for track merging.

Definition at line 215 of file CosmicTracker_module.cc.

Referenced by CosmicTracker(), and produce().

cluster::ClusterMatchTQ trkf::CosmicTracker::fClusterMatch
private

Definition at line 207 of file CosmicTracker_module.cc.

Referenced by CosmicTracker(), and produce().

std::string trkf::CosmicTracker::fClusterModuleLabel
private

label for input cluster collection

Definition at line 210 of file CosmicTracker_module.cc.

Referenced by CosmicTracker(), and produce().

trkf::CosmicTrackerAlg trkf::CosmicTracker::fCTAlg
private

Definition at line 208 of file CosmicTracker_module.cc.

Referenced by CosmicTracker(), and produce().

std::string trkf::CosmicTracker::fSortDir
private

sort space points

Definition at line 212 of file CosmicTracker_module.cc.

Referenced by CosmicTracker(), and produce().

bool trkf::CosmicTracker::fStitchTracks
private

Stitch tracks from different TPCs.

Definition at line 214 of file CosmicTracker_module.cc.

Referenced by CosmicTracker(), and produce().

bool trkf::CosmicTracker::fTrajOnly
private

Only use trajectory points from TrackTrajectoryAlg for debugging.

Definition at line 217 of file CosmicTracker_module.cc.

Referenced by CosmicTracker(), and produce().


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