28 const double value = 0,
const double step = 1,
29 const double low = 0,
const double high = 0,
30 const bool fixed =
false) :
77 Base(
const unsigned int nPar = 0,
const double up = 1)
80 Base(
const std::vector<ParameterDef>& pars,
const double up = 1)
102 GetParameterDefValues()
105 std::vector<double>
r;
108 r.push_back(
p.fValue);
116 if (vals.size() !=
n)
117 throw std::runtime_error(
"SetParameterDefValues: requires the same length");
118 for (
unsigned int i = 0; i <
n; ++i)
123 GetParameterDefFixed()
129 r.push_back(
p.fFixed);
137 if (fixed.size() !=
n)
138 throw std::runtime_error(
"SetParameterDefFixed: requires the same length");
139 for (
unsigned int i = 0; i <
n; ++i)
151 throw std::runtime_error(
"SetCurrentParameters: requires the same number");
162 std::vector<std::string>
167 std::vector<std::string>
r;
169 for (
int i = 0; i <
n; ++i)
175 GetIndex(
const std::string& parameterName)
182 throw std::out_of_range(
"GetIndex: parameter " + parameterName +
" not found!");
204 throw std::runtime_error(
"only one instance at the time allowed");
218 for (
unsigned int i = 0, n =
ps.size(); i < n; ++i) {
219 const auto&
p =
ps[i];
220 if (
p.fStep <= 0 && !
p.fFixed) {
221 const std::string err =
"In Minou::Minimizer::DefineParameters(): "
222 "Parameter " +
p.fName +
": "
223 "step should be > 0! (or fix the parameter)";
224 std::cerr << err << std::endl;
225 throw std::runtime_error(err);
227 fMinuit.DefineParameter(i,
p.fName.c_str(),
p.fValue,
p.fStep,
p.fLow,
p.fHigh);
275 GetMinosError(
const int parIndex)
286 std::vector<MinosParameterResult>
290 const int n =
fFunction->GetNParameters();
291 std::vector<MinosParameterResult>
r;
293 for (
int i = 0; i < n; ++i) {
294 const auto mRes = GetMinosError(i);
300 std::pair<double, double>
301 GetParameterAndError(
const int i)
304 std::pair<double, double>
ve;
305 fMinuit.GetParameter(i, ve.first, ve.second);
309 std::vector<std::pair<double, double>>
310 GetParametersAndErrors()
313 const int n =
fFunction->GetNParameters();
314 std::vector<std::pair<double, double>>
r;
316 for (
int i = 0; i < n; ++i) {
317 const auto p = GetParameterAndError(i);
324 {
return GetParameterAndError(i).first; }
330 const int n =
fFunction->GetNParameters();
331 std::vector<double>
r;
333 for (
int i = 0; i < n; ++i)
349 GetCovarianceMatrix()
352 const int n =
fMinuit.GetNumFreePars();
354 for (
int i = 0; i < n; i++)
355 for (
int j = 0; j < n; j++)
365 for (
int i = 0; i <
nTotal; ++i)
367 inverseIndex[i] = ++iFree;
375 const bool iIsFree =
ps[i].IsFree();
376 const auto& mii = matrix[inverseIndex[i]];
378 for (
int j = i; j <
nTotal; ++j) {
379 const double covariance = (iIsFree &&
ps[j].IsFree()) ? mii[inverseIndex[j]] : 0;
380 const auto el = fmi[j] = covariance;
411 Function(
int& ,
double* ,
double& f,
double* par,
int )
414 auto& fpars = func.GetCurrentParameters();
415 fpars.assign(par, par + func.GetNParameters());
426 template<
class Functor> Minimizer<Functor>* Minimizer<Functor>::fgMinimizer =
nullptr;
void SetVerbose(const bool verbose)
const std::vector< double > & GetCurrentParameters() const
void SetErrorDefinition(const double up)
double GetParameter(const int i) const
fMinuit GetParameter(parIndex, eRes.fValue, eRes.fParabolicError)
double GetErrorDefinition() const
int Minos(const int n=500)
void SetParameterDefFixed(const std::vector< int > &fixed)
static Minimizer * fgMinimizer
std::vector< double > & GetCurrentParameters()
int Migrad(const int n=500)
std::vector< ParameterDef > fParameterDefs
Base(const unsigned int nPar=0, const double up=1)
static void Function(int &, double *, double &f, double *par, int)
ParameterDef(const std::string name, const double value=0, const double step=1, const double low=0, const double high=0, const bool fixed=false)
std::vector< double > fCurrentParameters
std::vector< ParameterDef > & GetParameterDefs()
Evaluate functions given in a string. The real work is done by the ExpressionParser class...
void WriteBack(Base &base) const
int Minimize(const int n=500)
std::vector< std::pair< double, double > > r
void SetParameterDefValues(const std::vector< double > &vals)
double fGlobalCorrelation
std::vector< std::string > r
unsigned int GetNParameters() const
void SetCurrentParameters(const std::vector< double > &p)
Base(const std::vector< ParameterDef > &pars, const double up=1)
void SetParameterDefs(const std::vector< ParameterDef > &defs)
const std::vector< ParameterDef > & GetParameterDefs() const
std::string GetName(const int i) const
double EvaluateFunction(const std::vector< double > &p) const
double GetMinimum() const
void SetErrorDefinition(const double up)
std::vector< MinosParameterResult > r