# TMinuit with constraint

**URL:** <https://root-forum.cern.ch/t/tminuit-with-constraint/60271>\
**Category:** ROOT\
**Tags:** root\
**Created:** [July 19, 2024, 9:12am UTC](https://root-forum.cern.ch/t/tminuit-with-constraint/60271 "2024-07-19T09:12:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bshi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/edb3f5/32.png) [@bshi](https://root-forum.cern.ch/u/bshi)\
**Post date:** [July 19, 2024, 9:12am UTC](https://root-forum.cern.ch/t/tminuit-with-constraint/60271/1 "2024-07-19T09:12:59Z")

</div>

Hi ROOTer,

I am trying to minimize my FCN using the TMinuit with parameters x1, x2, and x3. The x1, x2, and x3 themselves have no constraints, but x1 + x2 + x3 \> 0.

My question is: How to impose this constraint during the minimization? Should I manually set the FCN to infinity when x1 + x2 + x3 \< 0 is satisfied?

With the best respect,  
Boan

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [July 19, 2024, 11:25am UTC](https://root-forum.cern.ch/t/tminuit-with-constraint/60271/2 "2024-07-19T11:25:44Z")

</div>

Hi Boan,

I am adding in the loop our expert, @jonas .

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![bshi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/edb3f5/32.png) [@bshi](https://root-forum.cern.ch/u/bshi)\
**Post date:** [July 22, 2024, 5:49am UTC](https://root-forum.cern.ch/t/tminuit-with-constraint/60271/3 "2024-07-22T05:49:02Z")

</div>

Hi, all,

I have an idea for discussion. We can multiply an exponential term (e^{-(x1+x2+x3)}) or a fractional term (1/(x1+x2+x3)) on FCN, so that when x1+x2+x3 tend to zero, FCN becomes infinite. But I am concerned about uncertainty estimates in this case.

Do you have any other suggestions?

With the best respect,  
Boan

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [July 23, 2024, 7:27am UTC](https://root-forum.cern.ch/t/tminuit-with-constraint/60271/4 "2024-07-23T07:27:36Z")

</div>

See post by @Eddy_Offermann here: [Minimization subject to constrains with Tminuit, is it possible? [PyROOT] - #7 by Eddy\_Offermann](https://root-forum.cern.ch/t/minimization-subject-to-constrains-with-tminuit-is-it-possible-pyroot/48027/7)

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [July 24, 2024, 6:42am UTC](https://root-forum.cern.ch/t/tminuit-with-constraint/60271/5 "2024-07-24T06:42:36Z")

</div>

Hi Boan,

If possible, transform your parameters (x1,x2,x3) to (z1,z2,z3) where z1=x1+x2+x3 .  
TMinuit has implemented simple parameter ranges like z1 \> 0.

best regards, Eddy

---

<div class="post-metadata">

**Author:** ![bshi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/edb3f5/32.png) [@bshi](https://root-forum.cern.ch/u/bshi)\
**Post date:** [July 24, 2024, 7:43am UTC](https://root-forum.cern.ch/t/tminuit-with-constraint/60271/6 "2024-07-24T07:43:51Z")

</div>

Hi, all,

Thank you for your prompt response! I have to say that the situation is more complex than initially described, as I need to consider various constraints, including nonlinear combinations of parameters. However, the set of parameters should be retained due to their physical meaning.

I will begin by exploring the previous post. If there are more questions, I will continue to seek your guidance.

Thank you all again.

With the best respect,  
Boan

---

<div class="post-metadata">

**Author:** ![bshi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/edb3f5/32.png) [@bshi](https://root-forum.cern.ch/u/bshi)\
**Post date:** [July 27, 2024, 3:28am UTC](https://root-forum.cern.ch/t/tminuit-with-constraint/60271/7 "2024-07-27T03:28:54Z")

</div>

Hi, all,

I tried the same approach as previous post but still couldn’t solve the problem. Let me show you the situation I encountered.

I attempted to enforce the condition that `r20` must be greater than `0` in any case. The formula for `r20` is defined as `r20 = (-3 - cos(2 * theta_1) - 2 * pow(Pt, 2) * cos(2 * phi_1) * pow(sin(theta_1), 2) + 4 * (-1 + pow(Pt, 2) * cos(2 * phi_1)) * pow(sin(theta_1), 2) * (pow(x1, 2) - pow(x3, 2)))`, where `x1` and `x3` are fit parameters, and `phi_1` are angles for each event, with `Pt` being a constant.

I tried multiplying `exp(r20)` to the amplitude (Amp) to construct the FCN, which is defined as `Amp*exp(r20)(for PHSP MC sample)-ln(Amp)*exp(r20)(for data sample)`.

If this constraint is effective, the amplitude should not be negative. However, despite trying different initial values for x1 and x3, negative amplitudes were still observed in the PHSP MC or data sample during minimization.

I also attempted using `1/(r20)`, but this approach also proved unsuccessful.

Is there any other way to solve this issue?

With the best respect,  
Boan

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [July 27, 2024, 8:18am UTC](https://root-forum.cern.ch/t/tminuit-with-constraint/60271/8 "2024-07-27T08:18:00Z")

</div>

Hi Boan,

Multiplying your function with exp(-r20) would prevent negative r20 values but favor large positive r20 values. This is just not the way to implement constrains. You will have to find a transformation of variables.

-Eddy

---

<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:** [August 10, 2024, 8:18am UTC](https://root-forum.cern.ch/t/tminuit-with-constraint/60271/9 "2024-08-10T08:18:36Z")

</div>

Closed on August 10, 2024, 8:18am UTC

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