# Fitting in ROOT with a function having two integrals in it

**URL:** <https://root-forum.cern.ch/t/fitting-in-root-with-a-function-having-two-integrals-in-it/49588>\
**Category:** ROOT\
**Tags:** root\
**Created:** [April 14, 2022, 1:52pm UTC](https://root-forum.cern.ch/t/fitting-in-root-with-a-function-having-two-integrals-in-it/49588 "2022-04-14T13:52:46Z")\
**Posts on this page:** 1\
**Showing post:** 10

<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:** [April 26, 2022, 7:33am UTC](https://root-forum.cern.ch/t/fitting-in-root-with-a-function-having-two-integrals-in-it/49588/10 "2022-04-26T07:33:52Z")

</div>

Hi,  
I realised I have posted before a wrong version of the code, for defining the fitting function with the integral, here below is the correct one, which should not give the segmentation violation.  
However the functions mathematical definitions look to me not correct, for example they diverge and this certainly explains why the integral does not work. You should check that you have implemented the various functions correctly.  
For example : `TF2 *part = new TF2("deno","exp([1]*pow(y,2)+[2]*pow(y,3))" );` is a 1D or a 2D function ?  
You compute an integral up to + infinity but it diverges.  
Then are you sure you want to use TMath::Factorial(x)) ? Is x an integer or a real value ? If it is a real you should use TMath::Gamma(x+1).

Cheers

Lorenzo

[TestFitFunction.C](https://root-forum.cern.ch/uploads/short-url/aQNBDEUkxg6NxOOTRdllmnS6fHv.C) (1.2 KB)

---

_[View the full topic](https://root-forum.cern.ch/t/fitting-in-root-with-a-function-having-two-integrals-in-it/49588)._
