All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpWaveform.h
Go to the documentation of this file.
1 /** ****************************************************************************
2  * @file lardataobj/RecoBase/OpWaveform.h
3  * @brief Definition of calibrated photon detector waveform.
4  * @author tjyang@fnal.gov
5  * @see lardataobj/RecoBase/OpWaveform.cxx
6  */
7 
8 #ifndef LARDATAOBJ_RECOBASE_OPWAVEFORM_H
9 #define LARDATAOBJ_RECOBASE_OPWAVEFORM_H
10 
11 
12 // LArSoft libraries
15 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
17 
18 // C/C++ standard libraries
19 #include <vector>
20 #include <cstddef> // std::size_t
21 
22 
23 namespace recob {
24 
25  /**
26  * @brief Class holding the regions of interest of signal from a photon detector channel.
27  * @note The class is designed based on recob::Wire.
28  *
29  * The channel content is expected to have been filtered from noise and
30  * corrected for electronics response, a process often called in jargon
31  * "deconvolution".
32  *
33  * The content is presented as calibrated ADC counts, pedestal removed, as
34  * function of time in discrete TDC units. The time is expected to be the same
35  * as for the `raw::OpDetWaveform` that originates it.
36  *
37  * The content is organized as time intervals where some signal is present
38  * ("regions of interest", RoI), outside which we assume no signal.
39  * By principle, the definition of the regions of interest is a negative one:
40  * we determine time intervals where we are confident no signal is present;
41  * the rest will constitute regions of interest where there _might_ be signal.
42  * The identification of such regions is responsibility of the algorithm
43  * creating the `OpWaveform` object. In the simplest approach, the whole readout
44  * window is stored in a single region of interest, meaning that we don't
45  * claim any of the channel signal to be definitely signal free.
46  * More generally, the first tick of the waveform is #0, and if the first
47  * region of interest starts after that tick, it implies that the region
48  * between tick #0 and the start of that first region lacks signal.
49  * Likewise, any samples in the end of the covered time window (defined above)
50  * which lack signal are indicated by the overall size of the content, while
51  * the last region of interest ends earlier.
52  *
53  * Algorithms using the regions of interest can access the channel signal
54  * information either ignoring the regions of interest, and being potentially
55  * flooded by zeroes from the non-signal regions:
56  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
57  * for (float ADCcount: opwf.Signal()) ...
58  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59  * or they can analyze region by region:
60  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
61  * for (auto iROI = opwf.begin_range(); iROI != opwf.end_range(); ++iROI) {
62  * const datarange_t& ROI = *iROI;
63  * const int FirstTick = ROI.begin_index();
64  * const int EndTick = ROI.end_index();
65  * const float FirstADC = ROI[FirstTick]; // index access is by absolute tick number
66  * for (float ADC: ROI) // ... or you can just iterate through
67  * // ...
68  * } // for
69  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70  * An alternative to the first form is:
71  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
72  * for (float ADCcount: opwf.SignalROI()) ...
73  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74  * which does not create a temporary dense vector, as `Signal()` does instead.
75  *
76  * Note that the indexed access is always by absolute tick number.
77  * More examples of the use of `SignalROI()` return value are documented in
78  * `lar::sparse_vector`.
79  *
80  * Each channel is associated with a `raw::OpDetWaveform` object. These
81  * associations should be stored together with `recob::OpWaveform` by the producer
82  * in a `art::Assns` data product.
83  *
84  *
85  * Creating `recob::OpWaveform` objects
86  * ===============================
87  *
88  * LArSoft "protocol" prescribes:
89  *
90  * * creation of an association of each `recob::OpWaveform` with the `raw::OpDetWaveform`
91  * it comes from; the association should be created by the same _art_ module
92  * producing the `recob::OpWaveform` collection
93  * * `recob::OpWaveform` time span should be the same as its `raw::OpDetWaveform`
94  * Please read the documentation of `recob::OpWaveform` constructors.
95  */
96 
97  class OpWaveform {
98  public:
99  /// a region of interest is a pair (TDC offset, readings)
101 
102  /// Default constructor: a wire with no signal information
103  OpWaveform();
104 
105  private:
106  raw::RDTimeStamp fTimeStamp; ///< Time stamp
107  raw::ChannelID_t fChannel; ///< ID of the associated channel.
108  RegionsOfInterest_t fSignalROI; ///< Signal on the channel as function of time tick.
109 
110  //friend class OpWaveformCreator; // helper to create wires in art
111 
112  public:
113 
114  // --- BEGIN -- Constructors ---------------------------------------------
115  /**
116  * @brief Constructor: uses specified signal in regions of interest.
117  * @param time time stamp of the signal
118  * @param channel the ID of the channel
119  * @param sigROIlist signal organized in regions of interest
120  *
121  * Signal is copied into the `recob::OpWaveform` object, including the sparse
122  * region of interest structure within `sigROIlist`.
123  * If possible, use the other constructor that moves the data instead.
124  *
125  * For more details, see the other constructor documentation.
126  */
127  OpWaveform(
128  raw::RDTimeStamp time,
129  raw::ChannelID_t channel,
130  RegionsOfInterest_t const& sigROIlist
131  );
132 
133  /**
134  * @brief Constructor: uses specified signal in regions of interest.
135  * @param time time stamp of the signal
136  * @param channel the ID of the channel
137  * @param sigROIlist signal organized in regions of interest
138  *
139  * The `recob::OpWaveform` object is constructed with the waveform information
140  * in `sigROIlist` and assigned the specified `channel` and `view`.
141  *
142  * The signal is stored in a sparse vector, each entry corresponding to a
143  * tick in the calibrated waveform. The tick range of the sparse vector
144  * reflects the one in the wire, i.e. the first sample in `sigROIlist`
145  * becomes the sample #0 of the `recob::OpWaveform` waveform.
146  * The total length of the waveform (that is, its duration in ticks) is
147  * also learned from the (nominal) size of `sigROIlist` (see also
148  * `lar::sparse_vector::resize()`), which can and should extend beyond
149  * the last region of interest.
150  *
151  * This constructor moves the signal information is moved `sigROIlist`,
152  * that becomes invalid.
153  * This also preserves the sparse region of interest structure within
154  * `sigROIlist`.
155  */
156  OpWaveform(
157  raw::RDTimeStamp time,
158  raw::ChannelID_t channel,
159  RegionsOfInterest_t&& sigROIlist
160  );
161  // --- END -- Constructors -----------------------------------------------
162 
163 
164  // --- BEGIN -- Accessors ------------------------------------------------
165  ///@name Accessors
166  ///@{
167 
168  /// Return a zero-padded full length vector filled with RoI signal
169  std::vector<float> Signal() const;
170 
171  /// Returns the list of regions of interest
172  const RegionsOfInterest_t& SignalROI() const;
173 
174  /// Returns the number of time ticks, or samples, in the channel
175  std::size_t NSignal() const;
176 
177  /// Returns the ID of the channel (or InvalidChannelID)
178  raw::ChannelID_t Channel() const;
179 
180  /// Returns the time stamp
181  raw::RDTimeStamp TimeStamp() const;
182 
183  ///@}
184  // --- END -- Accessors --------------------------------------------------
185 
186 
187  // --- BEGIN -- Sorting and comparison operations ------------------------
188  /// @name Sorting and comparison operations
189  /// @{
190 
191  /// Returns whether this channel ID is smaller than the other
192  bool operator< (const OpWaveform& than) const;
193 
194  // --- END -- Sorting and comparison operations --------------------------
195 
196 
197  }; // class OpWaveform
198 
199 } // namespace recob
200 
201 
202 //------------------------------------------------------------------------------
203 //--- inline implementation
204 //------------------------------------------------------------------------------
207 inline std::size_t recob::OpWaveform::NSignal() const { return fSignalROI.size(); }
208 inline raw::ChannelID_t recob::OpWaveform::Channel() const { return fChannel; }
209 inline raw::RDTimeStamp recob::OpWaveform::TimeStamp() const { return fTimeStamp; }
210 inline bool recob::OpWaveform::operator< (const OpWaveform& than) const
211  { return Channel() < than.Channel(); }
212 
213 //------------------------------------------------------------------------------
214 
215 
216 #endif // LARDATAOBJ_RECOBASE_OPWAVEFORM_H
217 
218 ////////////////////////////////////////////////////////////////////////
raw::RDTimeStamp TimeStamp() const
Returns the time stamp.
Definition: OpWaveform.h:209
Class holding the regions of interest of signal from a photon detector channel.
Definition: OpWaveform.h:97
OpWaveform()
Default constructor: a wire with no signal information.
Definition: OpWaveform.cxx:17
lar::sparse_vector< float > RegionsOfInterest_t
a region of interest is a pair (TDC offset, readings)
Definition: OpWaveform.h:100
const RegionsOfInterest_t & SignalROI() const
Returns the list of regions of interest.
Definition: OpWaveform.h:206
raw::RDTimeStamp fTimeStamp
Time stamp.
Definition: OpWaveform.h:106
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: OpWaveform.h:208
bool operator<(const OpWaveform &than) const
Returns whether this channel ID is smaller than the other.
Definition: OpWaveform.h:210
RegionsOfInterest_t fSignalROI
Signal on the channel as function of time tick.
Definition: OpWaveform.h:108
Definition of data types for geometry description.
std::size_t NSignal() const
Returns the number of time ticks, or samples, in the channel.
Definition: OpWaveform.h:207
raw::ChannelID_t fChannel
ID of the associated channel.
Definition: OpWaveform.h:107
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
Class defining a sparse vector (holes are zeroes)
std::vector< float > Signal() const
Return a zero-padded full length vector filled with RoI signal.
Definition: OpWaveform.cxx:47