Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
MartyFileWriter.cpp
Go to the documentation of this file.
1#include "MartyFileWriter.h"
2
3#include <unordered_set>
4
5namespace {
6const std::unordered_set<std::string>& wilsons_without_mudim() {
7 static const std::unordered_set<std::string> values = {
8 "C10", "CP10"
9 };
10 return values;
11}
12
13const std::unordered_set<std::string>& wilsons_with_marty_split_sm_components() {
14 static const std::unordered_set<std::string> values = {
15 // Empty by design: SM primed semileptonic coefficients are supplied by
16 // the builtin backend. For C9/CP9/CP10 the MARTY split is BSM-only.
17 };
18 return values;
19}
20
21bool should_read_marty_split_sm_components(const std::string& wilson) {
22 return wilsons_with_marty_split_sm_components().find(wilson) != wilsons_with_marty_split_sm_components().end();
23}
24
25bool uses_split_regprop_policy(const std::string& wilson) {
26 return wilson == "C9" || wilson == "CP9" || wilson == "CP10";
27}
28}
29
30MartyFileWriter::MartyFileWriter(const std::string& wilson,
31 const std::string& model,
32 bool bsm_split_generation,
33 bool full_target_generation) :
34 wilson(wilson),
35 model(model),
36 bsm_split_generation(bsm_split_generation),
37 full_target_generation(full_target_generation) {}
38
39bool MartyFileWriter::should_set_mudim() const {
40 return wilsons_without_mudim().find(this->wilson) == wilsons_without_mudim().end();
41}
42
43void MartyFileWriter::add_output_writer(std::ofstream& outputFile) {
44 outputFile << "\tconst std::string& path = output_file_path;\n";
45
46 if (should_set_mudim()) {
47 outputFile << "\tsetMu(Q_match);\n";
48 } else {
49 outputFile << "\t// setMu(Q_match) intentionally skipped for " << this->wilson
50 << " because LoopTools mudim must stay at its default value.\n";
51 }
52
53 if (bsm_split_generation && uses_split_regprop_policy(this->wilson)) {
54 outputFile << "\t// Split MARTY coefficient policy. " << wilson
55 << " is generated as non-photon and photon-linker pieces.\n";
56 outputFile << "\t// Non-photon pieces use reg_prop = 1e-6. Photon-linker pieces use reg_prop = 1.\n";
57 outputFile << "\tauto hyperiso_regprop_it = param.realParams.find(\"reg_prop\");\n";
58 outputFile << "\tbool hyperiso_has_regprop = hyperiso_regprop_it != param.realParams.end() && hyperiso_regprop_it->second != nullptr;\n";
59 const bool read_split_sm_components = should_read_marty_split_sm_components(this->wilson);
60 const bool expose_linker_components = (this->wilson == "CP10");
61 outputFile << "\tdouble hyperiso_regprop_saved = 1e-6;\n";
62 outputFile << "\tif (hyperiso_has_regprop) {\n";
63 outputFile << "\t\thyperiso_regprop_saved = static_cast<double>(*hyperiso_regprop_it->second);\n";
64 outputFile << "\t}\n";
65
66 outputFile << "\tif (hyperiso_has_regprop) {\n";
67 outputFile << "\t\t*hyperiso_regprop_it->second = 1e-6;\n";
68 outputFile << "\t}\n";
69 if (expose_linker_components) {
70 // Use the full non-photon branch for the physical value. The
71 // VECTOR / SCALAR calls are diagnostics: they help identify where
72 // CP10 comes from without risking double counting or losing boxes.
73 outputFile << "\tauto hyperiso_bsm_non_photon = " + wilson + "(param);\n";
74 outputFile << "\tauto hyperiso_bsm_vector = " + wilson + "_VECTOR(param);\n";
75 outputFile << "\tauto hyperiso_bsm_scalar = " + wilson + "_SCALAR(param);\n";
76 } else {
77 outputFile << "\tauto hyperiso_bsm_non_photon = " + wilson + "(param);\n";
78 outputFile << "\tauto hyperiso_bsm_vector = hyperiso_bsm_non_photon;\n";
79 outputFile << "\tauto hyperiso_bsm_scalar = 0.0 * hyperiso_bsm_non_photon;\n";
80 }
81 if (read_split_sm_components) {
82 if (expose_linker_components) {
83 outputFile << "\tauto hyperiso_sm_non_photon = " + wilson + "_SM(param);\n";
84 outputFile << "\tauto hyperiso_sm_vector = " + wilson + "_SM_VECTOR(param);\n";
85 outputFile << "\tauto hyperiso_sm_scalar = " + wilson + "_SM_SCALAR(param);\n";
86 } else {
87 outputFile << "\tauto hyperiso_sm_non_photon = " + wilson + "_SM(param);\n";
88 outputFile << "\tauto hyperiso_sm_vector = hyperiso_sm_non_photon;\n";
89 outputFile << "\tauto hyperiso_sm_scalar = 0.0 * hyperiso_sm_non_photon;\n";
90 }
91 } else {
92 outputFile << "\tauto hyperiso_sm_non_photon = 0.0 * hyperiso_bsm_non_photon;\n";
93 outputFile << "\tauto hyperiso_sm_vector = 0.0 * hyperiso_bsm_vector;\n";
94 outputFile << "\tauto hyperiso_sm_scalar = 0.0 * hyperiso_bsm_scalar;\n";
95 }
96
97 outputFile << "\tif (hyperiso_has_regprop) {\n";
98 outputFile << "\t\t*hyperiso_regprop_it->second = 1.0;\n";
99 outputFile << "\t}\n";
100 outputFile << "\tauto hyperiso_bsm_photon = " + wilson + "_A(param);\n";
101 if (read_split_sm_components) {
102 outputFile << "\tauto hyperiso_sm_photon = " + wilson + "_SM_A(param);\n";
103 } else {
104 outputFile << "\tauto hyperiso_sm_photon = 0.0 * hyperiso_bsm_photon;\n";
105 }
106
107 outputFile << "\tif (hyperiso_has_regprop) {\n";
108 outputFile << "\t\t*hyperiso_regprop_it->second = hyperiso_regprop_saved;\n";
109 outputFile << "\t}\n";
110 outputFile << "\tauto hyperiso_bsm_split = hyperiso_bsm_non_photon + hyperiso_bsm_photon;\n";
111 outputFile << "\tauto hyperiso_sm_split = hyperiso_sm_non_photon + hyperiso_sm_photon;\n";
112 outputFile << "\tauto hyperiso_total_split = hyperiso_sm_split + hyperiso_bsm_split;\n";
113 if (full_target_generation) {
114 outputFile << "\t// The analytical split contains the complete target model.\n";
115 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "\", hyperiso_bsm_split, Q_match, path);\n";
116 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_TARGET_SPLIT\", hyperiso_bsm_split, Q_match, path);\n";
117 } else {
118 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "\", hyperiso_bsm_split, Q_match, path);\n";
119 }
120 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_BSM_SPLIT\", hyperiso_bsm_split, Q_match, path);\n";
121 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_SM_SPLIT\", hyperiso_sm_split, Q_match, path);\n";
122 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_TOTAL_SPLIT\", hyperiso_total_split, Q_match, path);\n";
123 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_NONPHOTON\", hyperiso_bsm_non_photon, Q_match, path);\n";
124 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_A\", hyperiso_bsm_photon, Q_match, path);\n";
125 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_SM_NONPHOTON\", hyperiso_sm_non_photon, Q_match, path);\n";
126 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_SM_A\", hyperiso_sm_photon, Q_match, path);\n";
127 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_VECTOR\", hyperiso_bsm_vector, Q_match, path);\n";
128 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_SCALAR\", hyperiso_bsm_scalar, Q_match, path);\n";
129 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_SM_VECTOR\", hyperiso_sm_vector, Q_match, path);\n";
130 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_SM_SCALAR\", hyperiso_sm_scalar, Q_match, path);\n";
131 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_TOTAL_VECTOR\", hyperiso_sm_vector + hyperiso_bsm_vector, Q_match, path);\n";
132 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_TOTAL_SCALAR\", hyperiso_sm_scalar + hyperiso_bsm_scalar, Q_match, path);\n";
133 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_SM_COMPONENT\", hyperiso_sm_split, Q_match, path);\n";
134 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "_TOTAL_COMPONENT\", hyperiso_total_split, Q_match, path);\n";
135 } else {
136 outputFile << "\twriteWilsonCoefficients(\"" + wilson + "\", " + wilson + "(param), Q_match, path);\n";
137 }
138
139}
140
141void MartyFileWriter::add_argpars(std::ofstream& outputFile) {
142 const auto files = FileNameManager::getInstance(this->wilson, this->model);
143 outputFile << "\tdouble Q_match = 80.379;\n";
144 outputFile << "\tstd::string param_file_path = \"" << files->getParamFileName() << "\";\n";
145 outputFile << "\tstd::string output_file_path = \"" << files->getCsvWilsonFileName() << "\";\n";
146 outputFile << "\tfor (int i = 1; i < argc; i++) {\n";
147 outputFile << "\t\tif (std::string(argv[i]) == \"--Q_match\" || std::string(argv[i]) == \"-Q\") {\n";
148 outputFile << "\t\t\tif (i + 1 >= argc) { throw std::runtime_error(\"Missing value after --Q_match\"); }\n";
149 outputFile << "\t\t\tQ_match = std::stod(argv[i + 1]);\n";
150 outputFile << "\t\t\ti++;\n";
151 outputFile << "\t\t} else if (std::string(argv[i]) == \"--param-file\") {\n";
152 outputFile << "\t\t\tif (i + 1 >= argc) { throw std::runtime_error(\"Missing value after --param-file\"); }\n";
153 outputFile << "\t\t\tparam_file_path = argv[++i];\n";
154 outputFile << "\t\t} else if (std::string(argv[i]) == \"--output-file\") {\n";
155 outputFile << "\t\t\tif (i + 1 >= argc) { throw std::runtime_error(\"Missing value after --output-file\"); }\n";
156 outputFile << "\t\t\toutput_file_path = argv[++i];\n";
157 outputFile << "\t\t} else if (std::string(argv[i]) == \"--help\" || std::string(argv[i]) == \"-h\") {\n";
158 outputFile << "\t\t\tstd::cout << \"Options availables :\" << std::endl;\n";
159 outputFile << "\t\t\tstd::cout << \"--Q_match/-Q : Value of Q_match (default 80.379)\" << std::endl;\n";
160 outputFile << "\t\t\tstd::cout << \"--param-file : Per-invocation parameter CSV\" << std::endl;\n";
161 outputFile << "\t\t\tstd::cout << \"--output-file : Per-invocation Wilson CSV\" << std::endl;\n";
162 outputFile << "\t\t\tstd::cout << \"--help/-h : Affiche ce message.\" << std::endl;\n";
163 outputFile << "\t\t\treturn 0;\n";
164 outputFile << "\t\t}\n";
165 outputFile << "\t}\n\n";
166
167}
168
169void MartyFileWriter::add_input_reader(std::ofstream& outputFile) {
170 outputFile << "\tparam_t param;\n";
171 outputFile << "\tstd::ifstream ParamFile(param_file_path);" << "\n";
172 outputFile << "\tif (!ParamFile) { throw std::runtime_error(\"Cannot open MARTY parameter file: \" + param_file_path); }\n";
173 outputFile << "\treadParams(ParamFile, param.realParams, param.complexParams);" << "\n";
174
175
176}
Declares utilities to generate C++ code for MARTY wrappers.
static std::shared_ptr< FileNameManager > getInstance(const std::string &wilson="", const std::string &model="")
Retrieves a FileNameManager for a given (wilson, model) pair.
void add_output_writer(std::ofstream &outputFile)
Writes C++ code that handles writing Wilson coefficients to a CSV.
MartyFileWriter(const std::string &wilson, const std::string &model, bool bsm_split_generation=false, bool full_target_generation=false)
Constructs a MartyFileWriter for a given (wilson, model) pair.
void add_argpars(std::ofstream &outputFile)
Writes C++ code to parse command-line arguments.
void add_input_reader(std::ofstream &outputFile)
Writes C++ code to read numerical parameters from disk.