# Problem with changing function parameters

**URL:** <https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629>\
**Category:** Newbie\
**Created:** [May 29, 2025, 2:57pm UTC](https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629 "2025-05-29T14:57:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![gapp](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gapp/32/39007_2.png) [@gapp](https://root-forum.cern.ch/u/gapp)\
**Post date:** [May 29, 2025, 2:57pm UTC](https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629/1 "2025-05-29T14:57:29Z")

</div>

Hello.

I’ve been studying the Langaus distribution for calibration purposes, and at some point in my code I’m searching for fit function maximum and compare it to initial distribution maximum. Here’s the code for this:

```auto
for (s=0; s<250; s++){
            double truepar[4];
            truepar[0] = r0.Gaus(200, er1); truepar[1] = r0.Gaus(1000, er2); truepar[2] = fit1->GetParameter(2); truepar[3] = r0.Gaus(400, er3);
            char FunName[100];
            sprintf(FunName, "Fitfcn_%s", h0->GetName());
            TF1 *func = new TF1(FunName, langaufun, fr[0], fr[1], 4);
            func->SetParameters(truepar);
            double max1 = func->GetMaximumX();
            histmax->Fill(max1);
        }

```

I’m trying to initialize Langaus functions here with parameters varying around the “real” ones, then get their maximums and put them into a histogram, so I can use its standard deviation as maximum error. But suddenly it stopped working, as for some reason each function in cycle has the exact same maximum and the histogram’s stddev is 0.

I’d appreciate any help.

\_ROOT Version:\_6.34.02  
_Platform:_ Ubuntu on VM  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 29, 2025, 4:55pm UTC](https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629/2 "2025-05-29T16:55:31Z")

</div>

Hi,

> [@gapp](#):
>
> each function in cycle has the exact same maximum

which one is it? What is the value of `max1` you keep getting over and over again?

Also, can you make sure that the parameters are actually set? To do this, you could query the parameters before and after your

```auto
func->SetParameters(truepar);

```

line? By doing this you will also ensure that you are setting the correct parameters.

---

<div class="post-metadata">

**Author:** ![gapp](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gapp/32/39007_2.png) [@gapp](https://root-forum.cern.ch/u/gapp)\
**Post date:** [May 29, 2025, 4:59pm UTC](https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629/3 "2025-05-29T16:59:57Z")

</div>

> [@yus](#):
>
> which one is it? What is the value of `max1` you keep getting over and over again?

The function I’m referring to is func, and max1 is its maximum.

I haven’t considered checking that the parameters are set, thank you for advice. I’ll try it.

---

<div class="post-metadata">

**Author:** ![gapp](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gapp/32/39007_2.png) [@gapp](https://root-forum.cern.ch/u/gapp)\
**Post date:** [May 29, 2025, 5:06pm UTC](https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629/4 "2025-05-29T17:06:08Z")

</div>

I’ve checked and turns out they aren’t set actually… But I don’t quite understand what I’m doing wrong here.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 29, 2025, 5:19pm UTC](https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629/5 "2025-05-29T17:19:52Z")

</div>

> [@gapp](#):
>
> they aren’t set actually

How did you check that exactly?

I also noticed the `FunName` differs only because of `h0` name. What is `h0`? Does its name change inside the loop?

---

<div class="post-metadata">

**Author:** ![gapp](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gapp/32/39007_2.png) [@gapp](https://root-forum.cern.ch/u/gapp)\
**Post date:** [May 29, 2025, 5:26pm UTC](https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629/6 "2025-05-29T17:26:17Z")

</div>

I’m sorry, the parameters are set, they all equal zero before SetParameters line and obtain different non-zero values after the line. I was just a bit unattentive.

> [@yus](#):
>
> What is `h0`? Does its name change inside the loop?

It’s the initial Langaus distribution histogram that I generate randomly. It’s name doesn’t change, the only values that are changed are the ones of `truepar`.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 29, 2025, 5:46pm UTC](https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629/7 "2025-05-29T17:46:43Z")

</div>

Ok, I think I got it. The `TF1::GetMaximumX` gives you the X corresponding to the max Y. The search for this X only happens between `fr[0]` and `fr[1]`. So if your `langaufun` increases in this range for each set of your `truepar` values, then the Y-maximum will always be at `fr[1]`. It will most likely be different for different sets of `truepar` values, but the important thing it’s always at the right edge of the range, and `max1` will always equal `fr[1]`. Is that what you observe?

---

<div class="post-metadata">

**Author:** ![gapp](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gapp/32/39007_2.png) [@gapp](https://root-forum.cern.ch/u/gapp)\
**Post date:** [May 29, 2025, 5:55pm UTC](https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629/8 "2025-05-29T17:55:36Z")

</div>

It’s not quite the case, because the Langaus distribution function has maximum between the range edges I’ve set.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 29, 2025, 5:57pm UTC](https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629/9 "2025-05-29T17:57:41Z")

</div>

In that case, can you visualize your function? Please post a screenshot here and write the `max1` value you get for this case.

---

<div class="post-metadata">

**Author:** ![gapp](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gapp/32/39007_2.png) [@gapp](https://root-forum.cern.ch/u/gapp)\
**Post date:** [May 29, 2025, 6:34pm UTC](https://root-forum.cern.ch/t/problem-with-changing-function-parameters/63629/10 "2025-05-29T18:34:52Z")

</div>

Thank you, but that’s not needed anymore. I actually set the wrong range and didn’t notice. Thanks for pushing me in the direction of the right solution!
