Problem with changing function parameters

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:

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


Hi,

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

func->SetParameters(truepar);

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

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.

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

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?

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.

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.

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?

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

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

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!