All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpDetWaveformMetaUtils.h
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/Algorithms/OpDetWaveformMetaUtils.h
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 #ifndef ICARUSCODE_PMT_ALGORITHMS_OPDETWAVEFORMMETAUTILS_H
9 #define ICARUSCODE_PMT_ALGORITHMS_OPDETWAVEFORMMETAUTILS_H
10 
11 
12 // SBN libraries
14 
15 // LArSoft libraries
16 #include "lardataalg/DetectorInfo/DetectorTimingTypes.h" // electronics_time
17 #include "lardataalg/Utilities/quantities/spacetime.h" // microseconds
19 
20 // C/C++ standard libraries
21 #include <optional>
22 
23 
24 // -----------------------------------------------------------------------------
25 // forward declarations
26 namespace detinfo { class DetectorTimings; }
27 
28 
29 // -----------------------------------------------------------------------------
30 namespace sbn {
31 
32  // --- BEGIN -- Creation of sbn::OpDetWaveformMeta from raw::OpDetWaveform -----
33  /**
34  * @name Creation of `sbn::OpDetWaveformMeta` from `raw::OpDetWaveform`
35  *
36  * The creation of summary objects `sbn::OpDetWaveformMeta` from optical
37  * detector waveforms is possible with two options:
38  *
39  * * one shot: call to convert a single waveform (`makeOpDetWaveformMeta()`);
40  * * bulk: converter object reused for multiple conversions
41  * (`sbn::OpDetWaveformMetaMaker`).
42  *
43  * For usage examples, see their respective documentation.
44  */
45  /// @{
46  class OpDetWaveformMetaMaker;
47 
48  /**
49  * @brief Creates a `sbn::OpDetWaveformMeta` out of a `raw::OpDetWaveform`.
50  * @param waveform the input waveform
51  * @param detTimings timing service provider
52  * @return a `sbn::OpDetWaveformMeta` object with the summary information
53  *
54  * Returns a new summary object extracted from the `waveform`.
55  *
56  * The timing information is used to determine whether the global trigger
57  * and beam times are included.
58  *
59  * Example:
60  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
61  * detinfo::DetectorTimings const detTimings = detinfo::makeDetectorTimings
62  * (art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event));
63  *
64  * sbn::OpDetWaveformMeta info = sbn::makeOpDetWaveformMeta(waveform, detTimings);
65  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66  */
67  OpDetWaveformMeta makeOpDetWaveformMeta(
68  raw::OpDetWaveform const& waveform,
70  );
71 
72 
73  /**
74  * @brief Creates a `sbn::OpDetWaveformMeta` out of a `raw::OpDetWaveform`.
75  * @param waveform the input waveform
76  * @param opDetTickPeriod period of the optical detector digitizer
77  * @return a `sbn::OpDetWaveformMeta` object with the summary information
78  *
79  * Returns a new summary object extracted from the `waveform`.
80  *
81  * Information requiring timing is not saved.
82  *
83  * Example:
84  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
85  * util::quantities::intervals::nanoseconds const opDetPeriod { 2.0 };
86  *
87  * sbn::OpDetWaveformMeta info = sbn::makeOpDetWaveformMeta(waveform, opDetPeriod);
88  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89  */
90  OpDetWaveformMeta makeOpDetWaveformMeta(
91  raw::OpDetWaveform const& waveform,
93  );
94 
95  /// @}
96  // --- END ---- Creation of sbn::OpDetWaveformMeta from raw::OpDetWaveform -----
97 
98 
99 } // namespace sbn
100 
101 
102 // -----------------------------------------------------------------------------
103 /**
104  * @brief Converter from `raw::OpDetWaveform` into `sbn::OpDetWaveformMeta`.
105  *
106  * An object of this class is initialized once with some timings (e.g. once per
107  * event), used to `make()` multiple `sbn::OpDetWaveformMeta` and then discarded:
108  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
109  *
110  * detinfo::DetectorTimings const detTimings = detinfo::makeDetectorTimings
111  * (art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event));
112  *
113  * std::vector<sbn::OpDetWaveformMeta> PMTinfo;
114  * for (raw::OpDetWaveform const& waveform: waveforms)
115  * PMTinfo.push_back(makeOpDetWaveformMeta(waveform));
116  *
117  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118  *
119  * It supports a scenario where times (trigger and beam gate) are not available
120  * or not relevant, in which case only the duration in time of a optical
121  * detector waveform tick is needed.
122  */
124 
125  public:
126 
128 
129  /// Constructor: allows creation of `sbn::OpDetWaveformMeta` with full
130  /// information.
132 
133 
134  /// Constructor: allows creation of `sbn::OpDetWaveformMeta` with no
135  /// trigger/beam time information.
136  OpDetWaveformMetaMaker(microseconds opDetTickPeriod);
137 
138  //@{
139  /// Creates a `sbn::OpDetWaveformMeta` out of the specified `waveform`.
140  sbn::OpDetWaveformMeta make(raw::OpDetWaveform const& waveform) const;
142  { return make(waveform); }
143  //@}
144 
145  private:
146 
148 
149  microseconds fOpDetTickPeriod; ///< The duration of a optical detector tick.
150 
151  std::optional<electronics_time> fTriggerTime; ///< Cached trigger time.
152  std::optional<electronics_time> fBeamGateTime; ///< Cached beam gate time.
153 
154 }; // sbn::OpDetWaveformMetaMaker
155 
156 
157 // -----------------------------------------------------------------------------
158 
159 #endif // ICARUSCODE_PMT_ALGORITHMS_OPDETWAVEFORMMETAUTILS_H
std::optional< electronics_time > fBeamGateTime
Cached beam gate time.
sbn::OpDetWaveformMeta make(raw::OpDetWaveform const &waveform) const
Creates a sbn::OpDetWaveformMeta out of the specified waveform.
OpDetWaveformMeta makeOpDetWaveformMeta(raw::OpDetWaveform const &waveform, detinfo::DetectorTimings const &detTimings)
Creates a sbn::OpDetWaveformMeta out of a raw::OpDetWaveform.
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
Definition: spacetime.h:259
Derivative information from raw::OpDetWaveform data.
Derivative information from raw::OpDetWaveform data.
detinfo::timescales::electronics_time electronics_time
OpDetWaveformMetaMaker(detinfo::DetectorTimings const &detTimings)
microseconds fOpDetTickPeriod
The duration of a optical detector tick.
sbn::OpDetWaveformMeta operator()(raw::OpDetWaveform const &waveform) const
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
Converter from raw::OpDetWaveform into sbn::OpDetWaveformMeta.
Dimensioned variables representing space or time quantities.
std::optional< electronics_time > fTriggerTime
Cached trigger time.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
Data types for detinfo::DetectorTimings.
fDetProps &fDetProps fDetProps &fDetProps detTimings
timescale_traits< ElectronicsTimeCategory >::time_point_t electronics_time
A point in time on the electronics time scale.