# Plotting difference between pseudo-data and fit on the same plot

**URL:** <https://root-forum.cern.ch/t/plotting-difference-between-pseudo-data-and-fit-on-the-same-plot/40521>\
**Category:** Newbie\
**Created:** [July 20, 2020, 4:09am UTC](https://root-forum.cern.ch/t/plotting-difference-between-pseudo-data-and-fit-on-the-same-plot/40521 "2020-07-20T04:09:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [July 20, 2020, 4:09am UTC](https://root-forum.cern.ch/t/plotting-difference-between-pseudo-data-and-fit-on-the-same-plot/40521/1 "2020-07-20T04:09:59Z")

</div>

Hello,  
I am trying to plot the pseudo-data minus the fit for a 5-parameter function. I have done this before with actual data, but for some reason, this time I am not getting a graph that shows the difference on the same canvas. I get the following warnings:  
`Warning in <TPad::ResizePad>: Inf/NaN propagated to the pad. Check drawn objects.`  
`Warning in <TPad::ResizePad>: Comp_2 height changed from 0 to 10`  
I am very confused and any help would be greatly appreciated.  
[para\_five\_difference.cxx](https://root-forum.cern.ch/uploads/short-url/cgoy2MryQpQVMZRV3xVnqKezqkv.cxx) (2.5 KB)  
\_ROOT Version: 6.23/01

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [July 20, 2020, 11:27am UTC](https://root-forum.cern.ch/t/plotting-difference-between-pseudo-data-and-fit-on-the-same-plot/40521/2 "2020-07-20T11:27:49Z")

</div>

Hi  
at line 53 you do a fit

```auto
histo->Fit(parabola_5,"M","SAMES",2.e-1,1);

```

from line 61 on you set params again:

```auto
parabola_5->SetParameter(0,10);
parabola_5->SetParameter(1,2.6);

```

so your fitted params are lost  
Otto

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [July 20, 2020, 6:57pm UTC](https://root-forum.cern.ch/t/plotting-difference-between-pseudo-data-and-fit-on-the-same-plot/40521/3 "2020-07-20T18:57:54Z")

</div>

Thank you, it worked. Do you know how I could make it so that the axes are log-scaled?

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [July 21, 2020, 7:29am UTC](https://root-forum.cern.ch/t/plotting-difference-between-pseudo-data-and-fit-on-the-same-plot/40521/4 "2020-07-21T07:29:59Z")

</div>

```auto
gPad->SetLogy(1)

```

for details see:  
[https://root.cern/doc/master/classTPad.html#a148366f3d7b780d821b56e4ed35d47ea](https://root.cern/doc/master/classTPad.html#a148366f3d7b780d821b56e4ed35d47ea)  
Otto

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [July 21, 2020, 7:22pm UTC](https://root-forum.cern.ch/t/plotting-difference-between-pseudo-data-and-fit-on-the-same-plot/40521/5 "2020-07-21T19:22:12Z")

</div>

Thank you again. Sorry to bother you again, but when I try to divide by the Bin error (line 81), I get the same problem as before. [para\_five\_difference.cxx](https://root-forum.cern.ch/uploads/short-url/2iyyNhHDhARWBTEZeLsp1TZN6W7.cxx) (2.5 KB)

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [July 22, 2020, 7:41am UTC](https://root-forum.cern.ch/t/plotting-difference-between-pseudo-data-and-fit-on-the-same-plot/40521/6 "2020-07-22T07:41:09Z")

</div>

HI,  
your DiffHist (as it was before) represents the residuals  
(bin\_content - fitted\_value).  
Why do you divide the fitted\_value by the bin\_error?  
In this way you cannot expect something centered around 0  
Otto

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [July 22, 2020, 8:02am UTC](https://root-forum.cern.ch/t/plotting-difference-between-pseudo-data-and-fit-on-the-same-plot/40521/7 "2020-07-22T08:02:44Z")

</div>

in my last answer I overlooked one of your many “((((()))))”  
real problem is that the bin\_error can be 0 giving devide by 0 -\> NaN  
You must check for that.

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [July 22, 2020, 11:30pm UTC](https://root-forum.cern.ch/t/plotting-difference-between-pseudo-data-and-fit-on-the-same-plot/40521/8 "2020-07-22T23:30:32Z")

</div>

Thank you again! I just added an if statement in the for loop, and it seems to work.  
[para\_five\_difference.cxx](https://root-forum.cern.ch/uploads/short-url/tokJHhTv7T5ERPFZ9yTvn7uwOrZ.cxx) (2.5 KB)
