# Problem in fitting (in function!)

**URL:** <https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785>\
**Category:** ROOT\
**Created:** [April 9, 2020, 8:05am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785 "2020-04-09T08:05:03Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![Sandy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Sandy](https://root-forum.cern.ch/u/Sandy)\
**Post date:** [April 17, 2020, 8:06am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/67 "2020-04-17T08:06:26Z")

</div>

For that, First I have to install ROOT 6 and then paste the following in my bash file???

```auto
alias root-53436='source /opt/ROOT/releases/root_v5.34.36/bin/thisroot.sh'
alias root-60902='source /opt/ROOT/releases/root_v6.09.02/bin/thisroot.sh'
alias root-61004='source /opt/ROOT/releases/root_v6.10.04/bin/thisroot.sh'
alias root-old="root-53436"
alias root-pro="root-60902"
alias root-new="root-61004"
alias root-dev="root-61004"
alias root-5="root-old"
alias root-6="root-new"

```

What exactly I have to do?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 17, 2020, 8:10am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/68 "2020-04-17T08:10:17Z")

</div>

[google -\> bash aliases](https://www.google.com/search?q=bash+aliases)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 17, 2020, 8:34am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/69 "2020-04-17T08:34:34Z")

</div>

To be complete on the graphics side: one should be also careful that all the histograms you are superimposing on the same plot have exactly the same ranges in all directions. Here is the version of the macro doing that. [multi5.C](https://root-forum.cern.ch/uploads/short-url/lKuHQdsZ2CXilRvVRmYHNvJe9aD.C) (1.1 KB)

and the plot is:

 ![Screenshot 2020-04-17 at 10.31.21](https://root-forum.cern.ch/uploads/default/original/3X/3/0/3080af0cb95e6261584acfb664773599f0dbefeb.png)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 17, 2020, 8:44am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/70 "2020-04-17T08:44:55Z")

</div>

[75 -\> 52](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/64)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 17, 2020, 8:48am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/71 "2020-04-17T08:48:15Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> 75 → 52

[multi5.C](https://root-forum.cern.ch/uploads/short-url/bDTBNUifcPD7LbZY0mMFDc2svAV.C) (1.1 KB)

 ![Screenshot 2020-04-17 at 10.51.27](https://root-forum.cern.ch/uploads/default/original/3X/4/c/4c802fcb5b85a93a3845749955ec7186da5f4390.png)

---

<div class="post-metadata">

**Author:** ![Sandy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Sandy](https://root-forum.cern.ch/u/Sandy)\
**Post date:** [April 17, 2020, 9:52am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/72 "2020-04-17T09:52:57Z")

</div>

With data.txt I uploaded earlier, why with TGraph2DErrors I am not getting error bars drawn?  
Can I directly read with TGraph2DErrors from a file?

[er.cxx](https://root-forum.cern.ch/uploads/short-url/8zeBo4d2a8etbRAXI87BBXn5LKI.cxx) (2.4 KB)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 17, 2020, 10:38am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/73 "2020-04-17T10:38:46Z")

</div>

@couet There is a bug in the [TGraph2DErrors](https://root.cern/doc/master/classTGraph2DErrors.html) class. It uses the [TGraph2D::RemovePoint](https://root.cern/doc/master/classTGraph2D.html#a55361a9a408a78ea5a9799086e16c746) method while it should have its own implementation for this method which also removes the corresponding “point errors” … [JIRA -\> ROOT / ROOT-10695](https://sft.its.cern.ch/jira/browse/ROOT-10695)

@Sandy Sorry, due to the above bug, for the time being you must use “`#if 0`” for the part which removes points if “z” \<= “zmin”.

Here’s a modified version which does it properly in another way:

[fit.cxx](https://root-forum.cern.ch/uploads/short-url/zO85LEQYloOa1MVBDU9AmqSEu8l.cxx) (1.9 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 17, 2020, 12:11pm UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/74 "2020-04-17T12:11:30Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> @couet There is a bug in the [TGraph2DErrors](https://root.cern/doc/master/classTGraph2DErrors.html) class. It uses the [TGraph2D::RemovePoint](https://root.cern/doc/master/classTGraph2D.html#a55361a9a408a78ea5a9799086e16c746) method while it should have its own implementation for this method which also removes the corresponding “point errors”.

@Wile_E_Coyote: Can you make a Jira ticket with that ? I will look at it asap. I am on something else right now.

---

<div class="post-metadata">

**Author:** ![Sandy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Sandy](https://root-forum.cern.ch/u/Sandy)\
**Post date:** [April 18, 2020, 5:39am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/75 "2020-04-18T05:39:52Z")

</div>

Thanks. That’s nice.

---

<div class="post-metadata">

**Author:** ![Sandy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Sandy](https://root-forum.cern.ch/u/Sandy)\
**Post date:** [April 20, 2020, 7:07am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/76 "2020-04-20T07:07:10Z")

</div>

Dear @couet

What I am seeing that only 52, 53, and 55 are giving color transparency.

Anyway, I have a request:  
Since this QA series was more about plotting, could you please remove only the function part in my first post? As that functional form is under research, I do not want to disclose that. Thank you for your understanding.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 20, 2020, 7:44am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/77 "2020-04-20T07:44:29Z")

</div>

> [@Sandy](#):
>
> could you please remove only the function part in my first post

You should be allowed to remove/edit all your posts.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 20, 2020, 7:52am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/79 "2020-04-20T07:52:50Z")

</div>

So you want me to remove the data file and the code from your very first post ?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 20, 2020, 8:00am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/81 "2020-04-20T08:00:59Z")

</div>

> [@Sandy](#):
>
> Since this QA series was more about plotting, could you please remove only the function part in my first post? As that functional form is under research, I do not want to disclose that. Thank you for your understanding.

Done.

---

<div class="post-metadata">

**Author:** ![Sandy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Sandy](https://root-forum.cern.ch/u/Sandy)\
**Post date:** [April 20, 2020, 8:02am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/82 "2020-04-20T08:02:47Z")

</div>

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![Sandy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Sandy](https://root-forum.cern.ch/u/Sandy)\
**Post date:** [April 20, 2020, 2:15pm UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/85 "2020-04-20T14:15:54Z")

</div>

Dear @Wile_E_Coyote and @Couet,

 ![Test](https://root-forum.cern.ch/uploads/default/original/3X/b/d/bda66bfa47d0bc6c56145996b41ad08417483a93.png)

Should the peaks coming outside the fit range, be due to the (1) ill-defined fit parameters or (2) ill-defined functional form?

If the above two are correct, then is there a way to get rid of those unwanted peaks outside the fit-range?

I have tried changing the fit-range too, but, it it very difficult to remove those?

Is there any other trick to remove those?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 20, 2020, 4:06pm UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/86 "2020-04-20T16:06:23Z")

</div>

[Most probably your function diverges.](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/5)

---

<div class="post-metadata">

**Author:** ![Sandy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Sandy](https://root-forum.cern.ch/u/Sandy)\
**Post date:** [April 21, 2020, 9:04am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/87 "2020-04-21T09:04:28Z")

</div>

Ok, is there any way to get the integral under TGraph2DErrors?

{like what we do for histograms…myhist-\>Integral(); }

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 21, 2020, 9:07am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/88 "2020-04-21T09:07:00Z")

</div>

Maybe you should take the integral of your fitted function?

---

<div class="post-metadata">

**Author:** ![Sandy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@Sandy](https://root-forum.cern.ch/u/Sandy)\
**Post date:** [April 21, 2020, 9:35am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/89 "2020-04-21T09:35:57Z")

</div>

When the function is not uniquely defined…then…!!!

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 21, 2020, 9:41am UTC](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785/90 "2020-04-21T09:41:22Z")

</div>

You anyhow go through an “intermediate” histogram so maybe use its integral.

Otherwisse, you would need to create a [TF2](https://root.cern/doc/master/classTF2.html) from your 2D graph and integrate this new function.  
An example of a [TF1](https://root.cern/doc/master/classTF1.html) created from a 1D graph can be found in: “[Integral of TGraph](https://root-forum.cern.ch/t/integral-of-tgraph/4745)”

[Previous page](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785.md?page=3)

[Next page](https://root-forum.cern.ch/t/problem-in-fitting-in-function/38785.md?page=5)
