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
26
27////////////////////////////////////////////////////////////////////////////////
28/// Constructor from a ROOT::Fit::FitResult
29/// copy the contained TF1 pointer function if it is
30
32 TNamed("TFitResult","TFitResult"),
33 ROOT::Fit::FitResult(f)
34{
36 if (wfunc) wfunc->SetAndCopyFunction();
37}
38
39
40////////////////////////////////////////////////////////////////////////////////
41/// Print result of the fit, by default chi2, parameter values and errors.
42/// if option "V" is given print also error matrix and correlation
43
44void TFitResult::Print(Option_t *option) const
45{
46 TString opt(option);
47 opt.ToUpper();
48 bool doCovMat = opt.Contains("V");
49 ROOT::Fit::FitResult::Print( std::cout, doCovMat);
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Return the covariance matrix from fit
54///
55/// The matrix is a symmetric matrix with a size N equal to
56/// the total number of parameters considered in the fit including the fixed ones
57/// The matrix row and columns corresponding to the fixed parameters will contain only zero's
58
60{
61 if (CovMatrixStatus() == 0) {
62 Warning("GetCovarianceMatrix","covariance matrix is not available");
63 return TMatrixDSym();
64 }
65 TMatrixDSym mat(NPar());
66 ROOT::Fit::FitResult::GetCovarianceMatrix<TMatrixDSym>(mat);
67 return mat;
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Return the correlation matrix from fit.
72///
73/// The matrix is a symmetric matrix with a size N equal to
74/// the total number of parameters considered in the fit including the fixed ones
75/// The matrix row and columns corresponding to the fixed parameters will contain only zero's
76
78{
79 if (CovMatrixStatus() == 0) {
80 Warning("GetCorrelationMatrix","correlation matrix is not available");
81 return TMatrixDSym();
82 }
83 TMatrixDSym mat(NPar());
84 ROOT::Fit::FitResult::GetCorrelationMatrix<TMatrixDSym>(mat);
85 return mat;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Scan parameter ipar between value of xmin and xmax
90/// A graph must be given which will be on return filled with the scan resul
91/// If the graph size is zero, a default size n = 40 will be used
92
93bool TFitResult::Scan(unsigned int ipar, TGraph *gr, double xmin, double xmax)
94{
95 if (!gr)
96 return false;
97
98 unsigned int npoints = gr->GetN();
99 if (npoints == 0) {
100 npoints = 40;
101 gr->Set(npoints);
102 }
103 bool ret = ROOT::Fit::FitResult::Scan(ipar, npoints, gr->GetX(), gr->GetY(), xmin, xmax);
104 if ((int)npoints < gr->GetN())
105 gr->Set(npoints);
106 return ret;
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// Create a 2D contour around the minimum for the parameter ipar and jpar
111/// if a minimum does not exist or is invalid it will return false
112/// on exit a TGraph is filled with the contour points
113/// the number of contour points is determined by the size of the TGraph.
114/// if the size is zero a default number of points = 20 is used
115/// pass optionally the confidence level, default is 0.683
116/// it is assumed that ErrorDef() defines the right error definition
117/// (i.e 1 sigma error for one parameter). If not the confidence level are scaled to new level
118
119bool TFitResult::Contour(unsigned int ipar, unsigned int jpar, TGraph *gr, double confLevel)
120{
121 if (!gr)
122 return false;
123
124 unsigned int npoints = gr->GetN();
125 if (npoints == 0) {
126 npoints = 40;
127 gr->Set(npoints);
128 }
129 bool ret = ROOT::Fit::FitResult::Contour(ipar, jpar, npoints, gr->GetX(), gr->GetY(), confLevel);
130 if ((int)npoints < gr->GetN())
131 gr->Set(npoints);
132
133 return ret;
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Print the TFitResult.
138
139std::string cling::printValue(const TFitResult* val)
140{
141 std::stringstream outs;
142 val->ROOT::Fit::FitResult::Print(outs, false /*doCovMat*/);
143 return outs.str();
144}
#define f(i)
Definition RSha256.hxx:104
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
float xmin
float xmax
TMatrixTSym< Double_t > TMatrixDSym
class containg the result of the fit and all the related information (fitted parameter values,...
Definition FitResult.h:47
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 optionaly 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:338
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...
unsigned int NPar() const
total number of parameters (abbreviation)
Definition FitResult.h:131
int CovMatrixStatus() const
covariance matrix status code using Minuit convention : =0 not calculated, =1 approximated,...
Definition FitResult.h:142
Class to Wrap a ROOT Function class (like TF1) in a IParamMultiFunction interface of multi-dimensions...
void SetAndCopyFunction(const TF1 *f=0)
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.
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...
virtual void Print(Option_t *option="") const
Print result of the fit, by default chi2, parameter values and errors.
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
Double_t * GetY() const
Definition TGraph.h:133
Int_t GetN() const
Definition TGraph.h:125
Double_t * GetX() const
Definition TGraph.h:132
virtual void Set(Int_t n)
Set number of points in the graph Existing coordinates are preserved New coordinates above fNpoints a...
Definition TGraph.cxx:2233
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:949
Basic string class.
Definition TString.h:136
void ToUpper()
Change string to upper case.
Definition TString.cxx:1163
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
TGraphErrors * gr
Definition legend1.C:25
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...