Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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...
 
Constructors
 HitRefinerAssociator (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...
 
 HitRefinerAssociator (art::Event &event, art::InputTag const &HitModuleLabel, bool doWireAssns, bool doRawDigitAssns=true)
 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 hits_label
 Label of the collection of hits. 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::Eventevent = 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 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 842 of file HitCreator.h.

Constructor & Destructor Documentation

recob::HitRefinerAssociator::HitRefinerAssociator ( 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.

Parameters
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 513 of file HitCreator.cxx.

520  (event, instance_name, doWireAssns, doRawDigitAssns)
521  , hits_label(HitModuleLabel)
522  {
523  hits.reset(new std::vector<recob::Hit>);
524  } // HitRefinerAssociator::HitRefinerAssociator()
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 hits_label
Label of the collection of hits.
Definition: HitCreator.h:921
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:465
recob::HitRefinerAssociator::HitRefinerAssociator ( art::Event event,
art::InputTag const &  HitModuleLabel,
bool  doWireAssns,
bool  doRawDigitAssns = true 
)
inline

Constructor: sets instance name and whether to build associations.

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

877  :
879  (event, HitModuleLabel, "", doWireAssns, doRawDigitAssns)
880  {}
HitRefinerAssociator(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.cxx:513

Member Function Documentation

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

Finds out the associations for the specified hits.

Definition at line 543 of file HitCreator.cxx.

544  {
545  if (!RawDigitAssns && !WireAssns) return; // no associations needed
546  assert(event);
547 
548  // we make the associations anew
549  if (RawDigitAssns) ClearAssociations(*RawDigitAssns);
550 
551  // read the hits; this is going to hurt performances...
552  // no solution to that until there is a way to have a lazy read
554  = event->getValidHandle<std::vector<recob::Hit>>(hits_label);
555 
556  // now get the associations
557  if (WireAssns) {
558  // we make the associations anew
559  ClearAssociations(*WireAssns);
560 
561  // find the associations between the hits and the wires
562  art::FindOneP<recob::Wire> HitToWire(hHits, *event, hits_label);
563  if (!HitToWire.isValid()) {
565  << "Can't find the associations between hits and wires produced by '"
566  << hits_label << "'!\n";
567  } // if no association
568 
569  // fill a map of wire vs. channel number
570  std::vector<art::Ptr<recob::Wire>> WireMap;
571  for (size_t iAssn = 0; iAssn < HitToWire.size(); ++iAssn) {
572  art::Ptr<recob::Wire> wire = HitToWire.at(iAssn);
573  if (wire.isNull()) continue;
574  size_t channelID = (size_t) wire->Channel();
575  if (WireMap.size() <= channelID) // expand the map of necessary
576  WireMap.resize(std::max(channelID + 1, 2 * WireMap.size()), {});
577  WireMap[channelID] = std::move(wire);
578  } // for
579 
580  // now go through all the hits...
581  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
582  recob::Hit const& hit = srchits[iHit];
583  size_t channelID = (size_t) hit.Channel();
584 
585  // no association if there is no wire to associate with
586  if ((channelID >= WireMap.size()) || !WireMap[channelID]) continue;
587 
588  // create an association using the same wire pointer
589  WireAssns->addSingle(WireMap[channelID], CreatePtr(iHit));
590  } // for hits
591  } // if wire associations
592 
593  // now get the associations
594  if (RawDigitAssns) {
595  // we make the associations anew
596  ClearAssociations(*RawDigitAssns);
597 
598  // find the associations between the hits and the raw digits
599  art::FindOneP<raw::RawDigit> HitToDigits(hHits, *event, hits_label);
600  if (!HitToDigits.isValid()) {
602  << "Can't find the associations between hits and raw digits"
603  << " produced by '" << hits_label << "'!\n";
604  } // if no association
605 
606  // fill a map of digits vs. channel number
607  std::vector<art::Ptr<raw::RawDigit>> DigitMap;
608  for (size_t iAssn = 0; iAssn < HitToDigits.size(); ++iAssn) {
609  art::Ptr<raw::RawDigit> digits = HitToDigits.at(iAssn);
610  if (digits.isNull()) continue;
611  size_t channelID = (size_t) digits->Channel();
612  if (DigitMap.size() <= channelID) // expand the map of necessary
613  DigitMap.resize(std::max(channelID + 1, 2 * DigitMap.size()), {});
614  DigitMap[channelID] = std::move(digits);
615  } // for
616 
617  // now go through all the hits...
618  for (size_t iHit = 0; iHit < srchits.size(); ++iHit) {
619  recob::Hit const& hit = srchits[iHit];
620  size_t channelID = (size_t) hit.Channel();
621 
622  // no association if there is no digits to associate with
623  if ((channelID >= DigitMap.size()) || !DigitMap[channelID]) continue;
624 
625  // create an association using the same digits pointer
626  RawDigitAssns->addSingle(DigitMap[channelID], CreatePtr(iHit));
627  } // for hits
628  } // if digit associations
629 
630  } // HitRefinerAssociator::put_into()
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
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:231
def move(depos, offset)
Definition: depos.py:107
HitPtr_t CreatePtr(size_t index) const
Creates an art pointer to the hit with the specified index.
Definition: HitCreator.h:494
details::FindAllP< recob::Hit, recob::Wire > HitToWire
Query object connecting a hit to a wire.
Definition: HitUtils.h:56
bool isNull() const noexcept
Definition: Ptr.h:173
static int max(int a, int b)
Detector simulation of raw signals on wires.
art::InputTag hits_label
Label of the collection of hits.
Definition: HitCreator.h:921
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:469
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:230
Event finding and building.
void recob::HitRefinerAssociator::prepare_associations ( )
inlineprotected

Finds out the associations for the current hits.

Definition at line 927 of file HitCreator.h.

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

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

535  {
538  } // HitRefinerAssociator::put_into()
void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:927
void put_into()
Moves the data into the event.
Definition: HitCreator.cxx:267
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 528 of file HitCreator.cxx.

529  {
530  hits = std::move(srchits);
531  } // HitRefinerAssociator::use_hits()
def move(depos, offset)
Definition: depos.py:107
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:465

Member Data Documentation

art::InputTag recob::HitRefinerAssociator::hits_label
protected

Label of the collection of hits.

Definition at line 921 of file HitCreator.h.


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