Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
WilsonBuilder.cpp
Go to the documentation of this file.
1#include "WilsonBuilder.h"
2
3#include "GroupDefinition.h"
6#include "MartyAdapter.h"
7
11
12static std::shared_ptr<CoefficientRegistry> make_registry() {
13 auto reg = std::make_shared<CoefficientRegistry>();
14 register_B(*reg);
15 register_BPrime(*reg);
16 register_BScalar(*reg);
17 register_CC_bc(*reg);
18 register_CC_bu(*reg);
19 register_CC_cs(*reg);
20 register_CC_cd(*reg);
21 register_CC_su(*reg);
22 register_CC_du(*reg);
23 register_K(*reg);
25 return reg;
26}
27
28WilsonBuilder::WilsonBuilder(std::shared_ptr<CoefficientManager> manager) : cm(manager) {}
29
31
32 std::shared_ptr<IBlockComposer> iblock_c = std::make_shared<WilsonParamComposer>();
33
34 wilson_param_helpers[Model::SM] = std::make_shared<WilsonParameterHelper>(iblock_c);
35
36 for (const auto& elem : config.groups) {
37 wilson_param_helpers[Model::SM]->init(2, elem);
38
39 }
40
41 Model model = ModelAPI().get();
42
43 if (model == Model::THDM) {
44 wilson_param_helpers[model] = std::make_shared<THDMParameterHelper>(iblock_c);
45 for (const auto& elem : config.groups) {
46 wilson_param_helpers[model]->init(2, elem);
47
48 }
49 } else if (model == Model::SUSY) {
50 wilson_param_helpers[model] = std::make_shared<SUSYParameterHelper>(iblock_c);
51 for (const auto& elem : config.groups) {
52 wilson_param_helpers[model]->init(2, elem);
53 }
54 }
55
56
57
58 std::shared_ptr<IParameterProxy<std::string, LhaID>> wilson_proxy = std::make_shared<ParameterProxy>(ParameterType::WILSON);
59 std::shared_ptr<IParameterProxy<std::string, LhaID>> sm_proxy = std::make_shared<ParameterProxy>(ParameterType::SM);
60 std::shared_ptr<ICoreAPI<bool>> use_marty = std::make_shared<UseMarty>();
61 std::shared_ptr<ICoreAPI<bool>> has_wilson = std::make_shared<HasWilsonAPI>();
62 std::shared_ptr<ICoreAPI<Model>> model_api = std::make_shared<ModelAPI>();
63 std::shared_ptr<IParamSetter<ScaleType>> scale_setter_api = std::make_shared<ScaleSetter>(ScaleType::MATCHING);
64 std::shared_ptr<ICoreAPI<std::string>> marty_model_name = std::make_shared<MartyModelNameAPI>();
65 std::shared_ptr<ICoreAPI<fs::path>> marty_model_path = std::make_shared<MartyModelPathAPI>();
66 std::shared_ptr<IMartyWilsonProxy<InterpretedParam>> marty_proxy = nullptr;
67 std::shared_ptr<IMartyWilsonPathProxy> marty_paths = std::make_shared<MartyWilsonPathProxy>();
68 std::shared_ptr<ICoreAPI<bool>> hard_coded_lo =
69 std::make_shared<SMFromHypProxy>();
70 if (use_marty->get()) {
71 marty_proxy = std::make_shared<MartyWilsonProxy>();
72 }
73 WilsonGroupAdapterConfig adapters(wilson_proxy, iblock_c, use_marty, marty_model_name, marty_model_path, marty_proxy);
75 this->current_group_adapters = std::make_shared<WilsonGroupAdapterConfig>(adapters);
76 this->current_marty_paths = marty_paths;
77
78 auto reg_ptr = make_registry();
79 auto build_group_fn = [reg_ptr, adapters, marty_paths](WGroupId gid, Model mdl, bool useMarty, ContributionType ct, std::string group_name = "") -> std::shared_ptr<CoefficientGroup> {
80 BuildContext ctx{
81 .adapters = adapters,
82 .model = mdl,
83 .backend = useMarty ? Backend::Marty : Backend::Builtin,
84 .contrib = ct,
85 .group_id = gid,
86 .group_name = std::move(group_name),
87 .marty_paths = marty_paths
88 };
89 CoefficientGroupBuilder b{*reg_ptr};
90 return b.build(ctx);
91 };
92
93 std::map<std::string, std::shared_ptr<CoefficientGroup>> groups;
94 const bool marty = use_marty->get();
95
96 for (auto& g_id : config.groups) {
97 // A non-SM model is stored as a pure BSM calculation, including for
98 // the MARTY backend. CoefficientManager then composes TOTAL = SM + BSM.
99 // Do not store the complete MARTY target model as TOTAL and subtract a
100 // separately implemented SM: C9 photon-penguin conventions and tiny C10
101 // normalization differences would leak into the inferred BSM component.
102 ContributionType ct = (model == Model::SM)
105 auto grp = build_group_fn(g_id, model, marty, ct);
106 groups.emplace(GroupMapper::str(g_id), std::move(grp));
107
108 }
109 if (use_marty->get()
110 && config.order > QCDOrder::LO
111 && !(hard_coded_lo && hard_coded_lo->get()))
112 {
113 // Marty pur => LO-only global
114 config.order = QCDOrder::LO;
115 }
116
117 WilsonPortsConfig port_config{iblock_c, wilson_proxy, use_marty, has_wilson, model_api, scale_setter_api, hard_coded_lo, marty_paths};
118 // C9/CP9 photon-penguin finite pieces are intentionally not injected as a
119 // hidden default here. The SM C9 branch uses the builtin HyperIso/SuperIso
120 // coefficient; BSM photon pieces can be provided explicitly by the user via
121 // WilsonMatchingPatch.
122 port_config.build_group = build_group_fn;
123
124 this->cm = CoefficientManager::Builder(groups, config.matching_scale, config.hadronic_scale, OrderMapper::str(config.order), port_config, wilson_param_helpers);
125}
126
128
129 if (!this->cm) {
130 LOG_ERROR("LogicError", "Cannot add Wilson groups before WilsonBuilder has been built.");
131 }
132
133 if (!this->current_group_adapters) {
134 LOG_ERROR("LogicError", "WilsonBuilder has no cached group adapters for Wilson group registration.");
135 }
136
137 auto iblock_c = this->current_group_adapters->iblock_c;
138
139 if (!wilson_param_helpers[Model::SM]) {
140 wilson_param_helpers[Model::SM] = std::make_shared<WilsonParameterHelper>(iblock_c);
141 }
142
143 for (const auto& elem : config.groups) {
144 wilson_param_helpers[Model::SM]->init(2, elem);
145 }
146
147 Model model = ModelAPI().get();
148
149 if (model == Model::THDM) {
150 if (!wilson_param_helpers[model]) {
151 wilson_param_helpers[model] = std::make_shared<THDMParameterHelper>(iblock_c);
152 }
153 for (const auto& elem : config.groups) {
154 wilson_param_helpers[model]->init(2, elem);
155 }
156 } else if (model == Model::SUSY) {
157 if (!wilson_param_helpers[model]) {
158 wilson_param_helpers[model] = std::make_shared<SUSYParameterHelper>(iblock_c);
159 }
160 for (const auto& elem : config.groups) {
161 wilson_param_helpers[model]->init(2, elem);
162 }
163 }
164
165 this->cm->set_matching_scale(config.matching_scale);
166 this->cm->set_hadronic_scale(config.hadronic_scale);
167
168 const bool marty = this->current_group_adapters->use_marty->get();
169 auto hard_coded_lo = std::make_shared<SMFromHypProxy>();
170 if (marty
171 && config.order > QCDOrder::LO
172 && !(hard_coded_lo && hard_coded_lo->get()))
173 {
174 config.order = QCDOrder::LO;
175 }
176
177 auto reg_ptr = make_registry();
178 CoefficientGroupBuilder b{*reg_ptr};
179 auto marty_paths = this->current_marty_paths
180 ? this->current_marty_paths
181 : std::make_shared<MartyWilsonPathProxy>();
182
183 for (auto& g_id : config.groups) {
184 // A non-SM model is stored as a pure BSM calculation, including for
185 // the MARTY backend. CoefficientManager then composes TOTAL = SM + BSM.
186 // Do not store the complete MARTY target model as TOTAL and subtract a
187 // separately implemented SM: C9 photon-penguin conventions and tiny C10
188 // normalization differences would leak into the inferred BSM component.
189 ContributionType ct = (model == Model::SM)
192
193 BuildContext ctx{
194 .adapters = *this->current_group_adapters,
195 .model = model,
196 .backend = marty ? Backend::Marty : Backend::Builtin,
197 .contrib = ct,
198 .group_id = g_id,
199 .marty_paths = marty_paths
200 };
201
202 auto grp = b.build(ctx);
203
204 std::string group_name = GroupMapper::str(g_id);
205 LOG_VERBOSE("Initializing group", group_name);
206 this->cm->registerCoefficientGroup(group_name, std::move(grp));
207 LOG_VERBOSE("Initializing group at matching scale", group_name);
208 this->cm->init_group_matching(group_name, OrderMapper::str(config.order));
209 LOG_VERBOSE("Initializing group at hardronic scale", group_name);
210 this->cm->init_group_hadronic_all_bases(group_name, OrderMapper::str(config.order));
211 LOG_VERBOSE("Initialization done");
212 }
213}
214
216 if (!this->cm) {
217 LOG_ERROR("LogicError", "Cannot add a custom Wilson group before WilsonBuilder has been built.");
218 }
219
220 if (!this->current_group_adapters) {
221 LOG_ERROR("LogicError", "WilsonBuilder has no cached group adapters for custom Wilson group registration.");
222 }
223
224 if (config.coefficients.empty()) {
225 LOG_ERROR("ValueError", "Cannot add custom Wilson group", GroupMapper::str(config.group), "without coefficients.");
226 }
227
228 auto group = make_custom_wilson_group(config, *this->current_group_adapters);
229 const std::string group_name = GroupMapper::str(config.group);
230
231 this->cm->set_matching_scale(config.matching_scale);
232 this->cm->set_hadronic_scale(config.hadronic_scale);
233 this->cm->registerCoefficientGroup(group_name, std::move(group));
234 this->cm->init_group_matching(group_name, OrderMapper::str(config.order));
235 this->cm->init_group_hadronic_all_bases(group_name, OrderMapper::str(config.order));
236}
237
238
240 if (!this->cm) {
241 LOG_ERROR("LogicError", "Cannot add a Wilson matching patch before WilsonBuilder has been built.");
242 }
243 this->cm->add_matching_patch(patch);
244}
245
246void WilsonBuilder::add_matching_patches(const std::vector<WilsonMatchingPatch>& patches) {
247 if (!this->cm) {
248 LOG_ERROR("LogicError", "Cannot add Wilson matching patches before WilsonBuilder has been built.");
249 }
250 this->cm->add_matching_patches(patches);
251}
252
253std::shared_ptr<WilsonProvider> WilsonBuilder::get_wilson_provider() {
254 return std::make_shared<WilsonProvider>(shared_from_this());
255}
256
257std::shared_ptr<CoefficientManager> WilsonBuilder::get_coefficient_manager() {
258 return cm;
259}
Builder assembling a CoefficientGroup from a GroupDefinition and a CoefficientRegistry.
std::shared_ptr< CustomCoefficientGroup > make_custom_wilson_group(const CustomWilsonGroupConfig &cfg, WilsonGroupAdapterConfig adapters)
Build a CustomCoefficientGroup from a lambda config.
Model
ContributionType
Declarative registry describing Wilson coefficient groups, their sources, and setup hooks.
#define LOG_ERROR(type,...)
Macro for logging error messages and terminating the application.
Definition Logger.h:41
#define LOG_VERBOSE(...)
Macro for logging verbose messages.
Definition Logger.h:47
Core-side adapter giving MARTY access to configuration and managed paths.
void register_CC_su(CoefficientRegistry &reg)
Registers coefficient factories for charged-current s->u (C_V1_su, ...).
void register_BScalar(CoefficientRegistry &reg)
Registers coefficient factories for the scalar B group (CQ1, CQ2).
void register_CC_du(CoefficientRegistry &reg)
Registers coefficient factories for charged-current d->u (C_V1_du, ...).
void register_BPrime(CoefficientRegistry &reg)
Registers coefficient factories for the B' group (CP1..CP10, CPQ1, CPQ2).
void register_CC_bc(CoefficientRegistry &reg)
Registers coefficient factories for charged-current b->c (C_V1_bc, ...).
void register_CC_cd(CoefficientRegistry &reg)
Registers coefficient factories for charged-current c->d (C_V1_cd, ...).
void register_K(CoefficientRegistry &reg)
Registers coefficient factories for the K group (CK9, CK10, ...).
void register_MesonMixing(CoefficientRegistry &reg)
Registers coefficient factories for meson mixing coefficients.
void register_CC_bu(CoefficientRegistry &reg)
Registers coefficient factories for charged-current b->u (C_V1_bu, ...).
void register_B(CoefficientRegistry &reg)
Registers coefficient factories for the B group (C1..C10).
void register_CC_cs(CoefficientRegistry &reg)
Registers coefficient factories for charged-current c->s (C_V1_cs, ...).
Factory registry for creating concrete WilsonCoefficient objects by (coefficient, model,...
Builds a ready-to-use CoefficientGroup instance from a BuildContext.
std::shared_ptr< CoefficientGroup > build(const BuildContext &ctx) const
Builds the coefficient group described by ctx.group_id.
static std::shared_ptr< CoefficientManager > Builder(std::map< std::string, std::shared_ptr< CoefficientGroup > > groups, double mu_W, double mu_h, std::string order, WilsonPortsConfig portconfig, std::map< Model, std::shared_ptr< IWilsonParameterHelper > > wilson_param_helpers={})
Factory that builds and initializes a manager from pre-created groups.
static std::string str(const IdOf< QCDOrderTag > &id)
Returns the string representation associated with an identifier.
static std::string str(const WGroupId &gid, ScaleType s, WilsonBasis b=WilsonBasis::B_STANDARD)
Builds a composite block name using a WGroupId, scale and basis.
fs::path get_path(MartyPath path_name) override
Retrieves a required MARTY-related path.
Core API returning the current Model.
Definition ModelAPI.h:28
Model get() override
Returns the active physics model.
Definition ModelAPI.h:35
Returns an uppercase copy of the input string.
WilsonBuilder(WilsonBuildConfig config)
Constructs and immediately builds the Wilson pipeline from a config.
void add(WilsonBuildConfig config) override
Add additional Wilson groups to an existing manager.
void add_matching_patches(const std::vector< WilsonMatchingPatch > &patches)
Add several additive matching patches to the active Wilson manager.
void build(WilsonBuildConfig config) override
Build a new Wilson pipeline from scratch.
std::shared_ptr< CoefficientManager > get_coefficient_manager()
Returns the underlying coefficient manager.
void add_matching_patch(const WilsonMatchingPatch &patch)
Add one additive matching patch to the active Wilson manager.
void add_custom_group(const CustomWilsonGroupConfig &config)
Register and initialize a user-defined Wilson group built from lambdas.
std::shared_ptr< WilsonProvider > get_wilson_provider()
Returns a provider facade around this builder.
Build-time context passed to group setup hooks.
WilsonGroupAdapterConfig adapters
Adapter bundle used by domain objects (storage proxy, composer, core APIs, optional MARTY proxy).
Configuration of a user-defined Wilson group built from lambdas.
double hadronic_scale
Hadronic/running scale used when the group is added to the manager.
WGroupId group
Dynamic group id. Register it with GroupMapper before use if it is custom.
QCDOrder order
Highest QCD order to initialize.
double matching_scale
Matching scale used when the group is added to the manager.
std::vector< CustomWilsonCoefficientConfig > coefficients
Coefficients belonging to the group.
Configuration for building sets of Wilson coefficients.
Definition Configs.h:32
std::unordered_set< WGroupId > groups
Set of Wilson operator group identifiers to be included in the build.
Definition Configs.h:36
double hadronic_scale
Hadronic scale (in GeV) at which the Wilson coefficients are evaluated in the effective theory.
Definition Configs.h:48
QCDOrder order
Perturbative QCD order used for the evolution and matching of Wilson coefficients....
Definition Configs.h:54
double matching_scale
Matching scale (in GeV) at which the high-energy theory is matched to the effective theory.
Definition Configs.h:42
Dependency injection bundle for CoefficientGroup.
fs::path sm_path
Default path to the SM MARTY header under assets.
Aggregates “ports” / APIs that connect the manager to the rest of the framework.
std::function< std::shared_ptr< CoefficientGroup >(WGroupId, Model, bool, ContributionType, std::string)> build_group
Optional group builder hook.