MaCh3  2.5.0
Reference Guide
Manager.cpp
Go to the documentation of this file.
1 #include "Manager/Manager.h"
2 
4 // ROOT include
5 #include "TFile.h"
7 
8 // *************************
9 Manager::Manager(const YAML::Node ConfigNode) {
10 // *************************
11  config = ConfigNode;
12  FileName = "unknown";
13 
14  Initialise();
15 }
16 
17 // *************************
19 // *************************
22 
23  MACH3LOG_INFO("Setting config to be: {}", FileName);
24 
25  MACH3LOG_INFO("Config is now: ");
27 }
28 
29 
30 // *************************
31 // Empty destructor, for now...
33 // *************************
34 }
35 
36 // *************************
37 // Save all the settings of the class to an output file
38 // Reflection in C++ is a bit of a pain :(
39 // Outputfile is the TFile pointer we write to
40 void Manager::SaveSettings(TFile* const OutputFile) const {
41 // *************************
42  std::string OutputFilename = std::string(OutputFile->GetName());
43  OutputFile->cd();
44 
45  // EM: embed the config used for this app
46  TMacro ConfigSave = YAMLtoTMacro(config, "MaCh3_Config");
47  ConfigSave.Write();
48 
49  // The Branch!
50  TTree *SaveBranch = new TTree("Settings", "Settings");
51 
52  // Fill the doubles
53  SaveBranch->Branch("Output", &OutputFilename);
54 
55  // Get settings defined by pre-processor directives, e.g. CPU MP and GPU
56  #ifdef MULTITHREAD
57  bool cpu_mp_on = true;
58  int n_cpus = omp_get_max_threads();
59  #else
60  bool cpu_mp_on = false;
61  int n_cpus = 1;
62  #endif
63 
64  #ifdef MaCh3_CUDA
65  bool gpu_on = true;
66  #else
67  bool gpu_on = false;
68  #endif
69 
70  SaveBranch->Branch("GPU", &gpu_on);
71  SaveBranch->Branch("CPUMP", &cpu_mp_on);
72  SaveBranch->Branch("nCPUs", &n_cpus);
73 
74  SaveBranch->Fill();
75  SaveBranch->Write();
76 
77  delete SaveBranch;
78 }
79 
80 // *************************
81 void Manager::Print() const {
82 // *************************
83  MACH3LOG_INFO("---------------------------------");
85  MACH3LOG_INFO("---------------------------------");
86 }
87 
88 // *************************
89 int Manager::GetMCStatLLH() const {
90 // *************************
91  int mc_stat_llh = kNTestStatistics;
92  if (config["LikelihoodOptions"])
93  {
94  auto likelihood = GetFromManager<std::string>(config["LikelihoodOptions"]["TestStatistic"], "Barlow-Beeston", __FILE__ , __LINE__);
95  mc_stat_llh = TestStatFromString(likelihood);
96  } else {
97  MACH3LOG_WARN("Didn't find a TestStatistic specified");
98  MACH3LOG_WARN("Defaulting to using a {} likelihood", TestStatistic_ToString(kPoisson));
99  mc_stat_llh = kPoisson;
100  }
101  return mc_stat_llh;
102 }
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
Definition: Core.h:126
#define _MaCh3_Safe_Include_End_
KS: Restore warning checking after including external headers.
Definition: Core.h:141
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:35
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
Definition: MaCh3Logger.h:61
#define MACH3LOG_WARN
Definition: MaCh3Logger.h:36
TestStatistic TestStatFromString(const std::string &likelihood)
Convert a string to a TestStatistic enum.
std::string TestStatistic_ToString(const TestStatistic TestStat)
Convert a LLH type to a string.
@ kNTestStatistics
Number of test statistics.
@ kPoisson
Standard Poisson likelihood .
TMacro YAMLtoTMacro(const YAML::Node &yaml_node, const std::string &name)
Convert a YAML node to a ROOT TMacro object.
Definition: YamlHelper.h:167
void Initialise()
Common inialiser for both constructors.
Definition: Manager.cpp:18
int GetMCStatLLH() const
Get likelihood type defined in the config.
Definition: Manager.cpp:89
virtual ~Manager()
Destroys the manager object.
Definition: Manager.cpp:32
YAML::Node config
The YAML node containing the configuration data.
Definition: Manager.h:66
Manager(std::string const &filename)
Constructs a manager object with the specified file name.
Definition: Manager.h:20
void SaveSettings(TFile *const OutputFile) const
Add manager useful information's to TFile, in most cases to Fitter.
Definition: Manager.cpp:40
std::string FileName
The name of the configuration file.
Definition: Manager.h:68
void Print() const
Print currently used config.
Definition: Manager.cpp:81
void PrintConfig(const YAML::Node &node)
KS: Print Yaml config using logger.
Definition: Monitor.cpp:311
void MaCh3Welcome()
KS: Prints welcome message with MaCh3 logo.
Definition: Monitor.cpp:13