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