All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ApplyBeamGate.h
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/Trigger/Algorithms/ApplyBeamGate.h
3  * @brief Helper to manage a beam gate.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date September 16, 2020
6  */
7 
8 #ifndef ICARUSCODE_PMT_TRIGGER_ALGORITHMS_APPLYBEAMGATE_H
9 #define ICARUSCODE_PMT_TRIGGER_ALGORITHMS_APPLYBEAMGATE_H
10 
11 
12 // ICARUS libraries
13 // #include "icaruscode/PMT/Trigger/Algorithms/BeamGateMaker.h"
18 
19 // // LArSoft libraries
21 #include "lardataalg/DetectorInfo/DetectorTimingTypes.h" // optical_tick, ...
23 #include "lardataalg/Utilities/quantities/spacetime.h" // microseconds
24 
25 // // C/C++ standard libraries
26 // #include <utility> // std::pair<>
27 #include <ostream>
28 #include <vector>
29 #include <string>
30 
31 
32 // -----------------------------------------------------------------------------
33 namespace icarus::trigger {
34 
35  class ApplyBeamGateClass;
36 
37  /**
38  * @brief Returns a new `ApplyBeamGateClass` object with the specified gate.
39  * @param duration the desired duration of the gate
40  * @param delay the delay of gate start relative to the global beam gate time
41  * @param clockData the current detector clocks service provider data
42  * @param logCategory message category the returned object will use
43  * @return a new `ApplyBeamGateClass` object with the specified parameters
44  */
45  ApplyBeamGateClass makeApplyBeamGate(
48  detinfo::DetectorClocksData const& clockData,
49  std::string const& logCategory = "ApplyBeamGateClass"
50  );
51 
52  /**
53  * @brief Returns a new `ApplyBeamGateClass` object with the specified gate.
54  * @param duration the desired duration of the gate
55  * @param clockData the current detector clocks service provider data
56  * @param logCategory message category the returned object will use
57  * @return a new `ApplyBeamGateClass` object with the specified parameters
58  *
59  * The gate starts at the nominal beam gate time as reported by `clockData`.
60  */
61  ApplyBeamGateClass makeApplyBeamGate(
63  detinfo::DetectorClocksData const& clockData,
64  std::string const& logCategory = "ApplyBeamGateClass"
65  );
66 
67  std::ostream& operator<<
68  (std::ostream& out, icarus::trigger::ApplyBeamGateClass const& gate);
69 
70 } // namespace icarus::trigger
71 
72 /**
73  * @brief Helper applying a beam gate to any gate.
74  *
75  * The gate starts from `detinfo::DetectorClocks::BeamGateTime()` (with an
76  * optional delay) and has length specified on construction.
77  *
78  * The assumption that the optical tick clock starts with the electronics time
79  * is used.
80  *
81  * Access to beam gate range may happen in a few ways: in simulation time scale
82  * and in optical time ticks. In all cases, the returned object supports the
83  * calls to `start()`, `stop()` and `duration()`.
84  */
87 {
88 
89  public:
90  // @{
91  /// Type aliases
95  // @}
96 
97  /// Constructor: gets the gate (in optical ticks) and its duration (in time).
100  std::string const& logCategory = "ApplyBeamGateClass"
101  )
102  : icarus::ns::util::mfLoggingClass(logCategory)
103  , fGate(std::move(beamGate))
104  {}
105 
106  /// Returns the beam gate as a `icarus::trigger::OpticalTriggerGate`.
108  { return fGate.asGate(); }
109 
110  /// Returns the beam gate as the specified gate type `Gate`.
111  template <typename Gate>
112  Gate gateAs() const { return { gate() }; }
113 
114  /// Returns a copy of `gate` in AND with this beam gate.
115  template <typename Gate>
116  Gate apply(Gate gate) const
117  { return icarus::trigger::mulGates(gate, this->gate()); }
118 
119  /// Returns a collection of copies of the specified `gates` each in AND with
120  /// this beam gate.
121  template
122  <typename GateColl, typename GateObj = typename GateColl::value_type>
123  std::vector<GateObj> applyToAll(GateColl const& gates) const;
124 
125  /// Returns the gate as a simulation time range.
126  auto asSimulationTime() const { return fGate.asSimulationRange(); }
127 
128  /// Returns the range of the beam gate as start and stop tick.
129  auto tickRange() const { return fGate.asOptTickRange(); }
130 
131  /// Returns the length of the gate (in time units).
132  microseconds length() const { return fGate.duration(); }
133 
134  /// Returns the length of the gate (in time units).
135  optical_time_ticks lengthTicks() const { return tickRange().duration(); }
136 
137  //@{
138  /// Comparison operators.
139  bool operator== (ApplyBeamGateClass const& other) const
140  { return fGate == other.fGate; }
141  bool operator!= (ApplyBeamGateClass const& other) const
142  { return fGate != other.fGate; }
143  //@}
144 
145  private:
146 
148 
149 }; // class icarus::trigger::ApplyBeamGateClass
150 
151 
152 // -----------------------------------------------------------------------------
153 // --- inline implementation
154 // -----------------------------------------------------------------------------
158  detinfo::DetectorClocksData const& clockData,
159  std::string const& logCategory /* = "ApplyBeamGateClass" */
160  ) -> ApplyBeamGateClass
161 {
162  return {
164  (detinfo::DetectorTimings{ clockData }, duration, delay),
165  logCategory
166  };
167 } // icarus::trigger::makeApplyBeamGate()
168 
169 
170 // -----------------------------------------------------------------------------
173  detinfo::DetectorClocksData const& clockData,
174  std::string const& logCategory /* = "ApplyBeamGateClass" */
175  ) -> ApplyBeamGateClass
176  {
177  using namespace util::quantities::time_literals;
178  return makeApplyBeamGate(duration, 0.0_us, clockData, logCategory);
179  }
180 
181 
182 // -----------------------------------------------------------------------------
183 std::ostream& icarus::trigger::operator<<
184  (std::ostream& out, icarus::trigger::ApplyBeamGateClass const& gate)
185 {
186  out << gate.gate() << " (simulation time: " << gate.asSimulationTime()
187  << ")";
188  return out;
189 } // icarus::trigger::operator<< (icarus::trigger::ApplyBeamGateClass const&)
190 
191 
192 // -----------------------------------------------------------------------------
193 // --- template implementation
194 // -----------------------------------------------------------------------------
195 template
196  <typename GateColl, typename GateObj /* = typename GateColl::value_type */>
198  (GateColl const& gates) const
199 {
200  std::vector<GateObj> res;
202  gates.begin(), gates.end(), std::back_inserter(res),
203  [this](GateObj const& gate){ return apply(gate); }
204  );
205  return res;
206 } // icarus::trigger::ApplyBeamGateClass::applyToAll()
207 
208 
209 // -----------------------------------------------------------------------------
210 
211 #endif // ICARUSCODE_PMT_TRIGGER_ALGORITHMS_APPLYBEAMGATE_H
212 
213 
optical_time_ticks lengthTicks() const
Returns the length of the gate (in time units).
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
ApplyBeamGateClass makeApplyBeamGate(util::quantities::intervals::microseconds duration, util::quantities::intervals::microseconds delay, detinfo::DetectorClocksData const &clockData, std::string const &logCategory="ApplyBeamGateClass")
Returns a new ApplyBeamGateClass object with the specified gate.
static constexpr Sample_t transform(Sample_t sample)
An object representing a time gate, with a start and and end.
auto mulGates(GateColl const &gates)
Multiplies all the gates in a collection.
detinfo::timescales::optical_time_ticks optical_time_ticks
Definition: ApplyBeamGate.h:94
icarus::trigger::OpticalTriggerGate const & asGate() const
Returns the gate as an OpticalTriggerGate (electronics time).
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
Definition: spacetime.h:259
Base class facilitating logging to message facility.
icarus::trigger::OpticalTriggerGate const & gate() const
Returns the beam gate as a icarus::trigger::OpticalTriggerGate.
Helper applying a beam gate to any gate.
Definition: ApplyBeamGate.h:85
detinfo::timescales::optical_tick optical_tick
Definition: ApplyBeamGate.h:93
auto tickRange() const
Returns the range of the beam gate as start and stop tick.
Helper for logging classes.
mfLoggingClass(std::string const &logCategory)
Constructor: initializes with the specified log category.
timescale_traits< OpticalTimeCategory >::tick_interval_t optical_time_ticks
Interface to detinfo::DetectorClocks.
Gate gateAs() const
Returns the beam gate as the specified gate type Gate.
bool operator!=(ApplyBeamGateClass const &other) const
TimeRange< simulation_time > const & asSimulationRange() const
Returns the gate as start/stop pair in simulation time scale.
TimeRange< optical_tick > const & asOptTickRange() const
Returns the gate as start/stop pair in optical ticks.
auto asSimulationTime() const
Returns the gate as a simulation time range.
A trigger gate data object for optical detector electronics.
microseconds length() const
Returns the length of the gate (in time units).
Utilities for the conversion of trigger gate data formats.
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
bool operator==(ApplyBeamGateClass const &other) const
Comparison operators.
Object representing a time gate, with a start and and end.
Gate apply(Gate gate) const
Returns a copy of gate in AND with this beam gate.
timescale_traits< OpticalTimeCategory >::tick_t optical_tick
Contains all timing reference information for the detector.
BeamGateStruct makeBeamGateStruct(detinfo::DetectorTimings const &detTimings, util::quantities::intervals::microseconds duration, util::quantities::intervals::microseconds delay=util::quantities::intervals::microseconds{0.0})
Creates a BeamGateStruct object of specified duration and start.
Logical multi-level gate associated to one or more waveforms.
Dimensioned variables representing space or time quantities.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
Data types for detinfo::DetectorTimings.
Time duration() const
Returns the time duration of the gate in the specified time unit.
icarus::trigger::BeamGateStruct const fGate
std::vector< GateObj > applyToAll(GateColl const &gates) const
std::string logCategory() const
Returns the logging category string for this object.
ApplyBeamGateClass(icarus::trigger::BeamGateStruct &&beamGate, std::string const &logCategory="ApplyBeamGateClass")
Constructor: gets the gate (in optical ticks) and its duration (in time).
Definition: ApplyBeamGate.h:98