# Usage of TMath in Pyroot

**URL:** <https://root-forum.cern.ch/t/usage-of-tmath-in-pyroot/29367>\
**Category:** ROOT\
**Tags:** python, math\
**Created:** [June 14, 2018, 2:02pm UTC](https://root-forum.cern.ch/t/usage-of-tmath-in-pyroot/29367 "2018-06-14T14:02:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iMi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/919ad9/32.png) [@iMi](https://root-forum.cern.ch/u/iMi)\
**Post date:** [June 14, 2018, 2:02pm UTC](https://root-forum.cern.ch/t/usage-of-tmath-in-pyroot/29367/1 "2018-06-14T14:02:40Z")

</div>

\_ROOT Version: 6.12  
\_Platform: centos 7  
\_Compiler: g++ --version 4.8.5

Hello, I am looking for a translation of some cpp code :

double b\_I0(double k, double L\_n, double r){  
return TMath::BesselI0(2_k_r/L\_n);  
}

to pyroot code.

I want to use short methods as b\_I0 to keep the code easy to understand, short and easy to alter.

Thanks for your answers!

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [June 15, 2018, 3:28pm UTC](https://root-forum.cern.ch/t/usage-of-tmath-in-pyroot/29367/2 "2018-06-15T15:28:37Z")

</div>

Hi @iMi,

Do you have any particular issue with translating this code?

Please propose a Python implementation and I will be happy to point out if there is any issue.

Cheers,

Enric

---

<div class="post-metadata">

**Author:** ![iMi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/919ad9/32.png) [@iMi](https://root-forum.cern.ch/u/iMi)\
**Post date:** [June 15, 2018, 4:15pm UTC](https://root-forum.cern.ch/t/usage-of-tmath-in-pyroot/29367/3 "2018-06-15T16:15:58Z")

</div>

Hi @etejedor,

yes I do have a very simple one:

def b\_I0(k, L\_n, r):  
return TMath::BesselI0(2_k_r/L\_n)

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [June 18, 2018, 7:39am UTC](https://root-forum.cern.ch/t/usage-of-tmath-in-pyroot/29367/4 "2018-06-18T07:39:35Z")

</div>

Hi @iMi,  
That should work, besides the `TMath::Bessel` part which should be `TMath.Bessel` in Python, plus a previous `from ROOT import TMath`  
Cheers,  
Enric

---

<div class="post-metadata">

**Author:** ![iMi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/919ad9/32.png) [@iMi](https://root-forum.cern.ch/u/iMi)\
**Post date:** [June 19, 2018, 9:49pm UTC](https://root-forum.cern.ch/t/usage-of-tmath-in-pyroot/29367/5 "2018-06-19T21:49:01Z")

</div>

Hi @etejedor,

this worked. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [July 3, 2018, 9:51pm UTC](https://root-forum.cern.ch/t/usage-of-tmath-in-pyroot/29367/6 "2018-07-03T21:51:00Z")

</div>

Closed on July 3, 2018, 9:51pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
