35 #include "art/Framework/Services/Registry/ServiceHandle.h"
36 #include "art/Framework/Core/EDProducer.h"
37 #include "art/Framework/Core/ModuleMacros.h"
38 #include "art/Framework/Principal/Event.h"
39 #include "art/Framework/Principal/Handle.h"
40 #include "canvas/Utilities/InputTag.h"
41 #include "canvas/Utilities/Exception.h"
42 #include "messagefacility/MessageLogger/MessageLogger.h"
43 #include "fhiclcpp/types/OptionalSequence.h"
44 #include "fhiclcpp/types/Sequence.h"
45 #include "fhiclcpp/types/OptionalAtom.h"
46 #include "fhiclcpp/types/Atom.h"
47 #include "cetlib_except/exception.h"
66 namespace icarus::trigger {
class SlidingWindowTrigger; }
226 Name(
"TriggerGatesTag"),
227 Comment(
"label of the input trigger gate data product (no instance name)")
233 (
"thresholds to consider (instance names of `TriggerGatesTag` input)")
238 Comment(
"number of optical channels to be included in each window")
240 fhicl::OptionalAtom<unsigned int>
Stride {
243 "number of optical channel used as offset for sliding window [as WindowSize]"
248 Name(
"DisableWindows"),
249 Comment(
"ignores the windows with the specified index"),
254 Name(
"EnableOnlyWindows"),
255 Comment(
"only enables the windows with the specified index"),
260 Name(
"MissingChannels"),
261 Comment(
"list of ID of channels missing from the input"),
262 std::vector<raw::Channel_t>{}
266 Name(
"ProduceWaveformAssns"),
268 (
"also produce gate/waveform associations together with gate/metadata"),
274 Comment(
"name of the category used for the output"),
275 "SlidingWindowTrigger"
300 virtual void produce(art::Event& event)
override;
349 std::string
const& threshold,
350 art::InputTag
const& dataTag
354 std::vector<icarus::trigger::TrackedOpticalTriggerGate<sbn::OpDetWaveformMeta>>
ReadTriggerGates(
355 art::Event
const& event,
356 art::InputTag
const& dataTag,
366 , fhicl::OptionalSequence<std::size_t>
const& enabled
367 , fhicl::OptionalSequence<std::size_t>
const& disabled
373 art::Assns<TriggerGateData_t, sbn::OpDetWaveformMeta>
const& assns
387 template <
typename Cont,
typename Indices>
391 for (
auto const index: indices) selected.push_back(coll.at(index));
404 : art::EDProducer(config)
409 , fWindowChannels(defineWindows())
410 , fEnabledWindows(makeEnabledWindowIndices(
411 fWindowChannels.size(),
412 config().EnableOnlyWindows, config().DisableWindows
414 , fProduceWaveformAssns(config().ProduceWaveformAssns())
418 filter(fWindowChannels, fEnabledWindows),
419 config().MissingChannels(),
420 nDisabledWindows() == 0U
426 std::string
const discrModuleLabel = config().TriggerGatesTag();
427 for (std::string
const& threshold: config().
Thresholds())
428 fADCthresholds[threshold] = art::InputTag{ discrModuleLabel, threshold };
435 log <<
"Trigger configuration: " << fWindowChannels.size() <<
" windows";
436 if (fEnabledWindows.size() < fWindowChannels.size())
437 log <<
" (only " << fEnabledWindows.size() <<
" enabled)";
439 for (
auto const& [ iWindow, window ]:
util::enumerate(fWindowChannels)) {
440 log <<
"\n #" << iWindow <<
": "
442 if (std::find(fEnabledWindows.begin(), fEnabledWindows.end(), iWindow)
443 == fEnabledWindows.end())
445 log <<
" (disabled)";
449 log <<
"\nConfigured " << fADCthresholds.size() <<
" thresholds (ADC):";
450 for (
auto const& [ threshold, dataTag ]: fADCthresholds)
451 log <<
"\n * " << threshold <<
" (from '" << dataTag.encode() <<
"')";
461 consumes<std::vector<OpticalTriggerGateData_t>>(inputDataTag);
462 consumes<art::Assns<OpticalTriggerGateData_t, sbn::OpDetWaveformMeta>>
471 produces<std::vector<OpticalTriggerGateData_t>>(inputDataTag.instance());
472 produces<art::Assns<OpticalTriggerGateData_t, sbn::OpDetWaveformMeta>>
473 (inputDataTag.instance());
474 if (fProduceWaveformAssns) {
475 produces<art::Assns<OpticalTriggerGateData_t, raw::OpDetWaveform>>
476 (inputDataTag.instance());
505 *(lar::providerFrom<geo::Geometry>()),
506 "SlidingWindowTrigger/SlidingWindowDefinitionAlg"
509 return algo.
makeWindows(fWindowSize, fWindowStride);
518 std::string
const& threshold,
519 art::InputTag
const& dataTag
523 <<
"Processing threshold " << threshold
524 <<
" from '" << dataTag.encode() <<
"'"
531 std::vector<TrackedTriggerGate_t>
const& gates
534 std::vector<TrackedTriggerGate_t> combinedGates = fCombiner.combine(gates);
537 art::PtrMaker<OpticalTriggerGateData_t>
const makeGatePtr
538 (event, dataTag.instance());
539 auto [ outputGates, outputAssns ]
541 (std::move(combinedGates), makeGatePtr, waveformMap);
546 <<
"Threshold " << threshold <<
" ('" << dataTag.encode() <<
"'): "
547 << gates.size() <<
" input channels, "
548 << outputGates.size() <<
" output channels (+"
549 << outputAssns.size() <<
" associations to waveforms) into '"
550 << moduleDescription().moduleLabel() <<
":" << dataTag.instance() <<
"'"
553 log <<
"\n [#" << iGate <<
"] " <<
compactdump(gate);
557 if (fProduceWaveformAssns) {
562 art::Assns<OpticalTriggerGateData_t, raw::OpDetWaveform> outputWaveAssns;
563 for (
auto const [ gatePtr, metaPtr ]: outputAssns)
564 outputWaveAssns.addSingle(gatePtr, waveformMetaMatcher(metaPtr));
567 std::make_unique<art::Assns<OpticalTriggerGateData_t, raw::OpDetWaveform>>
568 (std::move(outputWaveAssns)),
574 std::make_unique<std::vector<OpticalTriggerGateData_t>>
575 (std::move(outputGates)),
579 std::make_unique<art::Assns<OpticalTriggerGateData_t, sbn::OpDetWaveformMeta>>
580 (std::move(outputAssns)),
590 , fhicl::OptionalSequence<std::size_t>
const& enabled
591 , fhicl::OptionalSequence<std::size_t>
const& disabled
592 ) -> std::vector<std::size_t> {
594 std::vector<std::size_t> selection;
597 if (!enabled(selection)) {
598 selection.resize(nWindows);
599 std::iota(selection.begin(), selection.end(), 0U);
603 std::vector<std::size_t> removeWindows;
604 disabled(removeWindows);
605 auto const find = [&selection](std::size_t index)
606 {
return std::find(selection.begin(), selection.end(), index); };
607 for (std::size_t
const index: removeWindows) {
608 if (
auto const it = find(index); it != selection.end()) selection.erase(it);
618 art::Assns<TriggerGateData_t, sbn::OpDetWaveformMeta>
const& assns
621 for (art::Ptr<sbn::OpDetWaveformMeta>
const& wave: util::get_elements<1U>(assns))
622 map.emplace(wave.get(), wave);
629 art::Event
const& event,
630 art::InputTag
const& dataTag,
632 )
const -> std::vector<TrackedTriggerGate_t> {
636 event.getProduct<art::Assns<OpticalTriggerGateData_t, sbn::OpDetWaveformMeta>>
639 UpdateWaveformMap(waveformMap, assns);
642 (event.getProduct<std::vector<OpticalTriggerGateData_t>>(dataTag), assns);
BEGIN_PROLOG BeamGateDuration pmtthr physics producers trigtilewindowORS Thresholds
std::vector< std::size_t > const fEnabledWindows
List of windows to be included.
fhicl::OptionalSequence< std::size_t > EnableOnlyWindows
Utilities related to art service access.
Utilities for the conversion of trigger gate data formats.
WindowDefs_t const fWindowChannels
Channel content of each window.
SlidingWindowTrigger & operator=(SlidingWindowTrigger const &)=delete
std::optional< typename Optional::value_type > getOptionalValue(Optional const ¶meter)
Returns the value of an optional parameter as std::optional.
bool fProduceWaveformAssns
Whether to produce gate/waveform associations.
Definition of util::get_elements() and util::get_const_elements().
fhicl::Atom< std::string > TriggerGatesTag
Definition of util::enumerate().
A wrapper to trigger gate objects tracking the input of operations.
std::vector< icarus::trigger::OpticalTriggerGateData_t > transformIntoOpticalTriggerGate(Gates &&gates)
Returns the trigger gates in serializable format.
fhicl::OptionalAtom< unsigned int > Stride
decltype(auto) const_values(Coll &&coll)
Range-for loop helper iterating across the constant values of the specified collection.
std::map< std::string, art::InputTag > fADCthresholds
ADC thresholds to read, and the input tag connected to their data.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
fhicl::Atom< bool > ProduceWaveformAssns
unsigned int nDisabledWindows() const noexcept
Returns the number of disabled windows.
Access the description of detector geometry.
unsigned int const fWindowStride
Sliding window base offset.
Combines trigger channels (V1730 LVDS gates) into sliding windows.
icarus::trigger::TriggerWindowDefs_t WindowDefs_t
Definition of all windows.
auto dumpTriggerWindowChannels(TriggerWindowChannels_t const &window) -> details::DumpTriggerWindowChannelWrapper
Logical multi-level gate associated to one or more readout channels.
Simple type definitions for trigger algorithms.
Algorithm composing PMT sliding windows from geometry information.
fhicl::Atom< std::string > LogCategory
A trigger gate data object for optical detector electronics.
unsigned int const fWindowSize
Sliding window size in number of channels.
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
Algorithm to combine trigger channels into sliding windows.
icarus::trigger::ReadoutTriggerGate< TriggerGateTick_t, TriggerGateTicks_t, raw::Channel_t > OpticalTriggerGateData_t
Type of trigger gate data serialized into art data products.
Algorihtm to group PMTs into piling towers.
std::string const fLogCategory
Message facility stream category for output.
BEGIN_PROLOG vertical distance to the surface Name
fhicl::OptionalSequence< std::size_t > DisableWindows
BEGIN_PROLOG triggeremu_data_config_icarus settings sequence::triggeremu_data_config_icarus settings PMTADCthresholds sequence::triggeremu_data_config_icarus settings PMTADCthresholds WindowSize
Definition for PMT sliding windows.
std::vector< icarus::trigger::TrackedOpticalTriggerGate< sbn::OpDetWaveformMeta > > ReadTriggerGates(art::Event const &event, art::InputTag const &dataTag, icarus::trigger::OpDetWaveformMetaDataProductMap_t &waveformMap) const
Reads a set of input gates from the event and updates waveformMap.
static void UpdateWaveformMap(icarus::trigger::OpDetWaveformMetaDataProductMap_t &map, art::Assns< TriggerGateData_t, sbn::OpDetWaveformMeta > const &assns)
Adds the waveforms in the specified association to the waveform map.
size_t Stride(bool allow_default)
SlidingWindowTrigger(Parameters const &config)
fhicl::Sequence< raw::Channel_t > MissingChannels
Functions pulling in STL customization if available.
icarus::trigger::SlidingWindowCombinerAlg const fCombiner
Combining algorithm.
static std::vector< std::size_t > makeEnabledWindowIndices(std::size_t nWindows, fhicl::OptionalSequence< std::size_t > const &enabled, fhicl::OptionalSequence< std::size_t > const &disabled)
Returns a list of enabled window indices.
void produceThreshold(art::Event &event, icarus::trigger::OpDetWaveformMetaDataProductMap_t &waveformMap, std::string const &threshold, art::InputTag const &dataTag) const
Performs the combination for data with a specified threshold.
A simple alias for a most commonly used TrackedTriggerGate type.
std::vector< icarus::trigger::TrackedOpticalTriggerGate< OpDetInfo > > FillTriggerGates(std::vector< icarus::trigger::OpticalTriggerGateData_t > const &gates, art::Assns< icarus::trigger::OpticalTriggerGateData_t, OpDetInfo > const &gateToWaveformInfo)
Creates a gate object out of trigger gate data products.
Simple helper functions to deal with FHiCL.
Groups optical detector channels into windows based on position.
Definition of util::values() and util::const_values().
fhicl::Sequence< std::string > Thresholds
virtual void produce(art::Event &event) override
Fills the plots. Also extracts the information to fill them with.
art::EDProducer::Table< Config > Parameters
std::vector< TriggerWindowChannels_t > TriggerWindowDefs_t
Definition of all windows.
std::vector< icarus::trigger::TrackedOpticalTriggerGate< OpDetInfo > > ReadTriggerGates(Event const &event, art::InputTag const &dataTag)
Assembles and returns trigger gates from serialized data.
Iterators recursing though nested collections.
util::DataProductPointerMap_t< sbn::OpDetWaveformMeta > OpDetWaveformMetaDataProductMap_t
Map util::DataProductPointerMap_t for sbn::OpDetWaveformMeta objects.
WindowDefs_t makeWindows(unsigned int windowSize, unsigned int windowStride) const
Performs the calculation and returns the sliding window composition.
fhicl::Atom< unsigned int > WindowSize
OpticalTriggerGateData_t GateData_t
Type for gate data access.
art framework interface to geometry description
WindowDefs_t defineWindows() const
Defines the channels falling in each window.
auto compactdump(ReadoutTriggerGate< Tick, TickInterval, ChannelIDType > const &gate) -> details::CompactFormatter< ReadoutTriggerGate< Tick, TickInterval, ChannelIDType >>
Manipulator-like function for compact format of trigger gates.