LArSoft  v09_93_00
Liquid Argon Software toolkit - https://larsoft.org/
HitCreator.h
Go to the documentation of this file.
1 
10 #ifndef LARDATA_ARTDATAHELPERS_HITCREATOR_H
11 #define LARDATA_ARTDATAHELPERS_HITCREATOR_H
12 
13 // LArSoft libraries
17 
18 // framework libraries
25 
26 // C/C++ standard library
27 #include <string>
28 #include <utility> // std::move()
29 #include <vector>
30 
31 namespace geo {
32  struct WireID;
33 }
34 namespace raw {
35  class RawDigit;
36 }
37 namespace art {
38  class ProducesCollector;
39  class Event;
40 }
41 
43 namespace recob {
44 
87  class HitCreator {
88  public:
90  using RegionOfInterest_t = recob::Wire::RegionsOfInterest_t::datarange_t;
91 
92  // destructor, copy and move constructor and assignment as default
93 
119  HitCreator(raw::RawDigit const& digits,
120  geo::WireID const& wireID,
121  raw::TDCtick_t start_tick,
122  raw::TDCtick_t end_tick,
123  float rms,
124  float peak_time,
125  float sigma_peak_time,
126  float peak_amplitude,
127  float sigma_peak_amplitude,
128  float hit_integral,
129  float hit_sigma_integral,
130  float ROIsummedADC,
131  float HitsummedADC,
132  short int multiplicity,
133  short int local_index,
134  float goodness_of_fit,
135  int dof);
136 
162  HitCreator(recob::Wire const& wire,
163  geo::WireID const& wireID,
164  raw::TDCtick_t start_tick,
165  raw::TDCtick_t end_tick,
166  float rms,
167  float peak_time,
168  float sigma_peak_time,
169  float peak_amplitude,
170  float sigma_peak_amplitude,
171  float hit_integral,
172  float hit_sigma_integral,
173  float ROIsummedADC,
174  float HitsummedADC,
175  short int multiplicity,
176  short int local_index,
177  float goodness_of_fit,
178  int dof);
179 
206  HitCreator(recob::Wire const& wire,
207  geo::WireID const& wireID,
208  raw::TDCtick_t start_tick,
209  raw::TDCtick_t end_tick,
210  float rms,
211  float peak_time,
212  float sigma_peak_time,
213  float peak_amplitude,
214  float sigma_peak_amplitude,
215  float hit_integral,
216  float hit_sigma_integral,
217  short int multiplicity,
218  short int local_index,
219  float goodness_of_fit,
220  int dof);
221 
249  HitCreator(recob::Wire const& wire,
250  geo::WireID const& wireID,
251  float rms,
252  float peak_time,
253  float sigma_peak_time,
254  float peak_amplitude,
255  float sigma_peak_amplitude,
256  float hit_integral,
257  float hit_sigma_integral,
258  float ROIsummedADC,
259  float HitsummedADC,
260  short int multiplicity,
261  short int local_index,
262  float goodness_of_fit,
263  int dof,
264  RegionOfInterest_t const& signal);
265 
293  HitCreator(recob::Wire const& wire,
294  geo::WireID const& wireID,
295  float rms,
296  float peak_time,
297  float sigma_peak_time,
298  float peak_amplitude,
299  float sigma_peak_amplitude,
300  float hit_integral,
301  float hit_sigma_integral,
302  float ROIsummedADC,
303  float HitsummedADC,
304  short int multiplicity,
305  short int local_index,
306  float goodness_of_fit,
307  int dof,
308  size_t iSignalRoI);
309 
314  HitCreator(recob::Hit const& from);
315 
321  HitCreator(recob::Hit const& from, geo::WireID const& wireID);
322 
338  recob::Hit&& move() { return std::move(hit); }
339 
355  recob::Hit const& copy() const { return hit; }
356 
357  protected:
359 
360  }; // class HitCreator
361 
392  public:
393  // no public constructor: use one of the derived classes!
394  // destructor, copy and move constructors and assignment are default
395 
397  size_t size() const { return hits ? hits->size() : 0; }
398 
409 
417  void put_into();
418 
420  std::vector<recob::Hit> const& peek() const { return *hits; }
421 
441  static void declare_products(art::ProducesCollector& collector,
442  std::string instance_name = "",
443  bool doWireAssns = true,
444  bool doRawDigitAssns = true);
445 
446  protected:
448 
449  std::string prod_instance;
450 
452  std::unique_ptr<std::vector<recob::Hit>> hits;
454  std::unique_ptr<art::Assns<recob::Wire, recob::Hit>> WireAssns;
456  std::unique_ptr<art::Assns<raw::RawDigit, recob::Hit>> RawDigitAssns;
457 
458  art::Event* event = nullptr;
459 
461 
473  std::string instance_name,
474  bool doWireAssns,
475  bool doRawDigitAssns);
476 
478  HitPtr_t CreatePtr(size_t index) const { return hitPtrMaker(index); }
479 
480  }; // class HitAndAssociationsWriterBase
481 
490  public:
493 
504  std::string instance_name = "",
505  bool doWireAssns = true,
506  bool doRawDigitAssns = true);
507 
514  HitCollectionCreator(art::Event& event, bool doWireAssns, bool doRawDigitAssns)
515  : HitCollectionCreator(event, "", doWireAssns, doRawDigitAssns)
516  {}
517 
519 
520  // destructor, copy and move constructors and assignment are default
521 
524 
533  void emplace_back(recob::Hit&& hit,
536 
545  void emplace_back(recob::Hit const& hit,
548 
561  {
562  emplace_back(hit.move(), wire, digits);
563  }
564 
574  {
575  emplace_back(std::move(hit), art::Ptr<recob::Wire>(), digits);
576  }
577 
587  {
588  emplace_back(std::move(hit), art::Ptr<recob::Wire>(), digits);
589  }
590 
598  void emplace_back(HitCreator const& hit, art::Ptr<raw::RawDigit> const& digits)
599  {
600  emplace_back(std::move(hit.copy()), art::Ptr<recob::Wire>(), digits);
601  }
603 
605  size_t size() const { return hits->size(); }
606 
608  void reserve(size_t new_size)
609  {
610  if (hits) hits->reserve(new_size);
611  }
612 
623 
631  void put_into();
632 
634  std::vector<recob::Hit> const& peek() const { return *hits; }
635 
636  protected:
638 
641  {
642  return hits->empty() ? HitPtr_t() : CreatePtr(hits->size() - 1);
643  }
644 
646  void CreateAssociationsToLastHit(art::Ptr<recob::Wire> const& wire,
647  art::Ptr<raw::RawDigit> const& digits);
648 
649  }; // class HitCollectionCreator
650 
659  public:
662 
675  std::string instance_name,
676  art::InputTag const& WireModuleLabel,
677  art::InputTag const& RawDigitModuleLabel);
678 
691  art::InputTag const& WireModuleLabel,
692  art::InputTag const& RawDigitModuleLabel)
693  : HitCollectionAssociator(event, "", WireModuleLabel, RawDigitModuleLabel)
694  {}
695 
710  std::string instance_name,
711  art::InputTag const& WireModuleLabel,
712  bool doRawDigitAssns);
713 
727  art::InputTag const& WireModuleLabel,
728  bool doRawDigitAssns)
729  : HitCollectionAssociator(event, "", WireModuleLabel, doRawDigitAssns)
730  {}
731 
733 
734  // destructor, copy and move constructors and assignment are default
735 
745  void use_hits(std::unique_ptr<std::vector<recob::Hit>>&& srchits);
746 
757 
765  void put_into();
766 
767  protected:
772 
774  void prepare_associations(std::vector<recob::Hit> const& srchits);
775 
778 
779  }; // class HitCollectionAssociator
780 
796  public:
799 
811  art::InputTag const& HitModuleLabel,
812  std::string instance_name = "",
813  bool doWireAssns = true,
814  bool doRawDigitAssns = true);
815 
827  art::InputTag const& HitModuleLabel,
828  bool doWireAssns,
829  bool doRawDigitAssns = true)
830  : HitRefinerAssociator(event, HitModuleLabel, "", doWireAssns, doRawDigitAssns)
831  {}
832 
834 
835  // destructor, copy and move constructors and assignment are default
836 
846  void use_hits(std::unique_ptr<std::vector<recob::Hit>>&& srchits);
847 
859 
867  void put_into();
868 
869  protected:
871 
873  void prepare_associations(std::vector<recob::Hit> const& srchits);
874 
877 
878  }; // class HitRefinerAssociator
879 
880  // ---------------------------------------------------------------------------
924  template <typename Writer>
926 
927  public:
928  using Writer_t = Writer;
929 
938 
949  std::string instanceName = "",
950  bool doWireAssns = true,
951  bool doRawDigitAssns = true);
952 
971  void declareProducts(art::ProducesCollector& collector,
972  std::string instanceName = "",
973  bool doWireAssns = true,
974  bool doRawDigitAssns = true);
975 
977  Writer_t collectionWriter(art::Event& event) const;
978 
980  std::string instanceName() const { return prodInstance; }
981 
983  bool ready() const noexcept { return collector_p != nullptr; }
984 
985  protected:
986  art::ProducesCollector* collector_p = nullptr;
987 
988  std::string prodInstance;
989 
991  bool hasRawDigitAssns = true;
992 
994  bool hasWireAssns = true;
995 
996  }; // class HitAndAssociationsWriterManager
997 
1000 
1001 } // namespace recob
1002 
1003 //------------------------------------------------------------------------------
1004 //--- template implementation
1005 //------------------------------------------------------------------------------
1006 //--- recob::HitAndAssociationsWriterBase
1007 //---
1008 //------------------------------------------------------------------------------
1009 //--- recob::HitAndAssociationsWriterManager
1010 //---
1011 template <typename Writer>
1013  art::ProducesCollector& collector,
1014  std::string instanceName /* = "" */,
1015  bool doWireAssns /* = true */,
1016  bool doRawDigitAssns /* = true */
1017 )
1018 {
1019  declareProducts(collector, instanceName, doWireAssns, doRawDigitAssns);
1020 } // recob::HitAndAssociationsWriterManager::HitAndAssociationsWriterManager()
1021 
1022 //------------------------------------------------------------------------------
1023 template <typename Writer>
1025  art::ProducesCollector& collector,
1026  std::string instanceName /* = "" */,
1027  bool doWireAssns /* = true */,
1028  bool doRawDigitAssns /* = true */
1029 )
1030 {
1031  if (collector_p) {
1032  // this means you already called to declaredProducts()
1033  // or used the wrong constructor (which did that for you):
1035  << "HitAndAssociationsWriter<> has already declared its products.";
1036  }
1037  collector_p = &collector;
1038  prodInstance = instanceName;
1039  hasWireAssns = doWireAssns;
1040  hasRawDigitAssns = doRawDigitAssns;
1041  HitAndAssociationsWriterBase::declare_products(
1042  collector, prodInstance, hasWireAssns, hasRawDigitAssns);
1043 } // recob::HitAndAssociationsWriterManager::declareProducts()
1044 
1045 //------------------------------------------------------------------------------
1046 template <typename Writer>
1049 {
1050  if (!collector_p) {
1051  // this means you forgot to code a call to declaredProducts()
1052  // or used the wrong constructor:
1054  << "HitAndAssociationsWriter<>::collectionWriter() called"
1055  " before products are declared.";
1056  }
1057  return {event, prodInstance, hasWireAssns, hasRawDigitAssns};
1058 } // recob::HitAndAssociationsWriterManager::collectionWriter()
1059 
1060 //------------------------------------------------------------------------------
1061 
1062 #endif // LARDATA_ARTDATAHELPERS_HITCREATOR_H
size_t size() const
Returns the number of hits currently in the collection.
Definition: HitCreator.h:397
HitPtr_t CreatePtrToLastHit() const
Creates an art pointer to the hit with the last index.
Definition: HitCreator.h:640
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:68
Reconstruction base classes.
void put_into(art::Event &)
Moves the data into the event.
Definition: HitCreator.h:408
recob::Hit const & copy() const
Returns the constructed wire.
Definition: HitCreator.h:355
void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:777
void emplace_back(HitCreator const &hit, art::Ptr< raw::RawDigit > const &digits)
Adds the specified hit to the data collection.
Definition: HitCreator.h:598
std::string prod_instance
Tame of the instance for data products.
Definition: HitCreator.h:449
art::PtrMaker< recob::Hit > hitPtrMaker
Tool to create hit pointers,.
Definition: HitCreator.h:460
Writer_t collectionWriter(art::Event &event) const
Returns a new writer already configured.
Definition: HitCreator.h:1048
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:769
Declaration of signal hit object.
A helper to centralise creation of a hit collection data product.
Definition: HitCreator.h:925
std::unique_ptr< art::Assns< recob::Wire, recob::Hit > > WireAssns
Associations with wires.
Definition: HitCreator.h:454
Definition of basic raw digits.
Raw data description.
Definition: RawTypes.h:6
recob::Hit hit
Local instance of the hit being constructed.
Definition: HitCreator.h:358
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:25
HitRefinerAssociator(art::Event &event, art::InputTag const &HitModuleLabel, bool doWireAssns, bool doRawDigitAssns=true)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.h:826
Class managing the creation of a new recob::Hit object.
Definition: HitCreator.h:87
void hits()
Definition: readHits.C:15
bool ready() const noexcept
Returns whether the class is fully configured.
Definition: HitCreator.h:983
void emplace_back(HitCreator &&hit, art::Ptr< raw::RawDigit > const &digits)
Adds the specified hit to the data collection.
Definition: HitCreator.h:586
A class handling a collection of hits and its associations.
Definition: HitCreator.h:489
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:876
void reserve(size_t new_size)
Prepares the collection to host at least new_size hits.
Definition: HitCreator.h:608
void put_into(art::Event &)
Moves the data into the event.
Definition: HitCreator.h:858
void declareProducts(art::ProducesCollector &collector, std::string instanceName="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.h:1024
A class handling a collection of hits and its associations.
Definition: HitCreator.h:658
HitPtr_t CreatePtr(size_t index) const
Creates an art pointer to the hit with the specified index.
Definition: HitCreator.h:478
A class handling a collection of hits and its associations.
Definition: HitCreator.h:795
HitCollectionCreator(art::Event &event, bool doWireAssns, bool doRawDigitAssns)
Constructor: no product instance name.
Definition: HitCreator.h:514
Writer Writer_t
Type of managed hit collection writer.
Definition: HitCreator.h:928
void emplace_back(HitCreator &&hit, art::Ptr< recob::Wire > const &wire=art::Ptr< recob::Wire >(), art::Ptr< raw::RawDigit > const &digits=art::Ptr< raw::RawDigit >())
Adds the specified hit to the data collection.
Definition: HitCreator.h:558
void put_into(art::Event &)
Moves the data into an event.
Definition: HitCreator.h:622
Detector simulation of raw signals on wires.
HitCollectionAssociator(art::Event &event, art::InputTag const &WireModuleLabel, bool doRawDigitAssns)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.h:726
art::InputTag hits_label
Label of the collection of hits.
Definition: HitCreator.h:870
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
size_t size() const
Returns the number of hits currently in the collection.
Definition: HitCreator.h:605
void put_into(art::Event &)
Moves the data into the event.
Definition: HitCreator.h:756
Class holding the regions of interest of signal from a channel.
Definition: Wire.h:116
art::InputTag digits_label
Label of raw digits collection to associate.
Definition: HitCreator.h:771
Definition: MVAAlg.h:12
std::vector< recob::Hit > const & peek() const
Returns a read-only reference to the current list of hits.
Definition: HitCreator.h:420
Declaration of basic channel signal object.
std::unique_ptr< art::Assns< raw::RawDigit, recob::Hit > > RawDigitAssns
Associations with raw digits.
Definition: HitCreator.h:456
HitCollectionAssociator(art::Event &event, art::InputTag const &WireModuleLabel, art::InputTag const &RawDigitModuleLabel)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.h:690
std::string prodInstance
Tame of the instance for data products.
Definition: HitCreator.h:988
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
std::vector< recob::Hit > const & peek() const
Returns a read-only reference to the current list of hits.
Definition: HitCreator.h:634
recob::Wire::RegionsOfInterest_t::datarange_t RegionOfInterest_t
Type of one region of interest.
Definition: HitCreator.h:90
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:452
Namespace collecting geometry-related classes utilities.
std::string instanceName() const
Returns the configured product instance name.
Definition: HitCreator.h:980
HitAndAssociationsWriterManager()=default
Constructor: does not declare anything.
recob::Hit && move()
Prepares the constructed hit to be moved away.
Definition: HitCreator.h:338
Base class handling a collection of hits and its associations.
Definition: HitCreator.h:391
void emplace_back(recob::Hit &&hit, art::Ptr< raw::RawDigit > const &digits)
Adds the specified hit to the data collection.
Definition: HitCreator.h:573
Event finding and building.