My question might be a simple one but I’m stumped. I’m using TFractionFitter to fit a histogram, hoping to get out a covariance matrix from the fit. I can see from the documentation that there is a function called GetFitter() that “Give direct access to the underlying fitter class.” From the “underlying fitter class” I should be able to access a FitResult and from FitResult I can use GetCovarianceMatrix().

My problem is that I can’t get the code to properly perform these steps and I can’t find an example online illustrating how to use TFractionFitter::GetFitter(). Could someone post a couple lines of code showing how to use TFractionFitter::GetFitter()?

Perhaps I’m having an error with the fact that I used TFractionFitter* but it doesn’t seem to work. The compiler is identifying “r” as type “int”. When I run the following code, I get an error stating that r is not of type ‘pointer’ and when I change it to .GetCovarianceMatrix() I get an error stating that it is an int.

TFractionFitter* fit = new TFractionFitter(dataHist, MCTheory); // initialise
auto r = fit->Fit();
auto matrix = r->GetCovarianceMatrix();
matrix.Print();

Quick follow-up, how would one access the correlation coefficients matrix from TFractionFitter? I see a function called Correlation() in ROOT::Fit::FitResult and I suspect this is what I’m trying to call.

If you are using ROOT 6, you can call also TFitResult::GetCorrelationMatrix()

TFractionFitter* fit = new TFractionFitter(dataHist, MCTheory); // initialise
auto r = fit->Fit();
auto matrix = r->GetCorrelationMatrix();
matrix.Print();

But there is no GetCorrelationMatrix from TVirtualFitter. But you can get the correlation matrix from the covariance

There is no static method TFitResult::GetCorrelationMatrix. You need to get the TFitResult as return object from the Fit method as shown in the code snipped in my previous post.

Thanks for all the help Lorenzo. This seems to be working.

if you don’t mind, I have yet another follow-up question. How would one set initial parameters in the frac0 and frac1 fitting? It always seems to start at 0.5 and 0.5 and I’m getting a bunch of seg faults on some of my data sets. I suspect it is because the actual fractions should end up as ~0.95 and ~0.05 so it is causing seg faults. Weirdly enough, it doesn’t cause it on all my data sets but just a select few that don’t seem to be special at all.

Nevermind, I figured it out. The following code snippet starts the parameter search at the fractions set by “value”.

[code] TFractionFitter* fit = new TFractionFitter(dataHist, MCTheory, “V”); // initialise
TVirtualFitter* vfit = fit->GetFitter();
int fitMin = 10;
int fitMax = 85;
fit -> SetRangeX(fitMin, fitMax); // Set range in bin numbers