# Fitting problem with TGraph and TF1

**URL:** <https://root-forum.cern.ch/t/fitting-problem-with-tgraph-and-tf1/59444>\
**Category:** Newbie\
**Created:** [May 24, 2024, 11:29am UTC](https://root-forum.cern.ch/t/fitting-problem-with-tgraph-and-tf1/59444 "2024-05-24T11:29:19Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [June 5, 2024, 11:11am UTC](https://root-forum.cern.ch/t/fitting-problem-with-tgraph-and-tf1/59444/22 "2024-06-05T11:11:09Z")

</div>

Thanks.  
The data is from [https://physics.nist.gov/PhysRefData/Star/Text/ASTAR.html](https://physics.nist.gov/PhysRefData/Star/Text/ASTAR.html).

[Si\_astar.txt](https://root-forum.cern.ch/uploads/short-url/22oafhdVAyLCit8g5zEOLnAqbZh.txt) (9.3 KB)

 ![Screenshot 2024-06-05 at 14.12.59](https://root-forum.cern.ch/uploads/default/original/3X/9/d/9d44d5e4a0a3c7729ba029f29e96552208430885.png)

First column of this data is T\_alpha and the 4th column is STP\_alpha. Anyways, the kinetic energy starts from 1.e-3 MeV. However, my code tells me the term in parenthesis in the equation goes minus values after 0.316MeV. That means the STP\_alpha also becomes negative which shows the energy limit.

Why do you think they put the data starting from 1.e-3 MeV? Do you think their formula is different?

Total STP fit:

 ![Screenshot 2024-06-05 at 14.09.32](https://root-forum.cern.ch/uploads/default/original/3X/4/0/40f9db6229a17ce86fd7c77099dcf796f7b27b49.png)

Electronic STP fit:

 ![Screenshot 2024-06-05 at 14.45.56](https://root-forum.cern.ch/uploads/default/original/3X/1/1/11572cd148c7f6cfd1d2b3595e53a17e07fcbd55.png)

I haven’t checked why my function is not fitted right on top!? Is it because the function I use is not representing the true data?

I can guess that I only added STP due to ionization and excitation (this is part of electronic STP), not the TOTAL STP. However, their data on the 4th column shows total STP. The fit only works when I set the minimum kinetic energy, like I said, to 0.316MeV.

---

<div class="post-metadata">

**Author:** ![Dilicus](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dilicus/32/14338_2.png) [@Dilicus](https://root-forum.cern.ch/u/Dilicus)\
**Post date:** [June 6, 2024, 10:24am UTC](https://root-forum.cern.ch/t/fitting-problem-with-tgraph-and-tf1/59444/23 "2024-06-06T10:24:15Z")

</div>

Hi,  
as I already told you t

> [@Dilicus](#):
>
> the range of application of the Bethe Bloch goes from \beta\gamma\sim0.05 to  
> \beta\gamma\sim80.

So for proton it means your formula is valid from T\_{min}\sim 1 MeV and for \alphaT\_{min}\sim 4.5 MeV , while for your maximum range the behte bloch without the \delta correction works just fine. ( [PDG consider Bethe-Bloch valid only down to 0.1 \beta\gamma\sim0.1 )](https://pdg.lbl.gov/2024/reviews/rpp2024-rev-passage-particles-matter.pdf)

Moreover on the NIST site where you took the data, [here](https://physics.nist.gov/PhysRefData/Star/Text/programs.html) in section 3.5 you can find how they evaluate the data. And how they use Bethe Bloch only down to 0.5 MeV for proton and 2 MeV for \alpha.

In section 3.5.2 they describe from where tehy took the formulas for proton and \alpha stopping power. The [Andersen and Ziegler](https://api.pageplace.de/preview/DT0400.9781483100968_A23879038/preview-9781483100968_A23879038.pdf) reference describes an empirical formula for the stopping power of low energy particles (this is valid for proton, but I think should works also for \alpha),where the Bethe Bloch fails.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [June 24, 2024, 1:39pm UTC](https://root-forum.cern.ch/t/fitting-problem-with-tgraph-and-tf1/59444/24 "2024-06-24T13:39:57Z")

</div>

![Screenshot 2024-06-24 at 16.32.29](https://root-forum.cern.ch/uploads/default/original/3X/c/b/cb3e544b36f23c8450e6f0f4c7e383cf34ef4011.png)

@Dilicus

Is it OK to make the fit better by introducing a coefficient into the function which we think it is not working for all energy regime? For instance, we know if we use f(x-2) instead of f(x) that we can shift the function to the right. In the case of f(x+2), we make a shift to the left. We can even make it f(x/2) or f(2\*x) to shift up or down.

I mean, instead of trying to find a better formula, can we do this with little touch! Maybe, I should ask how people end up finding the correction parameters, how do they decide what to do?

For instance, no matter what range I tried, this is the best fit I got. That only means the formula is not valid in all energies.

---

<div class="post-metadata">

**Author:** ![Dilicus](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dilicus/32/14338_2.png) [@Dilicus](https://root-forum.cern.ch/u/Dilicus)\
**Post date:** [June 25, 2024, 7:57am UTC](https://root-forum.cern.ch/t/fitting-problem-with-tgraph-and-tf1/59444/25 "2024-06-25T07:57:53Z")

</div>

Shifting the function doesn’t solve your problem, not even shift up or down (to shift up or down a fucntion you have to multiply k\times f(x), multiply the function argument rescale the x axis)

To have a better fit I see only 2 options

- Reduce your fitting range, where the BB works
- Define a piece wise function according to the energy range.

---

<div class="post-metadata">

**Author:** ![spyhunter01](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spyhunter01/32/23019_2.png) [@spyhunter01](https://root-forum.cern.ch/u/spyhunter01)\
**Post date:** [June 25, 2024, 8:10am UTC](https://root-forum.cern.ch/t/fitting-problem-with-tgraph-and-tf1/59444/26 "2024-06-25T08:10:53Z")

</div>

Thanks. Just reading the pdfs you sent earlier now.

[Previous page](https://root-forum.cern.ch/t/fitting-problem-with-tgraph-and-tf1/59444.md?page=1)
