58 #include "gallery/Event.h"
59 #include "canvas/Utilities/InputTag.h"
60 #include "messagefacility/MessageLogger/MessageLogger.h"
61 #include "fhiclcpp/types/Table.h"
62 #include "fhiclcpp/types/Atom.h"
63 #include "fhiclcpp/ParameterSet.h"
67 #include "TDirectory.h"
93 template <
typename Time>
97 template <
typename Time>
100 template <
typename DestTime,
typename Stream,
typename Time>
101 void printConvertedTimeRange(
102 Stream&& out, Time start, Time stop,
105 out << timeScaleName<DestTime>() <<
": "
106 << detTimings.
toTimeScale<DestTime>(start) <<
" -- "
111 template <
typename DestTick,
typename Stream,
typename Time>
112 void printConvertedTickRange(
113 Stream&& out, Time start, Time stop,
116 out << timeScaleName<DestTick>()
117 <<
" ticks: " << detTimings.
toTick<DestTick>(start)
118 <<
" -- " << detTimings.
toTick<DestTick>(stop)
161 template <
typename Po
int>
170 art::InputTag
edepTag {
"largeant",
"TPCActive" };
241 template <
typename Po
int,
typename Interval>
245 Comment{
"start of the range" }
253 Comment{
"duration of steps in the range" }
260 Comment{
"input tag for energy deposit data product" },
261 art::InputTag{
"largeant",
"TPCActive" }
264 Name{
"TPCchannels" },
265 Comment{
"input tag for simulated TPC channel data product" },
269 Name{
"OpDetChannels" },
270 Comment{
"input tag for simulated optical detector channel data product" },
274 fhicl::Table<BinningConfig<millisecond, milliseconds>>
SimBinning {
275 Name{
"SimulationBinning" },
276 Comment{
"range and binning for simulation times (simulation time) [ms]" }
280 Name{
"TPCBinning" },
281 Comment{
"range and binning for TPC readout [electronics ticks]" }
285 Name{
"OpDetBinning" },
286 Comment{
"range and binning for optical detector simulation (beam gate time)" }
312 TDirectory* pDestDir,
327 template <
typename Event>
335 template <
typename Stream>
339 template <
typename Stream>
348 (fhicl::ParameterSet
const& pset);
354 (fhicl::ParameterSet
const& pset)
357 template <
typename ConfigOut>
359 (ConfigOut& binConfig, fhicl::ParameterSet
const& pset);
361 template <
typename ConfigOut,
typename ConfigIn>
363 (ConfigOut& binConfig, ConfigIn
const& config);
365 template <
typename T,
typename BinConfig>
367 {
return { config.start, config.stop, config.step }; }
369 template <
typename T>
371 (fhicl::ParameterSet
const& pset, std::string
const& key, T& var)
372 { var = pset.get<T>(key); }
409 void plotPhotons(std::vector<sim::SimPhotons>
const& photonChannels);
415 template <
typename Plot>
428 : fConfig{ parseValidatedAlgorithmConfiguration(config()) }
429 , fSimBinner{ makeBinning<simulation_time>(fConfig.simBinning) }
430 , fTPCBinner{ makeBinning<electronics_tick>(fConfig.TPCBinning) }
431 , fOpDetBinner{ makeBinning<trigger_time>(fConfig.opDetBinning) }
439 algConfig.
edepTag = pset.get<art::InputTag>(
"Deposits",
"largeant");
440 algConfig.
chanTag = pset.get<art::InputTag>(
"TPCchannels",
"largeant");
441 algConfig.
photTag = pset.get<art::InputTag>(
"OpDetChannels",
"largeant");
444 (algConfig.
simBinning, pset.get<fhicl::ParameterSet>(
"SimBinning"));
446 (algConfig.
TPCBinning, pset.get<fhicl::ParameterSet>(
"TPCBinning"));
448 (algConfig.
opDetBinning, pset.get<fhicl::ParameterSet>(
"OpDetBinning"));
470 template <
typename ConfigOut>
472 (ConfigOut& binConfig, fhicl::ParameterSet
const& pset)
474 readParam(pset,
"Start", binConfig.start);
475 readParam(pset,
"Stop", binConfig.stop);
476 readParam(pset,
"Step", binConfig.step);
480 template <
typename ConfigOut,
typename ConfigIn>
482 (ConfigOut& binConfig, ConfigIn
const& config)
484 binConfig.start = config.Start();
485 binConfig.stop = config.Stop();
486 binConfig.step = config.Step();
492 out <<
"Configuration for the analysis algorithm:\n";
495 table.print_allowed_configuration(out);
502 TDirectory* pDestDir,
534 "EnergyDepositsInTime",
536 "Energy deposited in active volume vs. time"
537 ";deposition time (simulation time scale) [ "
558 "Electrons sensed by TPC channels vs. time (readout window: "
561 ";observation time (electronics time scale) [ TPC ticks, "
574 "PhotoelectronsInTime",
576 "Photoelectrons detected vs. time"
577 ";PMT conversion time (simulation time scale) [ "
599 template <
typename Event>
606 auto const& energyDeps
607 = *(
event.template getValidHandle<std::vector<sim::SimEnergyDeposit>>
615 auto const& TPCchannels
616 = *(
event.template getValidHandle<std::vector<sim::SimChannel>>
624 auto const& photonChannels
625 = *(
event.template getValidHandle<std::vector<sim::SimPhotons>>
642 template <
typename Stream>
645 out <<
"PlotDetectorActivityRates algorithm using:"
649 <<
"\n * time binning for: "
659 template <
typename Stream>
667 out <<
"Relevant timing settings:"
668 <<
"\n * TPC readout window: ";
669 printConvertedTickRange<detinfo::timescales::electronics_tick>
671 printConvertedTimeRange<detinfo::timescales::electronics_time>
673 printConvertedTimeRange<detinfo::timescales::simulation_time>
681 (std::vector<sim::SimEnergyDeposit>
const& energyDeps)
687 std::vector<EDepUnit_t> counters(fSimBinner.nBins() + 2U,
EDepUnit_t{ 0.0 });
694 int const timeBin = fSimBinner.cappedBinWithOverflows(time);
695 assert(timeBin + 1 < counters.size());
699 counters[timeBin + 1] += energy;
704 fEDepDistrib->Fill(fSimBinner.binCenter(iCount - 1).value(),
count.value());
708 = std::accumulate(counters.cbegin(), counters.cend(),
EDepUnit_t{ 0.0 });
709 fEDepStats.add(totalE.
value());
711 mf::LogVerbatim(
"PlotDetectorActivityRates")
712 <<
"Collected " << totalE <<
" in " << energyDeps.size() <<
" deposits.";
718 (std::vector<sim::SimChannel>
const& TPCchannels)
724 std::vector<double> counters(fTPCBinner.nBins() + 2U, 0U);
729 for (
auto const& [ TDC, IDEs ]: channel.TDCIDEMap()) {
735 int const tickBin = fTPCBinner.cappedBinWithOverflows(
tick);
736 assert(tickBin + 1 < counters.size());
738 counters[tickBin + 1] += channel.Charge(TDC);
745 fTPCchargeDistrib->Fill(fTPCBinner.binCenter(iCount - 1).value(),
count);
747 double const totalElectrons
748 = std::accumulate(counters.cbegin(), counters.cend(), 0.0);
749 fTPCchargeStats.add(totalElectrons);
750 mf::LogVerbatim(
"PlotDetectorActivityRates")
751 <<
"Detected " << totalElectrons
752 <<
" electrons in " << TPCchannels.size() <<
" channels (all planes)."
759 (std::vector<sim::SimPhotons>
const& photonChannels)
765 std::vector<unsigned int> counters(fOpDetBinner.nBins() + 2U, 0U);
775 = fOpDetBinner.cappedBinWithOverflows(fDetTimings->toTriggerTime(time));
776 assert(timeBin + 1 < counters.size());
778 ++counters[timeBin + 1];
785 fPhotonDistrib->Fill(fOpDetBinner.binCenter(iCount - 1).value(),
count);
787 unsigned int const totalPhotons
788 = std::accumulate(counters.cbegin(), counters.cend(), 0U);
789 fPhotonStats.add(totalPhotons);
791 mf::LogVerbatim(
"PlotDetectorActivityRates")
792 <<
"Collected " << totalPhotons
793 <<
" photoelectrons in " << photonChannels.size() <<
" channels."
815 mf::LogVerbatim(
"PlotDetectorActivityRates")
816 <<
"Statistics, on average per event (" <<
fEDepStats.
N() <<
" events):"
820 <<
") ionization electrons (all planes)"
822 <<
") photoelectrons"
828 template <
typename Plot>
846 (std::string
const& configFile, std::vector<std::string>
const&
inputFiles)
865 auto geom = lar::standalone::SetupGeometry<icarus::ICARUSChannelMapAlg>
866 (config.get<fhicl::ParameterSet>(
"services.Geometry"));
869 auto larProp = testing::setupProvider<detinfo::LArPropertiesStandard>
870 (config.get<fhicl::ParameterSet>(
"services.LArPropertiesService"));
873 auto detClocks = testing::setupProvider<detinfo::DetectorClocksStandard>
874 (config.get<fhicl::ParameterSet>(
"services.DetectorClocksService"));
877 auto detProps = testing::setupProvider<detinfo::DetectorPropertiesStandard>(
878 config.get<fhicl::ParameterSet>(
"services.DetectorPropertiesService"),
887 auto const& analysisConfig = config.get<fhicl::ParameterSet>(
"analysis");
890 constexpr
auto NoLimits = std::numeric_limits<unsigned int>::max();
891 unsigned int nSkip = analysisConfig.get(
"skipEvents", 0U);
892 unsigned int const maxEvents = analysisConfig.get(
"maxEvents", NoLimits);
897 if (inputFiles.size() != 1) {
898 throw std::runtime_error(
"Support for multiple input files not implemented yet!");
900 std::vector<std::string>
const allInputFiles =
expandInputFiles(inputFiles);
909 std::unique_ptr<TFile> pHistFile;
910 if (analysisConfig.has_key(
"histogramFile")) {
911 std::string
fileName = analysisConfig.get<std::string>(
"histogramFile");
912 mf::LogVerbatim(
"makePlots")
913 <<
"Creating output file: '" << fileName <<
"'" << std::endl;
914 pHistFile = std::make_unique<TFile>(fileName.c_str(),
"RECREATE");
923 analysisConfig.get<fhicl::ParameterSet>
930 auto clocksData = detClocks->DataForJob();
932 (pHistFile.get(), std::move(clocksData),
detProps->DataFor(clocksData));
934 plotAlg.printTimingSummary(mf::LogVerbatim{
"makePlots"});
943 unsigned int numEvents { 0U };
948 for (gallery::Event event(allInputFiles); !
event.atEnd();
event.next()) {
950 if (nSkip > 0) { --nSkip;
continue; }
951 if (numEvents >= maxEvents) {
952 mf::LogVerbatim(
"makePlots") <<
"Maximum number of events reached.";
962 mf::LogVerbatim log(
"makePlots");
963 log <<
"This is event " <<
event.fileEntry() <<
"-" <<
event.eventEntry()
964 <<
" (" << numEvents;
965 if (maxEvents < NoLimits) log <<
"/" <<
maxEvents;
972 plotAlg.setupEvent(std::move(clocksData),
detProps->DataFor(clocksData));
975 plotAlg.plotEvent(event);
985 plotAlg.printTimingSummary(mf::LogVerbatim{
"makePlots"} <<
"Once again:\n");
993 {
return makePlots(configFile, std::vector<std::string>{ filename }); }
995 #if !defined(__CLING__)
996 int main(
int argc,
char** argv) {
998 char **pParam = argv + 1, **pend = argv + argc;
999 if (pParam == pend) {
1000 std::cerr <<
"Usage: " << argv[0] <<
" configFile [inputFile ...]"
1005 std::string
const configFile = *(pParam++);
1006 std::vector<std::string> fileNames;
1007 std::copy(pParam, pend, std::back_inserter(fileNames));
1009 return makePlots(configFile, fileNames);
1012 #endif // !__CLING__
std::optional< detinfo::DetectorPropertiesData > fDetPropsData
void savePlots()
Writes all plots into the current ROOT directory (and then deletes them).
static void readParam(fhicl::ParameterSet const &pset, std::string const &key, T &var)
process_name can override from command line with o or output photon
timescale_traits< ElectronicsTimeCategory >::tick_t electronics_tick
A point on the electronics time scale expressed in its ticks.
Channel mapping algorithms for ICARUS detector.
std::optional< detinfo::DetectorTimings > fDetTimings
Energy deposited on a readout channel by simulated tracks.
void initializePlots()
Performs the initialization of the plots filled by the algorithm.
Utilities for one-line geometry initialization.
Service provider with utility LAr functions.
BEGIN_PROLOG could also be cerr
Definition of util::enumerate().
Data structure with all the configuration.
simulation_time_scale::time_point_t simulation_time
Helper functions for support of LArPropertiesService in LArSoft tests.
BinConfig< simulation_time > simBinning
AlgorithmConfiguration parseValidatedAlgorithmConfiguration(FHiCLconfig const &config)
detinfo::timescales::electronics_tick electronics_tick
BEGIN_PROLOG could also be dds filename
All information of a photon entering the sensitive optical detector volume.
lar::util::StatCollector< double > fEDepStats
Statistics of the total energy per event.
void initializeTPCionizationPlots()
Performs the initialization of plots pertaining collected TPC charge.
void plotEnergyDeposits(std::vector< sim::SimEnergyDeposit > const &energyDeps)
Plots data from energy deposits in liquid argon.
Provider const * get() const
Returns the provider with the specified type.
static void parseBinning(ConfigOut &binConfig, fhicl::ParameterSet const &pset)
A collection of traits for a time scale.
constexpr value_t value() const
Returns the value of the quantity.
source drop raw::ubdaqSoftwareTriggerData_ *_ *_ * maxEvents
Classes gathering simple statistics.
std::unique_ptr< TProfile > fTPCchargeDistrib
Average amount of ionization collected per time.
void printStats() const
Prints on screen some collected statistics.
Weight_t RMS() const
Returns the root mean square.
static void printConfigurationHelp(std::ostream &out)
Prints on out screen a configuration summary.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
void setup(TDirectory *pDestDir, detinfo::DetectorClocksData &&clocksData, detinfo::DetectorPropertiesData &&propsData)
Sets the algorithm up.
static auto unitSymbol()
Returns the symbol of the unit, in a string-like object.
Weight_t Average() const
Returns the value average.
Interface to detinfo::DetectorClocks.
static std::string const ConfigurationKey
Name of the recommended configuration table for this algorithm.
Helper functions for support of DetectorClocksService in LArSoft tests.
lar::util::StatCollector< unsigned int > fPhotonStats
Statistics of the total light (photoelectron count) per event.
void prepare()
Performs the initialization of the algorithm.
Access the description of detector geometry.
void SetupMessageFacility(fhicl::ParameterSet const &pset, std::string applName="standalone")
Sets up the message facility service.
Simulation objects for optical detectors.
BinConfig< electronics_tick > TPCBinning
Collection of functions for quick setup of basic facilities.
static util::Binner< T > makeBinning(BinConfig const &config)
PlotDetectorActivityRates(Parameters const &config)
Constructor: reads the configuration from the specified parameters set.
TDirectory * fDestDir
ROOT directory where to write the plots.
void plotPhotons(std::vector< sim::SimPhotons > const &photonChannels)
Plots data from photoelectron collection.
void printConfig(Stream &&out) const
Prints the current configuration to the specified output stream.
lar::util::StatCollector< double > fTPCchargeStats
Statistics of the total charge (electron count) per event.
int N() const
Returns the number of entries added.
timescale_traits< SimulationTimeCategory >::time_point_t simulation_time
A point in time on the simulation time scale.
static void Serialize(std::unique_ptr< Plot > &plot)
Writes plot into the current ROOT directory, then deletes it.
void initializePhotonPlots()
Performs the initialization of plots pertaining collected photoelectrons.
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
A value measured in the specified unit.
megaelectronvolt_as<> megaelectronvolt
Type of energy stored in megaelectronvolt, in double precision.
A bunch of diverse utilities and futilities related to ROOT.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
BEGIN_PROLOG vertical distance to the surface Name
int makePlots(std::string const &configFile, std::vector< std::string > const &inputFiles)
Runs the analysis macro.
void plotTPCionization(std::vector< sim::SimChannel > const &TPCchannels)
Plots data from photoelectron collection.
Helpers for support of DetectorPropertiesService in LArSoft tests.
fhicl::Atom< Point > Start
An interval (duration, length, distance) between two quantity points.
fhicl::Atom< Point > Stop
std::unique_ptr< TProfile > fPhotonDistrib
Average number of photon per time.
detinfo::DetectorClocksData detectorClocksStandardDataFor(detinfo::DetectorClocksStandard const &detClocks, Event const &event)
Returns DetectorClocksData tuned on the specified event.
AlgorithmConfiguration const fConfig
Complete configuration of the algorithm.
nanoseconds_as<> nanoseconds
Type of time interval stored in nanoseconds, in double precision.
milliseconds_as<> milliseconds
Type of time interval stored in milliseconds, in double precision.
fhicl::Table< BinningConfig< tick, ticks > > TPCBinning
fhicl::Atom< art::InputTag > OpDetChannels
Utilities to read interval and point quantity FHiCL configuration.
millisecond_as<> millisecond
Type of time point stored in milliseconds, in double precision.
Dimensioned variables related to electronics.
fhicl::Table< BinningConfig< millisecond, milliseconds > > OpDetBinning
Collection of photons which recorded on one channel.
fhicl::Atom< Interval > Step
util::Binner< simulation_time > fSimBinner
std::unique_ptr< TProfile > fEDepDistrib
Average amount of deposited energy per time [GeV].
void setupEvent(detinfo::DetectorClocksData &&clocksData, detinfo::DetectorPropertiesData &&propsData)
Set up for a specific event.
TargetTime toTimeScale(FromTime time) const
Returns a time point in a different time scale.
Dimensioned variables representing energy.
TargetTick toTick(FromTime time) const
Returns a time point as a tick on a different time scale.
Contains all timing reference information for the detector.
AlgorithmConfiguration parseAlgorithmConfiguration(fhicl::ParameterSet const &pset)
std::string to_string(WindowPattern const &pattern)
Dimensioned variables representing space or time quantities.
services TFileService fileName
contains information for a single step in the detector simulation
Data_t upper() const
Returns the upper limit of the range.
Container for a list of pointers to providers.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
Data types for detinfo::DetectorTimings.
Energy deposition in the active material.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
Step_t step() const
Returns the step size.
ticks_as<> ticks
A tick interval based on std::ptrdiff_t.
tick_as<> tick
A tick value based on std::ptrdiff_t.
BinConfig< trigger_time > opDetBinning
util::Binner< electronics_tick > fTPCBinner
fhicl::Table< FHiCLconfig > Parameters
A class restoring the previous TDirectory on destruction.
void plotEvent(Event const &event)
Processes a single event.
std::size_t count(Cont const &cont)
Helper to get clocks data from detinfo::DetectorClocksStandard.
fhicl::ParameterSet ParseConfiguration(std::string configPath, cet::filepath_maker &lookupPolicy)
Parses a FHiCL configuration file.
int main(int argc, char **argv)
decltype(std::declval< Data_t >()-std::declval< Data_t >()) Step_t
Type of difference between binning axis values.
Helper object to describing a binned axis.
fhicl::Atom< art::InputTag > Deposits
typename util::Binner< Point_t >::Step_t Interval_t
fhicl::Table< BinningConfig< millisecond, milliseconds > > SimBinning
timescale_traits< TPCelectronicsTimeCategory >::tick_t TPCelectronics_tick
A point on the TPC electronics time scale expressed in its ticks.
void printTimingSummary(Stream &&out) const
Prints some information about configured timing.
static void parseAndValidateBinning(ConfigOut &binConfig, ConfigIn const &config)
void initializeEnergyDepositPlots()
Performs the initialization of plots pertaining energy deposits.
unsigned int nBins() const
Returns the number of bins in the range.
fhicl::Atom< art::InputTag > TPCchannels
util::Binner< trigger_time > fOpDetBinner
detinfo::timescales::simulation_time trigger_time
void finish()
Completes and saves the plots.