DetectorClocksStandard.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // DetectorClocks.h
4 //
5 // This class provides electronics various electronics clocks. Currently supports
6 // three types of clocks: TPC, Optical, and Trigger in order to support the
7 // MicroBooNE experiment.
8 //
9 // Formally known as TimeService.
10 //
11 ////////////////////////////////////////////////////////////////////////
12 
13 #ifndef LARDATAALG_DETECTORINFO_DETECTORCLOCKSSTANDARD_H
14 #define LARDATAALG_DETECTORINFO_DETECTORCLOCKSSTANDARD_H
15 
16 #include <stddef.h>
17 #include <string>
18 #include <vector>
19 
20 #include "fhiclcpp/fwd.h"
24 
25 namespace detinfo {
26 
27  /**
28  * @brief Implementation of `detinfo::DetectorClocks` interface with fixed
29  * settings from configuration.
30  *
31  * In this implementation, all quantities are defined at configuration time
32  * and are unchanged for the duration of the entire job, with the exception
33  * of the trigger time (see below).
34  *
35  * Configuration parameters
36  * =========================
37  *
38  * All configuration parameters are mandatory, unless explicitly stated.
39  *
40  * * *G4RefTime* (_nanoseconds_):
41  * @ref DetectorClocksSimulationTime "simulation (Geant4) start time" in
42  * @ref DetectorClocksElectronicsTime "electronics time scale", i.e. when
43  * time `0.0` of simulation happens in the electronics time scale
44  * * *TriggerOffsetTPC*: time elapsed between the
45  * @ref DetectorClocksTPCelectronicsStartTime "start of the TPC readout clock"
46  * and the @ref DetectorClocksHardwareTrigger "hardware trigger"; it can
47  * be expressed in one of two ways:
48  * * negative number [&micro;s]: the offset of the start of the TPC
49  * readout clock start respect to the trigger time (where negative
50  * means that the clock starts _before_ the trigger arrives)
51  * * positive number [ticks]: the number of TPC readout clock tick at
52  * which the trigger arrives; despite this being a tick number, it can
53  * be fractional for added precision
54  *
55  * For example, `TriggerOffsetTPC` of `-1600.0` means that the TDC clock
56  * starts 1.6 milliseconds before the hardware trigger. `TriggerOffsetTPC`
57  * of `3200.0` means that the trigger arrives at the exact start of tick
58  * 3200 of the TPC readout. In this example, if the sampling frequency of
59  * that readout is 2 MHz, these two settings are equivalent.
60  * * *FramePeriod* (_microseconds_): duration of an electronics clock frame;
61  * @ref DetectorClocksIntroClocks "all clocks" share the same frame period
62  * * *ClockSpeedTPC* (_megahertz_): frequency of the
63  * @ref DetectorClocksIntroClocks "TPC electronics clock"
64  * * *ClockSpeedOptical* (_megahertz_): frequency of the
65  * @ref DetectorClocksIntroClocks "optical electronics clock"
66  * * *ClockSpeedTrigger* (_megahertz_): frequency of the
67  * @ref DetectorClocksIntroClocks "trigger electronics clock"
68  * * *ClockSpeedExternal* (_megahertz_): frequency of the
69  * @ref DetectorClocksIntroClocks "external electronics clock"
70  * * *DefaultTrigTime* (_microseconds_): the default
71  * @ref DetectorClocksHardwareTrigger "hardware trigger time", measured in
72  * the @ref DetectorClocksElectronicsTime "electronics time frame"
73  * * *DefaultBeamTime* (_microseconds_): the default
74  * @ref DetectorClocksBeamGateOpening "beam gate opening time", measured
75  * in the @ref DetectorClocksElectronicsTime "electronics time frame"
76  * * *TrigModuleName* (_string_): input tag for the trigger data product
77  * (see "Trigger time" section below)
78  * * *InheritClockConfig* (_boolean_): whether to inherit the configuration
79  * from previous jobs (see "Consistency check" below)
80  *
81  *
82  * Consistency check
83  * ------------------
84  *
85  * The consistency check feature verifies that the current configuration of
86  * `detinfo::DetectorClocksStandard` is compatible with the one from previous
87  * jobs. It is expected that when this feature is enabled
88  * (`InheritClockConfig` is configured to be `true`), either the configuration
89  * is overridden to follow the previous ones, or an exception is thrown in
90  * case of inconsistency.
91  *
92  * The service provider (`detinfo::DetectorClocksStandard`) does not provide
93  * a facility to inherit configuration from a previous job, but it stores the
94  * expectation whether this should happen (`InheritClockConfig()`).
95  * The service provider manager is in charge of implementing this feature
96  * (see `detinfo::DetectorClocksStandardService` for the manager in the _art_
97  * environment).
98  *
99  *
100  * Timing specifics
101  * =================
102  *
103  * For the general timing requirements, see the documentation of
104  * `detinfo::DetectorClocks`.
105  *
106  *
107  * Trigger time
108  * -------------
109  *
110  * In this implementation, the trigger time and the beam gate time both
111  * default to 0.0 &micro;s.
112  *
113  * The manager of this provider is expected to set those values by calling
114  * `detinfo::DetectorClocksStandard::SetTriggerTime()`. See
115  * `detinfo::DetectorClocksStandardService` for the manager in the _art_
116  * environment.
117  *
118  *
119  * @bug `ExternalClock()` clock is never initialized!
120  *
121  */
122  class DetectorClocksStandard final : public DetectorClocks {
123  public:
126 
127  void
128  SetConfigValue(size_t i, double val)
129  {
130  fConfigValue[i] = val;
131  }
132 
133  /**
134  * @brief Returns the input tag of the trigger data product.
135  * @return the input tag of the trigger data product (as string)
136  *
137  * The trigger module name is set directly in the configuration as
138  * `TrigModuleName`.
139  */
140  std::string const&
142  {
143  return fTrigModuleName;
144  }
145 
146  /**
147  * @brief Returns the input tag of the trigger data product for G4Ref correctons.
148  * @return the input tag of the trigger data product (as string)
149  *
150  * The trigger module name is set directly in the configuration as
151  * `G4RefCorrTrigModuleName`.
152  */
155  {
157  }
158 
159  std::vector<std::string> const&
160  ConfigNames() const override
161  {
162  return fConfigName;
163  }
164  std::vector<double> const&
165  ConfigValues() const override
166  {
167  return fConfigValue;
168  }
169 
171  DataForJob() const override
172  {
173  return DetectorClocksData{
174  fConfigValue[kG4RefTime], // FIXME: Should be run-dependent?
176  fTriggerTime,
179  ElecClock{fTriggerTime, fConfigValue[kFramePeriod], fConfigValue[kClockSpeedOptical]},
180  ElecClock{fTriggerTime, fConfigValue[kFramePeriod], fConfigValue[kClockSpeedTrigger]},
182  }
183 
185  DataFor(double const g4_ref_time,
186  double const trigger_time,
187  double const beam_time) const override
188  {
189  return DetectorClocksData{
190  g4_ref_time,
192  trigger_time,
193  beam_time,
195  ElecClock{trigger_time, fConfigValue[kFramePeriod], fConfigValue[kClockSpeedOptical]},
196  ElecClock{trigger_time, fConfigValue[kFramePeriod], fConfigValue[kClockSpeedTrigger]},
198  }
199 
200  /// Internal function to apply loaded parameters to member attributes
201  void ApplyParams();
202 
203  /// Internal function used to search for the right configuration set in the
204  /// data file
205  bool IsRightConfig(const fhicl::ParameterSet& ps) const;
206 
207  /// Dumps the current configuration to screen.
208  void debugReport() const;
209 
210  private:
211  /**
212  * @brief Setter for trigger times.
213  * @param trig_time @ref DetectorClocksHardwareTrigger "hardware trigger
214  * time" in @ref DetectorClocksElectronicsTime "electronics time scale"
215  * @param beam_time @ref DetectorClocksBeamGateOpening "beam gate opening
216  * time" in @ref DetectorClocksElectronicsTime "electronics time scale"
217  *
218  * The @ref DetectorClocksHardwareTrigger "hardware trigger" and
219  * @ref DetectorClocksBeamGateOpening "beam gate opening" times are set, and
220  * the electronic clocks are updated to store the new trigger time.
221  */
222  void
223  SetTriggerTime(double const trig_time, double const beam_time)
224  {
225  fTriggerTime = trig_time;
226  fBeamGateTime = beam_time;
228  }
229 
230  double
232  {
233  if (fTriggerOffsetTPC < 0)
234  return fTriggerOffsetTPC;
235  else
236  return -fTriggerOffsetTPC / fTPCClock.Frequency(); // convert ticks to
237  // us
238  }
239 
240  std::vector<std::string> fConfigName;
241  std::vector<double> fConfigValue;
242 
245 
246  /// Time offset from trigger to TPC readout start
248 
249  /// Trigger time in [us]
250  double fTriggerTime;
251 
252  /// BeamGate time in [us]
254 
255  /// Frame period
256  double fFramePeriod;
257 
259  }; // class DetectorClocksStandard
260 
261 } // namespace detinfo
262 
263 #endif // LARDATAALG_DETECTORINFO_DETECTORCLOCKSSTANDARD_H
DetectorClocksData DataFor(double const g4_ref_time, double const trigger_time, double const beam_time) const override
Returns a complete detinfo::DetectorClocksData object.
DetectorClocksData DataForJob() const override
Returns a complete detinfo::DetectorClocksData object.
bool IsRightConfig(const fhicl::ParameterSet &ps) const
void debugReport() const
Dumps the current configuration to screen.
std::string string
Definition: nybbler.cc:12
std::vector< std::string > fConfigName
std::string const & TrigModuleName() const
Returns the input tag of the trigger data product.
std::vector< std::string > const & ConfigNames() const override
std::vector< double > const & ConfigValues() const override
double fTriggerTime
Trigger time in [us].
timescale_traits< TriggerTimeCategory >::time_point_t trigger_time
A point in time on the trigger time scale.
void ApplyParams()
Internal function to apply loaded parameters to member attributes.
double fBeamGateTime
BeamGate time in [us].
std::string G4RefCorrTrigModuleName() const
Returns the input tag of the trigger data product for G4Ref correctons.
double fTriggerOffsetTPC
Time offset from trigger to TPC readout start.
General LArSoft Utilities.
static constexpr double ps
Definition: Units.h:99
Class used for the conversion of times between different formats and references.
constexpr double kDEFAULT_FREQUENCY_EXTERNAL
Default External clock speed in MHz.
void SetConfigValue(size_t i, double val)
Contains all timing reference information for the detector.
constexpr double kDEFAULT_FRAME_PERIOD
Default Frame period in micro-second.
void SetTriggerTime(double const trig_time, double const beam_time)
Setter for trigger times.
Implementation of detinfo::DetectorClocks interface with fixed settings from configuration.
constexpr double Frequency() const
Frequency in MHz.
Definition: ElecClock.h:191
DetectorClocksStandard(fhicl::ParameterSet const &pset)
Class representing the time measured by an electronics clock.
Definition: ElecClock.h:91
Functions to load trigger time in detinfo::DetectorClocksStandard.
pure virtual base interface for detector clocks