All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SlidingWindowCombinerAlg.h
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/Trigger/Algorithms/SlidingWindowCombinerAlg.h
3  * @brief Algorithm to combine trigger channels into sliding windows.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date January 6, 2020
6  * @see icaruscode/PMT/Trigger/Algorithms/SlidingWindowCombinerAlg.cxx
7  */
8 
9 #ifndef ICARUSCODE_PMT_TRIGGER_ALGORITHMS_SLIDINGWINDOWCOMBINERALG_H
10 #define ICARUSCODE_PMT_TRIGGER_ALGORITHMS_SLIDINGWINDOWCOMBINERALG_H
11 
12 
13 // ICARUS libraries
15 #include "icaruscode/PMT/Trigger/Utilities/TriggerDataUtils.h" // TriggerGateIndex
18 
19 // LArSoft libraries
21 #include "lardataobj/RawData/OpDetWaveform.h" // raw::Channel_t
22 
23 // framework libraries
24 #include "messagefacility/MessageLogger/MessageLogger.h"
25 
26 // C/C++ standard libraries
27 #include <set>
28 #include <vector>
29 #include <string>
30 #include <algorithm> // std::find(), std::binary_search()
31 
32 
33 // -----------------------------------------------------------------------------
34 // --- forward declarations
35 // ---
36 namespace icarus::trigger {
37  template <typename GateObject> class TriggerGateIndex;
38 } // namespace icarus::trigger
39 
40 
41 // -----------------------------------------------------------------------------
42 namespace icarus::trigger { class SlidingWindowCombinerAlg; }
44 
45  public:
46  /// Type of optical detector channel list in a window.
48 
49  /// Type of content of all windows.
51 
52  /// Trigger gate data type (tracks sources via `sbn::OpDetWaveformMeta`).
55 
56  /// Constructor: learns about the window pattern (keeps a reference).
58  Windows_t const& windows,
59  std::vector<raw::Channel_t> missingChannels = {},
60  bool requireFullCoverage = true,
61  std::string logCategory = "SlidingWindowCombinerAlg"
62  );
63 
64  /// Combines the `gates` according to the configured grouping.
65  std::vector<TrackedTriggerGate_t> combine
66  (std::vector<TrackedTriggerGate_t> const& gates) const;
67 
68  /// Returns if `channel` is configured to be missing.
69  bool isMissingChannel(raw::Channel_t channel) const;
70 
71 
72  private:
73 
74  using TriggerGateIndex_t
76 
77  /// Content of channels of each window.
79 
80  /// Channels known (and required) to be missing (sorted).
81  std::vector<raw::Channel_t> fMissingChannels;
82 
83  /// Whether to require all channels to be used.
85 
86  std::string fLogCategory; ///< Category for messages to MessageFacility.
87 
88  /// Throws an exception if the gates are not suitable for input.
89  void checkInput(TriggerGateIndex_t const& gates) const;
90 
91  /// Returns the combination of the `channels` selected from the `gates`.
93  (TriggerGateIndex_t const& gates, WindowChannels_t const& channels) const;
94 
95  /// Returns an iterator to the first of the `channels` which is not missing.
96  WindowChannels_t::const_iterator firstChannelPresent
97  (WindowChannels_t const& channels) const;
98 
99 
100  /// Adds the gate data of `input` to `dest`, unless it's already included.
101  /// @return whether the addition happened
102  static bool mergeGateInto
103  (TrackedTriggerGate_t& dest, TrackedTriggerGate_t const& input);
104 
105  /// Returns windows with numerically sorted channel numbers.
106  static Windows_t sortedWindowChannels(Windows_t const& windows);
107 
108  /// Returns a sorted copy of `channels`.
109  static std::vector<raw::Channel_t> sortChannels
110  (std::vector<raw::Channel_t> channels);
111 
112  /// Returns whether the container `c` has `value`.
113  template <typename Cont, typename T>
114  static bool inList(Cont const& c, T const& value)
115  { auto cend = c.end(); return std::find(c.begin(), cend, value) != cend; }
116 
117 }; // class icarus::trigger::SlidingWindowCombinerAlg
118 
119 
120 
121 // -----------------------------------------------------------------------------
122 // --- inline implementation
123 // -----------------------------------------------------------------------------
125  (raw::Channel_t channel) const
126 {
127  return std::find(fMissingChannels.begin(), fMissingChannels.end(), channel)
128  != fMissingChannels.end();
129 } // icarus::trigger::SlidingWindowCombinerAlg::isMissingChannel()
130 
131 
132 // -----------------------------------------------------------------------------
133 
134 #endif // ICARUSCODE_PMT_TRIGGER_ALGORITHMS_SLIDINGWINDOWCOMBINERALG_H
void checkInput(TriggerGateIndex_t const &gates) const
Throws an exception if the gates are not suitable for input.
Utilities for the conversion of trigger gate data formats.
icarus::trigger::TriggerWindowChannels_t WindowChannels_t
Type of optical detector channel list in a window.
A wrapper to trigger gate objects tracking the input of operations.
icarus::trigger::TriggerWindowDefs_t Windows_t
Type of content of all windows.
std::string fLogCategory
Category for messages to MessageFacility.
icarus::trigger::TriggerGateIndex< TrackedTriggerGate_t > TriggerGateIndex_t
bool isMissingChannel(raw::Channel_t channel) const
Returns if channel is configured to be missing.
std::vector< raw::Channel_t > TriggerWindowChannels_t
Type of optical detector channel list in a window.
auto cend(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:579
WindowChannels_t::const_iterator firstChannelPresent(WindowChannels_t const &channels) const
Returns an iterator to the first of the channels which is not missing.
Utilities for the conversion of trigger gate data formats.
Test of util::counter and support utilities.
static Windows_t sortedWindowChannels(Windows_t const &windows)
Returns windows with numerically sorted channel numbers.
Definition for PMT sliding windows.
TrackedTriggerGate_t combineChannels(TriggerGateIndex_t const &gates, WindowChannels_t const &channels) const
Returns the combination of the channels selected from the gates.
static bool mergeGateInto(TrackedTriggerGate_t &dest, TrackedTriggerGate_t const &input)
static std::vector< raw::Channel_t > sortChannels(std::vector< raw::Channel_t > channels)
Returns a sorted copy of channels.
std::vector< TrackedTriggerGate_t > combine(std::vector< TrackedTriggerGate_t > const &gates) const
Combines the gates according to the configured grouping.
std::vector< raw::Channel_t > fMissingChannels
Channels known (and required) to be missing (sorted).
Associates each optical detector channel to a gate.
A simple alias for a most commonly used TrackedTriggerGate type.
SlidingWindowCombinerAlg(Windows_t const &windows, std::vector< raw::Channel_t > missingChannels={}, bool requireFullCoverage=true, std::string logCategory="SlidingWindowCombinerAlg")
Constructor: learns about the window pattern (keeps a reference).
temporary value
std::vector< TriggerWindowChannels_t > TriggerWindowDefs_t
Definition of all windows.
static bool inList(Cont const &c, T const &value)
Returns whether the container c has value.
bool const fRequireFullCoverage
Whether to require all channels to be used.
Windows_t const fWindowChannels
Content of channels of each window.