7 : id(id), expected(mean), deviation_stat(std_stat), deviation_syst(std_syst), shift(0), mode(
ParameterMode::
FIXED) {}
16 if (new_mode !=
mode) {
27 this->scale.emplace(
scale);
36 b->ensure_up_to_date();
42 LOG_DEBUG(
"Parameter::set_expected of ",
id.block,
" ",
id.code);
65 return this->
scale.value_or(-1.0);
69 return this->
binning.value_or(std::pair(-1.0, -1.0));
85 throw std::runtime_error(
"Cannot change the value of immutable parameter " +
id.block +
" " + std::to_string(
id.code));
91 [&](
const std::shared_ptr<Parameter>& p){ return p.get() == observer.get(); });
96 auto dependents = std::exchange(
observers, {});
97 LOG_DEBUG(
"cleaning param : ",this->
id.block,this->
id.code);
101 for (
auto& obs : dependents) {
102 if (obs) obs->clear_below();
138 for (
size_t i = 0; i <
observers.size(); ++i) {
140 if (!observer)
continue;
149 b->notifyObservers();
155 [&](
const std::shared_ptr<Parameter>& p){ return p.get() == observer.get(); });
162 os <<
" [" << p.
binning.value().first <<
"," << p.
binning.value().second <<
"] ";
Defines classes used to store parameters and to build derived/dependent parameter blocks.
#define LOG_DEBUG(...)
Macro for logging debug messages.
std::ostream & operator<<(std::ostream &os, const Parameter &p)
Defines the Parameter class used to store individual physical/model parameters.
ParameterMode
Defines the modes in which a parameter can operate.
@ FIXED
The parameter remains fixed at its expected value.
@ SHIFTABLE
The parameter value is shifted by an additive offset.
Represents a single parameter with value, uncertainties, and dependency links.
scalar_t deviation_syst
Systematic standard deviation.
std::optional< double > scale
Optional renormalization scale associated with the parameter.
ParameterMode mode
Current operating mode.
Parameter & operator+=(const Parameter &other)
Adds another parameter payload to this one.
std::vector< std::shared_ptr< Parameter > > observers
Observers notified when this parameter changes.
void set_id(ParamId id)
Replaces the identifier of the parameter.
void notifyParamObserversOnly()
Notifies only parameter observers.
void addObserver(std::shared_ptr< Parameter > observer)
Adds an observer parameter.
scalar_t expected
Expected value of the parameter.
virtual void clear_below()
Recursively clears downstream dependencies below this parameter.
Parameter()
Default constructor.
double get_scale()
Returns the parameter scale metadata.
virtual std::unordered_map< ParamId, std::shared_ptr< Parameter > > get_source_parameters() const
Returns the source parameters this parameter depends on.
void set_expected(scalar_t val)
Sets the expected value and notifies dependents.
void set_owner(ParameterType type)
Changes the owner ParameterType part of the identifier.
Parameter & operator=(const Parameter &other)
Assignment operator.
void overwrite_payload_from(const Parameter &other)
Overwrites the numerical/configuration payload from another parameter.
virtual void clear_above()
Hook to clear upstream dependencies.
scalar_t deviation_stat
Statistical standard deviation.
void set_bin(std::pair< double, double > bin)
Sets the binning metadata of the parameter.
virtual scalar_t get_val() const
Returns the current value of the parameter.
std::pair< scalar_t, scalar_t > get_std() const
Returns statistical and systematic uncertainties separately.
void removeObserver(std::shared_ptr< Parameter > observer)
Removes an observer parameter.
void set_expected_silent(scalar_t val)
Sets the expected value without notifying observers.
ParamId id
Unique identifier for the parameter.
std::pair< double, double > get_bin()
Returns the parameter bin metadata.
std::optional< std::pair< double, double > > binning
Optional energy bin [low, high] associated with the parameter.
std::weak_ptr< Block > get_owner_block() const
Returns the owning block of this parameter.
void set_owner_block(std::weak_ptr< Block > owner)
Sets the owning block of this parameter.
void set_std(scalar_t stat, scalar_t syst)
Sets the statistical and systematic uncertainties.
ParamId get_id() const
Returns the identifier of the parameter.
Parameter & operator*=(const scalar_t &scale)
Multiplies the parameter by a scalar factor.
scalar_t shift
Additive shift applied when the parameter is SHIFTABLE.
scalar_t get_combined_std() const
Returns the combined standard deviation.
void set_scale(double scale)
Sets the parameter scale metadata.
void notifyObservers()
Notifies downstream parameter observers and then the owner block.
void set_shift(scalar_t shift)
Sets the additive shift of the parameter.
void set_mode(ParameterMode mode)
Sets the parameter mode.
std::weak_ptr< Block > owner_block
Owning Block (if any) that this parameter belongs to.
Composite identifier for a single parameter.
void set_parameter_type(ParameterType type)
Sets or overwrites the parameter type.
BlockName block
Name of the block where the parameter is stored.
LhaID code
Index or multi-index of the parameter inside the block.