46 fValid(
false), fNormalized(
false), fNFree(0), fNdf(0), fNCalls(0),
47 fStatus(-1), fCovStatus(0), fVal(0), fEdm(-1), fChi2(-1)
66 fParNames(std::vector<std::string> (
fconfig.NPar() ) )
75 if ( (
fMinimType.find(
"Fumili") == std::string::npos) )
85 for (
unsigned int i = 0; i <
npar; ++i ) {
96 std::cout <<
"create fit result from config - nfree " <<
fNFree << std::endl;
112 fVal = min->MinValue();
123 const unsigned int npar = min->NDim();
124 if (
npar == 0)
return;
127 fParams = std::vector<double>(min->X(), min->X() +
npar);
131 for (
unsigned int i = 0; i <
npar; ++i ) {
150 for (
unsigned int i = 0; i <
npar; ++i ) {
157 unsigned int nfree = 0;
161 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
172 MATH_ERROR_MSG(
"FitResult",
"FitConfiguration and Minimizer result are not consistent");
173 std::cout <<
"Number of free parameters from FitConfig = " <<
nfree << std::endl;
174 std::cout <<
"Number of free parameters from Minimizer = " <<
fNFree << std::endl;
198 if (min->Errors() !=
nullptr) {
200 fErrors = std::vector<double>(min->Errors(), min->Errors() +
npar ) ;
205 for (
unsigned int i = 0; i <
npar; ++i)
206 for (
unsigned int j = 0;
j <= i; ++
j)
227 if (min->NDim() !=
npar ) {
231 if (min->X() ==
nullptr ) {
235 if (
fNFree != min->NFree() ) {
242 fVal = min->MinValue();
248 if ( min->NCalls() > 0)
fNCalls = min->NCalls();
252 std::copy(min->X(), min->X() +
npar,
fParams.begin());
258 if (min->Errors() !=
nullptr) {
262 std::copy(min->Errors(), min->Errors() +
npar,
fErrors.begin() ) ;
270 for (
unsigned int i = 0; i <
npar; ++i) {
271 for (
unsigned int j = 0;
j <= i; ++
j)
288 for (
unsigned int i = 0; i <
fErrors.size() ; ++i)
290 for (
unsigned int i = 0; i <
fCovMatrix.size() ; ++i)
312 std::map<unsigned int, std::pair<double,double> >::const_iterator
itr =
fMinosErrors.find(i);
320 std::map<unsigned int, std::pair<double,double> >::const_iterator
itr =
fMinosErrors.find(i);
327 std::map<unsigned int, std::pair<double,double> >::const_iterator
itr =
fMinosErrors.find(i);
340 for (
unsigned int i = 0; i <
npar; ++i)
358 constexpr double inf = std::numeric_limits<double>::infinity();
378 os <<
"<Empty FitResult>\n";
381 os <<
"****************************************\n";
384 os <<
" Invalid FitResult";
385 os <<
" (status = " <<
fStatus <<
" )";
388 os <<
" FitResult before fitting";
390 os <<
"\n****************************************\n";
394 os <<
"Minimizer is " <<
fMinimType << std::endl;
395 const unsigned int nw = 25;
396 const unsigned int nn = 12;
397 const std::ios_base::fmtflags
prFmt = os.setf(std::ios::left,std::ios::adjustfield);
400 os << std::left << std::setw(
nw) <<
"MinFCN" <<
" = " << std::right << std::setw(
nn) <<
fVal << std::endl;
402 os << std::left << std::setw(
nw) <<
"Chi2" <<
" = " << std::right << std::setw(
nn) <<
fChi2 << std::endl;
403 os << std::left << std::setw(
nw) <<
"NDf" <<
" = " << std::right << std::setw(
nn) <<
fNdf << std::endl;
404 if (
fMinimType.find(
"Linear") == std::string::npos) {
405 if (
fEdm >=0) os << std::left << std::setw(
nw) <<
"Edm" <<
" = " << std::right << std::setw(
nn) <<
fEdm << std::endl;
406 os << std::left << std::setw(
nw) <<
"NCalls" <<
" = " << std::right << std::setw(
nn) <<
fNCalls << std::endl;
408 for (
unsigned int i = 0; i <
npar; ++i) {
410 os <<
" = " << std::right << std::setw(
nn) <<
fParams[i];
412 os << std::setw(9) <<
" " << std::setw(
nn) <<
" " <<
" \t (fixed)";
415 os <<
" +/- " << std::left << std::setw(
nn) <<
fErrors[i] << std::right;
420 os <<
" \t (limited)";
426 if (
prFmt != os.flags() ) os.setf(
prFmt, std::ios::adjustfield);
436 os <<
"\nCovariance Matrix:\n\n";
445 const std::ios_base::fmtflags
prevFmt = os.flags();
447 os << std::setw(
parw) <<
" " <<
"\t";
448 for (
unsigned int i = 0; i <
npar; ++i) {
454 for (
unsigned int i = 0; i <
npar; ++i) {
457 for (
unsigned int j = 0;
j <
npar; ++
j) {
466 os <<
"\nCorrelation Matrix:\n\n";
467 os << std::setw(
parw) <<
" " <<
"\t";
468 for (
unsigned int i = 0; i <
npar; ++i) {
474 for (
unsigned int i = 0; i <
npar; ++i) {
477 for (
unsigned int j = 0;
j <
npar; ++
j) {
486 os.setf(
prevFmt, std::ios::adjustfield);
499 MATH_ERROR_MSG(
"FitResult::GetConfidenceIntervals",
"Cannot compute Confidence Intervals without fit model function");
515 unsigned int ndim =
fFitFunc->NDim();
518 std::vector<double>
xpoint(ndim);
519 std::vector<double> grad(
npar);
533 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
540 d.SetStepSize( std::max(
fErrors[ipar]*1.E-5, 1.E-15) );
542 d.SetStepSize( std::min(std::max(
fParams[ipar]*1.E-5, 1.E-15), 0.0001 ) );
552 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
559 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
560 r2 += grad[ipar] *
vsum[ipar];
562 double r = std::sqrt(
r2);
571 unsigned int ndim =
data.NDim();
572 unsigned int np =
data.NPoints();
573 std::vector<double>
xdata( ndim *
np );
574 for (
unsigned int i = 0; i <
np ; ++i) {
575 const double *
x =
data.Coords(i);
577 std::copy(
x,
x+ndim,
itr);
587 std::vector<double>
result;
593 MATH_ERROR_MSG(
"FitResult::GetConfidenceIntervals",
"Cannot compute Confidence Intervals without the fit bin data");
629 MATH_ERROR_MSG(
"FitResult::Scan",
"Minimizer is not available - cannot Scan");
650 MATH_ERROR_MSG(
"FitResult::Contour",
"Minimizer is not available - cannot produce Contour");
#define MATH_ERROR_MSG(loc, str)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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...
std::vector< double > fGlobalCC
global Correlation coefficient
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...
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 ...
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, int fitType=1, 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...
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
std::vector< unsigned int > fBoundParams
if parameters are limited
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
std::vector< bool > fFixedParams
if parameters are fixed
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::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
void SetChi2AndNdf(double chi2, unsigned int npoints)
Set the chi2 and the ndf This function should be called when using an external FCN for fitting and on...
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
return parameter value
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.
const_iterator begin() const
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.
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,...