# Incorrect drawing of fit from roofit

**URL:** <https://root-forum.cern.ch/t/incorrect-drawing-of-fit-from-roofit/48216>\
**Category:** Newbie\
**Tags:** graphics, roofit, python, jupyter\
**Created:** [December 29, 2021, 3:57pm UTC](https://root-forum.cern.ch/t/incorrect-drawing-of-fit-from-roofit/48216 "2021-12-29T15:57:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryzol](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/49beb7/32.png) [@Bryzol](https://root-forum.cern.ch/u/Bryzol)\
**Post date:** [December 29, 2021, 3:57pm UTC](https://root-forum.cern.ch/t/incorrect-drawing-of-fit-from-roofit/48216/1 "2021-12-29T15:57:44Z")

</div>

* * *

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

* * *

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

```auto
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:

```auto
%jsroot on
c2 = ROOT.TCanvas()

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

func.SetParLimits(0,0,10)
func.SetParLimits(1,0,10)
func.SetParNames ("m","s");

wynik = g1.Fit(func,"MES", "", 0, 10000)
g1.Draw()
c2.SetLogx()
ROOT.gStyle.SetOptFit();
c2.Draw()

```

![image](https://root-forum.cern.ch/uploads/default/original/3X/0/6/064e9041ad1961048d427ba26e2bbe984059490a.png)  
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”)

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [December 29, 2021, 6:14pm UTC](https://root-forum.cern.ch/t/incorrect-drawing-of-fit-from-roofit/48216/2 "2021-12-29T18:14:25Z")

</div>

Hi,

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:

```auto
%jsroot off

```

before drawing data.

---

<div class="post-metadata">

**Author:** ![Bryzol](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/49beb7/32.png) [@Bryzol](https://root-forum.cern.ch/u/Bryzol)\
**Post date:** [December 29, 2021, 6:45pm UTC](https://root-forum.cern.ch/t/incorrect-drawing-of-fit-from-roofit/48216/3 "2021-12-29T18:45:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [December 29, 2021, 6:58pm UTC](https://root-forum.cern.ch/t/incorrect-drawing-of-fit-from-roofit/48216/4 "2021-12-29T18:58:26Z")

</div>

> [@Bryzol](#):
>
> The only problem now is still small reduced chi2

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

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [January 5, 2022, 3:52pm UTC](https://root-forum.cern.ch/t/incorrect-drawing-of-fit-from-roofit/48216/5 "2022-01-05T15:52:28Z")

</div>

Hi,

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.

Lorenzo
