6 #include <TND280Output.hxx>
7 #include <TOADatabase.hxx>
8 #include <nd280EventLoop.hxx>
21 #include "TND280Input.hxx"
37 namespace AnalysisLoopGlobals {
54 std::pair<std::string, ND::TAnalysisModuleBase *>
const &LHS,
55 std::pair<std::string, ND::TAnalysisModuleBase *>
const &RHS) {
57 return !(LHS.second->IsUsedForPreselection() &&
58 (!RHS.second->IsUsedForPreselection()));
67 fSaveOriginalFullEvent(false),
68 fSaveOutputOaEventTree(false),
92 std::make_pair(
"TTrackerECALReconModule",
125 <<
"\t-O inputdir=<path/to/dir> Set an input directory where the "
127 "\t can pick up non-nd280 files. For example use this if you need "
129 "\t recover pass-through information from a given directory\n"
130 "\t-O production Run eventAnalysis in production mode. It will exit if "
132 "\t RooTracker information is found for MC files or if "
134 "\t modules enabled modules crash\n"
135 "\t-O validation Run eventAnalysis in validation mode. It will exit if "
137 "\t enabled module crashes\n"
138 "\t-O geometry Save the ND280 geometry to the eventAnalysis file\n"
139 "\t (not saved by default)\n"
140 "\t-O save Save the original full TND280Event in analysis file\n\n"
141 "=====================Module Level Options=====================\n"
142 "\t-O enable=<modulename> Enable a particular module \n"
143 "\t (overrides all other disable/enable)\n"
144 "\t-O disable=<modulename> Disable a particular module \n"
145 "\t (overrides disable/enable all)\n"
146 "\t-O enable=all Enable all modules (overrides disable all)\n"
147 "\t-O disable=all Disable all modules\n"
148 "\t-O preselection=<modulename> Use module to output pre-selected\n"
149 "\t events in the ND280Events oaEvent tree\n"
150 "\t-O modulename=<option> Configure module\n"
151 "\t(for example. -O TTruthTrajectoriesModule=saveall)\n\n"
152 "\tAvailable modules {default status} and options are:"
157 std::cout <<
"\t\t" << mod_it->first
158 << (mod_it->second->IsEnabledByDefault() ?
" {enabled}"
161 mod_it->second->SayAvailableOpts(
"\t\t ");
166 if (option ==
"production") {
167 ND280NamedLog(
"TAnalysisLoop",
"Running in production mode");
172 if (option ==
"validation") {
173 ND280NamedLog(
"TAnalysisLoop",
"Running in validation mode");
178 if (option ==
"geometry") {
179 ND280NamedLog(
"TAnalysisLoop",
"Saving the ND280 geometry");
184 if (option ==
"disable" && value ==
"all") {
185 ND280NamedLog(
"TAnalysisLoop",
186 "Disabling all modules due to user command line option");
190 if (option ==
"enable" && value ==
"all") {
191 ND280NamedInfo(
"TAnalysisLoop",
" " << value);
192 ND280NamedLog(
"TAnalysisLoop",
193 "Enabling all modules due to user command line option "
194 <<
"(takes precedence over the disable=all option)");
199 if ((option ==
"disable") || (option ==
"enable") ||
200 (option ==
"preselection")) {
203 ND280NamedError(
"TAnalysisLoop",
204 "Module name " << value <<
" does not match any module.");
210 if (option ==
"disable") {
211 ND280NamedLog(
"TAnalysisLoop",
"Disabling module "
213 <<
" due to user cmd line option.");
219 }
else if (option ==
"enable") {
220 ND280NamedLog(
"TAnalysisLoop",
"Enabling module "
222 <<
" due to user cmd line option ");
225 }
else if (option ==
"preselection") {
226 ND280NamedLog(
"TAnalysisLoop",
"Enabling module "
227 << value <<
", and using it for");
228 ND280NamedLog(
"TAnalysisLoop",
229 "\toaEvent output preselection, "
230 "due to user cmd line option.");
237 }
else if (option ==
"save") {
242 else if (option ==
"inputdir") {
243 void *dir = gSystem->OpenDirectory(value.c_str());
247 mod_it->second->SetInputDirectory(value);
251 "Set input directory as: " << value.c_str());
256 "Unable to open specified input directory: " << value.c_str());
263 ND280NamedError(
"TAnalysisLoop",
"Module name "
265 <<
" does not match any module.");
268 return mod_it->second->Configure(value);
281 ND280NamedInfo(
"TAnalysisLoop",
"Processed Events " <<
fEventCount);
286 fGeom = ND::TOADatabase::Get().Geometry();
288 bool saveThisFullOaEvent =
false;
299 ND280NamedVerbose(
"TAnalysisLoop",
"Processing with module "
304 bool passThroughException =
false;
318 saveThisFullOaEvent =
320 }
catch (ND::EDataFile &ex) {
321 ND280NamedVerbose(
"TAnalysisLoop",
322 "Analysing data file, will disable "
323 "Monte Carlo module: "
324 << module.
GetName() <<
" module");
327 }
catch (ND::ENoKinematicsPassThroughTrees &ex) {
328 ND280NamedWarn(
"TAnalysisLoop",
329 "Caught ND::ENoKinematicsPassThroughTr"
332 passThroughException =
true;
333 }
catch (ND::EIncorrectInputGenerator &ex) {
334 ND280NamedWarn(
"TAnalysisLoop",
"Caught ND::EIncorrectInputGenerator, "
336 passThroughException =
true;
337 }
catch (ND::ENoBeamSummaryData &ex) {
342 "No BSD data available for this "
343 "Spill event - running in production mode - program will exit");
345 }
catch (std::exception &ex) {
346 ND280NamedError(
"TAnalysisLoop", ex.what());
347 ND280NamedError(
"TAnalysisLoop",
"Disabling module " << module.
GetName());
350 ND280NamedError(
"TAnalysisLoop",
351 "eventAnalysis is running in production"
352 " mode and has caught an exception so will exit");
357 ND280NamedError(
"TAnalysisLoop",
"Disabling module " << module.
GetName());
360 ND280NamedError(
"TAnalysisLoop",
361 "eventAnalysis is running in production"
362 " mode and has caught an exception so will exit");
368 if (passThroughException) {
375 (nroo_mod_it->second->IsEnabled());
377 (groo_mod_it->second->IsEnabled());
380 if ((nroo_mod_it->second == mod_it->second) && NRooIsEnabled) {
381 ND280NamedVerbose(
"TAnalysisLoop",
382 "No neutrino interaction pass-through information"
384 << module.
GetName() <<
" module, so it will be "
386 nroo_mod_it->second->SetDisabled();
387 ND280NamedLog(
"TAnalysisLoop",
"Deleting pass-through tree for module: "
388 << nroo_mod_it->second->GetName());
389 nroo_mod_it->second->KillOutputTree();
390 NRooIsEnabled =
false;
394 if ((groo_mod_it->second == mod_it->second) && GRooIsEnabled) {
395 ND280NamedVerbose(
"TAnalysisLoop",
396 "No neutrino interaction pass-through information"
398 << module.
GetName() <<
" module, so it will be "
400 groo_mod_it->second->SetDisabled();
401 ND280NamedLog(
"TAnalysisLoop",
"Deleting pass-through tree for module: "
402 << groo_mod_it->second->GetName());
403 groo_mod_it->second->KillOutputTree();
404 GRooIsEnabled =
false;
407 if (!NRooIsEnabled && !GRooIsEnabled) {
410 "No pass through information could be found from the "
411 "neutrino generators. Both RooTracker modules have therefore "
412 "been disabled so no generator information will be available in "
413 "the eventAnalysis file.");
418 "No pass through information has been found for this"
419 " MC file and eventAnalysis is running in production mode, so "
428 throw EProductionException();
443 "Output file not specified. Please use the -o filename option");
453 std::string className(mod_it->first);
485 if (gFile && !gFile->GetDirectory(dirname.c_str())) {
486 ND280NamedVerbose(
"TAnalysisLoop",
"Making " << dirname);
487 gDirectory->mkdir(dirname.c_str());
488 gDirectory->cd(dirname.c_str());
492 gDirectory->cd(dirname.c_str());
496 }
catch (std::exception &ex) {
497 ND280NamedError(
"TAnalysisLoop", ex.what());
498 ND280NamedError(
"TAnalysisLoop",
499 "Disabling module (unable to initialise) "
504 ND280NamedError(
"TAnalysisLoop",
505 "Disabling module (unable to initialise) "
515 ND280NamedLog(
"TAnalysisLoop",
"Begin reading input file");
516 ND::TND280Input *input =
dynamic_cast<ND::TND280Input *
>(vinput);
518 ND280NamedLog(
"TAnalysisLoop",
"Successfully cast TVInputFile");
519 TFile *file = input->GetFilePointer();
521 ND280NamedLog(
"TAnalysisLoop",
"Setting RooTracker module input files.");
526 ->SetBeginFile(file);
532 ->SetBeginFile(file);
543 output->WriteGeometry(
fGeom);
547 std::string utilsdir(
"Config");
548 ND280NamedLog(
"TAnalysisLoop",
"Writing Utils directory: \"" << utilsdir
551 output->mkdir(utilsdir.c_str());
552 if (output->cd(utilsdir.c_str())) {
553 TTree *SubDetectorTree =
554 new TTree(
"ESubdetector",
555 "Tree containing eventAnalysis subdetector enum Definitions.");
558 TObjString *sdetName = 0;
559 SubDetectorTree->Branch(
"ESubdetector_Value", &sdet);
560 SubDetectorTree->Branch(
"ESubdetector_Name", &sdetName);
565 sdet =
static_cast<int>(sdet_it);
566 SubDetectorTree->Fill();
569 TTree *ParticleCategoryTree =
new TTree(
571 "Tree containing eventAnalysis particle category enum Definitions.");
574 TObjString *partName = 0;
575 ParticleCategoryTree->Branch(
"EParticleCategory_Value", &part);
576 ParticleCategoryTree->Branch(
"EParticleCategory_Name", &partName);
581 part_it =
Next(part_it)) {
583 part =
static_cast<int>(part_it);
584 ParticleCategoryTree->Fill();
592 TTree *modConfigTree =
594 (std::string(module.
GetName()) +
"-ConfigTree").c_str());
599 ND280NamedError(
"TAnalysisLoop",
"Failed to make Config directory.");
610 delete mod_it->second;
614 ND280NamedLog(
"TAnalysisLoop",
615 "Total number of events processed in Analysis "
620 output->Delete(
"ND280Events;*");
627 mod_it->second->SetEnabled(mod_it->second->IsEnabledByDefault());
632 std::vector<TAnalysisLoop::ModDescriptor>
const &ModMap,
633 std::string ModuleName) {
635 mod_it != ModMap.end(); ++mod_it) {
636 if (mod_it->first == ModuleName) {
644 std::vector<TAnalysisLoop::ModDescriptor> &ModMap, std::string ModuleName) {
646 mod_it != ModMap.end(); ++mod_it) {
647 if (mod_it->first == ModuleName) {
virtual void Print()
Prints a simple message describing the module.
bool fGeometry
Flag to control saving ND280 geometry.
std::string CurrentlyProcessingModule
Holds the name of the module that is currently executing TAnalysisBase::Process.
virtual bool Process(ND::TND280Event &event)
Gets the run and event IDs and calls FillTree with the event, and then actually calls fOutputTree->Fi...
An analysis module which carries some very simple event-level header information. ...
bool fEnableAll
Enables All modules, if a given module isn't disabled in fUserEnabled.
virtual Bool_t IsEnabled() const
Whether the module is enable or not.
eventAnalysis module for storing the truth information for primary vertices in events ...
Abstract base class for converting the neutrino MC pass-through information into eventAnalysis define...
bool fExit
If set to true during execution will result in execution termination at the end of the next event...
Used to summarise the reconstruction of an event in the P0DECal.
virtual Bool_t IsUsedForPreselection() const
Whether the module should call IsFullEventWorthSaving() function for each event, to decide if the ful...
Responsible for setting up output tree, looping over oaEvent containers, and filling output objects...
A base class for classes which specify how to set up an Analysis format output tree, and fill it.
virtual void SetDisabled()
Disables the module.
std::string DetectorName(ESubdetector const subdet)
std::vector< ModDescriptor > fAnalysisModules
Internal map of all modules.
bool fSaveOutputOaEventTree
Set automatically if the oaEvent tree needs to be saved in output file.
TGeoManager * fGeom
The ND280 geometry to be saved.
TAnalysisLoop()
Initialize any class specific variables.
Used to fill a TTree of summary information for the SFG reconstruction algorithms.
int EventNumber
Holds the number of processed events.
void SetModuleDefaults()
Method to set the the default enable/disable values for all modules in fAnalysisModules map...
Used to fill a TTree of summary information for the P0D reconstruction algorithms.
std::string const GetDirectoryName() const
Returns the name of the directory which the output of a particular module will be saved in...
int fEventCount
Keep track of the events that have been read.
virtual void SetUsedForPreselection(Bool_t isused=true)
Sets whether the module should call IsFullEventWorthSaving() function for each event, to decide if the full oaEvent info for that event should be saved in the output.
This module summarizes the information from global reconstruction.
bool fSaveOriginalFullEvent
Flag if the full event (not the analysis format) is also to be saved This overrides any -preselection...
bool operator()(ND::TND280Event &event)
Called for each event inside the event loop, and returns true if the event should be saved to the out...
ESubdetector Next(ESubdetector const subdet)
virtual void SetEnabled(Bool_t isenabled=true)
Sets whether the module is enabled.
std::map< std::string, bool > fUserEnabled
Store whether a module has been set to disabled/enables by user as well as whether the disable/enable...
bool fProduction
Controls production mode.
TTRExReconModule - Object that contains information related to reconstructed object from the extende...
virtual void BeginFile(ND::TVInputFile *input)
Called before the first event of a file is read, but you should prefer TAnalysisLoop::Initialize for ...
std::string ParticleName(EParticleCategory const category)
Summary information from smrdRecon output.
void Initialize(TTree *tree)
virtual Bool_t ProcessFirstEvent(ND::TND280Event &)=0
Is called after the first event is loaded in.
virtual void Finalize(ND::TND280Output *const output)
An analysis module which carries some low level hit information.
virtual void EndFile(ND::TVInputFile *)
Called after the last event of a file is read, but you should prefer TAnalysisLoop: Finalize() for ge...
void Usage(void)
Print a usage message.
The eventAnalysis module responsible for saving information about the True Particles in an event from...
std::vector< ModDescriptor >::iterator ModDescripterator
Private typedef which makes talking to fAnalysisModules slightly nicer.
bool fDisableAll
This is overridden by fEnableAll.
virtual void Initialize(void)
Called after the arguments are processes by before reading the first event.
bool StopProcessing
Used to notify the event loop to stop processing events and finish quickly.
This module summarizes the reconstruction information from the trackerRecon.
bool fValidation
Control validation mode.
ModDescripterator FindNamedModule(std::vector< TAnalysisLoop::ModDescriptor > &ModMap, std::string ModuleName)
Searches through TAnalysisLoop::fAnalysisModules for a street module named Bob.
std::vector< ModDescriptor >::const_iterator CModDescripterator
Private typedef which makes talking to fAnalysisModules slightly nicer.
virtual bool SetOption(std::string, std::string)
Set an option and return true if it is valid.
bool PreselectionSorter(std::pair< std::string, ND::TAnalysisModuleBase * > const &LHS, std::pair< std::string, ND::TAnalysisModuleBase * > const &RHS)
Used to sort Preselecting modules to the end of the vector.
virtual void FillConfigTree(TTree *)