8std::map<ParameterType, std::shared_ptr<Parameters>> Parameters::instances;
9std::map<ParameterType, std::shared_ptr<Parameters>> ParametersFactory::instances;
13 const auto& allowed = ctx->parameter_types();
14 if (std::find(allowed.begin(), allowed.end(),
id) == allowed.end())
16 return ctx->get_parameters(
id);
20 if (std::find(allowed.begin(), allowed.end(),
id) == allowed.end())
30 for (
auto& [_, block] : *blockAccessor) {
31 block->set_owner(type);
35Parameters::Parameters(std::shared_ptr<ModelStrategy> modelStrategy)
36 : strategy(modelStrategy)
39 auto truc = strategy->initializeParameters(*
this);
40 strategy->add_absent_block(truc);
44 return blockAccessor->getValue(block,
id);
49 return blockAccessor->at(block)->retrieve(pdgCode);
53 if (!blockAccessor->contains(block))
return false;
54 return blockAccessor->at(block)->contains(
id);
58 blockAccessor->setValue(name,
id, value);
62 return blockAccessor->getAllValues(blockName);
66 return this->blockAccessor->at(blockName)->get_scale();
71 return blockAccessor->get_block_names();
75 return blockAccessor->is_dependent_block(blockName);
79 return blockAccessor->get_source_block_names(blockName);
83 return blockAccessor->get_dependent_block_names(blockName);
87 return blockAccessor->get_all_source_block_names(blockName);
91 return blockAccessor->get_all_dependent_block_names(blockName);
95 if (expected == actual) {
99 if (expected ==
"FOBS") {
100 return actual.to_string().starts_with(
"FOBS_");
109 std::unordered_set<BlockName> blocks_to_extract;
110 std::unordered_set<BlockName> missing;
112 const auto available_blocks =
120 for (
const auto& actual : available_blocks) {
123 blocks_to_extract.insert(actual);
128 missing.insert(expected);
134 blocks_to_extract.erase(
"FWCOEF");
135 blocks_to_extract.erase(
"IMFWCOEF");
141 throw std::logic_error(
"Theoretical observable input is not implemented");
145 this->blockAccessor = ctx->extract_blocks(blocks_to_extract);
149 claim_parameters(type);
154 if (!blockAccessor->contains(blockName)) {
156 LOG_ERROR(
"Cannot freeze non-existing block", blockName);
159 return this->blockAccessor->at(blockName)->freeze();
163 return this->blockAccessor->at(blockName)->unfreeze();
167 if (!blockAccessor->contains(blockName)) {
168 LOG_ERROR(
"Cannot freeze dependent parameter in non-existing block", blockName);
171 if (!blockAccessor->at(blockName)->contains(
id)) {
172 LOG_ERROR(
"Cannot freeze non-existing dependent parameter",
id.
to_string(),
"in block", blockName);
175 return this->blockAccessor->at(blockName)->retrieve(
id)->freeze();
179 return this->blockAccessor->at(blockName)->retrieve(
id)->unfreeze();
183 this->blockAccessor->detach_block(blockName);
187 this->blockAccessor->reattach_block(blockName);
191 this->blockAccessor->detach_parameter(blockName,
id);
195 this->blockAccessor->reattach_parameter(blockName,
id);
198std::ostream &
operator<<(std::ostream &os, std::shared_ptr<Parameters> instance) {
199 os << instance->blockAccessor;
210double superiso_scale(
double ref_mass,
double x_log2)
212 return (x_log2 > 0.0)
213 ? std::pow(2.0, x_log2) * ref_mass
217void add_wilson_ew_scale_from_nuisance()
219 std::unordered_map<ParameterType, std::vector<std::string>> src = {
225 [] (
const BlockSrc& src, std::shared_ptr<DependentBlock> dep_block)
227 const double x_W = src.get_val(
"SCALE_NUIS", 1);
228 const double m_W = src.get_val(
"MASS", 24);
230 const double mu_W = superiso_scale(m_W, x_W);
232 dep_block->store_or_assign(
234 std::make_shared<Parameter>(
249void add_wilson_b_scale_from_nuisance()
251 std::unordered_map<ParameterType, std::vector<std::string>> src = {
257 [] (
const BlockSrc& src, std::shared_ptr<DependentBlock> dep_block)
259 const double x_b = src.get_val(
"SCALE_NUIS", 2);
261 const double m_b_pole = src.get_val(
"QCD",
LhaID(5, 2));
263 const double mu_b = superiso_scale(m_b_pole, x_b);
265 dep_block->store_or_assign(
267 std::make_shared<Parameter>(
289 std::unordered_map<ParameterType, std::vector<std::string>> src_ckm = {
293 auto func_ckm = [] (
const BlockSrc& src, std::shared_ptr<DependentBlock> dep_block) {
294 double lambda = src.
get_val(
"VCKMIN", 1);
295 double l2 = lambda * lambda;
296 double l3 = l2 * lambda;
297 double A = src.
get_val(
"VCKMIN", 2);
298 double rho = src.
get_val(
"VCKMIN", 3);
299 double eta = src.
get_val(
"VCKMIN", 4);
301 double s_12 = lambda;
302 double s_23 = A * l2;
303 complex_t u_13 = A * l3 *
complex_t(rho, eta) * sqrt(1 - std::pow(A * l2, 2)) / (std::sqrt(1 - l2) * (1. - std::pow(A * l2, 2) *
complex_t(rho, eta)));
304 double s_13 = std::abs(u_13);
306 double c_12 = std::sqrt(1 - s_12 * s_12);
307 double c_23 = std::sqrt(1 - s_23 * s_23);
308 double c_13 = std::sqrt(1 - s_13 * s_13);
313 dep_block->store_or_assign(
LhaID(1, 0), std::make_shared<Parameter>(
ParamId{
ParameterType::SM,
"VCKM",
LhaID(1, 0)}, -s_12 * c_23 - c_12 * s_23 * s_13 * expid, 0., 0.));
314 dep_block->store_or_assign(
LhaID(1, 1), std::make_shared<Parameter>(
ParamId{
ParameterType::SM,
"VCKM",
LhaID(1, 1)}, c_12 * c_23 - s_12 * s_23 * s_13 * expid, 0., 0.));
316 dep_block->store_or_assign(
LhaID(2, 0), std::make_shared<Parameter>(
ParamId{
ParameterType::SM,
"VCKM",
LhaID(2, 0)}, s_12 * s_23 - c_12 * c_23 * s_13 * expid, 0., 0.));
317 dep_block->store_or_assign(
LhaID(2, 1), std::make_shared<Parameter>(
ParamId{
ParameterType::SM,
"VCKM",
LhaID(2, 1)}, -c_12 * s_23 - s_12 * c_23 * s_13 * expid, 0., 0.));
325 std::unordered_map<ParameterType, std::vector<std::string>> src_pmns = {
329 auto func_pmns = [] (
const BlockSrc& src, std::shared_ptr<DependentBlock> dep_block) {
330 double theta_12 = src.
get_val(
"UPMNSIN", 1);
331 double theta_23 = src.
get_val(
"UPMNSIN", 2);
332 double theta_13 = src.
get_val(
"UPMNSIN", 3);
333 double delta = src.
get_val(
"UPMNSIN", 4);
334 double alpha_1 = src.
get_val(
"UPMNSIN", 5);
335 double alpha_2 = src.
get_val(
"UPMNSIN", 6);
337 double s_12 = std::sin(theta_12);
338 double s_23 = std::sin(theta_23);
339 double s_13 = std::sin(theta_13);
340 double c_12 = std::sqrt(1 - s_12 * s_12);
341 double c_23 = std::sqrt(1 - s_23 * s_23);
342 double c_13 = std::sqrt(1 - s_13 * s_13);
344 complex_t exp_i_alpha_1 = std::exp(
I * alpha_1);
345 complex_t exp_i_alpha_2 = std::exp(
I * alpha_2);
350 dep_block->store_or_assign(
LhaID(1, 0), std::make_shared<Parameter>(
ParamId{
ParameterType::SM,
"UPMNS",
LhaID(1, 0)}, (-s_12 * c_23 - c_12 * s_23 * s_13 * exp_i_delta) * exp_i_alpha_1, 0., 0.));
351 dep_block->store_or_assign(
LhaID(1, 1), std::make_shared<Parameter>(
ParamId{
ParameterType::SM,
"UPMNS",
LhaID(1, 1)}, (c_12 * c_23 - s_12 * s_23 * s_13 * exp_i_delta) * exp_i_alpha_2, 0., 0.));
353 dep_block->store_or_assign(
LhaID(2, 0), std::make_shared<Parameter>(
ParamId{
ParameterType::SM,
"UPMNS",
LhaID(2, 0)}, (s_12 * s_23 - c_12 * c_23 * s_13 * exp_i_delta) * exp_i_alpha_1, 0., 0.));
354 dep_block->store_or_assign(
LhaID(2, 1), std::make_shared<Parameter>(
ParamId{
ParameterType::SM,
"UPMNS",
LhaID(2, 1)}, (-c_12 * s_23 - s_12 * c_23 * s_13 * exp_i_delta) * exp_i_alpha_2, 0., 0.));
363 const bool has_ew_scale = wilson_params->exist(
"EW_SCALE", 1);
364 const bool has_b_scale = wilson_params->exist(
"B_SCALE", 1);
366 const bool has_x_w = wilson_params->exist(
"SCALE_NUIS", 1);
367 const bool has_x_b = wilson_params->exist(
"SCALE_NUIS", 2);
373 "WILSON::EW_SCALE[1] is absent and WILSON::SCALE_NUIS[1] is absent. "
374 "Provide either EW_SCALE directly or SCALE_NUIS[1] to derive it."
378 add_wilson_ew_scale_from_nuisance();
387 "WILSON::B_SCALE[1] is absent and WILSON::SCALE_NUIS[2] is absent. "
388 "Provide either B_SCALE directly or SCALE_NUIS[2] to derive it."
392 add_wilson_b_scale_from_nuisance();
398 std::unordered_map<ParameterType, std::vector<std::string>> src = {
403 auto func = [] (
const BlockSrc& src, std::shared_ptr<DependentBlock> dep_block) {
404 double mu_W = src.get_val(
"EW_SCALE", 1);
410 dep_block->store_or_assign(4, std::make_shared<Parameter>(
ParamId{
ParameterType::SM,
"MASS_EW_SCALE", 4}, mass_c_muW, 0., 0.));
413 dep_block->store_or_assign(6, std::make_shared<Parameter>(
ParamId{
ParameterType::SM,
"MASS_EW_SCALE", 6}, mass_top_muW, 0., 0.));
428 auto ensure_zero_7x7 = [&](
const std::string& block_name) {
430 if (have.find(block_name) != have.end())
return;
432 auto filler = [](
const BlockSrc&, std::shared_ptr<DependentBlock> dep_block) {
433 for (
int i = 1; i <= 7; ++i) {
434 for (
int j = 1; j <= 7; ++j) {
435 dep_block->store_or_assign(
437 std::make_shared<Parameter>(
454 ensure_zero_7x7(
"USQMIX");
455 ensure_zero_7x7(
"DSQMIX");
477 if (params.
exist(
"EW_SCALE", 1)) {
486 [muW](
const BlockSrc&, std::shared_ptr<DependentBlock> dep_block) {
487 dep_block->store_or_assign(
489 std::make_shared<Parameter>(
519 blockAccessor->setValue(param_id.
block, param_id.
code, blockAccessor->getValue(param_id.
block, param_id.
code) + shift_value);
523 auto it = instances.find(
id);
524 if (it != instances.end()) {
531 [
id](
const std::shared_ptr<Parameters>& params) {
532 ParametersFactory::instances[id] = params;
536 ParametersFactory::instances.erase(
id);
547 const std::function<
void(
const std::shared_ptr<Parameters>&)>& register_before_postinit
549 std::shared_ptr<ModelStrategy> strategy = createStrategy(
id);
550 auto params = std::shared_ptr<Parameters>(
new Parameters(strategy));
552 if (register_before_postinit) {
553 register_before_postinit(params);
556 strategy->postInitialization(*params);
561 if (instances.find(
id) == instances.end()) {
562 LOG_ERROR(
"OutOfRange",
"Cannot remove parameters if it doesn't exist");
565 std::shared_ptr<Parameters> _ = instances[id];
569std::shared_ptr<ModelStrategy> ParametersFactory::createStrategy(
ParameterType id) {
586 throw std::invalid_argument(
"Unknown parameters instance ID");
595 std::cout << this->blockAccessor->at(blockname) << std::endl;
@ HAS_TH_OBSERVABLE_INPUT
User provided theoretical observable input.
@ HAS_WILSON_INPUT
User provided Wilson coefficient input.
Provides static utilities to create, manage, and update dependent blocks and dependent parameters.
#define LOG_ERROR(type,...)
Macro for logging error messages and terminating the application.
#define LOG_INFO(...)
Macro for logging informational messages.
#define LOG_DEBUG(...)
Macro for logging debug messages.
#define LOG_VERBOSE(...)
Macro for logging verbose messages.
Manages memory caching, parameter blocks, and LHA reader instances.
ParameterMode
Defines the modes in which a parameter can operate.
std::ostream & operator<<(std::ostream &os, std::shared_ptr< Parameters > instance)
Model-dependent parameter repository and initialization strategies.
std::string to_string(const LhaID &id)
Convenience stringification for LhaID.
std::complex< double > complex_t
Convenience alias for std::complex<double>.
Strategy responsible for BSM parameters.
std::unordered_set< BlockName > initializeParameters(class Parameters ¶ms) override
Initializes the block set for the target parameter repository.
void postInitialization(Parameters ¶ms) override
Performs additional initialization after raw blocks are loaded.
Block identifier with alias support.
Lightweight view over a set of source blocks.
scalar_t get_val(std::string_view blk, std::initializer_list< long > code) const
Retrieves the value of a parameter given as an initializer_list.
Strategy responsible for decay-related parameter blocks.
std::unordered_set< BlockName > initializeParameters(class Parameters ¶ms) override
Initializes the block set for the target parameter repository.
static void addDependentBlock(std::string name, std::unordered_map< ParameterType, std::vector< std::string > > source_names, ParameterType dest, DepUpdateFunc recalculateFunc)
Adds a DependentBlock with multiple sources coming from various Parameters instances.
static void Init()
Initializes the EW dependent block.
Strategy responsible for flavor-sector input blocks.
std::unordered_set< BlockName > initializeParameters(class Parameters ¶ms) override
Initializes the block set for the target parameter repository.
static std::string str(const IdOf< ParamTypeTag > &id)
Returns the string representation associated with an identifier.
const MemoryCache & getMemoryCache()
Retrieves the current memory cache.
static MemoryManager * GetInstance()
Retrieves the singleton instance of MemoryManager.
std::shared_ptr< BlockAccessor > extract_blocks(std::unordered_set< BlockName > block_names)
Extracts specific blocks from the cached input.
std::unordered_set< BlockName > absent_blocks
Strategy responsible for observable-related blocks.
std::unordered_set< BlockName > initializeParameters(class Parameters ¶ms) override
Initializes the block set for the target parameter repository.
static std::unordered_set< BlockName > GetOwnedBlocks(ParameterType ptype)
Retrieves all blocks owned by a given ParameterType.
std::unordered_set< BlockName > available_input_blocks() const
static ParameterRuntimeContext * current()
static std::shared_ptr< Parameters > CreateUncachedRegistered(ParameterType id, const std::function< void(const std::shared_ptr< Parameters > &)> ®ister_before_postinit)
Creates a fresh uncached repository and registers it before post-initialization.
static std::shared_ptr< Parameters > CreateUncached(ParameterType id)
Creates a fresh uncached repository for a runtime context.
static std::shared_ptr< Parameters > GetParameters(ParameterType id)
Returns the cached repository for one parameter type.
static void removeParameters(ParameterType id)
Removes one cached repository.
Block-based parameter repository for one ParameterType namespace.
void reattach_block(const BlockName &blockName)
Reattaches one previously detached dependent block.
void detach_param(const BlockName &blockName, const LhaID &id)
Detaches one dependent parameter from its upstream dependencies.
std::vector< std::string > get_dependent_blocks(const BlockName &blockName) const
Returns the direct blocks depending on one block.
std::vector< std::string > get_all_dependent_blocks(const BlockName &blockName) const
Returns all transitive blocks depending on one block.
std::unordered_set< BlockName > get_blocks_list()
Returns the list of blocks currently held in this repository.
void unfreeze_block(const BlockName &blockName)
Freezes one whole block.
void reattach_param(const BlockName &blockName, const LhaID &id)
Reattaches one previously detached dependent parameter.
void shiftParameter(const ParamId ¶m_id, scalar_t shift_value)
Applies an additive shift to a parameter by rewriting its value.
void CleanupInstance(ParameterType id=ParameterType::SM)
Removes one repository instance from the factory cache.
bool exist(const BlockName &block, LhaID pdgCode)
Checks whether a parameter exists in a given block.
std::unordered_set< BlockName > init_blocks(ParameterType type)
Loads the raw blocks for one parameter namespace from MemoryManager.
scalar_t operator()(const BlockName &block, LhaID pdgCode) const
Reads the current scalar value of a parameter.
void setBlockValue(const BlockName &name, LhaID pdgCode, scalar_t value)
Sets or creates a scalar value inside a block.
void detach_block(const BlockName &blockName)
Detaches one dependent block from its upstream dependency graph.
void changeParameterMode(const ParamId ¶m_id, ParameterMode new_mode)
Changes the mode of one parameter.
std::shared_ptr< Parameter > get_parameter(const BlockName &block, LhaID pdgCode)
Returns the full Parameter object for one entry.
static std::shared_ptr< Parameters > GetInstance(ParameterType id=ParameterType::SM)
Returns the singleton-like repository for a given parameter type.
std::vector< std::string > get_source_blocks(const BlockName &blockName) const
Returns the direct source blocks of one block.
double get_block_scale(BlockName blockName) const
Returns the scale attached to a block.
void unfreeze_param(const BlockName &blockName, const LhaID &id)
Unfreezes one parameter inside a block.
std::map< LhaID, scalar_t > get_block_infos(BlockName blockName)
Returns all scalar values stored in one block.
void freeze_param(const BlockName &blockName, const LhaID &id)
Freezes one parameter inside a block.
void freeze_block(const BlockName &blockName)
Freezes one whole block.
void print_block(const std::string blockname)
Prints one block to stdout.
std::vector< std::string > get_all_source_blocks(const BlockName &blockName) const
Returns all transitive source blocks of one block.
bool is_dependent_block(const BlockName &blockName) const
Checks whether one block is a dependent block.
Strategy responsible for passthrough / output-preserved blocks.
std::unordered_set< BlockName > initializeParameters(class Parameters ¶ms) override
Initializes the block set for the target parameter repository.
static double msbar_mass(int pdg_code, double mu, MassType mass_b_type=MassType::POLE, MassType mass_t_type=MassType::POLE)
Computes the MS-bar running mass of a quark at scale μ.
static void Init()
Initializes the QCD dependent block.
Strategy responsible for Standard Model parameters.
void postInitialization(Parameters ¶ms) override
Performs additional initialization after raw blocks are loaded.
std::unordered_set< BlockName > initializeParameters(class Parameters ¶ms) override
Initializes the block set for the target parameter repository.
constexpr std::complex< double > I
std::map< ExternalFlag, bool > flags
External flags describing the nature of the inputs.
Represents an identifier of a LHA element, possibly containing several sub-ids.
std::vector< ParameterType > parameter_types
List of parameter types currently managed.
HyperisoConfig config
Config struct for various flags and runtime information.
Composite identifier for a single parameter.
BlockName block
Name of the block where the parameter is stored.
LhaID code
Index or multi-index of the parameter inside the block.