Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
MarginalConfigFactory.cpp
Go to the documentation of this file.
2
3#include <cmath>
4#include <stdexcept>
5#include <utility>
6
8 std::shared_ptr<IStatParameterProxy> parameter_proxy
9)
10 : parameter_proxy_(std::move(parameter_proxy))
11{
12 if (!parameter_proxy_) {
13 throw std::invalid_argument(
14 "MarginalConfigFactory: parameter_proxy is null"
15 );
16 }
17}
18
19
21 double mu, sigma;
22
23 switch (marginal) {
25 mu = (*parameter_proxy_)(pid, DataType::VALUE);
26 sigma = (*parameter_proxy_)(pid, DataType::STD_COMBINED);
27 return GaussianMarginalCfg {mu, sigma};
29 mu = (*parameter_proxy_)(pid, DataType::VALUE);
30 sigma = (*parameter_proxy_)(pid, DataType::STD_COMBINED);
31 return FlatMarginalCfg {mu - sigma * std::sqrt(3), mu + sigma * std::sqrt(3)};
33 throw std::logic_error(
34 "MarginalConfigFactory: HALF_GAUSSIAN parameter marginals are not implemented"
35 );
37 throw std::logic_error(
38 "MarginalConfigFactory: LIKELIHOOD parameter marginals are not implemented"
39 );
40 default:
41 throw std::invalid_argument("Unknown marginal type");
42 }
43}
44
45
47 MarginalType marginal,
48 const NuisanceSpec& spec) const {
49 if (spec.param_id.block != pid.block || spec.param_id.code != pid.code) {
50 throw std::invalid_argument(
51 "MarginalConfigFactory: nuisance specification does not match parameter block/code"
52 );
53 }
54
55 if (marginal == MarginalType::FLAT) {
56 const auto [lower, upper] = spec.bounds;
57 if (!std::isfinite(lower) || !std::isfinite(upper) || !(lower < upper)) {
58 throw std::invalid_argument(
59 "MarginalConfigFactory: flat nuisance bounds must be finite and strictly ordered"
60 );
61 }
62 return FlatMarginalCfg{lower, upper};
63 }
64
65 return create(pid, marginal);
66}
67
69 MarginalType marginal) const {
70 std::map<ExperimentObs, double> sigma =
71 (*parameter_proxy_)(oid.obs, DataType::STD_COMBINED);
72 switch (marginal) {
74 for (const auto& [experiment, uncertainty] : sigma) {
75 if (experiment == oid) {
76 return GaussianMarginalCfg {0.0, uncertainty};
77 }
78 }
79 throw std::out_of_range(
80 "MarginalConfigFactory: no combined uncertainty found for the requested observable"
81 );
83 for (const auto& [experiment, uncertainty] : sigma) {
84 if (experiment == oid) {
85 return FlatMarginalCfg {
86 -uncertainty * std::sqrt(3),
87 uncertainty * std::sqrt(3)
88 };
89 }
90 }
91 throw std::out_of_range(
92 "MarginalConfigFactory: no combined uncertainty found for the requested observable"
93 );
95 throw std::logic_error(
96 "MarginalConfigFactory: HALF_GAUSSIAN observable marginals are not implemented"
97 );
99 throw std::logic_error(
100 "MarginalConfigFactory: LIKELIHOOD observable marginals are not implemented"
101 );
102 default:
103 throw std::invalid_argument("Unknown marginal type");
104 }
105}
Factory for building marginal-distribution configuration objects.
MarginalType
Supported marginal-distribution families.
@ GAUSSIAN
Symmetric Gaussian marginal.
@ HALF_GAUSSIAN
Asymmetric / half-Gaussian-like marginal (currently mapped to split Gaussian logic).
@ LIKELIHOOD
Discrete likelihood-based marginal built from weighted support points.
@ FLAT
Uniform (flat) marginal on a finite interval.
MarginalConfigFactory(std::shared_ptr< IStatParameterProxy > parameter_proxy)
Constructs the factory with its parameter-access port.
MarginalConfig create(ParamId pid, MarginalType marginal) const
Builds a marginal configuration from a parameter identifier.
Hash specialization for SymbolId<Tag>.
Definition BlockName.h:353
BinnedObservableId obs
Configuration object for FlatMarginal.
Configuration object for GaussianMarginal.
Specification of one nuisance parameter.
std::pair< double, double > bounds
Inclusive lower and upper bounds for the nuisance value.
ParamId param_id
Parameter identifier, usually an LHA block/code pair.
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
LhaID code
Index or multi-index of the parameter inside the block.
Definition ParamID.h:82