Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
MartyWilson.cpp
Go to the documentation of this file.
1#include "MartyWilson.h"
2
3#include <filesystem>
4#include <system_error>
5
6
8 : WilsonCoefficient(WCoefMapper::str(WCoefMapper::from_flha(config.coeff_id.get_parts()[0], config.coeff_id.get_parts()[1])), config.storage_block) {
9 if (config.model_path.empty()) {
10 throw std::invalid_argument(
11 "MartyWilson requires an explicit runtime-resolved MARTY model path"
12 );
13 }
14 this->type = static_cast<ContributionType>(config.coeff_id.get_parts()[3]);
15 this->set_model(config.model_name);
16 std::string name = this->get_name();
17
18 std::string csv_path = config.csv_path;
19 std::string marty_model = config.model_name;
20 std::string marty_generation_model = config.generation_model_name;
21 bool marty_sm_like_filter = config.sm_like_filter;
22 bool marty_bsm_split_generation = config.bsm_split_generation;
23 bool marty_full_target_generation = config.full_target_generation;
24 std::string marty_model_path = config.model_path;
25
26 std::shared_ptr<IMartyWilsonProxy<InterpretedParam>> marty_proxy = config.marty_proxy;
27 ContributionType contribution_type = this->type;
28
29 matching_info[QCDOrder::LO].compute = [name, csv_path, marty_model, marty_generation_model, marty_sm_like_filter, marty_bsm_split_generation, marty_full_target_generation, marty_model_path, marty_proxy, contribution_type] (const ParamSrc& src) -> scalar_t {
30 LOG_DEBUG("Updating coeff", name);
31 double epsi = 1e-4;
32 double ew_scale = src.get_val({ParameterType::WILSON, "EW_SCALE", 1});
33 if (!marty_proxy) {
34 throw std::runtime_error(
35 "MartyWilson cannot evaluate '" + name + "': no MARTY proxy was configured"
36 );
37 }
38
39 scalar_t result{};
40 bool found_matching_scale = false;
41
42 CSVReader csv_reader;
43 DataFrame df;
44
45 const std::string isolated_csv = marty_proxy->calculate_isolated(
46 name,
47 marty_model,
48 marty_generation_model,
49 ew_scale,
50 marty_model_path,
51 marty_sm_like_filter,
52 marty_bsm_split_generation,
53 marty_full_target_generation
54 );
55 const std::filesystem::path csv_to_read = isolated_csv.empty()
56 ? std::filesystem::path(csv_path)
57 : std::filesystem::path(isolated_csv);
58
59 struct InvocationCsvCleanup {
60 std::filesystem::path directory;
61 ~InvocationCsvCleanup() {
62 if (directory.empty()) {
63 return;
64 }
65 std::error_code ec;
66 std::filesystem::remove_all(directory, ec);
67 }
68 } cleanup {isolated_csv.empty() ? std::filesystem::path{} : csv_to_read.parent_path()};
69
70 df = csv_reader.read_csv(csv_to_read.string());
71 df.setIndex(df.getColumn<double>("Q_match").to_string_vec());
72
73 std::string csv_column_base = name;
74 if (marty_bsm_split_generation && name == "CP10") {
75 if (contribution_type == ContributionType::SM) {
76 csv_column_base = name + "_SM_SPLIT";
77 } else if (contribution_type == ContributionType::BSM) {
78 csv_column_base = name + "_BSM_SPLIT";
79 } else if (contribution_type == ContributionType::TOTAL) {
80 csv_column_base = name + "_TOTAL_SPLIT";
81 }
82 }
83
84 for (size_t i = 0; i < df.getRowCount(); ++i) {
85 double Q_match = df.iat<double>(i, "Q_match");
86 if (fabs(Q_match - ew_scale) < epsi) {
87 result = {df.iat<double>(i, csv_column_base+"_real"), df.iat<double>(i, csv_column_base+"_img")};
88 found_matching_scale = true;
89 break;
90 }
91 }
92
93 if (!found_matching_scale) {
94 throw std::runtime_error(
95 "MartyWilson CSV for '" + name + "' contains no row at Q_match="
96 + std::to_string(ew_scale)
97 );
98 }
99
100 return result;
101 };
102
103 ParamId pid {ParameterType::WILSON, "EW_SCALE", 1};
104 std::unordered_map<ParamId, std::shared_ptr<Parameter>> dummy {{pid, std::make_shared<Parameter>(pid, 1, 0, 0)}};
105 matching_info[QCDOrder::LO].compute(ParamSrc(dummy));
106
107 std::unordered_set<ParamId> sources;
108 const std::set<std::string> special = marty_proxy->get_special_blocks();
109 for (const auto& par : marty_proxy->get_dependencies(name)) {
110 if (special.contains(par.block)) {
111 continue;
112 }
113 sources.emplace(ParamId{
115 par.block,
116 par.code
117 });
118 }
119 sources.emplace(ParamId{ParameterType::WILSON, "EW_SCALE", 1});
120 matching_info[QCDOrder::LO].sources = std::move(sources);
121 matching_info[QCDOrder::LO].lhaid = config.coeff_id;
122
123 WCoef coef = WCoefMapper::from_flha(config.coeff_id.parts[0], config.coeff_id.parts[1]);
124 ContributionType ct = static_cast<ContributionType>(config.coeff_id.parts[3]);
127}
ContributionType
WCoef
#define LOG_DEBUG(...)
Macro for logging debug messages.
Definition Logger.h:45
WilsonCoefficient implementation whose matching is produced by a MARTY backend.
CSV → DataFrame loader with basic type handling.
Definition CSVReader.h:36
DataFrame read_csv(const std::string &filename, CSVOptions options=CSVOptions())
Read a CSV file and construct a DataFrame.
Definition CSVReader.cpp:45
Simple column-oriented data structure with basic analysis utilities.
Definition DataFrame.h:61
Series< T > getColumn(const std::string &colName) const
Returns a copy of a column as a Series<T>.
size_t getRowCount() const
Returns the number of rows in the DataFrame.
Definition DataFrame.cpp:70
void setIndex(const std::vector< std::string > &newIndex)
Sets the index labels for all rows.
T iat(size_t row, const std::string &colName) const
Positional access to a cell (row index, column name).
void set_model(std::string model)
Sets the MARTY model name used by this coefficient.
MartyWilson(MartyWilsonConfig config)
Constructs a Marty-backed Wilson coefficient.
Lightweight view over a set of source parameters keyed by ParamId.
High-level mapper for WCoef <-> text <-> FLHA base indices.
Definition wcoef_ids.hpp:57
static LhaID flha_full(WCoef e, QCDOrder q, ContributionType c)
static WCoef from_flha(int a, int b)
Returns the WCoef associated with a given FLHA base key (a,b).
Definition wcoef_ids.hpp:74
Abstract base class representing a Wilson coefficient and its matching information.
Definition Wilson.h:153
std::string get_name() const
Returns the current full name (may include suffixes).
Definition Wilson.h:272
std::map< QCDOrder, MatchingInfo > matching_info
Matching metadata indexed by QCD order.
Definition Wilson.h:330
ContributionType type
Contribution type for this coefficient (SM by default, inferred in constructors).
Definition Wilson.h:314
std::vector< long > get_parts() const
Returns the underlying vector of sub-ids.
Definition LhaID.h:148
std::vector< long > parts
Definition LhaID.h:57
Configuration bundle for constructing a MartyWilson coefficient.
Definition MartyWilson.h:65
std::string model_name
Output model label used for generated libraries/CSV files (e.g. "SM", "THDM").
Definition MartyWilson.h:67
LhaID coeff_id
Full coefficient id used to store the matching value (including order/type parts).
Definition MartyWilson.h:89
bool full_target_generation
Definition MartyWilson.h:86
fs::path model_path
Path to the MARTY model header file.
Definition MartyWilson.h:95
std::string csv_path
Absolute path to the CSV output produced by MARTY for this model.
std::shared_ptr< IMartyWilsonProxy< InterpretedParam > > marty_proxy
Proxy used to run MARTY and retrieve dependencies/special blocks.
Definition MartyWilson.h:98
std::string generation_model_name
Definition MartyWilson.h:71
Composite identifier for a single parameter.
Definition ParamID.h:57
BlockName block
Name of the block where the parameter is stored.
Definition ParamID.h:73