All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FixedTriggerGateBuilder.h
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/Trigger/Algorithms/FixedTriggerGateBuilder.h
3  * @brief Fixed-length gate builder.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date April 1, 2019
6  * @see `icaruscode/PMT/Trigger/Algorithms/FixedTriggerGateBuilder.cxx`
7  *
8  */
9 
10 #ifndef ICARUSCODE_PMT_TRIGGER_ALGORITHMS_FIXEDTRIGGERGATEBUILDER_H
11 #define ICARUSCODE_PMT_TRIGGER_ALGORITHMS_FIXEDTRIGGERGATEBUILDER_H
12 
13 
14 // ICARUS libraries
18 
19 // LArSoft libraries
21 #include "lardataalg/Utilities/quantities_fhicl.h" // for microsecond parameter
23 
24 // framework libraries
25 #include "messagefacility/MessageLogger/MessageLogger.h"
26 #include "fhiclcpp/types/Atom.h"
27 
28 // C/C++ standard libraries
29 #include <vector>
30 
31 
32 namespace icarus::trigger {
33 
34  // ---------------------------------------------------------------------------
35  //
36  // declarations
37  //
38 
39  class FixedTriggerGateBuilder;
40 
41  // ---------------------------------------------------------------------------
42 
43 } // namespace icarus::trigger
44 
45 
46 //------------------------------------------------------------------------------
47 /**
48  * @brief Fixed-length gate builder.
49  * @see `icarus::trigger::DynamicTriggerGateBuilder`
50  *
51  * Gates are opened when the waveform transits above threshold, and closed a
52  * fixed time after that.
53  * Optionally, if a transition happens when the gate is already open, the
54  * opening can be extended by another fixed time; otherwise, the opening time
55  * is considered dead time and transitions occurring in that while will be
56  * ignored.
57  *
58  * Note that gates at higher thresholds are usually not contained in the ones
59  * with lower thresholds: the former ones start later _and_ end later.
60  * Also, transitions on higher thresholds do not affect the lower threshold
61  * gates. For example, if the thresholds are at 50 and 100 counts, and the
62  * waveforms raises to 110, then starts oscillating between 90 and 110 counts,
63  * the gate for threshold 100 will be reopened or kept open, but the one for
64  * threshold 50 will close after the fixed time has elapsed and stay closed
65  * as long as no transition from under 50 to 50 or more happens.
66  *
67  */
70 {
72 
73  class FixedGateManager: private GateManager {
74 
75  struct FixedGateInfo: public GateInfoBase {
76  /// Activity ignored up to this tick excluded.
77  optical_tick openUntil { TriggerGateData_t::MinTick };
78 
79  /// Ticks to keep the gate open.
81 
82  /// Whether new crossings extend the duration of opening or are ignored.
83  bool const extendGate { false };
84 
87  bool extendGate = false
88  )
89  : GateInfoBase(gate), gateDuration(gateDuration), extendGate(extendGate)
90  {}
91 
92  void belowThresholdAt(optical_tick /* tick */) {}
94  {
95  using namespace util::quantities::electronics_literals;
96  MF_LOG_TRACE(details::TriggerGateDebugLog)
97  << "Declared above threshold at: " << tick;
98  if ((tick < openUntil) && !extendGate) {
99  MF_LOG_TRACE(details::TriggerGateDebugLog)
100  << " we are in dead time until " << openUntil
101  << ", come back later.";
102  return; // open only if not in "dead time"
103  }
104 
105  // open or extend the gate:
106  auto const reopenAt = extendGate? openUntil: tick;
107  openUntil = tick + gateDuration; // set some dead time
108  gate().openBetween(reopenAt.value(), openUntil.value());
109 
110  MF_LOG_TRACE(details::TriggerGateDebugLog) << " gate (re)opened ("
111  << gate().openingCount((tick - 1_tick).value())
112  << " => " << gate().openingCount(tick.value())
113  << ") for " << gateDuration << " until " << openUntil
114  << " (" << gate().openingCount((openUntil - 1_tick).value())
115  << " => " << gate().openingCount(openUntil.value()) << ")";
116  } // aboveThresholdAt()
117 
118  }; // struct FixedGateInfo
119 
120 
122 
123  bool const extendGate;
124 
125 
126  public:
128 
130  : gateDuration(gateDuration), extendGate(extendGate) {}
131 
133  { return { gate, gateDuration, extendGate }; }
134 
135  }; // struct FixedGateManager
136 
137 
138  public:
139 
140  // --- BEGIN Configuration ---------------------------------------------------
141  struct Config: public Base_t::Config {
142 
143  using Name = fhicl::Name;
144  using Comment = fhicl::Comment;
145 
146 
147  fhicl::Atom<microsecond> GateDuration {
148  Name("GateDuration"),
149  Comment("duration of a trigger gate")
150  };
151 
152  fhicl::Atom<bool> ExtendGate {
153  Name("ExtendGate"),
154  Comment("whether gate is extended by crossing activity inside it"),
155  false
156  };
157 
158  }; // struct Config
159  // --- END Configuration -----------------------------------------------------
160 
161 
162  /// Constructor: sets the configuration.
163  FixedTriggerGateBuilder(Config const& config);
164 
165 
166  /// Algorithm setup.
167  virtual void setup(detinfo::DetectorTimings const& timings) override;
168 
169  /// Returns a collection of `TriggerGates` objects sorted by threshold.
170  virtual std::vector<TriggerGates> build
171  (std::vector<WaveformWithBaseline> const& waveforms) const override
172  {
174  }
175 
176  private:
177 
178  // --- BEGIN Configuration parameters ----------------------------------------
179 
180  microsecond fGateDuration; ///< Duration of a channel gate [&micro;s]
181 
182  optical_time_ticks fGateTicks; ///< Duration of a channel gate [ticks]
183 
184  bool const fExtendGate; ///< Whether gate opening time can be extended.
185 
186  // --- END Configuration parameters ------------------------------------------
187 
188 
189  // --- BEGIN Setup -----------------------------------------------------------
190 
191  // --- END Setup -------------------------------------------------------------
192 
193 
194 }; // class icarus::trigger::FixedTriggerGateBuilder
195 
196 
197 //------------------------------------------------------------------------------
198 
199 #endif // ICARUSCODE_PMT_TRIGGER_ALGORITHMS_FIXEDTRIGGERGATEBUILDER_H
microsecond fGateDuration
Duration of a channel gate [s].
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Definition: spacetime.h:119
optical_time_ticks fGateTicks
Duration of a channel gate [ticks].
virtual void setup(detinfo::DetectorTimings const &timings) override
Algorithm setup.
FixedGateInfo(TriggerGate_t &gate, optical_time_ticks gateDuration, bool extendGate=false)
timescale_traits< OpticalTimeCategory >::tick_interval_t optical_time_ticks
FixedGateManager(optical_time_ticks gateDuration, bool extendGate=false)
BEGIN_PROLOG GateDuration
Utilities to read and write quantities in FHiCL configuration.
constexpr auto TriggerGateDebugLog
Simple type definitions for trigger algorithms.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
FixedTriggerGateBuilder(Config const &config)
Constructor: sets the configuration.
BEGIN_PROLOG vertical distance to the surface Name
GateInfo_t create(GateInfo_t::TriggerGate_t &gate) const
Algorithm to produce trigger gates out of optical readout waveforms.
optical_tick openUntil
Activity ignored up to this tick excluded.
Dimensioned variables related to electronics.
timescale_traits< OpticalTimeCategory >::tick_t optical_tick
virtual std::vector< TriggerGates > build(std::vector< WaveformWithBaseline > const &waveforms) const override
Returns a collection of TriggerGates objects sorted by threshold.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
bool const extendGate
Whether new crossings extend the duration of opening or are ignored.
temporary value
bool const fExtendGate
Whether gate opening time can be extended.
std::vector< TriggerGates > unifiedBuild(GateMgr &&gateManager, std::vector< WaveformWithBaseline > const &waveforms) const
Returns a collection of TriggerGates objects sorted by threshold.