46 fValid(false), fNormalized(false), fNFree(0), fNdf(0), fNCalls(0),
47 fStatus(-1), fCovStatus(0), fVal(0), fEdm(-1), fChi2(-1)
64 fParams(std::vector<
double>( fconfig.NPar() ) ),
65 fErrors(std::vector<
double>( fconfig.NPar() ) ),
66 fParNames(std::vector<std::string> ( fconfig.NPar() ) )
75 if ( (
fMinimType.find(
"Fumili") == std::string::npos) &&
76 (
fMinimType.find(
"GSLMultiFit") == std::string::npos)
82 unsigned int npar = fconfig.
NPar();
83 for (
unsigned int i = 0; i < npar; ++i ) {
97 std::cout <<
"create fit result from config - nfree " <<
fNFree << std::endl;
113 fVal = min->MinValue();
124 const unsigned int npar = min->NDim();
125 if (npar == 0)
return;
128 fParams = std::vector<double>(min->X(), min->X() + npar);
132 for (
unsigned int i = 0; i < npar; ++i ) {
137 if (sizeOfData > min->NFree() )
fNdf = sizeOfData - min->NFree();
151 for (
unsigned int i = 0; i < npar; ++i ) {
158 unsigned int nfree = 0;
160 for (
unsigned int ipar = 0; ipar < npar; ++ipar) {
173 MATH_ERROR_MSG(
"FitResult",
"FitConfiguration and Minimizer result are not consistent");
174 std::cout <<
"Number of free parameters from FitConfig = " << nfree << std::endl;
175 std::cout <<
"Number of free parameters from Minimizer = " <<
fNFree << std::endl;
195 if (min->Errors() != 0) {
197 fErrors = std::vector<double>(min->Errors(), min->Errors() + npar ) ;
200 unsigned int r = npar * ( npar + 1 )/2;
202 for (
unsigned int i = 0; i < npar; ++i)
203 for (
unsigned int j = 0; j <= i; ++j)
210 for (
unsigned int i = 0; i < npar; ++i) {
211 double globcc = min->GlobalCC(i);
212 if (globcc < 0)
break;
229 const unsigned int npar =
fParams.size();
230 if (min->NDim() != npar ) {
234 if (min->X() == 0 ) {
239 if (
fNFree != min->NFree() ) {
246 fVal = min->MinValue();
252 if ( min->NCalls() > 0)
fNCalls = min->NCalls();
256 std::copy(min->X(), min->X() + npar,
fParams.begin());
262 if (min->Errors() != 0) {
266 std::copy(min->Errors(), min->Errors() + npar,
fErrors.begin() ) ;
271 unsigned int r = npar * ( npar + 1 )/2;
274 for (
unsigned int i = 0; i < npar; ++i) {
275 for (
unsigned int j = 0; j <= i; ++j)
282 for (
unsigned int i = 0; i < npar; ++i) {
283 double globcc = min->GlobalCC(i);
300 for (
unsigned int i = 0; i <
fErrors.size() ; ++i)
302 for (
unsigned int i = 0; i <
fCovMatrix.size() ; ++i)
316 std::map<unsigned int, std::pair<double,double> >::const_iterator itr =
fMinosErrors.find(i);
324 std::map<unsigned int, std::pair<double,double> >::const_iterator itr =
fMinosErrors.find(i);
331 std::map<unsigned int, std::pair<double,double> >::const_iterator itr =
fMinosErrors.find(i);
343 unsigned int npar =
fParams.size();
344 for (
unsigned int i = 0; i < npar; ++i)
359 std::map<unsigned int, unsigned int>::const_iterator itr =
fBoundParams.find(ipar);
361 lower = -std::numeric_limits<Double_t>::infinity();
362 upper = std::numeric_limits<Double_t>::infinity();
381 unsigned int npar =
fParams.size();
383 os <<
"<Empty FitResult>\n";
386 os <<
"\n****************************************\n";
389 os <<
" Invalid FitResult";
390 os <<
" (status = " <<
fStatus <<
" )";
393 os <<
" FitResult before fitting";
395 os <<
"\n****************************************\n";
399 os <<
"Minimizer is " <<
fMinimType << std::endl;
400 const unsigned int nw = 25;
401 const unsigned int nn = 12;
402 const std::ios_base::fmtflags prFmt = os.setf(std::ios::left,std::ios::adjustfield);
405 os << std::left << std::setw(nw) <<
"MinFCN" <<
" = " << std::right << std::setw(nn) <<
fVal << std::endl;
407 os << std::left << std::setw(nw) <<
"Chi2" <<
" = " << std::right << std::setw(nn) <<
fChi2 << std::endl;
408 os << std::left << std::setw(nw) <<
"NDf" <<
" = " << std::right << std::setw(nn) <<
fNdf << std::endl;
409 if (
fMinimType.find(
"Linear") == std::string::npos) {
410 if (
fEdm >=0) os << std::left << std::setw(nw) <<
"Edm" <<
" = " << std::right << std::setw(nn) <<
fEdm << std::endl;
411 os << std::left << std::setw(nw) <<
"NCalls" <<
" = " << std::right << std::setw(nn) <<
fNCalls << std::endl;
413 for (
unsigned int i = 0; i < npar; ++i) {
415 os <<
" = " << std::right << std::setw(nn) <<
fParams[i];
417 os << std::setw(9) <<
" " << std::setw(nn) <<
" " <<
" \t (fixed)";
420 os <<
" +/- " << std::left << std::setw(nn) <<
fErrors[i] << std::right;
422 os <<
" " << std::left << std::setw(nn) <<
LowerError(i) <<
" +" << std::setw(nn) <<
UpperError(i)
425 os <<
" \t (limited)";
431 if (prFmt != os.flags() ) os.setf(prFmt, std::ios::adjustfield);
441 os <<
"\nCovariance Matrix:\n\n";
442 unsigned int npar =
fParams.size();
444 const int kWidth = 8;
446 const int matw = kWidth+4;
449 int prevPrec = os.precision(kPrec);
450 const std::ios_base::fmtflags prevFmt = os.flags();
452 os << std::setw(parw) <<
" " <<
"\t";
453 for (
unsigned int i = 0; i < npar; ++i) {
459 for (
unsigned int i = 0; i < npar; ++i) {
462 for (
unsigned int j = 0; j < npar; ++j) {
464 os.precision(kPrec); os.width(kWidth); os << std::right << std::setw(matw) <<
CovMatrix(i,j);
471 os <<
"\nCorrelation Matrix:\n\n";
472 os << std::setw(parw) <<
" " <<
"\t";
473 for (
unsigned int i = 0; i < npar; ++i) {
479 for (
unsigned int i = 0; i < npar; ++i) {
481 os << std::left << std::setw(parw) << std::left <<
GetParameterName(i) <<
"\t";
482 for (
unsigned int j = 0; j < npar; ++j) {
484 os.precision(kPrec); os.width(kWidth); os << std::right << std::setw(matw) <<
Correlation(i,j);
491 os.setf(prevFmt, std::ios::adjustfield);
492 os.precision(prevPrec);
504 MATH_ERROR_MSG(
"FitResult::GetConfidenceIntervals",
"Cannot compute Confidence Intervals without fit model function");
510 double corrFactor = 1;
511 if (
fChi2 <= 0 ||
fNdf == 0) norm =
false;
520 unsigned int ndim =
fFitFunc->NDim();
521 unsigned int npar =
fFitFunc->NPar();
523 std::vector<double> xpoint(ndim);
524 std::vector<double> grad(npar);
525 std::vector<double> vsum(npar);
528 for (
unsigned int ipoint = 0; ipoint <
n; ++ipoint) {
530 for (
unsigned int kdim = 0; kdim < ndim; ++kdim) {
531 unsigned int i = ipoint * stride1 + kdim * stride2;
538 for (
unsigned int ipar = 0; ipar < npar; ++ipar) {
541 d.SetFunction(fadapter);
545 d.SetStepSize( std::max(
fErrors[ipar]*1.E-5, 1.E-15) );
547 d.SetStepSize( std::min(std::max(
fParams[ipar]*1.E-5, 1.E-15), 0.0001 ) );
556 vsum.assign(npar,0.0);
557 for (
unsigned int ipar = 0; ipar < npar; ++ipar) {
558 for (
unsigned int jpar = 0; jpar < npar; ++jpar) {
559 vsum[ipar] +=
CovMatrix(ipar,jpar) * grad[jpar];
564 for (
unsigned int ipar = 0; ipar < npar; ++ipar) {
565 r2 += grad[ipar] * vsum[ipar];
567 double r = std::sqrt(r2);
568 ci[ipoint] =
r * corrFactor;
576 unsigned int ndim =
data.NDim();
577 unsigned int np =
data.NPoints();
578 std::vector<double> xdata( ndim *
np );
579 for (
unsigned int i = 0; i <
np ; ++i) {
580 const double *
x =
data.Coords(i);
581 std::vector<double>::iterator itr = xdata.begin()+ ndim * i;
582 std::copy(
x,
x+ndim,itr);
592 std::vector<double>
result;
598 MATH_ERROR_MSG(
"FitResult::GetConfidenceIntervals",
"Cannot compute Confidence Intervals without the fit bin data");
630 if (!pntsx || !pntsy || !npoints)
634 MATH_ERROR_MSG(
"FitResult::Scan",
"Minimizer is not available - cannot Scan");
649bool FitResult::Contour(
unsigned int ipar,
unsigned int jpar,
unsigned int &npoints,
double *pntsx,
double *pntsy,
double confLevel)
651 if (!pntsx || !pntsy || !npoints)
655 MATH_ERROR_MSG(
"FitResult::Contour",
"Minimizer is not available - cannot produce Contour");
667 bool ret =
fMinimizer->Contour(ipar, jpar, npoints, pntsx, pntsy);
#define MATH_ERROR_MSG(loc, str)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
const std::string & MinimizerAlgoType() const
return type of minimizer algorithms
unsigned int NPar() const
number of parameters settings
std::string MinimizerName() const
return Minimizer full name (type / algorithm)
const std::string & MinimizerType() const
return type of minimizer package
const ParameterSettings & ParSettings(unsigned int i) const
get the parameter settings for the i-th parameter (const method)
std::vector< double > fGlobalCC
global Correlation coefficient
void FillResult(const std::shared_ptr< ROOT::Math::Minimizer > &min, const FitConfig &fconfig, const std::shared_ptr< IModelFunction > &f, bool isValid, unsigned int sizeOfData=0, bool binFit=true, const ROOT::Math::IMultiGenFunction *chi2func=nullptr, unsigned int ncalls=0)
Fill the fit result from a Minimizer instance after fitting Run also Minos if requested from the conf...
unsigned int fNFree
number of fit free parameters (total parameters are in size of parameter vector)
bool Update(const std::shared_ptr< ROOT::Math::Minimizer > &min, const ROOT::Fit::FitConfig &fconfig, bool isValid, unsigned int ncalls=0)
Update the fit result with a new minimization status To be run only if same fit is performed with sam...
std::map< unsigned int, unsigned int > fBoundParams
list of limited parameters
const BinData * FittedBinData() const
return BinData used in the fit (return a nullptr in case a different fit is done or the data are not ...
double UpperError(unsigned int i) const
upper Minos error. If Minos has not run for parameter i return the parabolic error
double fVal
minimum function value
double fEdm
expected distance from minimum
std::vector< double > fErrors
errors
std::shared_ptr< ROOT::Math::Minimizer > fMinimizer
! minimizer object used for fitting
bool fValid
flag for indicating valid fit
bool IsParameterFixed(unsigned int ipar) const
query if a parameter is fixed
unsigned int fNdf
number of degree of freedom
double Error(unsigned int i) const
parameter error by index
double CovMatrix(unsigned int i, unsigned int j) const
retrieve covariance matrix element
void GetConfidenceIntervals(unsigned int n, unsigned int stride1, unsigned int stride2, const double *x, double *ci, double cl=0.95, bool norm=false) const
get confidence intervals for an array of n points x.
int fCovStatus
covariance matrix status code
bool Scan(unsigned int ipar, unsigned int &npoints, double *pntsx, double *pntsy, double xmin=0, double xmax=0)
scan likelihood value of parameter and fill the given graph.
FitResult()
Default constructor for an empty (non valid) fit result.
std::shared_ptr< FitData > fFitData
! data set used in the fit
std::string GetParameterName(unsigned int ipar) const
get name of parameter (deprecated)
bool ParameterBounds(unsigned int ipar, double &lower, double &upper) const
retrieve parameter bounds - return false if parameter is not bound
std::vector< double > fParams
parameter values. Size is total number of parameters
std::vector< double > fCovMatrix
covariance matrix (size is npar*(npar+1)/2) where npar is total parameters
void SetMinosError(unsigned int i, double elow, double eup)
set the Minos errors for parameter i (called by the Fitter class when running Minos)
void Print(std::ostream &os, bool covmat=false) const
print the result and optionally covariance matrix and correlations
double LowerError(unsigned int i) const
lower Minos error. If Minos has not run for parameter i return the parabolic error
void PrintCovMatrix(std::ostream &os) const
print error matrix and correlations
unsigned int fNCalls
number of function calls
bool Contour(unsigned int ipar, unsigned int jpar, unsigned int &npoints, double *pntsx, double *pntsy, double confLevel=0.683)
create contour of two parameters around the minimum pass as option confidence level: default is a val...
bool HasMinosError(unsigned int i) const
query if parameter i has the Minos error
std::vector< std::pair< double, double > > fParamBounds
parameter bounds
int fStatus
minimizer status code
double fChi2
fit chi2 value (different than fval in case of chi2 fits)
std::shared_ptr< IModelFunction > fFitFunc
! model function resulting from the fit.
std::map< unsigned int, bool > fFixedParams
list of fixed parameters
std::string fMinimType
string indicating type of minimizer
double Correlation(unsigned int i, unsigned int j) const
retrieve correlation elements
int Index(const std::string &name) const
get index for parameter name (return -1 if not found)
double Prob() const
p value of the fit (chi2 probability)
std::string ParName(unsigned int i) const
name of the parameter
void NormalizeErrors()
normalize errors using chi2/ndf for chi2 fits
bool fNormalized
flag for indicating is errors are normalized
bool IsParameterBound(unsigned int ipar) const
query if a parameter is bound
std::vector< std::string > fParNames
parameter names (only with FCN only fits, when fFitFunc=0)
std::map< unsigned int, std::pair< double, double > > fMinosErrors
map contains the two Minos errors
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
bool IsFixed() const
check if is fixed
bool HasUpperLimit() const
check if parameter has upper limit
double LowerLimit() const
return lower limit value
const std::string & Name() const
return name
bool HasLowerLimit() const
check if parameter has lower limit
double Value() const
copy constructor and assignment operators (leave them to the compiler)
double StepSize() const
return step size
double UpperLimit() const
return upper limit value
bool IsBound() const
check if is bound
Documentation for the abstract class IBaseFunctionMultiDim.
OneDimParamFunctionAdapter class to wrap a multi-dim parametric function in one dimensional one.
User class for calculating the derivatives of a function.
double chisquared_cdf_c(double x, double r, double x0=0)
Complement of the cumulative distribution function of the distribution with degrees of freedom (upp...
double normal_quantile(double z, double sigma)
Inverse ( ) of the cumulative distribution function of the lower tail of the normal (Gaussian) distri...
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
const int gInitialResultStatus
std::string ToString(const T &val)
Utility function for conversion to strings.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Double_t ChisquareQuantile(Double_t p, Double_t ndf)
Evaluate the quantiles of the chi-squared probability distribution function.
Double_t StudentQuantile(Double_t p, Double_t ndf, Bool_t lower_tail=kTRUE)
Computes quantiles of the Student's t-distribution 1st argument is the probability,...