LArSoft  v09_93_00
Liquid Argon Software toolkit - https://larsoft.org/
recob::HitCollectionAssociator Class Reference

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

#include "HitCreator.h"

Inheritance diagram for recob::HitCollectionAssociator:
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
 HitCollectionAssociator (art::Event &event, std::string instance_name, art::InputTag const &WireModuleLabel, art::InputTag const &RawDigitModuleLabel)
 Constructor: sets instance name and whether to build associations. More...
 
 HitCollectionAssociator (art::Event &event, art::InputTag const &WireModuleLabel, art::InputTag const &RawDigitModuleLabel)
 Constructor: sets instance name and whether to build associations. More...
 
 HitCollectionAssociator (art::Event &event, std::string instance_name, art::InputTag const &WireModuleLabel, bool doRawDigitAssns)
 Constructor: sets instance name and whether to build associations. More...
 
 HitCollectionAssociator (art::Event &event, art::InputTag const &WireModuleLabel, bool doRawDigitAssns)
 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 wires_label
 Label of the collection of wires to associate. More...
 
art::InputTag digits_label
 Label of raw digits collection to associate. 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 collection of recob::Hit and you simply want the hits associated to the wire and digit with the same channel.

Definition at line 658 of file HitCreator.h.

Member Typedef Documentation

Type of art pointer to Hit.

Definition at line 447 of file HitCreator.h.

Constructor & Destructor Documentation

recob::HitCollectionAssociator::HitCollectionAssociator ( art::Event event,
std::string  instance_name,
art::InputTag const &  WireModuleLabel,
art::InputTag const &  RawDigitModuleLabel 
)

Constructor: sets instance name and whether to build associations.

Parameters
eventthe event the products are going to be put into
instance_namename of the instance for all data products
WireModuleLabellabel of the module used to create wires
RawDigitModuleLabellabel of the module used to create raw digits

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

If a label is empty, the corresponding association will not be produced.

Definition at line 356 of file HitCreator.cxx.

References recob::HitAndAssociationsWriterBase::hits.

361  instance_name,
362  WireModuleLabel != "",
363  RawDigitModuleLabel != "")
364  , wires_label(WireModuleLabel)
365  , digits_label(RawDigitModuleLabel)
366  {
367  hits.reset(new std::vector<recob::Hit>);
368  } // HitCollectionAssociator::HitCollectionAssociator()
HitAndAssociationsWriterBase(art::Event &event, std::string instance_name, bool doWireAssns, bool doRawDigitAssns)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.cxx:248
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:769
art::InputTag digits_label
Label of raw digits collection to associate.
Definition: HitCreator.h:771
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:452
recob::HitCollectionAssociator::HitCollectionAssociator ( art::Event event,
art::InputTag const &  WireModuleLabel,
art::InputTag const &  RawDigitModuleLabel 
)
inline

Constructor: sets instance name and whether to build associations.

Parameters
eventthe event the products are going to be put into
WireModuleLabellabel of the module used to create wires
RawDigitModuleLabellabel of the module used to create raw digits

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

If a label is empty, the corresponding association will not be produced.

Definition at line 690 of file HitCreator.h.

693  : HitCollectionAssociator(event, "", WireModuleLabel, RawDigitModuleLabel)
694  {}
HitCollectionAssociator(art::Event &event, std::string instance_name, art::InputTag const &WireModuleLabel, art::InputTag const &RawDigitModuleLabel)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.cxx:356
recob::HitCollectionAssociator::HitCollectionAssociator ( art::Event event,
std::string  instance_name,
art::InputTag const &  WireModuleLabel,
bool  doRawDigitAssns 
)

Constructor: sets instance name and whether to build associations.

Parameters
eventthe event the products are going to be put into
instance_namename of the instance for all data products
WireModuleLabellabel of the module used to create wires
doRawDigitAssnswhether to write associations with raw digits

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

The raw digit association is built out of their existing associations with wires, rather than by directly using the raw digits data product.

Definition at line 371 of file HitCreator.cxx.

References recob::HitAndAssociationsWriterBase::hits, art::errors::LogicError, recob::HitAndAssociationsWriterBase::RawDigitAssns, and recob::HitAndAssociationsWriterBase::WireAssns.

376  : HitAndAssociationsWriterBase(event, instance_name, WireModuleLabel != "", doRawDigitAssns)
377  , wires_label(WireModuleLabel)
378  , digits_label()
379  {
380  if (RawDigitAssns && !WireAssns) {
382  << "HitCollectionAssociator can't create hit <--> raw digit"
383  " associations through wires, without wires!\n";
384  }
385  hits.reset(new std::vector<recob::Hit>);
386  } // HitCollectionAssociator::HitCollectionAssociator()
HitAndAssociationsWriterBase(art::Event &event, std::string instance_name, bool doWireAssns, bool doRawDigitAssns)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.cxx:248
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:769
std::unique_ptr< art::Assns< recob::Wire, recob::Hit > > WireAssns
Associations with wires.
Definition: HitCreator.h:454
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
art::InputTag digits_label
Label of raw digits collection to associate.
Definition: HitCreator.h:771
std::unique_ptr< art::Assns< raw::RawDigit, recob::Hit > > RawDigitAssns
Associations with raw digits.
Definition: HitCreator.h:456
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:452
recob::HitCollectionAssociator::HitCollectionAssociator ( art::Event event,
art::InputTag const &  WireModuleLabel,
bool  doRawDigitAssns 
)
inline

Constructor: sets instance name and whether to build associations.

Parameters
eventthe event the products are going to be put into
WireModuleLabellabel of the module used to create wires
doRawDigitAssnswhether to write associations with raw digits

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

The raw digit association is built out of their existing associations with wires, rather than by directly using the raw digits data product.

Definition at line 726 of file HitCreator.h.

729  : HitCollectionAssociator(event, "", WireModuleLabel, doRawDigitAssns)
730  {}
HitCollectionAssociator(art::Event &event, std::string instance_name, art::InputTag const &WireModuleLabel, art::InputTag const &RawDigitModuleLabel)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.cxx:356

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

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

478 { return hitPtrMaker(index); }
art::PtrMaker< recob::Hit > hitPtrMaker
Tool to create hit pointers,.
Definition: HitCreator.h:460
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 261 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().

266  {
267  collector.produces<std::vector<recob::Hit>>(instance_name);
268 
269  // declare the other products we are creating (if any)
270  if (doWireAssns) { collector.produces<art::Assns<recob::Wire, recob::Hit>>(instance_name); }
271  if (doRawDigitAssns) {
272  collector.produces<art::Assns<raw::RawDigit, recob::Hit>>(instance_name);
273  }
274  } // 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 420 of file HitCreator.h.

References hits().

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

Finds out the associations for the specified hits.

Definition at line 402 of file HitCreator.cxx.

References raw::RawDigit::Channel(), recob::Wire::Channel(), recob::HitAndAssociationsWriterBase::CreatePtr(), digits_label, art::Ptr< T >::isNull(), art::errors::LogicError, util::MakeIndex(), recob::HitAndAssociationsWriterBase::RawDigitAssns, recob::HitAndAssociationsWriterBase::WireAssns, and wires_label.

403  {
404  if (!RawDigitAssns && !WireAssns) return; // no associations needed
405  assert(event);
406 
407  // we make the associations anew
408  if (RawDigitAssns) ClearAssociations(*RawDigitAssns);
409  if (WireAssns) ClearAssociations(*WireAssns);
410 
411  // the following is true is we want associations with digits
412  // but we don't know where digits are; in that case, we try to use wires
413  const bool bUseWiresForDigits = RawDigitAssns && (digits_label == "");
414 
415  if (WireAssns || bUseWiresForDigits) {
416  // do we use wires for digit associations too?
417 
418  // get the wire collection
420  event->getValidHandle<std::vector<recob::Wire>>(wires_label);
421 
422  // fill a map of wire index vs. channel number
423  std::vector<size_t> WireMap = util::MakeIndex(*hWires, std::mem_fn(&recob::Wire::Channel));
424 
425  // use raw rigit - wire association, assuming they have been produced
426  // by the same producer as the wire and with the same instance name;
427  // we don't check whether the data product is found, but the following
428  // code will have FindOneP throw if that was not the case
429  // (that's what we would do here anyway, maybe with a better message...)
430  std::unique_ptr<art::FindOneP<raw::RawDigit>> WireToDigit;
431  if (bUseWiresForDigits) {
432  WireToDigit.reset(new art::FindOneP<raw::RawDigit>(hWires, *event, wires_label));
433  }
434 
435  // add associations, hit by hit:
436  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
437 
438  // find the channel
439  size_t iChannel = size_t(srchits[iHit].Channel()); // forcibly converted
440 
441  // find the wire associated to that channel
442  size_t iWire = std::numeric_limits<size_t>::max();
443  if (iChannel < WireMap.size()) iWire = WireMap[iChannel];
444  if (iWire == std::numeric_limits<size_t>::max()) {
446  << "No wire associated to channel #" << iChannel << " whence hit #" << iHit
447  << " comes!\n";
448  } // if no channel
449 
450  // make the association with wires
451  if (WireAssns) {
452  art::Ptr<recob::Wire> wire(hWires, iWire);
453  WireAssns->addSingle(wire, CreatePtr(iHit));
454  }
455 
456  if (bUseWiresForDigits) {
457  // find the digit associated to that channel
458  art::Ptr<raw::RawDigit> const& digit = WireToDigit->at(iWire);
459  if (digit.isNull()) {
461  << "No raw digit associated to channel #" << iChannel << " whence hit #" << iHit
462  << " comes!\n";
463  } // if no channel
464 
465  // make the association
466  RawDigitAssns->addSingle(digit, CreatePtr(iHit));
467  } // if create digit associations through wires
468  } // for hit
469 
470  } // if wire associations
471 
472  if (RawDigitAssns && !bUseWiresForDigits) {
473  // get the digit collection
475  event->getValidHandle<std::vector<raw::RawDigit>>(digits_label);
476 
477  // fill a map of wire index vs. channel number
478  std::vector<size_t> DigitMap =
479  util::MakeIndex(*hDigits, std::mem_fn(&raw::RawDigit::Channel));
480 
481  // add associations, hit by hit:
482  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
483 
484  // find the channel
485  size_t iChannel = size_t(srchits[iHit].Channel()); // forcibly converted
486 
487  // find the digit associated to that channel
488  size_t iDigit = std::numeric_limits<size_t>::max();
489  if (iChannel < DigitMap.size()) iDigit = DigitMap[iChannel];
490  if (iDigit == std::numeric_limits<size_t>::max()) {
492  << "No raw digit associated to channel #" << iChannel << " whence hit #" << iHit
493  << " comes!\n";
494  } // if no channel
495 
496  // make the association
497  art::Ptr<raw::RawDigit> digit(hDigits, iDigit);
498  RawDigitAssns->addSingle(digit, CreatePtr(iHit));
499 
500  } // for hit
501  } // if we have rawdigit label
502 
503  } // HitCollectionAssociator::put_into()
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:769
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:454
std::vector< size_t > MakeIndex(Coll const &data, KeyOf key_of=KeyOf())
Creates a map of indices from an existing collection.
Definition: MakeIndex.h:43
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:478
bool isNull() const noexcept
Definition: Ptr.h:211
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
art::InputTag digits_label
Label of raw digits collection to associate.
Definition: HitCreator.h:771
std::unique_ptr< art::Assns< raw::RawDigit, recob::Hit > > RawDigitAssns
Associations with raw digits.
Definition: HitCreator.h:456
Definition: fwd.h:26
Event finding and building.
void recob::HitCollectionAssociator::prepare_associations ( )
inlineprotected

Finds out the associations for the current hits.

Definition at line 777 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:777
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:452
void recob::HitCollectionAssociator::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 756 of file HitCreator.h.

References put_into().

Referenced by hit::HitFinder::produce(), hit::RFFHitFinder::produce(), cluster::ClusterCrawler::produce(), and put_into().

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

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

396  {
399  } // HitCollectionAssociator::put_into()
void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:777
void put_into()
Moves the data into the event.
Definition: HitCreator.cxx:277
size_t recob::HitAndAssociationsWriterBase::size ( ) const
inlineinherited

Returns the number of hits currently in the collection.

Definition at line 397 of file HitCreator.h.

References hits().

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

References recob::HitAndAssociationsWriterBase::hits.

Referenced by hit::HitFinder::produce(), hit::RFFHitFinder::produce(), and cluster::ClusterCrawler::produce().

390  {
391  hits = std::move(srchits);
392  } // HitCollectionAssociator::use_hits()
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:452

Member Data Documentation

art::InputTag recob::HitCollectionAssociator::digits_label
protected

Label of raw digits collection to associate.

Definition at line 771 of file HitCreator.h.

Referenced by prepare_associations().

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

Pointer to the event we are using.

Definition at line 458 of file HitCreator.h.

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

Tool to create hit pointers,.

Definition at line 460 of file HitCreator.h.

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

Tame of the instance for data products.

Definition at line 449 of file HitCreator.h.

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

std::unique_ptr<art::Assns<raw::RawDigit, recob::Hit> > recob::HitAndAssociationsWriterBase::RawDigitAssns
protectedinherited
std::unique_ptr<art::Assns<recob::Wire, recob::Hit> > recob::HitAndAssociationsWriterBase::WireAssns
protectedinherited
art::InputTag recob::HitCollectionAssociator::wires_label
protected

Label of the collection of wires to associate.

Definition at line 769 of file HitCreator.h.

Referenced by prepare_associations().


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