Drawing a function with the parameters of another function

Hi,

I want to draw a function obtained out of a fitting. For that, I’m fitting first the function within a range and then I get the parameters. After, I am defining a new function with the same parameter values from the previous one but I want to draw it in an extended range. I get some error concerning the FixParameter, and, I cannot see the extended function in my histogram. Here is the code that I’m trying to fix:

TF1 *powvar=new TF1("powvar","[0]+[1]*x^2",27,50); powvar->SetParName(0,"c0"); powvar->SetParName(1,"c1"); powvar->SetParameter(0, 1); powvar->SetParameter(1, 0); powvar->SetLineColor(2); powvar->SetLineWidth(2); ADC8->Fit("powvar","R"); Double_t param[2]; powvar->GetParameters(param); TF1 *powvarfull=new TF1("powvarfull","[0]+[1]*x^2",0,75); powvarfull->SetParameters(param); powvarfull->FixParameter(0,&param[0]); powvarfull->FixParameter(1,&param[1]); powvarfull->SetLineColor(3); powvarfull->SetLineWidth(2); ADC8->Fit("powvarfull","RB+");

Does someone has some clue about how to solve it?

Thanks in advance,

psc

Hi,

Your code is not correct. You should not do :

powvarfull->FixParameter(0,&param[0]);
powvarfull->FixParameter(1,&param[1]);

but

powvarfull->FixParameter(0,param[0]);
powvarfull->FixParameter(1,param[1]);

Then I do not understand why you fix the all parameters of the function and then used it for fitting. You cannot fit using a function which has not free parameters

Best Regards
Lorenzo

Hi Lorenzo,

Now it works, thank you very much.

The point to fit with the fix parameters if to see how the fitted function looks like outside the fitting range.

Thanks again,

psc

Hi,
Tes, I understand this, but you don’t need to fit, but just call TF1::Draw after setting a different range using TF1::SetRange

Lorenzo