All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Functions
DetectorActivityRatePlots.cpp File Reference

Draws some plots of detector activity with time. For simulation. More...

#include "Binner.h"
#include "icarusalg/Utilities/ROOTutils.h"
#include "icarusalg/gallery/helpers/C++/expandInputFiles.h"
#include "lardataobj/Simulation/SimChannel.h"
#include "lardataobj/Simulation/SimPhotons.h"
#include "lardataobj/Simulation/SimEnergyDeposit.h"
#include "lardataalg/DetectorInfo/DetectorPropertiesStandardTestHelpers.h"
#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h"
#include "lardataalg/DetectorInfo/DetectorPropertiesData.h"
#include "lardataalg/DetectorInfo/DetectorClocksStandardTestHelpers.h"
#include "lardataalg/DetectorInfo/DetectorClocksStandard.h"
#include "lardataalg/DetectorInfo/DetectorClocksStandardDataFor.h"
#include "lardataalg/DetectorInfo/DetectorClocksData.h"
#include "lardataalg/DetectorInfo/LArPropertiesStandardTestHelpers.h"
#include "lardataalg/DetectorInfo/LArPropertiesStandard.h"
#include "icarusalg/Geometry/ICARUSChannelMapAlg.h"
#include "larcorealg/Geometry/StandaloneGeometrySetup.h"
#include "larcorealg/Geometry/GeometryCore.h"
#include "larcorealg/Geometry/StandaloneBasicSetup.h"
#include "lardataalg/DetectorInfo/DetectorTimings.h"
#include "lardataalg/DetectorInfo/DetectorTimingTypes.h"
#include "lardataalg/Utilities/StatCollector.h"
#include "lardataalg/Utilities/intervals_fhicl.h"
#include "lardataalg/Utilities/quantities/energy.h"
#include "lardataalg/Utilities/quantities/electronics.h"
#include "lardataalg/Utilities/quantities/spacetime.h"
#include "larcorealg/CoreUtils/enumerate.h"
#include "gallery/Event.h"
#include "canvas/Utilities/InputTag.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "fhiclcpp/types/Table.h"
#include "fhiclcpp/types/Atom.h"
#include "fhiclcpp/ParameterSet.h"
#include "TFile.h"
#include "TDirectory.h"
#include "TProfile.h"
#include <algorithm>
#include <vector>
#include <array>
#include <memory>
#include <iostream>
#include <limits>
#include <cmath>
#include <iterator>

Go to the source code of this file.

Classes

class  PlotDetectorActivityRates
 Produces plots. Aaah! More...
 
struct  PlotDetectorActivityRates::AlgorithmConfiguration
 Data structure with all the configuration. More...
 
struct  PlotDetectorActivityRates::AlgorithmConfiguration::BinConfig< Point >
 
struct  PlotDetectorActivityRates::FHiCLconfig
 
struct  PlotDetectorActivityRates::FHiCLconfig::BinningConfig< Point, Interval >
 

Functions

int makePlots (std::string const &configFile, std::vector< std::string > const &inputFiles)
 Runs the analysis macro. More...
 
int makePlots (std::string const &configFile, std::string filename)
 Version with a single input file. More...
 
int main (int argc, char **argv)
 

Detailed Description

Draws some plots of detector activity with time. For simulation.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
October 13, 2020

The configuration requires:

Definition in file DetectorActivityRatePlots.cpp.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 996 of file DetectorActivityRatePlots.cpp.

996  {
997 
998  char **pParam = argv + 1, **pend = argv + argc;
999  if (pParam == pend) {
1000  std::cerr << "Usage: " << argv[0] << " configFile [inputFile ...]"
1001  << std::endl;
1003  return 1;
1004  }
1005  std::string const configFile = *(pParam++);
1006  std::vector<std::string> fileNames;
1007  std::copy(pParam, pend, std::back_inserter(fileNames));
1008 
1009  return makePlots(configFile, fileNames);
1010 } // main()
BEGIN_PROLOG could also be cerr
static void printConfigurationHelp(std::ostream &out)
Prints on out screen a configuration summary.
int makePlots(std::string const &configFile, std::vector< std::string > const &inputFiles)
Runs the analysis macro.
T copy(T const &v)
int makePlots ( std::string const &  configFile,
std::vector< std::string > const &  inputFiles 
)

Runs the analysis macro.

Parameters
configFilepath to the FHiCL configuration to be used for the services
inputFilesvector of path of file names
Returns
an integer as exit code (0 means success)

Definition at line 846 of file DetectorActivityRatePlots.cpp.

847 {
848  /*
849  * the "test" environment configuration
850  */
851  // read FHiCL configuration from a configuration file:
852  fhicl::ParameterSet config = lar::standalone::ParseConfiguration(configFile);
853 
854  // set up message facility (always picked from "services.message")
856 
857  // ***************************************************************************
858  // *** SERVICE PROVIDER SETUP BEGIN ****************************************
859  // ***************************************************************************
860  //
861  // Uncomment the things you need
862  // (and make sure the corresponding headers are also uncommented)
863  //
864  // geometry setup (it's special)
865  auto geom = lar::standalone::SetupGeometry<icarus::ICARUSChannelMapAlg>
866  (config.get<fhicl::ParameterSet>("services.Geometry"));
867 
868  // LArProperties setup
869  auto larProp = testing::setupProvider<detinfo::LArPropertiesStandard>
870  (config.get<fhicl::ParameterSet>("services.LArPropertiesService"));
871 
872  // DetectorClocks setup
873  auto detClocks = testing::setupProvider<detinfo::DetectorClocksStandard>
874  (config.get<fhicl::ParameterSet>("services.DetectorClocksService"));
875 
876  // DetectorProperties setup
877  auto detProps = testing::setupProvider<detinfo::DetectorPropertiesStandard>(
878  config.get<fhicl::ParameterSet>("services.DetectorPropertiesService"),
880 // { geom.get(), larProp.get() } // FIXME try this simpler version
881  );
882 
883  // ***************************************************************************
884  // *** SERVICE PROVIDER SETUP END ****************************************
885  // ***************************************************************************
886 
887  auto const& analysisConfig = config.get<fhicl::ParameterSet>("analysis");
888 
889  // event loop options
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);
893 
894  /*
895  * the preparation of input file list
896  */
897  if (inputFiles.size() != 1) {
898  throw std::runtime_error("Support for multiple input files not implemented yet!");
899  }
900  std::vector<std::string> const allInputFiles = expandInputFiles(inputFiles);
901 
902  /*
903  * other parameters
904  */
905 
906  /*
907  * preparation of histogram output file
908  */
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");
915  }
916 
917  /*
918  * preparation of the algorithm class
919  */
920 
921  // configuration from `ConfigurationKey` table of configuration file:
922  PlotDetectorActivityRates plotAlg {
923  analysisConfig.get<fhicl::ParameterSet>
925  };
926 
927  plotAlg.printConfig(mf::LogVerbatim{"makePlots"});
928 
929  {
930  auto clocksData = detClocks->DataForJob();
931  plotAlg.setup
932  (pHistFile.get(), std::move(clocksData), detProps->DataFor(clocksData));
933  }
934  plotAlg.printTimingSummary(mf::LogVerbatim{"makePlots"});
935 
936  plotAlg.prepare();
937 
938  /*
939  auto const clock_data = detclk->DataForJob();
940  auto const det_prop_data = detp->DataFor(clock_data);
941  */
942 
943  unsigned int numEvents { 0U };
944 
945  /*
946  * the event loop
947  */
948  for (gallery::Event event(allInputFiles); !event.atEnd(); event.next()) {
949 
950  if (nSkip > 0) { --nSkip; continue; }
951  if (numEvents >= maxEvents) {
952  mf::LogVerbatim("makePlots") << "Maximum number of events reached.";
953  break;
954  }
955 
956  // *************************************************************************
957  // *** SINGLE EVENT PROCESSING BEGIN *************************************
958  // *************************************************************************
959 
960  ++numEvents;
961  {
962  mf::LogVerbatim log("makePlots");
963  log << "This is event " << event.fileEntry() << "-" << event.eventEntry()
964  << " (" << numEvents;
965  if (maxEvents < NoLimits) log << "/" << maxEvents;
966  log << ")";
967  }
968 
969  {
970  auto clocksData
971  = detinfo::detectorClocksStandardDataFor(*detClocks, event);
972  plotAlg.setupEvent(std::move(clocksData), detProps->DataFor(clocksData));
973  }
974 
975  plotAlg.plotEvent(event);
976 
977 
978  // *************************************************************************
979  // *** SINGLE EVENT PROCESSING END *************************************
980  // *************************************************************************
981 
982  } // for
983 
984  plotAlg.finish();
985  plotAlg.printTimingSummary(mf::LogVerbatim{"makePlots"} << "Once again:\n");
986 
987  return 0;
988 } // makePlots()
fDetProps &fDetProps detProps
Provider const * get() const
Returns the provider with the specified type.
Definition: ProviderPack.h:193
source drop raw::ubdaqSoftwareTriggerData_ *_ *_ * maxEvents
Definition: frame-shunt.fcl:6
static std::string const ConfigurationKey
Name of the recommended configuration table for this algorithm.
void SetupMessageFacility(fhicl::ParameterSet const &pset, std::string applName="standalone")
Sets up the message facility service.
std::vector< std::string > expandInputFiles(std::vector< std::string > const &filePaths)
Expands all input files into a vector of file paths.
void printConfig(Stream &&out) const
Prints the current configuration to the specified output stream.
detinfo::DetectorClocksData detectorClocksStandardDataFor(detinfo::DetectorClocksStandard const &detClocks, Event const &event)
Returns DetectorClocksData tuned on the specified event.
Container for a list of pointers to providers.
Definition: ProviderPack.h:114
fhicl::ParameterSet ParseConfiguration(std::string configPath, cet::filepath_maker &lookupPolicy)
Parses a FHiCL configuration file.
int makePlots ( std::string const &  configFile,
std::string  filename 
)

Version with a single input file.

Definition at line 992 of file DetectorActivityRatePlots.cpp.

993  { return makePlots(configFile, std::vector<std::string>{ filename }); }
BEGIN_PROLOG could also be dds filename
int makePlots(std::string const &configFile, std::vector< std::string > const &inputFiles)
Runs the analysis macro.