Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TFitResult.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: David Gonzalez Maline 12/11/09
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TFitResult.h"
14#include "TGraph.h"
15
16
17#include <iostream>
18
19/** \class TFitResult
20 \ingroup Hist
21Extends the ROOT::Fit::Result class with a TNamed inheritance
22providing easy possibility for I/O
23*/
24
25
26////////////////////////////////////////////////////////////////////////////////
27/// Constructor from a ROOT::Fit::FitResult
28/// copy the contained TF1 pointer function if it is
29
31 TNamed("TFitResult","TFitResult"),
32 ROOT::Fit::FitResult(f)
33{
35 if (wfunc) wfunc->SetAndCopyFunction();
36}
37
38
39////////////////////////////////////////////////////////////////////////////////
40/// Print result of the fit, by default chi2, parameter values and errors.
41/// if option "V" is given print also error matrix and correlation
42
43void TFitResult::Print(Option_t *option) const
44{
45 TString opt(option);
46 opt.ToUpper();
47 bool doCovMat = opt.Contains("V");
48 ROOT::Fit::FitResult::Print( std::cout, doCovMat);
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Return the covariance matrix from fit
53///
54/// The matrix is a symmetric matrix with a size N equal to
55/// the total number of parameters considered in the fit including the fixed ones
56/// The matrix row and columns corresponding to the fixed parameters will contain only zero's
57
59{
60 if (CovMatrixStatus() == 0) {
61 Warning("GetCovarianceMatrix","covariance matrix is not available");
62 return TMatrixDSym();
63 }
64 TMatrixDSym mat(NPar());
66 return mat;
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Return the correlation matrix from fit.
71///
72/// The matrix is a symmetric matrix with a size N equal to
73/// the total number of parameters considered in the fit including the fixed ones
74/// The matrix row and columns corresponding to the fixed parameters will contain only zero's
75
77{
78 if (CovMatrixStatus() == 0) {
79 Warning("GetCorrelationMatrix","correlation matrix is not available");
80 return TMatrixDSym();
81 }
82 TMatrixDSym mat(NPar());
84 return mat;
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// Scan parameter ipar between value of xmin and xmax
89/// A graph must be given which will be on return filled with the scan resul
90/// If the graph size is zero, a default size n = 40 will be used
91
92bool TFitResult::Scan(unsigned int ipar, TGraph *gr, double xmin, double xmax)
93{
94 if (!gr)
95 return false;
96
97 unsigned int npoints = gr->GetN();
98 if (npoints == 0) {
99 npoints = 40;
100 gr->Set(npoints);
101 }
102 bool ret = ROOT::Fit::FitResult::Scan(ipar, npoints, gr->GetX(), gr->GetY(), xmin, xmax);
103 if ((int)npoints < gr->GetN())
104 gr->Set(npoints);
105 return ret;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Create a 2D contour around the minimum for the parameter ipar and jpar
110/// if a minimum does not exist or is invalid it will return false
111/// on exit a TGraph is filled with the contour points
112/// the number of contour points is determined by the size of the TGraph.
113/// if the size is zero a default number of points = 20 is used
114/// pass optionally the confidence level, default is 0.683
115/// it is assumed that ErrorDef() defines the right error definition
116/// (i.e 1 sigma error for one parameter). If not the confidence level are scaled to new level
117
118bool TFitResult::Contour(unsigned int ipar, unsigned int jpar, TGraph *gr, double confLevel)
119{
120 if (!gr)
121 return false;
122
123 unsigned int npoints = gr->GetN();
124 if (npoints == 0) {
125 npoints = 40;
126 gr->Set(npoints);
127 }
128 bool ret = ROOT::Fit::FitResult::Contour(ipar, jpar, npoints, gr->GetX(), gr->GetY(), confLevel);
129 if ((int)npoints < gr->GetN())
130 gr->Set(npoints);
131
132 return ret;
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Print the TFitResult.
137
138std::string cling::printValue(const TFitResult* val)
139{
140 std::stringstream outs;
141 val->ROOT::Fit::FitResult::Print(outs, false /*doCovMat*/);
142 return outs.str();
143}
#define f(i)
Definition RSha256.hxx:104
char * ret
Definition Rotated.cxx:221
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
float xmin
float xmax
TMatrixTSym< Double_t > TMatrixDSym
class containing the result of the fit and all the related information (fitted parameter values,...
Definition FitResult.h:44
FitResult()=default
Default constructor for an empty (non valid) fit result.
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.
void Print(std::ostream &os, bool covmat=false) const
print the result and optionally covariance matrix and correlations
std::shared_ptr< IModelFunction > ModelFunction()
Return pointer non const pointer to model (fit) function with fitted parameter values.
Definition FitResult.h:331
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...
void GetCorrelationMatrix(Matrix &mat) const
fill a correlation matrix elements using a generic symmetric matrix class implementing operator(i,...
Definition FitResult.h:243
unsigned int NPar() const
total number of parameters (abbreviation)
Definition FitResult.h:116
int CovMatrixStatus() const
covariance matrix status code using Minuit convention : =0 not calculated, =1 approximated,...
Definition FitResult.h:127
void GetCovarianceMatrix(Matrix &mat) const
fill covariance matrix elements using a generic matrix class implementing operator(i,...
Definition FitResult.h:229
void SetAndCopyFunction(const TF1 *f=nullptr)
method to set a new function pointer and copy it inside.
Extends the ROOT::Fit::Result class with a TNamed inheritance providing easy possibility for I/O.
Definition TFitResult.h:34
TFitResult(int status=0)
Definition TFitResult.h:39
TMatrixDSym GetCorrelationMatrix() const
Return the correlation matrix from fit.
bool Contour(unsigned int ipar, unsigned int jpar, TGraph *gr, double confLevel=0.683)
Create a 2D contour around the minimum for the parameter ipar and jpar if a minimum does not exist or...
TMatrixDSym GetCovarianceMatrix() const
Return the covariance matrix from fit.
void Print(Option_t *option="") const override
Print result of the fit, by default chi2, parameter values and errors.
bool Scan(unsigned int ipar, TGraph *gr, double xmin=0, double xmax=0)
Scan parameter ipar between value of xmin and xmax A graph must be given which will be on return fill...
TNamed()
Definition TNamed.h:38
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1084
Basic string class.
Definition TString.h:138
void ToUpper()
Change string to upper case.
Definition TString.cxx:1202
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:641
TGraphErrors * gr
Definition legend1.C:25
WrappedMultiTF1Templ< double > WrappedMultiTF1