All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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...
 
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...
 
- Public Member Functions inherited from recob::HitAndAssociationsWriterBase
size_t size () const
 Returns the number of hits currently in the collection. More...
 
void put_into (art::Event &)
 Moves the data into the event. More...
 
void put_into ()
 Moves the data into the event. More...
 
std::vector< recob::Hit > const & peek () const
 Returns a read-only reference to the current list of hits. 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...
 
- Protected Member Functions inherited from recob::HitAndAssociationsWriterBase
 HitAndAssociationsWriterBase (art::Event &event, std::string instance_name, bool doWireAssns, bool doRawDigitAssns)
 Constructor: sets instance name and whether to build associations. 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...
 
- Protected Attributes inherited from recob::HitAndAssociationsWriterBase
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::Event * event = nullptr
 Pointer to the event we are using. More...
 
art::PtrMaker< recob::HithitPtrMaker
 Tool to create hit pointers,. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from recob::HitAndAssociationsWriterBase
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 inherited from recob::HitAndAssociationsWriterBase
using HitPtr_t = art::Ptr< recob::Hit >
 Type of art pointer to Hit. 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 692 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 350 of file HitCreator.cxx.

357  event, instance_name,
358  WireModuleLabel != "", RawDigitModuleLabel != ""
359  )
361  , digits_label(RawDigitModuleLabel)
362  {
363  hits.reset(new std::vector<recob::Hit>);
364  } // 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:233
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:815
art::Event * event
Pointer to the event we are using.
Definition: HitCreator.h:471
process_name ccluster WireModuleLabel
Definition: hitana.fcl:49
art::InputTag digits_label
Label of raw digits collection to associate.
Definition: HitCreator.h:817
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:465
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 726 of file HitCreator.h.

730  :
732  (event, "", WireModuleLabel, RawDigitModuleLabel)
733  {}
art::Event * event
Pointer to the event we are using.
Definition: HitCreator.h:471
process_name ccluster WireModuleLabel
Definition: hitana.fcl:49
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:350
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 367 of file HitCreator.cxx.

374  event, instance_name,
375  WireModuleLabel != "", doRawDigitAssns
376  )
378  , digits_label()
379  {
380  if (RawDigitAssns && !WireAssns) {
381  throw art::Exception(art::errors::LogicError)
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:233
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:815
std::unique_ptr< art::Assns< recob::Wire, recob::Hit > > WireAssns
Associations with wires.
Definition: HitCreator.h:467
art::Event * event
Pointer to the event we are using.
Definition: HitCreator.h:471
process_name ccluster WireModuleLabel
Definition: hitana.fcl:49
art::InputTag digits_label
Label of raw digits collection to associate.
Definition: HitCreator.h:817
std::unique_ptr< art::Assns< raw::RawDigit, recob::Hit > > RawDigitAssns
Associations with raw digits.
Definition: HitCreator.h:469
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:465
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 767 of file HitCreator.h.

771  :
773  (event, "", WireModuleLabel, doRawDigitAssns)
774  {}
art::Event * event
Pointer to the event we are using.
Definition: HitCreator.h:471
process_name ccluster WireModuleLabel
Definition: hitana.fcl:49
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:350

Member Function Documentation

void recob::HitCollectionAssociator::prepare_associations ( std::vector< recob::Hit > const &  srchits)
protected

Finds out the associations for the specified hits.

Definition at line 405 of file HitCreator.cxx.

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

Finds out the associations for the current hits.

Definition at line 823 of file HitCreator.h.

void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:823
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:465
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 801 of file HitCreator.h.

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

397  {
400  } // HitCollectionAssociator::put_into()
void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:823
void put_into()
Moves the data into the event.
Definition: HitCreator.cxx:267
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 390 of file HitCreator.cxx.

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

Member Data Documentation

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

Label of raw digits collection to associate.

Definition at line 817 of file HitCreator.h.

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

Label of the collection of wires to associate.

Definition at line 815 of file HitCreator.h.


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