All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BeamGateStruct.h
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/Trigger/Algorithms/BeamGateStruct.h
3  * @brief An object representing a time gate, with a start and and end.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date September 15, 2020
6  */
7 
8 #ifndef ICARUSCODE_PMT_TRIGGER_ALGORITHMS_BEAMGATESTRUCT_H
9 #define ICARUSCODE_PMT_TRIGGER_ALGORITHMS_BEAMGATESTRUCT_H
10 
11 
12 // ICARUS libraries
15 
16 // LArSoft libraries
18 #include "lardataalg/DetectorInfo/DetectorTimingTypes.h" // simulation_time, ...
20 #include "lardataalg/Utilities/quantities/spacetime.h" // microseconds
21 
22 // C/C++ standard libraries
23 #include <utility> // std::pair<>
24 #include <ostream>
25 
26 
27 // -----------------------------------------------------------------------------
28 namespace icarus::trigger {
29  struct BeamGateStruct;
30 
31  /**
32  * @brief Creates a `BeamGateStruct` object of specified duration and start.
33  * @param detTimings object used for time conversions
34  * @param duration length of the gate [&micro;s]
35  * @param delay (default: `0_us`) time the gate opens relative to beam gate
36  * opening [&micro;s]
37  * @return a `BeamGateStruct`
38  *
39  * This is for when I will regret to have coupled `BeamGateStruct` interface
40  * to `detinfo::DetectorTimings`.
41  */
42  BeamGateStruct makeBeamGateStruct(
47  );
48 
49 } // icarus::trigger
50 
51 
52 /**
53  * @brief Object representing a time gate, with a start and and end.
54  *
55  * The object caches the gate in a few formats.
56  *
57  */
59 
60  // type aliases
65 
66  /// Utility class expressing a time range.
67  template <typename Time>
68  struct TimeRange: std::pair<Time, Time> {
69  using std::pair<Time, Time>::pair;
70  auto start() const { return this->first; }
71  auto end() const { return this->second; }
72  auto duration() const { return end() - start(); }
73  }; // TimeRange
74 
75 
76  /**
77  * @brief Constructor: gate of specified duration and start.
78  * @param duration length of the gate [&micro;s]
79  * @param delay (default: `0_us`) time the gate opens relative to beam gate
80  * opening [&micro;s]
81  * @param detTimings object used for time conversions
82  */
86  );
87 
88 
89  // --- BEGIN -- Access -------------------------------------------------------
90  /// @name Access
91  /// @{
92 
93  /// Returns the gate as an OpticalTriggerGate (electronics time).
95 
96  /// Returns the gate as start/stop pair in simulation time scale.
98  { return fRangeSim; }
99 
100  /// Returns the gate as start/stop pair in optical ticks.
102  { return fRangeOpt; }
103 
104  /// Returns the gate as start/stop pair in electronics time scale.
106  { return fRangeElec; }
107 
108  /// Returns the time duration of the gate in the specified time unit.
109  template <typename Time = microseconds>
110  Time duration() const { return { asElectronicsTimeRange().duration() }; }
111 
112  /// @}
113  // --- END -- Access ---------------------------------------------------------
114 
115  //@{
116  /// Comparison operators.
117  bool operator== (BeamGateStruct const& other) const
118  { return asGate() == other.asGate(); }
119  bool operator!= (BeamGateStruct const& other) const
120  { return asGate() != other.asGate(); }
121  //@}
122 
123  private:
124  // so far, we cache everything (but not the timings helper)
125 
127 
129 
131 
133 
134 }; // struct icarus::trigger::BeamGateStruct
135 
136 
137 // -----------------------------------------------------------------------------
138 // --- inline implementation
139 // -----------------------------------------------------------------------------
141  microseconds duration, microseconds delay,
143  )
144  : fGate(icarus::trigger::BeamGateMaker{detTimings}(duration, delay))
145  , fRangeElec
146  {
147  detTimings.BeamGateTime() + delay,
148  detTimings.BeamGateTime() + delay + duration
149  }
150  , fRangeSim
151  {
152  detTimings.toSimulationTime(fRangeElec.start()),
153  detTimings.toSimulationTime(fRangeElec.end())
154  }
155  , fRangeOpt
156  {
157  detTimings.toOpticalTick(fRangeElec.start()),
158  detTimings.toOpticalTick(fRangeElec.end())
159  }
160 {} // icarus::trigger::BeamGateStruct::BeamGateStruct()
161 
162 
163 // -----------------------------------------------------------------------------
164 namespace icarus::trigger {
165 
166  template <typename Time>
167  std::ostream& operator<< (
168  std::ostream& out,
170  )
171  {
172  out << range.start() << " -- " << range.end()
173  << " (duration: " << range.duration() << ")";
174  return out;
175  } // operator<< (icarus::trigger::BeamGateStruct::TimeRange<>)
176 
177 } // namespace icarus::trigger
178 
179 
180 // -----------------------------------------------------------------------------
185  /* = util::quantities::microsecond{ 0.0 } */
186 ) {
187 
188  return { duration, delay, detTimings };
189 
190 } // icarus::trigger::makeBeamGateStruct()
191 
192 
193 // -----------------------------------------------------------------------------
194 
195 #endif // ICARUSCODE_PMT_TRIGGER_ALGORITHMS_BEAMGATESTRUCT_H
BeamGateStruct(microseconds duration, microseconds delay, detinfo::DetectorTimings const &detTimings)
Constructor: gate of specified duration and start.
TimeRange< simulation_time > const fRangeSim
Utility class expressing a time range.
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
std::ostream & operator<<(std::ostream &out, icarus::trigger::ApplyBeamGateClass const &gate)
icarus::trigger::OpticalTriggerGate const fGate
bool operator!=(BeamGateStruct const &other) const
util::quantities::intervals::microseconds microseconds
detinfo::timescales::simulation_time simulation_time
pure virtual base interface for detector clocks
Interface to detinfo::DetectorClocks.
TimeRange< electronics_time > const fRangeElec
detinfo::timescales::optical_tick optical_tick
TimeRange< simulation_time > const & asSimulationRange() const
Returns the gate as start/stop pair in simulation time scale.
timescale_traits< SimulationTimeCategory >::time_point_t simulation_time
A point in time on the simulation time scale.
TimeRange< optical_tick > const & asOptTickRange() const
Returns the gate as start/stop pair in optical ticks.
A trigger gate data object for optical detector electronics.
bool operator==(BeamGateStruct const &other) const
Comparison operators.
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
Object representing a time gate, with a start and and end.
timescale_traits< OpticalTimeCategory >::tick_t optical_tick
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.
Class to create an object representing a beam gate.
detinfo::timescales::electronics_time electronics_time
Simple utility to generate gates around beam time.
Definition: BeamGateMaker.h:49
fDetProps &fDetProps fDetProps &fDetProps detTimings
Time duration() const
Returns the time duration of the gate in the specified time unit.
TimeRange< electronics_time > const & asElectronicsTimeRange() const
Returns the gate as start/stop pair in electronics time scale.
timescale_traits< ElectronicsTimeCategory >::time_point_t electronics_time
A point in time on the electronics time scale.
TimeRange< optical_tick > const fRangeOpt