MaCh3  2.8.0
Reference Guide
MulticanonicalMCMCHandler.h
Go to the documentation of this file.
1 #pragma once
2 #include <ostream>
3 #include <string>
4 #include <vector>
5 
7 #include "Manager/Manager.h"
8 
10 #include "TSpline.h"
12 
13 
14 namespace M3 {
15  enum class BiasFunction {
16  kGaussian,
17  kVonMises,
19  };
20 
21  inline M3::BiasFunction ParseBiasFunction(const std::string& biasFunctionName) {
22  if (biasFunctionName == "gaussian") {
24  }
25  if (biasFunctionName == "vonMises") {
27  }
28  if (biasFunctionName == "generalisedGaussian") {
30  }
31  throw MaCh3Exception(__FILE__, __LINE__, "Unknown multicanonical bias function: " + biasFunctionName);
32  }
33 
34  inline std::string BiasFunction_ToString(const M3::BiasFunction& biasFunction) {
35  switch (biasFunction) {
37  return "gaussian";
39  return "vonMises";
41  return "generalisedGaussian";
42  default:
43  throw MaCh3Exception(__FILE__, __LINE__, "Unknown multicanonical bias function");
44  }
45  }
46 
53  constexpr double UmbrellaGaussianNormFactor = 0.906402477055;
54 }
55 
73  public:
78 
79  #ifdef MACH3_DEBUG
81  void setDebugStream(std::ostream* os, bool enabled);
82  #endif
83 
85  void FindOscCovParams(const std::vector<ParameterHandlerBase*>& systematics);
86 
91  void AdjustUmbrellaStepScale(const std::vector<ParameterHandlerBase*>& systematics);
92 
94  void InitializeMulticanonicalHandlerConfig(Manager* fitMan, std::vector<ParameterHandlerBase*>& systematics);
95 
98  void InitializeMulticanonicalParams(std::vector<ParameterHandlerBase*>& systematics);
99 
103  double GetMulticanonicalWeight() const;
104 
106  double GetMulticanonicalWeightSpline(double param_value, double delm23) const;
107 
109  double GetMulticanonicalWeightGaussian(double param_value) const;
110 
113  double GetMulticanonicalWeightTripleGaussian(double param_value) const;
114 
119  double GetMulticanonicalWeightVonMises(double param_value) const;
120 
127  double GetMulticanonicalWeightGenGaussian(double param_value) const;
128 
131  double circularDistance(double x, double mean) const;
132 
134  double generalisedGaussian2(double x, double mean, double width) const;
135 
144 
149 
152 
155 
158 
159  protected:
162 
164  TSpline3* dcp_spline_IO;
166  TSpline3* dcp_spline_NO;
167 
169  double umbrellaMean;
176 
181 
182 #ifdef MACH3_DEBUG
183  std::ostream* debugStream = nullptr;
184  bool debugEnabled = false;
185 #endif
186 };
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
Definition: Core.h:126
#define _MaCh3_Safe_Include_End_
Custom exception class used throughout MaCh3.
The manager class is responsible for managing configurations and settings.
Definition: Manager.h:17
Helper class for configuring and evaluating multicanonical umbrella weights.
double vonMises_I0_kappa
Cached I0(kappa) value for the von Mises form.
void InitializeMulticanonicalParams(std::vector< ParameterHandlerBase * > &systematics)
Initialise the starting values used by the multicanonical parameter handling.
void InitializeMulticanonicalHandlerConfig(Manager *fitMan, std::vector< ParameterHandlerBase * > &systematics)
Read multicanonical configuration from the yaml via manager and initialise handler state.
double GetMulticanonicalWeightVonMises(double param_value) const
Compute a von Mises multicanonical penalty.
double GetMulticanonicalWeightGaussian(double param_value) const
Compute a Gaussian multicanonical penalty.
double umbrellaWidth
Umbrella width used for the current configuration.
TSpline3 * dcp_spline_IO
Spline for the IO branch, if spline mode is enabled.
void AdjustUmbrellaStepScale(const std::vector< ParameterHandlerBase * > &systematics)
Adjust the parameter-of-interest's step scale according to the width of the umbrella bias function.
int multicanonicalVar_dm23
Parameter index used for the multicanonical delm2_23 weight.
double GetMulticanonicalWeightSpline(double param_value, double delm23) const
Compute the multicanonical penalty using a spline.
M3::BiasFunction umbrellaBiasFunction
Selected bias function for multicanonical weights.
TSpline3 * dcp_spline_NO
Spline for the NO branch, if spline mode is enabled.
std::string multicanonicalVarName
Parameter name used for the multicanonical weight, most often delta_cp.
double GetMulticanonicalWeight() const
Compute the multicanonical penalty for the configured bias mode.
bool multicanonicalSpline
Toggle for spline-based multicanonical weights.
void FindOscCovParams(const std::vector< ParameterHandlerBase * > &systematics)
Locate the systematic object which contains the parameters used by the handler. Stores the parameter ...
double vonMises_kappa
Von Mises kappa parameter. Analogue of sigma for a gaussian.
double circularDistance(double x, double mean) const
Compute the circular distance between two angles.
std::string umbrellaBiasFunctionName
Configured bias function name for logging.
double GetMulticanonicalWeightTripleGaussian(double param_value) const
Compute a triple-Gaussian multicanonical penalty.
const M3::float_t * multicanonicalVarValue
Pointer to value of parameter vale used for multicanonical weight, most often delta_cp.
double generalisedGaussian2(double x, double mean, double width) const
Wraps the generalised gaussian function for a given x, mean, and width. Required to handle the wrappi...
double umbrellaMean
Umbrella centre used for the current configuration.
double GetMulticanonicalWeightGenGaussian(double param_value) const
Compute a generalised-Gaussian multicanonical penalty.
const M3::float_t * multicanonicalVar_dm23_value
Pointer to value of delm2_23 weight used for multicanonical weight.
virtual ~MulticanonicalMCMCHandler()
Destructor.
double umbrellaStepScaleFactor
Additional scale factor applied when rescaling the step size. This is for fine tuning.
int oscCovVar
Index of the oscillation-covariance systematic in the current fit.
int multicanonicalVar
Parameter index used for the multicanonical weight, most often delta_cp.
bool umbrellaAdjustStepScale
Toggle for rescaling the step size based on the umbrella width.
double multicanonicalBeta
Global scale factor applied to the multicanonical penalty. 1 is full strength, 0 is no penalty.
Main namespace for MaCh3 software.
M3::BiasFunction ParseBiasFunction(const std::string &biasFunctionName)
double float_t
Definition: Core.h:37
std::string BiasFunction_ToString(const M3::BiasFunction &biasFunction)
constexpr double UmbrellaGaussianNormFactor
@ kGaussian
Assumes gaussian prior.