Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
LambdaDecay.h
Go to the documentation of this file.
1#ifndef LAMBDA_DECAY_H
2#define LAMBDA_DECAY_H
3
4#include <any>
5#include <functional>
6#include <optional>
7#include <string>
8#include <unordered_map>
9#include <unordered_set>
10#include <utility>
11#include <vector>
12
13#include "DecayParent.h"
14#include "CustomWilsonLambda.h"
15#include "mapper_hub.hpp"
16
17class LambdaDecay;
18
32 std::function<std::vector<ObservableValue>(LambdaDecay&, ObservableId)>;
33
40using LambdaDecayLoadHook = std::function<void(LambdaDecay&)>;
41
49using LambdaDecayConfigureHook = std::function<void(LambdaDecay&, const std::any&)>;
50
61 std::string canonical;
62
64 std::vector<std::string> aliases {};
65
67 std::optional<LhaID> flha = std::nullopt;
68
70 std::unordered_set<ParamId> dependencies {};
71
74
76
80 LambdaObservableConfig(std::string canonical_, LambdaObservableComputer compute_)
81 : canonical(std::move(canonical_)), compute(std::move(compute_)) {}
82
90 std::string canonical_,
91 std::function<double(LambdaDecay&, ObservableId)> compute_
92 ) {
94 out.canonical = std::move(canonical_);
95 out.compute = [fn = std::move(compute_)](LambdaDecay& ctx, ObservableId id) {
96 return std::vector<ObservableValue>{ObservableValue(id, fn(ctx, id))};
97 };
98 return out;
99 }
100
110 std::string canonical_,
111 std::function<double(LambdaDecay&, std::pair<double,double>, ObservableId)> compute_
112 );
113};
114
126 std::string canonical;
127
129 std::vector<std::string> aliases {};
130
132 double matching_scale = 81.0;
133
135 double hadronic_scale = 4.8;
136
139
142
144 std::unordered_set<WGroupId> wilson_groups {};
145
154 std::vector<CustomWilsonGroupConfig> custom_wilson_groups {};
155
157 std::vector<LambdaObservableConfig> observables {};
158
173
176
179};
180
198class LambdaDecay : public DecayParent {
199public:
208 : DecayParent(id, config.matching_scale, config.hadronic_scale, config.order, ports),
209 config_(std::move(config))
210 {
211 this->max_order = config_.max_order;
212 this->w_config.groups = config_.wilson_groups;
213
214 for (const auto& custom_group : config_.custom_wilson_groups) {
215 this->w_config.groups.insert(custom_group.group);
216 }
217
218 for (const auto& obs : config_.observables) {
219 if (!obs.compute) {
220 LOG_ERROR("ValueError", "Lambda observable", obs.canonical, "has no compute function.");
221 }
222 computers_.emplace(ObservableMapper::id_of(obs.canonical), obs.compute);
223 }
224 }
225
229 void load_params() override {
230 if (config_.load_params) {
231 config_.load_params(*this);
232 }
233 }
234
238 std::vector<ObservableValue> compute_observable(Observables obs) override {
240 }
241
245 std::vector<ObservableValue> compute_observable(ObservableId obs) override {
246 auto it = computers_.find(obs);
247 if (it == computers_.end()) {
248 LOG_ERROR("KeyError", "Lambda decay", DecayMapper::str(this->id),
249 "does not contain observable", ObservableMapper::str(obs));
250 }
251 return it->second(*this, obs);
252 }
253
257 void set_config(std::any cfg) override {
258 runtime_config_ = std::move(cfg);
259 if (config_.configure) {
260 config_.configure(*this, runtime_config_);
261 }
262 }
263
265 const LambdaDecayConfig& config() const { return config_; }
266
268 const std::any& user_config() const { return runtime_config_; }
269
271 bool has_user_config() const { return runtime_config_.has_value(); }
272
275 if (!this->w_proxy) {
276 LOG_ERROR("LogicError", "Wilson proxy is not available before LambdaDecay is enabled.");
277 }
278 return *this->w_proxy;
279 }
280
282 std::shared_ptr<IObsWilsonProxy> wilson_proxy() {
283 if (!this->w_proxy) {
284 LOG_ERROR("LogicError", "Wilson proxy is not available before LambdaDecay is enabled.");
285 }
286 return this->w_proxy;
287 }
288
291
294
296 IObsQCDProxy& QCD() { return *this->iobs_qcdp; }
297
300
302 std::optional<std::vector<std::pair<double,double>>> current_bins() { return this->get_bins(); }
303
304private:
305 LambdaDecayConfig config_;
306 std::any runtime_config_;
307 std::unordered_map<ObservableId, LambdaObservableComputer> computers_;
308};
309
311 std::string canonical_,
312 std::function<double(LambdaDecay&, std::pair<double,double>, ObservableId)> compute_
313) {
315 out.canonical = std::move(canonical_);
316 out.compute = [fn = std::move(compute_)](LambdaDecay& ctx, ObservableId id) {
317 std::vector<ObservableValue> values;
318 auto bins = ctx.current_bins();
319 if (!bins.has_value() || bins->empty()) {
320 values.emplace_back(id, fn(ctx, {0.0, 0.0}, id));
321 return values;
322 }
323
324 values.reserve(bins->size());
325 for (const auto& bin : *bins) {
326 values.emplace_back(id, fn(ctx, bin, id), bin);
327 }
328 return values;
329 };
330 return out;
331}
332
333#endif // LAMBDA_DECAY_H
High-level configuration helpers for user-defined Wilson groups and coefficients.
Base class for observable/decay computation modules.
Observables
Definition GeneralEnum.h:4
QCDOrder
std::function< void(LambdaDecay &, const std::any &)> LambdaDecayConfigureHook
Optional hook called from LambdaDecay::set_config().
Definition LambdaDecay.h:49
std::function< std::vector< ObservableValue >(LambdaDecay &, ObservableId)> LambdaObservableComputer
User function used to compute a runtime/custom observable.
Definition LambdaDecay.h:32
std::function< void(LambdaDecay &)> LambdaDecayLoadHook
Optional hook called when the lambda decay is enabled/reloaded.
Definition LambdaDecay.h:40
#define LOG_ERROR(type,...)
Macro for logging error messages and terminating the application.
Definition Logger.h:41
Abstract base class for a decay/observable module.
Definition DecayParent.h:87
DecayId id
Unique decay identifier.
WilsonBuildConfig w_config
Wilson build configuration used when enabling this decay (scales, order, groups).
ObservablePortsConfig & ports
Reference to the ports/configuration wiring this decay to the framework.
Definition DecayParent.h:93
std::shared_ptr< IObsParameterProxy< ParamId, DataType, std::string, LhaID > > p
Parameter proxy for SM-like quantities used by the decay (may be SM/BSM depending on wiring).
QCDOrder max_order
Maximum QCD order supported by this decay module (default: LO).
Definition DecayParent.h:90
std::shared_ptr< IObsWilsonProxy > w_proxy
Wilson proxy used at compute-time to query coefficients (matching/run).
Definition DecayParent.h:99
std::shared_ptr< IObsQCDProxy > iobs_qcdp
QCD proxy (alpha_s, running masses, constants...).
std::optional< std::vector< std::pair< double, double > > > get_bins()
Returns the current binning of the decay.
static IdOf< ObservableTag > to_id(Observables e)
Converts an enum value to an IdOf<Tag>.
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< DecayTag > &id)
Returns the string representation of an identifier.
DecayParent implementation backed by user-provided lambdas.
ObservablePortsConfig & observable_ports()
Access all observable ports for advanced use.
bool has_user_config() const
True if set_config() has received a payload.
LambdaDecay(DecayId id, LambdaDecayConfig config, ObservablePortsConfig &ports)
Construct a lambda-backed decay from a dynamic id and config.
IObsWilsonProxy & W()
Access the Wilson proxy after enable().
void set_config(std::any cfg) override
Store and optionally handle a type-erased user config.
std::vector< ObservableValue > compute_observable(Observables obs) override
Compute a builtin observable by converting it to ObservableId.
IObsQCDProxy & QCD()
Access the QCD proxy used by decays.
std::optional< std::vector< std::pair< double, double > > > current_bins()
Return the current optional bin list.
IObsParameterProxy< ParamId, DataType, std::string, LhaID > & SM()
Access the SM/BSM parameter proxy used by decays.
std::vector< ObservableValue > compute_observable(ObservableId obs) override
Compute a runtime/custom observable by dispatching to its lambda.
const std::any & user_config() const
Access the last std::any payload passed to set_config().
void load_params() override
Run the user-defined loading/cache hook, if any.
const LambdaDecayConfig & config() const
Access the immutable LambdaDecayConfig.
std::shared_ptr< IObsWilsonProxy > wilson_proxy()
Access the Wilson proxy as a shared pointer after enable().
IObsParameterProxy< ParamId, DataType, std::string, LhaID > & FLAVOR()
Access the FLAVOR parameter proxy from the ports configuration.
Non-templated façade over the project mapper families.
Hash specialization for SymbolId<Tag>.
Definition BlockName.h:353
Full runtime definition of a custom decay and its observables.
std::vector< CustomWilsonGroupConfig > custom_wilson_groups
Custom Wilson groups to install before this decay is evaluated.
std::vector< LambdaObservableConfig > observables
Custom observables owned by this decay. Must not be empty.
double matching_scale
Matching scale used by the decay's Wilson build config.
QCDOrder max_order
Maximum QCD order supported by this custom decay.
QCDOrder order
Requested QCD order for the decay.
bool propagate_custom_wilson_dependencies
Propagate custom-Wilson matching dependencies to every observable.
std::vector< std::string > aliases
Optional alternative decay names accepted by DecayMapper::id_of().
LambdaDecayConfigureHook configure
Optional type-erased configuration hook called by LambdaDecay::set_config().
LambdaDecayLoadHook load_params
Optional cache/loading hook called by LambdaDecay::load_params().
double hadronic_scale
Hadronic scale used by the decay's Wilson build config.
std::unordered_set< WGroupId > wilson_groups
Builtin or already-registered Wilson groups needed by the decay.
std::string canonical
Canonical decay name, for example "MY_DECAY".
Registration and compute function for one runtime/custom observable.
Definition LambdaDecay.h:59
std::unordered_set< ParamId > dependencies
Optional dependency list used by scans/profilers/likelihood tooling.
Definition LambdaDecay.h:70
LambdaObservableConfig(std::string canonical_, LambdaObservableComputer compute_)
Construct a custom observable from a vector-valued compute lambda.
Definition LambdaDecay.h:80
LambdaObservableConfig()=default
static LambdaObservableConfig binned_scalar(std::string canonical_, std::function< double(LambdaDecay &, std::pair< double, double >, ObservableId)> compute_)
Convenience factory for a scalar binned observable.
std::string canonical
Canonical observable name, for example "BR_MY_DECAY".
Definition LambdaDecay.h:61
static LambdaObservableConfig scalar(std::string canonical_, std::function< double(LambdaDecay &, ObservableId)> compute_)
Convenience factory for a scalar, unbinned observable.
Definition LambdaDecay.h:89
std::optional< LhaID > flha
Optional FLHA id used for experimental values / binned encodings.
Definition LambdaDecay.h:67
LambdaObservableComputer compute
User-provided observable computation.
Definition LambdaDecay.h:73
std::vector< std::string > aliases
Optional alternative names accepted by ObservableMapper::id_of().
Definition LambdaDecay.h:64
Dependency container (“ports”) for observable computations.
std::shared_ptr< IObsParameterProxy< ParamId, DataType, std::string, LhaID > > iobspp_flav
Parameter proxy for flavor-specific parameters.
Container for a computed observable value, optionally binned.
std::unordered_set< WGroupId > groups
Set of Wilson operator group identifiers to be included in the build.
Definition Configs.h:36