6 std::map<std::string, std::vector<double>> orderedTunes;
9 for (
const auto& sysNode : Settings) {
10 const auto& values = sysNode[
"Systematic"][
"ParameterValues"];
12 for (
const auto& tuneNode : values) {
13 std::string key = tuneNode.first.as<std::string>();
14 if (key ==
"PreFitValue")
continue;
16 double val = tuneNode.second.as<
double>();
17 orderedTunes[key].push_back(val);
21 size_t expectedSize = 0;
22 bool hasMismatch =
false;
23 std::ostringstream errorMsg;
24 errorMsg <<
"Inconsistent number of parameter values across tunes:\n";
26 for (
const auto& kv : orderedTunes) {
27 const auto& vals = kv.second;
28 if (expectedSize == 0) {
29 expectedSize = vals.size();
30 }
else if (vals.size() != expectedSize) {
33 errorMsg <<
" - Tune '" << kv.first <<
"': " << vals.size() <<
" values\n";
37 errorMsg <<
"Expected all tunes to have " << expectedSize <<
" values.";
43 for (
const auto& kv : orderedTunes) {
51 for (
size_t i = 0; i <
TuneNames.size(); ++i) {
66std::vector<double> ParameterTunes::ParameterTunes::GetTune(
const int TuneNumber)
const {
68 if (TuneNumber >=
static_cast<int>(TuneValues.size())) {
69 MACH3LOG_ERROR(
"I only have {} tune(s), but you asked for index {}", TuneValues.size(), TuneNumber);
73 return TuneValues[TuneNumber];
77std::vector<double> ParameterTunes::ParameterTunes::GetTune(
const std::string& TuneName)
const {
79 auto it = TuneMap.find(TuneName);
80 if (it == TuneMap.end()) {
81 MACH3LOG_ERROR(
"Tune '{}' not found. Available tunes: {}", TuneName, fmt::join(TuneNames,
", "));
85 return GetTune(it->second);
89void ParameterTunes::ParameterTunes::PrintTunes()
const {
92 for (
size_t i = 0; i < TuneNames.size(); ++i) {
94 for (
size_t j = 0; j < TuneValues[i].size(); ++j) {
Custom exception class for MaCh3 errors.
ParameterTunes(const YAML::Node &Settings)
Constructor.
std::vector< std::string > TuneNames
Name of each Tun.
void PrintTunes() const
Simply print all tunes and associated values.
virtual ~ParameterTunes()
std::unordered_map< std::string, int > TuneMap
Map between tune name and value.
std::vector< std::vector< double > > TuneValues
Values for each Tune and Parameter.