# How to set conditions on fit parameters?

**URL:** <https://root-forum.cern.ch/t/how-to-set-conditions-on-fit-parameters/40137>\
**Category:** Newbie\
**Created:** [June 29, 2020, 2:44pm UTC](https://root-forum.cern.ch/t/how-to-set-conditions-on-fit-parameters/40137 "2020-06-29T14:44:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Va\_Findesiecle](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/va_findesiecle/32/20144_2.png) [@Va\_Findesiecle](https://root-forum.cern.ch/u/Va_Findesiecle)\
**Post date:** [June 29, 2020, 2:44pm UTC](https://root-forum.cern.ch/t/how-to-set-conditions-on-fit-parameters/40137/1 "2020-06-29T14:44:53Z")

</div>

I have the function that I use to fit:

```auto
Double_t fun(Double_t *x, Double_t *par) 
{
    Double_t z2 = x[0] * x[0] / par[0] / par[0] + x[1] * x[1] / par[1] / par[1];
    z2 *= par[2] * par[2];
    return -sqrt(z2) + par[3];
}
...
TF2 *f = new TF2("f", fun, -50, 50, -50, 50, npar);
...
hist>Fit("f", "Q");

```

I want the process to be carried out on the condition that the `par[0]/par[1]` relation is constant and equal, for example, 2. How to perform it?

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [June 29, 2020, 3:42pm UTC](https://root-forum.cern.ch/t/how-to-set-conditions-on-fit-parameters/40137/2 "2020-06-29T15:42:25Z")

</div>

Perhaps @StephanH can help

---

<div class="post-metadata">

**Author:** ![StephanH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@StephanH](https://root-forum.cern.ch/u/StephanH)\
**Post date:** [June 29, 2020, 4:26pm UTC](https://root-forum.cern.ch/t/how-to-set-conditions-on-fit-parameters/40137/3 "2020-06-29T16:26:34Z")

</div>

Multiply the current fit function with something like  
`Gauss(2 | par[0]/par[1], 0.1)`

For the fitter, this is something like:  
`par[0]/par[1]` should be equal to 2 within 10% uncertainty. You can obviously change the target value and the “strength” of this constraint as desired.  
Make sure, though, that `par[1]` doesn’t go to zero. Otherwise, it will blow up.

---

<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:** [June 29, 2020, 5:23pm UTC](https://root-forum.cern.ch/t/how-to-set-conditions-on-fit-parameters/40137/4 "2020-06-29T17:23:38Z")

</div>

Redefine your “`fun`” so that the new “`par[1]`” becomes the current “`par[0]/par[1]`” and then you can simply use: "`f->FixParameter(1, 2.);`
