LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
cosmic::CosmicPCAxisTagger Class Reference
Inheritance diagram for cosmic::CosmicPCAxisTagger:
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

 CosmicPCAxisTagger (fhicl::ParameterSet const &p)
 
void produce (art::Event &e) override
 
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 Types

typedef std::vector< reco::ClusterHit2DHit2DVector
 

Private Attributes

std::string fPFParticleModuleLabel
 
std::string fPCAxisModuleLabel
 
lar_cluster3d::PrincipalComponentsAlg fPcaAlg
 Principal Components algorithm. More...
 
int fDetectorWidthTicks
 
float fTPCXBoundary
 
float fTPCYBoundary
 
float fTPCZBoundary
 
float fDetHalfHeight
 
float fDetWidth
 
float fDetLength
 

Detailed Description

Definition at line 50 of file CosmicPCAxisTagger_module.cc.

Member Typedef Documentation

Definition at line 57 of file CosmicPCAxisTagger_module.cc.

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

cosmic::CosmicPCAxisTagger::CosmicPCAxisTagger ( fhicl::ParameterSet const &  p)
explicit

Definition at line 69 of file CosmicPCAxisTagger_module.cc.

References geo::GeometryCore::DetHalfHeight(), geo::GeometryCore::DetHalfWidth(), geo::GeometryCore::DetLength(), fDetectorWidthTicks, fDetHalfHeight, fDetLength, fDetWidth, fPcaAlg, fPCAxisModuleLabel, fPFParticleModuleLabel, fTPCXBoundary, fTPCYBoundary, fTPCZBoundary, and detinfo::sampling_rate().

70  : EDProducer{p}, fPcaAlg(p.get<fhicl::ParameterSet>("PrincipalComponentsAlg"))
71 {
73 
75  fDetWidth = 2. * geo->DetHalfWidth();
76  fDetLength = geo->DetLength();
77 
78  auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
79  float fSamplingRate = sampling_rate(clock_data);
80 
81  fPFParticleModuleLabel = p.get<std::string>("PFParticleModuleLabel");
82  fPCAxisModuleLabel = p.get<std::string>("PCAxisModuleLabel");
83 
84  fTPCXBoundary = p.get<float>("TPCXBoundary", 5);
85  fTPCYBoundary = p.get<float>("TPCYBoundary", 5);
86  fTPCZBoundary = p.get<float>("TPCZBoundary", 5);
87 
88  auto const detector =
90  const double driftVelocity =
91  detector.DriftVelocity(detector.Efield(), detector.Temperature()); // cm/us
92 
94  2 * geo->DetHalfWidth() / (driftVelocity * fSamplingRate / 1000); // ~3200 for uB
95 
96  produces<std::vector<anab::CosmicTag>>();
97  produces<art::Assns<recob::PFParticle, anab::CosmicTag>>();
98  produces<art::Assns<recob::PCAxis, anab::CosmicTag>>();
99 }
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
Length_t DetHalfWidth(TPCID const &tpcid=tpc_zero) const
Returns the half width of the active volume of the specified TPC.
Length_t DetLength(TPCID const &tpcid=tpc_zero) const
Returns the length of the active volume of the specified TPC.
lar_cluster3d::PrincipalComponentsAlg fPcaAlg
Principal Components algorithm.
Length_t DetHalfHeight(TPCID const &tpcid=tpc_zero) const
Returns the half height of the active volume of the specified TPC.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
Namespace collecting geometry-related classes utilities.

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 cosmic::CosmicPCAxisTagger::produce ( art::Event e)
overridevirtual

Implements art::EDProducer.

Definition at line 101 of file CosmicPCAxisTagger_module.cc.

References util::CreateAssn(), DEFINE_ART_MODULE, fDetectorWidthTicks, fDetHalfHeight, fDetLength, fDetWidth, fPCAxisModuleLabel, fPFParticleModuleLabel, fTPCXBoundary, fTPCYBoundary, fTPCZBoundary, recob::PCAxis::getAvePosition(), art::ProductRetriever::getByLabel(), recob::PCAxis::getEigenValues(), recob::PCAxis::getEigenVectors(), art::Handle< T >::isValid(), art::Ptr< T >::key(), anab::kGeometry_X, anab::kGeometry_XX, anab::kGeometry_XY, anab::kGeometry_XZ, anab::kGeometry_Y, anab::kGeometry_YY, anab::kGeometry_YZ, anab::kGeometry_Z, anab::kGeometry_ZZ, anab::kNotTagged, anab::kOutsideDrift_Partial, and art::Event::put().

102 {
103  // Instatiate the output
104  std::unique_ptr<std::vector<anab::CosmicTag>> cosmicTagPFParticleVector(
105  new std::vector<anab::CosmicTag>);
106  std::unique_ptr<art::Assns<recob::PCAxis, anab::CosmicTag>> assnOutCosmicTagPCAxis(
108  std::unique_ptr<art::Assns<recob::PFParticle, anab::CosmicTag>> assnOutCosmicTagPFParticle(
110 
111  // Recover handle for PFParticles
113  evt.getByLabel(fPFParticleModuleLabel, pfParticleHandle);
114 
115  if (!pfParticleHandle.isValid()) {
116  evt.put(std::move(cosmicTagPFParticleVector));
117  evt.put(std::move(assnOutCosmicTagPFParticle));
118  evt.put(std::move(assnOutCosmicTagPCAxis));
119  return;
120  }
121 
122  // We need a handle to the collection of clusters in the data store so we can
123  // handle associations to hits.
125  evt.getByLabel(fPFParticleModuleLabel, clusterHandle);
126 
127  // Recover the handle for the PCAxes
129  evt.getByLabel(fPCAxisModuleLabel, pcaxisHandle);
130 
131  if (!pcaxisHandle.isValid() || !clusterHandle.isValid()) {
132  evt.put(std::move(cosmicTagPFParticleVector));
133  evt.put(std::move(assnOutCosmicTagPFParticle));
134  evt.put(std::move(assnOutCosmicTagPCAxis));
135  return;
136  }
137 
138  // Recover the list of associated PCA axes
139  art::FindManyP<recob::PCAxis> pfPartToPCAxisAssns(pfParticleHandle, evt, fPCAxisModuleLabel);
140 
141  // Add the relations to recover associations cluster hits
142  art::FindManyP<recob::SpacePoint> spacePointAssnVec(
143  pfParticleHandle, evt, fPFParticleModuleLabel);
144 
145  // Recover the collection of associations between PFParticles and clusters, this will
146  // be the mechanism by which we actually deal with clusters
147  art::FindManyP<recob::Cluster> clusterAssns(pfParticleHandle, evt, fPFParticleModuleLabel);
148 
149  // Likewise, recover the collection of associations to hits
150  art::FindManyP<recob::Hit> clusterHitAssns(clusterHandle, evt, fPFParticleModuleLabel);
151 
152  // The outer loop is going to be over PFParticles
153  for (size_t pfPartIdx = 0; pfPartIdx != pfParticleHandle->size(); pfPartIdx++) {
154  art::Ptr<recob::PFParticle> pfParticle(pfParticleHandle, pfPartIdx);
155 
156  // Recover the PCAxis vector
157  std::vector<art::Ptr<recob::PCAxis>> pcAxisVec = pfPartToPCAxisAssns.at(pfPartIdx);
158 
159  // Is there an axis associated to this PFParticle?
160  if (pcAxisVec.empty()) continue;
161 
162  // *****************************************************************************************
163  // For what follows below we want the "best" PCAxis object only. However, it can be that
164  // there are two PCAxes for a PFParticle (depending on source) where the "first" axis will
165  // be the "better" one that we want (this statement by fiat, it is defined that way in the
166  // axis producer module).
167  if (pcAxisVec.size() > 1 && pcAxisVec.front()->getID() > pcAxisVec.back()->getID())
168  std::reverse(pcAxisVec.begin(), pcAxisVec.end());
169  // We need to confirm this!!
170  // *****************************************************************************************
171 
172  // Recover the axis
173  const art::Ptr<recob::PCAxis>& pcAxis = pcAxisVec.front();
174 
175  // Start the tagging process...
176  int isCosmic = 0;
178 
179  // There are two sections to the tagging, in the first we are going to check for hits that are
180  // "out of time" and for this we only need the hit vector. If no hits are out of time then
181  // we need to do a more thorough check of the positions of the hits.
182  // If we find hits that are out of time we'll set the "end points" of our trajectory to
183  // a scale factor past the principle eigen value
184  double eigenVal0 = sqrt(pcAxis->getEigenValues()[0]);
185  double maxArcLen = 3. * eigenVal0;
186 
187  // Recover PCA end points
188  TVector3 vertexPosition(
189  pcAxis->getAvePosition()[0], pcAxis->getAvePosition()[1], pcAxis->getAvePosition()[2]);
190  TVector3 vertexDirection(pcAxis->getEigenVectors()[0][0],
191  pcAxis->getEigenVectors()[0][1],
192  pcAxis->getEigenVectors()[0][2]);
193 
194  TVector3 pcAxisStart = vertexPosition - maxArcLen * vertexDirection;
195  TVector3 pcAxisEnd = vertexPosition + maxArcLen * vertexDirection;
196 
197  // "Track" end points in easily readable form
198  float trackEndPt1_X = pcAxisStart[0];
199  float trackEndPt1_Y = pcAxisStart[1];
200  float trackEndPt1_Z = pcAxisStart[2];
201  float trackEndPt2_X = pcAxisEnd[0];
202  float trackEndPt2_Y = pcAxisEnd[1];
203  float trackEndPt2_Z = pcAxisEnd[2];
204 
205  // Now we get the 2D clusters associated to this PFParticle
206  std::vector<art::Ptr<recob::Cluster>> clusterVec = clusterAssns.at(pfParticle.key());
207 
208  bool dumpMe(false);
209 
210  // Once we have the clusters then we can loop over them to find the associated hits
211  for (const auto& cluster : clusterVec) {
212  // Recover the 2D hits associated to a given cluster
213  std::vector<art::Ptr<recob::Hit>> hitVec = clusterHitAssns.at(cluster->ID());
214 
215  // Once we have the hits the first thing we should do is to check if any are "out of time"
216  // If there are out of time hits then we are going to reject the cluster so no need to do
217  // any further processing.
219  // Check that all hits on particle are "in time"
221  for (const auto& hit : hitVec) {
222  if (dumpMe) {
223  std::cout << "***>> Hit key: " << hit.key() << ", peak - RMS: " << hit->PeakTimeMinusRMS()
224  << ", peak + RMS: " << hit->PeakTimePlusRMS()
225  << ", det width: " << fDetectorWidthTicks << std::endl;
226  }
227  if (hit->PeakTimeMinusRMS() < fDetectorWidthTicks ||
228  hit->PeakTimePlusRMS() > 2. * fDetectorWidthTicks) {
229  isCosmic = 1;
231  break; // If one hit is out of time it must be a cosmic ray
232  }
233  }
234  }
235 
236  // Recover the space points associated to this PFParticle.
237  std::vector<art::Ptr<recob::SpacePoint>> spacePointVec = spacePointAssnVec.at(pfParticle.key());
238 
240  // Now check the TPC boundaries:
242  if (isCosmic == 0 && !spacePointVec.empty()) {
243  // Do a check on the transverse components of the PCA axes to make sure we are looking at long straight
244  // tracks and not the kind of events we might want to keep
245  double transRMS =
246  sqrt(std::pow(pcAxis->getEigenValues()[1], 2) + std::pow(pcAxis->getEigenValues()[1], 2));
247 
248  if (eigenVal0 > 0. && transRMS > 0.) {
249  // The idea is to find the maximum extents of this PFParticle using the PCA axis which we
250  // can then use to determine proximity to a TPC boundary.
251  // We implement this by recovering the 3D Space Points and then make a pass through them to
252  // find the space points at the extremes of the distance along the principle axis.
253  // We'll loop through the space points looking for those which have the largest arc lengths along
254  // the principle axis. Set up to do that
255  double arcLengthToFirstHit(9999.);
256  double arcLengthToLastHit(-9999.);
257 
258  for (const auto spacePoint : spacePointVec) {
259  TVector3 spacePointPos(spacePoint->XYZ()[0], spacePoint->XYZ()[1], spacePoint->XYZ()[2]);
260  TVector3 deltaPos = spacePointPos - vertexPosition;
261  double arcLenToHit = deltaPos.Dot(vertexDirection);
262 
263  if (arcLenToHit < arcLengthToFirstHit) {
264  arcLengthToFirstHit = arcLenToHit;
265  pcAxisStart = spacePointPos;
266  }
267 
268  if (arcLenToHit > arcLengthToLastHit) {
269  arcLengthToLastHit = arcLenToHit;
270  pcAxisEnd = spacePointPos;
271  }
272  }
273 
274  // "Track" end points in easily readable form
275  trackEndPt1_X = pcAxisStart[0];
276  trackEndPt1_Y = pcAxisStart[1];
277  trackEndPt1_Z = pcAxisStart[2];
278  trackEndPt2_X = pcAxisEnd[0];
279  trackEndPt2_Y = pcAxisEnd[1];
280  trackEndPt2_Z = pcAxisEnd[2];
281 
282  // In below we check entry and exit points. Note that a special case of a particle entering
283  // and exiting the same surface is considered to be running parallel to the surface and NOT
284  // entering and exiting.
285  // Also, in what follows we make no assumptions on which end point is the "start" or
286  // "end" of the track being considered.
287  bool nBdX[] = {false, false};
288  bool nBdY[] = {false, false};
289  bool nBdZ[] = {false, false};
290 
291  // Check x extents - note that uboone coordinaes system has x=0 at edge
292  // Note this counts the case where the track enters and exits the same surface as a "1", not a "2"
293  // Also note that, in theory, any cosmic ray entering or exiting the X surfaces will have presumably
294  // been removed already by the checking of "out of time" hits... but this will at least label
295  // neutrino interaction tracks which exit through the X surfaces of the TPC
296  if (fDetWidth - trackEndPt1_X < fTPCXBoundary || trackEndPt1_X < fTPCXBoundary)
297  nBdX[0] = true;
298  if (fDetWidth - trackEndPt2_X < fTPCXBoundary || trackEndPt2_X < fTPCXBoundary)
299  nBdX[1] = true;
300 
301  // Check y extents (note coordinate system change)
302  // Note this counts the case where the track enters and exits the same surface as a "1", not a "2"
303  if (fDetHalfHeight - trackEndPt1_Y < fTPCYBoundary ||
304  fDetHalfHeight + trackEndPt1_Y < fTPCYBoundary)
305  nBdY[0] = true; // one end of track exits out top
306  if (fDetHalfHeight - trackEndPt2_Y < fTPCYBoundary ||
307  fDetHalfHeight + trackEndPt2_Y < fTPCYBoundary)
308  nBdY[1] = true; // one end of track exist out bottom
309 
310  // Check z extents
311  // Note this counts the case where the track enters and exits the same surface as a "1", not a "2"
312  if (fDetLength - trackEndPt1_Z < fTPCZBoundary || trackEndPt1_Z < fTPCZBoundary)
313  nBdZ[0] = true;
314  if (fDetLength - trackEndPt2_Z < fTPCZBoundary || trackEndPt2_Z < fTPCZBoundary)
315  nBdZ[1] = true;
316 
317  // Endpoints exiting?
318  bool exitEnd1 = nBdX[0] || nBdY[0]; // end point 1 enters/exits top/bottom or x sides
319  bool exitEnd2 = nBdX[1] || nBdY[1]; // end point 2 enters/exits top/bottom or x sides
320  bool exitEndZ1 =
321  exitEnd1 && nBdZ[1]; // end point 1 enters/exits top/bottom and exits/enters z
322  bool exitEndZ2 =
323  exitEnd1 && nBdZ[0]; // end point 2 enters/exits top/bottom and exits/enters z
324 
325  // This should check for the case of a track which is both entering and exiting
326  // but we consider entering and exiting the z boundaries to be a special case (should it be?)
327  if ((exitEnd1 && exitEnd2) || exitEndZ1 || exitEndZ2) {
328  isCosmic = 2;
329  if (nBdX[0] && nBdX[1])
331  else if (nBdY[0] && nBdY[1])
333  else if ((nBdX[0] || nBdX[1]) && (nBdY[0] || nBdY[1]))
335  else if ((nBdX[0] || nBdX[1]) && (nBdZ[0] || nBdZ[1]))
337  else
339  }
340  // This is the special case of track which appears to enter/exit z boundaries
341  else if (nBdZ[0] && nBdZ[1]) {
342  isCosmic = 3;
344  }
345  // This looks for track which enters/exits a boundary but has other endpoint in TPC
346  else if ((nBdX[0] || nBdY[0] || nBdZ[0]) != (nBdX[1] || nBdY[1] || nBdZ[1])) {
347  isCosmic = 4;
348  if (nBdX[0] || nBdX[1])
350  else if (nBdY[0] || nBdY[1])
352  else if (nBdZ[0] || nBdZ[1])
354  }
355  }
356  }
357 
358  std::vector<float> endPt1;
359  std::vector<float> endPt2;
360  endPt1.push_back(trackEndPt1_X);
361  endPt1.push_back(trackEndPt1_Y);
362  endPt1.push_back(trackEndPt1_Z);
363  endPt2.push_back(trackEndPt2_X);
364  endPt2.push_back(trackEndPt2_Y);
365  endPt2.push_back(trackEndPt2_Z);
366 
367  float cosmicScore = isCosmic > 0 ? 1. : 0.;
368 
369  // Handle special cases
370  if (isCosmic == 3)
371  cosmicScore = 0.4; // Enter/Exit at opposite Z boundaries
372  else if (isCosmic == 4)
373  cosmicScore = 0.5; // Enter or Exit but not both
374 
375  // Create the tag object for this PFParticle and make the corresponding association
376  cosmicTagPFParticleVector->emplace_back(endPt1, endPt2, cosmicScore, tag_id);
377 
378  util::CreateAssn(evt, *cosmicTagPFParticleVector, pfParticle, *assnOutCosmicTagPFParticle);
379 
380  // Loop through the tracks resulting from this PFParticle and mark them
381  for (const auto& axis : pcAxisVec) {
382  util::CreateAssn(evt, *cosmicTagPFParticleVector, axis, *assnOutCosmicTagPCAxis);
383  }
384  }
385 
386  evt.put(std::move(cosmicTagPFParticleVector));
387  evt.put(std::move(assnOutCosmicTagPFParticle));
388  evt.put(std::move(assnOutCosmicTagPCAxis));
389 } // end of produce
const EigenVectors & getEigenVectors() const
Definition: PCAxis.h:74
const double * getEigenValues() const
Definition: PCAxis.h:70
enum anab::cosmic_tag_id CosmicTagID_t
Cluster finding and building.
bool isValid() const noexcept
Definition: Handle.h:203
Detector simulation of raw signals on wires.
const double * getAvePosition() const
Definition: PCAxis.h:78
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.
TCEvent evt
Definition: DataStructs.cxx:8
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

int cosmic::CosmicPCAxisTagger::fDetectorWidthTicks
private

Definition at line 64 of file CosmicPCAxisTagger_module.cc.

Referenced by CosmicPCAxisTagger(), and produce().

float cosmic::CosmicPCAxisTagger::fDetHalfHeight
private

Definition at line 66 of file CosmicPCAxisTagger_module.cc.

Referenced by CosmicPCAxisTagger(), and produce().

float cosmic::CosmicPCAxisTagger::fDetLength
private

Definition at line 66 of file CosmicPCAxisTagger_module.cc.

Referenced by CosmicPCAxisTagger(), and produce().

float cosmic::CosmicPCAxisTagger::fDetWidth
private

Definition at line 66 of file CosmicPCAxisTagger_module.cc.

Referenced by CosmicPCAxisTagger(), and produce().

lar_cluster3d::PrincipalComponentsAlg cosmic::CosmicPCAxisTagger::fPcaAlg
private

Principal Components algorithm.

Definition at line 62 of file CosmicPCAxisTagger_module.cc.

Referenced by CosmicPCAxisTagger().

std::string cosmic::CosmicPCAxisTagger::fPCAxisModuleLabel
private

Definition at line 60 of file CosmicPCAxisTagger_module.cc.

Referenced by CosmicPCAxisTagger(), and produce().

std::string cosmic::CosmicPCAxisTagger::fPFParticleModuleLabel
private

Definition at line 59 of file CosmicPCAxisTagger_module.cc.

Referenced by CosmicPCAxisTagger(), and produce().

float cosmic::CosmicPCAxisTagger::fTPCXBoundary
private

Definition at line 65 of file CosmicPCAxisTagger_module.cc.

Referenced by CosmicPCAxisTagger(), and produce().

float cosmic::CosmicPCAxisTagger::fTPCYBoundary
private

Definition at line 65 of file CosmicPCAxisTagger_module.cc.

Referenced by CosmicPCAxisTagger(), and produce().

float cosmic::CosmicPCAxisTagger::fTPCZBoundary
private

Definition at line 65 of file CosmicPCAxisTagger_module.cc.

Referenced by CosmicPCAxisTagger(), and produce().


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