All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SlidingWindowPatternAlg.h
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/Trigger/Algorithms/SlidingWindowPatternAlg.h
3  * @brief Applies sliding window trigger patterns.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date January 29, 2021
6  * @see icaruscode/PMT/Trigger/Algorithms/SlidingWindowPatternAlg.cxx
7  */
8 
9 #ifndef ICARUSCODE_PMT_TRIGGER_ALGORITHMS_SLIDINGWINDOWPATTERNALG_H
10 #define ICARUSCODE_PMT_TRIGGER_ALGORITHMS_SLIDINGWINDOWPATTERNALG_H
11 
12 
13 // ICARUS libraries
20 #include "icaruscode/IcarusObj/OpDetWaveformMeta.h" // sbn::OpDetWaveformMeta
21 
22 // framework libraries
23 #include "cetlib_except/exception.h"
24 
25 // C/C++ standard libraries
26 #include <vector>
27 #include <optional>
28 #include <string>
29 #include <limits> // std::numeric_limits<>
30 #include <cstddef> // std::size_t
31 
32 
33 // -----------------------------------------------------------------------------
34 namespace icarus::trigger { class SlidingWindowPatternAlg; }
35 /**
36  * @brief Applies sliding window patterns to discriminated waveforms.
37  *
38  * This algorithm takes as input one trigger gate for each window.
39  * Each window is identified by an index, and the input gates are assigned one
40  * per window, in order.
41  *
42  * The window mapping that defines the topology of the windows is passed to the
43  * algorithm.
44  *
45  * If a beam gate is present, it is applied to all input before simulating the
46  * pattern. Otherwise, the full input is used.
47  *
48  * For the definition of the windows, see `icarus::trigger::WindowChannelMap`.
49  *
50  */
53 {
54 
55  public:
56 
57  /// Record of the trigger response.
59 
60  /// Type of trigger gate provided as input.
61  using InputTriggerGate_t
63 
64  /// A list of trigger gates from input.
65  using TriggerGates_t = std::vector<InputTriggerGate_t>;
66 
67  /// Type of gate data without channel information (gate levels only).
69 
70  /// Type holding information about composition and topology of all windows.
72 
73  /// Type representing the requirement pattern for a window.
75 
76  /// Additional information on the trigger.
77  struct MoreInfo_t {
78 
79  /// Index of the window which led the trigger.
80  std::size_t windowIndex = std::numeric_limits<std::size_t>::max();
81 
82  }; // struct MoreInfo_t
83 
84  /// Complete information from this algorithm, standard + non-standard (extra).
86  TriggerInfo_t info; ///< Standard trigger information.
87  MoreInfo_t extra; ///< Extra trigger information.
88  /// Returns whether this trigger fired.
89  operator bool() const { return info.fired(); }
90  /// Returns whether this trigger did not fire.
91  bool operator!() const { return !info.fired(); }
92  }; // AllTriggerInfo_t
93 
94  /**
95  * @brief Constructor: configures window topology and times.
96  * @param windowTopology full composition and topology description of windows
97  * @param windowPattern the pattern that this algorithm applies
98  * @param beamGate object applying the beam gate to trigger gates
99  * @param logCategory category tag for algorithm messages on screen
100  *
101  * Window topology can be computed with `icarus::trigger::WindowTopologyAlg`
102  * starting from a (complete) set of trigger gates.
103  *
104  * A beam gate application class can be constructed via
105  * `icarus::trigger::makeApplyBeamGate()` helper function.
106  *
107  */
109  WindowTopology_t windowTopology,
110  WindowPattern_t windowPattern,
112  std::string const& logCategory = "SlidingWindowPatternAlg"
113  );
114 
115  /**
116  * @brief Constructor: configures window topology and times.
117  * @param windowTopology full composition and topology description of windows
118  * @param windowPattern the pattern that this algorithm applies
119  * @param logCategory category tag for algorithm messages on screen
120  *
121  * Window topology can be computed with `icarus::trigger::WindowTopologyAlg`
122  * starting from a (complete) set of trigger gates.
123  *
124  * The beam gate is set to be empty; it must be set before simulating the
125  * response (`simulateResponse()`) via `setBeamGate()`.
126  *
127  */
129  WindowTopology_t windowTopology,
130  WindowPattern_t windowPattern,
131  std::string const& logCategory = "SlidingWindowPatternAlg"
132  );
133 
134  /**
135  * @brief Returns the trigger response from the specified `gates`.
136  * @param gates the trigger gates to be used as input, one per window
137  * @return the response to the configured pattern
138  * @see `applyWindowPattern(WindowChannelMap::WindowInfo const&, WindowPattern_t const&, TriggerGates_t const&)`
139  *
140  * The return value comprises a "standard" `TriggerInfo_t` object, which
141  * stores whether the pattern fired and when, and some `extra` information,
142  * including which window made the trigger fire first (in case of ties,
143  * the window with the smallest index is reported).
144  *
145  * The list `gates` must contain a single trigger gate for each window, with
146  * the gate index in the list matching the window index in the configured
147  * window topology.
148  *
149  * See the static version of `applyWindowPattern()` for more details.
150  *
151  */
152  AllTriggerInfo_t simulateResponse(TriggerGates_t const& gates) const;
153 
154 
155  /// Returns a new collection of gates, set each in coincidence with beam gate.
156  TriggerGates_t applyBeamGate(TriggerGates_t const& gates) const;
157 
158  /// Returns whether a beam gate is being applied.
159  bool hasBeamGate() const;
160 
161  /// Changes the beam gate to the specified value.
163 
164  /// Do not apply any beam gate.
165  void clearBeamGate();
166 
167 
168  /**
169  * @brief Returns the trigger response for the specified window pattern.
170  * @param windowInfo the topology of the windows
171  * @param pattern the trigger requirement pattern
172  * @param gates trigger gates, one per window
173  * @return a `TriggerInfo_t` record with the response of the pattern
174  *
175  * The input `gates` represent all the trigger gates relevant to the trigger
176  * determination, in a list by window index: the first gate belongs to the
177  * window `0`, the second one to the window `1` and so on.
178  * The topology `windowInfo` identifies a window and its topology, i.e. its
179  * neighbours, by window index. It is required and assumed that the values of
180  * the window indices match the ones in the `gates` list.
181  * This function applies the requirements in the specified `pattern` to the
182  * window identified by `windowInfo`, using the actual trigger gates from
183  * the `gates` list as needed.
184  *
185  * The return value includes the first tick at which the requirements have
186  * been all met.
187  * Note that if a beam gate needs to be applied, it should be applies to
188  * all `gates` before calling this function (see e.g. `applyBeamGate()`).
189  *
190  */
192  WindowTopology_t::WindowInfo_t const& windowInfo,
193  WindowPattern_t const& pattern,
194  TriggerGates_t const& gates
195  ) const;
196 
197 
198  private:
199 
200  /// Data structure to communicate internally a trigger response.
202 
203  std::size_t windowIndex = std::numeric_limits<std::size_t>::max();
205 
206  bool fired() const { return info.fired(); }
207 
208  operator bool() const { return bool(info); }
209  bool operator! () const { return !info; }
210 
211  void emplace(std::size_t index, TriggerInfo_t info)
212  { windowIndex = index; this->info = std::move(info); }
213 
214  }; // WindowTriggerInfo_t
215 
216 
217  /// Definition of the neighborhood of each window in terms of window indices.
219 
220  /// Requirement pattern to be applied to each window.
222 
223  /// Time interval when to evaluate the trigger.
224  std::optional<icarus::trigger::ApplyBeamGateClass const> fBeamGate;
225 
226 
227  /**
228  * @brief Returns the trigger response for the specified window pattern.
229  * @param pattern the trigger requirement pattern
230  * @param iWindow index of the window to be tested
231  * @param gates trigger gates, one per window
232  * @return a `TriggerInfo_t` record with the response of the pattern
233  * @see `applyWindowPattern(WindowChannelMap::WindowInfo const&, WindowPattern_t const&, TriggerGates_t const&)`
234  *
235  * Applies the specified `pattern` to the window with index `iWindow` of the
236  * configured window topology.
237  *
238  * See the static version of `applyWindowPattern()` for details.
239  */
241  WindowPattern_t const& pattern, std::size_t iWindow,
242  TriggerGates_t const& gates
243  ) const;
244 
245  /**
246  * @brief Checks `gates` are compatible with the current window configuration.
247  * @param gates the combined sliding window trigger gates, per cryostat
248  * @throw cet::exception (category: `SlidingWindowTriggerEfficiencyPlots`)
249  * or derived, if an incompatibility is found
250  *
251  * The method verifies that the current channel mapping is compatible with the
252  * gates.
253  *
254  * This currently means that the `gates` are in the expected order and have
255  * the expected channel content.
256  */
257  void verifyInputTopology(TriggerGates_t const& gates) const;
258 
259 }; // class icarus::trigger::SlidingWindowPatternAlg
260 
261 
262 //------------------------------------------------------------------------------
263 
264 #endif // ICARUSCODE_PMT_TRIGGER_ALGORITHMS_SLIDINGWINDOWPATTERNALG_H
Data structure to communicate internally a trigger response.
bool fired() const
Returns whether the trigger fired.
AllTriggerInfo_t simulateResponse(TriggerGates_t const &gates) const
Returns the trigger response from the specified gates.
void setBeamGate(icarus::trigger::ApplyBeamGateClass beamGate)
Changes the beam gate to the specified value.
TriggerGates_t applyBeamGate(TriggerGates_t const &gates) const
Returns a new collection of gates, set each in coincidence with beam gate.
TriggerInfo_t applyWindowPattern(WindowTopology_t::WindowInfo_t const &windowInfo, WindowPattern_t const &pattern, TriggerGates_t const &gates) const
Returns the trigger response for the specified window pattern.
icarus::trigger::WindowPattern WindowPattern_t
Type representing the requirement pattern for a window.
void verifyInputTopology(TriggerGates_t const &gates) const
Checks gates are compatible with the current window configuration.
std::size_t windowIndex
Index of the window which led the trigger.
A wrapper to trigger gate objects tracking the input of operations.
Base class facilitating logging to message facility.
Derivative information from raw::OpDetWaveform data.
Helper to manage a beam gate.
static constexpr bool
Information about composition and topology of trigger sliding windows.
SlidingWindowPatternAlg(WindowTopology_t windowTopology, WindowPattern_t windowPattern, icarus::trigger::ApplyBeamGateClass beamGate, std::string const &logCategory="SlidingWindowPatternAlg")
Constructor: configures window topology and times.
Helper applying a beam gate to any gate.
Definition: ApplyBeamGate.h:85
Helper for logging classes.
Helper data structure to store transient trigger result.
Definition: TriggerInfo_t.h:50
Specification of the requirement of sliding window firing pattern.
Definition: WindowPattern.h:51
void clearBeamGate()
Do not apply any beam gate.
Logical multi-level gate associated to one or more readout channels.
Defines a (sliding) window trigger pattern.
icarus::trigger::ReadoutTriggerGate< TriggerGateTick_t, TriggerGateTicks_t, raw::Channel_t > OpticalTriggerGateData_t
Type of trigger gate data serialized into art data products.
icarus::trigger::details::TriggerInfo_t TriggerInfo_t
Record of the trigger response.
icarus::trigger::WindowChannelMap WindowTopology_t
Type holding information about composition and topology of all windows.
WindowTopology_t const fWindowTopology
Definition of the neighborhood of each window in terms of window indices.
WindowPattern_t const fWindowPattern
Requirement pattern to be applied to each window.
Applies sliding window patterns to discriminated waveforms.
Data structure enclosing information for trigger sliding windows.
bool hasBeamGate() const
Returns whether a beam gate is being applied.
bool operator!() const
Returns whether this trigger did not fire.
std::optional< icarus::trigger::ApplyBeamGateClass const > fBeamGate
Time interval when to evaluate the trigger.
Helper class to store transient trigger result.
std::vector< InputTriggerGate_t > TriggerGates_t
A list of trigger gates from input.
A simple alias for a most commonly used TrackedTriggerGate type.
Complete information from this algorithm, standard + non-standard (extra).
std::string logCategory() const
Returns the logging category string for this object.