Hi all,
I am slightly confused by TFitResultPtr, when used in the case of a histogram fit.
When returning the covariance matrix, if the matrix is initialised beforehand, then the result returned is rubbish.,
I present working and non-working cases below.
Non-Working:
[code]#include
#include “TH1.h”
#include “TF1.h”
#include “TRandom3.h”
#include “TMatrix.h”
#include “TFitResult.h”
int main(void)
{//binned fit - need to fix at some point
TH1D *hist1 = new TH1D(“hist1”,“”,40,-5,5);
TF1 *func1 = new TF1(“gaus”,“gaus(0)”,-5,5);
TRandom3 *r = new TRandom3;
TMatrixDSym m;
for (int j=0;j<100;j++){hist1->Fill(r->Gaus(0,1));}
TFitResultPtr s = hist1->Fit(func1,“SQ”,“goff”);
s->Print(“V”);
m = s->GetCovarianceMatrix();
std::cout<<"s matrix properties "<GetCovarianceMatrix().GetNrows()<<‘\t’<GetCovarianceMatrix().GetNcols()<<std::endl;
std::cout<<"m matrix properties "<<m.GetNrows()<<‘\t’<<m.GetNcols()<<std::endl;
delete hist1;
delete func1;
return int(s);
}[/code]
Output:
and working
[code]#include
#include “TH1.h”
#include “TF1.h”
#include “TRandom3.h”
#include “TMatrix.h”
#include “TFitResult.h”
int main(void)
{//binned fit - need to fix at some point
TH1D *hist1 = new TH1D(“hist1”,“”,40,-5,5);
TF1 *func1 = new TF1(“gaus”,“gaus(0)”,-5,5);
TRandom3 *r = new TRandom3;
for (int j=0;j<100;j++){hist1->Fill(r->Gaus(0,1));}
TFitResultPtr s = hist1->Fit(func1,“SQ”,“goff”);
s->Print(“V”);
TMatrixDSym m = s->GetCovarianceMatrix();
std::cout<<"s matrix properties "<GetCovarianceMatrix().GetNrows()<<‘\t’<GetCovarianceMatrix().GetNcols()<<std::endl;
std::cout<<"m matrix properties "<<m.GetNrows()<<‘\t’<<m.GetNcols()<<std::endl;
delete hist1;
delete func1;
return int(s);
}[/code]
Output:
[quote][~] g++ test.cpp `root-config --cflags --libs`
[~] ./a.out
TCanvas::MakeDefCanvas: created default TCanvas with name c1
Minimizer is Minuit / Migrad
Chi2 = 100
NDf = 14
Edm = 0
NCalls = 124
p0 = 0 +/- 4.16108e-31
p1 = 0 +/- 1.41421
p2 = 0 +/- 1.41421
Covariance Matrix
p0 p1 p2
p0 1.7315e-61 0 0
p1 0 2 0
p2 0 0 2
Correlation Matrix
p0 p1 p2
p0 1 0 0
p1 0 1 0
p2 0 0 1
s matrix properties 3 3
m matrix properties 3 3
[/quote]
Why the difference?
Thanks