43 #include "art_root_io/TFileService.h"
44 #include "art/Framework/Services/Registry/ServiceHandle.h"
45 #include "art/Framework/Core/EDAnalyzer.h"
46 #include "art/Framework/Core/ModuleMacros.h"
47 #include "art/Framework/Principal/Event.h"
48 #include "canvas/Utilities/Exception.h"
49 #include "messagefacility/MessageLogger/MessageLogger.h"
50 #include "fhiclcpp/types/OptionalSequence.h"
51 #include "fhiclcpp/types/Sequence.h"
52 #include "fhiclcpp/types/OptionalAtom.h"
53 #include "fhiclcpp/types/Atom.h"
93 std::ostream&
operator<<
158 namespace icarus::trigger {
class MakeTriggerSimulationTree; }
276 Name(
"GeneratorTags"),
277 Comment(
"labels of the event generators"),
278 std::vector<art::InputTag>{
"generator" }
282 Name(
"EnergyDepositTags"),
283 Comment(
"label of energy deposition data product(s) in the detector")
287 Name(
"EnergyDepositSummaryTag"),
288 Comment(
"label of energy deposition summary data product")
292 Name(
"TriggerGatesTag"),
293 Comment(
"label of the input trigger gate data product (no instance name)")
297 Name(
"BeamGateDuration"),
298 Comment(
"length of time interval when optical triggers are accepted")
302 Name(
"BeamGateStart"),
303 Comment(
"open the beam gate this long after the nominal beam gate time"),
308 Name(
"PreSpillWindow"),
309 Comment(
"duration of the pre-spill window"),
314 Name(
"PreSpillWindowGap"),
315 Comment(
"gap from the end of pre-spill window to the start of beam gate"),
320 Name(
"EventTreeName"),
321 Comment(
"name of the ROOT tree"),
327 Comment(
"name of the category used for the output"),
328 "MakeTriggerSimulationTree"
352 virtual void analyze(art::Event
const& event)
override;
455 fhicl::OptionalSequence<art::InputTag>
const& EnergyDepositTags,
456 fhicl::OptionalAtom<art::InputTag>
const& EnergyDepositSummaryTag
468 std::ostream&
operator<<
471 out <<
"center at " <<
info.center;
472 if (
info.nOpenings == 0) out <<
" never opened";
474 out <<
" opened " <<
info.nOpenings <<
" times, first at "
475 <<
info.firstOpenTime;
485 out <<
"\n [" << iGate <<
"] " << gate;
510 auto checkSize = [
this](
auto const& v){
return v.size() ==
fNChannels; };
513 throw cet::exception(
"TriggerGateTree") << __func__
514 <<
": Internal error: unexpected buffer size (" <<
fOpDetPos.size()
515 <<
") : fOpDetPos\n";
518 throw cet::exception(
"TriggerGateTree") << __func__
519 <<
": Internal error: unexpected buffer size (" <<
fNOpenings.size()
520 <<
") : fNOpenings\n";
523 throw cet::exception(
"TriggerGateTree") << __func__
524 <<
": Internal error: unexpected buffer size (" <<
fOpeningTime.size()
525 <<
") : fOpeningTime\n";
547 fOpeningTime.push_back(channelInfo.firstOpenTime.value());
561 : art::EDAnalyzer(config)
563 , fBeamGateDuration (config().BeamGateDuration())
564 , fBeamGateStart (config().BeamGateStart())
565 , fPreSpillWindow (config().PreSpillWindow())
567 (fBeamGateStart - config().PreSpillWindowGap() - fPreSpillWindow)
568 , fTriggerGatesTag(config().TriggerGatesTag())
571 ,
fGeom(*lar::providerFrom<geo::Geometry>())
573 , fIDTree(*(art::ServiceHandle<art::TFileService>()
574 ->make<TTree>(config().EventTreeName().c_str(),
"Event information")
576 , fEventTree(fIDTree.tree())
577 , fTriggerGateTree(fIDTree.tree())
578 , fEventInfoExtractorMaker(
579 config().GeneratorTags(),
580 makeEdepTag(config().EnergyDepositTags, config().EnergyDepositSummaryTag),
601 (art::Event
const& event)
609 (detTimings, fBeamGateDuration, fBeamGateStart);
611 if (
auto oldGate = fBeamGateChangeCheck(beamGate); oldGate) {
612 MF_LOG_DEBUG(fLogCategory)
613 <<
"Beam gate has changed from " << oldGate->asOptTickRange()
614 <<
" to " << beamGate.asOptTickRange() <<
" (optical tick)!";
618 beamGate.asSimulationRange(),
620 (detTimings, fPreSpillStart, fPreSpillStart + fPreSpillWindow)
626 mf::LogDebug(fLogCategory) <<
event.id() <<
" trigger info: " << triggerInfo;
628 fIDTree.assignID(event.id());
629 if (fEventTree) fEventTree->assignEvent(eventInfo);
630 if (fTriggerGateTree) fTriggerGateTree->assignTriggerGatesInfo(triggerInfo);
632 fIDTree.tree().Fill();
659 .make(fBeamGateDuration, fBeamGateStart);
665 =
event.getProduct<std::vector<OpticalTriggerGateData_t>>(fTriggerGatesTag);
672 unsigned int nOpenChannels = 0U;
682 = beamAndGate.findOpen();
687 unsigned int nOpenings = 0U;
689 while (openTick != OpticalTriggerGateData_t::MaxTick) {
692 openTick = beamAndGate.findClose(1U, openTick);
693 openTick = beamAndGate.findOpen(1U, openTick);
695 if (nOpenings > 0) ++nOpenChannels;
700 info.TriggerGates.push_back({
701 gateChannelCentroid(gate),
705 ? std::numeric_limits<simulation_time>::max()
714 mf::LogTrace(fLogCategory)
715 <<
"Information from '" << fTriggerGatesTag.encode() <<
"' ("
716 << gates.size() <<
" trigger gates, " << nOpenChannels
717 <<
" channels) written to tree."
731 for (
auto const channel: gate.
channels()) {
734 centroid.
add(
fGeom.OpDetGeoFromOpChannel(channel).GetCenter());
736 catch (cet::exception
const&
e) {
737 throw cet::exception(
"MakeTriggerSimulationTree",
"", e)
738 <<
"Error while accessing position of optical detector with channel "
752 fhicl::OptionalSequence<art::InputTag>
const& EnergyDepositTags,
753 fhicl::OptionalAtom<art::InputTag>
const& EnergyDepositSummaryTag
756 if (EnergyDepositSummaryTag.hasValue()) {
757 if (EnergyDepositTags.hasValue()) {
758 throw art::Exception(art::errors::Configuration)
759 <<
"MakeTriggerSimulationTree: "
760 <<
"both EnergyDepositTags and EnergyDepositSummaryTag "
761 <<
"have been specified, but they are exclusive: @erase one.\n";
765 EnergyDepositSummaryTag(tag);
773 std::vector<art::InputTag> tags;
774 if (!EnergyDepositTags(tags)) tags.push_back(
"largeant:TPCActive");
775 return { std::move(tags) };
decltype(auto) channels() const
Returns the channels associated to the gate data.
fhicl::Atom< microseconds > PreSpillWindow
std::vector< Double_t > fOpeningTime
Time of first opening.
fhicl::Atom< std::string > LogCategory
std::optional< details::EventInfoTree > fEventTree
ROOT tree: event information.
art::InputTag const fTriggerGatesTag
Tag for optical trigger gate data product.
Utilities related to art service access.
Utilities for the conversion of trigger gate data formats.
An object representing a time gate, with a start and and end.
TriggerGatesInfo extractTriggerInfo(art::Event const &event, detinfo::DetectorTimings const &detTimings) const
Returns a TriggerGatesInfo with trigger information for the tree.
Definition of util::enumerate().
Algorithm to produce trigger gates out of optical readout waveforms.
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
Information from a single trigger gate.
Helper class to compute the middle point in a point set.
UInt_t fNChannels
Number of channels.
fhicl::Atom< std::string > TriggerGatesTag
std::size_t size(FixedBins< T, C > const &) noexcept
Helper to check if an object has changed. Thread-safe.
fhicl::Atom< microseconds > PreSpillWindowGap
void add(Point const &p)
Accumulates a point.
MakeTriggerSimulationTree(Parameters const &config)
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Interface to detinfo::DetectorClocks.
geo::Point_t gateChannelCentroid(icarus::trigger::OpticalTriggerGateData_t const &gate) const
Access the description of detector geometry.
std::optional< TriggerGateTree > fTriggerGateTree
ROOT tree: trigger gates.
Class holding a ROOT tree, to be shared by other classes.
Logical multi-level gate associated to one or more readout channels.
Tick ClockTick_t
Tick point.
details::EventInfoExtractorMaker const fEventInfoExtractorMaker
Helper to fill a EventInfo_t from an art event.
TimeRange< simulation_time > const & asSimulationRange() const
Returns the gate as start/stop pair in simulation time scale.
geo::GeometryCore const & fGeom
Utilities to read and write quantities in FHiCL configuration.
timescale_traits< SimulationTimeCategory >::time_point_t simulation_time
A point in time on the simulation time scale.
Simple functions to streamline the creation of DetectorClocksData.
A logical multilevel gate for triggering.
microseconds const fPreSpillStart
Start of the pre-spill gate.
static icarus::trigger::details::EventInfoExtractor::EDepTags_t makeEdepTag(fhicl::OptionalSequence< art::InputTag > const &EnergyDepositTags, fhicl::OptionalAtom< art::InputTag > const &EnergyDepositSummaryTag)
Creates a EDepTags_t from two optional parameters.
Simple type definitions for trigger algorithms.
microseconds const fPreSpillWindow
Duration of the pre-spill gate.
virtual void analyze(art::Event const &event) override
Fills the plots. Also extracts the information to fill them with.
A trigger gate data object for optical detector electronics.
icarus::trigger::ReadoutTriggerGate< TriggerGateTick_t, TriggerGateTicks_t, raw::Channel_t > OpticalTriggerGateData_t
Type of trigger gate data serialized into art data products.
details::EventIDTree fIDTree
Main ROOT tree: event ID.
simulation_time toSimulationTime(FromTime time) const
Converts a time point into simulation time scale.
Utilities to extend the interface of geometry vectors.
Class managing the serialization of trigger gates in a simple ROOT tree.
Class managing the serialization of event ID in a simple ROOT tree.
BEGIN_PROLOG vertical distance to the surface Name
TriggerGateTree(TTree &tree)
Constructor.
Simple class holding a tree.
All information from the trigger gates.
Description of geometry of one entire detector.
An interval (duration, length, distance) between two quantity points.
Functions dealing with icarus::trigger::details::EventInfo_t.
microseconds const fBeamGateDuration
Duration of the gate during with global optical triggers are accepted.
fhicl::Sequence< art::InputTag > GeneratorTags
geo::Point_t center
Middle point of the center of all contributing channels.
fhicl::Atom< std::string > EventTreeName
std::vector< UInt_t > fNOpenings
Number of openings (0 if never opens).
Utilities to read interval and point quantity FHiCL configuration.
Class writing event information into a ROOT tree.
geo::Point_t middlePoint() const
timescale_traits< OpticalTimeCategory >::tick_t optical_tick
Classes to detect the change of object values.
art::EDAnalyzer::Table< Config > Parameters
Class hosting selected information about the event.
BeamGateStruct makeBeamGateStruct(detinfo::DetectorTimings const &detTimings, util::quantities::intervals::microseconds duration, util::quantities::intervals::microseconds delay=util::quantities::intervals::microseconds{0.0})
Creates a BeamGateStruct object of specified duration and start.
fhicl::Atom< microseconds > BeamGateDuration
MakeTriggerSimulationTree & operator=(MakeTriggerSimulationTree const &)=delete
A class exposing an upgraded interface of detinfo::DetectorClocksData.
Data types for detinfo::DetectorTimings.
Class to create an object representing a beam gate.
void checkSizes() const
Internal check: all branch buffers have the same size.
icarus::ns::util::ThreadSafeChangeMonitor< icarus::trigger::BeamGateStruct > fBeamGateChangeCheck
Functor returning whether a gate has changed.
A simple alias for a most commonly used TrackedTriggerGate type.
simulation_time firstOpenTime
The time of the first opening on the channel, in simulation time [ns].
Simple utility to generate gates around beam time.
Selected information about the event.
unsigned int nOpenings
Number of times the gate was "open".
Simple helper functions to deal with FHiCL.
fhicl::Atom< microseconds > BeamGateStart
fhicl::OptionalSequence< art::InputTag > EnergyDepositTags
Definition of util::values() and util::const_values().
std::string const fLogCategory
Name of output stream for message facility.
Class hosting selected information about the event.
microseconds const fBeamGateStart
Start of the beam gate with respect to BeamGate().
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
void assignTriggerGatesInfo(TriggerGatesInfo const &info)
Copies the information from the info record into the ROOT tree buffers.
fhicl::OptionalAtom< art::InputTag > EnergyDepositSummaryTag
std::ostream & operator<<(std::ostream &out, lar::example::CheatTrack const &track)
art framework interface to geometry description
std::vector< TriggerGateInfo > TriggerGates
Collection of all available trigger gates.
detinfo::DetectorTimings makeDetTimings(art::Event const *event)
Returns a detinfo::DetectorTimings from DetectorClocksService.
std::vector< geo::Point_t > fOpDetPos
Coordinates of the optical detector.
Make ROOT tree with information about event and trigger input.
Utilities to map data pointer elements to their art::Ptr.