LArSoft  v09_90_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 650 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::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 343 of file HitCreator.cxx.

References recob::HitAndAssociationsWriterBase::hits.

348  instance_name,
349  WireModuleLabel != "",
350  RawDigitModuleLabel != "")
351  , wires_label(WireModuleLabel)
352  , digits_label(RawDigitModuleLabel)
353  {
354  hits.reset(new std::vector<recob::Hit>);
355  } // 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:235
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:761
art::InputTag digits_label
Label of raw digits collection to associate.
Definition: HitCreator.h:763
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:444
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 682 of file HitCreator.h.

685  : HitCollectionAssociator(event, "", WireModuleLabel, RawDigitModuleLabel)
686  {}
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:343
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 358 of file HitCreator.cxx.

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

363  : HitAndAssociationsWriterBase(event, instance_name, WireModuleLabel != "", doRawDigitAssns)
364  , wires_label(WireModuleLabel)
365  , digits_label()
366  {
367  if (RawDigitAssns && !WireAssns) {
369  << "HitCollectionAssociator can't create hit <--> raw digit"
370  " associations through wires, without wires!\n";
371  }
372  hits.reset(new std::vector<recob::Hit>);
373  } // 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:235
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:761
std::unique_ptr< art::Assns< recob::Wire, recob::Hit > > WireAssns
Associations with wires.
Definition: HitCreator.h:446
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:763
std::unique_ptr< art::Assns< raw::RawDigit, recob::Hit > > RawDigitAssns
Associations with raw digits.
Definition: HitCreator.h:448
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:444
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 718 of file HitCreator.h.

721  : HitCollectionAssociator(event, "", WireModuleLabel, doRawDigitAssns)
722  {}
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:343

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 prepare_associations(), and recob::HitRefinerAssociator::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::HitCollectionAssociator::prepare_associations ( std::vector< recob::Hit > const &  srchits)
protected

Finds out the associations for the specified hits.

Definition at line 389 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.

390  {
391  if (!RawDigitAssns && !WireAssns) return; // no associations needed
392  assert(event);
393 
394  // we make the associations anew
395  if (RawDigitAssns) ClearAssociations(*RawDigitAssns);
396  if (WireAssns) ClearAssociations(*WireAssns);
397 
398  // the following is true is we want associations with digits
399  // but we don't know where digits are; in that case, we try to use wires
400  const bool bUseWiresForDigits = RawDigitAssns && (digits_label == "");
401 
402  if (WireAssns || bUseWiresForDigits) {
403  // do we use wires for digit associations too?
404 
405  // get the wire collection
407  event->getValidHandle<std::vector<recob::Wire>>(wires_label);
408 
409  // fill a map of wire index vs. channel number
410  std::vector<size_t> WireMap = util::MakeIndex(*hWires, std::mem_fn(&recob::Wire::Channel));
411 
412  // use raw rigit - wire association, assuming they have been produced
413  // by the same producer as the wire and with the same instance name;
414  // we don't check whether the data product is found, but the following
415  // code will have FindOneP throw if that was not the case
416  // (that's what we would do here anyway, maybe with a better message...)
417  std::unique_ptr<art::FindOneP<raw::RawDigit>> WireToDigit;
418  if (bUseWiresForDigits) {
419  WireToDigit.reset(new art::FindOneP<raw::RawDigit>(hWires, *event, wires_label));
420  }
421 
422  // add associations, hit by hit:
423  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
424 
425  // find the channel
426  size_t iChannel = size_t(srchits[iHit].Channel()); // forcibly converted
427 
428  // find the wire associated to that channel
429  size_t iWire = std::numeric_limits<size_t>::max();
430  if (iChannel < WireMap.size()) iWire = WireMap[iChannel];
431  if (iWire == std::numeric_limits<size_t>::max()) {
433  << "No wire associated to channel #" << iChannel << " whence hit #" << iHit
434  << " comes!\n";
435  } // if no channel
436 
437  // make the association with wires
438  if (WireAssns) {
439  art::Ptr<recob::Wire> wire(hWires, iWire);
440  WireAssns->addSingle(wire, CreatePtr(iHit));
441  }
442 
443  if (bUseWiresForDigits) {
444  // find the digit associated to that channel
445  art::Ptr<raw::RawDigit> const& digit = WireToDigit->at(iWire);
446  if (digit.isNull()) {
448  << "No raw digit associated to channel #" << iChannel << " whence hit #" << iHit
449  << " comes!\n";
450  } // if no channel
451 
452  // make the association
453  RawDigitAssns->addSingle(digit, CreatePtr(iHit));
454  } // if create digit associations through wires
455  } // for hit
456 
457  } // if wire associations
458 
459  if (RawDigitAssns && !bUseWiresForDigits) {
460  // get the digit collection
462  event->getValidHandle<std::vector<raw::RawDigit>>(digits_label);
463 
464  // fill a map of wire index vs. channel number
465  std::vector<size_t> DigitMap =
466  util::MakeIndex(*hDigits, std::mem_fn(&raw::RawDigit::Channel));
467 
468  // add associations, hit by hit:
469  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
470 
471  // find the channel
472  size_t iChannel = size_t(srchits[iHit].Channel()); // forcibly converted
473 
474  // find the digit associated to that channel
475  size_t iDigit = std::numeric_limits<size_t>::max();
476  if (iChannel < DigitMap.size()) iDigit = DigitMap[iChannel];
477  if (iDigit == std::numeric_limits<size_t>::max()) {
479  << "No raw digit associated to channel #" << iChannel << " whence hit #" << iHit
480  << " comes!\n";
481  } // if no channel
482 
483  // make the association
484  art::Ptr<raw::RawDigit> digit(hDigits, iDigit);
485  RawDigitAssns->addSingle(digit, CreatePtr(iHit));
486 
487  } // for hit
488  } // if we have rawdigit label
489 
490  } // HitCollectionAssociator::put_into()
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:761
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
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:470
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:763
std::unique_ptr< art::Assns< raw::RawDigit, recob::Hit > > RawDigitAssns
Associations with raw digits.
Definition: HitCreator.h:448
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 769 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:769
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:444
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 748 of file HitCreator.h.

References put_into().

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

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

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

383  {
386  } // HitCollectionAssociator::put_into()
void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:769
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::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 376 of file HitCreator.cxx.

References recob::HitAndAssociationsWriterBase::hits.

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

377  {
378  hits = std::move(srchits);
379  } // HitCollectionAssociator::use_hits()
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:444

Member Data Documentation

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

Label of raw digits collection to associate.

Definition at line 763 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 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.

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().

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

Referenced by prepare_associations().


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