I encountered a problem when I wanted to fit a Breit-Wigner function and a constant background to a set of data points with x and y errors. The x error seems not to be considered during the fit. I attached a macro that reproduces this behaviour.
What am I doing wrong? test.C (1.8 KB)

I can reproduce your problem. There is an error in the computation of the derivatives of the function which are used to compute the effective weight for each point to be used in the least square function. The error comes because you have a very small range in x (DeltaX << X). I will fix this problem.
Thank you for reporting it

I would have one further question. Could you point which files you changed exactly in order to fix the bug?
My root version is part of a bigger software package used in our collaboration and some part of it seems to have problems with the trunk version.

I hope this is the appropriate thread to post in. I am using ROOT 6.23.
I am fitting a series of points that span a large y-axis range (~1000 units) and a short x-axis range (~20 units). I’m fitting with a pol1 so the result should be a nearly vertical line.

If the x-errors on my TGraphErrors are set to zero, the fit is performed (but obviously my x-errors are not accounted). When I feed in non-zero x-errors, the fit fails.

Info for code below:
ll_edge[0][100] are x values obtained by doing gaussian fits on 100 cross sections of a vertical band of points on a TH2D. These cross sections are obtained by projecting onto the x-axis. The “edge” of the band is found by adding 2*sigma to the mean of these gaussians. These values vary between -1180 and -1160. But not necessarily in a linear fashion.
ll_pos[0][100] are the y values given by the middle of the range of y values for each cross section. position of the points in each cross section. These vary linearly from -495 to +495.
ll_err[0][100] are the x errors obtained by adding in quadrature the errors on the gaussian mean and sigma in each cross section. These range between ~0.5 and ~1.0.
noE[0][100] is an array of zeros for my y errors. (do I have to provide errors for these as well?)

Here is the relevant code (I think):
TGraphErrors *g_ll = new TGraphErrors(100,ll_edge[0],ll_pos[0],ll_err[0],noE[0]);
TF1 *ll_fit = new TF1(“ll_fit”, “[0]+[1]*x”, -1250,-1100);
g_ll->Fit(“ll_fit”,“RF”);

How does the fit fail? i.e., what is the output message?
Probably an expert can provide a better answer, but in any case maybe with the errors the ‘points’ become ‘too vertical’ since you have many ‘overlapping x-points’ now… what about avoiding this in the first place by swapping x and y? since you have a pol1 it would be very easy to invert the fit function.

Hi thank you for your response!
The fit output would say that it did not converge and the parameters returned were zeros.
But I tried your suggestion of switching the x and y axes in the graph and inverting the parameters and that worked perfectly.
Thanks!

Thank you!
I have done this and also the simple inversion suggested by dastudillo and it is working perfectly.
Thanks for your continuous support on this forum!