DetectorClocksStandardDataFor.h
Go to the documentation of this file.
1 /**
2  * @file lardataalg/DetectorInfo/DetectorClocksStandardDataFor.h
3  * @brief Helper to get clocks data from `detinfo::DetectorClocksStandard`.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date October 14, 2020
6  *
7  * This library is header-only.
8  */
9 
10 #ifndef LARDATAALG_DETECTORINFO_DETECTORCLOCKSSTANDARDDATAFOR_H
11 #define LARDATAALG_DETECTORINFO_DETECTORCLOCKSSTANDARDDATAFOR_H
12 
13 // LArSoft libraries
15 #include "lardataobj/RawData/TriggerData.h" // raw::Trigger
16 
17 // framework libraries
19 #include "cetlib_except/exception.h"
20 
21 // C++ standard libraries
22 #include <optional>
23 #include <vector>
24 
25 namespace detinfo {
26 
27  /**
28  * @brief Returns `DetectorClocksData` tuned on the specified `event`.
29  * @tparam Event type of framework event
30  * @param detClocks service provider generating the data
31  * @param event event to read information from
32  * @return `DetectorClocksData` tuned on the specified `event`
33  *
34  * This function takes care to extract all what is needed by
35  * `DetectorClocksStandard` service provider in order to provide data for
36  * the event.
37  *
38  * Example:
39  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
40  * detinfo::DetectorClocksStandard const detClocks
41  * { config.get<fhicl::ParameterSet>("services.DetectorClocksService") };
42  *
43  * for (gallery::Event event(inputFiles); !event.atEnd(); event.next()) {
44  *
45  * detinfo::DetectorClocksData const clockData
46  * = detinfo::detectorClocksStandardDataFor(detClocks, event);
47  *
48  * auto const triggerTime = clockData.TriggerTime();
49  *
50  * // etc...
51  *
52  * } // for
53  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54  *
55  *
56  * Requirements
57  * -------------
58  *
59  * The implementation is effectively dependent on the framework managing the
60  * `event`, but it is not _formally_ dependent on any implementation.
61  * Assumptions include everything that is required by other helper functions
62  * like `detinfo::trigger_times_for_event()` and
63  * `detinfo::g4ref_time_for_event()` (mostly, support for a call like
64  * `Event::getByLabel(art::InputTag, Event::HandleT<T>)`).
65  */
66  template <typename Event>
68  detinfo::DetectorClocksStandard const& detClocks,
69  Event const& event
70  ) {
71 
72  auto const& config_values = detClocks.ConfigValues();
73  // Trigger times
74  double trig_time{config_values[kDefaultTrigTime]};
75  double beam_time{config_values[kDefaultBeamTime]};
76  if (auto times = trigger_times_for_event(detClocks.TrigModuleName(), event)) {
77  std::tie(trig_time, beam_time) = *times;
78  }
79 
80  double g4_ref_time{config_values[kG4RefTime]};
81  if (auto sim_trig_time = g4ref_time_for_event(detClocks.G4RefCorrTrigModuleName(), event)) {
82  g4_ref_time -= trig_time;
83  g4_ref_time += *sim_trig_time;
84  }
85  return detClocks.DataFor(g4_ref_time, trig_time, beam_time);
86  } // detinfo::detectorClocksStandardDataFor()
87 
88 
89 } // namespace detinfo
90 
91 
92 
93 #endif // LARDATA_DETECTORINFO_DETECTORCLOCKSSTANDARDTRIGGERLOADER_H
DetectorClocksData DataFor(double const g4_ref_time, double const trigger_time, double const beam_time) const override
Returns a complete detinfo::DetectorClocksData object.
std::optional< double > g4ref_time_for_event(art::InputTag const &triggerTag, Event const &event)
Loads DetectorClocksStandard G4Ref correction times.
std::string const & TrigModuleName() const
Returns the input tag of the trigger data product.
std::vector< double > const & ConfigValues() const override
std::string G4RefCorrTrigModuleName() const
Returns the input tag of the trigger data product for G4Ref correctons.
General LArSoft Utilities.
detinfo::DetectorClocksData detectorClocksStandardDataFor(detinfo::DetectorClocksStandard const &detClocks, Event const &event)
Returns DetectorClocksData tuned on the specified event.
Contains all timing reference information for the detector.
Implementation of detinfo::DetectorClocks interface with fixed settings from configuration.
Functions to load trigger time in detinfo::DetectorClocksStandard.
std::optional< std::pair< double, double > > trigger_times_for_event(art::InputTag const &triggerTag, Event const &event)
Loads DetectorClocksStandard trigger times.
Event finding and building.