10 #ifndef ICARUSCODE_PMT_TRIGGER_UTILITIES_TRIGGERGATEOPERATIONS_H
11 #define ICARUSCODE_PMT_TRIGGER_UTILITIES_TRIGGERGATEOPERATIONS_H
22 namespace icarus::trigger {
64 template <
typename GateObj>
67 typename GateObj::OpeningCount_t threshold = 1U,
68 typename GateObj::OpeningCount_t pass = 1U,
69 typename GateObj::OpeningCount_t fail = 0U
87 template <
typename BIter,
typename EIter>
101 template <
typename GateColl>
102 [[nodiscard]]
auto sumGates(GateColl
const& gates);
121 template <
typename AGate,
typename BGate,
typename... OTrigGates>
123 (AGate
A, BGate
const& B, OTrigGates
const&... others);
143 template <
typename BIter,
typename EIter>
157 template <
typename GateColl>
158 [[nodiscard]]
auto mulGates(GateColl
const& gates);
180 template <
typename AGate,
typename BGate,
typename... OTrigGates>
182 (AGate
A, BGate
const& B, OTrigGates
const&... others);
203 template <
typename BIter,
typename EIter>
218 template <
typename GateColl>
219 [[nodiscard]]
auto maxGates(GateColl
const& gates);
238 template <
typename AGate,
typename BGate,
typename... OTrigGates>
240 (AGate
A, BGate
const& B, OTrigGates
const&... others);
261 template <
typename BIter,
typename EIter>
276 template <
typename GateColl>
277 [[nodiscard]]
auto minGates(GateColl
const& gates);
296 template <
typename AGate,
typename BGate,
typename... OTrigGates>
298 (AGate
A, BGate
const& B, OTrigGates
const&... others);
333 template <
typename Op,
typename AGate,
typename BGate,
typename... OGates>
335 (Op op, AGate
A, BGate
const& B, OGates
const&... others);
350 template <
typename Op,
typename GateColl>
351 [[nodiscard]]
auto OpGateColl(Op op, GateColl
const& gates);
369 template <
typename Op,
typename BIter,
typename EIter>
385 inline constexpr
auto Min = [](
auto A,
auto const& B){
A.Min(B);
return A; };
387 inline constexpr
auto Max = [](
auto A,
auto const& B){
A.Max(B);
return A; };
389 inline constexpr
auto Sum = [](
auto A,
auto const& B){
A.Sum(B);
return A; };
391 inline constexpr
auto Mul = [](
auto A,
auto const& B){
A.Mul(B);
return A; };
410 template <
typename GateObj>
413 typename GateObj::OpeningCount_t threshold ,
414 typename GateObj::OpeningCount_t pass ,
415 typename GateObj::OpeningCount_t fail
421 auto discrGate { gate };
423 auto const closeToOpen
424 =
static_cast<typename GateObj::OpeningDiff_t
>(pass - fail);
430 auto lastTick = discrGate.MinTick;
431 if (gate.openingCount(lastTick) < threshold) {
433 discrGate.setOpeningAt(lastTick, fail);
437 discrGate.setOpeningAt(lastTick, pass);
440 lastTick = gate.findClose(threshold, ++lastTick);
441 if (lastTick != gate.MaxTick) discrGate.closeAt(lastTick, closeToOpen);
445 while (lastTick < gate.MaxTick) {
448 lastTick = gate.findOpen(threshold, ++lastTick);
449 if (lastTick == gate.MaxTick)
break;
450 discrGate.openAt(lastTick, closeToOpen);
453 lastTick = gate.findClose(threshold, ++lastTick);
454 if (lastTick == gate.MaxTick)
break;
455 discrGate.closeAt(lastTick, closeToOpen);
466 template <
typename Op,
typename AGate,
typename BGate,
typename... OGates>
468 (Op op, AGate
A, BGate
const& B, OGates
const&... others)
471 if constexpr(
sizeof...(others) == 0U) {
473 if constexpr(isTrackedTriggerGate_v<AGate>) {
474 if constexpr(isTrackedTriggerGate_v<BGate>) {
475 A.tracking().add(B.tracking());
477 A.gate() = op(std::move(A.gate()),
gateIn(B));
480 else return op(std::move(A), B);
490 template <
typename Op,
typename GateColl>
496 template <
typename Op,
typename BIter,
typename EIter>
500 using Gate_t =
typename std::iterator_traits<BIter>::value_type;
503 if (begin == end)
return Gate_t{};
506 Gate_t resGate = *iGate;
507 while (++iGate != end)
508 resGate =
OpGates(std::move(op), std::move(resGate), *iGate);
518 template <
typename AGate,
typename BGate,
typename... OGates>
524 template <
typename BIter,
typename EIter>
530 template <
typename GateColl>
538 template <
typename AGate,
typename BGate,
typename... OGates>
544 template <
typename BIter,
typename EIter>
550 template <
typename GateColl>
558 template <
typename AGate,
typename BGate,
typename... OGates>
564 template <
typename BIter,
typename EIter>
570 template <
typename GateColl>
578 template <
typename AGate,
typename BGate,
typename... OGates>
584 template <
typename BIter,
typename EIter>
590 template <
typename GateColl>
598 #endif // ICARUSCODE_PMT_TRIGGER_UTILITIES_TRIGGERGATEOPERATIONS_H
auto maxGates(GateColl const &gates)
Computes the gate with the maximum opening of gates from collection.
auto maxGatesSequence(BIter const begin, EIter const end)
Computes the gate with the maximum opening of a sequence of gates.
auto mulGates(GateColl const &gates)
Multiplies all the gates in a collection.
auto OpGateColl(Op op, GateColl const &gates)
Computes the result of an operation on all gates from collection.
auto mulGatesSequence(BIter const begin, EIter const end)
Multiplies a sequence of gates.
A trigger gate data object for optical detector electronics.
auto end(FixedBins< T, C > const &) noexcept
auto sumGates(GateColl const &gates)
Sums all the gates in a collection.
auto begin(FixedBins< T, C > const &) noexcept
AGate OpGates(Op op, AGate A, BGate const &B, OGates const &...others)
Applies an operation to two gates.
A wrapper to trigger gate objects tracking the contributions.
auto minGates(GateColl const &gates)
Computes the gate with the minimum opening of gates from collection.
auto sumGatesSequence(BIter const begin, EIter const end)
Sums a sequence of gates.
auto OpGatesSequence(Op op, BIter const begin, EIter const end)
Computes the result of an operation on all gates in the sequence.
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.
auto minGatesSequence(BIter const begin, EIter const end)
Computes the gate with the minimum opening of a sequence of gates.
decltype(auto) gateIn(Gate &&gate)
Returns the trigger gate (a ReadoutTriggerGate) from the specified gate.