Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
test_minuit.cpp
Go to the documentation of this file.
1#include "Logger.h"
2#include <iostream>
3#include <cassert>
5#include "HyperisoMaster.h"
6#include "config.hpp"
7#include "BlockProxy.h"
9
11 double err_down; // erreur vers le bas
12 double err_up; // erreur vers le haut
13 double err_sym; // erreur vers tout
14};
15
16static ObservableUncertainty uncertainty_from_summary(const GaussianSummary& gs) {
18
19 if (gs.symmetric) {
20 out.err_down = std::abs(gs.sigma);
21 out.err_up = std::abs(gs.sigma);
22 } else {
23 // Convention naturelle :
24 // sigma_m = erreur vers le bas
25 // sigma_p = erreur vers le haut
26 out.err_down = std::abs(gs.sigma_m);
27 out.err_up = std::abs(gs.sigma_p);
28
29 // Sécurité si jamais sigma_m/p sont nuls mais sigma existe
30 if (out.err_down == 0.0 && out.err_up == 0.0 && gs.sigma != 0.0) {
31 out.err_down = std::abs(gs.sigma);
32 out.err_up = std::abs(gs.sigma);
33 }
34 }
35 out.err_sym = gs.sigma;
36 return out;
37}
38
39
40static void write_observables_to_csv(
41 const std::string& filename,
42 const std::vector<ObservableValue>& obs_val,
43 const std::vector<ObservableUncertainty>& uncertainties
44) {
45 if (obs_val.size() != uncertainties.size()) {
46 throw std::runtime_error("obs_val et uncertainties n'ont pas la même taille");
47 }
48
49 std::ofstream out(filename);
50 if (!out) {
51 throw std::runtime_error("Impossible d'ouvrir le fichier CSV: " + filename);
52 }
53
54 out << "bin_low,bin_high,value,err_down,err_up,err_sym\n";
55 out << std::setprecision(17);
56
57 for (std::size_t i = 0; i < obs_val.size(); ++i) {
58 const auto& obs = obs_val[i];
59 const auto& unc = uncertainties[i];
60
61 if (!obs.bin.has_value()) {
62 continue;
63 }
64
65 out << obs.bin->first << ","
66 << obs.bin->second << ","
67 << obs.value << ","
68 << unc.err_down << ","
69 << unc.err_up << ","
70 << unc.err_sym << "\n";
71 }
72}
73
74int main() {
77 HyperisoConfig config;
78 config.model = Model::SM;
79 hyp.init("lha/si_input.flha", config);
80
82 std::shared_ptr<ObservableInterface> oi = std::make_shared<ObservableInterface>();
83
85 // KllDecayConfig dec_cfg;
86 // dec_cfg.gen = 1;
87 // dec_cfg.N_L_sign = -1;
88
89 // oi.set_decay_config(dec, dec_cfg);
90 // oi.add_observable(Observables::TEST, order);
91 // oi.compute_observable(Observables::TEST);
92 std::vector<double> squares;
93
94 for (double x = 0.05; x<8.1; x+=0.01) {
95 squares.push_back(x);
96 }
97 for (double x = 15; x<20; x+=0.01) {
98 squares.push_back(x);
99 }
100 for (auto elem : squares) {
102 }
103
104 std::vector<ObservableValue> obs_val = oi->compute_observable(Observables::F_L_B__KSTAR_MU_MU);
105
107 sc.MC_draws = 10000;
109
110 std::map<BinnedObservableId, GaussianSummary> unc_map = si.compute_uncertainties();
111
112 std::vector<ObservableUncertainty> uncertainties;
113 uncertainties.reserve(obs_val.size());
114
115 for (const auto& obs : obs_val) {
116 if (!obs.bin.has_value()) {
117 uncertainties.push_back({0.0, 0.0});
118 continue;
119 }
120
121 BinnedObservableId key(obs.id, *obs.bin);
122
123 auto it = unc_map.find(key);
124 std::cout
125 << "OBS [" << obs.bin->first << ", " << obs.bin->second << "] "
126 << " value=" << obs.value
127 << " | GS.id=[" << it->second.id.p.first << ", " << it->second.id.p.second << "]"
128 << " mu=" << it->second.mu
129 << " sigma=" << it->second.sigma
130 << " sigma_m=" << it->second.sigma_m
131 << " sigma_p=" << it->second.sigma_p
132 << " skew=" << it->second.skew
133 << " symmetric=" << it->second.symmetric
134 << "\n";
135 if (it == unc_map.end()) {
136 std::cerr << "Warning: uncertainty not found for bin ["
137 << obs.bin->first << ", " << obs.bin->second << "]\n";
138
139 // Tu peux choisir 0, ou bien throw si tu veux que ça casse tout de suite
140 uncertainties.push_back({0.0, 0.0});
141 continue;
142 }
143
144 uncertainties.push_back(uncertainty_from_summary(it->second));
145 }
146
147 write_observables_to_csv("K__pi_nu_nu.csv", obs_val, uncertainties);
148
149 std::cout << "CSV écrit dans K__pi_nu_nu.csv\n";
150 return 0;
151
152 // oi.add_observables(dec, order, false);
153 // for (auto o : DecayMapper::get_observables(dec)) {
154 // if (o == Observables::TEST) continue;
155
156 // // if (o == Observables::A_FB_B__KSTAR_L_L || o == Observables::F_L_B__KSTAR_L_L) {
157 // auto obs_values = oi.compute_observable(o);
158 // std::stringstream ss;
159 // ss << std::scientific << std::setprecision(3);
160 // if (obs_values.size() == 1) {
161 // ss << "= " << obs_values[0].value;
162 // } else {
163 // ss << ": ";
164 // for (auto ov : obs_values) {
165 // ss << "[" << ov.bin.value().first << ", " << ov.bin.value().second << "] = " << ov.value << ", ";
166 // }
167 // }
168
169 // LOG_INFO(ObservableMapper::str(o), ss.str());
170 // // }
171 // }
172
173 // auto Gamma = oi.compute_observable(Observables::DGAMMA_DQ2_BS__PHI_L_L)[0].value;
174 // auto Gamma_bar = oi.compute_observable(Observables::DGAMMA_BAR_DQ2_BS__PHI_L_L)[0].value;
175
176 // std::stringstream ss;
177 // ss << std::scientific << std::setprecision(3);
178 // ss << "= " << (Gamma + Gamma_bar) / 2;
179 // LOG_INFO("BR(Bs > phi mu mu)", ss.str());
180
181 return 0;
182}
Facade combining block existence/logging (BlockProvider) and block listing (APIAdapter).
QCDOrder
Decays
@ K__pi_nu_nu
High-level helpers for initializing and monitoring the Hyperiso framework.
High-level, user-facing entry point to compute flavor observables.
High-level facade for statistical computations.
static IdOf< ObservableTag > to_id(Observables e)
Converts an enum value to an IdOf<Tag>.
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 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::map< BinnedObservableId, GaussianSummary > compute_uncertainties()
Computes Gaussian uncertainty summaries for all active observables.
Identifies an observable together with a numerical bin.
double sigma_m
Left-side standard deviation for an asymmetric approximation.
bool symmetric
True when the distribution is treated as sufficiently symmetric.
double sigma_p
Right-side standard deviation for an asymmetric approximation.
double sigma
Symmetric population standard deviation.
Configuration object controlling model, input flags and optional MARTY resources.
Definition Config.h:24
Model model
Current model.
Definition Config.h:33
std::size_t MC_draws
Number of accepted MC draws used for uncertainty propagation.
int main()