Fitting Contour Plot with Linear Fit?

Hi,

I have two linearly correlated variables which I plot in a TH2F xy contour plot. I am then trying to fit this plot with a straight line, but the fit returns strange values for the line. If I define:

TF1* fit = new TF1(“fit”,"[0] + [1]*x",0.0,0.3);

and then try to fit:

hist->Fit(“fit”);

The line is quite off and does not show the correlation. Is there a better way to fit a straight line to a contour plot? Thank you for your help.

Cheers,
Peter

Hello,

If you send me a root file containing the histogram, I can have a look at it.
Otherwise, you can try also to convert the 2D histogram to a TProfile class and fitting that one.

Best Regards

Lorenzo

Hi Lorenzo,

Converting to a TProfile and fitting it worked great. Thank you for the hint.

Cheers,
Peter