LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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
template<typename ModuleType >
 HitCollectionAssociator (ModuleType &producer, 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...
 
template<typename ModuleType >
 HitCollectionAssociator (ModuleType &producer, art::Event &event, art::InputTag const &WireModuleLabel, art::InputTag const &RawDigitModuleLabel)
 Constructor: sets instance name and whether to build associations. More...
 
template<typename ModuleType >
 HitCollectionAssociator (ModuleType &producer, art::Event &event, std::string instance_name, art::InputTag const &WireModuleLabel, bool doRawDigitAssns)
 Constructor: sets instance name and whether to build associations. More...
 
template<typename ModuleType >
 HitCollectionAssociator (ModuleType &producer, art::Event &event, art::InputTag const &WireModuleLabel, bool doRawDigitAssns)
 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 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 703 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::HitCollectionAssociator::HitCollectionAssociator ( ModuleType &  producer,
art::Event event,
std::string  instance_name,
art::InputTag const &  WireModuleLabel,
art::InputTag const &  RawDigitModuleLabel 
)

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

References recob::HitAndAssociationsWriterBase::hits.

1182  producer, event, instance_name,
1183  WireModuleLabel != "", RawDigitModuleLabel != ""
1184  )
1185  , wires_label(WireModuleLabel)
1186  , digits_label(RawDigitModuleLabel)
1187 {
1188  hits.reset(new std::vector<recob::Hit>);
1189 } // recob::HitCollectionAssociator::HitCollectionAssociator()
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:838
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 digits_label
Label of raw digits collection to associate.
Definition: HitCreator.h:840
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:467
template<typename ModuleType >
recob::HitCollectionAssociator::HitCollectionAssociator ( ModuleType &  producer,
art::Event event,
art::InputTag const &  WireModuleLabel,
art::InputTag const &  RawDigitModuleLabel 
)
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
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 743 of file HitCreator.h.

747  :
749  (producer, event, "", WireModuleLabel, RawDigitModuleLabel)
750  {}
HitCollectionAssociator(ModuleType &producer, 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.h:1175
template<typename ModuleType >
recob::HitCollectionAssociator::HitCollectionAssociator ( ModuleType &  producer,
art::Event event,
std::string  instance_name,
art::InputTag const &  WireModuleLabel,
bool  doRawDigitAssns 
)

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

References recob::HitAndAssociationsWriterManager< Writer, ModuleType >::HitAndAssociationsWriterManager(), recob::HitAndAssociationsWriterBase::hits, art::errors::LogicError, recob::HitAndAssociationsWriterBase::RawDigitAssns, and recob::HitAndAssociationsWriterBase::WireAssns.

1201  producer, event, instance_name,
1202  WireModuleLabel != "", doRawDigitAssns
1203  )
1204  , wires_label(WireModuleLabel)
1205  , digits_label()
1206 {
1207  if (RawDigitAssns && !WireAssns) {
1209  << "HitCollectionAssociator can't create hit <--> raw digit"
1210  " associations through wires, without wires!\n";
1211  }
1212  hits.reset(new std::vector<recob::Hit>);
1213 } // recob::HitCollectionAssociator::HitCollectionAssociator()
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:838
std::unique_ptr< art::Assns< recob::Wire, recob::Hit > > WireAssns
Associations with wires.
Definition: HitCreator.h:469
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
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:840
std::unique_ptr< art::Assns< raw::RawDigit, recob::Hit > > RawDigitAssns
Associations with raw digits.
Definition: HitCreator.h:471
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:467
template<typename ModuleType >
recob::HitCollectionAssociator::HitCollectionAssociator ( ModuleType &  producer,
art::Event event,
art::InputTag const &  WireModuleLabel,
bool  doRawDigitAssns 
)
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
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 790 of file HitCreator.h.

794  :
796  (producer, event, "", WireModuleLabel, doRawDigitAssns)
797  {}
HitCollectionAssociator(ModuleType &producer, 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.h:1175

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

Finds out the associations for the specified hits.

Definition at line 321 of file HitCreator.cxx.

References raw::RawDigit::Channel(), recob::Wire::Channel(), art::Ptr< T >::isNull(), art::errors::LogicError, util::MakeIndex(), max, and recob::HitRefinerAssociator::use_hits().

322  {
323  if (!RawDigitAssns && !WireAssns) return; // no associations needed
324  assert(event);
325 
326  // we make the associations anew
327  if (RawDigitAssns) ClearAssociations(*RawDigitAssns);
328  if (WireAssns) ClearAssociations(*WireAssns);
329 
330  // the following is true is we want associations with digits
331  // but we don't know where digits are; in that case, we try to use wires
332  const bool bUseWiresForDigits = RawDigitAssns && (digits_label == "");
333 
334  if (WireAssns || bUseWiresForDigits) {
335  // do we use wires for digit associations too?
336 
337  // get the wire collection
339  = event->getValidHandle<std::vector<recob::Wire>>(wires_label);
340 
341  // fill a map of wire index vs. channel number
342  std::vector<size_t> WireMap
343  = util::MakeIndex(*hWires, std::mem_fn(&recob::Wire::Channel));
344 
345  // use raw rigit - wire association, assuming they have been produced
346  // by the same producer as the wire and with the same instance name;
347  // we don't check whether the data product is found, but the following
348  // code will have FindOneP throw if that was not the case
349  // (that's what we would do here anyway, maybe with a better message...)
350  std::unique_ptr<art::FindOneP<raw::RawDigit>> WireToDigit;
351  if (bUseWiresForDigits) {
352  WireToDigit.reset
354  }
355 
356  // add associations, hit by hit:
357  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
358 
359  // find the channel
360  size_t iChannel = size_t(srchits[iHit].Channel()); // forcibly converted
361 
362  // find the wire associated to that channel
363  size_t iWire = std::numeric_limits<size_t>::max();
364  if (iChannel < WireMap.size()) iWire = WireMap[iChannel];
365  if (iWire == std::numeric_limits<size_t>::max()) {
367  << "No wire associated to channel #" << iChannel << " whence hit #"
368  << iHit << " comes!\n";
369  } // if no channel
370 
371  // make the association with wires
372  if (WireAssns) {
373  art::Ptr<recob::Wire> wire(hWires, iWire);
374  WireAssns->addSingle(wire, CreatePtr(iHit));
375  }
376 
377  if (bUseWiresForDigits) {
378  // find the digit associated to that channel
379  art::Ptr<raw::RawDigit> const& digit = WireToDigit->at(iWire);
380  if (digit.isNull()) {
382  << "No raw digit associated to channel #" << iChannel
383  << " whence hit #" << iHit << " comes!\n";
384  } // if no channel
385 
386  // make the association
387  RawDigitAssns->addSingle(digit, CreatePtr(iHit));
388  } // if create digit associations through wires
389  } // for hit
390 
391  } // if wire associations
392 
393  if (RawDigitAssns && !bUseWiresForDigits) {
394  // get the digit collection
396  = event->getValidHandle<std::vector<raw::RawDigit>>(digits_label);
397 
398  // fill a map of wire index vs. channel number
399  std::vector<size_t> DigitMap
400  = util::MakeIndex(*hDigits, std::mem_fn(&raw::RawDigit::Channel));
401 
402  // add associations, hit by hit:
403  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
404 
405  // find the channel
406  size_t iChannel = size_t(srchits[iHit].Channel()); // forcibly converted
407 
408  // find the digit associated to that channel
409  size_t iDigit = std::numeric_limits<size_t>::max();
410  if (iChannel < DigitMap.size()) iDigit = DigitMap[iChannel];
411  if (iDigit == std::numeric_limits<size_t>::max()) {
413  << "No raw digit associated to channel #" << iChannel
414  << " whence hit #" << iHit << " comes!\n";
415  } // if no channel
416 
417  // make the association
418  art::Ptr<raw::RawDigit> digit(hDigits, iDigit);
419  RawDigitAssns->addSingle(digit, CreatePtr(iHit));
420 
421  } // for hit
422  } // if we have rawdigit label
423 
424  } // HitCollectionAssociator::put_into()
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:838
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
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
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
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:840
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
Definition: fwd.h:25
Event finding and building.
void recob::HitCollectionAssociator::prepare_associations ( )
inlineprotected

Finds out the associations for the current hits.

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

References put_into().

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

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

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

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

References hits().

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

307  {
308  hits = std::move(srchits);
309  } // HitCollectionAssociator::use_hits()
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:467

Member Data Documentation

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

Label of raw digits collection to associate.

Definition at line 840 of file HitCreator.h.

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

art::InputTag recob::HitCollectionAssociator::wires_label
protected

Label of the collection of wires to associate.

Definition at line 838 of file HitCreator.h.


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