21 std::vector<raw::Channel_t> missingChannels ,
22 bool requireFullCoverage ,
23 std::string logCategory
25 : fWindowChannels(sortedWindowChannels(windows))
26 , fMissingChannels(sortChannels(
std::move(missingChannels)))
27 , fRequireFullCoverage(requireFullCoverage)
34 (std::vector<TrackedTriggerGate_t>
const& gates)
const
35 -> std::vector<TrackedTriggerGate_t>
40 checkInput(gateIndex);
42 std::vector<TrackedTriggerGate_t> combinedGates;
43 for (std::vector<raw::Channel_t>
const& channels: fWindowChannels) {
44 assert(!channels.empty());
46 combinedGates.push_back(combineChannels(gateIndex, channels));
66 auto const isChannelInWindow
67 = [](
raw::Channel_t channel, std::vector<raw::Channel_t>
const& window)
68 {
return std::binary_search(window.begin(), window.end(), channel); };
70 std::set<TrackedTriggerGate_t const*> usedGates;
71 for (std::vector<raw::Channel_t>
const& window: fWindowChannels) {
75 if (isMissingChannel(channel))
continue;
82 cet::exception
e(
"SlidingWindowCombinerAlg");
83 e <<
"SlidingWindowCombinerAlg::checkInput(): No gate has channel "
84 << channel <<
", required in the window including channels: ";
94 if (isChannelInWindow(gateChannel, window))
continue;
96 cet::exception
e(
"SlidingWindowCombinerAlg");
97 e <<
"SlidingWindowCombinerAlg::checkInput(): gate with channels {";
100 e <<
" } is not fully included in window including channels: ";
102 e <<
" (" << gateChannel <<
" is missing).\n";
106 usedGates.insert(gate);
114 std::vector<raw::Channel_t> spuriousChannels;
116 if (gateIndex.
find(channel)) spuriousChannels.push_back(channel);
118 if (!spuriousChannels.empty()) {
119 cet::exception
e(
"SlidingWindowCombinerAlg");
120 e <<
"SlidingWindowCombinerAlg::checkInput(): "
121 << spuriousChannels.size() <<
" of the " << fMissingChannels.size()
122 <<
" supposedly missing channels are actually included:";
123 for (
raw::Channel_t const channel: spuriousChannels) e <<
" " << channel;
131 if (fRequireFullCoverage) {
132 std::set<TrackedTriggerGate_t const*> allGates;
133 for (
auto const channel: util::counter<raw::Channel_t >(gateIndex.
nChannels())) {
134 if (isMissingChannel(channel))
continue;
135 allGates.insert(&(gateIndex[channel]));
138 std::vector<TrackedTriggerGate_t const*> unusedGates;
140 allGates.cbegin(), allGates.cend(), usedGates.cbegin(), usedGates.cend(),
141 std::back_inserter(unusedGates)
143 if (!unusedGates.empty()) {
145 cet::exception
e(
"SlidingWindowCombinerAlg");
146 e <<
"SlidingWindowCombinerAlg::checkInput(): "
147 <<
"used only " << usedGates.size() <<
"/" << allGates.size()
148 <<
" input trigger gates, " << unusedGates.size() <<
" were not used:";
168 assert(!channels.empty());
170 auto iChannel = firstChannelPresent(channels);
171 auto const cend = channels.end();
172 if (iChannel ==
cend)
return {};
180 while (++iChannel !=
cend) {
181 if (isMissingChannel(*iChannel))
continue;
186 mergeGateInto(gate, inputGate);
200 auto iChannel = channels.begin();
201 auto const cend = channels.end();
202 while (iChannel !=
cend)
if (!isMissingChannel(*iChannel))
return iChannel;
213 auto const& channels = dest.
gate().channels();
214 if (inList(channels, *(input.
gate().channels().begin())))
return false;
228 for (
auto& window: newWindows) std::sort(window.begin(), window.end());
235 (std::vector<raw::Channel_t> channels) -> std::vector<raw::Channel_t>
237 std::sort(channels.begin(), channels.end());
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
void checkInput(TriggerGateIndex_t const &gates) const
Throws an exception if the gates are not suitable for input.
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.
TriggerGate_t const * find(raw::Channel_t const channel) const
Returns the gate corresponding to the specified channel.
auto cend(FixedBins< T, C > const &) noexcept
WindowChannels_t::const_iterator firstChannelPresent(WindowChannels_t const &channels) const
Returns an iterator to the first of the channels which is not missing.
Algorithm to combine trigger channels into sliding windows.
auto sumGates(GateColl const &gates)
Sums all the gates in a collection.
static Windows_t sortedWindowChannels(Windows_t const &windows)
Returns windows with numerically sorted channel numbers.
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)
TriggerGate_t const & gate() const &
Returns the enclosed gate.
static std::vector< raw::Channel_t > sortChannels(std::vector< raw::Channel_t > channels)
Returns a sorted copy of channels.
std::string to_string(WindowPattern const &pattern)
std::vector< TrackedTriggerGate_t > combine(std::vector< TrackedTriggerGate_t > const &gates) const
Combines the gates according to the configured grouping.
Associates each optical detector channel to a gate.
decltype(auto) channels() const
Returns the list of channels of the enclosed gate.
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).
unsigned int nChannels() const
Returns the total number of registered channels.