93 const std::vector<Double_t>& matrices,
94 const std::map<Int_t, Int_t>& overrides,
95 Bool_t logInterpolation) {
98 const size_t n = energies.size();
99 if (n == 0) Invalid(
"no energy points");
100 if (matrices.size() != 9 * n) {
101 Invalid(
"expected " + std::to_string(9 * n) +
102 " matrix values (9 per energy point), got " +
103 std::to_string(matrices.size()));
105 for (
size_t k = 0; k < n; ++k) {
106 std::ostringstream where;
107 where <<
"energy point " << k <<
" (" << energies[k] <<
" GeV)";
108 if (!std::isfinite(energies[k])) Invalid(where.str() +
": not finite");
109 if (k > 0 && energies[k] <= energies[k - 1]) {
110 Invalid(where.str() +
": energies must be strictly increasing");
112 if (logInterpolation && energies[k] <= 0.) {
113 Invalid(where.str() +
": log interpolation needs positive energies");
116 const std::string row = where.str() +
", true " +
SpeciesName(i) +
" row";
119 const double x = matrices[9 * k +
static_cast<size_t>(3 * i + j)];
120 if (!std::isfinite(x)) Invalid(row +
": entry not finite");
121 if (x < 0.) Invalid(row +
": negative entry");
124 if (std::fabs(sum - 1.) > kRowSumTolerance) {
125 std::ostringstream os;
126 os << row <<
" sums to " << sum <<
", expected 1";
131 std::map<Int_t, Int_t> byAbsPdg;
132 for (
const auto& [pdg, species] : overrides) {
133 if (species < kUnknown || species >=
kNSpecies) {
134 Invalid(
"override for PDG code " + std::to_string(pdg) +
": species " +
135 std::to_string(species) +
136 " is not -1 (unknown), 0 (electron), 1 (hadron) or 2 (muon)");
138 const auto [it, inserted] = byAbsPdg.emplace(std::abs(pdg), species);
139 if (!inserted && it->second != species) {
140 Invalid(
"conflicting overrides for |PDG code| " +
141 std::to_string(std::abs(pdg)));