Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
CorrelationAdapter.cpp
Go to the documentation of this file.
2#include "ExperimentObs.h"
3
5 std::shared_ptr<CorrelationMatrixPair<ParamId>>, fs::path, bool);
6
7// template void CorrelationLoader<ExperimentObs>::load(
8// std::shared_ptr<CorrelationMatrixPair<ExperimentObs>>, fs::path, bool);
9
10template <typename T>
12 fs::path src_file,
13 bool block_in_blocks) {
15 auto src = np->provide_db_as_node();
16
17 for (auto &list_item : src->getGroup({"correlations"})) {
18 emplace_correlation(dest, std::get<std::shared_ptr<DBNode>>(list_item.second));
19 }
20}
21
22template<>
24 std::shared_ptr<CorrelationMatrixPair<ParamId>> corr_matrices,
25 std::shared_ptr<DBNode> leaf) {
26
27 auto parse_pid = [leaf](size_t i) {
28 DBNode::Value id_value = leaf->get("id_" + std::to_string(i));
29 LhaID id;
30
31 if (std::holds_alternative<int>(id_value)) {
32 id = LhaID{std::get<int>(id_value)};
33 } else {
34 id = LhaID{std::get<BlockName>(id_value)};
35 }
36
37 auto block = std::get<BlockName>(leaf->get("block_" + std::to_string(i)));
38 return ParamId{ParamRouter::GetType(block, id), block, id};
39 };
40
41 if (!leaf->contains("block_1") || !leaf->contains("block_2")
42 || !leaf->contains("id_1") || !leaf->contains("id_2")
43 || !leaf->contains("stat_correlation")) {
44 LOG_ERROR("CorrelationLoader",
45 "DBNode doesn't have all necessary keys for parameter correlation.");
46 return;
47 }
48
49 ParamId pid_1 = parse_pid(1);
50 ParamId pid_2 = parse_pid(2);
51
52 auto stat_value = std::get<double>(leaf->get("stat_correlation"));
53 auto syst_value = leaf->contains("syst_correlation")
54 ? std::get<double>(leaf->get("syst_correlation"))
55 : 0.0;
56
57 corr_matrices->emplace(std::make_pair(pid_1, pid_2), stat_value, syst_value);
58}
59
60template<>
62 std::shared_ptr<CorrelationMatrixPair<ExperimentObs>> dest,
63 fs::path src_file,
64 bool block_in_blocks) {
65
67 auto src = np->provide_db_as_node();
68
69 if (!src->contains("correlations")) {
70 LOG_ERROR("CorrelationLoader",
71 "DBNode doesn't contain 'correlations' for observable correlations.");
72 return;
73 }
74
75 // Nouveau format :
76 // {
77 // "correlations": {
78 // "DEFAULT": [ ... ],
79 // "DEFAULT2": [ ... ]
80 // }
81 // }
82
83 for (auto &exp_item : src->getGroup({"correlations"})) {
84 const std::string experiment = exp_item.first;
85
86 for (auto &list_item : src->getGroup({"correlations", experiment})) {
87 auto leaf = std::get<std::shared_ptr<DBNode>>(list_item.second);
88
89 if (!leaf->contains("id_1") || !leaf->contains("id_2")
90 || !leaf->contains("stat_correlation")) {
91 LOG_ERROR("CorrelationLoader",
92 "DBNode doesn't have all necessary keys for observable correlation.");
93 continue;
94 }
95
96 BinnedObservableId obs_1 =
97 BinnedObservableId::from_flha(LhaID(std::get<BlockName>(leaf->get("id_1"))));
98 BinnedObservableId obs_2 =
99 BinnedObservableId::from_flha(LhaID(std::get<BlockName>(leaf->get("id_2"))));
100
101 auto stat_value = std::get<double>(leaf->get("stat_correlation"));
102 auto syst_value = leaf->contains("syst_correlation")
103 ? std::get<double>(leaf->get("syst_correlation"))
104 : 0.0;
105
106 dest->emplace(
107 std::make_pair(
108 ExperimentObs{experiment, obs_1},
109 ExperimentObs{experiment, obs_2}
110 ),
111 stat_value,
112 syst_value
113 );
114 }
115 }
116}
Experiment-scoped observable identifiers.
#define LOG_ERROR(type,...)
Macro for logging error messages and terminating the application.
Definition Logger.h:41
Loader class to populate CorrelationMatrixPair from a file.
void load(std::shared_ptr< CorrelationMatrixPair< T > > dest, fs::path src_file, bool block_in_blocks=false) override
Loads correlation matrices from a source file into a destination CorrelationMatrixPair.
static std::shared_ptr< IDBNodeProvider > createDBNodeProvider(fs::path src_path)
Creates an IDBNodeProvider for a given file path.
std::variant< BlockName, int, double, bool, std::shared_ptr< DBNode >, std::vector< std::shared_ptr< DBNode > > > Value
Variant type used to store values in the tree.
Definition DBNode.h:45
static ParameterType GetType(BlockName block, LhaID id)
Determines the ParameterType of a given (block, LhaID) pair.
Identifies an observable together with a numerical bin.
static BinnedObservableId from_flha(LhaID const &id)
Reconstructs a binned observable identifier from an FLHA encoding.
Stores a pair of correlation matrices (statistical and systematic) for a given key type.
Represents an identifier of a LHA element, possibly containing several sub-ids.
Definition LhaID.h:56
Composite identifier for a single parameter.
Definition ParamID.h:57