All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WriteBeamGateInfo_module.cc
Go to the documentation of this file.
1 /**
2  * @file WriteBeamGateInfo_module.cc
3  * @brief Writes a fixed collection of sim::BeamGateInfo.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date November 18, 2021
6  */
7 
8 // LArSoft libraries
9 #include "lardataalg/Utilities/intervals_fhicl.h" // microseconds from FHiCL
10 #include "lardataalg/Utilities/quantities/spacetime.h" // microseconds
13 
14 // framework libraries
15 #include "art/Framework/Core/SharedProducer.h"
16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Principal/Event.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
19 #include "fhiclcpp/types/TableAs.h"
20 #include "fhiclcpp/types/Sequence.h"
21 #include "fhiclcpp/types/Atom.h"
22 
23 // C/C++ standard libraries
24 #include <vector>
25 #include <string>
26 #include <memory> // std::make_unique()
27 
28 
29 //------------------------------------------------------------------------------
30 namespace icarus::trigger { class WriteBeamGateInfo; }
31 
32 /**
33  * @brief Writes a set collection of beam gates into each event.
34  *
35  * This module simply injects a list of `sim::BeamGateInfo` from the
36  * configuration into each event.
37  *
38  * It may be used as input to modules which require to operate on beam gates.
39  *
40  *
41  * Output data products
42  * =====================
43  *
44  * * `std::vector<sim::BeamGateInfo>`: a collection of as many
45  * `sim::BeamGateInfo` as the `BeamGates` configuration parameter entries,
46  * with the content from them.
47  *
48  *
49  * Configuration parameters
50  * =========================
51  *
52  * A terse online description of the parameters is printed by running
53  * `lar --print-description WriteBeamGateInfo`.
54  *
55  * * `BeamGates` (list of configuration tables, mandatory): list of beam gate
56  * specifications; one output element is produced for each entry in this
57  * list. Each entry is a configuration table in the form:
58  * * `Duration` (time, _mandatory_): the duration of the beam
59  * gate; _the time requires the unit to be explicitly specified_: use
60  * `"1.6 us"` for BNB, `9.5 us` for NuMI (also available as
61  * `BNB_settings.spill_duration` and `NuMI_settings.spill_duration` in
62  * `trigger_icarus.fcl`);
63  * * `Start` (time, default: `0_us`): how long after the
64  * @ref DetectorClocksBeamGateOpening "nominal beam gate opening time"
65  * the actual beam gate opens at;
66  * * `Type` (string, default: "unknown"): type of the gate; see online
67  * description for the configuration keys representing the values of
68  * `sim::BeamType_t`.
69  * * `LogCategory` (string, default: `WriteBeamGateInfo`): name of the output
70  * stream category for console messages (managed by MessageFacility
71  * library).
72  *
73  *
74  */
75 class icarus::trigger::WriteBeamGateInfo: public art::SharedProducer {
76 
77  public:
78 
79  // --- BEGIN Configuration ---------------------------------------------------
80  struct Config {
81 
82  using Name = fhicl::Name;
83  using Comment = fhicl::Comment;
84 
86 
87  struct GateConfig {
88 
89  enum class BeamType_t { // we need to translate enum into a strong type
91  , kBNB = sim::kBNB
92  , kNuMI = sim::kNuMI
93  };
94 
95  /// Selector for `Type` parameter.
97 
98  fhicl::Atom<microseconds> Duration {
99  Name("Duration"),
100  Comment("length of gate time interval")
101  };
102 
103  fhicl::Atom<microseconds> Start {
104  Name("Start"),
105  Comment("open the beam gate this long after the nominal beam gate time"),
106  microseconds{ 0.0 }
107  };
108 
109  fhicl::Atom<std::string> Type {
110  Name("Type"),
111  Comment("gate type: " + BeamTypeSelector.optionListString()),
113  };
114 
115 
117  {
118  try {
119  return static_cast<sim::BeamType_t>
121  }
123  {
124  throw art::Exception(art::errors::Configuration)
125  << "Invalid value for '" << Type.name()
126  << "' parameter: '" << e.label() << "'; valid options: "
127  << BeamTypeSelector.optionListString() << ".\n";
128  }
129  } // getBeamType()
130 
131  };
132 
133  fhicl::Sequence<fhicl::TableAs<sim::BeamGateInfo, GateConfig>> BeamGates {
134  Name("BeamGates"),
135  Comment("list of gates to write")
136  };
137 
138 
139  fhicl::Atom<std::string> LogCategory {
140  Name("LogCategory"),
141  Comment("name of the category used for the output"),
142  "WriteBeamGateInfo" // default
143  };
144 
145 
146  }; // struct Config
147 
148  using Parameters = art::SharedProducer::Table<Config>;
149 
150  // --- END Configuration -----------------------------------------------------
151 
152 
153  // --- BEGIN Constructors ----------------------------------------------------
154 
155  explicit WriteBeamGateInfo
156  (Parameters const& config, art::ProcessingFrame const&);
157 
158  // --- END Constructors ------------------------------------------------------
159 
160 
161  // --- BEGIN Framework hooks -------------------------------------------------
162 
163  /// Fills the plots. Also extracts the information to fill them with.
164  virtual void produce(art::Event& event, art::ProcessingFrame const&) override;
165 
166  // --- END Framework hooks ---------------------------------------------------
167 
168 
169  private:
170 
171  // --- BEGIN Configuration variables -----------------------------------------
172 
173  std::vector<sim::BeamGateInfo> const fBeamGates; ///< The gates to write.
174 
175  /// Message facility stream category for output.
176  std::string const fLogCategory;
177 
178  // --- END Configuration variables -------------------------------------------
179 
180 
181 }; // class icarus::trigger::WriteBeamGateInfo
182 
183 
184 namespace icarus::trigger {
185 
186  // configuration conversion automatically picked by fhicl::TableAs<>
188  {
189  // nanoseconds is the standard unit for simulation and for sim::BeamGateInfo
191  return sim::BeamGateInfo{
192  config.Start().convertInto<nanoseconds>().value() // start
193  , config.Duration().convertInto<nanoseconds>().value() // width
194  , config.getBeamType() // type
195  };
196 
197  } // convert(GateConfig)
198 
199 } // namespace icarus::trigger
200 
201 
202 //------------------------------------------------------------------------------
203 //--- Implementation
204 //------------------------------------------------------------------------------
205 namespace icarus::trigger {
206 
209  {
210  { BeamType_t::kUnknown, "unknown" }
211  , { BeamType_t::kBNB, "BNB" }
212  , { BeamType_t::kNuMI, "NuMI" }
213  };
214 
215 } // namespace icarus::trigger
216 
217 //------------------------------------------------------------------------------
219  (Parameters const& config, art::ProcessingFrame const&)
220  : art::SharedProducer(config)
221  // configuration
222  , fBeamGates(config().BeamGates())
223  , fLogCategory(config().LogCategory())
224 {
225 
226  //
227  // output data declaration
228  //
229  produces<std::vector<sim::BeamGateInfo>>();
230 
231  async<art::InEvent>();
232 
233  //
234  // configuration report (short)
235  //
236  {
237  mf::LogInfo log { fLogCategory };
238  log << "Writing " << fBeamGates.size() << " gates in each event:";
239  for (sim::BeamGateInfo const& gate: fBeamGates) {
240  auto const& beamType = Config::GateConfig::BeamTypeSelector.get
241  (Config::GateConfig::BeamType_t(gate.BeamType()));
242  log << "\n * [ " << gate.Start() << " -- " << gate.Start() + gate.Width()
243  << " ] ns (duration: " << gate.Width() << " ns), type: "
244  << beamType.name() << " (" << gate.BeamType() << ")"
245  ;
246  } // for
247  }
248 
249 } // icarus::trigger::WriteBeamGateInfo::WriteBeamGateInfo()
250 
251 
252 //------------------------------------------------------------------------------
254  (art::Event& event, art::ProcessingFrame const&)
255 {
256 
257  // put a copy
258  event.put(std::make_unique<std::vector<sim::BeamGateInfo>>(fBeamGates));
259 
260 } // icarus::trigger::WriteBeamGateInfo::produce()
261 
262 
263 //------------------------------------------------------------------------------
264 DEFINE_ART_MODULE(icarus::trigger::WriteBeamGateInfo)
265 
266 
267 //------------------------------------------------------------------------------
DiscriminatePMTwaveformsByChannel::ChannelInfo_t convert(DiscriminatePMTwaveformsByChannel::ChannelConfig const &config)
std::vector< sim::BeamGateInfo > const fBeamGates
The gates to write.
Helper to select an string option among a set of allowed choices.
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
Definition: spacetime.h:259
Option_t const & parse(std::string const &label) const
Returns the option matching the specified label.
std::string optionListString(std::string const &sep=", ") const
Returns a string with the (main) name of all options.
static util::MultipleChoiceSelection< BeamType_t > const BeamTypeSelector
Selector for Type parameter.
Unknown beam type.
Definition: BeamTypes.h:10
std::string const fLogCategory
Message facility stream category for output.
NuMI.
Definition: BeamTypes.h:12
fDetProps &fDetProps fDetProps &fDetProps fLogCategory
Option_t const & get(Choices_t value) const
Returns the specified option.
WriteBeamGateInfo(Parameters const &config, art::ProcessingFrame const &)
art::SharedProducer::Table< Config > Parameters
BEGIN_PROLOG vertical distance to the surface Name
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
fhicl::Sequence< fhicl::TableAs< sim::BeamGateInfo, GateConfig > > BeamGates
virtual void produce(art::Event &event, art::ProcessingFrame const &) override
Fills the plots. Also extracts the information to fill them with.
std::string name() const
Returns the name of the option (i.e. the main label).
nanoseconds_as<> nanoseconds
Type of time interval stored in nanoseconds, in double precision.
Definition: spacetime.h:270
Utilities to read interval and point quantity FHiCL configuration.
BNB.
Definition: BeamTypes.h:11
Dimensioned variables representing space or time quantities.
do i e
temporary value
BeamType_t
Defines category of beams to be stored in sim::BeamGateInfo.
Definition: BeamTypes.h:9
Choices_t value() const
Returns a copy of the value of the option.
nanosecond nanoseconds
Alias for common language habits.
Definition: spacetime.h:139
Writes a set collection of beam gates into each event.