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

 CRHitRemoval (fhicl::ParameterSet const &pset)
 
virtual void produce (art::Event &e)
 
virtual void beginJob ()
 Begin job method. More...
 
virtual void endJob ()
 End job method. More...
 
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

using HitPtrVector = std::vector< art::Ptr< recob::Hit >>
 

Private Member Functions

void collectPFParticleHits (const recob::PFParticle *pfParticle, const art::Handle< std::vector< recob::PFParticle >> &pfParticleHandle, const art::FindManyP< recob::Cluster > &partToClusAssns, const art::FindManyP< recob::Hit > &clusToHitAssns, HitPtrVector &hitVec)
 
void copyAllHits (std::vector< art::Ptr< recob::Hit >> &, art::FindOneP< recob::Wire > &, recob::HitCollectionCreator &)
 
void copyInTimeHits (std::vector< art::Ptr< recob::Hit >> &, art::FindOneP< recob::Wire > &, recob::HitCollectionCreator &)
 
void FilterHits (HitPtrVector &hits, HitPtrVector &used_hits)
 

Private Attributes

std::vector< std::string > fCosmicProducerLabels
 List of cosmic tagger producers. More...
 
std::string fHitProducerLabel
 The full collection of hits. More...
 
std::string fPFParticleProducerLabel
 PFParticle producer. More...
 
std::vector< std::string > fTrackProducerLabels
 Track producer. More...
 
std::vector< std::string > fAssnProducerLabels
 Track to PFParticle assns producer. More...
 
std::vector< double > fCosmicTagThresholds
 Thresholds for tagging. More...
 
int fEndTickPadding
 Padding the end tick. More...
 
int fDetectorWidthTicks
 Effective drift time in ticks. More...
 
int fMinTickDrift
 Starting tick. More...
 
int fMaxTickDrift
 Ending tick. More...
 
int fMaxOutOfTime
 Max hits that can be out of time before rejecting. More...
 
int fNumEvent
 Number of events seen. More...
 
int fNumCRRejects
 Number of tracks produced. More...
 

Detailed Description

Definition at line 48 of file CRHitRemoval_module.cc.

Member Typedef Documentation

using CRHitRemoval::HitPtrVector = std::vector<art::Ptr<recob::Hit>>
private

Definition at line 60 of file CRHitRemoval_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

CRHitRemoval::CRHitRemoval ( fhicl::ParameterSet const &  pset)
explicit

Constructor.

Arguments:

pset - Fcl parameters.

Definition at line 109 of file CRHitRemoval_module.cc.

References recob::HitAndAssociationsWriterBase::declare_products(), fAssnProducerLabels, fCosmicProducerLabels, fCosmicTagThresholds, fEndTickPadding, fHitProducerLabel, fMaxOutOfTime, fNumCRRejects, fNumEvent, fPFParticleProducerLabel, fTrackProducerLabels, and art::ProductRegistryHelper::producesCollector().

110  : EDProducer{pset}, fNumEvent(0), fNumCRRejects(0)
111 {
112  fCosmicProducerLabels = pset.get<std::vector<std::string>>("CosmicProducerLabels");
113  fHitProducerLabel = pset.get<std::string>("HitProducerLabel");
114  fPFParticleProducerLabel = pset.get<std::string>("PFParticleProducerLabel");
115  fTrackProducerLabels = pset.get<std::vector<std::string>>("TrackProducerLabels");
116  fAssnProducerLabels = pset.get<std::vector<std::string>>("AssnProducerLabels");
117  fCosmicTagThresholds = pset.get<std::vector<double>>("CosmicTagThresholds");
118  fEndTickPadding = pset.get<int>("EndTickPadding", 50);
119  fMaxOutOfTime = pset.get<int>("MaxOutOfTime", 4);
120 
121  // let HitCollectionCreator declare that we are going to produce
122  // hits and associations with wires and raw digits
123  // (with no particular product label)
125 
126  // Report.
127  mf::LogInfo("CRHitRemoval") << "CRHitRemoval configured\n";
128 }
std::string fPFParticleProducerLabel
PFParticle producer.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
int fEndTickPadding
Padding the end tick.
int fNumCRRejects
Number of tracks produced.
static void declare_products(art::ProducesCollector &collector, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.cxx:248
std::vector< std::string > fAssnProducerLabels
Track to PFParticle assns producer.
std::string fHitProducerLabel
The full collection of hits.
std::vector< double > fCosmicTagThresholds
Thresholds for tagging.
ProducesCollector & producesCollector() noexcept
int fMaxOutOfTime
Max hits that can be out of time before rejecting.
std::vector< std::string > fTrackProducerLabels
Track producer.
int fNumEvent
Number of events seen.
std::vector< std::string > fCosmicProducerLabels
List of cosmic tagger producers.

Member Function Documentation

void CRHitRemoval::beginJob ( )
virtual

Begin job method.

Reimplemented from art::EDProducer.

Definition at line 132 of file CRHitRemoval_module.cc.

References fDetectorWidthTicks, fEndTickPadding, fMaxTickDrift, fMinTickDrift, and detinfo::sampling_rate().

133 {
134  auto const* geo = lar::providerFrom<geo::Geometry>();
135  auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
136  auto const detp =
138 
139  float const samplingRate = sampling_rate(clock_data);
140  float const driftVelocity = detp.DriftVelocity(detp.Efield(), detp.Temperature()); // cm/us
141 
142  fDetectorWidthTicks = 2 * geo->DetHalfWidth() / (driftVelocity * samplingRate / 1000);
143  fMinTickDrift =
144  clock_data.Time2Tick(clock_data.TriggerTime()); // this is the hardware trigger time
146 }
int fEndTickPadding
Padding the end tick.
int fMaxTickDrift
Ending tick.
int fDetectorWidthTicks
Effective drift time in ticks.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
Namespace collecting geometry-related classes utilities.
int fMinTickDrift
Starting tick.
void CRHitRemoval::collectPFParticleHits ( const recob::PFParticle pfParticle,
const art::Handle< std::vector< recob::PFParticle >> &  pfParticleHandle,
const art::FindManyP< recob::Cluster > &  partToClusAssns,
const art::FindManyP< recob::Hit > &  clusToHitAssns,
HitPtrVector hitVec 
)
private

Find all hits in PFParticle hierarchy

Arguments:

pfParticle - the top level PFParticle to have hits removed pfParticleHandle - handle to the PFParticle objects partToClusAssns - list of PFParticle to Cluster associations clusToHitAssns - list of Cluster to Hit associations hitVec - the current list of hits

This recursively called method will remove all hits associated to an input PFParticle and, in addition, will call itself for all daughters of the input PFParticle

Definition at line 416 of file CRHitRemoval_module.cc.

References recob::PFParticle::Daughters(), fMaxTickDrift, fMinTickDrift, art::Ptr< T >::get(), and recob::PFParticle::Self().

Referenced by produce().

422 {
423  // Recover the clusters associated to the input PFParticle
424  std::vector<art::Ptr<recob::Cluster>> clusterVec = partToClusAssns.at(pfParticle->Self());
425 
426  int minTick(fMinTickDrift);
427  int maxTick(fMaxTickDrift);
428 
429  // Loop over the clusters and grab the associated hits
430  for (const auto& cluster : clusterVec) {
431  std::vector<art::Ptr<recob::Hit>> clusHitVec = clusToHitAssns.at(cluster.key());
432  hitVec.insert(hitVec.end(), clusHitVec.begin(), clusHitVec.end());
433 
434  int minHitTick = (*std::min_element(clusHitVec.begin(),
435  clusHitVec.end(),
436  [](const auto& hit, const auto& min) {
437  return hit->PeakTimeMinusRMS() < min->PeakTimeMinusRMS();
438  }))
439  ->PeakTimeMinusRMS();
440  int maxHitTick = (*std::max_element(clusHitVec.begin(),
441  clusHitVec.end(),
442  [](const auto& hit, const auto& max) {
443  return hit->PeakTimePlusRMS() > max->PeakTimePlusRMS();
444  }))
445  ->PeakTimePlusRMS();
446 
447  if (minHitTick < minTick) minTick = minHitTick;
448  if (maxHitTick < maxTick) maxTick = maxHitTick;
449  }
450 
451  // Loop over the daughters of this particle and remove their hits as well
452  for (const auto& daughterId : pfParticle->Daughters()) {
453  art::Ptr<recob::PFParticle> daughter(pfParticleHandle, daughterId);
454 
456  daughter.get(), pfParticleHandle, partToClusAssns, clusToHitAssns, hitVec);
457  }
458 
459  return;
460 }
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
Definition: PFParticle.h:110
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:88
Cluster finding and building.
int fMaxTickDrift
Ending tick.
Detector simulation of raw signals on wires.
void collectPFParticleHits(const recob::PFParticle *pfParticle, const art::Handle< std::vector< recob::PFParticle >> &pfParticleHandle, const art::FindManyP< recob::Cluster > &partToClusAssns, const art::FindManyP< recob::Hit > &clusToHitAssns, HitPtrVector &hitVec)
int fMinTickDrift
Starting tick.
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 CRHitRemoval::copyAllHits ( std::vector< art::Ptr< recob::Hit >> &  inputHits,
art::FindOneP< recob::Wire > &  wireAssns,
recob::HitCollectionCreator newHitCollection 
)
private

Definition at line 462 of file CRHitRemoval_module.cc.

References recob::HitCollectionCreator::emplace_back().

Referenced by produce().

465 {
466  for (const auto& hitPtr : inputHits) {
467  art::Ptr<recob::Wire> wire = wireAssns.at(hitPtr.key());
468 
469  // just copy it
470  newHitCollection.emplace_back(*hitPtr, wire);
471  }
472 
473  return;
474 }
void emplace_back(recob::Hit &&hit, art::Ptr< recob::Wire > const &wire=art::Ptr< recob::Wire >(), art::Ptr< raw::RawDigit > const &digits=art::Ptr< raw::RawDigit >())
Adds the specified hit to the data collection.
Definition: HitCreator.cxx:286
Definition: fwd.h:26
void CRHitRemoval::copyInTimeHits ( std::vector< art::Ptr< recob::Hit >> &  inputHits,
art::FindOneP< recob::Wire > &  wireAssns,
recob::HitCollectionCreator newHitCollection 
)
private

Definition at line 476 of file CRHitRemoval_module.cc.

References recob::HitCollectionCreator::emplace_back(), fMaxTickDrift, and fMinTickDrift.

Referenced by produce().

479 {
480  for (const auto& hitPtr : inputHits) {
481  // Check on out of time hits
482  if (hitPtr->PeakTimeMinusRMS() < fMinTickDrift || hitPtr->PeakTimePlusRMS() > fMaxTickDrift)
483  continue;
484 
485  art::Ptr<recob::Wire> wire = wireAssns.at(hitPtr.key());
486 
487  // just copy it
488  newHitCollection.emplace_back(*hitPtr, wire);
489  }
490 
491  return;
492 }
int fMaxTickDrift
Ending tick.
void emplace_back(recob::Hit &&hit, art::Ptr< recob::Wire > const &wire=art::Ptr< recob::Wire >(), art::Ptr< raw::RawDigit > const &digits=art::Ptr< raw::RawDigit >())
Adds the specified hit to the data collection.
Definition: HitCreator.cxx:286
int fMinTickDrift
Starting tick.
Definition: fwd.h:26
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 CRHitRemoval::endJob ( )
virtual

End job method.

Reimplemented from art::EDProducer.

Definition at line 521 of file CRHitRemoval_module.cc.

References fNumCRRejects, and fNumEvent.

522 {
523  double aveCRPerEvent = fNumEvent > 0 ? double(fNumCRRejects) / double(fNumEvent) : 0.;
524 
525  mf::LogInfo("CRHitRemoval") << "CRHitRemoval statistics:\n"
526  << " Number of events = " << fNumEvent << "\n"
527  << " Number of Cosmic Rays found = " << fNumCRRejects << ", "
528  << aveCRPerEvent << " average/event";
529 }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
int fNumCRRejects
Number of tracks produced.
int fNumEvent
Number of events seen.
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
void CRHitRemoval::FilterHits ( HitPtrVector hits,
HitPtrVector used_hits 
)
private

Definition at line 503 of file CRHitRemoval_module.cc.

Referenced by produce().

504 {
505  if (used_hits.size() > 0) {
506  // Make sure both hit collections are sorted.
507  std::stable_sort(hits.begin(), hits.end());
508  std::stable_sort(used_hits.begin(), used_hits.end());
509 
510  // Do set difference operation.
511  std::vector<art::Ptr<recob::Hit>>::iterator it = std::set_difference(
512  hits.begin(), hits.end(), used_hits.begin(), used_hits.end(), hits.begin());
513 
514  // Truncate hit collection.
515  hits.erase(it, hits.end());
516  }
517 }
void hits()
Definition: readHits.C:15
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 CRHitRemoval::produce ( art::Event evt)
virtual

Produce method.

Arguments:

evt - Art event.

This is the primary method. The goal is to produce a list of recob::Hit objects which are a "clean" subset of all hits and which are believed to be due to a neutrino interaction. It does this by considering input CosmicTag objects, relating them to PFParticles/Tracks and removing the hits associated to those objects which are believed to be Cosmic Rays.

Implements art::EDProducer.

Definition at line 161 of file CRHitRemoval_module.cc.

References collectPFParticleHits(), copyAllHits(), copyInTimeHits(), anab::CosmicTag::CosmicScore(), fAssnProducerLabels, fCosmicProducerLabels, fCosmicTagThresholds, fHitProducerLabel, art::fill_ptr_vector(), FilterHits(), fMaxOutOfTime, fMaxTickDrift, fMinTickDrift, fNumEvent, fPFParticleProducerLabel, fTrackProducerLabels, art::ProductRetriever::getByLabel(), recob::PFParticle::IsPrimary(), art::Handle< T >::isValid(), art::Ptr< T >::key(), recob::PFParticle::Parent(), and track.

162 {
163  ++fNumEvent;
164 
165  // Start by looking up the original hits
167  evt.getByLabel(fHitProducerLabel, hitHandle);
168 
169  // If there are no hits then there should be no output
170  if (!hitHandle.isValid()) return;
171 
172  // also get the associated wires
173  // Note that we no longer assume RawDigit associations and will not preserve them if they exist
174  // we assume they have been created by the same module as the hits
175  art::FindOneP<recob::Wire> ChannelHitWires(hitHandle, evt, fHitProducerLabel);
176 
177  HitPtrVector ChHits;
178  art::fill_ptr_vector(ChHits, hitHandle);
179 
180  // this object contains the hit collection
181  // and its associations to wires and raw digits:
182  recob::HitCollectionCreator hcol(evt, ChannelHitWires.isValid(), false);
183 
184  // Now recover thre remaining collections of objects in the event store that we need
185  // Recover the PFParticles that are ultimately associated to tracks
186  // This will be the key to recovering the hits
188  evt.getByLabel(fPFParticleProducerLabel, pfParticleHandle);
189 
190  // Without a valid collection of PFParticles we can't do the hit removal
191  if (!pfParticleHandle.isValid()) {
192  copyAllHits(ChHits, ChannelHitWires, hcol);
193 
194  // put the hit collection and associations into the event
195  hcol.put_into(evt);
196 
197  return;
198  }
199 
200  // Recover the clusters so we can do associations to the hits
201  // In theory the clusters come from the same producer as the PFParticles
203  evt.getByLabel(fPFParticleProducerLabel, clusterHandle);
204 
205  // If there are no clusters then something is really wrong
206  if (!clusterHandle.isValid()) {
207  copyAllHits(ChHits, ChannelHitWires, hcol);
208 
209  // put the hit collection and associations into the event
210  hcol.put_into(evt);
211 
212  return;
213  }
214 
215  // Build the list of cosmic tag producers, associations and thresholds
216  std::vector<art::Handle<std::vector<anab::CosmicTag>>> cosmicHandleVec;
217  std::vector<std::map<int, std::vector<art::Ptr<recob::Track>>>> cosmicToTrackVecMapVec;
218  std::vector<std::map<int, std::vector<art::Ptr<recob::PFParticle>>>> trackToPFParticleVecMapVec;
219  std::vector<double> thresholdVec;
220 
221  for (size_t idx = 0; idx != fCosmicProducerLabels.size(); idx++) {
222  std::string& handleLabel(fCosmicProducerLabels[idx]);
223 
225  evt.getByLabel(handleLabel, cosmicHandle);
226 
227  if (cosmicHandle.isValid()) {
228  // Look up the associations to tracks
229  art::FindManyP<recob::Track> cosmicTrackAssns(cosmicHandle, evt, handleLabel);
230 
231  // Get the handle to the tracks
233  evt.getByLabel(fTrackProducerLabels[idx], trackHandle);
234 
235  // This should be the case
236  if (trackHandle.isValid()) {
237  std::map<int, std::vector<art::Ptr<recob::Track>>> cosmicToTrackVecMap;
238  std::map<int, std::vector<art::Ptr<recob::PFParticle>>> trackToPFParticleVecMap;
239 
240  // Loop through the cosmic tags
241  for (size_t cosmicIdx = 0; cosmicIdx < cosmicHandle->size(); cosmicIdx++) {
242  art::Ptr<anab::CosmicTag> cosmicTag(cosmicHandle, cosmicIdx);
243 
244  std::vector<art::Ptr<recob::Track>> cosmicToTrackVec =
245  cosmicTrackAssns.at(cosmicTag.key());
246 
247  cosmicToTrackVecMap[cosmicTag.key()] = cosmicToTrackVec;
248 
249  art::FindManyP<recob::PFParticle> trackPFParticleAssns(
250  trackHandle, evt, fAssnProducerLabels[idx]);
251 
252  for (auto& track : cosmicToTrackVec) {
253  std::vector<art::Ptr<recob::PFParticle>> trackToPFParticleVec =
254  trackPFParticleAssns.at(track.key());
255 
256  for (auto& pfParticle : trackToPFParticleVec)
257  trackToPFParticleVecMap[track.key()].push_back(pfParticle);
258  }
259  }
260 
261  // Store these collections
262  cosmicHandleVec.emplace_back(cosmicHandle);
263  cosmicToTrackVecMapVec.emplace_back(cosmicToTrackVecMap);
264  trackToPFParticleVecMapVec.emplace_back(trackToPFParticleVecMap);
265  thresholdVec.push_back(fCosmicTagThresholds[idx]);
266  }
267  }
268  }
269 
270  // No cosmic tags then nothing to do here
271  if (cosmicHandleVec.empty()) {
272  copyAllHits(ChHits, ChannelHitWires, hcol);
273 
274  // put the hit collection and associations into the event
275  hcol.put_into(evt);
276 
277  return;
278  }
279 
280  // Now we walk up the remaining list of associations needed to go from CR tags to hits
281  // We'll need to go from tracks to PFParticles
282  // From PFParticles we go to clusters
283  art::FindManyP<recob::Cluster> clusterAssns(pfParticleHandle, evt, fPFParticleProducerLabel);
284 
285  // Likewise, recover the collection of associations to hits
286  art::FindManyP<recob::Hit> clusterHitAssns(clusterHandle, evt, fPFParticleProducerLabel);
287 
288  // No point double counting hits
289  std::set<const recob::PFParticle*> taggedSet;
290 
291  // Start the identification of hits to remove. The outer loop is over the various producers of
292  // the CosmicTag objects we're examininig
293  for (size_t idx = 0; idx != cosmicHandleVec.size(); idx++) {
294  // Obviously, dereference the handle and associations
295  const art::Handle<std::vector<anab::CosmicTag>>& cosmicHandle(cosmicHandleVec[idx]);
296  const std::map<int, std::vector<art::Ptr<recob::Track>>>& crTagTrackVec(
297  cosmicToTrackVecMapVec[idx]);
298  const std::map<int, std::vector<art::Ptr<recob::PFParticle>>>& trackToPFParticleVecMap(
299  trackToPFParticleVecMapVec[idx]);
300 
301  for (size_t crIdx = 0; crIdx != cosmicHandle->size(); crIdx++) {
302  art::Ptr<anab::CosmicTag> cosmicTag(cosmicHandle, crIdx);
303 
304  // If this was tagged as a CR muon then we have work to do!
305  if (cosmicTag->CosmicScore() > thresholdVec[idx]) {
306  // Recover the associated track
307  std::vector<art::Ptr<recob::Track>> trackVec(crTagTrackVec.at(cosmicTag.key()));
308 
309  // Loop over the tracks (almost always only 1)
310  for (const auto& track : trackVec) {
311  std::map<int, std::vector<art::Ptr<recob::PFParticle>>>::const_iterator
312  trackToPFParticleVecItr = trackToPFParticleVecMap.find(track.key());
313 
314  if (trackToPFParticleVecItr != trackToPFParticleVecMap.end()) {
315  // Loop through them
316  for (const auto& pfParticlePtr : trackToPFParticleVecItr->second) {
317  // Get bare pointer
318  const recob::PFParticle* pfParticle = pfParticlePtr.get();
319 
320  // A cosmic ray must be a primary (by fiat)
321  while (!pfParticle->IsPrimary())
322  pfParticle =
323  art::Ptr<recob::PFParticle>(pfParticleHandle, pfParticle->Parent()).get();
324 
325  // Add to our list of tagged PFParticles
326  taggedSet.insert(pfParticle);
327  }
328  }
329  }
330  }
331  }
332  }
333 
334  // If no PFParticles have been tagged then nothing to do
335  if (!taggedSet.empty()) {
336  // This may all seem backwards... but what you want to do is remove all the hits which are associated to tagged
337  // cosmic ray tracks/PFParticles and what you want to leave is all other hits. This includes hits on other PFParticles
338  // as well as unassociated (as yet) hits.
339  // One also needs to deal with a slight complication with hits in 2D which are shared between untagged PFParticles and
340  // tagged ones... we should leave these in.
341 
342  // All that is left is to go through the PFParticles which have not been tagged and collect up all their hits
343  // to output to our new collection
344  // Note that this SHOULD take care of the case of shared 2D hits automagically since if the PFParticle has not
345  // been tagged and it shares hits we'll pick those up here.
346  HitPtrVector taggedHits;
347  HitPtrVector untaggedHits;
348 
349  // Loop through the PFParticles and build out the list of hits on untagged PFParticle trees
350  for (const auto& pfParticle : *pfParticleHandle) {
351  // Start with only primaries
352  if (!pfParticle.IsPrimary()) continue;
353 
354  // Temporary container for these hits
355  HitPtrVector tempHits;
356 
357  // Find the hits associated to this untagged PFParticle
358  collectPFParticleHits(&pfParticle, pfParticleHandle, clusterAssns, clusterHitAssns, tempHits);
359 
360  // One more possible chance at identifying tagged hits...
361  // Check these hits to see if any lie outside time window
362  bool goodHits(true);
363 
364  if (taggedSet.find(&pfParticle) != taggedSet.end()) goodHits = false;
365 
366  if (goodHits) {
367  int nOutOfTime(0);
368 
369  for (const auto& hit : tempHits) {
370  // Check on out of time hits
371  if (hit->PeakTimeMinusRMS() < fMinTickDrift || hit->PeakTimePlusRMS() > fMaxTickDrift)
372  nOutOfTime++;
373 
374  if (nOutOfTime > fMaxOutOfTime) {
375  goodHits = false;
376  break;
377  }
378  }
379  }
380 
381  if (goodHits)
382  std::copy(tempHits.begin(), tempHits.end(), std::back_inserter(untaggedHits));
383  else
384  std::copy(tempHits.begin(), tempHits.end(), std::back_inserter(taggedHits));
385  }
386 
387  // First task - remove hits from the tagged hit collection that are inthe untagged hits (shared hits)
388  FilterHits(taggedHits, untaggedHits);
389 
390  // Now filter the tagged hits from the total hit collection
391  FilterHits(ChHits, taggedHits);
392  }
393 
394  // Copy our new hit collection to the output
395  copyInTimeHits(ChHits, ChannelHitWires, hcol);
396 
397  // put the hit collection and associations into the event
398  hcol.put_into(evt);
399 }
std::string fPFParticleProducerLabel
PFParticle producer.
void copyAllHits(std::vector< art::Ptr< recob::Hit >> &, art::FindOneP< recob::Wire > &, recob::HitCollectionCreator &)
bool isValid() const noexcept
Definition: Handle.h:203
A class handling a collection of hits and its associations.
Definition: HitCreator.h:481
std::vector< std::string > fAssnProducerLabels
Track to PFParticle assns producer.
size_t Parent() const
Definition: PFParticle.h:92
std::vector< art::Ptr< recob::Hit >> HitPtrVector
std::string fHitProducerLabel
The full collection of hits.
int fMaxTickDrift
Ending tick.
bool IsPrimary() const
Returns whether the particle is the root of the flow.
Definition: PFParticle.h:82
std::vector< double > fCosmicTagThresholds
Thresholds for tagging.
Detector simulation of raw signals on wires.
void collectPFParticleHits(const recob::PFParticle *pfParticle, const art::Handle< std::vector< recob::PFParticle >> &pfParticleHandle, const art::FindManyP< recob::Cluster > &partToClusAssns, const art::FindManyP< recob::Hit > &clusToHitAssns, HitPtrVector &hitVec)
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
int fMaxOutOfTime
Max hits that can be out of time before rejecting.
void copyInTimeHits(std::vector< art::Ptr< recob::Hit >> &, art::FindOneP< recob::Wire > &, recob::HitCollectionCreator &)
std::vector< std::string > fTrackProducerLabels
Track producer.
int fNumEvent
Number of events seen.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
Float_t track
Definition: plot.C:35
int fMinTickDrift
Starting tick.
void FilterHits(HitPtrVector &hits, HitPtrVector &used_hits)
Definition: fwd.h:26
std::vector< std::string > fCosmicProducerLabels
List of cosmic tagger producers.
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

std::vector<std::string> CRHitRemoval::fAssnProducerLabels
private

Track to PFParticle assns producer.

Definition at line 84 of file CRHitRemoval_module.cc.

Referenced by CRHitRemoval(), and produce().

std::vector<std::string> CRHitRemoval::fCosmicProducerLabels
private

List of cosmic tagger producers.

Definition at line 80 of file CRHitRemoval_module.cc.

Referenced by CRHitRemoval(), and produce().

std::vector<double> CRHitRemoval::fCosmicTagThresholds
private

Thresholds for tagging.

Definition at line 86 of file CRHitRemoval_module.cc.

Referenced by CRHitRemoval(), and produce().

int CRHitRemoval::fDetectorWidthTicks
private

Effective drift time in ticks.

Definition at line 90 of file CRHitRemoval_module.cc.

Referenced by beginJob().

int CRHitRemoval::fEndTickPadding
private

Padding the end tick.

Definition at line 88 of file CRHitRemoval_module.cc.

Referenced by beginJob(), and CRHitRemoval().

std::string CRHitRemoval::fHitProducerLabel
private

The full collection of hits.

Definition at line 81 of file CRHitRemoval_module.cc.

Referenced by CRHitRemoval(), and produce().

int CRHitRemoval::fMaxOutOfTime
private

Max hits that can be out of time before rejecting.

Definition at line 93 of file CRHitRemoval_module.cc.

Referenced by CRHitRemoval(), and produce().

int CRHitRemoval::fMaxTickDrift
private

Ending tick.

Definition at line 92 of file CRHitRemoval_module.cc.

Referenced by beginJob(), collectPFParticleHits(), copyInTimeHits(), and produce().

int CRHitRemoval::fMinTickDrift
private

Starting tick.

Definition at line 91 of file CRHitRemoval_module.cc.

Referenced by beginJob(), collectPFParticleHits(), copyInTimeHits(), and produce().

int CRHitRemoval::fNumCRRejects
private

Number of tracks produced.

Definition at line 97 of file CRHitRemoval_module.cc.

Referenced by CRHitRemoval(), and endJob().

int CRHitRemoval::fNumEvent
private

Number of events seen.

Definition at line 96 of file CRHitRemoval_module.cc.

Referenced by CRHitRemoval(), endJob(), and produce().

std::string CRHitRemoval::fPFParticleProducerLabel
private

PFParticle producer.

Definition at line 82 of file CRHitRemoval_module.cc.

Referenced by CRHitRemoval(), and produce().

std::vector<std::string> CRHitRemoval::fTrackProducerLabels
private

Track producer.

Definition at line 83 of file CRHitRemoval_module.cc.

Referenced by CRHitRemoval(), and produce().


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