LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
recob::HitRefinerAssociator Class Reference

A class handling a collection of hits and its associations. More...

#include "HitCreator.h"

Inheritance diagram for recob::HitRefinerAssociator:
recob::HitAndAssociationsWriterBase

Public Member Functions

void use_hits (std::unique_ptr< std::vector< recob::Hit >> &&srchits)
 Uses the specified collection as data product. More...
 
void put_into (art::Event &)
 Moves the data into the event. More...
 
void put_into ()
 Moves the data into the event. More...
 
size_t size () const
 Returns the number of hits currently in the collection. More...
 
std::vector< recob::Hit > const & peek () const
 Returns a read-only reference to the current list of hits. More...
 
Constructors
 HitRefinerAssociator (art::Event &event, art::InputTag const &HitModuleLabel, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
 Constructor: sets instance name and whether to build associations. More...
 
 HitRefinerAssociator (art::Event &event, art::InputTag const &HitModuleLabel, bool doWireAssns, bool doRawDigitAssns=true)
 Constructor: sets instance name and whether to build associations. More...
 

Static Public Member Functions

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. More...
 

Protected Types

using HitPtr_t = art::Ptr< recob::Hit >
 Type of art pointer to Hit. More...
 

Protected Member Functions

void prepare_associations (std::vector< recob::Hit > const &srchits)
 Finds out the associations for the specified hits. More...
 
void prepare_associations ()
 Finds out the associations for the current hits. More...
 
HitPtr_t CreatePtr (size_t index) const
 Creates an art pointer to the hit with the specified index. More...
 

Protected Attributes

art::InputTag hits_label
 Label of the collection of hits. More...
 
std::string prod_instance
 Tame of the instance for data products. More...
 
std::unique_ptr< std::vector< recob::Hit > > hits
 Collection of hits. More...
 
std::unique_ptr< art::Assns< recob::Wire, recob::Hit > > WireAssns
 Associations with wires. More...
 
std::unique_ptr< art::Assns< raw::RawDigit, recob::Hit > > RawDigitAssns
 Associations with raw digits. More...
 
art::Eventevent = nullptr
 Pointer to the event we are using. More...
 
art::PtrMaker< recob::HithitPtrMaker
 Tool to create hit pointers,. More...
 

Detailed Description

A class handling a collection of hits and its associations.


Use this object if you already have a recob::Hit data product and another collection that is going to become a data product, and you simply want the new hits associated to the wire and digit with the same channel. No hit-to-hit association is attempted (that would be, incidentally, not supported by art): the data product is used to get all the associated wires and digits, then they are associated to the new hits by channel ID. If a channel is not available, a warning is produced. If different hits on the same channel are associated to different wires or raw digits, an exception is thrown.

Definition at line 787 of file HitCreator.h.

Member Typedef Documentation

Type of art pointer to Hit.

Definition at line 439 of file HitCreator.h.

Constructor & Destructor Documentation

recob::HitRefinerAssociator::HitRefinerAssociator ( art::Event event,
art::InputTag const &  HitModuleLabel,
std::string  instance_name = "",
bool  doWireAssns = true,
bool  doRawDigitAssns = true 
)

Constructor: sets instance name and whether to build associations.

Parameters
eventthe event the products are going to be put into
HitModuleLabellabel of the module used to create hits
instance_namename of the instance for all data products
doWireAssnswhether to enable associations to wires
doRawDigitAssnswhether to enable associations to raw digits

All the data products (hit collection and associations) will have the specified product instance name.

Definition at line 495 of file HitCreator.cxx.

References recob::HitAndAssociationsWriterBase::hits.

501  : HitAndAssociationsWriterBase(event, instance_name, doWireAssns, doRawDigitAssns)
502  , hits_label(HitModuleLabel)
503  {
504  hits.reset(new std::vector<recob::Hit>);
505  } // HitRefinerAssociator::HitRefinerAssociator()
HitAndAssociationsWriterBase(art::Event &event, std::string instance_name, bool doWireAssns, bool doRawDigitAssns)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.cxx:235
art::InputTag hits_label
Label of the collection of hits.
Definition: HitCreator.h:862
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:444
recob::HitRefinerAssociator::HitRefinerAssociator ( art::Event event,
art::InputTag const &  HitModuleLabel,
bool  doWireAssns,
bool  doRawDigitAssns = true 
)
inline

Constructor: sets instance name and whether to build associations.

Parameters
eventthe event the products are going to be put into
HitModuleLabellabel of the module used to create hits
doWireAssnswhether to enable associations to wires
doRawDigitAssnswhether to enable associations to raw digits

All the data products (hit collection and associations) will have an empty product instance name.

Definition at line 818 of file HitCreator.h.

822  : HitRefinerAssociator(event, HitModuleLabel, "", doWireAssns, doRawDigitAssns)
823  {}
HitRefinerAssociator(art::Event &event, art::InputTag const &HitModuleLabel, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.cxx:495

Member Function Documentation

HitPtr_t recob::HitAndAssociationsWriterBase::CreatePtr ( size_t  index) const
inlineprotectedinherited

Creates an art pointer to the hit with the specified index.

Definition at line 470 of file HitCreator.h.

Referenced by recob::HitCollectionAssociator::prepare_associations(), and prepare_associations().

470 { return hitPtrMaker(index); }
art::PtrMaker< recob::Hit > hitPtrMaker
Tool to create hit pointers,.
Definition: HitCreator.h:452
void recob::HitAndAssociationsWriterBase::declare_products ( art::ProducesCollector collector,
std::string  instance_name = "",
bool  doWireAssns = true,
bool  doRawDigitAssns = true 
)
staticinherited

Declares the hit products we are going to fill.

Template Parameters
ModuleTypetype of producing module (EDProducer or EDFilter)
Parameters
producerthe module producing the data products
instance_namename of the instance for all data products
doWireAssnswhether to enable associations to wires
doRawDigitAssnswhether to enable associations to raw digits

This declaration must be given in the constructor of producer. It is equivalent to manually declare the relevant among these products:

produces<std::vector<recob::Hit>>(prod_instance);
produces<art::Assns<recob::Wire, recob::Hit>>(prod_instance);
produces<art::Assns<raw::RawDigit, recob::Hit>>(prod_instance);

in the producer constructor. All the data products (hit collection and associations) will have the specified product instance name.

Definition at line 248 of file HitCreator.cxx.

References art::ProducesCollector::produces().

Referenced by apa::APAHitFinder::APAHitFinder(), cluster::ClusterCrawler::ClusterCrawler(), CRHitRemoval::CRHitRemoval(), hit::DisambigCheater::DisambigCheater(), hit::DPRawHitFinder::DPRawHitFinder(), hit::FFTHitFinder::FFTHitFinder(), hit::GausHitFinder::GausHitFinder(), hit::HitCheater::HitCheater(), hit::HitFinder::HitFinder(), cluster::LineCluster::LineCluster(), hit::RawHitFinder::RawHitFinder(), hit::RFFHitFinder::RFFHitFinder(), cluster::TrajCluster::TrajCluster(), and hit::TTHitFinder::TTHitFinder().

253  {
254  collector.produces<std::vector<recob::Hit>>(instance_name);
255 
256  // declare the other products we are creating (if any)
257  if (doWireAssns) { collector.produces<art::Assns<recob::Wire, recob::Hit>>(instance_name); }
258  if (doRawDigitAssns) {
259  collector.produces<art::Assns<raw::RawDigit, recob::Hit>>(instance_name);
260  }
261  } // HitAndAssociationsWriterBase::declare_products()
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
std::vector<recob::Hit> const& recob::HitAndAssociationsWriterBase::peek ( ) const
inlineinherited

Returns a read-only reference to the current list of hits.

Definition at line 412 of file HitCreator.h.

References hits().

412 { return *hits; }
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:444
void recob::HitRefinerAssociator::prepare_associations ( std::vector< recob::Hit > const &  srchits)
protected

Finds out the associations for the specified hits.

Definition at line 521 of file HitCreator.cxx.

References raw::RawDigit::Channel(), recob::Hit::Channel(), recob::Wire::Channel(), recob::HitAndAssociationsWriterBase::CreatePtr(), hits_label, art::Ptr< T >::isNull(), art::errors::ProductNotFound, recob::HitAndAssociationsWriterBase::RawDigitAssns, and recob::HitAndAssociationsWriterBase::WireAssns.

522  {
523  if (!RawDigitAssns && !WireAssns) return; // no associations needed
524  assert(event);
525 
526  // we make the associations anew
527  if (RawDigitAssns) ClearAssociations(*RawDigitAssns);
528 
529  // read the hits; this is going to hurt performances...
530  // no solution to that until there is a way to have a lazy read
532  event->getValidHandle<std::vector<recob::Hit>>(hits_label);
533 
534  // now get the associations
535  if (WireAssns) {
536  // we make the associations anew
537  ClearAssociations(*WireAssns);
538 
539  // find the associations between the hits and the wires
541  if (!HitToWire.isValid()) {
543  << "Can't find the associations between hits and wires produced by '" << hits_label
544  << "'!\n";
545  } // if no association
546 
547  // fill a map of wire vs. channel number
548  std::vector<art::Ptr<recob::Wire>> WireMap;
549  for (size_t iAssn = 0; iAssn < HitToWire.size(); ++iAssn) {
550  art::Ptr<recob::Wire> wire = HitToWire.at(iAssn);
551  if (wire.isNull()) continue;
552  size_t channelID = (size_t)wire->Channel();
553  if (WireMap.size() <= channelID) // expand the map of necessary
554  WireMap.resize(std::max(channelID + 1, 2 * WireMap.size()), {});
555  WireMap[channelID] = std::move(wire);
556  } // for
557 
558  // now go through all the hits...
559  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
560  recob::Hit const& hit = srchits[iHit];
561  size_t channelID = (size_t)hit.Channel();
562 
563  // no association if there is no wire to associate with
564  if ((channelID >= WireMap.size()) || !WireMap[channelID]) continue;
565 
566  // create an association using the same wire pointer
567  WireAssns->addSingle(WireMap[channelID], CreatePtr(iHit));
568  } // for hits
569  } // if wire associations
570 
571  // now get the associations
572  if (RawDigitAssns) {
573  // we make the associations anew
574  ClearAssociations(*RawDigitAssns);
575 
576  // find the associations between the hits and the raw digits
577  art::FindOneP<raw::RawDigit> HitToDigits(hHits, *event, hits_label);
578  if (!HitToDigits.isValid()) {
580  << "Can't find the associations between hits and raw digits"
581  << " produced by '" << hits_label << "'!\n";
582  } // if no association
583 
584  // fill a map of digits vs. channel number
585  std::vector<art::Ptr<raw::RawDigit>> DigitMap;
586  for (size_t iAssn = 0; iAssn < HitToDigits.size(); ++iAssn) {
587  art::Ptr<raw::RawDigit> digits = HitToDigits.at(iAssn);
588  if (digits.isNull()) continue;
589  size_t channelID = (size_t)digits->Channel();
590  if (DigitMap.size() <= channelID) // expand the map of necessary
591  DigitMap.resize(std::max(channelID + 1, 2 * DigitMap.size()), {});
592  DigitMap[channelID] = std::move(digits);
593  } // for
594 
595  // now go through all the hits...
596  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
597  recob::Hit const& hit = srchits[iHit];
598  size_t channelID = (size_t)hit.Channel();
599 
600  // no association if there is no digits to associate with
601  if ((channelID >= DigitMap.size()) || !DigitMap[channelID]) continue;
602 
603  // create an association using the same digits pointer
604  RawDigitAssns->addSingle(DigitMap[channelID], CreatePtr(iHit));
605  } // for hits
606  } // if digit associations
607 
608  } // HitRefinerAssociator::put_into()
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:213
std::unique_ptr< art::Assns< recob::Wire, recob::Hit > > WireAssns
Associations with wires.
Definition: HitCreator.h:446
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:223
HitPtr_t CreatePtr(size_t index) const
Creates an art pointer to the hit with the specified index.
Definition: HitCreator.h:470
details::FindAllP< recob::Hit, recob::Wire > HitToWire
Query object connecting a hit to a wire.
Definition: HitUtils.h:54
bool isNull() const noexcept
Definition: Ptr.h:211
Detector simulation of raw signals on wires.
art::InputTag hits_label
Label of the collection of hits.
Definition: HitCreator.h:862
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::unique_ptr< art::Assns< raw::RawDigit, recob::Hit > > RawDigitAssns
Associations with raw digits.
Definition: HitCreator.h:448
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:268
Definition: fwd.h:26
Event finding and building.
void recob::HitRefinerAssociator::prepare_associations ( )
inlineprotected

Finds out the associations for the current hits.

Definition at line 868 of file HitCreator.h.

References hits(), and prepare_associations().

Referenced by prepare_associations(), and put_into().

void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:868
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:444
void recob::HitRefinerAssociator::put_into ( art::Event )
inline

Moves the data into the event.

The calling module must have already declared the production of these products with the proper instance name. After the move, the collections in this object are empty.

Deprecated:
Use the version with no arguments instead.

Definition at line 850 of file HitCreator.h.

References put_into().

Referenced by lar_cluster3d::SpacePointHit3DBuilder::Hit3DBuilder(), cluster::LineCluster::produce(), cluster::TrajCluster::produce(), and put_into().

850 { put_into(); }
void put_into()
Moves the data into the event.
Definition: HitCreator.cxx:514
void recob::HitRefinerAssociator::put_into ( )

Moves the data into the event.

The calling module must have already declared the production of these products with the proper instance name. After the move, the collections in this object are empty.

Definition at line 514 of file HitCreator.cxx.

References prepare_associations(), and recob::HitAndAssociationsWriterBase::put_into().

515  {
518  } // HitRefinerAssociator::put_into()
void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:868
void put_into()
Moves the data into the event.
Definition: HitCreator.cxx:264
size_t recob::HitAndAssociationsWriterBase::size ( ) const
inlineinherited

Returns the number of hits currently in the collection.

Definition at line 389 of file HitCreator.h.

References hits().

389 { return hits ? hits->size() : 0; }
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:444
void recob::HitRefinerAssociator::use_hits ( std::unique_ptr< std::vector< recob::Hit >> &&  srchits)

Uses the specified collection as data product.

Parameters
srchitsthe collection to be used as data product

The very same collection is put into the event. This object will temporary own the collection until the hits are put into the event. If there were previous hits in the object, they are lost.

Definition at line 508 of file HitCreator.cxx.

References recob::HitAndAssociationsWriterBase::hits.

Referenced by lar_cluster3d::SpacePointHit3DBuilder::Hit3DBuilder(), cluster::LineCluster::produce(), and cluster::TrajCluster::produce().

509  {
510  hits = std::move(srchits);
511  } // HitRefinerAssociator::use_hits()
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:444

Member Data Documentation

art::Event* recob::HitAndAssociationsWriterBase::event = nullptr
protectedinherited

Pointer to the event we are using.

Definition at line 450 of file HitCreator.h.

art::PtrMaker<recob::Hit> recob::HitAndAssociationsWriterBase::hitPtrMaker
protectedinherited

Tool to create hit pointers,.

Definition at line 452 of file HitCreator.h.

art::InputTag recob::HitRefinerAssociator::hits_label
protected

Label of the collection of hits.

Definition at line 862 of file HitCreator.h.

Referenced by prepare_associations().

std::string recob::HitAndAssociationsWriterBase::prod_instance
protectedinherited

Tame of the instance for data products.

Definition at line 441 of file HitCreator.h.

Referenced by recob::HitAndAssociationsWriterBase::put_into().


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