All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpticalTriggerGate.h
Go to the documentation of this file.
1 /**
2  * @file sbnobj/ICARUS/PMT/Trigger/Data/OpticalTriggerGate.h
3  * @brief A trigger gate data object for optical detector electronics.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date April 1, 2019
6  *
7  * This is a header-only library.
8  */
9 
10 #ifndef SBNOBJ_ICARUS_PMT_TRIGGER_DATA_OPTICALTRIGGERGATE_H
11 #define SBNOBJ_ICARUS_PMT_TRIGGER_DATA_OPTICALTRIGGERGATE_H
12 
13 
14 // ICARUS libraries
16 
17 // LArSoft libraries
18 #include "lardataalg/DetectorInfo/DetectorTimingTypes.h" // detinfo::timescales
21 
22 // C/C++ standard libraries
23 #include <iosfwd> // std::ostream
24 #include <vector>
25 #include <utility> // std::move()
26 
27 
28 //------------------------------------------------------------------------------
29 
30 //
31 // declarations
32 //
33 namespace icarus::trigger {
34  class OpticalTriggerGate;
35  std::ostream& operator<< (std::ostream&, OpticalTriggerGate const&);
36 
39 
40  /// Type of trigger gate data serialized into _art_ data products.
43  // <detinfo::timescales::optical_tick, detinfo::timescales::optical_time_ticks, raw::Channel_t>
44  ;
45 
46 } // namespace icarus::trigger
47 
48 
49 //------------------------------------------------------------------------------
50 /**
51  * @brief Logical multi-level gate associated to one or more waveforms.
52  *
53  * This object is a trigger gate associated with one or more optical waveforms.
54  *
55  * @note This object should be parametrized with optical ticks
56  * (`detinfo::timescales::optical_tick`). But currently the quantities
57  * (`util::quantity` derived objects) are not well suited to be serialized
58  * by ROOT, because
59  * 1. they are defined in `lardataalg` rather than `lardataobj`
60  * 2. writing all their serialization is daunting (see how ROOT dealt with
61  * GenVector vectors for an example of how to do it)
62  * So we chicken out here and use simple data types instead.
63  */
66 {
67 
68  public:
69  /// Type for gate data access.
71 
72  using ChannelID_t = GateData_t::ChannelID_t; ///< Type of channel identifier.
73 
74  /// Constructor: a closed gate with no associated waveform (`add()` them).
75  OpticalTriggerGate() = default;
76 
77  OpticalTriggerGate(OpticalTriggerGate const&) = default;
81 
82  /// Constructor: a closed gate for the channel in `waveform`.
84  : GateData_t({ waveform.ChannelNumber() })
85  , fWaveforms({ &waveform })
86  {}
87 
88  /// Constructor: a closed gate for the specified channel.
90 
91 
92  /// Adds another waveform to the gate (unless it has already been added).
93  bool add(raw::OpDetWaveform const& waveform);
94 
95  //@{
96  /// Copies/steals all the levels and channels from the specified data.
98  { GateData_t::operator=(data); return *this; }
100  { GateData_t::operator=(std::move(data)); return *this; }
101  //@}
102 
103 
104  // --- BEGIN Query -----------------------------------------------------------
105  /// @name Query
106  /// @{
107 
108  /// Access to the underlying gate level data (mutable).
109  GateData_t& gateLevels() { return *this; }
110 
111  /// Access to the underlying gate level data (immutable).
112  GateData_t const& gateLevels() const { return *this; }
113 
114  /// Returns a list of pointers to the waveforms associated to the gate,
115  /// sorted.
116  std::vector<raw::OpDetWaveform const*> waveforms() const
117  { return fWaveforms; }
118 
119  // --- END Query -------------------------------------------------------------
120 
121 
122  // --- BEGIN Combination operations ------------------------------------------
123  /// @name Combination operations
124  /// @{
125 
126  /**
127  * @brief Combines with a gate, keeping the minimum opening among the two.
128  * @param other gate to combine to
129  * @return this object
130  * @see `Max()`
131  *
132  * Multi-level equivalent of an _and_ logical operation.
133  */
135 
136  /**
137  * @brief Combines with a gate, keeping the maximum opening among the two.
138  * @param other gate to combine to
139  * @return this object
140  * @see `Min()`, `Sum()`
141  *
142  * Multi-level equivalent of an _or_ logical operation.
143  */
145 
146  /**
147  * @brief Combines with a gate, keeping the sum of openings of the two.
148  * @param other gate to combine to
149  * @return this object
150  * @see `Min()`, `Max()`
151  */
153 
154  /**
155  * @brief Combines with a gate, keeping the product of openings of the two.
156  * @param other gate to combine to
157  * @return this object
158  * @see `Min()`, `Max()`, `Sum()`
159  */
161 
162  /**
163  * @brief Returns a gate with the minimum opening between the specified two.
164  * @param a first gate
165  * @param b second gate
166  * @return gate with at every tick the minimum opening among `a` and `b`
167  * @see `Max()`
168  *
169  * Multi-level equivalent of an _and_ logical operation.
170  */
171  static OpticalTriggerGate Min
172  (OpticalTriggerGate const& a, OpticalTriggerGate const& b);
173 
174  /**
175  * @brief Returns a gate with the maximum opening between the specified two.
176  * @param a first gate
177  * @param b second gate
178  * @return gate with at every tick the maximum opening among `a` and `b`
179  * @see `Min()`, `Sum()`
180  *
181  * Multi-level equivalent of an _or_ logical operation.
182  */
183  static OpticalTriggerGate Max
184  (OpticalTriggerGate const& a, OpticalTriggerGate const& b);
185 
186  /**
187  * @brief Returns a gate with opening sum of the specified two.
188  * @param a first gate
189  * @param b second gate
190  * @return gate with at every tick the total opening of `a` and `b`
191  * @see `Max()`
192  */
193  static OpticalTriggerGate Sum
194  (OpticalTriggerGate const& a, OpticalTriggerGate const& b);
195 
196  /**
197  * @brief Returns a gate with opening product of the specified two.
198  * @param a first gate
199  * @param b second gate
200  * @return gate with at every tick the product of openings of `a` and `b`
201  * @see `Max()`
202  */
203  static OpticalTriggerGate Mul
204  (OpticalTriggerGate const& a, OpticalTriggerGate const& b);
205 
206 
207  /**
208  * @brief Returns a gate combination of the openings of two other gates.
209  * @tparam Op binary operation: `OpeningCount_t` (x2) to `OpeningCount_t`
210  * @param op symmetric binary combination operation
211  * @param a first gate
212  * @param b second gate
213  * @return gate with opening combination of `a` and `b`
214  *
215  * For this algorithm to work, the operation needs to be symmetric, i.e.
216  * `op(c1, c2) == op(c2, c1)` for every valid combinations of counts
217  * `c1` and `c2`.
218  *
219  */
220  template <typename Op>
222  Op&& op, OpticalTriggerGate const& a, OpticalTriggerGate const& b,
225  );
226 
227  /// @}
228  // --- END Combination operations --------------------------------------------
229 
230  // standard comparison operators: all must be the same
231  bool operator== (OpticalTriggerGate const&) const;
232  bool operator!= (OpticalTriggerGate const&) const;
233 
234  protected:
235  // we allow some manipulation by the derived classes
236 
237  /// Internal list of registered waveforms.
238  using Waveforms_t = std::vector<raw::OpDetWaveform const*>;
239 
240  /// Protected constructor: set the data directly.
242  : ReadoutTriggerGate(std::move(gateLevel), waveformChannels(waveforms))
243  , fWaveforms(std::move(waveforms))
244  {}
245 
246 
247  /// Registers the waveforms from the specified list.
248  void registerWaveforms(Waveforms_t const& moreWaveforms);
249 
250  /// Registers the waveforms from the `other` gate into this one.
252  { registerWaveforms(other.waveforms()); }
253 
254 
255  /// Registers the waveforms from the `other` gate into this one.
256  static Waveforms_t mergeWaveforms(Waveforms_t const& a, Waveforms_t const& b);
257 
258  private:
259 
260  /// List of waveforms involved in this channel.
261  std::vector<raw::OpDetWaveform const*> fWaveforms;
262 
263 
264  /// Returns the list of all channels from the `waveforms` (duplicate allowed).
266  (Waveforms_t const& waveforms);
267 
268  /// Returns the list of all unique channels (sorted) from the `waveforms`.
270  (Waveforms_t const& waveforms);
271 
272 }; // class icarus::trigger::OpticalTriggerGate
273 
274 //------------------------------------------------------------------------------
275 
276 #endif // SBNOBJ_ICARUS_PMT_TRIGGER_DATA_OPTICALTRIGGERGATE_H
static GateData_t::ChannelList_t waveformChannels(Waveforms_t const &waveforms)
Returns the list of all unique channels (sorted) from the waveforms.
std::vector< raw::OpDetWaveform const * > waveforms() const
ChannelID_t channel() const
Returns the channel associated to the gate data.
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
OpticalTriggerGate & Max(OpticalTriggerGate const &other)
Combines with a gate, keeping the maximum opening among the two.
static OpticalTriggerGate SymmetricCombination(Op &&op, OpticalTriggerGate const &a, OpticalTriggerGate const &b, TriggerGateTicks_t aDelay=TriggerGateTicks_t{0}, TriggerGateTicks_t bDelay=TriggerGateTicks_t{0})
Returns a gate combination of the openings of two other gates.
std::ostream & operator<<(std::ostream &out, icarus::trigger::ApplyBeamGateClass const &gate)
bool operator!=(OpticalTriggerGate const &) const
std::vector< ChannelID_t > ChannelList_t
Type of list of associated channels.
OpticalTriggerGate(raw::OpDetWaveform const &waveform)
Constructor: a closed gate for the channel in waveform.
ChannelIDType ChannelID_t
Type of stored channel ID.
bool add(raw::OpDetWaveform const &waveform)
Adds another waveform to the gate (unless it has already been added).
OpticalTriggerGate & Sum(OpticalTriggerGate const &other)
Combines with a gate, keeping the sum of openings of the two.
GateData_t & gateLevels()
Access to the underlying gate level data (mutable).
OpticalTriggerGate(GateEvolution_t &&gateLevel, Waveforms_t &&waveforms)
Protected constructor: set the data directly.
process_name gaushit a
void registerWaveforms(Waveforms_t const &moreWaveforms)
Registers the waveforms from the specified list.
Logical multi-level gate associated to one or more readout channels.
static Waveforms_t mergeWaveforms(Waveforms_t const &a, Waveforms_t const &b)
Registers the waveforms from the other gate into this one.
icarus::trigger::ReadoutTriggerGate< TriggerGateTick_t, TriggerGateTicks_t, raw::Channel_t > OpticalTriggerGateData_t
Type of trigger gate data serialized into art data products.
OpticalTriggerGate & operator=(OpticalTriggerGate const &)=default
OpticalTriggerGate & Min(OpticalTriggerGate const &other)
Combines with a gate, keeping the minimum opening among the two.
util::quantities::tick::value_t TriggerGateTicks_t
Tick interval.
bool operator==(OpticalTriggerGate const &) const
static GateData_t::ChannelList_t extractChannels(Waveforms_t const &waveforms)
Returns the list of all channels from the waveforms (duplicate allowed).
T value_t
Type of the stored value.
Definition: quantities.h:570
util::quantities::tick::value_t TriggerGateTick_t
Tick point.
Dimensioned variables related to electronics.
ReadoutTriggerGate & operator=(ReadoutTriggerGate const &)=default
OpticalTriggerGate & Mul(OpticalTriggerGate const &other)
Combines with a gate, keeping the product of openings of the two.
std::vector< raw::OpDetWaveform const * > Waveforms_t
Internal list of registered waveforms.
Logical multi-level gate associated to one or more waveforms.
GateData_t::ChannelID_t ChannelID_t
Type of channel identifier.
A trigger gate data object associated to one or more channels.
Data types for detinfo::DetectorTimings.
std::vector< raw::OpDetWaveform const * > fWaveforms
List of waveforms involved in this channel.
typename Base_t::GateEvolution_t GateEvolution_t
GateData_t const & gateLevels() const
Access to the underlying gate level data (immutable).
void mergeWaveformsFromGate(OpticalTriggerGate const &other)
Registers the waveforms from the other gate into this one.
OpticalTriggerGate(ChannelID_t channel)
Constructor: a closed gate for the specified channel.
OpticalTriggerGate()=default
Constructor: a closed gate with no associated waveform (add() them).