Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
main_core.cpp
Go to the documentation of this file.
1#include "HyperisoMaster.h"
2#include "ParameterProvider.h"
3#include "Include.h"
4#include "Logger.h"
6#include "QCDProvider.h"
7#include "ParameterSetter.h"
8#include "BlockProvider.h"
9#include "ParamBlockWriter.h"
10#include "JsonParser.h"
11#include "YamlParser.h"
12#include "LhaParser.h"
13#include "FileWriter.h"
14
15static ParamId make_id(ParameterType t, const char* block, int code) {
16 return ParamId(t, BlockName(block), LhaID(code));
17}
18
19int main() {
21 HyperisoConfig config;
22 config.model = Model::SM;
23
25
27 hi.init("lha/testInput.flha", config);
28
30
34
35 auto obs_p = obs.get_parameter({ParameterType::OBSERVABLE, "FOBS", {521, 2, 3, 321, 13}});
36 LOG_INFO(*obs_p);
37 auto bin = obs_p->get_bin();
38 LOG_INFO("A_FB(B > K mu mu) = [", bin.first, ",", bin.second, "] =", obs_p->get_val());
39
40
41 // 521_11_3_423_-15_16
42
43 auto obs_p2 = obs.get_parameter({ParameterType::OBSERVABLE, "FOBS", {521, 11, 3, 423, -15, 16}});
44 LOG_INFO(*obs_p2);
45 auto bin2 = obs_p2->get_bin();
46 LOG_INFO("A_FB(B > K mu mu) = [", bin2.first, ",", bin2.second, "] =", obs_p2->get_val());
47
48 LOG_INFO(sm("SMINPUTS", 6));
49
51 std::unordered_map<ParameterType, std::vector<std::string>> src = {{ParameterType::SM, {"SMINPUTS", "MASS"}}};
52
53 auto func = [] (const BlockSrc& src, std::shared_ptr<DependentBlock> dep_block) {
54 QCDProvider qcd;
55 auto xt = std::pow(qcd(MassConfig{6, 80, MassType::MSBAR, MassType::POLE}) / src.get_val("MASS",24), 2);
56 dep_block->store_or_assign(1, std::make_shared<Parameter>(Parameter({ParameterType::WILSON, "WPARAM", 1}, xt, 0., 0.)));
57 };
58 cpc.add_block_dependency("WPARAM", src, ParameterType::WILSON, func);
59
61 LOG_INFO("Before: m_W =", sm("MASS", 24), ", x_t =", wil("WPARAM", 1));
62 ps.mutate({ParameterType::SM, "MASS", 24}, 100);
63 LOG_INFO("After: m_W =", sm("MASS", 24), ", x_t =", wil("WPARAM", 1));
64
65 std::shared_ptr<DBNode> node = std::make_shared<DBNode>();
66 std::shared_ptr<BlockAccessor> acc = MemoryManager::GetInstance()->extract_block_accessor();
67 ParamBlockWriter().write(node, acc);
68
69 std::cout << "writing to file.." << std::endl;
70 hi.switch_lha("lha/si_input.flha", config);
71 JSONParser().writeToFile("test.json", node);
72 YAMLParser().writeToFile("test.yaml", node);
73 LhaParser().writeToFile("test.flha", node);
74
75 FileWriter().write("test2.json");
76 FileWriter().write("test2.yaml");
77 FileWriter().write("test2.flha");
78
79
80 try {
81 auto src = std::make_shared<Block>();
82 src->blockname = "SRC";
83
84 ParamId x_id = make_id(ParameterType::SM, "SRC", 1);
85 auto x = std::make_shared<Parameter>(x_id, 1.0, 0.0, 0.0);
86 src->store(LhaID(1), x);
87
88 std::unordered_map<std::string, std::shared_ptr<Block>> blk_sources;
89 blk_sources.emplace("SRC", src);
90
91 DepUpdateFunc blk_recalc = DepUpdateFunc(
92 [](const BlockSrc& srcs, std::shared_ptr<DependentBlock> self) {
93 auto s = srcs.block("SRC");
94 double xv = s->retrieve(LhaID(1))->get_val();
95
96 if (!self->contains(LhaID(1))) {
97 ParamId a_id(ParameterType::SM, BlockName("DBLK"), LhaID(1));
98 auto a = std::make_shared<Parameter>(a_id, xv + 10.0, 0.0, 0.0);
99 self->store(LhaID(1), a);
100 } else {
101 self->retrieve(LhaID(1))->set_expected(xv + 10.0);
102 }
103 }
104 );
105
106 auto dblk = std::make_shared<DependentBlock>(blk_sources, blk_recalc);
107 dblk->blockname = "DBLK";
108 dblk->init();
109 dblk->update();
110
111 ParamId a_id = make_id(ParameterType::SM, "DBLK", 1);
112 ParamId y_id = make_id(ParameterType::SM, "Y", 1);
113
114 std::unordered_map<ParamId, std::shared_ptr<Parameter>> psources;
115 psources.emplace(a_id, dblk->retrieve(LhaID(1)));
116
118 [a_id](const ParamSrc& srcs, std::shared_ptr<DependentParameter> self) {
119 double av = srcs.get_val(a_id);
120 self->set_expected(2.0 * av + 1.0);
121 }
122 );
123
124 auto y = std::make_shared<DependentParameter>(y_id, psources, y_recalc);
125 y->init();
126 y->update();
127
128 auto out = std::make_shared<Block>();
129 out->blockname = "OUT";
130 out->store(LhaID(1), y);
131
132 double y0 = out->retrieve(LhaID(1))->get_val();
133 std::cout << "y0 = " << y0 << " (expect 23)\n";
134
135 src->assign(LhaID(1), 2.0);
136
137 double a1 = dblk->retrieve(LhaID(1))->get_val();
138 std::cout << "a after x=2 => " << a1 << " (expect 12)\n";
139 double y1 = out->retrieve(LhaID(1))->get_val();
140 std::cout << "y1 = " << y1 << " (expect 25)\n";
141
142 if (std::abs(y0 - 23.0) > 1e-9) {
143 std::cerr << "[FAIL] y0 != 23\n";
144 return 1;
145 }
146 if (std::abs(y1 - 25.0) > 1e-9) {
147 std::cerr << "[FAIL] y1 != 25 -> cascade broken (block->param)\n";
148 return 2;
149 }
150
151 std::cout << "[OK] DependentBlock + DependentParameter cascade works.\n";
152 return 0;
153 }
154 catch (const std::exception& e) {
155 std::cerr << "Exception: " << e.what() << "\n";
156 return 99;
157 }
158 return 0;
159}
Concrete implementation of IBlockProvider for HyperISO parameter blocks.
std::function< void(const BlockSrc &, std::shared_ptr< DependentBlock >)> DepUpdateFunc
Function type used to recompute a DependentBlock from its sources.
Definition Block.h:56
@ HAS_WILSON_INPUT
User provided Wilson coefficient input.
std::function< void(const ParamSrc &, std::shared_ptr< DependentParameter >)> DepParamUpdateFunc
Function signature used to recompute a DependentParameter.
Export the current HyperIso parameter database to JSON, YAML or LHA.
ParameterType
High-level helpers for initializing and monitoring the Hyperiso framework.
Lightweight JSON parser/serializer for DBNode trees.
Parser for LHA / FLHA-style files into LhaBlock structures and DBNode trees.
#define LOG_INFO(...)
Macro for logging informational messages.
Definition Logger.h:39
Write parameter blocks from a BlockAccessor into a DBNode.
High-level access to parameter values and uncertainties.
High-level access to QCD quantities like α_s and running quark masses.
Lightweight YAML parser/serializer for DBNode trees.
Block identifier with alias support.
Definition BlockName.h:59
Block provider bound to HyperISO Parameters / ParameterType.
void log_all_blocks(ParameterType type) override
Logs all blocks for a given ParameterType.
Lightweight view over a set of source blocks.
Definition SourcesView.h:71
scalar_t get_val(std::string_view blk, std::initializer_list< long > code) const
Retrieves the value of a parameter given as an initializer_list.
const std::shared_ptr< Block > & block(std::string_view name) const
Returns a reference to a block by name.
Concrete implementation of IDependency using DependentBlockManager.
void add_block_dependency(const BlockName &name, const std::unordered_map< ParameterType, std::vector< std::string > > &source_names, ParameterType dest, DepUpdateFunc recalculateFunc) override
Adds a dependent block using DependentBlockManager.
void write(const std::string &dest, std::shared_ptr< BlockAccessor > src=nullptr) override
Export all blocks from an accessor or from the current database.
High-level interface to initialize and monitor the main framework configuration.
void init(const std::string &lhaFile, HyperisoConfig config)
Initializes Hyperiso using a LHA file and a full Config object.
void switch_lha(const std::string &lhaFile, HyperisoConfig config)
Switches the LHA file and applies a new configuration.
JSON implementation of the IParser interface.
Definition JsonParser.h:42
void writeToFile(const std::string &filename, const std::shared_ptr< DBNode > &root) const override
Serializes a DBNode tree to a JSON file.
Parser for LHA/FLHA files, producing blocks and a DBNode representation.
Definition LhaParser.h:113
void writeToFile(const std::string &filename, const std::shared_ptr< DBNode > &root) const
Serializes a DBNode structure back to an LHA-like file.
void setLevel(LogLevel level)
Sets the logging level.
Definition Logger.cpp:38
static Logger * getInstance()
Retrieves the singleton instance of the Logger.
Definition Logger.cpp:5
std::shared_ptr< BlockAccessor > extract_block_accessor()
Extracts all blocks from the cached input.
static MemoryManager * GetInstance()
Retrieves the singleton instance of MemoryManager.
Writer class to populate a DbNode from a BlockAccessor.
void write(std::shared_ptr< DBNode > dest, std::shared_ptr< BlockAccessor > src) override
Write node parameters from a BlockAccessor into the given destination node.
Lightweight view over a set of source parameters keyed by ParamId.
Provides access to parameter values, errors, and existence checks.
std::shared_ptr< Parameter > get_parameter(const ParamId &pid) const
Retrieves the actual Parameter object corresponding to the given ParamId.
Concrete mutator that directly sets the value of parameters.
void mutate(const ParamId &pid, scalar_t value) override
Sets the value of a parameter.
Represents a single parameter with value, uncertainties, and dependency links.
Definition Parameter.h:78
Provides strong coupling constant and MS-bar mass values at various energy scales.
Definition QCDProvider.h:45
YAML implementation of the IParser interface.
Definition YamlParser.h:39
void writeToFile(const std::string &filename, const std::shared_ptr< DBNode > &root) const override
Writes a DBNode hierarchy to a YAML file.
int main()
Definition main_core.cpp:19
Configuration object controlling model, input flags and optional MARTY resources.
Definition Config.h:24
std::map< ExternalFlag, bool > flags
External flags describing the nature of the inputs.
Definition Config.h:26
Model model
Current model.
Definition Config.h:33
Represents an identifier of a LHA element, possibly containing several sub-ids.
Definition LhaID.h:56
Configuration for computing a particle mass at a given scale.
Definition Configs.h:242
Composite identifier for a single parameter.
Definition ParamID.h:57