7 std::unique_ptr<FitterBase> MaCh3Fitter =
nullptr;
9 auto Algorithm = GetFromManager<std::string>(fitMan->
raw()[
"General"][
"FittingAlgorithm"],
"MCMC");
11 if(Algorithm ==
"MCMC") {
12 MaCh3Fitter = std::make_unique<mcmc>(fitMan);
13 }
else if (Algorithm ==
"PSO") {
14 MaCh3Fitter = std::make_unique<PSO>(fitMan);
15 }
else if (Algorithm ==
"Minuit2") {
17 MaCh3Fitter = std::make_unique<MinuitFit>(fitMan);
19 MACH3LOG_ERROR(
"Trying to use Minuit2 however MaCh3 was compiled without Minuit2 support");
23 MACH3LOG_ERROR(
"You want to use algorithm {}, I don't recognize it, sry", Algorithm);
35 MACH3LOG_ERROR(
"Where config.yaml is a valid config file, compatible with the manager class (manager/manager.cpp/h)");
40 if (argc >= 4 && std::string(argv[2]) ==
"--override") {
41 const std::string overrideFile = argv[3];
42 MACH3LOG_INFO(
"Merging configuration files: base config '{}', override config '{}'. "
43 "Options in '{}' will take precedence over '{}'.",
44 argv[1], overrideFile, overrideFile, argv[1]);
47 MACH3LOG_ERROR(
"Too many arguments provided when using '--override'. "
48 "Expected only two config files. "
49 "If using override feature, you cannot provide any additional arguments.");
57 YAML::Node merged =
MergeNodes(config1, config2);
58 auto FitManager = std::make_unique<manager>(merged);
64 auto FitManager = std::make_unique<manager>(argv[1]);
67 auto SanityOverwrite = [](
const std::string& Name) {
68 if (Name.find(
"Systematics") != std::string::npos ||
69 Name.find(
"Samples") != std::string::npos)
71 MACH3LOG_CRITICAL(
"You are overwriting settings ({}) that are highly likely intended to be committed.", Name);
76 for (
int i = 2; i < argc; ++i)
78 const std::string arg = argv[i];
79 const size_t colonCount = std::count(arg.begin(), arg.end(),
':');
82 if (colonCount == 1) {
83 const size_t firstColon = arg.find(
':');
84 const std::string section = arg.substr(0, firstColon);
85 const std::string value = arg.substr(firstColon + 1);
87 MACH3LOG_INFO(
"Overriding setting: Section={}, Value={}", section, value);
88 SanityOverwrite(section);
89 FitManager->OverrideSettings(section, value);
90 }
else if (colonCount == 2) {
91 const size_t firstColon = arg.find(
':');
92 const size_t secondColon = arg.find(
':', firstColon + 1);
94 const std::string section = arg.substr(0, firstColon);
95 const std::string key = arg.substr(firstColon + 1, secondColon - firstColon - 1);
96 const std::string value = arg.substr(secondColon + 1);
98 MACH3LOG_INFO(
"Overriding setting: Section={}, Key={}, Value={}", section, key, value);
99 SanityOverwrite(section);
100 SanityOverwrite(key);
101 FitManager->OverrideSettings(section, key, value);
102 }
else if (colonCount == 3) {
103 const size_t firstColon = arg.find(
':');
104 const size_t secondColon = arg.find(
':', firstColon + 1);
105 const size_t thridColon = arg.find(
':', secondColon + 1);
107 const std::string section = arg.substr(0, firstColon);
108 const std::string key = arg.substr(firstColon + 1, secondColon - firstColon - 1);
109 const std::string key2 = arg.substr(secondColon + 1, thridColon - secondColon - 1);
110 const std::string value = arg.substr(thridColon + 1);
112 MACH3LOG_INFO(
"Overriding setting: Section={}, Key={}, Key={}, Value={}", section, key, key2, value);
113 SanityOverwrite(section);
114 SanityOverwrite(key);
115 SanityOverwrite(key2);
116 FitManager->OverrideSettings(section, key, key2, value);
119 MACH3LOG_ERROR(
"Expected format:Section:Key:Key:Value, Section:Key:Value or Section:Value");
std::unique_ptr< FitterBase > MaCh3FitterFactory(manager *fitMan)
std::unique_ptr< manager > MaCh3ManagerFactory(int argc, char **argv)
Factory methods for MaCh3 software which streamline initialisation of different objects.
#define MACH3LOG_CRITICAL
YAML::Node MergeNodes(YAML::Node a, YAML::Node b)
KS: Recursively merges two YAML nodes.
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Custom exception class for MaCh3 errors.
The manager class is responsible for managing configurations and settings.
YAML::Node const & raw()
Return config.