Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FitResult.cxx
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: L. Moneta Wed Aug 30 11:05:34 2006
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11#include "Fit/FitResult.h"
12
13#include "Fit/BinData.h"
14#include "Fit/FitConfig.h"
15#include "Math/Error.h"
16#include "Math/IParamFunction.h"
17#include "Math/Minimizer.h"
22#include "TMath.h"
23
24#include <cassert>
25#include <cmath>
26#include <iostream>
27#include <iomanip>
28
29namespace ROOT::Fit {
30
31const int gInitialResultStatus = -99; // use this special convention to flag it when printing result
32
34 fStatus(gInitialResultStatus),
35 fParams(fconfig.NPar()),
36 fErrors(fconfig.NPar()),
37 fParNames(fconfig.NPar())
38{
39 // create a Fit result from a fit config (i.e. with initial parameter values
40 // and errors equal to step values
41 // The model function is NULL in this case
42
43 // set minimizer type and algorithm
44 fMinimType = fconfig.MinimizerType();
45 // append algorithm name for minimizer that support it
46 if ( (fMinimType.find("Fumili") == std::string::npos) )
47 {
48 if (!fconfig.MinimizerAlgoType().empty()) fMinimType += " / " + fconfig.MinimizerAlgoType();
49 }
50
51 // get parameter values and errors (step sizes)
52 unsigned int npar = fconfig.NPar();
53 fParamBounds.resize(npar);
54 fFixedParams.resize(npar);
55 fBoundParams.resize(npar);
56 for (unsigned int i = 0; i < npar; ++i ) {
57 const ParameterSettings & par = fconfig.ParSettings(i);
58 fParams[i] = par.Value();
59 fErrors[i] = par.StepSize();
60 fParNames[i] = par.Name();
61 fFixedParams[i] = par.IsFixed();
62 if (!par.IsFixed() ) fNFree++;
63 double lower = par.HasLowerLimit() ? par.LowerLimit() : - std::numeric_limits<double>::infinity() ;
64 double upper = par.HasUpperLimit() ? par.UpperLimit() : std::numeric_limits<double>::infinity() ;
65 fParamBounds.emplace_back(lower,upper);
66 }
67 std::cout << "create fit result from config - nfree " << fNFree << std::endl;
68}
69
70void FitResult::FillResult(const std::shared_ptr<ROOT::Math::Minimizer> & min, const FitConfig & fconfig, const std::shared_ptr<IModelFunction> & func,
71 bool isValid, unsigned int sizeOfData, int fitType, const ROOT::Math::IMultiGenFunction * chi2func, unsigned int ncalls )
72{
73 // Fill the FitResult after minimization using result from Minimizers
74
75 // minimizer must exist
76 assert(min);
77
78 fValid = isValid;
79 fNFree= min->NFree();
80 fNCalls = min->NCalls();
81 fStatus = min->Status();
82 fCovStatus= min->CovMatrixStatus();
83 fVal = min->MinValue();
84 fEdm = min->Edm();
85
86 fMinimizer= min;
87 fFitFunc = func;
88
89 fMinimType = fconfig.MinimizerName();
90
91 // replace ncalls if minimizer does not support it (they are taken then from the FitMethodFunction)
92 if (fNCalls == 0) fNCalls = ncalls;
93
94 const unsigned int npar = min->NDim();
95 if (npar == 0) return;
96
97 if (min->X() )
98 fParams = std::vector<double>(min->X(), min->X() + npar);
99 else {
100 // case minimizer does not provide minimum values (it failed) take from configuration
101 fParams.resize(npar);
102 for (unsigned int i = 0; i < npar; ++i ) {
103 fParams[i] = fconfig.ParSettings(i).Value();
104 }
105 }
106
107 if (sizeOfData > min->NFree() ) fNdf = sizeOfData - min->NFree();
108
109
110 // set right parameters in function (in case minimizer did not do before)
111 // do also when fit is not valid
112 if (func ) {
113 // I think we can avoid cloning the model function
114 //fFitFunc = dynamic_cast<IModelFunction *>( func->Clone() );
115 //assert(fFitFunc);
116 fFitFunc->SetParameters(&fParams.front());
117 }
118 else {
119 // when no fFitFunc is present take parameters from FitConfig
120 fParNames.resize( npar );
121 for (unsigned int i = 0; i < npar; ++i ) {
122 fParNames[i] = fconfig.ParSettings(i).Name();
123 }
124 }
125
126
127 // check for fixed or limited parameters
128 unsigned int nfree = 0;
129 fParamBounds.resize(npar);
130 fFixedParams.resize(npar);
131 fBoundParams.resize(npar);
132 for (unsigned int ipar = 0; ipar < npar; ++ipar) {
133 const ParameterSettings & par = fconfig.ParSettings(ipar);
134 fFixedParams[ipar] = par.IsFixed();
135 fBoundParams[ipar] = par.IsBound();
136 if (!par.IsFixed() ) nfree++;
137 double lower = par.HasLowerLimit() ? par.LowerLimit() : - std::numeric_limits<double>::infinity() ;
138 double upper = par.HasUpperLimit() ? par.UpperLimit() : std::numeric_limits<double>::infinity() ;
139 fParamBounds.emplace_back(lower,upper);
140 }
141 // check if nfree (from FitConfig) and fNFree (from minimizer) are consistent
142 if (nfree != fNFree ) {
143 MATH_ERROR_MSG("FitResult","FitConfiguration and Minimizer result are not consistent");
144 std::cout << "Number of free parameters from FitConfig = " << nfree << std::endl;
145 std::cout << "Number of free parameters from Minimizer = " << fNFree << std::endl;
146 }
147
148 // if flag is binned compute a chi2 when a chi2 function is given
149 if (fitType == 1) {
150 if (chi2func == nullptr)
151 fChi2 = fVal;
152 else {
153 // compute chi2 equivalent for likelihood fits
154 // NB: empty bins are considered
155 fChi2 = (*chi2func)(&fParams[0]);
156 }
157 }
158 else if (fitType == 3) {
159 // case of binned likelihood fits (use Baker-Cousins chi2)
160 fChi2 = 2 * fVal;
161 }
162
163 // fill error matrix
164 // if minimizer provides error provides also error matrix
165 // clear in case of re-filling an existing result
166 if (!fCovMatrix.empty()) fCovMatrix.clear();
167 if (!fGlobalCC.empty()) fGlobalCC.clear();
168
169 if (min->Errors() != nullptr) {
170
171 fErrors = std::vector<double>(min->Errors(), min->Errors() + npar ) ;
172
173 if (fCovStatus != 0) {
174 unsigned int r = npar * ( npar + 1 )/2;
175 fCovMatrix.reserve(r);
176 for (unsigned int i = 0; i < npar; ++i)
177 for (unsigned int j = 0; j <= i; ++j)
178 fCovMatrix.push_back(min->CovMatrix(i,j) );
179 }
180 // minos errors are set separately when calling Fitter::CalculateMinosErrors()
181
182 // globalCC
183 fGlobalCC = min->GlobalCC();
184 }
185
186}
187
188bool FitResult::Update(const std::shared_ptr<ROOT::Math::Minimizer> & min, const ROOT::Fit::FitConfig & fconfig, bool isValid, unsigned int ncalls) {
189 // update fit result with new status from minimizer
190 // ncalls if it is not zero is used instead of value from minimizer
191
192 fMinimizer = min;
193
194 // in case minimizer changes
195 fMinimType = fconfig.MinimizerName();
196
197 const unsigned int npar = fParams.size();
198 if (min->NDim() != npar ) {
199 MATH_ERROR_MSG("FitResult::Update","Wrong minimizer status ");
200 return false;
201 }
202 if (min->X() == nullptr ) {
203 MATH_ERROR_MSG("FitResult::Update","Invalid minimizer status ");
204 return false;
205 }
206 if (fNFree != min->NFree() ) {
207 MATH_ERROR_MSG("FitResult::Update","Configuration has changed ");
208 return false;
209 }
210
211 fValid = isValid;
212 // update minimum value
213 fVal = min->MinValue();
214 fEdm = min->Edm();
215 fStatus = min->Status();
216 fCovStatus = min->CovMatrixStatus();
217
218 // update number of function calls
219 if ( min->NCalls() > 0) fNCalls = min->NCalls();
220 else fNCalls = ncalls;
221
222 // copy parameter value and errors
223 std::copy(min->X(), min->X() + npar, fParams.begin());
224
225
226 // set parameters in fit model function
227 if (fFitFunc) fFitFunc->SetParameters(&fParams.front());
228
229 if (min->Errors() != nullptr) {
230
231 if (fErrors.size() != npar) fErrors.resize(npar);
232
233 std::copy(min->Errors(), min->Errors() + npar, fErrors.begin() ) ;
234
235 if (fCovStatus != 0) {
236
237 // update error matrix
238 unsigned int r = npar * ( npar + 1 )/2;
239 if (fCovMatrix.size() != r) fCovMatrix.resize(r);
240 unsigned int l = 0;
241 for (unsigned int i = 0; i < npar; ++i) {
242 for (unsigned int j = 0; j <= i; ++j)
243 fCovMatrix[l++] = min->CovMatrix(i,j);
244 }
245 }
246
247 // update global CC
248 fGlobalCC = min->GlobalCC();
249 fGlobalCC.resize(npar); // pad with zeros
250 }
251 return true;
252}
253
255 // normalize errors and covariance matrix according to chi2 value
256 if (fNdf == 0 || fChi2 <= 0) return;
257 double s2 = fChi2/fNdf;
258 double s = std::sqrt(fChi2/fNdf);
259 for (unsigned int i = 0; i < fErrors.size() ; ++i)
260 fErrors[i] *= s;
261 for (unsigned int i = 0; i < fCovMatrix.size() ; ++i)
262 fCovMatrix[i] *= s2;
263
264 fNormalized = true;
265}
266
267void FitResult::SetChi2AndNdf(double chi2, unsigned int npoints) {
268 if (chi2 >= 0)
269 fChi2 = chi2;
270 if (npoints > fNFree )
271 fNdf = npoints - fNFree;
272 else
273 fNdf = 0;
274}
275
276double FitResult::Prob() const {
277 // fit probability
278 return ROOT::Math::chisquared_cdf_c(fChi2, static_cast<double>(fNdf) );
279}
280
281bool FitResult::HasMinosError(unsigned int i) const {
282 // query if the parameter i has the Minos error
283 return fMinosErrors.find(i) != fMinosErrors.end();
284}
285
286
287double FitResult::LowerError(unsigned int i) const {
288 // return lower Minos error for parameter i
289 // return the parabolic error if Minos error has not been calculated for the parameter i
290 auto itr = fMinosErrors.find(i);
291 return itr != fMinosErrors.end() ? itr->second.first : Error(i);
292}
293
294double FitResult::UpperError(unsigned int i) const {
295 // return upper Minos error for parameter i
296 // return the parabolic error if Minos error has not been calculated for the parameter i
297 auto itr = fMinosErrors.find(i);
298 return itr != fMinosErrors.end() ? itr->second.second : Error(i);
299}
300
301void FitResult::SetMinosError(unsigned int i, double elow, double eup) {
302 // set the Minos error for parameter i
303 fMinosErrors[i] = std::make_pair(elow,eup);
304}
305
306int FitResult::Index(const std::string & name) const {
307 // find index for given parameter name
308 if (! fFitFunc) return -1;
309 unsigned int npar = fParams.size();
310 for (unsigned int i = 0; i < npar; ++i) {
311 if ( fFitFunc->ParameterName(i) == name) return i;
312 }
313
314 return -1; // case name is not found
315}
316
317bool FitResult::IsParameterBound(unsigned int ipar) const
318{
319 return ipar < fBoundParams.size() ? fBoundParams[ipar] : false;
320}
321
322bool FitResult::IsParameterFixed(unsigned int ipar) const
323{
324 return ipar < fFixedParams.size() ? fFixedParams[ipar] : false;
325}
326
327bool FitResult::ParameterBounds(unsigned int ipar, double &lower, double &upper) const
328{
329 constexpr double inf = std::numeric_limits<double>::infinity();
330 if (ipar < fParamBounds.size()) {
331 lower = fParamBounds[ipar].first;
332 upper = fParamBounds[ipar].second;
333 }
334 return lower != -inf || upper != inf;
335}
336
337std::string FitResult::ParName(unsigned int ipar) const {
338 // return parameter name
339 if (fFitFunc) return fFitFunc->ParameterName(ipar);
340 else if (ipar < fParNames.size() ) return fParNames[ipar];
341 return "param_" + ROOT::Math::Util::ToString(ipar);
342}
343
344void FitResult::Print(std::ostream & os, bool doCovMatrix) const {
345 // print the result in the given stream
346 // need to add also minos errors , globalCC, etc..
347 unsigned int npar = fParams.size();
348 if (npar == 0) {
349 os << "<Empty FitResult>\n";
350 return;
351 }
352 os << "****************************************\n";
353 if (!fValid) {
355 os << " Invalid FitResult";
356 os << " (status = " << fStatus << " )";
357 }
358 else {
359 os << " FitResult before fitting";
360 }
361 os << "\n****************************************\n";
362 }
363
364 //os << " FitResult \n\n";
365 os << "Minimizer is " << fMinimType << std::endl;
366 const unsigned int nw = 25; // spacing for text
367 const unsigned int nn = 12; // spacing for numbers
368 const std::ios_base::fmtflags prFmt = os.setf(std::ios::left,std::ios::adjustfield); // set left alignment
369
370 if (fVal != fChi2 || fChi2 < 0)
371 os << std::left << std::setw(nw) << "MinFCN" << " = " << std::right << std::setw(nn) << fVal << std::endl;
372 if (fChi2 >= 0)
373 os << std::left << std::setw(nw) << "Chi2" << " = " << std::right << std::setw(nn) << fChi2 << std::endl;
374 os << std::left << std::setw(nw) << "NDf" << " = " << std::right << std::setw(nn) << fNdf << std::endl;
375 if (fMinimType.find("Linear") == std::string::npos) { // no need to print this for linear fits
376 if (fEdm >=0) os << std::left << std::setw(nw) << "Edm" << " = " << std::right << std::setw(nn) << fEdm << std::endl;
377 os << std::left << std::setw(nw) << "NCalls" << " = " << std::right << std::setw(nn) << fNCalls << std::endl;
378 }
379 for (unsigned int i = 0; i < npar; ++i) {
380 os << std::left << std::setw(nw) << GetParameterName(i);
381 os << " = " << std::right << std::setw(nn) << fParams[i];
382 if (IsParameterFixed(i) )
383 os << std::setw(9) << " " << std::setw(nn) << " " << " \t (fixed)";
384 else {
385 if (!fErrors.empty())
386 os << " +/- " << std::left << std::setw(nn) << fErrors[i] << std::right;
387 if (HasMinosError(i))
388 os << " " << std::left << std::setw(nn) << LowerError(i) << " +" << std::setw(nn) << UpperError(i)
389 << " (Minos) ";
390 if (IsParameterBound(i))
391 os << " \t (limited)";
392 }
393 os << std::endl;
394 }
395
396 // restore stremam adjustfield
397 if (prFmt != os.flags() ) os.setf(prFmt, std::ios::adjustfield);
398
400}
401
402void FitResult::PrintCovMatrix(std::ostream &os) const {
403 // print the covariance and correlation matrix
404 if (!fValid) return;
405 if (fCovMatrix.empty()) return;
406// os << "****************************************\n";
407 os << "\nCovariance Matrix:\n\n";
408 unsigned int npar = fParams.size();
409 const int kPrec = 5;
410 const int kWidth = 8;
411 const int parw = 12;
412 const int matw = kWidth+4;
413
414 // query previous precision and format flags
415 int prevPrec = os.precision(kPrec);
416 const std::ios_base::fmtflags prevFmt = os.flags();
417
418 os << std::setw(parw) << " " << "\t";
419 for (unsigned int i = 0; i < npar; ++i) {
420 if (!IsParameterFixed(i) ) {
421 os << std::right << std::setw(matw) << GetParameterName(i) ;
422 }
423 }
424 os << std::endl;
425 for (unsigned int i = 0; i < npar; ++i) {
426 if (!IsParameterFixed(i) ) {
427 os << std::left << std::setw(parw) << GetParameterName(i) << "\t";
428 for (unsigned int j = 0; j < npar; ++j) {
429 if (!IsParameterFixed(j) ) {
430 os.precision(kPrec); os.width(kWidth); os << std::right << std::setw(matw) << CovMatrix(i,j);
431 }
432 }
433 os << std::endl;
434 }
435 }
436// os << "****************************************\n";
437 os << "\nCorrelation Matrix:\n\n";
438 os << std::setw(parw) << " " << "\t";
439 for (unsigned int i = 0; i < npar; ++i) {
440 if (!IsParameterFixed(i) ) {
441 os << std::right << std::setw(matw) << GetParameterName(i) ;
442 }
443 }
444 os << std::endl;
445 for (unsigned int i = 0; i < npar; ++i) {
446 if (!IsParameterFixed(i) ) {
447 os << std::left << std::setw(parw) << std::left << GetParameterName(i) << "\t";
448 for (unsigned int j = 0; j < npar; ++j) {
449 if (!IsParameterFixed(j) ) {
450 os.precision(kPrec); os.width(kWidth); os << std::right << std::setw(matw) << Correlation(i,j);
451 }
452 }
453 os << std::endl;
454 }
455 }
456 // restore alignment and precision
457 os.setf(prevFmt, std::ios::adjustfield);
458 os.precision(prevPrec);
459}
460
461void FitResult::GetConfidenceIntervals(unsigned int n, unsigned int stride1, unsigned int stride2, const double * x, double * ci, double cl, bool norm ) const {
462 // stride1 stride in coordinate stride2 stride in dimension space
463 // i.e. i-th point in k-dimension is x[ stride1 * i + stride2 * k]
464 // compute the confidence interval of the fit on the given data points
465 // the dimension of the data points must match the dimension of the fit function
466 // confidence intervals are returned in array ci
467
468 if (!fFitFunc) {
469 // check if model function exists
470 MATH_ERROR_MSG("FitResult::GetConfidenceIntervals","Cannot compute Confidence Intervals without fit model function");
471 return;
472 }
474
475 // use student quantile in case of normalized errors
476 double corrFactor = 1;
477 if (fChi2 <= 0 || fNdf == 0) norm = false;
478 if (norm)
479 corrFactor = TMath::StudentQuantile(0.5 + cl/2, fNdf) * std::sqrt( fChi2/fNdf );
480 else
481 // correction to apply to the errors given a CL different than 1 sigma (cl=0.683)
483
484
485
486 unsigned int ndim = fFitFunc->NDim();
487 unsigned int npar = fFitFunc->NPar();
488
489 std::vector<double> xpoint(ndim);
490 std::vector<double> grad(npar);
491 std::vector<double> vsum(npar);
492
493 // loop on the points
494 for (unsigned int ipoint = 0; ipoint < n; ++ipoint) {
495
496 for (unsigned int kdim = 0; kdim < ndim; ++kdim) {
497 unsigned int i = ipoint * stride1 + kdim * stride2;
498 assert(i < ndim*n);
499 xpoint[kdim] = x[i];
500 }
501
502 // calculate gradient of fitted function w.r.t the parameters
504 for (unsigned int ipar = 0; ipar < npar; ++ipar) {
505 if (!IsParameterFixed(ipar)) {
507 d.SetFunction(fadapter);
508 // compute step size as a small fraction of the error
509 // (see numerical recipes in C 5.7.8) 1.E-5 is ~ (eps)^1/3
510 if ( fErrors[ipar] > 0 )
511 d.SetStepSize( std::max( fErrors[ipar]*1.E-5, 1.E-15) );
512 else
513 d.SetStepSize( std::min(std::max(fParams[ipar]*1.E-5, 1.E-15), 0.0001 ) );
514
515 grad[ipar] = d(fParams[ipar] ); // evaluate df/dp
516 }
517 else
518 grad[ipar] = 0.; // for fixed parameters
519 }
520
521 // multiply covariance matrix with gradient
522 vsum.assign(npar,0.0);
523 for (unsigned int ipar = 0; ipar < npar; ++ipar) {
524 for (unsigned int jpar = 0; jpar < npar; ++jpar) {
525 vsum[ipar] += CovMatrix(ipar,jpar) * grad[jpar];
526 }
527 }
528 // multiply gradient by vsum
529 double r2 = 0;
530 for (unsigned int ipar = 0; ipar < npar; ++ipar) {
531 r2 += grad[ipar] * vsum[ipar];
532 }
533 double r = std::sqrt(r2);
534 ci[ipoint] = r * corrFactor;
535 }
536}
537
538void FitResult::GetConfidenceIntervals(const BinData & data, double * ci, double cl, bool norm ) const {
539 // implement confidence intervals from a given bin data sets
540 // currently copy the data from Bindata.
541 // could implement otherwise directly
542 unsigned int ndim = data.NDim();
543 unsigned int np = data.NPoints();
544 std::vector<double> xdata( ndim * np );
545 for (unsigned int i = 0; i < np ; ++i) {
546 const double * x = data.Coords(i);
547 std::vector<double>::iterator itr = xdata.begin()+ ndim * i;
548 std::copy(x,x+ndim,itr);
549 }
550 // points are arranged as x0,y0,z0, ....xN,yN,zN (stride1=ndim, stride2=1)
551 GetConfidenceIntervals(np,ndim,1,&xdata.front(),ci,cl,norm);
552}
553
554std::vector<double> FitResult::GetConfidenceIntervals(double cl, bool norm ) const {
555 // implement confidence intervals using stored data sets (if can be retrieved from objective function)
556 // it works only in case of chi2 or binned likelihood fits
557 const BinData * data = FittedBinData();
558 std::vector<double> result;
559 if (data) {
560 result.resize(data->NPoints() );
561 GetConfidenceIntervals(*data, result.data(), cl, norm);
562 }
563 else {
564 MATH_ERROR_MSG("FitResult::GetConfidenceIntervals","Cannot compute Confidence Intervals without the fit bin data");
565 }
566 return result;
567}
568
570 return dynamic_cast<const BinData*> ( fFitData.get() );
571}
572
573////////////////////////////////////////////////////////////////////////////////
574/// Scan parameter ipar between value of xmin and xmax
575/// A array for x and y points should be provided
576
577bool FitResult::Scan(unsigned int ipar, unsigned int &npoints, double *pntsx, double *pntsy, double xmin, double xmax)
578{
579 if (!pntsx || !pntsy || !npoints)
580 return false;
581
582 if (!fMinimizer) {
583 MATH_ERROR_MSG("FitResult::Scan", "Minimizer is not available - cannot Scan");
584 return false;
585 }
586
587 return fMinimizer->Scan(ipar, npoints, pntsx, pntsy, xmin, xmax);
588}
589
590////////////////////////////////////////////////////////////////////////////////
591/// Create a 2D contour around the minimum for the parameter ipar and jpar
592/// if a minimum does not exist or is invalid it will return false
593/// A array for x and y points should be provided
594/// Pass optionally the confidence level, default is 0.683
595/// it is assumed that ErrorDef() defines the right error definition
596/// (i.e 1 sigma error for one parameter). If not the confidence level are scaled to new level
597
598bool FitResult::Contour(unsigned int ipar, unsigned int jpar, unsigned int &npoints, double *pntsx, double *pntsy, double confLevel)
599{
600 if (!pntsx || !pntsy || !npoints)
601 return false;
602
603 if (!fMinimizer) {
604 MATH_ERROR_MSG("FitResult::Contour", "Minimizer is not available - cannot produce Contour");
605 return false;
606 }
607
608 // get error level used for fitting
609 double upScale = fMinimizer->ErrorDef();
610
611 double upVal = TMath::ChisquareQuantile(confLevel, 2); // 2 is number of parameter we do the contour
612
613 // set required error definition in minimizer
614 fMinimizer->SetErrorDef(upScale * upVal);
615
616 bool ret = fMinimizer->Contour(ipar, jpar, npoints, pntsx, pntsy);
617
618 // restore the error level used for fitting
619 fMinimizer->SetErrorDef(upScale);
620
621 return ret;
622}
623
624} // namespace ROOT::Fit
#define MATH_ERROR_MSG(loc, str)
Definition Error.h:83
#define d(i)
Definition RSha256.hxx:102
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
char name[80]
Definition TGX11.cxx:110
float xmin
float xmax
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Definition BinData.h:52
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Definition FitConfig.h:49
std::vector< double > fGlobalCC
global Correlation coefficient
Definition FitResult.h:357
unsigned int fNFree
number of fit free parameters (total parameters are in size of parameter vector)
Definition FitResult.h:339
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 ...
FitResult()=default
Default constructor for an empty (non valid) fit result.
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...
Definition FitResult.cxx:70
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
Definition FitResult.h:344
double fEdm
expected distance from minimum
Definition FitResult.h:345
std::vector< double > fErrors
errors
Definition FitResult.h:355
std::shared_ptr< ROOT::Math::Minimizer > fMinimizer
! minimizer object used for fitting
Definition FitResult.h:347
bool fValid
flag for indicating valid fit
Definition FitResult.h:337
bool IsParameterFixed(unsigned int ipar) const
query if a parameter is fixed
unsigned int fNdf
number of degree of freedom
Definition FitResult.h:340
double Error(unsigned int i) const
parameter error by index
Definition FitResult.h:173
double CovMatrix(unsigned int i, unsigned int j) const
retrieve covariance matrix element
Definition FitResult.h:209
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
Definition FitResult.h:343
std::vector< unsigned int > fBoundParams
if parameters are limited
Definition FitResult.h:352
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.
std::shared_ptr< FitData > fFitData
! data set used in the fit
Definition FitResult.h:350
std::string GetParameterName(unsigned int ipar) const
get name of parameter (deprecated)
Definition FitResult.h:321
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
Definition FitResult.h:354
std::vector< double > fCovMatrix
covariance matrix (size is npar*(npar+1)/2) where npar is total parameters
Definition FitResult.h:356
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
Definition FitResult.h:351
void PrintCovMatrix(std::ostream &os) const
print error matrix and correlations
unsigned int fNCalls
number of function calls
Definition FitResult.h:341
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
Definition FitResult.h:353
int fStatus
minimizer status code
Definition FitResult.h:342
double fChi2
fit chi2 value (different than fval in case of chi2 fits)
Definition FitResult.h:346
std::shared_ptr< IModelFunction > fFitFunc
! model function resulting from the fit.
Definition FitResult.h:349
std::string fMinimType
string indicating type of minimizer
Definition FitResult.h:359
double Correlation(unsigned int i, unsigned int j) const
retrieve correlation elements
Definition FitResult.h:219
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
Definition FitResult.h:338
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)
Definition FitResult.h:360
std::map< unsigned int, std::pair< double, double > > fMinosErrors
map contains the two Minos errors
Definition FitResult.h:358
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.
Definition IFunction.h:63
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...
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Namespace for the fitting classes.
const int gInitialResultStatus
Definition FitResult.cxx:31
std::string ToString(const T &val)
Utility function for conversion to strings.
Definition Util.h:65
Double_t ChisquareQuantile(Double_t p, Double_t ndf)
Evaluate the quantiles of the chi-squared probability distribution function.
Definition TMath.cxx:2196
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,...
Definition TMath.cxx:2676
TLine l
Definition textangle.C:4