All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExtractEnergyDepositionSummary_module.cc
Go to the documentation of this file.
1 /**
2  * @file ExtractEnergyDepositionSummary_module.cc
3  * @brief Module producing a summary deposited energy data product.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  */
6 
7 // ICARUS libraries
12 #include "icaruscode/Utilities/DetectorClocksHelpers.h" // makeDetTimings()...
14 #include "icarusalg/Utilities/ChangeMonitor.h" // ThreadSafeChangeMonitor
15 #include "icarusalg/Utilities/FHiCLutils.h" // util::fhicl::getOptionalValue()
16 
17 // LArSoft libraries
21 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
22 #include "lardataalg/DetectorInfo/DetectorTimings.h" // detinfo::DetectorTimings
25 #include "lardataalg/Utilities/intervals_fhicl.h" // microseconds from FHiCL
29 
30 // framework libraries
31 #include "art/Framework/Core/ModuleMacros.h"
32 #include "art/Framework/Core/EDProducer.h"
33 #include "art/Framework/Principal/Event.h"
34 #include "canvas/Utilities/InputTag.h"
35 #include "messagefacility/MessageLogger/MessageLogger.h"
36 #include "fhiclcpp/types/OptionalAtom.h"
37 #include "fhiclcpp/types/Sequence.h"
38 #include "fhiclcpp/types/Atom.h"
39 
40 // C/C++ standard libraries
41 #include <vector>
42 #include <string>
43 #include <cassert>
44 /*
45 #include <map>
46 */
47 
48 //------------------------------------------------------------------------------
49 namespace icarus::trigger { class ExtractEnergyDepositionSummary; }
50 
51 /**
52  * @brief Produces energy deposition summary data products.
53  *
54  * The data product produced by this module is an alternative to storing the
55  * whole energy deposition, which can be huge.
56  *
57  * This module takes its information from `sim::SimEnergyDeposits` data product
58  * in input, simply providing a sum of it within the specified time interval.
59  *
60  *
61  * Output data products
62  * =====================
63  *
64  * * a single `icarus::SimEnergyDepositSummary`: sums of energies in a spill
65  * time, in a pre-spill time, and total, everywhere and in active volume only.
66  *
67  *
68  * Input data products
69  * ====================
70  *
71  * * `std::vector<sim::SimEnergyDeposits>` (multiple supported) _or_
72  * `std::vector<sim::SimChannel>` to extract the deposited energy from.
73  *
74  *
75  * Service requirements
76  * ---------------------
77  *
78  * The following services are _required_:
79  *
80  * * `Geometry` for the determination of the active volume(s)
81  * * `DetectorClocksService` for the determination of beam gate and for time
82  * backtracking if energy deposition information is from `sim::SimChannel`
83  * * `DetectorPropertiesService` for time backtracking if energy deposition
84  * * information is from `sim::SimChannel`
85  * * _art_ message facility
86  *
87  *
88  * Configuration parameters
89  * =========================
90  *
91  * A terse description of the parameters is printed by running
92  * `lar --print-description ExtractEnergyDepositionSummary`.
93  *
94  * * `EnergyDepositTags`
95  * (list of input tags, default: `[ "largeant:TPCActive" ]`): a list of
96  * data products with energy depositions. In alternative, `SimChannelTag`
97  * can be specified instead.
98  * * `SimChannelTag` (input tag): tag of the data product with
99  * `sim::SimChannels` to extract the energy information from. If specified,
100  * it overrides `EnergyDepositTags` and extracts energy information from the
101  * `sim::SimChannel` data product identified by this tag. This option is
102  * for flawed input samples only, and `EnergyDepositTags` is recommended
103  * instead.
104  * * `BeamGateDuration` (time, _mandatory_): the duration of the beam
105  * gate; _the time requires the unit to be explicitly specified_: use
106  * `"1.6 us"` for BNB, `9.5 us` for NuMI (also available as
107  * `BNB_settings.spill_duration` and `NuMI_settings.spill_duration` in
108  * `trigger_icarus.fcl`).
109  * * `BeamGateStart` (time, default: 0 &micro;s): open the beam gate this long
110  * after the nominal beam gate time.
111  * * `PreSpillWindow` (time, default: 10 &micro;s): duration of the pre-spill
112  * window.
113  * * `PreSpillWindowGap` (time, default: 0 &micro;s): gap from the end of
114  * pre-spill window to the start of beam gate.
115  * * `OutputCategory` (string, default: `"ExtractEnergyDepositionSummary"`): label
116  * for the category of messages in the console output; this is the label
117  * that can be used for filtering messages via MessageFacility service
118  * configuration.
119  *
120  */
121 class icarus::trigger::ExtractEnergyDepositionSummary: public art::EDProducer {
122 
123  public:
124 
126 
127  // --- BEGIN Configuration ---------------------------------------------------
128  struct Config {
129 
130  using Name = fhicl::Name;
131  using Comment = fhicl::Comment;
132 
133  fhicl::Sequence<art::InputTag> EnergyDepositTags {
134  Name("EnergyDepositTags"),
135  Comment("label of energy deposition data product(s) in the detector"),
136  std::vector<art::InputTag>{ "largeant:TPCActive" }
137  };
138 
139  fhicl::OptionalAtom<art::InputTag> SimChannelTag {
140  Name("SimChannelTag"),
141  Comment("label of source sim::SimChannels data product in the detector"),
142  };
143 
144  fhicl::Atom<microseconds> BeamGateDuration {
145  Name("BeamGateDuration"),
146  Comment("length of time interval when optical triggers are accepted")
147  };
148 
149  fhicl::Atom<microseconds> BeamGateStart {
150  Name("BeamGateStart"),
151  Comment("open the beam gate this long after the nominal beam gate time"),
152  microseconds{ 0.0 }
153  };
154 
155  fhicl::Atom<microseconds> PreSpillWindow {
156  Name("PreSpillWindow"),
157  Comment("duration of the pre-spill window"),
158  microseconds{ 10.0 }
159  };
160 
161  fhicl::Atom<microseconds> PreSpillWindowGap {
162  Name("PreSpillWindowGap"),
163  Comment("gap from the end of pre-spill window to the start of beam gate"),
164  microseconds{ 0.0 }
165  };
166 
167  fhicl::Atom<std::string> OutputCategory {
168  Name("OutputCategory"),
169  Comment("tag of the module output to console via message facility"),
170  "ExtractEnergyDepositionSummary"
171  };
172 
173  }; // struct Config
174 
175  using Parameters = art::EDProducer::Table<Config>;
176  // --- END Configuration -----------------------------------------------------
177 
178 
179  // --- BEGIN Constructors ----------------------------------------------------
180  explicit ExtractEnergyDepositionSummary(Parameters const& config);
181 
182  // --- END Constructors ------------------------------------------------------
183 
184 
185  // --- BEGIN Framework hooks -------------------------------------------------
186 
187  /// Creates the data products.
188  virtual void produce(art::Event& event) override;
189 
190  // --- END Framework hooks ---------------------------------------------------
191 
192 
193  private:
194 
196 
197 
198  // --- BEGIN Configuration variables -----------------------------------------
199 
200  /// Duration of the gate during with global optical triggers are accepted.
202 
203  /// Start of the beam gate with respect to `BeamGate()`.
205 
206  microseconds fPreSpillWindow; ///< Duration of the pre-spill gate.
207 
208  microseconds fPreSpillStart; ///< Start of the pre-spill gate.
209 
210  std::string const fLogCategory; ///< Category name for the console output stream.
211 
212  // --- END Configuration variables -------------------------------------------
213 
214 
215  // --- BEGIN Service variables -----------------------------------------------
216 
217  struct TimingPack_t {
218 
219  /// Detector clocks information.
221 
222  /// Detector properties information.
224 
225  /// Detector timing conversion utility.
227 
229  detinfo::DetectorClocksData clocksData,
231  )
232  : detClocks{ std::move(clocksData) }
233  , detProps{ std::move(propsData) }
235  {}
236 
237  }; // TimingPack_t
238 
239  geo::GeometryCore const& fGeom; ///< Access to detector geometry information.
240 
241  /// All information about detector timings and properties.
242  std::optional<TimingPack_t> fDetProps;
243 
244  // --- END Service variables -------------------------------------------------
245 
246 
247  // --- BEGIN Algorithms ------------------------------------------------------
248 
249  /// Functor returning whether a gate has changed.
252 
254 
255  // --- END Algorithms --------------------------------------------------------
256 
257 
258  /// Fills a energy deposition tag object from the specified configuration.
260  fhicl::Sequence<art::InputTag> const& energyDepositTags,
261  fhicl::OptionalAtom<art::InputTag> const& simChannelTag
262  );
263 
264 }; // icarus::trigger::ExtractEnergyDepositionSummary
265 
266 
267 
268 //------------------------------------------------------------------------------
269 //--- Implementation
270 //------------------------------------------------------------------------------
271 //--- icarus::trigger::ExtractEnergyDepositionSummary
272 //------------------------------------------------------------------------------
274  (Parameters const& config)
275  : art::EDProducer(config)
276  // configuration
277  , fBeamGateDuration (config().BeamGateDuration())
278  , fBeamGateStart (config().BeamGateStart())
279  , fPreSpillWindow (config().PreSpillWindow())
280  , fPreSpillStart
281  (fBeamGateStart - config().PreSpillWindowGap() - fPreSpillWindow)
282  , fLogCategory(config().OutputCategory())
283  // services
284  , fGeom(*(lar::providerFrom<geo::Geometry>()))
285  , fDetProps{
286  config().SimChannelTag.hasValue()
287  ? std::make_optional<TimingPack_t>(
288  art::ServiceHandle<detinfo::DetectorClocksService const>()
289  ->DataForJob(),
290  art::ServiceHandle<detinfo::DetectorPropertiesService const>()
291  ->DataForJob()
292  )
293  : std::nullopt
294  }
295  // algorithms
296  , fEventInfoExtractorMaker(
297  {} // truthTags: none
298  , makeEnergyDepSourceTag(config().EnergyDepositTags, config().SimChannelTag)
299  // edepTags
300  , fGeom // geom
301  , (fDetProps? &(fDetProps->detProps): nullptr) // detProps
302  , (fDetProps? &(fDetProps->detTimings): nullptr) // detTimings
303  , fLogCategory // logCategory
304  , consumesCollector() // consumesCollector
305  )
306 {
307  produces<icarus::SimEnergyDepositSummary>();
308 } // icarus::trigger::ExtractEnergyDepositionSummary::ExtractEnergyDepositionSummary()
309 
310 
311 //------------------------------------------------------------------------------
313 {
314 
315  //
316  // prepare the information extractor and extract the information
317  //
318 
319  // we need to convert the two relevant gates with the proper parameters
320  auto const detTimings = icarus::ns::util::makeDetTimings(event);
321 
322  auto const beamGate = icarus::trigger::makeBeamGateStruct
324 
325  if (auto oldGate = fBeamGateChangeCheck(beamGate); oldGate) {
326  mf::LogWarning(fLogCategory)
327  << "Beam gate has changed from " << oldGate->asOptTickRange()
328  << " to " << beamGate.asOptTickRange() << " (optical tick)!";
329  }
330 
332  beamGate.asSimulationRange(),
336  )(event);
337  assert(info.hasDepEnergy());
338 
339  //
340  // move the information into the data product
341  //
343  summary.Total = info.DepositedEnergy().value();
344  summary.Spill = info.DepositedEnergyInSpill().value();
345  summary.PreSpill = info.DepositedEnergyInPreSpill().value();
346  summary.Active = info.DepositedEnergyInActiveVolume().value();
347  summary.SpillActive = info.DepositedEnergyInSpillInActiveVolume().value();
348  summary.PreSpillActive = info.DepositedEnergyInPreSpillInActiveVolume().value();
349 
350  //
351  // finish
352  //
353  event.put
354  (std::make_unique<icarus::SimEnergyDepositSummary>(std::move(summary)));
355 
356 } // icarus::trigger::ExtractEnergyDepositionSummary::produce()
357 
358 
359 //------------------------------------------------------------------------------
361  fhicl::Sequence<art::InputTag> const& energyDepositTags,
362  fhicl::OptionalAtom<art::InputTag> const& simChannelTag
363  ) -> EDepTags_t
364 {
365  EDepTags_t edepTags;
366 
367  if (auto const tag = util::fhicl::getOptionalValue(simChannelTag)) {
368  edepTags
370  ;
371  }
372  else {
373  edepTags = energyDepositTags();
374  }
375 
376  return edepTags;
377 } // icarus::trigger::ExtractEnergyDepositionSummary::makeEnergyDepSourceTag()
378 
379 
380 //------------------------------------------------------------------------------
382 
383 
384 //------------------------------------------------------------------------------
float Total
Total deposited energy [GeV].
Utilities related to art service access.
std::optional< typename Optional::value_type > getOptionalValue(Optional const &parameter)
Returns the value of an optional parameter as std::optional.
Definition: FHiCLutils.h:188
An object representing a time gate, with a start and and end.
geo::GeometryCore const & fGeom
Access to detector geometry information.
detinfo::DetectorClocksData const detClocks
Detector clocks information.
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
Definition: spacetime.h:259
microseconds fPreSpillWindow
Duration of the pre-spill gate.
Object storing a summary of energy depositions in the detector.
TimingPack_t(detinfo::DetectorClocksData clocksData, detinfo::DetectorPropertiesData propsData)
makeEnergyDepSourceTag(config().EnergyDepositTags, config().SimChannelTag)
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Helper to check if an object has changed. Thread-safe.
bool hasDepEnergy() const
Returns whether generator information is available.
Definition: EventInfo_t.h:140
Interface to detinfo::DetectorClocks.
fDetProps &fDetProps fDetProps &fDetProps fLogCategory
detinfo::DetectorPropertiesData const detProps
Detector properties information.
Access the description of detector geometry.
Data structure containing summary information about deposited energy.
virtual void produce(art::Event &event) override
Creates the data products.
TimeRange< simulation_time > const & asSimulationRange() const
Returns the gate as start/stop pair in simulation time scale.
Simple functions to streamline the creation of DetectorClocksData.
detinfo::DetectorTimings makeDetectorTimings(detinfo::DetectorClocksData const &detClocks)
static EDepTags_t makeEnergyDepSourceTag(fhicl::Sequence< art::InputTag > const &energyDepositTags, fhicl::OptionalAtom< art::InputTag > const &simChannelTag)
Fills a energy deposition tag object from the specified configuration.
microseconds fBeamGateDuration
Duration of the gate during with global optical triggers are accepted.
BEGIN_PROLOG vertical distance to the surface Name
detinfo::DetectorTimings const detTimings
Detector timing conversion utility.
Description of geometry of one entire detector.
GeV DepositedEnergyInSpill() const
Returns the total energy deposited in the detector during beam [GeV].
Definition: EventInfo_t.h:146
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
Functions dealing with icarus::trigger::details::EventInfo_t.
GeV DepositedEnergyInSpillInActiveVolume() const
Returns the energy deposited in the active volume during the beam [GeV].
Definition: EventInfo_t.h:156
Utilities to read interval and point quantity FHiCL configuration.
GeV DepositedEnergyInPreSpillInActiveVolume() const
Definition: EventInfo_t.h:161
Classes to detect the change of object values.
A helper class creating a EventInfoExtractor with a specific setup.
icarus::ns::util::ThreadSafeChangeMonitor< icarus::trigger::BeamGateStruct > fBeamGateChangeCheck
Functor returning whether a gate has changed.
Contains all timing reference information for the detector.
Class hosting selected information about the event.
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.
std::string const fLogCategory
Category name for the console output stream.
contains information for a single step in the detector simulation
A class exposing an upgraded interface of detinfo::DetectorClocksData.
Class to create an object representing a beam gate.
GeV DepositedEnergy() const
Returns the total energy deposited in the detector during the event [GeV].
Definition: EventInfo_t.h:143
object containing MC truth information necessary for making RawDigits and doing back tracking ...
GeV DepositedEnergyInActiveVolume() const
Returns the energy deposited in the active volume during the event [GeV].
Definition: EventInfo_t.h:153
Selected information about the event.
Definition: EventInfo_t.h:45
microseconds fBeamGateStart
Start of the beam gate with respect to BeamGate().
Simple helper functions to deal with FHiCL.
fDetProps &fDetProps fDetProps &fDetProps detTimings
Utility tag to identify a parameter as a specific type of tag.
std::optional< TimingPack_t > fDetProps
All information about detector timings and properties.
Produces energy deposition summary data products.
art framework interface to geometry description
detinfo::DetectorTimings makeDetTimings(art::Event const *event)
Returns a detinfo::DetectorTimings from DetectorClocksService.
fDetProps &fDetProps fDetProps &fDetProps consumesCollector())