24 #include "messagefacility/MessageLogger/MessageLogger.h"
38 std::string
const& logCategory
40 : icarus::ns::util::mfLoggingClass(logCategory)
41 , fWindowTopology(
std::move(windowTopology))
42 , fWindowPattern(
std::move(windowPattern))
43 , fBeamGate(
std::move(beamGate))
51 std::string
const& logCategory
53 : icarus::ns::util::mfLoggingClass(logCategory)
54 , fWindowTopology(
std::move(windowTopology))
55 , fWindowPattern(
std::move(windowPattern))
65 verifyInputTopology(gates);
67 auto const& inBeamGates = fBeamGate? fBeamGate->applyToAll(gates): gates;
72 std::size_t
const nWindows = fWindowTopology.nWindows();
81 = applyWindowPattern(fWindowPattern, iWindow, inBeamGates);
83 if (!windowResponse)
continue;
86 assert(windowResponse.
location() == iWindow);
88 mfLogTrace() <<
"Pattern fired on window #" << iWindow
89 <<
" at tick " << windowResponse.
atTick();
92 std::vector<TriggerInfo_t::OpeningInfo_t>
const& triggers
93 = windowResponse.
all();
95 auto log = mfLogTrace();
96 log <<
"Pattern fired " << triggers.size()
97 <<
" times on window #" << iWindow <<
":";
99 log <<
" [#" << iTrigger <<
"] " <<
" on " << trigger.tick
101 if (&trigger == pMain) log <<
"main; ";
102 log <<
"lvl=" << trigger.level <<
")";
111 if (!triggerInfo) mfLogTrace() <<
" (new global trigger)";
112 triggerInfo.
emplace(iWindow, windowResponse);
123 {
return fBeamGate.has_value(); }
129 { fBeamGate.emplace(std::move(beamGate)); }
134 { fBeamGate.reset(); }
146 std::string errorMsg;
149 std::string windowError;
152 if (iWindow >= fWindowTopology.nWindows()) {
153 windowError =
"unexpected input gate #" +
std::to_string(iWindow) +
" (";
157 errorMsg += windowError +
'\n';
162 = fWindowTopology.info(iWindow);
164 auto const channelInWindow
167 {
return std::binary_search(
begin,
end, channel); }
171 if (channelInWindow(channel))
continue;
172 if (windowError.empty()) {
180 if (!windowError.empty()) errorMsg += windowError +
'\n';
184 if (fWindowTopology.nWindows() >
size(gates)) {
190 if (errorMsg.empty())
return;
193 throw cet::exception(
"SlidingWindowPatternAlg")
194 <<
"Some channels from trigger gates do not match"
195 " the configured window allocation:\n"
198 <<
"Window configuration: "
199 << fWindowTopology <<
"\n";
223 {
return gateIn(gates[index]); };
230 if (
pattern.requireUpstreamWindow && !windowInfo.hasUpstreamWindow())
232 if (
pattern.requireDownstreamWindow && !windowInfo.hasDownstreamWindow())
242 <<
"Window info #" << windowInfo.index <<
" pattern " <<
pattern.tag();
246 std::optional<TriggerGateData_t>
const mainPlusOpposite
247 = (
pattern.minSumInOppositeWindows > 0U)
249 windowInfo.hasOppositeWindow()
250 ?
sumGates(gateAt(windowInfo.index), gateAt(windowInfo.opposite))
251 : gateAt(windowInfo.index)
259 = mainPlusOpposite? *mainPlusOpposite: gateAt(windowInfo.index);
261 mfLogTrace() <<
" base: " <<
compactdump(trigPrimitive);
264 if (
pattern.minInMainWindow > 0U) {
268 <<
" main >= " <<
pattern.minInMainWindow <<
": "
273 if ((
pattern.minInOppositeWindow > 0U) && windowInfo.hasOppositeWindow()) {
276 mfLogTrace() <<
" opposite [#" << windowInfo.opposite <<
"]: "
282 if (
pattern.minSumInOppositeWindows > 0U) {
283 assert(mainPlusOpposite.has_value());
286 mfLogTrace() <<
" sum [+ #" << windowInfo.opposite <<
"]: "
293 if ((
pattern.minInUpstreamWindow > 0U) && windowInfo.hasUpstreamWindow()) {
299 if ((
pattern.minInDownstreamWindow > 0U) && windowInfo.hasDownstreamWindow())
306 mfLogTrace() <<
" final: " <<
compactdump(trigPrimitive);
314 extractOpeningInfo.setLocation
317 while (extractOpeningInfo) {
318 auto info = extractOpeningInfo();
335 = fWindowTopology.info(iWindow);
336 assert(windowInfo.
index == iWindow);
338 return applyWindowPattern(windowInfo,
pattern, gates);
Data structure to communicate internally a trigger response.
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.
ReadoutTriggerGate & Mul(ReadoutTriggerGate const &other)
Combines with a gate, keeping the product of openings of the two.
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.
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
void verifyInputTopology(TriggerGates_t const &gates) const
Checks gates are compatible with the current window configuration.
std::vector< OpeningInfo_t > const & all() const
Utilities for the conversion of trigger gate data formats.
Definition of util::enumerate().
LocationID_t location() const
Returns the ID of the location of the trigger (undefined if !fired()).
std::size_t size(FixedBins< T, C > const &) noexcept
OpeningInfo_t const & main() const
Returns the full data (undefined if !fired()).
Information about composition and topology of trigger sliding windows.
bool hasLocation() const
Returns if the location of the trigger is set (undefined if !fired()).
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.
Information of a single window.
Helper data structure to store transient trigger result.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Specification of the requirement of sliding window firing pattern.
void clearBeamGate()
Do not apply any beam gate.
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Logical multi-level gate associated to one or more readout channels.
auto end(FixedBins< T, C > const &) noexcept
std::size_t LocationID_t
Type for ID of trigger location.
Utilities for the conversion of trigger gate data formats.
Test of util::counter and support utilities.
auto sumGates(GateColl const &gates)
Sums all the gates in a collection.
auto begin(FixedBins< T, C > const &) noexcept
bool hasBeamGate() const
Returns whether a beam gate is being applied.
Additional information on the trigger.
optical_tick atTick() const
Returns the time of the trigger (undefined if !fired()).
std::string to_string(WindowPattern const &pattern)
std::vector< raw::Channel_t > channels
Optical detector channels covered by this window.
std::vector< InputTriggerGate_t > TriggerGates_t
A list of trigger gates from input.
WindowIndex_t index
Index of the window this information is about.
void emplace(std::size_t index, TriggerInfo_t info)
GateObj discriminate(GateObj const &gate, typename GateObj::OpeningCount_t threshold=1U, typename GateObj::OpeningCount_t pass=1U, typename GateObj::OpeningCount_t fail=0U)
Returns a discriminated version of gate.
Complete information from this algorithm, standard + non-standard (extra).
Applies sliding window trigger patterns.
void add(OpeningInfo_t info)
std::size_t nTriggers() const
Returns the number of registered triggers.
auto compactdump(ReadoutTriggerGate< Tick, TickInterval, ChannelIDType > const &gate) -> details::CompactFormatter< ReadoutTriggerGate< Tick, TickInterval, ChannelIDType >>
Manipulator-like function for compact format of trigger gates.
decltype(auto) gateIn(Gate &&gate)
Returns the trigger gate (a ReadoutTriggerGate) from the specified gate.