Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
Parameter.h
Go to the documentation of this file.
1#ifndef PARAMETER_H
2#define PARAMETER_H
3
4#include <string>
5#include <iostream>
6#include <functional>
7
8#include "Logger.h"
9#include "Include.h"
10#include "Math.h"
11
36class Block;
37
45enum class ParameterMode {
46 FIXED,
48};
49
78class Parameter : public std::enable_shared_from_this<Parameter> {
79protected:
86 std::vector<std::shared_ptr<Parameter>> observers;
87 std::weak_ptr<Block> owner_block;
88 std::optional<double> scale;
89 std::optional<std::pair<double, double>> binning;
90
91public:
103
114 Parameter(ParamId id, scalar_t mean, scalar_t std_stat, scalar_t std_syst);
115
122 Parameter(const Parameter& other);
123
132
139 void set_std(scalar_t stat, scalar_t syst);
140
148 void set_scale(double scale);
149
155 void set_bin(std::pair<double, double> bin);
156
162 void set_id(ParamId id);
163
177 virtual scalar_t get_val() const;
178
186 void set_expected(scalar_t val);
187
198
210
217 std::pair<scalar_t, scalar_t> get_std() const;
218
226 double get_scale();
227
235 std::pair<double, double> get_bin();
236
237
243 ParamId get_id() const;
244
252 void set_owner(ParameterType type);
253
264
272 void addObserver(std::shared_ptr<Parameter> observer);
273
281 void removeObserver(std::shared_ptr<Parameter> observer);
282
292 void notifyObservers();
293
306
313 virtual void update() {}
314
321 virtual void freeze() {}
322
328 virtual void unfreeze() {}
329
336 virtual void clear_above() {}
337
349 virtual void clear_below();
350
361 virtual std::unordered_map<ParamId, std::shared_ptr<Parameter>> get_source_parameters() const;
362
368 void set_owner_block(std::weak_ptr<Block> owner);
369
375 std::weak_ptr<Block> get_owner_block() const;
376
396 void overwrite_payload_from(const Parameter& other);
397
417 Parameter& operator=(const Parameter& other);
418
429 friend std::ostream& operator<<(std::ostream& os, const Parameter& p);
430
444 Parameter& operator+=(const Parameter& other);
445
460
464 virtual ~Parameter() = default;
465};
466
467
468
469#endif // PARAMETER_H
470
ParameterType
ParameterMode
Defines the modes in which a parameter can operate.
Definition Parameter.h:45
@ FIXED
The parameter remains fixed at its expected value.
@ SHIFTABLE
The parameter value is shifted by an additive offset.
Definition Block.h:73
Represents a single parameter with value, uncertainties, and dependency links.
Definition Parameter.h:78
scalar_t deviation_syst
Systematic standard deviation.
Definition Parameter.h:83
virtual void unfreeze()
Hook to unfreeze the parameter.
Definition Parameter.h:328
std::optional< double > scale
Optional renormalization scale associated with the parameter.
Definition Parameter.h:88
ParameterMode mode
Current operating mode.
Definition Parameter.h:85
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.
Definition Parameter.h:86
void set_id(ParamId id)
Replaces the identifier of the parameter.
Definition Parameter.cpp:51
void notifyParamObserversOnly()
Notifies only parameter observers.
void addObserver(std::shared_ptr< Parameter > observer)
Adds an observer parameter.
Definition Parameter.cpp:89
scalar_t expected
Expected value of the parameter.
Definition Parameter.h:81
virtual void clear_below()
Recursively clears downstream dependencies below this parameter.
Definition Parameter.cpp:95
Parameter()
Default constructor.
Definition Parameter.h:102
double get_scale()
Returns the parameter scale metadata.
Definition Parameter.cpp:64
virtual ~Parameter()=default
Virtual destructor.
virtual std::unordered_map< ParamId, std::shared_ptr< Parameter > > get_source_parameters() const
Returns the source parameters this parameter depends on.
friend std::ostream & operator<<(std::ostream &os, const Parameter &p)
Stream output operator for a parameter.
void set_expected(scalar_t val)
Sets the expected value and notifies dependents.
Definition Parameter.cpp:41
void set_owner(ParameterType type)
Changes the owner ParameterType part of the identifier.
Definition Parameter.cpp:77
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.
Definition Parameter.h:336
scalar_t deviation_stat
Statistical standard deviation.
Definition Parameter.h:82
void set_bin(std::pair< double, double > bin)
Sets the binning metadata of the parameter.
Definition Parameter.cpp:30
virtual scalar_t get_val() const
Returns the current value of the parameter.
Definition Parameter.cpp:34
std::pair< scalar_t, scalar_t > get_std() const
Returns statistical and systematic uncertainties separately.
Definition Parameter.cpp:60
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.
Definition Parameter.cpp:47
ParamId id
Unique identifier for the parameter.
Definition Parameter.h:80
std::pair< double, double > get_bin()
Returns the parameter bin metadata.
Definition Parameter.cpp:68
std::optional< std::pair< double, double > > binning
Optional energy bin [low, high] associated with the parameter.
Definition Parameter.h:89
virtual void update()
Hook called when an upstream dependency changes.
Definition Parameter.h:313
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.
Definition Parameter.cpp:21
ParamId get_id() const
Returns the identifier of the parameter.
Definition Parameter.cpp:72
Parameter & operator*=(const scalar_t &scale)
Multiplies the parameter by a scalar factor.
scalar_t shift
Additive shift applied when the parameter is SHIFTABLE.
Definition Parameter.h:84
virtual void freeze()
Hook to freeze the parameter.
Definition Parameter.h:321
scalar_t get_combined_std() const
Returns the combined standard deviation.
Definition Parameter.cpp:55
void set_scale(double scale)
Sets the parameter scale metadata.
Definition Parameter.cpp:26
void notifyObservers()
Notifies downstream parameter observers and then the owner block.
void set_shift(scalar_t shift)
Sets the additive shift of the parameter.
Definition Parameter.cpp:81
void set_mode(ParameterMode mode)
Sets the parameter mode.
Definition Parameter.cpp:15
std::weak_ptr< Block > owner_block
Owning Block (if any) that this parameter belongs to.
Definition Parameter.h:87
Composite identifier for a single parameter.
Definition ParamID.h:57