LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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
18 
19 // framework libraries
24 
25 // C/C++ standard library
26 #include <utility> // std::move()
27 #include <vector>
28 #include <string>
29 
30 
31 // declaration of some heavy art stuff
32 namespace art {
33  class Event;
34  class EDProducer;
35  class EDProductGetter;
36 } // namespace art
37 
38 
40 namespace recob {
41 
84  class HitCreator {
85  public:
87  using RegionOfInterest_t = recob::Wire::RegionsOfInterest_t::datarange_t;
88 
89  // destructor, copy and move constructor and assignment as default
90 
115  HitCreator(
116  raw::RawDigit const& digits,
117  geo::WireID const& wireID,
118  raw::TDCtick_t start_tick,
119  raw::TDCtick_t end_tick,
120  float rms,
121  float peak_time,
122  float sigma_peak_time,
123  float peak_amplitude,
124  float sigma_peak_amplitude,
125  float hit_integral,
126  float hit_sigma_integral,
127  float summedADC,
128  short int multiplicity,
129  short int local_index,
130  float goodness_of_fit,
131  int dof
132  );
133 
134 
159  HitCreator(
160  recob::Wire const& wire,
161  geo::WireID const& wireID,
162  raw::TDCtick_t start_tick,
163  raw::TDCtick_t end_tick,
164  float rms,
165  float peak_time,
166  float sigma_peak_time,
167  float peak_amplitude,
168  float sigma_peak_amplitude,
169  float hit_integral,
170  float hit_sigma_integral,
171  float summedADC,
172  short int multiplicity,
173  short int local_index,
174  float goodness_of_fit,
175  int dof
176  );
177 
178 
205  HitCreator(
206  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  );
222 
223 
250  HitCreator(
251  recob::Wire const& wire,
252  geo::WireID const& wireID,
253  float rms,
254  float peak_time,
255  float sigma_peak_time,
256  float peak_amplitude,
257  float sigma_peak_amplitude,
258  float hit_integral,
259  float hit_sigma_integral,
260  float summedADC,
261  short int multiplicity,
262  short int local_index,
263  float goodness_of_fit,
264  int dof,
265  RegionOfInterest_t const& signal
266  );
267 
268 
295  HitCreator(
296  recob::Wire const& wire,
297  geo::WireID const& wireID,
298  float rms,
299  float peak_time,
300  float sigma_peak_time,
301  float peak_amplitude,
302  float sigma_peak_amplitude,
303  float hit_integral,
304  float hit_sigma_integral,
305  float summedADC,
306  short int multiplicity,
307  short int local_index,
308  float goodness_of_fit,
309  int dof,
310  size_t iSignalRoI
311  );
312 
313 
318  HitCreator(recob::Hit const& from);
319 
320 
326  HitCreator(recob::Hit const& from, geo::WireID const& wireID);
327 
328 
344  recob::Hit&& move() { return std::move(hit); }
345 
346 
362  recob::Hit const& copy() const { return hit; }
363 
364  protected:
365 
367 
368  }; // class HitCreator
369 
370 
371 
402  public:
403 
404  // no public constructor: use one of the derived classes!
405  // destructor, copy and move constructors and assignment are default
406 
408  size_t size() const { return hits? hits->size(): 0; }
409 
410 
421 
429  void put_into();
430 
431 
433  std::vector<recob::Hit> const& peek() const { return *hits; }
434 
435 
455  template <typename ModuleType>
456  static void declare_products(
457  ModuleType& producer, std::string instance_name = "",
458  bool doWireAssns = true, bool doRawDigitAssns = true
459  );
460 
461  protected:
463 
464  std::string prod_instance;
465 
467  std::unique_ptr<std::vector<recob::Hit>> hits;
469  std::unique_ptr<art::Assns<recob::Wire, recob::Hit>> WireAssns;
471  std::unique_ptr<art::Assns<raw::RawDigit, recob::Hit>> RawDigitAssns;
472 
473  art::Event* event = nullptr;
474 
476 
477 
490  template <typename ModuleType>
492  ModuleType& producer, art::Event& event,
493  std::string instance_name,
494  bool doWireAssns, bool doRawDigitAssns
495  );
496 
497 
499  HitPtr_t CreatePtr(size_t index) const { return hitPtrMaker(index); }
500 
501  }; // class HitAndAssociationsWriterBase
502 
503 
504 
505 
514  public:
515 
518 
530  template <typename ModuleType>
532  ModuleType& producer, art::Event& event,
533  std::string instance_name = "",
534  bool doWireAssns = true, bool doRawDigitAssns = true
535  );
536 
537 
546  template <typename ModuleType>
548  ModuleType& producer, art::Event& event,
549  bool doWireAssns, bool doRawDigitAssns
550  ):
551  HitCollectionCreator(producer, event, "", doWireAssns, doRawDigitAssns)
552  {}
553 
555 
556  // destructor, copy and move constructors and assignment are default
557 
558 
561 
570  void emplace_back(
571  recob::Hit&& hit,
574  );
575 
576 
585  void emplace_back(
586  recob::Hit const& hit,
589  );
590 
591 
602  HitCreator&& hit,
605  )
606  { emplace_back(hit.move(), wire, digits); }
607 
608 
618  { emplace_back(std::move(hit), art::Ptr<recob::Wire>(), digits); }
619 
620 
630  { emplace_back(std::move(hit), art::Ptr<recob::Wire>(), digits); }
631 
632 
640  void emplace_back
641  (HitCreator const& hit, art::Ptr<raw::RawDigit> const& digits)
642  { emplace_back(std::move(hit.copy()), art::Ptr<recob::Wire>(), digits); }
644 
645 
647  size_t size() const { return hits->size(); }
648 
649 
651  void reserve(size_t new_size) { if (hits) hits->reserve(new_size); }
652 
653 
664 
672  void put_into();
673 
674 
676  std::vector<recob::Hit> const& peek() const { return *hits; }
677 
678 
679  protected:
681 
684  { return hits->empty()? HitPtr_t(): CreatePtr(hits->size() - 1); }
685 
687  void CreateAssociationsToLastHit(
688  art::Ptr<recob::Wire> const& wire, art::Ptr<raw::RawDigit> const& digits
689  );
690 
691  }; // class HitCollectionCreator
692 
693 
694 
695 
704  public:
707 
721  template <typename ModuleType>
723  ModuleType& producer, art::Event& event,
724  std::string instance_name,
725  art::InputTag const& WireModuleLabel,
726  art::InputTag const& RawDigitModuleLabel
727  );
728 
742  template <typename ModuleType>
744  ModuleType& producer, art::Event& event,
745  art::InputTag const& WireModuleLabel,
746  art::InputTag const& RawDigitModuleLabel
747  ):
749  (producer, event, "", WireModuleLabel, RawDigitModuleLabel)
750  {}
751 
767  template <typename ModuleType>
769  ModuleType& producer, art::Event& event,
770  std::string instance_name,
771  art::InputTag const& WireModuleLabel,
772  bool doRawDigitAssns
773  );
774 
789  template <typename ModuleType>
791  ModuleType& producer, art::Event& event,
792  art::InputTag const& WireModuleLabel,
793  bool doRawDigitAssns
794  ):
796  (producer, event, "", WireModuleLabel, doRawDigitAssns)
797  {}
798 
800 
801  // destructor, copy and move constructors and assignment are default
802 
812  void use_hits(std::unique_ptr<std::vector<recob::Hit>>&& srchits);
813 
814 
825 
833  void put_into();
834 
835 
836  protected:
841 
843  void prepare_associations(std::vector<recob::Hit> const& srchits);
844 
847 
848  }; // class HitCollectionAssociator
849 
850 
866  public:
867 
870 
883  template <typename ModuleType>
885  ModuleType& producer, art::Event& event,
886  art::InputTag const& HitModuleLabel,
887  std::string instance_name = "",
888  bool doWireAssns = true, bool doRawDigitAssns = true
889  );
890 
903  template <typename ModuleType>
905  ModuleType& producer, art::Event& event,
906  art::InputTag const& HitModuleLabel,
907  bool doWireAssns, bool doRawDigitAssns = true
908  ):
910  (producer, event, HitModuleLabel, "", doWireAssns, doRawDigitAssns)
911  {}
912 
914 
915  // destructor, copy and move constructors and assignment are default
916 
926  void use_hits(std::unique_ptr<std::vector<recob::Hit>>&& srchits);
927 
928 
940 
948  void put_into();
949 
950 
951  protected:
953 
955  void prepare_associations(std::vector<recob::Hit> const& srchits);
956 
959 
960  }; // class HitRefinerAssociator
961 
962 
963  // ---------------------------------------------------------------------------
1006  template <typename Writer, typename ModuleType = art::EDProducer>
1008 
1009  public:
1010  using Writer_t = Writer;
1012 
1020  HitAndAssociationsWriterManager() = default;
1021 
1032  Module_t& callingProducer, std::string instanceName = "",
1033  bool doWireAssns = true, bool doRawDigitAssns = true
1034  );
1035 
1054  void declareProducts(
1055  Module_t& callingProducer, std::string instanceName = "",
1056  bool doWireAssns = true, bool doRawDigitAssns = true
1057  );
1058 
1060  Writer_t collectionWriter(art::Event& event) const;
1061 
1062 
1064  std::string instanceName() const { return prodInstance; }
1065 
1067  bool ready() const { return producer; }
1068 
1069  protected:
1070  Module_t* producer = nullptr;
1071 
1072  std::string prodInstance;
1073 
1075  bool hasRawDigitAssns = true;
1076 
1078  bool hasWireAssns = true;
1079 
1080 
1081  }; // class HitAndAssociationsWriterManager
1082 
1084  template <typename ModuleType = art::EDProducer>
1087 
1088 } // namespace recob
1089 
1090 
1091 //------------------------------------------------------------------------------
1092 //--- template implementation
1093 //------------------------------------------------------------------------------
1094 //--- recob::HitAndAssociationsWriterBase
1095 //---
1096 template <typename ModuleType>
1098  ModuleType& producer, art::Event& event,
1099  std::string instance_name, bool doWireAssns, bool doRawDigitAssns
1100  )
1101  : prod_instance(instance_name)
1102  , hits()
1103  , WireAssns
1104  (doWireAssns? new art::Assns<recob::Wire, recob::Hit>: nullptr)
1105  , RawDigitAssns
1106  (doRawDigitAssns? new art::Assns<raw::RawDigit, recob::Hit>: nullptr)
1107  , event(&event)
1108  , hitPtrMaker(*(this->event), producer, prod_instance)
1109 {
1110  // this must be run in the producer constructor...
1111 // declare_products(producer, doWireAssns, doRawDigitAssns);
1112 } // recob::HitAndAssociationsWriterBase::HitAndAssociationsWriterBase()
1113 
1114 
1115 //------------------------------------------------------------------------------
1116 template <typename ModuleType>
1118  ModuleType& producer,
1119  std::string instance_name /* = "" */,
1120  bool doWireAssns /* = true */, bool doRawDigitAssns /* = true */
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()
1135 
1136 
1137 //------------------------------------------------------------------------------
1138 //--- recob::HitRefinerAssociator
1139 //---
1140 template <typename ModuleType>
1142  ModuleType& producer, art::Event& event,
1143  art::InputTag const& HitModuleLabel,
1144  std::string instance_name /* = "" */,
1145  bool doWireAssns /* = true */, bool doRawDigitAssns /* = true */
1146 )
1148  (producer, event, instance_name, doWireAssns, doRawDigitAssns)
1149  , hits_label(HitModuleLabel)
1150 {
1151  hits.reset(new std::vector<recob::Hit>);
1152 } // recob::HitRefinerAssociator::HitRefinerAssociator()
1153 
1154 
1155 //------------------------------------------------------------------------------
1156 //--- recob::HitCollectionCreator
1157 //---
1158 template <typename ModuleType>
1160  ModuleType& producer, art::Event& event,
1161  std::string instance_name /* = "" */,
1162  bool doWireAssns /* = true */, bool doRawDigitAssns /* = true */
1163  )
1165  (producer, event, instance_name, doWireAssns, doRawDigitAssns)
1166 {
1167  hits.reset(new std::vector<recob::Hit>);
1168 } // recob::HitCollectionCreator::HitCollectionCreator()
1169 
1170 
1171 //------------------------------------------------------------------------------
1172 //--- recob::HitCollectionAssociator
1173 //---
1174 template <typename ModuleType>
1176  ModuleType& producer, art::Event& event,
1177  std::string instance_name,
1178  art::InputTag const& WireModuleLabel,
1179  art::InputTag const& RawDigitModuleLabel
1180 )
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()
1190 
1191 
1192 //------------------------------------------------------------------------------
1193 template <typename ModuleType>
1195  ModuleType& producer, art::Event& event,
1196  std::string instance_name,
1197  art::InputTag const& WireModuleLabel,
1198  bool doRawDigitAssns /* = false */
1199 )
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()
1214 
1215 
1216 //------------------------------------------------------------------------------
1217 //--- recob::HitAndAssociationsWriterManager
1218 //---
1219 template <typename Writer, typename ModuleType /* = art::EDProducer */>
1222  (
1223  Module_t& callingProducer, std::string instanceName /* = "" */,
1224  bool doWireAssns /* = true */, bool doRawDigitAssns /* = true */
1225  )
1226 {
1227  declareProducts
1228  (callingProducer, instanceName, doWireAssns, doRawDigitAssns);
1229 } // recob::HitAndAssociationsWriterManager::HitAndAssociationsWriterManager()
1230 
1231 
1232 //------------------------------------------------------------------------------
1233 template <typename Writer, typename ModuleType /* = art::EDProducer */>
1235  (
1236  Module_t& callingProducer, std::string instanceName /* = "" */,
1237  bool doWireAssns /* = true */, bool doRawDigitAssns /* = true */
1238  )
1239 {
1240  if (producer) {
1241  // this means you already called to declaredProducts()
1242  // or used the wrong constructor (which did that for you):
1244  << "HitAndAssociationsWriter<> has already declared its products.";
1245  }
1246  producer = &callingProducer;
1247  prodInstance = instanceName;
1248  hasWireAssns = doWireAssns;
1249  hasRawDigitAssns = doRawDigitAssns;
1251  (callingProducer, prodInstance, hasWireAssns, hasRawDigitAssns);
1252 } // recob::HitAndAssociationsWriterManager::declareProducts()
1253 
1254 
1255 //------------------------------------------------------------------------------
1256 template <typename Writer, typename ModuleType /* = art::EDProducer */>
1259  (art::Event& event) const
1260 {
1261  if (!producer) {
1262  // this means you forgot to code a call to declaredProducts()
1263  // or used the wrong constructor:
1265  << "HitAndAssociationsWriter<>::collectionWriter() called"
1266  " before products are declared.";
1267  }
1268  return
1269  { *producer, event, prodInstance, hasWireAssns, hasRawDigitAssns };
1270 } // recob::HitAndAssociationsWriterManager::collectionWriter()
1271 
1272 
1273 //------------------------------------------------------------------------------
1274 
1275 #endif // LARDATA_ARTDATAHELPERS_HITCREATOR_H
HitAndAssociationsWriterManager()=default
Constructor: does not declare anything.
size_t size() const
Returns the number of hits currently in the collection.
Definition: HitCreator.h:408
HitPtr_t CreatePtrToLastHit() const
Creates an art pointer to the hit with the last index.
Definition: HitCreator.h:683
HitCollectionAssociator(ModuleType &producer, art::Event &event, art::InputTag const &WireModuleLabel, art::InputTag const &RawDigitModuleLabel)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.h:743
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:420
Writer Writer_t
Type of managed hit collection writer.
Definition: HitCreator.h:1010
recob::Hit const & copy() const
Returns the constructed wire.
Definition: HitCreator.h:362
void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:846
HitCollectionAssociator(ModuleType &producer, art::Event &event, art::InputTag const &WireModuleLabel, bool doRawDigitAssns)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.h:790
std::string prod_instance
Tame of the instance for data products.
Definition: HitCreator.h:464
art::PtrMaker< recob::Hit > hitPtrMaker
Tool to create hit pointers,.
Definition: HitCreator.h:475
art::InputTag wires_label
Label of the collection of wires to associate.
Definition: HitCreator.h:838
Declaration of signal hit object.
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
A helper to centralise creation of a hit collection data product.
Definition: HitCreator.h:1007
std::unique_ptr< art::Assns< recob::Wire, recob::Hit > > WireAssns
Associations with wires.
Definition: HitCreator.h:469
Definition of basic raw digits.
Raw data description.
Definition: RawTypes.h:6
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.
Definition: HitCreator.h:1117
HitRefinerAssociator(ModuleType &producer, art::Event &event, art::InputTag const &HitModuleLabel, bool doWireAssns, bool doRawDigitAssns=true)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.h:904
art::Event * event
Pointer to the event we are using.
Definition: HitCreator.h:473
recob::Hit hit
Local instance of the hit being constructed.
Definition: HitCreator.h:366
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:24
Class managing the creation of a new recob::Hit object.
Definition: HitCreator.h:84
void hits()
Definition: readHits.C:15
void emplace_back(HitCreator &&hit, art::Ptr< raw::RawDigit > const &digits)
Adds the specified hit to the data collection.
Definition: HitCreator.h:629
A class handling a collection of hits and its associations.
Definition: HitCreator.h:513
void prepare_associations()
Finds out the associations for the current hits.
Definition: HitCreator.h:958
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
void reserve(size_t new_size)
Prepares the collection to host at least new_size hits.
Definition: HitCreator.h:651
void declareProducts(Module_t &callingProducer, std::string instanceName="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.h:1235
void put_into(art::Event &)
Moves the data into the event.
Definition: HitCreator.h:939
HitRefinerAssociator(ModuleType &producer, 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.h:1141
A class handling a collection of hits and its associations.
Definition: HitCreator.h:703
HitPtr_t CreatePtr(size_t index) const
Creates an art pointer to the hit with the specified index.
Definition: HitCreator.h:499
A class handling a collection of hits and its associations.
Definition: HitCreator.h:865
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:601
void put_into(art::Event &)
Moves the data into an event.
Definition: HitCreator.h:663
Detector simulation of raw signals on wires.
art::InputTag hits_label
Label of the collection of hits.
Definition: HitCreator.h:952
HitCollectionCreator(ModuleType &producer, art::Event &event, bool doWireAssns, bool doRawDigitAssns)
Constructor: no product instance name.
Definition: HitCreator.h:547
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:647
void put_into(art::Event &)
Moves the data into the event.
Definition: HitCreator.h:824
bool ready() const
Returns whether the class is fully configured.
Definition: HitCreator.h:1067
Class holding the deconvoluted signals from a channel.
Definition: Wire.h:80
art::InputTag digits_label
Label of raw digits collection to associate.
Definition: HitCreator.h:840
HLT enums.
std::vector< recob::Hit > const & peek() const
Returns a read-only reference to the current list of hits.
Definition: HitCreator.h:433
ModuleType Module_t
Type of producing module.
Definition: HitCreator.h:1011
Declaration of basic channel signal object.
std::unique_ptr< art::Assns< raw::RawDigit, recob::Hit > > RawDigitAssns
Associations with raw digits.
Definition: HitCreator.h:471
std::string instanceName() const
Returns the configured product instance name.
Definition: HitCreator.h:1064
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
HitCollectionCreator(ModuleType &producer, art::Event &event, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Constructor: sets instance name and whether to build associations.
Definition: HitCreator.h:1159
Writer_t collectionWriter(art::Event &event) const
Returns a new writer already configured.
Definition: HitCreator.h:1259
std::vector< recob::Hit > const & peek() const
Returns a read-only reference to the current list of hits.
Definition: HitCreator.h:676
recob::Wire::RegionsOfInterest_t::datarange_t RegionOfInterest_t
Type of one region of interest.
Definition: HitCreator.h:87
std::unique_ptr< std::vector< recob::Hit > > hits
Collection of hits.
Definition: HitCreator.h:467
recob::Hit && move()
Prepares the constructed hit to be moved away.
Definition: HitCreator.h:344
Base class handling a collection of hits and its associations.
Definition: HitCreator.h:401
void emplace_back(recob::Hit &&hit, art::Ptr< raw::RawDigit > const &digits)
Adds the specified hit to the data collection.
Definition: HitCreator.h:617
Event finding and building.
ModuleType
Definition: ModuleType.h:22
std::string prodInstance
Tame of the instance for data products.
Definition: HitCreator.h:1072