Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
ObservableHandler.cpp
Go to the documentation of this file.
1#include "ObservableHandler.h"
2
3#include <iostream>
4#include <sstream>
5#include <vector>
6
7#include "CliUtils.h"
9#include "mapper_hub.hpp"
10
11namespace {
12
13void print_observable_usage() {
14 std::cout
15 << "Usage:\n"
16 << " hyperiso-ui observable summary [options]\n\n"
17 << "Options:\n"
18 << " --observables <csv> Observable names, default BR_Bs__mu_mu,BR_B__Xs_gamma\n"
19 << " --bins <specs> Binned specs OBS:min:max, comma-separated\n"
20 << " --order <order> LO, NLO or NNLO, default NNLO\n"
21 << " --model <model> SM, THDM, MSSM or MARTY, default SM\n"
22 << " --lha <path> Input LHA/FLHA file\n";
23}
24
25struct BinSpec {
26 std::string observable;
27 double low = 0.0;
28 double high = 0.0;
29};
30
31BinSpec parse_bin_spec(const std::string& raw) {
32 std::stringstream ss(raw);
33 std::string obs, lo, hi;
34 if (!std::getline(ss, obs, ':') || !std::getline(ss, lo, ':') || !std::getline(ss, hi, ':')) {
35 throw std::invalid_argument("Invalid bin spec '" + raw + "'. Expected OBS:min:max");
36 }
37 return {obs, std::stod(lo), std::stod(hi)};
38}
39
40void print_values(const std::vector<ObservableValue>& values) {
41 for (const auto& value : values) {
42 std::cout << " " << value.id.str() << " = " << value.value;
43 if (value.bin.has_value()) {
44 std::cout << " in [" << value.bin->first << ", " << value.bin->second << "]";
45 }
46 std::cout << "\n";
47 }
48}
49
50} // namespace
51
52int handleObservableOptions(int argc, char* argv[]) {
53 CliOptions opts = CliOptions::parse(argc, argv, 1);
54 const std::string command = opts.positionals.empty() ? "summary" : opts.positionals[0];
55
56 if (opts.flag("help", false) || command == "help") {
57 print_observable_usage();
58 return 0;
59 }
60 if (command != "summary") {
61 throw std::invalid_argument("Unknown observable command: " + command);
62 }
63
64 auto hyp = init_hyperiso_from_cli(opts);
66
67 const QCDOrder order = parse_qcd_order(opts.get("order", "NNLO"));
68 const auto obs_names = opts.list("observables", {"BR_Bs__mu_mu", "BR_B__Xs_gamma"});
69 const auto bin_specs = opts.list("bins", {});
70
71 ObservableInterface interface;
72 for (const auto& name : obs_names) {
73 interface.add_observable(ObservableMapper::id_of(name), order, true);
74 }
75 for (const auto& raw : bin_specs) {
76 const BinSpec spec = parse_bin_spec(raw);
77 interface.add_observable(
78 BinnedObservableId(ObservableMapper::id_of(spec.observable), {spec.low, spec.high}),
79 order,
80 true
81 );
82 }
83
84 interface.enable_obs();
85
86 print_section("Observable summary");
87 std::cout << "order=" << OrderMapper::str(order) << "\n";
88 for (const auto& [obs, values] : interface.compute_all()) {
89 std::cout << "\n" << ObservableMapper::str(obs) << "\n";
90 print_values(values);
91 }
92
93 return 0;
94}
void print_section(const std::string &title)
Definition CliUtils.cpp:100
HyperisoMaster init_hyperiso_from_cli(const CliOptions &opts)
Definition CliUtils.cpp:130
QCDOrder parse_qcd_order(const std::string &order)
Definition CliUtils.cpp:113
QCDOrder
int handleObservableOptions(int argc, char *argv[])
High-level, user-facing entry point to compute flavor observables.
static std::string str(const IdOf< QCDOrderTag > &id)
Returns the string representation associated with an identifier.
static IdOf< ObservableTag > id_of(std::string_view s)
Resolves a string into an IdOf<Tag> via the registry.
static std::string str(const IdOf< ObservableTag > &id)
Returns the string representation of an identifier.
void enable_obs()
Force enabling/re-enabling currently registered observables.
std::map< ObservableId, std::vector< ObservableValue > > compute_all()
Compute all currently registered observables.
ObservableInterface & add_observable(Observables obs, QCDOrder order, bool add_dependencies=false)
Add an observable to the manager (enum API).
Non-templated façade over the project mapper families.
void init_all_builtins()
Initializes all builtin mapper registries and the decay graph.
Identifies an observable together with a numerical bin.