# How to use TF1::SetParLimits on a function of two parameters?

**URL:** <https://root-forum.cern.ch/t/how-to-use-tf1-setparlimits-on-a-function-of-two-parameters/55537>\
**Category:** ROOT\
**Tags:** roofit, python, hist, root\
**Created:** [July 4, 2023, 9:13am UTC](https://root-forum.cern.ch/t/how-to-use-tf1-setparlimits-on-a-function-of-two-parameters/55537 "2023-07-04T09:13:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SAYAN\_CHATTERJEE](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sayan_chatterjee/32/21843_2.png) [@SAYAN\_CHATTERJEE](https://root-forum.cern.ch/u/SAYAN_CHATTERJEE)\
**Post date:** [July 4, 2023, 9:13am UTC](https://root-forum.cern.ch/t/how-to-use-tf1-setparlimits-on-a-function-of-two-parameters/55537/1 "2023-07-04T09:13:37Z")

</div>

Dear Experts,

I want to fit a 1D histogram using a one-dimensional generalized Gaussian function. This generalized Gaussian function has three parameters (excluding the normalization constant). I explained this below in detail.

* * *

Double\_t generalised\_1Dgauss(double \*x, double \*par)  
{  
return (par[0]/(2.\*par[1]\*tgamma(1./par[0])))\*TMath::Exp(-pow((abs(x[0]-par[2])/par[1]),par[0]));  
}

Double\_t SigmaWidth\_generalised\_1Dgauss(TF1\* f1)  
{  
return std::sqrt((pow(f1-\>GetParameter(1),2)\*tgamma(3/f1-\>GetParameter(0)))/tgamma(1/f1-\>GetParameter(0)));  
}

* * *

TH1D \* hist\_1D; **(Already filled with the data points)**  
**double** xmin = -4.0;  
**double** xmax = 4.0;

TF1\* GenGauss = new TF1(“GenGauss”, generalised\_1Dgauss, xmin, xmax, 3);

**Now Set the parameters:**  
GenGauss-\>SetParameters(value0, value1, value2);

**Now Set the parameter Limits:**  
GenGauss-\>SetParLimits(0, value0\_min, value0\_max);  
GenGauss-\>SetParLimits(1, value1\_min, value1\_max);  
GenGauss-\>SetParLimits(2, value2\_min, value2\_max);

**double** width\_gengauss = SigmaWidth\_generalised\_1Dgauss(GenGauss);

**Here I also want to use SetParLimits on “width\_gengauss”, which is a function of par[0] and par[1].**

_**GenGauss-\>SetParLimits(width\_gengauss, width\_min, width\_max);**_  
**[I know it is not the correct procedure, but I need a similar one.]**

**Now, I would proceed with fitting.**

hist\_1D-\>Fit(GenGauss, “SER”);  
hist\_1D-\>Fit(GenGauss, “SER”);  
hist\_1D-\>Fit(GenGauss, “SER”);

* * *

Could you please suggest how I can apply “SetParLimits” on the new parameter “_ **width\_gengauss** _” for the fitting? If you suggest another way to set limits on “_ **width\_gengauss** _,” it will also be fine.

I am looking forward to hearing from you.

Thanks & Regards,  
Sayan

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [July 4, 2023, 9:30am UTC](https://root-forum.cern.ch/t/how-to-use-tf1-setparlimits-on-a-function-of-two-parameters/55537/2 "2023-07-04T09:30:34Z")

</div>

Hi @SAYAN_CHATTERJEE; maybe @couet can help here.

Cheers.  
J.

---

<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:** [July 4, 2023, 9:49am UTC](https://root-forum.cern.ch/t/how-to-use-tf1-setparlimits-on-a-function-of-two-parameters/55537/3 "2023-07-04T09:49:35Z")

</div>

The expert in that area in @moneta

---

<div class="post-metadata">

**Author:** ![SAYAN\_CHATTERJEE](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sayan_chatterjee/32/21843_2.png) [@SAYAN\_CHATTERJEE](https://root-forum.cern.ch/u/SAYAN_CHATTERJEE)\
**Post date:** [July 4, 2023, 11:44am UTC](https://root-forum.cern.ch/t/how-to-use-tf1-setparlimits-on-a-function-of-two-parameters/55537/4 "2023-07-04T11:44:06Z")

</div>

Dear @moneta,

Could you please help? It is very important for me!

Thanks & Regards,  
Sayan

---

<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:** [July 4, 2023, 5:17pm UTC](https://root-forum.cern.ch/t/how-to-use-tf1-setparlimits-on-a-function-of-two-parameters/55537/5 "2023-07-04T17:17:02Z")

</div>

Hi,  
Unfortunately for fitting you can set up only trivial parameter limits, you cannot setup a constraint as a function of parameters. It is something much more complicated and we are working on this.  
The only possibility and re-parametrize (if possible) your function such as a new parameter is the one you want to constraint.  
If not possible you can try adding a barrier in the minimization function (e.g. chi2) such that the minimization function becomes very large in the not-allowed region

Lorenzo

---

<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 18, 2023, 5:17pm UTC](https://root-forum.cern.ch/t/how-to-use-tf1-setparlimits-on-a-function-of-two-parameters/55537/6 "2023-07-18T17:17:49Z")

</div>

Closed on July 18, 2023, 5:17pm UTC

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