31#include "BDSOutputROOTEventHeader.hh"
32#include "BDSOutputROOTEventOptions.hh"
33#include "BDSOutputROOTEventModel.hh"
36#include "BeamAnalysis.hh"
38#include "DataLoader.hh"
39#include "EventAnalysis.hh"
40#include "HeaderAnalysis.hh"
41#include "ModelAnalysis.hh"
42#include "OptionsAnalysis.hh"
43#include "RBDSException.hh"
44#include "RebdsimTypes.hh"
45#include "RunAnalysis.hh"
47int main(
int argc,
char *argv[])
50 if (argc < 2 || argc > 4)
52 std::cout <<
"usage: rebdsim <analysisConfig> (<dataFile>) (<outputFile>)" << std::endl;
53 std::cout <<
" <datafile> (optional) - root file to operate on" << std::endl;
54 std::cout <<
" <outputfile> (optional) - output file name for analysis" << std::endl;
55 std::cout <<
" if no <datafile> and <outputfile> are specified, those from <analysisConfig> are used." << std::endl;
59 std::string configFilePath = std::string(argv[1]);
60 std::string configFileExtension = configFilePath.substr(configFilePath.find_last_of(
'.') + 1) ;
61 if (configFileExtension !=
"txt")
63 std::cerr <<
"Unrecognised extension for file: " << configFilePath <<
". Extension: " << configFileExtension << std::endl;
64 std::cerr <<
"Make sure the config file is plain text with the .txt extension!" << std::endl;
68 std::cout <<
"rebdsim> configuration file name : " << configFilePath << std::endl;
70 std::string inputFilePath =
"";
71 std::string outputFileName =
"";
74 {inputFilePath = std::string(argv[2]);}
76 {outputFileName = std::string(argv[3]);}
86 {std::cerr << error.
what() << std::endl; exit(1);}
87 catch (
const std::exception& error)
88 {std::cerr << error.what() << std::endl; exit(1);}
93 bool debug = config->
Debug();
105 {std::cerr << error.
what() << std::endl; exit(1);}
106 catch (
const std::exception& error)
107 {std::cerr << error.what() << std::endl; exit(1);}
113 unsigned long long int nOriginalEvents = ha->CountNOriginalEvents();
134 {std::cerr << error.
what() << std::endl; exit(1);}
148 std::vector<Analysis*> analyses = {beaAnalysis,
154 for (
auto& analysis : analyses)
160 TFile* outputFile =
new TFile(config->
OutputFileName().c_str(),
"RECREATE");
168 TTree* headerTree =
new TTree(
"Header",
"REBDSIM Header");
169 headerTree->Branch(
"Header.",
"BDSOutputROOTEventHeader", headerOut);
171 headerTree->Write(
"", TObject::kOverwrite);
173 for (
auto& analysis : analyses)
174 {analysis->Write(outputFile);}
178 TTree* treeTest = modelTree->GetTree();
181 auto newTree = modelTree->CloneTree();
184 newTree->SetName(
"ModelTree");
185 newTree->Write(
"", TObject::kOverwrite);
190 std::cout <<
"Result written to: " << config->
OutputFileName() << std::endl;
193 {std::cerr << error.
what() << std::endl; exit(1);}
194 catch (
const std::exception& error)
195 {std::cerr << error.what() << std::endl; exit(1);}
198 for (
auto analysis : analyses)
virtual void Execute()
Method which calls all other methods in order.
Analysis of the options tree.
Configuration and configuration parser class.
std::string InputFilePath() const
Accessor.
bool PerEntryEvent() const
bool AllBranchesToBeActivated() const
bool GetOptionBool(const std::string &key) const
General accessor for option.
double PrintModuloFraction() const
Accessor.
static Config * Instance(const std::string &fileName="", const std::string &inputFilePath="", const std::string &outputFileName="", const std::string &defaultOutputFileSuffix="_ana")
Singleton accessor.
bool PerEntryModel() const
bool PerEntryOption() const
double GetOptionNumber(const std::string &key) const
General accessor for option.
bool Debug() const
Accessor.
bool PerEntryBeam() const
std::string OutputFileName() const
Accessor.
bool ProcessSamplers() const
Accessor.
const RBDS::VectorString & BranchesToBeActivated(const std::string &treeName) const
Loader for a ROOT file using classes used to generate the file.
std::vector< std::string > GetFileNames()
Accessor.
Event * GetEvent()
Accessor.
Beam * GetBeam()
Accessor.
Header * GetHeader()
Accessor.
TChain * GetBeamTree()
Accessor.
TChain * GetOptionsTree()
Accessor.
TChain * GetRunTree()
Accessor.
TChain * GetModelTree()
Accessor.
Options * GetOptions()
Accessor.
TChain * GetEventTree()
Accessor.
Model * GetModel()
Accessor.
TChain * GetHeaderTree()
Accessor.
Analysis of the model tree.
Analysis of the options tree.
General exception with possible name of object and message.
const char * what() const noexcept override
Override message in std::exception.