8 #ifndef ICARUSCODE_PMT_TRIGGER_TRIGGEREFFICIENCYPLOTSBASE_H
9 #define ICARUSCODE_PMT_TRIGGER_TRIGGEREFFICIENCYPLOTSBASE_H
44 #include "art_root_io/TFileDirectory.h"
45 #include "art/Framework/Core/ConsumesCollector.h"
46 #include "art/Framework/Principal/Event.h"
47 #include "canvas/Persistency/Provenance/EventID.h"
48 #include "canvas/Utilities/InputTag.h"
49 #include "fhiclcpp/types/Sequence.h"
50 #include "fhiclcpp/types/Atom.h"
51 #include "fhiclcpp/types/OptionalAtom.h"
57 #include "TEfficiency.h"
63 #include <unordered_map>
77 namespace icarus::trigger {
79 using namespace util::quantities::time_literals;
81 class TriggerEfficiencyPlotsBase;
87 namespace icarus::trigger::details {
91 class TriggerPassCounters;
92 std::ostream&
operator<<
93 (std::ostream& out, TriggerPassCounters
const& counters);
111 static constexpr std::size_t NoIndex
112 = std::numeric_limits<std::size_t>::max();
121 (
Threshold_t const& threshold, std::string
const& patternName);
129 (
Threshold_t const& threshold, std::string
const& patternName)
const;
131 (std::size_t threshold, std::string
const& patternName)
const;
133 (
Threshold_t const& threshold, std::size_t patternName)
const;
135 (std::size_t threshold, std::size_t patternName)
const;
139 (
Threshold_t const& threshold, std::string
const& patternName)
const
140 {
return counter(threshold, patternName); }
141 Counter_t
const& operator()
142 (std::size_t threshold, std::string
const& patternName)
const
143 {
return counter(threshold, patternName); }
144 Counter_t
const& operator()
146 {
return counter(threshold, patternName); }
147 Counter_t
const& operator()
148 (std::size_t threshold, std::size_t patternName)
const
149 {
return counter(threshold, patternName); }
154 (Threshold_t
const& threshold, std::string
const& patternName);
155 Counter_t&
counter(std::size_t threshold, std::string
const& patternName);
156 Counter_t&
counter(Threshold_t
const& threshold, std::size_t patternName);
157 Counter_t&
counter(std::size_t threshold, std::size_t patternName);
160 Counter_t& operator()
162 {
return counter(threshold, patternName); }
163 Counter_t& operator() (std::size_t threshold, std::string
const& patternName)
164 {
return counter(threshold, patternName); }
166 {
return counter(threshold, patternName); }
167 Counter_t& operator() (std::size_t threshold, std::size_t patternName)
168 {
return counter(threshold, patternName); }
175 bool hasThreshold(Threshold_t
const& threshold)
const;
176 bool hasThreshold(std::size_t index)
const;
181 bool hasPattern(std::string
const& patternName)
const;
182 bool hasPattern(std::size_t patternIndex)
const;
186 std::size_t thresholdIndex(Threshold_t
const& threshold)
const;
189 std::size_t patternIndex(std::string
const& patternName)
const;
193 Threshold_t
const& threshold(std::size_t index)
const;
197 std::string
const& patternName(std::size_t index)
const;
200 std::size_t nThresholds()
const;
203 std::size_t nPatterns()
const;
206 void dump(std::ostream& out)
const;
220 std::size_t registerThreshold(
Threshold_t const& threshold);
223 std::size_t registerPattern(std::string
const&
name);
258 void assign(
bool inPlots);
989 fhicl::Sequence<art::InputTag> GeneratorTags {
990 Name(
"GeneratorTags"),
991 Comment(
"labels of the event generators"),
992 std::vector<art::InputTag>{
"generator" }
995 fhicl::Atom<art::InputTag> DetectorParticleTag {
996 Name(
"DetectorParticleTag"),
997 Comment(
"label of simulated particles through the detector"),
1001 fhicl::Sequence<art::InputTag> EnergyDepositTags {
1002 Name(
"EnergyDeposits"),
1003 Comment(
"label of energy deposition data product(s) in the detector"),
1004 std::vector<art::InputTag>{
"largeant:TPCActive" }
1007 fhicl::OptionalAtom<art::InputTag> EnergyDepositSummaryTag {
1008 Name(
"EnergyDepositSummaryTag"),
1009 Comment(
"label of energy deposition summary data product")
1012 fhicl::Atom<std::string> TriggerGatesTag {
1013 Name(
"TriggerGatesTag"),
1014 Comment(
"label of the input trigger gate data product (no instance name)")
1019 Comment(
"thresholds to consider (as tags)")
1022 fhicl::Atom<microseconds> BeamGateDuration {
1023 Name(
"BeamGateDuration"),
1024 Comment(
"length of time interval when optical triggers are accepted")
1027 fhicl::Atom<microseconds> BeamGateStart {
1028 Name(
"BeamGateStart"),
1029 Comment(
"open the beam gate this long after the nominal beam gate time"),
1033 fhicl::Atom<microseconds> PreSpillWindow {
1034 Name(
"PreSpillWindow"),
1035 Comment(
"duration of the pre-spill window"),
1039 fhicl::Atom<microseconds> PreSpillWindowGap {
1040 Name(
"PreSpillWindowGap"),
1041 Comment(
"gap from the end of pre-spill window to the start of beam gate"),
1045 fhicl::Atom<nanoseconds> TriggerTimeResolution {
1046 Name(
"TriggerTimeResolution"),
1047 Comment(
"resolution of trigger in time"),
1051 fhicl::Atom<bool> PlotOnlyActiveVolume {
1052 Name(
"PlotOnlyActiveVolume"),
1054 (
"only events within TPC active volume are plot (if that makes sense)"),
1058 fhicl::Sequence<std::string> OnlyPlotCategories {
1059 Name(
"OnlyPlotCategories"),
1061 (
"if specified, plot categories not in this list are not considered"),
1062 std::vector<std::string>{}
1065 fhicl::OptionalAtom<std::string> EventTreeName {
1066 Name(
"EventTreeName"),
1067 Comment(
"name of a ROOT tree where to store event-by-event information")
1070 fhicl::OptionalAtom<std::string> EventDetailsLogCategory {
1071 Name(
"EventDetailsLogCategory"),
1072 Comment(
"name of the category used for event information output")
1075 fhicl::Atom<std::string> LogCategory {
1076 Name(
"LogCategory"),
1077 Comment(
"name of the category used for the output"),
1078 "SlidingWindowTrigger"
1095 (
Config const& config, art::ConsumesCollector& consumer);
1103 void process(art::Event
const& event);
1106 void printSummary()
const;
1120 TTree*
eventTree() {
return fIDTree? &(fIDTree->tree()):
nullptr; }
1123 bool useGen()
const {
return fEventInfoExtractorMaker.hasGenerated(); }
1126 bool useEDep()
const {
return fEventInfoExtractorMaker.hasEDep(); }
1138 {
return next(fADCthresholds.begin(), iThr)->
first; }
1153 = std::vector<std::reference_wrapper<PlotSandbox const>>;
1167 std::string
name, std::string descr = {},
1170 : fName(std::move(name)), fDescr(std::move(descr)), fTest(std::move(
test))
1174 std::string
const&
name()
const {
return fName; }
1182 operator std::string()
const {
return name(); }
1207 TEfficiency&
Eff(std::string
const& name)
const
1208 {
return plots.demand<TEfficiency>(
name); }
1223 : index(index), tag(tag), description(descr) {}
1228 using InputTriggerGate_t
1251 virtual void initializePlots
1252 (
PlotCategories_t categories, std::vector<SettingsInfo_t>
const& settings);
1256 { initializePlots(DefaultPlotCategories, settings); }
1259 virtual void initializePlotSet
1263 virtual void initializeEfficiencyPerTriggerPlots(
PlotSandbox&
plots)
const;
1274 virtual bool shouldPlotEvent(
EventInfo_t const& eventInfo)
const;
1339 virtual void simulateAndPlot(
1340 std::size_t
const thresholdIndex,
1341 TriggerGatesPerCryostat_t
const& gates,
1344 PlotSandboxRefs_t
const& selectedPlots
1349 virtual void fillEventPlots
1353 virtual void fillPMTplots
1358 virtual void fillEfficiencyPlots(
1360 TriggerInfo_t
const& triggerInfo,
1366 virtual void fillAllEfficiencyPlots(
1368 PMTInfo_t
const& PMTinfo,
1369 TriggerInfo_t
const& triggerInfo,
1379 void deleteEmptyPlots();
1386 std::size_t createCountersForPattern(std::string
const& patternName);
1391 void registerTriggerResult
1392 (std::size_t threshold, std::size_t
pattern,
bool fired);
1393 void registerTriggerResult(
1394 std::size_t threshold, std::size_t
pattern,
1395 TriggerInfo_t
const& triggerInfo
1410 GatePack_t makeGatePack(art::Event
const* event =
nullptr)
const;
1418 (fBeamGateDuration, fBeamGateStart, clockData,
fLogCategory);
1421 (art::Event
const* event =
nullptr)
const
1424 (art::Event
const& event)
const {
return makeMyBeamGate(&event); }
1441 static std::vector<ChannelID_t> extractActiveChannels
1512 std::atomic<unsigned int> nEvents { 0U };
1513 std::atomic<unsigned int> nPlottedEvents { 0U };
1525 std::vector<std::string> selectPlotCategories
1538 (art::Event
const& event, art::InputTag
const& dataTag)
const;
1549 static std::vector<geo::CryostatID> makeChannelCryostatMap
1552 static std::string thrAndCatName
1553 (std::string
const& boxName, std::string
const& category)
1554 {
return boxName +
"_" + category; }
1555 static std::string thrAndCatName
1557 {
return thrAndCatName(box.
name(), category); }
1561 fhicl::Sequence<art::InputTag>
const& EnergyDepositTags,
1562 fhicl::OptionalAtom<art::InputTag>
const& EnergyDepositSummaryTag
1571 #endif // ICARUSCODE_PMT_TRIGGER_TRIGGEREFFICIENCYPLOTSBASE_H
BEGIN_PROLOG BeamGateDuration pmtthr physics producers trigtilewindowORS Thresholds
HistGetter(PlotSandbox const &plots)
std::pair< std::size_t, std::size_t > IndexPair_t
Class managing the serialization of plot information in a simple ROOT tree.
std::string const & ADCthresholdTag(std::size_t iThr) const
Helper class to produce plots about trigger simulation and trigger efficiency.
microseconds fPreSpillWindow
Duration of the pre-spill gate.
std::string fLogEventDetails
Steam where to print event info.
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.
An object representing a time gate, with a start and and end.
Tracks pass rate by discrimination threshold and trigger pattern name.
Definition of util::get_elements() and util::get_const_elements().
static PlotCategories_t const DefaultPlotCategories
List of event categories.
A wrapper to trigger gate objects tracking the input of operations.
bool useGen() const
Returns whether we are using and filling generator information.
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
std::vector< geo::CryostatID > const fChannelCryostat
ID of cryostat where each optical detector channel (vector index) is.
A collection of useful beam gates. Make one with makeGatePack().
std::vector< std::vector< Counter_t > > fCounters
All counters; indices: [threshold][pattern].
std::string const & logCategory() const
Returns the name of the log category.
std::unordered_map< Threshold_t, std::size_t > fThresholdIndex
Map: threshold -> threshold index.
Geometry information for a single TPC.
std::unordered_map< std::string, std::size_t > fPatternIndex
Map: pattern name -> pattern index.
TTree * eventTree()
Returns a pointer to the tree where event information is written.
PlotCategories_t fPlotCategories
Plot categories (via initializePlots()).
std::string const fLogCategory
Message facility stream category for output.
Helper to manage a beam gate.
TEfficiency & Eff(std::string const &name) const
std::string const & name() const
Returns the name of the category.
std::string const & name() const
Returns the sandbox name.
Helper applying a beam gate to any gate.
geo::GeometryCore const & fGeom
Helper to check if an object has changed. Thread-safe.
Class to keep count of a pass/fail result.
pure virtual base interface for detector clocks
microseconds fBeamGateDuration
Duration of the gate during with global optical triggers are accepted.
TH1 & Hist(std::string const &name) const
Helper data structure to store transient trigger result.
std::string const & description() const
Returns the description of the category.
Interface to detinfo::DetectorClocks.
nanoseconds triggerTimeResolution() const
Returns the resolution of trigger timing clock [ns].
Access the description of detector geometry.
Information about the event.
std::unique_ptr< details::EventInfoTree > fEventTree
Handler of ROOT tree output.
icarus::trigger::BeamGateStruct beamGate
art::TFileDirectory fOutputDir
ROOT directory where all the plots are written.
details::EventInfoExtractorMaker const fEventInfoExtractorMaker
Helper to extract information from the event.
Class holding a ROOT tree, to be shared by other classes.
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
details::TriggerPassCounters fPassCounters
Counters for all triggers.
detinfo::DetectorTimings detTimings
Definitions of geometry vector data types.
Simple functions to streamline the creation of DetectorClocksData.
Simple type definitions for trigger algorithms.
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
auto ADCthresholds() const
Returns a iterable sequence of all configured PMT thresholds.
geo::GeometryCore const & geometry() const
Returns the detector geometry service provider.
std::vector< PlotDef > plots
Class managing the serialization of plot information in a simple ROOT tree.
BEGIN_PROLOG vertical distance to the surface Name
Helper data structure to store PMT activity information in the event.
art::InputTag fDetectorParticleTag
Input simulated particles.
bool test(EventInfo_t const &info) const
Returns whether the event belong to this category.
Simple class holding a tree.
PlotSandbox const & plots
Description of geometry of one entire detector.
An interval (duration, length, distance) between two quantity points.
Functions dealing with icarus::trigger::details::EventInfo_t.
Definition of data types for geometry description.
TH2 & Hist2D(std::string const &name) const
void initializePlots(std::vector< SettingsInfo_t > const &settings)
Initializes sets of default plots, one per PMT threshold.
InputTriggerGate_t::TriggerGate_t::ChannelID_t ChannelID_t
Type representing the unique identifier of a optical detector channel.
nanoseconds_as<> nanoseconds
Type of time interval stored in nanoseconds, in double precision.
std::map< std::string, art::InputTag > fADCthresholds
ADC threshold tags to read, and the input tag connected to their data.
Utilities to read interval and point quantity FHiCL configuration.
Object representing a time gate, with a start and and end.
std::string description
A description of the settings (for plots).
Class writing event information into a ROOT tree.
Classes to detect the change of object values.
Dimensioned variables representing energy.
Contains all timing reference information for the detector.
Class hosting selected information about the event.
PlotCategory(std::string name, std::string descr={}, QualifyFunc_t &&test=[](EventInfo_t const &){return true;})
Constructor from category name and test function.
std::unique_ptr< details::PlotInfoTree > fPlotTree
Handler of ROOT tree output.
Dimensioned variables representing space or time quantities.
Helper class to store transient trigger result.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
PlotSandbox const & box() const
Data types for detinfo::DetectorTimings.
std::string tag
A tag of the settings (for object names).
std::function< bool(EventInfo_t const &)> QualifyFunc_t
Type of test function.
std::vector< std::string > fOnlyPlotCategories
A simple alias for a most commonly used TrackedTriggerGate type.
Selected information about the event.
Generic description of trigger settings.
std::size_t nADCthresholds() const
Returns the number of configured PMT thresholds.
microseconds fPreSpillStart
Start of the pre-spill gate.
std::vector< std::reference_wrapper< PlotSandbox const >> PlotSandboxRefs_t
List of references to plot sandboxes.
std::unique_ptr< details::EventIDTree > fIDTree
Handler of ROOT tree output.
BEGIN_PROLOG hitmakerfive clustermakerfour pfparticlemakerthree showermakertwo END_PROLOG hitmakerfive clustermakerfour pfparticlemakerthree sequence::inline_paths sequence::inline_paths sequence::inline_paths showermakers test
Helper class to store discriminated PMT information.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
std::vector< PlotSandbox > fThresholdPlots
All plots, one set per ADC threshold.
SettingsInfo_t(std::size_t index, std::string tag, std::string descr)
Class hosting selected information about the event.
nanoseconds fTriggerTimeResolution
Trigger resolution in time.
std::vector< TriggerGates_t > TriggerGatesPerCryostat_t
Type of lists of gates, one list per cryostat (outer index: cryostat no).
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
detinfo::DetectorClocksData makeDetClockData(art::Event const *event)
Returns a detinfo::DetectorClocksData from DetectorClocksService.
icarus::trigger::BeamGateStruct preSpillWindow
std::vector< PlotCategory > PlotCategories_t
Class counting pass/fail events.
bool fPlotOnlyActiveVolume
Plot only events in active volume.
A helper to manage ROOT objects in a art::TFileDirectory.
std::vector< InputTriggerGate_t > TriggerGates_t
A list of trigger gates from input.
Encapsulate the construction of a single detector plane.
bool useEDep() const
Returns whether we are using and filling energy deposition information.
microseconds fBeamGateStart
Start of the beam gate with respect to BeamGate().
icarus::ns::util::ThreadSafeChangeMonitor< icarus::trigger::BeamGateStruct > fBeamGateChangeCheck
Functor returning whether a gate has changed.
std::size_t index
Settings unique index.
A helper to manage ROOT objects with consistent naming.