Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Minimizer.cxx
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023, CERN
3 */
4
5#include <Math/Minimizer.h>
6
7#include <Math/Error.h>
8#include <Math/Util.h>
9
10namespace ROOT {
11namespace Math {
12
13/** set initial second derivatives
14 */
15bool Minimizer::SetCovarianceDiag(std::span<const double> g2, unsigned int n)
16{
19 return false;
20}
21
22/**
23 * Set initial values for covariance/error matrix.
24 * The covariance matrix must be provided in compressed form (row-major ordered upper traingular part)
25 */
26bool Minimizer::SetCovariance(std::span<const double> cov, unsigned int nrow)
27{
30 return false;
31}
32
33/// Set a new upper/lower limited variable (override if minimizer supports them) otherwise as default set an unlimited
34/// variable (i.e. the lower and upper bounds will be ignored).
35/// @see Minimizer::SetVariable
36/// @param ivar the index of this variable in the array
37/// @param name the variable name
38/// @param val the value
39/// @param step the step size
40/// @param lower the lower bound
41/// @param upper this upper bound
42bool Minimizer::SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower,
43 double upper)
44{
45 MATH_WARN_MSG("Minimizer::SetLimitedVariable", "Setting of limited variable not implemented - set as unlimited");
48 return SetVariable(ivar, name, val, step);
49}
50
51/// Set a new fixed variable (override if minimizer supports them).
52bool Minimizer::SetFixedVariable(unsigned int ivar, const std::string &name, double val)
53{
54 MATH_ERROR_MSG("Minimizer::SetFixedVariable", "Setting of fixed variable not implemented");
57 MATH_UNUSED(val);
58 return false;
59}
60/// Set the value of an already existing variable.
61bool Minimizer::SetVariableValue(unsigned int ivar, double value)
62{
63 MATH_ERROR_MSG("Minimizer::SetVariableValue", "Set of a variable value not implemented");
66 return false;
67}
68
69/// Set the step size of an already existing variable.
70bool Minimizer::SetVariableStepSize(unsigned int ivar, double value)
71{
72 MATH_ERROR_MSG("Minimizer::SetVariableStepSize", "Setting an existing variable step size not implemented");
75 return false;
76}
77/// Set the lower-limit of an already existing variable.
79{
80 MATH_ERROR_MSG("Minimizer::SetVariableLowerLimit", "Setting an existing variable limit not implemented");
83 return false;
84}
85/// Set the upper-limit of an already existing variable.
87{
88 MATH_ERROR_MSG("Minimizer::SetVariableUpperLimit", "Setting an existing variable limit not implemented");
91 return false;
92}
93
94/// Fix an existing variable.
95bool Minimizer::FixVariable(unsigned int ivar)
96{
97 MATH_ERROR_MSG("Minimizer::FixVariable", "Fixing an existing variable not implemented");
99 return false;
100}
101/// Release an existing variable.
103{
104 MATH_ERROR_MSG("Minimizer::ReleaseVariable", "Releasing an existing variable not implemented");
106 return false;
107}
108/// Query if an existing variable is fixed (i.e. considered constant in the minimization).
109/// @note By default all variables are not fixed.
110bool Minimizer::IsFixedVariable(unsigned int ivar) const
111{
112 MATH_ERROR_MSG("Minimizer::IsFixedVariable", "Querying an existing variable not implemented");
114 return false;
115}
116/// Get variable settings in a variable object (like ROOT::Fit::ParamsSettings).
118{
119 MATH_ERROR_MSG("Minimizer::GetVariableSettings", "Querying an existing variable not implemented");
121 MATH_UNUSED(pars);
122 return false;
123}
124/**
125 * @return covariance matrices element for variables ivar,jvar
126 * if the variable is fixed the return value is zero.
127 * The ordering of the variables is the same as in the parameter and errors vectors.
128 */
129double Minimizer::CovMatrix(unsigned int ivar, unsigned int jvar) const
130{
133 return 0;
134}
135
136/**
137 * Fill the passed array with the covariance matrix elements
138 * if the variable is fixed or const the value is zero.
139 * The array will be filled as cov[i *ndim + j]
140 * The ordering of the variables is the same as in errors and parameter value.
141 * This is different from the direct interface of Minuit2 or TMinuit where the
142 * values were obtained only to variable parameters
143 */
145{
147 return false;
148}
149
150/**
151 * Fill the passed array with the Hessian matrix elements
152 * The Hessian matrix is the matrix of the second derivatives
153 * and is the inverse of the covariance matrix
154 * If the variable is fixed or const the values for that variables are zero.
155 * The array will be filled as h[i *ndim + j]
156 */
158{
160 return false;
161}
162
163/**
164 * @return global correlation coefficient for variable i.
165 * This is a number between zero and one which gives
166 * the correlation between the i-th parameter and that linear combination of all
167 * other parameters which is most strongly correlated with i.
168 * Minimizer must overload method if implemented
169 */
170double Minimizer::GlobalCC(unsigned int ivar) const
171{
173 return -1;
174}
175
176/**
177 * Minos error for variable i, return false if Minos failed or not supported
178 * and the lower and upper errors are returned in errLow and errUp
179 * An extra flag specifies if only the lower (option=-1) or the upper (option=+1) error calculation is run
180 */
181bool Minimizer::GetMinosError(unsigned int ivar, double &errLow, double &errUp, int option)
182{
183 MATH_ERROR_MSG("Minimizer::GetMinosError", "Minos Error not implemented");
188 return false;
189}
190
191/**
192 * Perform a full calculation of the Hessian matrix for error calculation.
193 */
195{
196 MATH_ERROR_MSG("Minimizer::Hesse", "Hesse not implemented");
197 return false;
198}
199
200/**
201 * Scan function minimum for variable i. Variable and function must be set before using Scan.
202 * @return false if an error or if minimizer does not support this functionality
203 */
204bool Minimizer::Scan(unsigned int ivar, unsigned int &nstep, double *x, double *y, double xmin, double xmax)
205{
206 MATH_ERROR_MSG("Minimizer::Scan", "Scan not implemented");
209 MATH_UNUSED(x);
210 MATH_UNUSED(y);
213 return false;
214}
215
216/**
217 * Find the contour points (xi, xj) of the function for parameter ivar and jvar around the minimum.
218 * The contour will be find for value of the function = Min + ErrorUp();
219 */
220bool Minimizer::Contour(unsigned int ivar, unsigned int jvar, unsigned int &npoints, double *xi, double *xj)
221{
222 MATH_ERROR_MSG("Minimizer::Contour", "Contour not implemented");
226 MATH_UNUSED(xi);
228 return false;
229}
230
231/// Get name of variables (override if minimizer support storing of variable names).
232/// @return an empty string if variable is not found
233std::string Minimizer::VariableName(unsigned int ivar) const
234{
236 return std::string(); // return empty string
237}
238
239/// Get index of variable given a variable given a name.
240/// @return -1 if variable is not found
241int Minimizer::VariableIndex(const std::string &name) const
242{
243 MATH_ERROR_MSG("Minimizer::VariableIndex", "Getting variable index from name not implemented");
245 return -1;
246}
247
248} // namespace Math
249} // namespace ROOT
#define MATH_ERROR_MSG(loc, str)
Definition Error.h:83
#define MATH_WARN_MSG(loc, str)
Definition Error.h:80
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:110
float xmin
float xmax
#define MATH_UNUSED(var)
Definition Util.h:35
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
virtual bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double lower, double upper)
Set a new upper/lower limited variable (override if minimizer supports them) otherwise as default set...
Definition Minimizer.cxx:42
virtual int VariableIndex(const std::string &name) const
Get index of variable given a variable given a name.
virtual bool GetCovMatrix(double *covMat) const
Fill the passed array with the covariance matrix elements if the variable is fixed or const the value...
virtual bool SetVariableStepSize(unsigned int ivar, double value)
Set the step size of an already existing variable.
Definition Minimizer.cxx:70
virtual bool SetCovarianceDiag(std::span< const double > d2, unsigned int n)
Set initial second derivatives.
Definition Minimizer.cxx:15
virtual bool GetVariableSettings(unsigned int ivar, ROOT::Fit::ParameterSettings &pars) const
Get variable settings in a variable object (like ROOT::Fit::ParamsSettings).
virtual double GlobalCC(unsigned int ivar) const
virtual bool SetVariableValue(unsigned int ivar, double value)
Set the value of an already existing variable.
Definition Minimizer.cxx:61
virtual bool Scan(unsigned int ivar, unsigned int &nstep, double *x, double *y, double xmin=0, double xmax=0)
Scan function minimum for variable i.
virtual bool SetVariableUpperLimit(unsigned int ivar, double upper)
Set the upper-limit of an already existing variable.
Definition Minimizer.cxx:86
virtual bool SetCovariance(std::span< const double > cov, unsigned int nrow)
Set initial covariance matrix.
Definition Minimizer.cxx:26
virtual std::string VariableName(unsigned int ivar) const
Get name of variables (override if minimizer support storing of variable names).
virtual double CovMatrix(unsigned int ivar, unsigned int jvar) const
virtual bool GetHessianMatrix(double *hMat) const
Fill the passed array with the Hessian matrix elements The Hessian matrix is the matrix of the second...
virtual bool SetVariable(unsigned int ivar, const std::string &name, double val, double step)=0
Set a new free variable.
virtual bool FixVariable(unsigned int ivar)
Fix an existing variable.
Definition Minimizer.cxx:95
virtual bool SetFixedVariable(unsigned int ivar, const std::string &name, double val)
Set a new fixed variable (override if minimizer supports them).
Definition Minimizer.cxx:52
virtual bool GetMinosError(unsigned int ivar, double &errLow, double &errUp, int option=0)
Minos error for variable i, return false if Minos failed or not supported and the lower and upper err...
virtual bool SetVariableLowerLimit(unsigned int ivar, double lower)
Set the lower-limit of an already existing variable.
Definition Minimizer.cxx:78
virtual bool IsFixedVariable(unsigned int ivar) const
Query if an existing variable is fixed (i.e.
virtual bool ReleaseVariable(unsigned int ivar)
Release an existing variable.
virtual bool Hesse()
Perform a full calculation of the Hessian matrix for error calculation.
virtual bool Contour(unsigned int ivar, unsigned int jvar, unsigned int &npoints, double *xi, double *xj)
Find the contour points (xi, xj) of the function for parameter ivar and jvar around the minimum.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...