LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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
template<typename ModuleType >
 HitRefinerAssociator (ModuleType &producer, 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...
 
template<typename ModuleType >
 HitRefinerAssociator (ModuleType &producer, 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

template<typename ModuleType >
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. 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 865 of file HitCreator.h.

Member Typedef Documentation

Type of art pointer to Hit.

Definition at line 462 of file HitCreator.h.

Constructor & Destructor Documentation

template<typename ModuleType >
recob::HitRefinerAssociator::HitRefinerAssociator ( ModuleType &  producer,
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.

Template Parameters
ModuleTypetype of producing module (EDProducer or EDFilter)
Parameters
producerthe module producing the data products
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 1141 of file HitCreator.h.

References recob::HitAndAssociationsWriterBase::hits.

1148  (producer, event, instance_name, doWireAssns, doRawDigitAssns)
1149  , hits_label(HitModuleLabel)
1150 {
1151  hits.reset(new std::vector<recob::Hit>);
1152 } // recob::HitRefinerAssociator::HitRefinerAssociator()
HitAndAssociationsWriterBase(ModuleType &producer, art::Event &event, std::string instance_name, bool doWireAssns, bool doRawDigitAssns)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.h:1097
art::InputTag hits_label
Label of the collection of hits.
Definition: HitCreator.h:952
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:467
template<typename ModuleType >
recob::HitRefinerAssociator::HitRefinerAssociator ( ModuleType &  producer,
art::Event event,
art::InputTag const &  HitModuleLabel,
bool  doWireAssns,
bool  doRawDigitAssns = true 
)
inline

Constructor: sets instance name and whether to build associations.

Template Parameters
ModuleTypetype of producing module (EDProducer or EDFilter)
Parameters
producerthe module producing the data products
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 904 of file HitCreator.h.

908  :
910  (producer, event, HitModuleLabel, "", doWireAssns, doRawDigitAssns)
911  {}
HitRefinerAssociator(ModuleType &producer, 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.h:1141

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 499 of file HitCreator.h.

499 { return hitPtrMaker(index); }
art::PtrMaker< recob::Hit > hitPtrMaker
Tool to create hit pointers,.
Definition: HitCreator.h:475
template<typename ModuleType >
void recob::HitAndAssociationsWriterBase::declare_products ( ModuleType &  producer,
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 1117 of file HitCreator.h.

Referenced by apa::APAHitFinder::APAHitFinder(), cluster::ClusterCrawler::ClusterCrawler(), CRHitRemoval::CRHitRemoval(), recob::HitAndAssociationsWriterManager< Writer, ModuleType >::declareProducts(), 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::SimpleLineCluster::SimpleLineCluster(), cluster::TrajCluster::TrajCluster(), and hit::TTHitFinder::TTHitFinder().

1121  {
1122  producer.template produces<std::vector<recob::Hit>>(instance_name);
1123 
1124  // declare the other products we are creating (if any)
1125  if (doWireAssns) {
1126  producer.template produces<art::Assns<recob::Wire, recob::Hit>>
1127  (instance_name);
1128  }
1129  if (doRawDigitAssns) {
1130  producer.template produces<art::Assns<raw::RawDigit, recob::Hit>>
1131  (instance_name);
1132  }
1133 
1134 } // recob::HitAndAssociationsWriterBase::declare_products()
std::vector<recob::Hit> const& recob::HitAndAssociationsWriterBase::peek ( ) const
inlineinherited

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

Definition at line 433 of file HitCreator.h.

References hits().

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

Finds out the associations for the specified hits.

Definition at line 446 of file HitCreator.cxx.

References raw::RawDigit::Channel(), recob::Wire::Channel(), recob::Hit::Channel(), art::Ptr< T >::isNull(), max, and art::errors::ProductNotFound.

447  {
448  if (!RawDigitAssns && !WireAssns) return; // no associations needed
449  assert(event);
450 
451  // we make the associations anew
452  if (RawDigitAssns) ClearAssociations(*RawDigitAssns);
453 
454  // read the hits; this is going to hurt performances...
455  // no solution to that until there is a way to have a lazy read
457  = event->getValidHandle<std::vector<recob::Hit>>(hits_label);
458 
459  // now get the associations
460  if (WireAssns) {
461  // we make the associations anew
462  ClearAssociations(*WireAssns);
463 
464  // find the associations between the hits and the wires
466  if (!HitToWire.isValid()) {
468  << "Can't find the associations between hits and wires produced by '"
469  << hits_label << "'!\n";
470  } // if no association
471 
472  // fill a map of wire vs. channel number
473  std::vector<art::Ptr<recob::Wire>> WireMap;
474  for (size_t iAssn = 0; iAssn < HitToWire.size(); ++iAssn) {
475  art::Ptr<recob::Wire> wire = HitToWire.at(iAssn);
476  if (wire.isNull()) continue;
477  size_t channelID = (size_t) wire->Channel();
478  if (WireMap.size() <= channelID) // expand the map of necessary
479  WireMap.resize(std::max(channelID + 1, 2 * WireMap.size()), {});
480  WireMap[channelID] = std::move(wire);
481  } // for
482 
483  // now go through all the hits...
484  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
485  recob::Hit const& hit = srchits[iHit];
486  size_t channelID = (size_t) hit.Channel();
487 
488  // no association if there is no wire to associate with
489  if ((channelID >= WireMap.size()) || !WireMap[channelID]) continue;
490 
491  // create an association using the same wire pointer
492  WireAssns->addSingle(WireMap[channelID], CreatePtr(iHit));
493  } // for hits
494  } // if wire associations
495 
496  // now get the associations
497  if (RawDigitAssns) {
498  // we make the associations anew
499  ClearAssociations(*RawDigitAssns);
500 
501  // find the associations between the hits and the raw digits
502  art::FindOneP<raw::RawDigit> HitToDigits(hHits, *event, hits_label);
503  if (!HitToDigits.isValid()) {
505  << "Can't find the associations between hits and raw digits"
506  << " produced by '" << hits_label << "'!\n";
507  } // if no association
508 
509  // fill a map of digits vs. channel number
510  std::vector<art::Ptr<raw::RawDigit>> DigitMap;
511  for (size_t iAssn = 0; iAssn < HitToDigits.size(); ++iAssn) {
512  art::Ptr<raw::RawDigit> digits = HitToDigits.at(iAssn);
513  if (digits.isNull()) continue;
514  size_t channelID = (size_t) digits->Channel();
515  if (DigitMap.size() <= channelID) // expand the map of necessary
516  DigitMap.resize(std::max(channelID + 1, 2 * DigitMap.size()), {});
517  DigitMap[channelID] = std::move(digits);
518  } // for
519 
520  // now go through all the hits...
521  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
522  recob::Hit const& hit = srchits[iHit];
523  size_t channelID = (size_t) hit.Channel();
524 
525  // no association if there is no digits to associate with
526  if ((channelID >= DigitMap.size()) || !DigitMap[channelID]) continue;
527 
528  // create an association using the same digits pointer
529  RawDigitAssns->addSingle(DigitMap[channelID], CreatePtr(iHit));
530  } // for hits
531  } // if digit associations
532 
533  } // HitRefinerAssociator::put_into()
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:211
std::unique_ptr< art::Assns< recob::Wire, recob::Hit > > WireAssns
Associations with wires.
Definition: HitCreator.h:469
Int_t max
Definition: plot.C:27
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:164
HitPtr_t CreatePtr(size_t index) const
Creates an art pointer to the hit with the specified index.
Definition: HitCreator.h:499
details::FindAllP< recob::Hit, recob::Wire > HitToWire
Query object connecting a hit to a wire.
Definition: HitUtils.h:56
Detector simulation of raw signals on wires.
art::InputTag hits_label
Label of the collection of hits.
Definition: HitCreator.h:952
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:471
bool isNull() const
Definition: Ptr.h:328
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:231
Definition: fwd.h:25
Event finding and building.
void recob::HitRefinerAssociator::prepare_associations ( )
inlineprotected

Finds out the associations for the current hits.

Definition at line 958 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:958
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:467
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 939 of file HitCreator.h.

References put_into().

Referenced by cluster::TrajCluster::produce(), and put_into().

939 { put_into(); }
void put_into()
Moves the data into the event.
Definition: HitCreator.cxx:438
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 438 of file HitCreator.cxx.

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

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

Returns the number of hits currently in the collection.

Definition at line 408 of file HitCreator.h.

References hits().

408 { return hits? hits->size(): 0; }
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:467
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 431 of file HitCreator.cxx.

References hits().

Referenced by recob::HitCollectionAssociator::prepare_associations(), cluster::SimpleLineCluster::produce(), and cluster::TrajCluster::produce().

432  {
433  hits = std::move(srchits);
434  } // HitRefinerAssociator::use_hits()
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:467

Member Data Documentation

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

Pointer to the event we are using.

Definition at line 473 of file HitCreator.h.

Referenced by recob::HitAndAssociationsWriterManager< Writer, ModuleType >::collectionWriter().

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

Tool to create hit pointers,.

Definition at line 475 of file HitCreator.h.

std::unique_ptr<std::vector<recob::Hit> > recob::HitAndAssociationsWriterBase::hits
protectedinherited
art::InputTag recob::HitRefinerAssociator::hits_label
protected

Label of the collection of hits.

Definition at line 952 of file HitCreator.h.

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

Tame of the instance for data products.

Definition at line 464 of file HitCreator.h.

std::unique_ptr<art::Assns<raw::RawDigit, recob::Hit> > recob::HitAndAssociationsWriterBase::RawDigitAssns
protectedinherited

Associations with raw digits.

Definition at line 471 of file HitCreator.h.

Referenced by recob::HitCollectionAssociator::HitCollectionAssociator().

std::unique_ptr<art::Assns<recob::Wire, recob::Hit> > recob::HitAndAssociationsWriterBase::WireAssns
protectedinherited

Associations with wires.

Definition at line 469 of file HitCreator.h.

Referenced by recob::HitCollectionAssociator::HitCollectionAssociator().


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