22 #include "art/Framework/Core/SharedProducer.h"
23 #include "art/Framework/Core/ModuleMacros.h"
24 #include "art/Framework/Principal/Event.h"
25 #include "art/Persistency/Common/PtrMaker.h"
26 #include "canvas/Persistency/Common/FindOneP.h"
27 #include "canvas/Persistency/Common/Assns.h"
28 #include "canvas/Persistency/Common/Ptr.h"
29 #include "canvas/Utilities/InputTag.h"
30 #include "canvas/Utilities/Exception.h"
31 #include "cetlib_except/exception.h"
32 #include "messagefacility/MessageLogger/MessageLogger.h"
33 #include "fhiclcpp/types/Atom.h"
161 Name(
"T0selProducer"),
163 (
"tag of the selected particles (as a collection of art::Ptr)")
169 Comment(
"tag of the input track time (t0) information")
175 Name(
"GateStartOffset"),
176 Comment(
"offset from time track to gate start")
180 Name(
"GateEndOffset"),
181 Comment(
"offset from time track to gate end")
193 Comment(
"name of the category used for the output"),
194 "BeamGateInfoFromTracks"
206 throw art::Exception(art::errors::Configuration)
207 <<
"Invalid value for '" <<
GateType.name()
208 <<
"' parameter: '" << e.
label() <<
"'; valid options: "
224 (
Parameters const& config, art::ProcessingFrame
const&);
232 virtual void produce(art::Event& event, art::ProcessingFrame
const&)
override;
264 template <
typename T>
265 std::unique_ptr<T> moveToUniquePtr(T& data)
266 {
return std::make_unique<T>(std::move(data)); }
272 namespace icarus::trigger {
277 { GateType_t::kUnknown,
"unknown" }
288 : art::SharedProducer(config)
290 , fT0selProducer(config().T0selProducer())
291 , fT0Producer(config().T0Producer())
292 , fGateStartOffset(config().GateStartOffset())
293 , fGateDuration(config().GateEndOffset() - fGateStartOffset)
294 , fBeamGateType(config().getGateType())
298 async<art::InEvent>();
303 produces<std::vector<sim::BeamGateInfo>>();
304 produces<art::Assns<sim::BeamGateInfo, recob::PFParticle>>();
305 produces<art::Assns<sim::BeamGateInfo, anab::T0>>();
315 <<
"\n - particle selection: '" << fT0selProducer.encode() <<
'\''
316 <<
"\n - associated times: '" << fT0Producer.encode() <<
'\''
317 <<
"\n - gate around particle time: " << fGateStartOffset
318 <<
" -- " << (fGateStartOffset+fGateDuration)
319 <<
" (" << fGateDuration <<
"; gate type: \"" << beamType.name()
320 <<
"\" [#" << fBeamGateType <<
"])"
328 (art::Event& event, art::ProcessingFrame
const&)
334 auto const& particles
335 =
event.getProduct<std::vector<art::Ptr<recob::PFParticle>>>(fT0selProducer);
338 <<
"Writing gates for " << particles.size() <<
" particles.";
340 art::FindOneP<anab::T0>
const particleT0(particles, event, fT0Producer);
343 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event)
353 std::vector<sim::BeamGateInfo> gates;
354 art::Assns<sim::BeamGateInfo, recob::PFParticle> gateToParticle;
355 art::Assns<sim::BeamGateInfo, anab::T0> gateToTime;
357 art::PtrMaker<sim::BeamGateInfo>
const makeGatePtr {
event };
359 for (
auto const& [ iParticle, particlePtr ]:
util::enumerate(particles)) {
361 art::Ptr<anab::T0>
const t0Ptr = particleT0.at(iParticle);
362 if (t0Ptr.isNull()) {
363 art::Exception
e { art::errors::NotFound };
364 e <<
"Selected track #" << iParticle <<
" (";
365 if (particlePtr)
e <<
"ID=" << particlePtr->Self() <<
", ";
366 e <<
"#" << particlePtr.key()
367 <<
" in its collection) has no associated time."
379 =
detTimings.toSimulationTime(
t0 + triggerToBeamGate + fGateStartOffset);
390 log <<
"Gate for selected track #" << iParticle <<
" (";
391 if (particlePtr) log <<
"ID=" << particlePtr->Self() <<
", ";
392 log <<
"#" << particlePtr.key()
393 <<
" in its collection): time = " <<
t0 <<
" => "
394 << gate.Start() <<
" -- " << (gate.Start() + gate.Width())
395 <<
" ns (" << gate.Width() <<
" ns)"
399 gates.push_back(std::move(gate));
401 art::Ptr<sim::BeamGateInfo> gatePtr { makeGatePtr(gates.size() - 1) };
402 gateToParticle.addSingle(gatePtr, particlePtr);
403 gateToTime.addSingle(gatePtr, t0Ptr);
410 event.put(moveToUniquePtr(gates));
411 event.put(moveToUniquePtr(gateToParticle));
412 event.put(moveToUniquePtr(gateToTime));
Request for unknown option.
sim::BeamType_t const fBeamGateType
Type of gate saved.
Helper to select an string option among a set of allowed choices.
Definition of util::enumerate().
nanoseconds const fGateDuration
Width of the gate being created.
art::InputTag const fT0selProducer
Input particles.
Option_t const & parse(std::string const &label) const
Returns the option matching the specified label.
static util::MultipleChoiceSelection< GateType_t > const GateTypeSelector
Selector for Type parameter.
std::string optionListString(std::string const &sep=", ") const
Returns a string with the (main) name of all options.
fhicl::Atom< nanoseconds > GateEndOffset
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Interface to detinfo::DetectorClocks.
Writes a set collection of beam gates into each event.
timescale_traits< TriggerTimeCategory >::time_point_t trigger_time
A point in time on the trigger time scale.
fhicl::Atom< art::InputTag > T0selProducer
Option_t const & get(Choices_t value) const
Returns the specified option.
BeamGateInfoFromTracks(Parameters const &config, art::ProcessingFrame const &)
timescale_traits< SimulationTimeCategory >::time_point_t simulation_time
A point in time on the simulation time scale.
fhicl::Atom< nanoseconds > GateStartOffset
fhicl::Atom< art::InputTag > T0Producer
BEGIN_PROLOG vertical distance to the surface Name
fhicl::Atom< std::string > LogCategory
An interval (duration, length, distance) between two quantity points.
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.
fhicl::Atom< std::string > GateType
Utilities to read interval and point quantity FHiCL configuration.
art::SharedProducer::Table< Config > Parameters
Dimensioned variables representing space or time quantities.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
Data types for detinfo::DetectorTimings.
std::string const & label() const
nanosecond_as<> nanosecond
Type of time point stored in nanoseconds, in double precision.
std::string const fLogCategory
Message facility stream category for output.
sim::BeamType_t getGateType() const
nanoseconds const fGateStartOffset
Offset of gate start from particle time.
virtual void produce(art::Event &event, art::ProcessingFrame const &) override
Fills the plots. Also extracts the information to fill them with.
BeamType_t
Defines category of beams to be stored in sim::BeamGateInfo.
art::InputTag const fT0Producer
Input particle/time associations.
Choices_t value() const
Returns a copy of the value of the option.