# Fixing the value of the sum of multiple parameters

**URL:** <https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484>\
**Category:** Newbie\
**Created:** [September 17, 2020, 3:15am UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484 "2020-09-17T03:15:00Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [September 17, 2020, 3:15am UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/1 "2020-09-17T03:15:00Z")

</div>

Hi,  
I was wondering if there is a way to fix parameter limits on the sum of multiple parameters. Something like:  
`g->FixPar(1+2+3,1)`  
where 1,2,3 are fitting parameters and 1 is the value to fix the sum to. Is this in any way possible? I am trying to implement a constraint, which is why this would be useful.

\_ROOT Version: 6.23/01  
_Platform:_ MacBook Pro  
_Compiler:_ Not Provided

* * *

---

<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:** [September 17, 2020, 2:57pm UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/2 "2020-09-17T14:57:04Z")

</div>

Perhaps @moneta can help?

---

<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:** [September 17, 2020, 4:43pm UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/3 "2020-09-17T16:43:08Z")

</div>

Hi,

This is currently not possible. There is not yet support for constraints which consists of function of parameters, instead only simple parameter bounds are supported.  
In some simple cases as above, can be re-formulated by some parameter transformation .  
For example defining `q1 = p1; q2 = p2; q3 = p1+p2+p3; `

Lorenzo

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [September 17, 2020, 4:44pm UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/4 "2020-09-17T16:44:52Z")

</div>

Ah ok, I think this would work, thank you moneta!

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [September 20, 2020, 4:04am UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/5 "2020-09-20T04:04:04Z")

</div>

Hello again,  
It makes sense when you explain it, but I have trouble implementing it. Do you know how I could implement the following?  
 ![Screen Shot 2020-09-20 at 12.00.43 AM](https://root-forum.cern.ch/uploads/default/original/3X/8/d/8df69c6bf2a8128a3a49843d35fcf2cebaf9ccc5.png)  
where  
 ![Screen Shot 2020-09-20 at 12.00.49 AM](https://root-forum.cern.ch/uploads/default/original/3X/8/c/8c4715eba14d14507f5242af3b9a9ecf79cb8801.png) .  
Like how would I code the above equation as a TF1 pointer? Can you help?  
The function is a function of only beta, and it has three parameters, p\_1, theta, and p\_2.

---

<div class="post-metadata">

**Author:** ![smgrig](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/smgrig/32/19464_2.png) [@smgrig](https://root-forum.cern.ch/u/smgrig)\
**Post date:** [September 20, 2020, 8:40am UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/6 "2020-09-20T08:40:54Z")

</div>

Hello,  
try p1\*[…]+(p2-p1)/4  
0\<=p2\<=1

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [September 20, 2020, 6:35pm UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/7 "2020-09-20T18:35:41Z")

</div>

Why would this work, it is not the same function, and there is no limit on p\_1?

---

<div class="post-metadata">

**Author:** ![smgrig](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/smgrig/32/19464_2.png) [@smgrig](https://root-forum.cern.ch/u/smgrig)\
**Post date:** [September 20, 2020, 8:05pm UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/8 "2020-09-20T20:05:52Z")

</div>

Sorry, you are right!

---

<div class="post-metadata">

**Author:** ![smgrig](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/smgrig/32/19464_2.png) [@smgrig](https://root-forum.cern.ch/u/smgrig)\
**Post date:** [September 21, 2020, 9:33am UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/9 "2020-09-21T09:33:12Z")

</div>

Hello,  
define your fit function for 0 \<= p[1],p[2] \<= 1 like this

```auto
double Pvv (double *x, double *p) {
  double A=cos(p[0])*cos(p[0]);
  double B=cos(x[0])*cos(x[0]);
  double a=p[1];
  if (a>1-p[2]) a=1-p[2];
  return a*A*B+p[2]/4;
}

```

---

<div class="post-metadata">

**Author:** ![Edward\_Finkelstein](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edward_finkelstein/32/20070_2.png) [@Edward\_Finkelstein](https://root-forum.cern.ch/u/Edward_Finkelstein)\
**Post date:** [September 21, 2020, 5:00pm UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/10 "2020-09-21T17:00:45Z")

</div>

To some extent this works, but I still get

```auto
p[1]+p[2]>1

```

when I do the fit. I try to restrict the parameters, and then the above works, but I do not think it is ideal, since the only restriction should be that their sum is \<=1.

Thank you for the answer though, I learned something new today from your post!

---

<div class="post-metadata">

**Author:** ![smgrig](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/smgrig/32/19464_2.png) [@smgrig](https://root-forum.cern.ch/u/smgrig)\
**Post date:** [September 21, 2020, 5:22pm UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/11 "2020-09-21T17:22:31Z")

</div>

Maybe ROOT experts can suggest a better solution…

---

<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:** [September 21, 2020, 5:48pm UTC](https://root-forum.cern.ch/t/fixing-the-value-of-the-sum-of-multiple-parameters/41484/12 "2020-09-21T17:48:36Z")

</div>

Unfortunately, as I said before, we don’t have yet the support for constraint minimisation, the only thing you can do is to set 0\<= p1 \<= 1 and 0 \<= p2 \<=1 and if the function minimum has p1+p2 \<= 1 then it is fine.

Lorenzo
