LArSoft  v09_90_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 
118  HitCreator(raw::RawDigit const& digits,
119  geo::WireID const& wireID,
120  raw::TDCtick_t start_tick,
121  raw::TDCtick_t end_tick,
122  float rms,
123  float peak_time,
124  float sigma_peak_time,
125  float peak_amplitude,
126  float sigma_peak_amplitude,
127  float hit_integral,
128  float hit_sigma_integral,
129  float summedADC,
130  short int multiplicity,
131  short int local_index,
132  float goodness_of_fit,
133  int dof);
134 
159  HitCreator(recob::Wire const& wire,
160  geo::WireID const& wireID,
161  raw::TDCtick_t start_tick,
162  raw::TDCtick_t end_tick,
163  float rms,
164  float peak_time,
165  float sigma_peak_time,
166  float peak_amplitude,
167  float sigma_peak_amplitude,
168  float hit_integral,
169  float hit_sigma_integral,
170  float summedADC,
171  short int multiplicity,
172  short int local_index,
173  float goodness_of_fit,
174  int dof);
175 
202  HitCreator(recob::Wire const& wire,
203  geo::WireID const& wireID,
204  raw::TDCtick_t start_tick,
205  raw::TDCtick_t end_tick,
206  float rms,
207  float peak_time,
208  float sigma_peak_time,
209  float peak_amplitude,
210  float sigma_peak_amplitude,
211  float hit_integral,
212  float hit_sigma_integral,
213  short int multiplicity,
214  short int local_index,
215  float goodness_of_fit,
216  int dof);
217 
244  HitCreator(recob::Wire const& wire,
245  geo::WireID const& wireID,
246  float rms,
247  float peak_time,
248  float sigma_peak_time,
249  float peak_amplitude,
250  float sigma_peak_amplitude,
251  float hit_integral,
252  float hit_sigma_integral,
253  float summedADC,
254  short int multiplicity,
255  short int local_index,
256  float goodness_of_fit,
257  int dof,
258  RegionOfInterest_t const& signal);
259 
286  HitCreator(recob::Wire const& wire,
287  geo::WireID const& wireID,
288  float rms,
289  float peak_time,
290  float sigma_peak_time,
291  float peak_amplitude,
292  float sigma_peak_amplitude,
293  float hit_integral,
294  float hit_sigma_integral,
295  float summedADC,
296  short int multiplicity,
297  short int local_index,
298  float goodness_of_fit,
299  int dof,
300  size_t iSignalRoI);
301 
306  HitCreator(recob::Hit const& from);
307 
313  HitCreator(recob::Hit const& from, geo::WireID const& wireID);
314 
330  recob::Hit&& move() { return std::move(hit); }
331 
347  recob::Hit const& copy() const { return hit; }
348 
349  protected:
351 
352  }; // class HitCreator
353 
384  public:
385  // no public constructor: use one of the derived classes!
386  // destructor, copy and move constructors and assignment are default
387 
389  size_t size() const { return hits ? hits->size() : 0; }
390 
401 
409  void put_into();
410 
412  std::vector<recob::Hit> const& peek() const { return *hits; }
413 
433  static void declare_products(art::ProducesCollector& collector,
434  std::string instance_name = "",
435  bool doWireAssns = true,
436  bool doRawDigitAssns = true);
437 
438  protected:
440 
441  std::string prod_instance;
442 
444  std::unique_ptr<std::vector<recob::Hit>> hits;
446  std::unique_ptr<art::Assns<recob::Wire, recob::Hit>> WireAssns;
448  std::unique_ptr<art::Assns<raw::RawDigit, recob::Hit>> RawDigitAssns;
449 
450  art::Event* event = nullptr;
451 
453 
465  std::string instance_name,
466  bool doWireAssns,
467  bool doRawDigitAssns);
468 
470  HitPtr_t CreatePtr(size_t index) const { return hitPtrMaker(index); }
471 
472  }; // class HitAndAssociationsWriterBase
473 
482  public:
485 
496  std::string instance_name = "",
497  bool doWireAssns = true,
498  bool doRawDigitAssns = true);
499 
506  HitCollectionCreator(art::Event& event, bool doWireAssns, bool doRawDigitAssns)
507  : HitCollectionCreator(event, "", doWireAssns, doRawDigitAssns)
508  {}
509 
511 
512  // destructor, copy and move constructors and assignment are default
513 
516 
525  void emplace_back(recob::Hit&& hit,
528 
537  void emplace_back(recob::Hit const& hit,
540 
553  {
554  emplace_back(hit.move(), wire, digits);
555  }
556 
566  {
567  emplace_back(std::move(hit), art::Ptr<recob::Wire>(), digits);
568  }
569 
579  {
580  emplace_back(std::move(hit), art::Ptr<recob::Wire>(), digits);
581  }
582 
590  void emplace_back(HitCreator const& hit, art::Ptr<raw::RawDigit> const& digits)
591  {
592  emplace_back(std::move(hit.copy()), art::Ptr<recob::Wire>(), digits);
593  }
595 
597  size_t size() const { return hits->size(); }
598 
600  void reserve(size_t new_size)
601  {
602  if (hits) hits->reserve(new_size);
603  }
604 
615 
623  void put_into();
624 
626  std::vector<recob::Hit> const& peek() const { return *hits; }
627 
628  protected:
630 
633  {
634  return hits->empty() ? HitPtr_t() : CreatePtr(hits->size() - 1);
635  }
636 
638  void CreateAssociationsToLastHit(art::Ptr<recob::Wire> const& wire,
639  art::Ptr<raw::RawDigit> const& digits);
640 
641  }; // class HitCollectionCreator
642 
651  public:
654 
667  std::string instance_name,
668  art::InputTag const& WireModuleLabel,
669  art::InputTag const& RawDigitModuleLabel);
670 
683  art::InputTag const& WireModuleLabel,
684  art::InputTag const& RawDigitModuleLabel)
685  : HitCollectionAssociator(event, "", WireModuleLabel, RawDigitModuleLabel)
686  {}
687 
702  std::string instance_name,
703  art::InputTag const& WireModuleLabel,
704  bool doRawDigitAssns);
705 
719  art::InputTag const& WireModuleLabel,
720  bool doRawDigitAssns)
721  : HitCollectionAssociator(event, "", WireModuleLabel, doRawDigitAssns)
722  {}
723 
725 
726  // destructor, copy and move constructors and assignment are default
727 
737  void use_hits(std::unique_ptr<std::vector<recob::Hit>>&& srchits);
738 
749 
757  void put_into();
758 
759  protected:
764 
766  void prepare_associations(std::vector<recob::Hit> const& srchits);
767 
770 
771  }; // class HitCollectionAssociator
772 
788  public:
791 
803  art::InputTag const& HitModuleLabel,
804  std::string instance_name = "",
805  bool doWireAssns = true,
806  bool doRawDigitAssns = true);
807 
819  art::InputTag const& HitModuleLabel,
820  bool doWireAssns,
821  bool doRawDigitAssns = true)
822  : HitRefinerAssociator(event, HitModuleLabel, "", doWireAssns, doRawDigitAssns)
823  {}
824 
826 
827  // destructor, copy and move constructors and assignment are default
828 
838  void use_hits(std::unique_ptr<std::vector<recob::Hit>>&& srchits);
839 
851 
859  void put_into();
860 
861  protected:
863 
865  void prepare_associations(std::vector<recob::Hit> const& srchits);
866 
869 
870  }; // class HitRefinerAssociator
871 
872  // ---------------------------------------------------------------------------
916  template <typename Writer>
918 
919  public:
920  using Writer_t = Writer;
921 
930 
941  std::string instanceName = "",
942  bool doWireAssns = true,
943  bool doRawDigitAssns = true);
944 
963  void declareProducts(art::ProducesCollector& collector,
964  std::string instanceName = "",
965  bool doWireAssns = true,
966  bool doRawDigitAssns = true);
967 
969  Writer_t collectionWriter(art::Event& event) const;
970 
972  std::string instanceName() const { return prodInstance; }
973 
975  bool ready() const noexcept { return collector_p != nullptr; }
976 
977  protected:
978  art::ProducesCollector* collector_p = nullptr;
979 
980  std::string prodInstance;
981 
983  bool hasRawDigitAssns = true;
984 
986  bool hasWireAssns = true;
987 
988  }; // class HitAndAssociationsWriterManager
989 
992 
993 } // namespace recob
994 
995 //------------------------------------------------------------------------------
996 //--- template implementation
997 //------------------------------------------------------------------------------
998 //--- recob::HitAndAssociationsWriterBase
999 //---
1000 //------------------------------------------------------------------------------
1001 //--- recob::HitAndAssociationsWriterManager
1002 //---
1003 template <typename Writer>
1005  art::ProducesCollector& collector,
1006  std::string instanceName /* = "" */,
1007  bool doWireAssns /* = true */,
1008  bool doRawDigitAssns /* = true */
1009 )
1010 {
1011  declareProducts(collector, instanceName, doWireAssns, doRawDigitAssns);
1012 } // recob::HitAndAssociationsWriterManager::HitAndAssociationsWriterManager()
1013 
1014 //------------------------------------------------------------------------------
1015 template <typename Writer>
1017  art::ProducesCollector& collector,
1018  std::string instanceName /* = "" */,
1019  bool doWireAssns /* = true */,
1020  bool doRawDigitAssns /* = true */
1021 )
1022 {
1023  if (collector_p) {
1024  // this means you already called to declaredProducts()
1025  // or used the wrong constructor (which did that for you):
1027  << "HitAndAssociationsWriter<> has already declared its products.";
1028  }
1029  collector_p = &collector;
1030  prodInstance = instanceName;
1031  hasWireAssns = doWireAssns;
1032  hasRawDigitAssns = doRawDigitAssns;
1033  HitAndAssociationsWriterBase::declare_products(
1034  collector, prodInstance, hasWireAssns, hasRawDigitAssns);
1035 } // recob::HitAndAssociationsWriterManager::declareProducts()
1036 
1037 //------------------------------------------------------------------------------
1038 template <typename Writer>
1041 {
1042  if (!collector_p) {
1043  // this means you forgot to code a call to declaredProducts()
1044  // or used the wrong constructor:
1046  << "HitAndAssociationsWriter<>::collectionWriter() called"
1047  " before products are declared.";
1048  }
1049  return {event, prodInstance, hasWireAssns, hasRawDigitAssns};
1050 } // recob::HitAndAssociationsWriterManager::collectionWriter()
1051 
1052 //------------------------------------------------------------------------------
1053 
1054 #endif // LARDATA_ARTDATAHELPERS_HITCREATOR_H
size_t size() const
Returns the number of hits currently in the collection.
Definition: HitCreator.h:389
HitPtr_t CreatePtrToLastHit() const
Creates an art pointer to the hit with the last index.
Definition: HitCreator.h:632
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:400
recob::Hit const & copy() const
Returns the constructed wire.
Definition: HitCreator.h:347
void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:769
void emplace_back(HitCreator const &hit, art::Ptr< raw::RawDigit > const &digits)
Adds the specified hit to the data collection.
Definition: HitCreator.h:590
std::string prod_instance
Tame of the instance for data products.
Definition: HitCreator.h:441
art::PtrMaker< recob::Hit > hitPtrMaker
Tool to create hit pointers,.
Definition: HitCreator.h:452
Writer_t collectionWriter(art::Event &event) const
Returns a new writer already configured.
Definition: HitCreator.h:1040
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:761
Declaration of signal hit object.
A helper to centralise creation of a hit collection data product.
Definition: HitCreator.h:917
std::unique_ptr< art::Assns< recob::Wire, recob::Hit > > WireAssns
Associations with wires.
Definition: HitCreator.h:446
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:350
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:818
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:975
void emplace_back(HitCreator &&hit, art::Ptr< raw::RawDigit > const &digits)
Adds the specified hit to the data collection.
Definition: HitCreator.h:578
A class handling a collection of hits and its associations.
Definition: HitCreator.h:481
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:868
void reserve(size_t new_size)
Prepares the collection to host at least new_size hits.
Definition: HitCreator.h:600
void put_into(art::Event &)
Moves the data into the event.
Definition: HitCreator.h:850
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:1016
A class handling a collection of hits and its associations.
Definition: HitCreator.h:650
HitPtr_t CreatePtr(size_t index) const
Creates an art pointer to the hit with the specified index.
Definition: HitCreator.h:470
A class handling a collection of hits and its associations.
Definition: HitCreator.h:787
HitCollectionCreator(art::Event &event, bool doWireAssns, bool doRawDigitAssns)
Constructor: no product instance name.
Definition: HitCreator.h:506
Writer Writer_t
Type of managed hit collection writer.
Definition: HitCreator.h:920
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:550
void put_into(art::Event &)
Moves the data into an event.
Definition: HitCreator.h:614
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:718
art::InputTag hits_label
Label of the collection of hits.
Definition: HitCreator.h:862
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:597
void put_into(art::Event &)
Moves the data into the event.
Definition: HitCreator.h:748
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:763
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:412
Declaration of basic channel signal object.
std::unique_ptr< art::Assns< raw::RawDigit, recob::Hit > > RawDigitAssns
Associations with raw digits.
Definition: HitCreator.h:448
HitCollectionAssociator(art::Event &event, art::InputTag const &WireModuleLabel, art::InputTag const &RawDigitModuleLabel)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.h:682
std::string prodInstance
Tame of the instance for data products.
Definition: HitCreator.h:980
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:626
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:444
Namespace collecting geometry-related classes utilities.
std::string instanceName() const
Returns the configured product instance name.
Definition: HitCreator.h:972
HitAndAssociationsWriterManager()=default
Constructor: does not declare anything.
recob::Hit && move()
Prepares the constructed hit to be moved away.
Definition: HitCreator.h:330
Base class handling a collection of hits and its associations.
Definition: HitCreator.h:383
void emplace_back(recob::Hit &&hit, art::Ptr< raw::RawDigit > const &digits)
Adds the specified hit to the data collection.
Definition: HitCreator.h:565
Event finding and building.