Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
StatisticHandler.cpp
Go to the documentation of this file.
1#include "StatisticHandler.h"
2
3#include <iostream>
4#include <map>
5#include <memory>
6#include <vector>
7
8#include "CliUtils.h"
10#include "StatisticInterface.h"
11#include "mapper_hub.hpp"
12
13namespace {
14
15void print_statistic_usage() {
16 std::cout
17 << "Usage:\n"
18 << " hyperiso-ui statistic summary [options]\n\n"
19 << "Options:\n"
20 << " --observables <csv> Observable names, default BR_Bs__mu_mu,BR_B__Xs_gamma\n"
21 << " --draws <n> MC draws for uncertainty mode, default 200\n"
22 << " --seed <n> RNG seed for reproducible MC runs, default 123456\n"
23 << " --uncertainties Also compute MC uncertainty summaries\n"
24 << " --chi2 Use CHI2_MC_COVARIANCE advanced likelihood mode\n"
25 << " --progress Show MC progress bar when MC is run\n"
26 << " --samples-csv <path> Write accepted MC observable samples to CSV\n"
27 << " --order <order> LO, NLO or NNLO, default NNLO\n"
28 << " --model <model> SM, THDM, MSSM or MARTY, default SM\n"
29 << " --lha <path> Input LHA/FLHA file\n";
30}
31
32void print_predictions(const std::map<ObservableId, std::vector<ObservableValue>>& predictions) {
33 for (const auto& [obs, values] : predictions) {
34 std::cout << "\n" << ObservableMapper::str(obs) << "\n";
35 for (const auto& value : values) {
36 std::cout << " prediction=" << value.value;
37 if (value.bin.has_value()) {
38 std::cout << " in [" << value.bin->first << ", " << value.bin->second << "]";
39 }
40 std::cout << "\n";
41 }
42 }
43}
44
45} // namespace
46
47int handleStatisticOptions(int argc, char* argv[]) {
48 CliOptions opts = CliOptions::parse(argc, argv, 1);
49 const std::string command = opts.positionals.empty() ? "summary" : opts.positionals[0];
50
51 if (opts.flag("help", false) || command == "help") {
52 print_statistic_usage();
53 return 0;
54 }
55 if (command != "summary") {
56 throw std::invalid_argument("Unknown statistic command: " + command);
57 }
58
59 auto hyp = init_hyperiso_from_cli(opts);
61
62 const QCDOrder order = parse_qcd_order(opts.get("order", "NNLO"));
63 const auto obs_names = opts.list("observables", {"BR_Bs__mu_mu", "BR_B__Xs_gamma"});
64
65 auto oi = std::make_shared<ObservableInterface>();
66 for (const auto& name : obs_names) {
67 oi->add_observable(ObservableMapper::id_of(name), order, true);
68 }
69 oi->enable_obs();
70
72 cfg.MC_draws = static_cast<std::size_t>(opts.get_int("draws", 200));
73 cfg.MC_seed = static_cast<unsigned int>(opts.get_int("seed", 123456));
74 cfg.print_mc_progress = opts.flag("progress", false);
75 if (opts.has("samples-csv")) {
76 cfg.write_mc_samples_csv = true;
77 cfg.mc_samples_csv_path = opts.get("samples-csv");
78 }
79 cfg.print_fit_summary = opts.flag("verbose", false);
80 cfg.print_scan_summary = opts.flag("verbose", false);
81 cfg.advanced.likelihood_mode = opts.flag("chi2", false)
84
85 StatisticInterface stat(cfg, oi);
86
87 print_section("Statistic summary");
88 std::cout << "observables=" << obs_names.size()
89 << ", draws=" << cfg.MC_draws
90 << ", seed=" << cfg.MC_seed
91 << ", mode=" << (opts.flag("chi2", false) ? "CHI2_MC_COVARIANCE" : "PROFILED_NUISANCE")
92 << "\n";
93
94 print_section("Predictions");
95 print_predictions(oi->compute_all());
96
97 print_section("Active observable dependencies");
98 const auto deps = stat.get_active_observable_dependencies();
99 if (deps.empty()) {
100 std::cout << " <none>\n";
101 } else {
102 for (const auto& [pid, value] : deps) {
103 std::cout << " " << pid << " = " << value << "\n";
104 }
105 }
106
107 if (opts.flag("uncertainties", false)) {
108 print_section("MC uncertainty summaries");
109 const auto summaries = stat.compute_uncertainties();
110 for (const auto& [obs, summary] : summaries) {
111 std::cout << " " << obs.str() << " -> " << summary << "\n";
112 }
113 }
114
115 return 0;
116}
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
High-level, user-facing entry point to compute flavor observables.
int handleStatisticOptions(int argc, char *argv[])
High-level facade for statistical computations.
@ PROFILED_NUISANCE
Full likelihood with explicit nuisance parameters profiled during the fit.
@ CHI2_MC_COVARIANCE
Fast chi-square likelihood using MC theory covariance plus experimental covariance.
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.
std::map< BinnedObservableId, GaussianSummary > compute_uncertainties()
Computes Gaussian uncertainty summaries for all active observables.
std::map< ParamId, double > get_active_observable_dependencies()
Returns the nuisance/input parameters currently seen by the statistical manager.
Non-templated façade over the project mapper families.
void init_all_builtins()
Initializes all builtin mapper registries and the decay graph.
StatisticLikelihoodMode likelihood_mode
Likelihood mode used by compute_MLE().
std::string mc_samples_csv_path
Output CSV path used when write_mc_samples_csv is true.
bool print_scan_summary
Print likelihood-scan summaries.
bool print_fit_summary
Print high-level fit backend summaries.
unsigned int MC_seed
RNG seed used for reproducible MC nuisance and experimental-data sampling.
bool write_mc_samples_csv
Write accepted MC observable samples to CSV.
AdvancedStatisticConfig advanced
Advanced fit/pruning/covariance configuration.
bool print_mc_progress
Print MC progress with ETA based on measured draw time.
std::size_t MC_draws
Number of accepted MC draws used for uncertainty propagation.