All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
icarus::trigger::TriggerSimulationOnGates Class Reference

Simulates a sliding window trigger at specified gate times. More...

Inheritance diagram for icarus::trigger::TriggerSimulationOnGates:
lar::UncopiableAndUnmovableClass

Classes

struct  Config
 
struct  ThresholdPlotInfo_t
 All information needed to generate plots for a specific threshold. More...
 

Public Types

using microseconds = util::quantities::intervals::microseconds
 
using nanoseconds = util::quantities::intervals::nanoseconds
 
using Parameters = art::EDProducer::Table< Config >
 

Public Member Functions

 TriggerSimulationOnGates (Parameters const &config)
 
virtual void beginJob () override
 Initializes the plots. More...
 
virtual void produce (art::Event &event) override
 Runs the simulation and saves the results into the art event. More...
 
virtual void endJob () override
 Prints end-of-job summaries. More...
 

Private Types

using TriggerInfo_t = details::TriggerInfo_t
 Type alias. More...
 
using InputTriggerGate_t = icarus::trigger::SlidingWindowPatternAlg::InputTriggerGate_t
 Type of trigger gate extracted from the input event. More...
 
using TriggerGates_t = icarus::trigger::SlidingWindowPatternAlg::TriggerGates_t
 List of trigger gates. More...
 
using WindowTriggerInfo_t = icarus::trigger::SlidingWindowPatternAlg::AllTriggerInfo_t
 Data structure to communicate internally a trigger response. More...
 
using BinnedContent_t = icarus::ns::util::FixedBins< double >
 Content for future histograms, binned. More...
 
using BeamGates_t = std::vector< sim::BeamGateInfo >
 Type of list of gates to simulate trigger into. More...
 

Private Member Functions

void initializePlots ()
 Initializes the full set of plots (all ADC thresholds). More...
 
void finalizePlots ()
 Creates summary plots from proto-histogram data. More...
 
void makeThresholdPlots (std::string const &threshold, icarus::trigger::PlotSandbox &plots, ThresholdPlotInfo_t const &plotInfo)
 
void makeEventPlots ()
 Creates in the main sandbox all event-wide plots. More...
 
void plotEvent (art::Event const &event, detinfo::DetectorTimings const &detTimings, std::vector< icarus::trigger::ApplyBeamGateClass > const &gates)
 Fills event-wide plots. More...
 
void plotTriggerResponse (std::size_t iThr, std::string const &thrTag, WindowTriggerInfo_t const &triggerInfo, detinfo::DetectorTimings const &detTimings)
 Fills the plots for threshold index iThr with trigger information. More...
 
std::vector< WindowTriggerInfo_tproduceForThreshold (art::Event &event, detinfo::DetectorTimings const &detTimings, std::vector< ApplyBeamGateClass > const &beamGates, std::size_t const iThr, std::string const &thrTag, unsigned int firstTriggerNumber)
 Performs the simulation for the specified ADC threshold. More...
 
raw::Trigger triggerInfoToTriggerData (detinfo::DetectorTimings const &detTimings, ApplyBeamGateClass const &beamGate, unsigned int triggerNumber, WindowTriggerInfo_t const &info) const
 Converts the trigger information into a raw::Trigger object. More...
 
void printSummary () const
 Prints the summary of fired triggers on screen. More...
 
TH1 * makeHistogramFromBinnedContent (icarus::trigger::PlotSandbox &plots, std::string const &name, std::string const &title, BinnedContent_t const &binnedContent) const
 Creates and returns a 1D histogram filled with binnedContent. More...
 
icarus::trigger::ApplyBeamGateClass makeMyBeamGate (detinfo::DetectorTimings const &detTimings, sim::BeamGateInfo const &gate) const
 Shortcut to create an ApplyBeamGate with the specified gate. More...
 
std::vector
< icarus::trigger::ApplyBeamGateClass
makeMyBeamGates (detinfo::DetectorTimings const &detTimings, BeamGates_t const &gates) const
 Shortcut to create ApplyBeamGate from a list of gates. More...
 
std::vector
< icarus::trigger::ApplyBeamGateClass
makeMyBeamGates (art::Event const *event, BeamGates_t const &gates) const
 
std::vector
< icarus::trigger::ApplyBeamGateClass
makeMyBeamGates (art::Event const &event, BeamGates_t const &gates) const
 
- Private Member Functions inherited from lar::UncopiableClass
 UncopiableClass ()=default
 Default constructor. More...
 
 ~UncopiableClass ()=default
 Default destructor. More...
 
 UncopiableClass (UncopiableClass const &)=delete
 Deleted copy and move constructors and assignments. More...
 
 UncopiableClass (UncopiableClass &&)=default
 
UncopiableClassoperator= (UncopiableClass const &)=delete
 
UncopiableClassoperator= (UncopiableClass &&)=default
 
- Private Member Functions inherited from lar::UnmovableClass
 UnmovableClass ()=default
 Default constructor. More...
 
 ~UnmovableClass ()=default
 Default destructor. More...
 
 UnmovableClass (UnmovableClass const &)=default
 Default copy constructor and assignment. More...
 
UnmovableClassoperator= (UnmovableClass const &)=default
 
 UnmovableClass (UnmovableClass &&)=delete
 Deleted move constructor and assignment. More...
 
UnmovableClassoperator= (UnmovableClass &&)=delete
 

Static Private Member Functions

static double eventTimestampInSeconds (art::Timestamp const &time)
 Returns the time of the event in seconds from The Epoch. More...
 
static double eventTimestampInSeconds (art::Event const &event)
 

Private Attributes

std::map< std::string,
art::InputTag > 
fADCthresholds
 Name of ADC thresholds to read, and the input tag connected to their data. More...
 
WindowPattern const fPattern
 Configured sliding window requirement pattern. More...
 
art::InputTag const fBeamGateTag
 Data product of beam gates to simulate. More...
 
std::uint32_t fBeamBits
 Bits for the beam gate being simulated. More...
 
nanoseconds fTriggerTimeResolution
 Trigger resolution in time. More...
 
double fEventTimeBinning
 Trigger time plot binning [s]. More...
 
std::string const fLogCategory
 Message facility stream category for output. More...
 
art::TFileDirectory fOutputDir
 ROOT directory where all the plots are written. More...
 
std::vector< std::string > fOutputInstances
 Output data product instance names (same order as fADCthresholds). More...
 
icarus::trigger::WindowTopologyManager fWindowMapMan
 Mapping of each sliding window with location and topological information. More...
 
std::optional
< icarus::trigger::SlidingWindowPatternAlg
fPatternAlg
 Pattern algorithm. More...
 
icarus::trigger::PlotSandbox fPlots
 All plots in one practical sandbox. More...
 
ThresholdPlotInfo_t fEventPlotInfo
 Proto-histogram information in a convenient packet; event-wide. More...
 
std::vector< ThresholdPlotInfo_tfThresholdPlots
 Proto-histogram information in a not-so-practical array; per threshold. More...
 
std::vector< std::atomic
< unsigned int > > 
fTriggerCount
 
std::atomic< unsigned int > fTotalGates { 0U }
 Count of opened gates. More...
 

Detailed Description

Simulates a sliding window trigger at specified gate times.

This module produces raw::Trigger objects each representing the outcome of some trigger logic applied to discriminated optical detector input ("trigger primitives"). The logic is applied to each event at multiple times, according to a list of time intervals read from each event.

The main purpose of this module is to simulate the trigger logic at times of special interest, typically the times some track is believed to have crossed the detector.

A trigger primitive is a two-level function of time which describes when that primitive is on and when it is off. Trigger primitives are given as input to this module and their origin may vary, but the standard source in ICARUS is single trigger request (LVDS).

This module applies a sliding window pattern to the input: the pattern consists of a requirement on the main window and optional additional requirements on the neighbouring windows. This module rebases the configured pattern on each of the available windows, evaluates the requirement of the pattern in that configuration, and decides whether those requirements are met. The general trigger is considered passed if any of the rebased patterns satisfies the requirement at any time, and no special treatment is performed in case multiple windows fulfil them, except that the trigger time is driven by the earliest of the satisfied patterns.

A single trigger pattern is configured for each instance of the module, while multiple input sets (e.g. with different discrimination thresholds) can be processed on the same pattern by the same module instance. Conversely, testing a different pattern requires the instantiation of a new module.

Configuration

An example job configuration is provided as simulate_sliding_window_trigger_icarus.fcl.

Input data products

Output data products

Trigger logic algorithm

This section describes the trigger logic algorithm used in icarus::trigger::TriggerSimulationOnGates and its assumptions. Nevertheless, more up-to-date information can be found in SlidingWindowTrigger module (for the combination of the LVDS signals into window-wide gates) and in icarus::trigger::SlidingWindowPatternAlg, which applies the configured pattern logic to the input.

The module receives as input a multi-level trigger gate for each of the windows to be considered. On the first input (i.e. the first event), that input is parsed to learn the windows and their relative position from the input trigger gates. This topology will be used to apply the configured patterns. On the following events, their input is checked to confirm the compatibility of the composition of its windows with the one from that first event (both aspects are handled by an icarus::trigger::WindowTopologyManager object).

All multi-level gates are set in coincidence with the beam gate by multiplying the multi-level and the beam gates. Because of this, trigger gates are suppressed everywhere except than during the beam gate (see below). The reference time for the beam gates is the time configured in DetectorClocks service provider (detinfo::DetectorClocks::BeamGateTime()).

The algorithm handles independently multiple trigger patterns. On each input, each configured pattern is applied based on the window topology. Each pattern describes a minimum level of the trigger gate in the window, that usually means the number of LVDS signals in coincidence at any given time ("majority"). A pattern may have requirements on the neighbouring windows in addition to the main one. The pattern is satisfied if all involved windows pass their specific requirements at the same time (coincidence between windows). Each pattern is applied in turn to each of the windows (which is the "main" window). The neighborhood described in the pattern is applied with respect to that main window. The trigger fires if one or more of the windows satisfy the pattern, and the trigger time is the one of the earliest satisfied pattern (more precisely, the earliest tick when the coincidence required by that pattern is satisfied).* All windows in the detector are considered independently, but the supported patterns may only include components in the same cryostat. Therefore, triggers are effectively on a single cryostat. An object of class icarus::trigger::SlidingWindowPatternAlg applies this logic: see its documentation for the most up-to-date details.

Eventually, for each event there are as many different trigger responses as how many different patterns are configured (Patterns configuration parameter), times how many ADC thresholds are provided in input, configured in Thresholds.

Beam gates

A single instance of this module can perform the simulation on several beam gates. The values of these beam gates are picked from the data product specified in BeamGates, event by event. The specified beam gate times are on beam gate time scale, i.e. their reference time 0 is the time of the beam gate as known by detinfo::DetectorClocks::BeamGateTime(). In case the same beam gate is desired for all events, such data product can be produced by icarus::trigger::WriteBeamGateInfo module. The trigger data product collection produced by this module has the same number of entries as the beam gates in the data product, and they match one-to-one.

Technical aspects of the module

This module does not build the trigger gates of the sliding windows, but rather it takes them as input (see e.g. SlidingWindowTrigger module). Window topology (size of the windows and their relations) is stored in icarus::trigger::WindowChannelMap objects, and its construction is delegated to icarus::trigger::WindowTopologyAlg (under the hood of the WindowTopologyManager class) which learns it from the actual trigger gate input rather than on explicit configuration. Pattern definitions and configuration are defined in icarus::trigger::WindowPattern and icarus::trigger::ns::fhicl::WindowPatternConfig respectively. Trigger simulation is delegated to icarus::trigger::SlidingWindowPatternAlg.

Todo:
Plots need to be thought and implemented.

Definition at line 287 of file TriggerSimulationOnGates_module.cc.

Member Typedef Documentation

Type of list of gates to simulate trigger into.

Definition at line 407 of file TriggerSimulationOnGates_module.cc.

Content for future histograms, binned.

Definition at line 396 of file TriggerSimulationOnGates_module.cc.

Type of trigger gate extracted from the input event.

Definition at line 385 of file TriggerSimulationOnGates_module.cc.

Definition at line 294 of file TriggerSimulationOnGates_module.cc.

Definition at line 295 of file TriggerSimulationOnGates_module.cc.

Definition at line 355 of file TriggerSimulationOnGates_module.cc.

List of trigger gates.

Definition at line 389 of file TriggerSimulationOnGates_module.cc.

Type alias.

Definition at line 381 of file TriggerSimulationOnGates_module.cc.

Data structure to communicate internally a trigger response.

Definition at line 393 of file TriggerSimulationOnGates_module.cc.

Constructor & Destructor Documentation

icarus::trigger::TriggerSimulationOnGates::TriggerSimulationOnGates ( Parameters const &  config)
explicit

Definition at line 604 of file TriggerSimulationOnGates_module.cc.

605  : art::EDProducer (config)
606  // configuration
607  , fPattern (config().Pattern())
608  , fBeamGateTag (config().BeamGates())
609  , fBeamBits (config().BeamBits())
610  , fTriggerTimeResolution(config().TriggerTimeResolution())
611  , fEventTimeBinning (config().EventTimeBinning())
612  , fLogCategory (config().LogCategory())
613  // services
614  , fOutputDir (*art::ServiceHandle<art::TFileService>())
615  // internal and cached
616  , fWindowMapMan
617  { *lar::providerFrom<geo::Geometry>(), fLogCategory + "_WindowMapManager" }
618  , fPlots(
619  fOutputDir, "", "requirement: " + fPattern.description()
620  )
621  , fEventPlotInfo{
622  BinnedContent_t{ fEventTimeBinning } // eventTimes
623  , BinnedContent_t{ // HWtrigTimeVsBeam
625  <detinfo::timescales::trigger_time::interval_t>().value()
626  }
627  , BinnedContent_t{ // triggerTimesVsHWtrig
629  <detinfo::timescales::trigger_time::interval_t>().value()
630  }
631  , BinnedContent_t{ // triggerTimesVsBeam
633  <detinfo::timescales::trigger_time::interval_t>().value()
634  }
635  }
636 {
637 
638  //
639  // more complex parameter parsing
640  //
641  std::string const& discrModuleLabel = config().TriggerGatesTag();
642  for (std::string const& threshold: config().Thresholds())
643  fADCthresholds[threshold] = art::InputTag{ discrModuleLabel, threshold };
644 
645  // initialization of a vector of atomic is not as trivial as it sounds...
646  fTriggerCount = std::vector<std::atomic<unsigned int>>(fADCthresholds.size());
647  std::fill(fTriggerCount.begin(), fTriggerCount.end(), 0U);
648 
649  //
650  // input data declaration
651  //
652  using icarus::trigger::OpticalTriggerGateData_t; // for convenience
653 
654  // trigger primitives
655  for (art::InputTag const& inputDataTag: util::const_values(fADCthresholds)) {
658  } // for
659 
660  //
661  // output data declaration
662  //
663  // keepThresholdName is true if we write instance name in output data products
664  bool const keepThresholdName
665  = config().KeepThresholdName().value_or(config().Thresholds().size() > 1);
666  if (!keepThresholdName && (config().Thresholds().size() > 1)) {
667  throw art::Exception(art::errors::Configuration)
668  << config().KeepThresholdName.name()
669  << " can be set to `true` only when a single threshold is specified ("
670  << config().Thresholds.name() << " has " << config().Thresholds().size()
671  << ")";
672  }
673 
674  for (auto const& inputDataTag: util::const_values(fADCthresholds)) {
675  std::string const outputInstance
676  = keepThresholdName? inputDataTag.instance(): "";
677  produces<std::vector<raw::Trigger>>(outputInstance);
678  fOutputInstances.push_back(outputInstance);
679  }
680 
681  {
682  mf::LogInfo log(fLogCategory);
683  log << "\nConfigured " << fADCthresholds.size() << " thresholds (ADC):";
684  for (auto const& [ thresholdTag, dataTag ]: fADCthresholds)
685  log << "\n * " << thresholdTag << " (from '" << dataTag.encode() << "')";
686 
687  } // local block
688 
689 
690 } // icarus::trigger::TriggerSimulationOnGates::TriggerSimulationOnGates()
BEGIN_PROLOG BeamGateDuration pmtthr physics producers trigtilewindowORS Thresholds
std::map< std::string, art::InputTag > fADCthresholds
Name of ADC thresholds to read, and the input tag connected to their data.
art::InputTag const fBeamGateTag
Data product of beam gates to simulate.
double fEventTimeBinning
Trigger time plot binning [s].
decltype(auto) const_values(Coll &&coll)
Range-for loop helper iterating across the constant values of the specified collection.
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
void declareConsumes(ConsumesCollector &collector) const
Declares to the collector the data products that are going to be read.
std::string const fLogCategory
Message facility stream category for output.
Assembles and returns trigger gates from serialized data.
std::vector< std::string > fOutputInstances
Output data product instance names (same order as fADCthresholds).
icarus::trigger::ReadoutTriggerGate< TriggerGateTick_t, TriggerGateTicks_t, raw::Channel_t > OpticalTriggerGateData_t
Type of trigger gate data serialized into art data products.
icarus::trigger::WindowTopologyManager fWindowMapMan
Mapping of each sliding window with location and topological information.
std::uint32_t fBeamBits
Bits for the beam gate being simulated.
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
constexpr IV convertInto() const
Convert this interval into the specified one.
Definition: intervals.h:389
icarus::ns::util::FixedBins< double > BinnedContent_t
Content for future histograms, binned.
WindowPattern const fPattern
Configured sliding window requirement pattern.
std::vector< std::atomic< unsigned int > > fTriggerCount
icarus::trigger::PlotSandbox fPlots
All plots in one practical sandbox.
art::TFileDirectory fOutputDir
ROOT directory where all the plots are written.
ThresholdPlotInfo_t fEventPlotInfo
Proto-histogram information in a convenient packet; event-wide.
temporary value
BEGIN_PROLOG triggeremu_data_config_icarus settings sequence::triggeremu_data_config_icarus settings PMTADCthresholds sequence::triggeremu_data_config_icarus settings PMTADCthresholds sequence::triggeremu_data_config_icarus settings PMTADCthresholds Pattern
nanoseconds fTriggerTimeResolution
Trigger resolution in time.
fDetProps &fDetProps fDetProps &fDetProps consumesCollector())
std::string description() const
Returns a description of the pattern.

Member Function Documentation

void icarus::trigger::TriggerSimulationOnGates::beginJob ( )
overridevirtual

Initializes the plots.

Definition at line 694 of file TriggerSimulationOnGates_module.cc.

694  {
695 
696  initializePlots();
697 
698 } // icarus::trigger::TriggerSimulationOnGates::beginJob()
void initializePlots()
Initializes the full set of plots (all ADC thresholds).
void icarus::trigger::TriggerSimulationOnGates::endJob ( )
overridevirtual

Prints end-of-job summaries.

Definition at line 767 of file TriggerSimulationOnGates_module.cc.

767  {
768 
769  finalizePlots();
770 
771  printSummary();
772 
773 } // icarus::trigger::TriggerSimulationOnGates::endJob()
void finalizePlots()
Creates summary plots from proto-histogram data.
void printSummary() const
Prints the summary of fired triggers on screen.
double icarus::trigger::TriggerSimulationOnGates::eventTimestampInSeconds ( art::Timestamp const &  time)
staticprivate

Returns the time of the event in seconds from The Epoch.

Definition at line 1249 of file TriggerSimulationOnGates_module.cc.

1250 {
1251  // high value: seconds from the Epoch (Jan 1, 1970 UTC?);
1252  // low value: nanoseconds after that the start of that second
1253  return static_cast<double>(time.timeHigh())
1254  + static_cast<double>(time.timeHigh()) * 1e-9;
1255 } // icarus::trigger::TriggerSimulationOnGates::eventTimestampInSeconds()
do i e
double icarus::trigger::TriggerSimulationOnGates::eventTimestampInSeconds ( art::Event const &  event)
staticprivate

Definition at line 1260 of file TriggerSimulationOnGates_module.cc.

1261  { return eventTimestampInSeconds(event.time()); }
static double eventTimestampInSeconds(art::Timestamp const &time)
Returns the time of the event in seconds from The Epoch.
void icarus::trigger::TriggerSimulationOnGates::finalizePlots ( )
private

Creates summary plots from proto-histogram data.

Definition at line 923 of file TriggerSimulationOnGates_module.cc.

923  {
924 
925 #if 0
926 
927  for (auto const& [ thr, info ]
928  : util::zip(util::get_elements<0U>(fADCthresholds), fThresholdPlots))
929  {
931  makeThresholdPlots(thr, plots, info);
932  if (plots.empty()) fPlots.deleteSubSandbox(plots.name());
933  } // for thresholds
934 
935  makeEventPlots();
936 
937 #endif // 0
938 
939 } // icarus::trigger::TriggerSimulationOnGates::finalizePlots()
std::map< std::string, art::InputTag > fADCthresholds
Name of ADC thresholds to read, and the input tag connected to their data.
void makeThresholdPlots(std::string const &threshold, icarus::trigger::PlotSandbox &plots, ThresholdPlotInfo_t const &plotInfo)
std::string const & name() const
Returns the sandbox name.
Definition: PlotSandbox.h:196
bool deleteSubSandbox(std::string const &name)
Deletes the subbox with the specified name and its directory.
std::vector< ThresholdPlotInfo_t > fThresholdPlots
Proto-histogram information in a not-so-practical array; per threshold.
bool empty() const
Returns if the sandbox is empty (neither it nor subboxes hold objects).
std::vector< PlotDef > plots
Definition: demo.h:54
icarus::trigger::PlotSandbox fPlots
All plots in one practical sandbox.
static auto & demandSandbox(SandboxType &sandbox, std::string const &name)
Helper function for demandSandbox() implementations.
Definition: PlotSandbox.h:750
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295
void makeEventPlots()
Creates in the main sandbox all event-wide plots.
A helper to manage ROOT objects with consistent naming.
Definition: PlotSandbox.h:95
void icarus::trigger::TriggerSimulationOnGates::initializePlots ( )
private

Initializes the full set of plots (all ADC thresholds).

Definition at line 777 of file TriggerSimulationOnGates_module.cc.

777  {
778 
779 #if 0
780  //
781  // overview plots with different settings
782  //
783 
784  std::vector<std::string> thresholdLabels;
785  thresholdLabels.reserve(size(fADCthresholds));
786  for (std::string thr: util::get_elements<0U>(fADCthresholds))
787  thresholdLabels.push_back(std::move(thr));
788 
789  auto const beamGate = makeMyBeamGate();
790  mf::LogInfo(fLogCategory)
791  << "Beam gate for plots: " << beamGate.asSimulationTime()
792  << " (simulation time), " << beamGate.tickRange()
793  << " (optical ticks)"
794  ;
795 
796  //
797  // Triggering efficiency vs. ADC threshold.
798  //
799  auto* NTriggers = fPlots.make<TH1F>(
800  "NTriggers",
801  "Number of triggering events"
802  ";PMT discrimination threshold [ ADC counts ]"
803  ";events",
804  thresholdLabels.size(), 0.0, double(thresholdLabels.size())
805  );
806  util::ROOT::applyAxisLabels(NTriggers->GetXaxis(), thresholdLabels);
807 
808  auto* Eff = fPlots.make<TEfficiency>(
809  "Eff",
810  "Triggering pass fraction"
811  ";PMT discrimination threshold [ ADC counts ]"
812  ";trigger pass fraction",
813  thresholdLabels.size(), 0.0, double(thresholdLabels.size())
814  );
815  // people are said to have earned hell for things like this;
816  // but TEfficiency really does not expose the interface to assign labels to
817  // its axes, which supposedly could be done had we chosen to create it by
818  // histograms instead of directly as recommended.
820  (const_cast<TH1*>(Eff->GetTotalHistogram())->GetXaxis(), thresholdLabels);
821 
822  detinfo::timescales::optical_time_ticks const triggerResolutionTicks{
824  };
825 
826  auto const& beamGateTicks = beamGate.tickRange();
827  auto* TrigTime = fPlots.make<TH2F>(
828  "TriggerTick",
829  "Trigger time tick"
830  ";optical time tick [ /" + util::to_string(triggerResolutionTicks) + " ]"
831  ";PMT discrimination threshold [ ADC counts ]"
832  ";events",
833  static_cast<int>(std::ceil(beamGate.lengthTicks()/triggerResolutionTicks)),
834  beamGateTicks.start().value(),
836  (beamGateTicks.start() + beamGate.lengthTicks(), triggerResolutionTicks)
837  .value(),
838  thresholdLabels.size(), 0.0, double(thresholdLabels.size())
839  );
840  util::ROOT::applyAxisLabels(TrigTime->GetYaxis(), thresholdLabels);
841 
842 
843  // we allow some fixed margin in the plot, just in case:
844  constexpr microseconds beamPlotPadding { 4_us };
845 
847 
848  // hardware trigger may happen at any place within the beam gate,
849  // and in this plot range I want to include the full beam gate;
850  // so I take a beam gate worth of time before the trigger time,
851  // and as much after it; since this plot is relative to the hardware trigger,
852  // the hardware trigger time itself is 0
853  icarus::ns::util::BinningSpecs const HWtrigBinning = alignBinningTo(
855  (- beamGate.length() - beamPlotPadding).value(),
856  (beamGate.length() + beamPlotPadding).value(),
857  fTriggerTimeResolution.convertInto<trigger_time::interval_t>().value()
858  },
859  0.0
860  );
861  fPlots.make<TH2F>(
862  "TriggerTimeVsHWTrig",
863  "Time of the trigger"
864  ";trigger time (relative to hardware trigger) [ #mus ]"
865  ";PMT discrimination threshold [ ADC counts ]"
866  ";triggers",
867  HWtrigBinning.nBins(), HWtrigBinning.lower(), HWtrigBinning.upper(),
868  thresholdLabels.size(), 0.0, double(thresholdLabels.size())
869  );
870 
871  icarus::ns::util::BinningSpecs const beamGateBinning = alignBinningTo(
873  (-beamPlotPadding).value(),
874  (beamGate.length() + beamPlotPadding).value(),
875  fTriggerTimeResolution.convertInto<trigger_time::interval_t>().value()
876  },
877  0.0
878  );
879  fPlots.make<TH2F>(
880  "TriggerTimeVsBeamGate",
881  "Time of the trigger"
882  ";trigger time (relative to beam gate opening) [ #mus ]"
883  ";PMT discrimination threshold [ ADC counts ]"
884  ";triggers",
885  beamGateBinning.nBins(), beamGateBinning.lower(), beamGateBinning.upper(),
886  thresholdLabels.size(), 0.0, double(thresholdLabels.size())
887  );
888 
889  //
890  // per-threshold plots; should this initialization be set into its own method?
891  //
892  for (auto const& [ thr, info ]
893  : util::zip(util::get_elements<0U>(fADCthresholds), fThresholdPlots))
894  {
896  = fPlots.addSubSandbox("Thr" + thr, "Threshold: " + thr);
897 
898  plots.make<TGraph>(
899  "TriggerTimeVsHWTrigVsBeam",
900  "Time of the trigger: emulated vs. hardware"
901  ";hardware trigger time (relative to beam gate opening) [ #mus ]"
902  ";emulated trigger time (relative to beam gate opening) [ #mus ]"
903  );
904 
905  } // for thresholds
906 
907  fThresholdPlots.resize(
909  {
910  BinnedContent_t{ fEventTimeBinning }, // eventTimes
911  BinnedContent_t{ HWtrigBinning.binWidth() }, // HWtrigTimeVsBeam
912  BinnedContent_t{ HWtrigBinning.binWidth() }, // triggerTimesVsHWtrig
913  BinnedContent_t{ beamGateBinning.binWidth() } // triggerTimesVsBeam
914  }
915  );
916 
917 #endif // 0
918 
919 } // icarus::trigger::TriggerSimulationOnGates::initializePlots()
icarus::trigger::ApplyBeamGateClass makeMyBeamGate(detinfo::DetectorTimings const &detTimings, sim::BeamGateInfo const &gate) const
Shortcut to create an ApplyBeamGate with the specified gate.
std::map< std::string, art::InputTag > fADCthresholds
Name of ADC thresholds to read, and the input tag connected to their data.
Obj * make(std::string const &name, std::string const &title, Args &&...args)
Creates a new ROOT object with the specified name and title.
Definition: PlotSandbox.h:701
constexpr T roundup(T const value, U const quantum, T const offset=T{})
Returns the value, rounded up.
Definition: rounding.h:112
double fEventTimeBinning
Trigger time plot binning [s].
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
void applyAxisLabels(TAxis *pAxis, std::vector< std::string > const &labels, int first=1)
Sets all the labels starting with the bin first (1 by default).
Definition: ROOTutils.h:175
double lower() const
Returns the value of the lower end of the first bin.
Definition: BinningSpecs.h:187
std::string const fLogCategory
Message facility stream category for output.
BinningSpecs alignBinningTo(BinningSpecs const &binning, double boundary, bool extendCoverage=true)
Returns a binning shifted to align with the specified boundary.
timescale_traits< OpticalTimeCategory >::tick_interval_t optical_time_ticks
std::vector< ThresholdPlotInfo_t > fThresholdPlots
Proto-histogram information in a not-so-practical array; per threshold.
timescale_traits< TriggerTimeCategory >::time_point_t trigger_time
A point in time on the trigger time scale.
Data structure holding binning information.
Definition: BinningSpecs.h:170
double binWidth() const
Returns the width of the bins (all bins have the same width).
Definition: BinningSpecs.h:199
Ticks toOpticalTicks(time_interval time) const
Returns the optical ticks corresponding to a time interval.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
util::quantities::intervals::microseconds microseconds
std::vector< PlotDef > plots
Definition: demo.h:54
constexpr IV convertInto() const
Convert this interval into the specified one.
Definition: intervals.h:389
icarus::ns::util::FixedBins< double > BinnedContent_t
Content for future histograms, binned.
icarus::trigger::PlotSandbox fPlots
All plots in one practical sandbox.
double upper() const
Returns the value of the upper end of the last bin.
Definition: BinningSpecs.h:190
SandboxType & addSubSandbox(std::string const &name, std::string const &desc, Args &&...args)
Creates a new sandbox contained in this one.
Definition: PlotSandbox.h:723
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295
temporary value
unsigned long nBins() const
Returns the number of bins.
Definition: BinningSpecs.h:196
nanoseconds fTriggerTimeResolution
Trigger resolution in time.
detinfo::DetectorTimings makeDetTimings(art::Event const *event)
Returns a detinfo::DetectorTimings from DetectorClocksService.
A helper to manage ROOT objects with consistent naming.
Definition: PlotSandbox.h:95
void icarus::trigger::TriggerSimulationOnGates::makeEventPlots ( )
private

Creates in the main sandbox all event-wide plots.

Definition at line 1000 of file TriggerSimulationOnGates_module.cc.

1000  {
1001 
1002 #if 0
1003 
1004  BinnedContent_t const* content;
1005 
1006  content = &(fEventPlotInfo.eventTimes);
1008  "EventTime",
1009  "Time of the events"
1010  ";time"
1011  ";events [ / " + std::to_string(content->binWidth())
1012  + "\" ]",
1013  *content
1014  );
1015 
1016  content = &(fEventPlotInfo.HWtrigTimeVsBeam);
1018  "HWTrigVsBeam",
1019  "Time of the hardware trigger"
1020  ";trigger time (relative to beam gate) [ #mus ]"
1021  ";events [ / " + std::to_string(content->binWidth())
1022  + " #mus ]",
1023  *content
1024  );
1025 
1026 #endif // 0
1027 
1028 } // icarus::trigger::TriggerSimulationOnGates::makeEventPlots()
TH1 * makeHistogramFromBinnedContent(icarus::trigger::PlotSandbox &plots, std::string const &name, std::string const &title, BinnedContent_t const &binnedContent) const
Creates and returns a 1D histogram filled with binnedContent.
icarus::ns::util::FixedBins< double > BinnedContent_t
Content for future histograms, binned.
icarus::trigger::PlotSandbox fPlots
All plots in one practical sandbox.
std::string to_string(WindowPattern const &pattern)
ThresholdPlotInfo_t fEventPlotInfo
Proto-histogram information in a convenient packet; event-wide.
TH1 * icarus::trigger::TriggerSimulationOnGates::makeHistogramFromBinnedContent ( icarus::trigger::PlotSandbox plots,
std::string const &  name,
std::string const &  title,
BinnedContent_t const &  binnedContent 
) const
private

Creates and returns a 1D histogram filled with binnedContent.

Definition at line 1223 of file TriggerSimulationOnGates_module.cc.

1227  {
1228 
1229  if (binnedContent.empty()) return nullptr;
1230 
1231  TH1* hist = plots.make<TH1F>(
1232  name, title,
1233  binnedContent.nBins(), binnedContent.min(), binnedContent.max()
1234  );
1235 
1236  // directly transfer the content bin by bin
1237  unsigned int total = 0U;
1238  for (auto [ iBin, count ]: util::enumerate(binnedContent)) {
1239  hist->SetBinContent(iBin + 1, count);
1240  total += count;
1241  }
1242  hist->SetEntries(static_cast<double>(total));
1243  return hist;
1244 } // icarus::trigger::TriggerSimulationOnGates::makeHistogramFromBinnedContent
Obj * make(std::string const &name, std::string const &title, Args &&...args)
Creates a new ROOT object with the specified name and title.
Definition: PlotSandbox.h:701
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
then echo fcl name
std::size_t count(Cont const &cont)
icarus::trigger::ApplyBeamGateClass icarus::trigger::TriggerSimulationOnGates::makeMyBeamGate ( detinfo::DetectorTimings const &  detTimings,
sim::BeamGateInfo const &  gate 
) const
inlineprivate

Shortcut to create an ApplyBeamGate with the specified gate.

Definition at line 559 of file TriggerSimulationOnGates_module.cc.

560  {
561  // the input gate is assumed to be relative to the global beam gate
562  // opening (which is the implicit convention of simulation time and of
563  // sim::BeamGateInfo in my understanding - [petrillo@slac.stanford.edu])
564  // so it does not need further processing here
565  return makeApplyBeamGate(
566  nanoseconds{ gate.Width() }, nanoseconds{ gate.Start() },
567  detTimings.clockData(), fLogCategory
568  );
569  }
ApplyBeamGateClass makeApplyBeamGate(util::quantities::intervals::microseconds duration, util::quantities::intervals::microseconds delay, detinfo::DetectorClocksData const &clockData, std::string const &logCategory="ApplyBeamGateClass")
Returns a new ApplyBeamGateClass object with the specified gate.
std::string const fLogCategory
Message facility stream category for output.
fDetProps &fDetProps fDetProps &fDetProps detTimings
util::quantities::intervals::nanoseconds nanoseconds
std::vector<icarus::trigger::ApplyBeamGateClass> icarus::trigger::TriggerSimulationOnGates::makeMyBeamGates ( detinfo::DetectorTimings const &  detTimings,
BeamGates_t const &  gates 
) const
inlineprivate

Shortcut to create ApplyBeamGate from a list of gates.

Definition at line 574 of file TriggerSimulationOnGates_module.cc.

575  {
576  std::vector<icarus::trigger::ApplyBeamGateClass> applyGates;
577  for (sim::BeamGateInfo const& gate: gates)
578  applyGates.push_back(makeMyBeamGate(detTimings, gate));
579  return applyGates;
580  }
icarus::trigger::ApplyBeamGateClass makeMyBeamGate(detinfo::DetectorTimings const &detTimings, sim::BeamGateInfo const &gate) const
Shortcut to create an ApplyBeamGate with the specified gate.
fDetProps &fDetProps fDetProps &fDetProps detTimings
std::vector<icarus::trigger::ApplyBeamGateClass> icarus::trigger::TriggerSimulationOnGates::makeMyBeamGates ( art::Event const *  event,
BeamGates_t const &  gates 
) const
inlineprivate

Definition at line 582 of file TriggerSimulationOnGates_module.cc.

583  { return makeMyBeamGates(icarus::ns::util::makeDetTimings(event), gates); }
std::vector< icarus::trigger::ApplyBeamGateClass > makeMyBeamGates(detinfo::DetectorTimings const &detTimings, BeamGates_t const &gates) const
Shortcut to create ApplyBeamGate from a list of gates.
detinfo::DetectorTimings makeDetTimings(art::Event const *event)
Returns a detinfo::DetectorTimings from DetectorClocksService.
std::vector<icarus::trigger::ApplyBeamGateClass> icarus::trigger::TriggerSimulationOnGates::makeMyBeamGates ( art::Event const &  event,
BeamGates_t const &  gates 
) const
inlineprivate

Definition at line 585 of file TriggerSimulationOnGates_module.cc.

586  { return makeMyBeamGates(&event, gates); }
std::vector< icarus::trigger::ApplyBeamGateClass > makeMyBeamGates(detinfo::DetectorTimings const &detTimings, BeamGates_t const &gates) const
Shortcut to create ApplyBeamGate from a list of gates.
void icarus::trigger::TriggerSimulationOnGates::makeThresholdPlots ( std::string const &  threshold,
icarus::trigger::PlotSandbox plots,
ThresholdPlotInfo_t const &  plotInfo 
)
private

Creates in plots sandbox all plots for threshold threshold from data in plotInfo.

Definition at line 943 of file TriggerSimulationOnGates_module.cc.

947  {
948 
949 #if 0
950 
951  BinnedContent_t const* content;
952 
953  content = &(plotInfo.eventTimes);
955  "TriggerTime",
956  "Time of the triggered events"
957  ";time"
958  ";triggered events [ / " + std::to_string(content->binWidth())
959  + "\" ]",
960  *content
961  );
962 
963  content = &(plotInfo.HWtrigTimeVsBeam);
965  "HWTrigVsBeam",
966  "Time of the hardware trigger"
967  ";trigger time (relative to beam gate) [ #mus ]"
968  ";events [ / " + std::to_string(content->binWidth())
969  + " #mus ]",
970  *content
971  );
972 
973  content = &(plotInfo.triggerTimesVsHWtrig);
975  "TriggerTimeVsHWTrig",
976  "Time of the trigger"
977  ";trigger time (relative to hardware trigger) [ #mus ]"
978  ";triggers [ / " + std::to_string(content->binWidth())
979  + " #mus ]",
980  *content
981  );
982 
983  content = &(plotInfo.triggerTimesVsBeam);
985  "TriggerTimeVsBeamGate",
986  "Time of the trigger"
987  ";trigger time (relative to beam gate opening) [ #mus ]"
988  ";triggers [ / " + std::to_string(content->binWidth())
989  + " #mus ]",
990  *content
991  );
992 
993 #endif // 0
994 
995 } // icarus::trigger::TriggerSimulationOnGates::makeThresholdPlots()
TH1 * makeHistogramFromBinnedContent(icarus::trigger::PlotSandbox &plots, std::string const &name, std::string const &title, BinnedContent_t const &binnedContent) const
Creates and returns a 1D histogram filled with binnedContent.
icarus::ns::util::FixedBins< double > BinnedContent_t
Content for future histograms, binned.
std::string to_string(WindowPattern const &pattern)
void icarus::trigger::TriggerSimulationOnGates::plotEvent ( art::Event const &  event,
detinfo::DetectorTimings const &  detTimings,
std::vector< icarus::trigger::ApplyBeamGateClass > const &  gates 
)
private

Fills event-wide plots.

Definition at line 1094 of file TriggerSimulationOnGates_module.cc.

1097  {
1098 
1099 #if 0
1100 
1101  detinfo::timescales::trigger_time const beamGateTime
1102  { detTimings.toTriggerTime(detTimings.BeamGateTime()) };
1103 
1105  fEventPlotInfo.HWtrigTimeVsBeam.add(-beamGateTime.value());
1106 
1107  // `gates` is currently unused; it may be used e.g. to show how many gates
1108  // were tested in each event
1109 
1110 #endif // 0
1111 
1112 } // icarus::trigger::TriggerSimulationOnGates::plotEvent()
BinIndex_t add(Data_t value)
Increases by a unit the count at the bin including value.
Definition: FixedBins.h:338
timescale_traits< TriggerTimeCategory >::time_point_t trigger_time
A point in time on the trigger time scale.
ThresholdPlotInfo_t fEventPlotInfo
Proto-histogram information in a convenient packet; event-wide.
static double eventTimestampInSeconds(art::Timestamp const &time)
Returns the time of the event in seconds from The Epoch.
fDetProps &fDetProps fDetProps &fDetProps detTimings
void icarus::trigger::TriggerSimulationOnGates::plotTriggerResponse ( std::size_t  iThr,
std::string const &  thrTag,
WindowTriggerInfo_t const &  triggerInfo,
detinfo::DetectorTimings const &  detTimings 
)
private

Fills the plots for threshold index iThr with trigger information.

Definition at line 1116 of file TriggerSimulationOnGates_module.cc.

1120  {
1121 
1122 #if 0
1123 
1124  bool const fired = triggerInfo.info.fired();
1125 
1126  fPlots.demand<TEfficiency>("Eff").Fill(fired, iThr);
1127 
1128  if (fired) {
1129  using namespace detinfo::timescales;
1130 
1131  // time of the beam gate in hardware trigger time scale
1132  trigger_time const beamGateTime
1133  { detTimings.toTriggerTime(detTimings.BeamGateTime()) };
1134 
1135  optical_tick const thisTriggerTick { triggerInfo.info.atTick() };
1136  trigger_time const thisTriggerTimeVsHWtrig
1137  { detTimings.toTriggerTime(thisTriggerTick) };
1138  time_interval const thisTriggerTimeVsBeamGate
1139  { thisTriggerTimeVsHWtrig - beamGateTime };
1140 
1141  mf::LogTrace(fLogCategory)
1142  << "Trigger " << fPattern.tag() << " at tick " << thisTriggerTick
1143  << " (" << thisTriggerTimeVsHWtrig << " vs. HW trigger, "
1144  << thisTriggerTimeVsBeamGate << " vs. beam gate)"
1145  ;
1146 
1147  fPlots.demand<TH1>("NTriggers").Fill(iThr);
1148  fPlots.demand<TH2>("TriggerTick").Fill(thisTriggerTick.value(), iThr);
1149  fPlots.demand<TH2>("TriggerTimeVsHWTrig").Fill
1150  (thisTriggerTimeVsHWtrig.value(), iThr);
1151  fPlots.demand<TH2>("TriggerTimeVsBeamGate").Fill
1152  (thisTriggerTimeVsBeamGate.value(), iThr);
1153 
1155 // plots.demand<TGraph>("TriggerTimeVsHWTrigVsBeam").AddPoint( // ROOT 6.24?
1156  TGraph& graph = plots.demand<TGraph>("TriggerTimeVsHWTrigVsBeam");
1157  graph.SetPoint(graph.GetN(),
1158  -beamGateTime.value(), thisTriggerTimeVsBeamGate.value()
1159  );
1160 
1161  ThresholdPlotInfo_t& plotInfo { fThresholdPlots[iThr] };
1162  plotInfo.HWtrigTimeVsBeam.add(-beamGateTime.value());
1163  plotInfo.triggerTimesVsHWtrig.add(thisTriggerTimeVsHWtrig.value());
1164  plotInfo.triggerTimesVsBeam.add(thisTriggerTimeVsBeamGate.value());
1165 
1166  }
1167 
1168 #endif // 0
1169 
1170 } // icarus::trigger::TriggerSimulationOnGates::plotTriggerResponse()
std::string const fLogCategory
Message facility stream category for output.
std::vector< ThresholdPlotInfo_t > fThresholdPlots
Proto-histogram information in a not-so-practical array; per threshold.
timescale_traits< TriggerTimeCategory >::time_point_t trigger_time
A point in time on the trigger time scale.
std::vector< PlotDef > plots
Definition: demo.h:54
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
WindowPattern const fPattern
Configured sliding window requirement pattern.
icarus::trigger::PlotSandbox fPlots
All plots in one practical sandbox.
timescale_traits< OpticalTimeCategory >::tick_t optical_tick
std::string tag() const
Returns a tag summarizing the pattern.
static auto & demandSandbox(SandboxType &sandbox, std::string const &name)
Helper function for demandSandbox() implementations.
Definition: PlotSandbox.h:750
Obj & demand(std::string const &name) const
Fetches an object with the specified name to be modified.
Definition: PlotSandbox.h:667
fDetProps &fDetProps fDetProps &fDetProps detTimings
A helper to manage ROOT objects with consistent naming.
Definition: PlotSandbox.h:95
void icarus::trigger::TriggerSimulationOnGates::printSummary ( ) const
private

Prints the summary of fired triggers on screen.

Definition at line 1174 of file TriggerSimulationOnGates_module.cc.

1174  {
1175 
1176  //
1177  // summary from our internal counters
1178  //
1179  mf::LogInfo log(fLogCategory);
1180  log
1181  << "Summary of triggers for " << fTriggerCount.size()
1182  << " thresholds (ADC) with pattern: " << fPattern.description()
1183  ;
1184  for (auto const& [ count, thr ]
1185  : util::zip(fTriggerCount, util::get_elements<0U>(fADCthresholds)))
1186  {
1187  log << "\n threshold " << thr
1188  << ": " << count;
1189  if (fTotalGates > 0U) {
1190  log << "/" << fTotalGates
1191  << " (" << (double(count) / fTotalGates * 100.0) << "%)";
1192  }
1193  else log << " gates triggered";
1194  } // for
1195 
1196 } // icarus::trigger::TriggerSimulationOnGates::printSummary()
std::atomic< unsigned int > fTotalGates
Count of opened gates.
std::map< std::string, art::InputTag > fADCthresholds
Name of ADC thresholds to read, and the input tag connected to their data.
std::string const fLogCategory
Message facility stream category for output.
WindowPattern const fPattern
Configured sliding window requirement pattern.
std::vector< std::atomic< unsigned int > > fTriggerCount
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295
std::size_t count(Cont const &cont)
std::string description() const
Returns a description of the pattern.
void icarus::trigger::TriggerSimulationOnGates::produce ( art::Event &  event)
overridevirtual

Runs the simulation and saves the results into the art event.

Definition at line 702 of file TriggerSimulationOnGates_module.cc.

703 {
704 
705  //
706  // prepare all the gates to run the simulation on
707  //
709  art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event)
710  };
711 
712  std::vector<icarus::trigger::ApplyBeamGateClass> const beamGates {
714  detTimings,
715  event.getProduct<std::vector<sim::BeamGateInfo>>(fBeamGateTag)
716  )
717  };
718 
719 
720  { // BEGIN local block
721  mf::LogDebug log { fLogCategory };
722  log << "Trigger simulation for " << beamGates.size() << " gates";
723  if (!beamGates.empty()) {
724  log << " ('" << fBeamGateTag.encode() << "'):";
725  for (auto const& [iGate, gate]: util::enumerate(beamGates)) {
726  log << "\n [" << iGate << "] " << gate;
727  } // for
728  } // if
729  } // END local block
730 
731 
732  //
733  // run the simulation on each threshold in turn
734  //
735  mf::LogDebug log(fLogCategory); // this will print at the end of produce()
736  log << "Event " << event.id() << ":";
737 
738  // FIXME these two operations should be atomic
739  unsigned int const firstTriggerNumber
740  = fTotalGates.fetch_add(beamGates.size());
741 
742  for (auto const& [ iThr, thrTag ]
743  : util::enumerate(util::get_elements<0U>(fADCthresholds))
744  ) {
745 
746  std::vector<WindowTriggerInfo_t> const triggers = produceForThreshold
747  (event, detTimings, beamGates, iThr, thrTag, firstTriggerNumber);
748 
749  log << "\n * threshold " << thrTag << ": ";
750  icarus::ns::util::PassCounter gateResults;
751  for (WindowTriggerInfo_t const& triggerInfo: triggers)
752  gateResults.add(triggerInfo.info.fired());
753  log << gateResults.passed() << "/" << gateResults.total()
754  << " gates triggered";
755 
756  } // for
757 
758  //
759  // event-level plots
760  //
761  plotEvent(event, detTimings, beamGates);
762 
763 } // icarus::trigger::TriggerSimulationOnGates::produce()
std::atomic< unsigned int > fTotalGates
Count of opened gates.
std::map< std::string, art::InputTag > fADCthresholds
Name of ADC thresholds to read, and the input tag connected to their data.
art::InputTag const fBeamGateTag
Data product of beam gates to simulate.
icarus::trigger::SlidingWindowPatternAlg::AllTriggerInfo_t WindowTriggerInfo_t
Data structure to communicate internally a trigger response.
void plotEvent(art::Event const &event, detinfo::DetectorTimings const &detTimings, std::vector< icarus::trigger::ApplyBeamGateClass > const &gates)
Fills event-wide plots.
Count_t total() const
Returns the total number of registered events.
Definition: PassCounter.h:60
std::string const fLogCategory
Message facility stream category for output.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
void add(bool pass)
Adds a single event, specifying whether it &quot;passes&quot; or not.
Definition: PassCounter.h:112
std::vector< icarus::trigger::ApplyBeamGateClass > makeMyBeamGates(detinfo::DetectorTimings const &detTimings, BeamGates_t const &gates) const
Shortcut to create ApplyBeamGate from a list of gates.
std::vector< WindowTriggerInfo_t > produceForThreshold(art::Event &event, detinfo::DetectorTimings const &detTimings, std::vector< ApplyBeamGateClass > const &beamGates, std::size_t const iThr, std::string const &thrTag, unsigned int firstTriggerNumber)
Performs the simulation for the specified ADC threshold.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
fDetProps &fDetProps fDetProps &fDetProps detTimings
Count_t passed() const
Returns the number of events which &quot;passed&quot;.
Definition: PassCounter.h:54
Class counting pass/fail events.
Definition: PassCounter.h:15
auto icarus::trigger::TriggerSimulationOnGates::produceForThreshold ( art::Event &  event,
detinfo::DetectorTimings const &  detTimings,
std::vector< ApplyBeamGateClass > const &  beamGates,
std::size_t const  iThr,
std::string const &  thrTag,
unsigned int  firstTriggerNumber 
)
private

Performs the simulation for the specified ADC threshold.

Parameters
eventart event to read data from and put results into
detTimingsdetector clocks service provider proxy
beamGateslist of all beam gates to evaluate
iThrindex of the threshold in the configuration
thrvalue of the threshold (ADC counts)
firstTriggerNumberthe next unassigned trigger number
Returns
the trigger response information

For the given threshold, the simulation of the configured trigger is performed. The input data is read from the event (the source tag is from the module configuration), simulation is performed, auxiliary plots are drawn and a raw::Trigger collection is stored into the event.

The stored collection contains either one or zero raw::Trigger elements.

The simulation itself is performed by the simulate() method.

Definition at line 1032 of file TriggerSimulationOnGates_module.cc.

1038  {
1039 
1040 // auto& plotInfo = fThresholdPlots[iThr];
1041 
1042  //
1043  // get the input
1044  //
1045  art::InputTag const& dataTag = fADCthresholds.at(thrTag);
1046  auto const& gates = icarus::trigger::ReadTriggerGates(event, dataTag);
1047 
1048 
1049  // extract or verify the topology of the trigger windows
1050  if (fWindowMapMan(gates))
1052  assert(fPatternAlg);
1053 
1054  //
1055  // simulate the trigger response on all beam gates
1056  //
1057  std::vector<WindowTriggerInfo_t> allTriggerInfo; // one per gate
1058  auto triggers = std::make_unique<std::vector<raw::Trigger>>();
1059  unsigned int triggerNumber = firstTriggerNumber;
1060  for (auto const& beamGate: beamGates) {
1061  WindowTriggerInfo_t const triggerInfo
1062  = fPatternAlg->simulateResponse(beamGate.applyToAll(gates));
1063 
1064  // FIXME what do we do with statistics and plots?
1065  if (triggerInfo) {
1066  ++fTriggerCount[iThr]; // keep the unique count
1067 // plotInfo.eventTimes.add(eventTimestampInSeconds(event));
1068  }
1069 
1070  //
1071  // fill the plots
1072  //
1073  plotTriggerResponse(iThr, thrTag, triggerInfo, detTimings);
1074 
1075  //
1076  // create and store the data product
1077  //
1078  triggers->push_back(
1080  (detTimings, beamGate, triggerNumber++, triggerInfo)
1081  );
1082  allTriggerInfo.push_back(std::move(triggerInfo));
1083 
1084  } // for beam gates
1085 
1086  event.put(std::move(triggers), fOutputInstances[iThr]);
1087 
1088  return allTriggerInfo;
1089 
1090 } // icarus::trigger::TriggerSimulationOnGates::produceForThreshold()
std::map< std::string, art::InputTag > fADCthresholds
Name of ADC thresholds to read, and the input tag connected to their data.
icarus::trigger::SlidingWindowPatternAlg::AllTriggerInfo_t WindowTriggerInfo_t
Data structure to communicate internally a trigger response.
raw::Trigger triggerInfoToTriggerData(detinfo::DetectorTimings const &detTimings, ApplyBeamGateClass const &beamGate, unsigned int triggerNumber, WindowTriggerInfo_t const &info) const
Converts the trigger information into a raw::Trigger object.
std::optional< icarus::trigger::SlidingWindowPatternAlg > fPatternAlg
Pattern algorithm.
void plotTriggerResponse(std::size_t iThr, std::string const &thrTag, WindowTriggerInfo_t const &triggerInfo, detinfo::DetectorTimings const &detTimings)
Fills the plots for threshold index iThr with trigger information.
std::string const fLogCategory
Message facility stream category for output.
std::vector< std::string > fOutputInstances
Output data product instance names (same order as fADCthresholds).
icarus::trigger::WindowTopologyManager fWindowMapMan
Mapping of each sliding window with location and topological information.
WindowPattern const fPattern
Configured sliding window requirement pattern.
std::vector< std::atomic< unsigned int > > fTriggerCount
fDetProps &fDetProps fDetProps &fDetProps detTimings
std::vector< icarus::trigger::TrackedOpticalTriggerGate< OpDetInfo > > ReadTriggerGates(Event const &event, art::InputTag const &dataTag)
Assembles and returns trigger gates from serialized data.
raw::Trigger icarus::trigger::TriggerSimulationOnGates::triggerInfoToTriggerData ( detinfo::DetectorTimings const &  detTimings,
ApplyBeamGateClass const &  beamGate,
unsigned int  triggerNumber,
WindowTriggerInfo_t const &  info 
) const
private

Converts the trigger information into a raw::Trigger object.

Parameters
triggerNumberthe unique number to assign to this trigger
infothe information about the fired trigger
Returns
a raw::Trigger object with all the information encoded

The trigger described by info is encoded into a raw::Trigger object. The trigger must have fired.

Definition at line 1201 of file TriggerSimulationOnGates_module.cc.

1205  {
1206 
1207  return {
1208  triggerNumber, // counter
1209  info.info.fired() // trigger time
1210  ? double(detTimings.toElectronicsTime(info.info.atTick()))
1211  : std::numeric_limits<double>::lowest()
1212  ,
1213  double(detTimings.toElectronicsTime(beamGate.tickRange().start())),
1214  // beam gate in electronics time scale
1215  (info.info.fired()? fBeamBits: 0) // bits
1216  };
1217 
1218 } // icarus::trigger::TriggerSimulationOnGates::triggerInfoToTriggerData()
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
std::uint32_t fBeamBits
Bits for the beam gate being simulated.
fDetProps &fDetProps fDetProps &fDetProps detTimings

Member Data Documentation

std::map<std::string, art::InputTag> icarus::trigger::TriggerSimulationOnGates::fADCthresholds
private

Name of ADC thresholds to read, and the input tag connected to their data.

Definition at line 413 of file TriggerSimulationOnGates_module.cc.

std::uint32_t icarus::trigger::TriggerSimulationOnGates::fBeamBits
private

Bits for the beam gate being simulated.

Definition at line 420 of file TriggerSimulationOnGates_module.cc.

art::InputTag const icarus::trigger::TriggerSimulationOnGates::fBeamGateTag
private

Data product of beam gates to simulate.

Definition at line 418 of file TriggerSimulationOnGates_module.cc.

ThresholdPlotInfo_t icarus::trigger::TriggerSimulationOnGates::fEventPlotInfo
private

Proto-histogram information in a convenient packet; event-wide.

Definition at line 456 of file TriggerSimulationOnGates_module.cc.

double icarus::trigger::TriggerSimulationOnGates::fEventTimeBinning
private

Trigger time plot binning [s].

Definition at line 424 of file TriggerSimulationOnGates_module.cc.

std::string const icarus::trigger::TriggerSimulationOnGates::fLogCategory
private

Message facility stream category for output.

Definition at line 427 of file TriggerSimulationOnGates_module.cc.

art::TFileDirectory icarus::trigger::TriggerSimulationOnGates::fOutputDir
private

ROOT directory where all the plots are written.

Definition at line 435 of file TriggerSimulationOnGates_module.cc.

std::vector<std::string> icarus::trigger::TriggerSimulationOnGates::fOutputInstances
private

Output data product instance names (same order as fADCthresholds).

Definition at line 443 of file TriggerSimulationOnGates_module.cc.

WindowPattern const icarus::trigger::TriggerSimulationOnGates::fPattern
private

Configured sliding window requirement pattern.

Definition at line 416 of file TriggerSimulationOnGates_module.cc.

std::optional<icarus::trigger::SlidingWindowPatternAlg> icarus::trigger::TriggerSimulationOnGates::fPatternAlg
private

Pattern algorithm.

Definition at line 450 of file TriggerSimulationOnGates_module.cc.

icarus::trigger::PlotSandbox icarus::trigger::TriggerSimulationOnGates::fPlots
private

All plots in one practical sandbox.

Definition at line 453 of file TriggerSimulationOnGates_module.cc.

std::vector<ThresholdPlotInfo_t> icarus::trigger::TriggerSimulationOnGates::fThresholdPlots
private

Proto-histogram information in a not-so-practical array; per threshold.

Count of fired triggers, per threshold.

Definition at line 459 of file TriggerSimulationOnGates_module.cc.

std::atomic<unsigned int> icarus::trigger::TriggerSimulationOnGates::fTotalGates { 0U }
private

Count of opened gates.

Definition at line 463 of file TriggerSimulationOnGates_module.cc.

std::vector<std::atomic<unsigned int> > icarus::trigger::TriggerSimulationOnGates::fTriggerCount
private

Definition at line 462 of file TriggerSimulationOnGates_module.cc.

nanoseconds icarus::trigger::TriggerSimulationOnGates::fTriggerTimeResolution
private

Trigger resolution in time.

Definition at line 422 of file TriggerSimulationOnGates_module.cc.

icarus::trigger::WindowTopologyManager icarus::trigger::TriggerSimulationOnGates::fWindowMapMan
mutableprivate

Mapping of each sliding window with location and topological information.

Definition at line 447 of file TriggerSimulationOnGates_module.cc.


The documentation for this class was generated from the following file: