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