Incorrect drawing of fit from roofit

_ROOT Version: JupyROOT 6.24/06
_Platform: Linux Ubuntu 20.04
_Compiler: Python 3.9.7

While fitting cdf function, I come across incorrect drawing of the fit, the parameters however are correct (checked in Iminuit).
Creating Ttree:

t = ROOT.TTree("t", "Tree");
t.ReadFile("dane.csv", "Y/F:X/F");
g1 = ROOT.TGraph(t.GetSelectedRows(),t.GetV2(), t.GetV1())

Fitting looks like this:

%jsroot on
c2 = ROOT.TCanvas()

func = ROOT.TF1("func","ROOT::Math::lognormal_cdf(x,[0],[1])")

func.SetParNames ("m","s");

wynik = g1.Fit(func,"MES", "", 0, 10000)

As you can see the graph is just bad, but calculated parameters are fine.
The problem comes from the fact that fitting line has step of drawing 100, which results in creation of fitting line points 0, 100, 200 and so on, skipping everything that is in between.
It is for sure because of X axis has large range <0, 10000>.

The conclusion is that i don’t really know how to fix this. Changing parameters steps is useless because they are fine. I tried to search for answers reading most of documentation about fitting classes but haven’t found anything useful.

Ps. Quick fix of this is to fit 3 functions in different ranges like <0,20>, <20,1000>, <1000, 10000>, but besides being ugly, parameters are wrong.

(Can’t upload program and data because of “new user”)


Here you observe side effects of jsroot drawing, which is used by default in jupyter notebooks.
Because of log scale there are very few points in the left part of the X scale.
You can disable jsroot by typing:

%jsroot off

before drawing data.

1 Like

Thank you very much, after reading a lot of documentation on this topic I was sure it is gonna be some trivial problem but i just couldn’t figure out it myself.

The only problem now is still small reduced chi2. Do you also recognize maybe why it is so? Back then i thought it was because of inaccurate graph but now I’m not sure. On Iminuit with the same parameters it is 1.5, but here it is still the same 0.00015.

No idea, may be @moneta can help you - after holidays

1 Like


Here you are fitting a TGraph which is not having any errors. The shown chi2 in ROOT is the unweighted one, i.e. assuming a point error = 1. It is clear, given your data points an error=1 is too large.