LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
CRHitRemoval Class Reference
Inheritance diagram for CRHitRemoval:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 CRHitRemoval (fhicl::ParameterSet const &pset)
 
virtual ~CRHitRemoval ()
 Destructor. More...
 
virtual void reconfigure (fhicl::ParameterSet const &pset)
 
virtual void produce (art::Event &e)
 
virtual void beginJob ()
 Begin job method. More...
 
virtual void endJob ()
 End job method. More...
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > consumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > consumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > mayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > mayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

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< raw::RawDigit > &, art::FindOneP< recob::Wire > &, recob::HitCollectionCreator &)
 
void copyInTimeHits (std::vector< art::Ptr< recob::Hit >> &, art::FindOneP< raw::RawDigit > &, 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 45 of file CRHitRemoval_module.cc.

Member Typedef Documentation

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

Definition at line 61 of file CRHitRemoval_module.cc.

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

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

Constructor.

Arguments:

pset - Fcl parameters.

Definition at line 112 of file CRHitRemoval_module.cc.

References recob::HitAndAssociationsWriterBase::declare_products(), and reconfigure().

112  :
113 fNumEvent(0),
114 fNumCRRejects(0)
115 {
116  reconfigure(pset);
117 
118  // let HitCollectionCreator declare that we are going to produce
119  // hits and associations with wires and raw digits
120  // (with no particular product label)
122 
123  // Report.
124  mf::LogInfo("CRHitRemoval") << "CRHitRemoval configured\n";
125 }
virtual void reconfigure(fhicl::ParameterSet const &pset)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
static void declare_products(ModuleType &producer, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.h:1117
int fNumCRRejects
Number of tracks produced.
int fNumEvent
Number of events seen.
CRHitRemoval::~CRHitRemoval ( )
virtual

Destructor.

Definition at line 129 of file CRHitRemoval_module.cc.

130 {}

Member Function Documentation

void CRHitRemoval::beginJob ( )
virtual

Begin job method.

Reimplemented from art::EDProducer.

Definition at line 153 of file CRHitRemoval_module.cc.

References fDetectorWidthTicks, fEndTickPadding, fMaxTickDrift, and fMinTickDrift.

154 {
155  auto const* detp = lar::providerFrom<detinfo::DetectorPropertiesService>();
156  auto const* geo = lar::providerFrom<geo::Geometry>();
157  auto const* ts = lar::providerFrom<detinfo::DetectorClocksService>();
158 
159  float samplingRate = detp->SamplingRate();
160  float driftVelocity = detp->DriftVelocity( detp->Efield(), detp->Temperature() ); // cm/us
161 
162  fDetectorWidthTicks = 2*geo->DetHalfWidth()/(driftVelocity*samplingRate/1000);
163  fMinTickDrift = ts->Time2Tick(ts->TriggerTime()); // this is the hardware trigger time
165 }
int fEndTickPadding
Padding the end tick.
int fMaxTickDrift
Ending tick.
int fDetectorWidthTicks
Effective drift time in ticks.
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 448 of file CRHitRemoval_module.cc.

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

Referenced by produce().

453 {
454  // Recover the clusters associated to the input PFParticle
455  std::vector<art::Ptr<recob::Cluster> > clusterVec = partToClusAssns.at(pfParticle->Self());
456 
457  int minTick(fMinTickDrift);
458  int maxTick(fMaxTickDrift);
459 
460  // Loop over the clusters and grab the associated hits
461  for(const auto& cluster : clusterVec)
462  {
463  std::vector<art::Ptr<recob::Hit> > clusHitVec = clusToHitAssns.at(cluster.key());
464  hitVec.insert(hitVec.end(), clusHitVec.begin(), clusHitVec.end());
465 
466  int minHitTick = (*std::min_element(clusHitVec.begin(),clusHitVec.end(),[](const auto& hit,const auto& min){return hit->PeakTimeMinusRMS() < min->PeakTimeMinusRMS();}))->PeakTimeMinusRMS();
467  int maxHitTick = (*std::max_element(clusHitVec.begin(),clusHitVec.end(),[](const auto& hit,const auto& max){return hit->PeakTimePlusRMS() > max->PeakTimePlusRMS();}))->PeakTimePlusRMS();
468 
469  if (minHitTick < minTick) minTick = minHitTick;
470  if (maxHitTick < maxTick) maxTick = maxHitTick;
471  }
472 
473  // Loop over the daughters of this particle and remove their hits as well
474  for(const auto& daughterId : pfParticle->Daughters())
475  {
476  art::Ptr<recob::PFParticle> daughter(pfParticleHandle, daughterId);
477 
478  collectPFParticleHits(daughter.get(), pfParticleHandle, partToClusAssns, clusToHitAssns, hitVec);
479  }
480 
481  return;
482 }
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
Definition: PFParticle.h:114
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
Cluster finding and building.
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_t max
Definition: plot.C:27
int fMaxTickDrift
Ending tick.
Detector simulation of raw signals on wires.
Int_t min
Definition: plot.C:26
int fMinTickDrift
Starting tick.
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 147 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

148 {
149  if (!moduleContext_)
150  return ProductToken<T>::invalid();
151 
152  consumables_[BT].emplace_back(ConsumableType::Product,
153  TypeID{typeid(T)},
154  it.label(),
155  it.instance(),
156  it.process());
157  return ProductToken<T>{it};
158 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 162 of file Consumer.h.

163 {
164  if (!moduleContext_)
165  return;
166 
167  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
168 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 172 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

173 {
174  if (!moduleContext_)
175  return ViewToken<T>::invalid();
176 
177  consumables_[BT].emplace_back(ConsumableType::ViewElement,
178  TypeID{typeid(T)},
179  it.label(),
180  it.instance(),
181  it.process());
182  return ViewToken<T>{it};
183 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
void CRHitRemoval::copyAllHits ( std::vector< art::Ptr< recob::Hit >> &  inputHits,
art::FindOneP< raw::RawDigit > &  rawDigitAssns,
art::FindOneP< recob::Wire > &  wireAssns,
recob::HitCollectionCreator newHitCollection 
)
private

Definition at line 484 of file CRHitRemoval_module.cc.

References recob::HitCollectionCreator::emplace_back().

Referenced by produce().

488 {
489  for(const auto& hitPtr : inputHits)
490  {
491  art::Ptr<recob::Wire> wire = wireAssns.at(hitPtr.key());
492  art::Ptr<raw::RawDigit> rawdigits = rawDigitAssns.at(hitPtr.key());
493 
494  // just copy it
495  newHitCollection.emplace_back(*hitPtr, wire, rawdigits);
496  }
497 
498  return;
499 }
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:245
Definition: fwd.h:25
void CRHitRemoval::copyInTimeHits ( std::vector< art::Ptr< recob::Hit >> &  inputHits,
art::FindOneP< raw::RawDigit > &  rawDigitAssns,
art::FindOneP< recob::Wire > &  wireAssns,
recob::HitCollectionCreator newHitCollection 
)
private

Definition at line 501 of file CRHitRemoval_module.cc.

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

Referenced by produce().

505 {
506  for(const auto& hitPtr : inputHits)
507  {
508  // Check on out of time hits
509  if (hitPtr->PeakTimeMinusRMS() < fMinTickDrift || hitPtr->PeakTimePlusRMS() > fMaxTickDrift) continue;
510 
511  art::Ptr<recob::Wire> wire = wireAssns.at(hitPtr.key());
512  art::Ptr<raw::RawDigit> rawdigits = rawDigitAssns.at(hitPtr.key());
513 
514  // just copy it
515  newHitCollection.emplace_back(*hitPtr, wire, rawdigits);
516  }
517 
518  return;
519 }
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:245
int fMinTickDrift
Starting tick.
Definition: fwd.h:25
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited

Definition at line 32 of file EngineCreator.cc.

References art::EngineCreator::rng().

34 {
35  return rng()->createEngine(
36  placeholder_schedule_id(), seed, kind_of_engine_to_make);
37 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited

Definition at line 40 of file EngineCreator.cc.

References art::EngineCreator::rng().

43 {
44  return rng()->createEngine(
45  placeholder_schedule_id(), seed, kind_of_engine_to_make, engine_label);
46 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
CurrentProcessingContext const * art::EDProducer::currentContext ( ) const
protectedinherited

Definition at line 120 of file EDProducer.cc.

References art::EDProducer::current_context_.

121  {
122  return current_context_.get();
123  }
CPC_exempt_ptr current_context_
Definition: EDProducer.h:116
void CRHitRemoval::endJob ( )
virtual

End job method.

Reimplemented from art::EDProducer.

Definition at line 550 of file CRHitRemoval_module.cc.

References fNumCRRejects, and fNumEvent.

551 {
552  double aveCRPerEvent = fNumEvent > 0 ? double(fNumCRRejects) / double(fNumEvent) : 0.;
553 
554  mf::LogInfo("CRHitRemoval")
555  << "CRHitRemoval statistics:\n"
556  << " Number of events = " << fNumEvent << "\n"
557  << " Number of Cosmic Rays found = " << fNumCRRejects
558  << ", " << aveCRPerEvent << " average/event";
559 }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
int fNumCRRejects
Number of tracks produced.
int fNumEvent
Number of events seen.
void CRHitRemoval::FilterHits ( HitPtrVector hits,
HitPtrVector used_hits 
)
private

Definition at line 530 of file CRHitRemoval_module.cc.

Referenced by produce().

531 {
532  if(used_hits.size() > 0)
533  {
534  // Make sure both hit collections are sorted.
535  std::stable_sort(hits.begin(), hits.end());
536  std::stable_sort(used_hits.begin(), used_hits.end());
537 
538  // Do set difference operation.
539  std::vector<art::Ptr<recob::Hit>>::iterator it
540  = std::set_difference(hits.begin(), hits.end(), used_hits.begin(), used_hits.end(), hits.begin());
541 
542  // Truncate hit collection.
543  hits.erase(it, hits.end());
544  }
545 }
void hits()
Definition: readHits.C:15
EngineCreator::seed_t EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited

Definition at line 49 of file EngineCreator.cc.

References fhicl::ParameterSet::get().

Referenced by art::MixFilter< T >::initEngine_().

52 {
53  auto const& explicit_seeds = pset.get<std::vector<int>>(key, {});
54  return explicit_seeds.empty() ? implicit_seed : explicit_seeds.front();
55 }
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References B, and art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
Int_t B
Definition: plot.C:25
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 190 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

191 {
192  if (!moduleContext_)
193  return ProductToken<T>::invalid();
194 
195  consumables_[BT].emplace_back(ConsumableType::Product,
196  TypeID{typeid(T)},
197  it.label(),
198  it.instance(),
199  it.process());
200  return ProductToken<T>{it};
201 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 205 of file Consumer.h.

206 {
207  if (!moduleContext_)
208  return;
209 
210  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
211 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 215 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

216 {
217  if (!moduleContext_)
218  return ViewToken<T>::invalid();
219 
220  consumables_[BT].emplace_back(ConsumableType::ViewElement,
221  TypeID{typeid(T)},
222  it.label(),
223  it.instance(),
224  it.process());
225  return ViewToken<T>{it};
226 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID().

41  {
42  return true;
43  }
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited

Definition at line 89 of file Consumer.cc.

References fhicl::ParameterSet::get_if_present().

Referenced by art::EDProducer::doBeginJob(), art::EDFilter::doBeginJob(), and art::EDAnalyzer::doBeginJob().

90 {
91  if (!moduleContext_)
92  return;
93 
94  pset.get_if_present("errorOnMissingConsumes", requireConsumes_);
95  for (auto& consumablesPerBranch : consumables_) {
96  cet::sort_all(consumablesPerBranch);
97  }
98 }
bool requireConsumes_
Definition: Consumer.h:137
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
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 180 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::DataViewImpl::getByLabel(), recob::PFParticle::IsPrimary(), art::Handle< T >::isValid(), art::Ptr< T >::key(), recob::PFParticle::Parent(), and track.

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

Reconfigure method.

Arguments:

pset - Fcl parameter set.

Definition at line 139 of file CRHitRemoval_module.cc.

References fAssnProducerLabels, fCosmicProducerLabels, fCosmicTagThresholds, fEndTickPadding, fHitProducerLabel, fMaxOutOfTime, fPFParticleProducerLabel, fTrackProducerLabels, and fhicl::ParameterSet::get().

Referenced by CRHitRemoval().

140 {
141  fCosmicProducerLabels = pset.get<std::vector<std::string> >("CosmicProducerLabels");
142  fHitProducerLabel = pset.get<std::string>("HitProducerLabel");
143  fPFParticleProducerLabel = pset.get<std::string>("PFParticleProducerLabel");
144  fTrackProducerLabels = pset.get<std::vector<std::string>>("TrackProducerLabels");
145  fAssnProducerLabels = pset.get<std::vector<std::string>>("AssnProducerLabels");
146  fCosmicTagThresholds = pset.get<std::vector<double> >("CosmicTagThresholds");
147  fEndTickPadding = pset.get<int>("EndTickPadding", 50);
148  fMaxOutOfTime = pset.get<int>("MaxOutOfTime", 4);
149 }
std::string fPFParticleProducerLabel
PFParticle producer.
int fEndTickPadding
Padding the end tick.
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.
int fMaxOutOfTime
Max hits that can be out of time before rejecting.
std::vector< std::string > fTrackProducerLabels
Track producer.
std::vector< std::string > fCosmicProducerLabels
List of cosmic tagger producers.
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Definition at line 125 of file Consumer.cc.

Referenced by art::EDProducer::doEndJob(), art::EDFilter::doEndJob(), art::EDAnalyzer::doEndJob(), and art::RootOutput::endJob().

126 {
127  if (!moduleContext_)
128  return;
129 
130  // If none of the branches have missing consumes statements, exit early.
131  if (std::all_of(cbegin(missingConsumes_),
132  cend(missingConsumes_),
133  [](auto const& perBranch) { return perBranch.empty(); }))
134  return;
135 
136  constexpr cet::HorizontalRule rule{60};
137  mf::LogPrint log{"MTdiagnostics"};
138  log << '\n'
139  << rule('=') << '\n'
140  << "The following consumes (or mayConsume) statements are missing from\n"
141  << module_context(moduleDescription_) << '\n'
142  << rule('-') << '\n';
143 
144  cet::for_all_with_index(
145  missingConsumes_, [&log](std::size_t const i, auto const& perBranch) {
146  for (auto const& pi : perBranch) {
147  log << " "
148  << assemble_consumes_statement(static_cast<BranchType>(i), pi)
149  << '\n';
150  }
151  });
152  log << rule('=');
153 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139
void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Definition at line 101 of file Consumer.cc.

References art::errors::ProductRegistrationFailure.

103 {
104  // Early exits if consumes tracking has been disabled or if the
105  // consumed product is an allowed consumable.
106  if (!moduleContext_)
107  return;
108 
109  if (cet::binary_search_all(consumables_[bt], pi))
110  return;
111 
112  if (requireConsumes_) {
114  "Consumer: an error occurred during validation of a "
115  "retrieved product\n\n")
116  << "The following consumes (or mayConsume) statement is missing from\n"
117  << module_context(moduleDescription_) << ":\n\n"
118  << " " << assemble_consumes_statement(bt, pi) << "\n\n";
119  }
120 
121  missingConsumes_[bt].insert(pi);
122 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
bool requireConsumes_
Definition: Consumer.h:137
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139

Member Data Documentation

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

Track to PFParticle assns producer.

Definition at line 87 of file CRHitRemoval_module.cc.

Referenced by produce(), and reconfigure().

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

List of cosmic tagger producers.

Definition at line 83 of file CRHitRemoval_module.cc.

Referenced by produce(), and reconfigure().

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

Thresholds for tagging.

Definition at line 89 of file CRHitRemoval_module.cc.

Referenced by produce(), and reconfigure().

int CRHitRemoval::fDetectorWidthTicks
private

Effective drift time in ticks.

Definition at line 93 of file CRHitRemoval_module.cc.

Referenced by beginJob().

int CRHitRemoval::fEndTickPadding
private

Padding the end tick.

Definition at line 91 of file CRHitRemoval_module.cc.

Referenced by beginJob(), and reconfigure().

std::string CRHitRemoval::fHitProducerLabel
private

The full collection of hits.

Definition at line 84 of file CRHitRemoval_module.cc.

Referenced by produce(), and reconfigure().

int CRHitRemoval::fMaxOutOfTime
private

Max hits that can be out of time before rejecting.

Definition at line 96 of file CRHitRemoval_module.cc.

Referenced by produce(), and reconfigure().

int CRHitRemoval::fMaxTickDrift
private

Ending tick.

Definition at line 95 of file CRHitRemoval_module.cc.

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

int CRHitRemoval::fMinTickDrift
private

Starting tick.

Definition at line 94 of file CRHitRemoval_module.cc.

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

int CRHitRemoval::fNumCRRejects
private

Number of tracks produced.

Definition at line 100 of file CRHitRemoval_module.cc.

Referenced by endJob().

int CRHitRemoval::fNumEvent
private

Number of events seen.

Definition at line 99 of file CRHitRemoval_module.cc.

Referenced by endJob(), and produce().

std::string CRHitRemoval::fPFParticleProducerLabel
private

PFParticle producer.

Definition at line 85 of file CRHitRemoval_module.cc.

Referenced by produce(), and reconfigure().

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

Track producer.

Definition at line 86 of file CRHitRemoval_module.cc.

Referenced by produce(), and reconfigure().


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