Dear Root users,
I would like to get the covariance matrix from my fit, but I don’t know how to do it. Could you please indicate me? I tried like below, but it did not work.
Thank you very much,
int QA2()
{
Double_t x[]={1,2,3,4,5};
Double_t y[]={1.1, 1.9, 3.2, 3.9, 5.5};
TGraph *g = new TGraph(5,x,y);
g->Draw("A*P");
TFitResult *kq = g->Fit("pol1");
kq.CovMatrix();
return 0;
}
See “Access to the fit result” in the TGraph::Fit method description.
[code]#include “TGraph.h”
#include “TFitResult.h”
#include “TMatrixD.h”
int QA2()
{
Double_t x[] = {1, 2, 3, 4, 5};
Double_t y[] = {1.1, 1.9, 3.2, 3.9, 5.5};
TGraph g = new TGraph((sizeof(x) / sizeof(Double_t)), x, y);
g->Draw("A");
TFitResultPtr r = g->Fit(“pol1”, “S”);
TMatrixD cov = r->GetCorrelationMatrix();
TMatrixD cor = r->GetCovarianceMatrix();
cov.Print();
cor.Print();
return 0;
}[/code]