All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpDetWaveformMetaMaker_module.cc
Go to the documentation of this file.
1 /**
2  * @file OpDetWaveformMetaMaker_module.cc
3  * @brief Writes a collection of sbn::OpDetWaveformMeta from PMT waveforms.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date November 22, 2021
6  */
7 
8 
9 // ICARUS libraries
11 #include "icaruscode/PMT/Algorithms/OpDetWaveformMetaUtils.h" // OpDetWaveformMetaMaker
12 
13 // LArSoft libraries
15 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
17 #include "lardataalg/DetectorInfo/DetectorTimingTypes.h" // electronics_time
20 
21 // framework libraries
22 #include "art/Framework/Core/SharedProducer.h"
23 #include "art/Framework/Core/ModuleMacros.h"
24 #include "art/Framework/Principal/Event.h"
25 #include "art/Persistency/Common/PtrMaker.h"
26 #include "canvas/Persistency/Common/Assns.h"
27 #include "canvas/Persistency/Common/Ptr.h"
28 #include "canvas/Utilities/InputTag.h"
29 #include "messagefacility/MessageLogger/MessageLogger.h"
30 #include "fhiclcpp/types/Atom.h"
31 
32 // C/C++ standard libraries
33 #include <vector>
34 #include <string>
35 #include <memory> // std::make_unique()
36 #include <utility> // std::move()
37 #include <cassert>
38 
39 
40 //------------------------------------------------------------------------------
41 namespace icarus::trigger { class OpDetWaveformMetaMaker; }
42 
43 /**
44  * @brief Extracts and saves the time coverage of optical detector waveforms.
45  *
46  * This module writes a list of `sbn::OpDetWaveformMeta` objects matching the
47  * information of each optical detector waveform.
48  *
49  * It may be used as input to modules which require all the information of a
50  * PMT waveform except the actual content of the waveform. For such uses,
51  * the large waveforms may be dropped and this summary information be kept
52  * instead.
53  *
54  *
55  * Input data products
56  * ====================
57  *
58  * This module acts on a _selection_ of tracks, which implies that the input is
59  * a set of _pointers_ to tracks rather than to an actual track collection.
60  * For each track, an associated time is required.
61  *
62  * * `std::vector<raw::OpDetWaveform>` (tag from `Waveforms`):
63  * all optical detector waveforms to extract the information from
64  *
65  *
66  * Output data products
67  * =====================
68  *
69  * * `std::vector<sbn::OpDetWaveformMeta>`: a collection parallel to the input
70  * one (from data product configured by `Waveforms`) with the summary
71  * information on each of them; also an explicit courtesy association
72  * `art::Assns<sbn::OpDetWaveformMeta, raw::OpDetWaveform>` for uses where
73  * order is not preserved.
74  * The times in these objects are on the same scale as the ones in the source
75  * data product, which is expected to be
76  * @ref DetectorClocksElectronicsStartTime "electronics time scale [us]".
77  *
78  *
79  * Configuration parameters
80  * =========================
81  *
82  * A terse online description of the parameters is printed by running
83  * `lar --print-description OpDetWaveformMetaMaker`.
84  *
85  * * `Waveforms` (input tag, mandatory): the list of optical detector waveforms
86  * to be processed.
87  * * `LogCategory` (string, default: `OpDetWaveformMetaMaker`): name of the
88  * output stream category for console messages (managed by MessageFacility
89  * library).
90  *
91  *
92  */
93 class icarus::trigger::OpDetWaveformMetaMaker: public art::SharedProducer {
94 
95  public:
96 
97  // --- BEGIN Configuration ---------------------------------------------------
98  struct Config {
99 
100  using Name = fhicl::Name;
101  using Comment = fhicl::Comment;
102 
103 
104  fhicl::Atom<art::InputTag> Waveforms {
105  Name("Waveforms"),
106  Comment("tag of input optical detector waveforms")
107  // mandatory
108  };
109 
110  fhicl::Atom<std::string> LogCategory {
111  Name("LogCategory"),
112  Comment("name of the category used for the output"),
113  "OpDetWaveformMetaMaker" // default
114  };
115 
116  }; // struct Config
117 
118  using Parameters = art::SharedProducer::Table<Config>;
119 
120  // --- END Configuration -----------------------------------------------------
121 
122 
123  // --- BEGIN Constructors ----------------------------------------------------
124 
125  explicit OpDetWaveformMetaMaker
126  (Parameters const& config, art::ProcessingFrame const&);
127 
128  // --- END Constructors ------------------------------------------------------
129 
130 
131  // --- BEGIN Framework hooks -------------------------------------------------
132 
133  /// Fills the plots. Also extracts the information to fill them with.
134  virtual void produce(art::Event& event, art::ProcessingFrame const&) override;
135 
136  // --- END Framework hooks ---------------------------------------------------
137 
138 
139  private:
140 
141  // --- BEGIN Configuration variables -----------------------------------------
142 
143  art::InputTag const fWaveformTag; ///< Input waveforms.
144 
145  /// Message facility stream category for output.
146  std::string const fLogCategory;
147 
148  // --- END Configuration variables -------------------------------------------
149 
150 
151 }; // class icarus::trigger::OpDetWaveformMetaMaker
152 
153 
154 //------------------------------------------------------------------------------
155 //--- Implementation
156 //------------------------------------------------------------------------------
157 namespace {
158 
159  template <typename T>
160  std::unique_ptr<T> moveToUniquePtr(T& data)
161  { return std::make_unique<T>(std::move(data)); }
162 
163 } // local namespace
164 
165 
166 //------------------------------------------------------------------------------
168  (Parameters const& config, art::ProcessingFrame const&)
169  : art::SharedProducer(config)
170  // configuration
171  , fWaveformTag(config().Waveforms())
172  , fLogCategory(config().LogCategory())
173 {
174 
175  async<art::InEvent>();
176 
177  //
178  // output data declaration
179  //
180  produces<std::vector<sbn::OpDetWaveformMeta>>();
181  produces<art::Assns<sbn::OpDetWaveformMeta, raw::OpDetWaveform>>();
182 
183  //
184  // configuration report (short)
185  //
186 
187  mf::LogInfo{ fLogCategory }
188  << "Configuration:"
189  << "\n - input waveforms: '" << fWaveformTag.encode() << '\''
190  ;
191 
192 } // icarus::trigger::OpDetWaveformMetaMaker::OpDetWaveformMetaMaker()
193 
194 
195 //------------------------------------------------------------------------------
197  (art::Event& event, art::ProcessingFrame const&)
198 {
199 
201 
202  //
203  // get the timing information for this event
204  //
206  (art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event))
207  ;
208 
209  //
210  // fetch input
211  //
212  auto const& waveformHandle
213  = event.getValidHandle<std::vector<raw::OpDetWaveform>>(fWaveformTag);
214 
215  {
216  electronics_time const triggerTime = detTimings.TriggerTime();
217  electronics_time const beamGateTime = detTimings.BeamGateTime();
218  mf::LogDebug(fLogCategory)
219  << "Event " << event.id() << " has beam gate starting at " << beamGateTime
220  << " and trigger at " << triggerTime << "."
221  << "\nNow extracting information from " << waveformHandle->size()
222  << " waveforms."
223  ;
224  }
225 
226  //
227  // create the content
228  //
230 
231  std::vector<sbn::OpDetWaveformMeta> PMTinfo;
232  art::Assns<sbn::OpDetWaveformMeta, raw::OpDetWaveform> infoToWaveform;
233 
234  art::PtrMaker<sbn::OpDetWaveformMeta> const makeInfoPtr { event };
235  art::PtrMaker<raw::OpDetWaveform> const makeWaveformPtr
236  { event, waveformHandle.id() };
237 
238  for (auto const& [ iWaveform, waveform ]: util::enumerate(*waveformHandle)) {
239  assert(iWaveform == PMTinfo.size());
240 
241  PMTinfo.push_back(makeOpDetWaveformMeta(waveform));
242 
243  {
244  sbn::OpDetWaveformMeta const& info = PMTinfo.back();
245  mf::LogTrace log{ fLogCategory };
246  log << "Coverage for waveform #" << iWaveform
247  << " on channel " << info.channel << ": "
248  << info.startTime << " -- " << info.endTime;
249  if (info.withTrigger()) log << "; includes trigger";
250  if (info.withBeamGate()) log << "; includes beam gate start";
251  }
252 
253  infoToWaveform.addSingle
254  (makeInfoPtr(iWaveform), makeWaveformPtr(iWaveform));
255 
256  } // for
257 
258  //
259  // store output
260  //
261  event.put(moveToUniquePtr(PMTinfo));
262  event.put(moveToUniquePtr(infoToWaveform));
263 
264 } // icarus::trigger::OpDetWaveformMetaMaker::produce()
265 
266 
267 //------------------------------------------------------------------------------
269 
270 
271 //------------------------------------------------------------------------------
electronics_time BeamGateTime() const
Utilities related to art service access.
Writes a collection of sbn::OpDetWaveformMeta from PMT waveforms.
OpDetWaveformMeta makeOpDetWaveformMeta(raw::OpDetWaveform const &waveform, detinfo::DetectorTimings const &detTimings)
Creates a sbn::OpDetWaveformMeta out of a raw::OpDetWaveform.
Definition of util::enumerate().
Extracts and saves the time coverage of optical detector waveforms.
Derivative information from raw::OpDetWaveform data.
Derivative information from raw::OpDetWaveform data.
double endTime
Time at the end of the last sample in the waveform [us].
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
Interface to detinfo::DetectorClocks.
art::SharedProducer::Table< Config > Parameters
fDetProps &fDetProps fDetProps &fDetProps fLogCategory
virtual void produce(art::Event &event, art::ProcessingFrame const &) override
Fills the plots. Also extracts the information to fill them with.
std::string const fLogCategory
Message facility stream category for output.
bool withBeamGate() const
Returns whether the time interval includes for sure the beam opening time.
art::InputTag const fWaveformTag
Input waveforms.
detinfo::DetectorTimings makeDetectorTimings(detinfo::DetectorClocksData const &detClocks)
BEGIN_PROLOG vertical distance to the surface Name
bool withTrigger() const
Returns whether the time interval includes for sure the trigger time.
electronics_time TriggerTime() const
OpDetWaveformMetaMaker(Parameters const &config, art::ProcessingFrame const &)
Converter from raw::OpDetWaveform into sbn::OpDetWaveformMeta.
raw::Channel_t channel
ID of the PMT channel.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
Data types for detinfo::DetectorTimings.
fDetProps &fDetProps fDetProps &fDetProps detTimings
double startTime
Time of the first sample in the waveform [us].
timescale_traits< ElectronicsTimeCategory >::time_point_t electronics_time
A point in time on the electronics time scale.