All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
sbndcode/sbndcode/gallery/galleryAnalysis/galleryAnalysis.cpp File Reference
#include "TrackAnalysis.h"
#include "HitAnalysisAlg.h"
#include "MCAssociations.h"
#include "sbndcode/gallery/helpers/expandInputFiles.h"
#include "lardataobj/RecoBase/Track.h"
#include "lardataalg/DetectorInfo/DetectorPropertiesStandardTestHelpers.h"
#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h"
#include "lardataalg/DetectorInfo/DetectorClocksStandardTestHelpers.h"
#include "lardataalg/DetectorInfo/DetectorClocksStandard.h"
#include "lardataalg/DetectorInfo/LArPropertiesStandardTestHelpers.h"
#include "lardataalg/DetectorInfo/LArPropertiesStandard.h"
#include "larcorealg/Geometry/StandaloneGeometrySetup.h"
#include "larcorealg/Geometry/GeometryCore.h"
#include "sbndcode/Geometry/ChannelMapSBNDAlg.h"
#include "larcorealg/Geometry/StandaloneBasicSetup.h"
#include "gallery/Event.h"
#include "canvas/Utilities/InputTag.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "fhiclcpp/ParameterSet.h"
#include "TFile.h"
#include <string>
#include <vector>
#include <memory>
#include <iostream>
#include <algorithm>
#include <iterator>

Go to the source code of this file.

Functions

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

Function Documentation

int galleryAnalysis ( 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 75 of file sbndcode/sbndcode/gallery/galleryAnalysis/galleryAnalysis.cpp.

76 {
77  /*
78  * the "test" environment configuration
79  */
80  // read FHiCL configuration from a configuration file:
81  fhicl::ParameterSet config = lar::standalone::ParseConfiguration(configFile);
82 
83  // set up message facility (always picked from "services.message")
84  lar::standalone::SetupMessageFacility(config, "galleryAnalysis");
85 
86  // configuration from the "analysis" table of the FHiCL configuration file:
87  auto const& analysisConfig = config.get<fhicl::ParameterSet>("analysis");
88 
89  // ***************************************************************************
90  // *** SERVICE PROVIDER SETUP BEGIN ****************************************
91  // ***************************************************************************
92  //
93  // Uncomment the things you need
94  // (and make sure the corresponding headers are also uncommented)
95  //
96 
97  // geometry setup (it's special)
98  auto geom = lar::standalone::SetupGeometry<geo::ChannelMapSBNDAlg>(config.get<fhicl::ParameterSet>("services.Geometry"));
99 
100  // LArProperties setup
101  auto larp = testing::setupProvider<detinfo::LArPropertiesStandard>(config.get<fhicl::ParameterSet>("services.LArPropertiesService"));
102 
103  // DetectorClocks setup
104  auto detclk = testing::setupProvider<detinfo::DetectorClocksStandard>(config.get<fhicl::ParameterSet>("services.DetectorClocksService"));
105 
106  // DetectorProperties setup
107  auto detp = testing::setupProvider<detinfo::DetectorPropertiesStandard>(config.get<fhicl::ParameterSet>("services.DetectorPropertiesService"),
108  detinfo::DetectorPropertiesStandard::providers_type{geom.get(),static_cast<detinfo::LArProperties const*>(larp.get())}); // TODO type cast is required until issue #18001 is solved
109 
110  // ***************************************************************************
111  // *** SERVICE PROVIDER SETUP END ****************************************
112  // ***************************************************************************
113 
114  /*
115  * the preparation of input file list
116  */
117  std::vector<std::string> const allInputFiles = expandInputFiles(inputFiles);
118 
119  /*
120  * other parameters
121  */
122  art::InputTag trackTag = analysisConfig.get<art::InputTag>("tracks");
123  art::InputTag hitsTag = analysisConfig.get<art::InputTag>("hits");
124 
125  /*
126  * preparation of histogram output file
127  */
128  std::unique_ptr<TFile> pHistFile;
129  if (analysisConfig.has_key("histogramFile"))
130  {
131  std::string fileName = analysisConfig.get<std::string>("histogramFile");
132  std::cout << "Creating output file: '" << fileName << "'" << std::endl;
133  pHistFile = std::make_unique<TFile>(fileName.c_str(), "RECREATE");
134  }
135 
136  /*
137  * preparation of the algorithm class
138  */
139  TrackAnalysis trackAnalysis(analysisConfig.get<fhicl::ParameterSet>("trackAnalysis"));
140 
141  trackAnalysis.setup(*geom, pHistFile.get());
142  trackAnalysis.prepare();
143  auto const clock_data = detclk->DataForJob();
144  auto const det_prop_data = detp->DataFor(clock_data);
145  HitAnalysis::HitAnalysisAlg hitAnalysisAlg(analysisConfig.get<fhicl::ParameterSet>("hitAnalysisAlg"));
146 
147  hitAnalysisAlg.setup(*geom, pHistFile.get());
148 
149  MCAssociations mcAssociations(analysisConfig.get<fhicl::ParameterSet>("mcAssociations"));
150 
151  mcAssociations.setup(*geom, det_prop_data, pHistFile.get());
152  mcAssociations.prepare();
153 
154  int numEvents(0);
155 
156  /*
157  * the event loop
158  */
159  for (gallery::Event event(allInputFiles); !event.atEnd(); event.next())
160  {
161  // *************************************************************************
162  // *** SINGLE EVENT PROCESSING BEGIN *************************************
163  // *************************************************************************
164 
165  mf::LogVerbatim("galleryAnalysis") << "This is event " << event.fileEntry() << "-" << event.eventEntry();
166 
167  trackAnalysis.processTracks(*(event.getValidHandle<std::vector<recob::Track>>(trackTag)));
168 
169  hitAnalysisAlg.fillHistograms(*(event.getValidHandle<std::vector<recob::Hit>>(hitsTag)));
170 
171  mcAssociations.doTrackHitMCAssociations(event);
172 
173  numEvents++;
174 
175  // *************************************************************************
176  // *** SINGLE EVENT PROCESSING END *************************************
177  // *************************************************************************
178 
179  } // for
180 
181  trackAnalysis.finish();
182  mcAssociations.finish();
183 
184  hitAnalysisAlg.endJob(numEvents);
185 
186  return 0;
187 } // galleryAnalysis()
Provider const * get() const
Returns the provider with the specified type.
Definition: ProviderPack.h:193
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.
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.
BEGIN_PROLOG could also be cout
int galleryAnalysis ( std::string const &  configFile,
std::string  filename 
)

Version with a single input file.

Definition at line 191 of file sbndcode/sbndcode/gallery/galleryAnalysis/galleryAnalysis.cpp.

192  { return galleryAnalysis(configFile, std::vector<std::string>{ filename }); }
BEGIN_PROLOG could also be dds filename
int galleryAnalysis(std::string const &configFile, std::vector< std::string > const &inputFiles)
Runs the analysis macro.
int main ( int  argc,
char **  argv 
)

Definition at line 195 of file sbndcode/sbndcode/gallery/galleryAnalysis/galleryAnalysis.cpp.

195  {
196 
197  char **pParam = argv + 1, **pend = argv + argc;
198  if (pParam == pend) {
199  std::cerr << "Usage: " << argv[0] << " configFile [inputFile ...]"
200  << std::endl;
201  return 1;
202  }
203  std::string const configFile = *(pParam++);
204  std::vector<std::string> fileNames;
205  std::copy(pParam, pend, std::back_inserter(fileNames));
206 
207  return galleryAnalysis(configFile, fileNames);
208 } // main()
BEGIN_PROLOG could also be cerr
int galleryAnalysis(std::string const &configFile, std::vector< std::string > const &inputFiles)
Runs the analysis macro.
T copy(T const &v)