Setting some Fit parameters

Hi,

I’m fitting a distribution with a function (pol2+gaus+pol2). I want to fix the width of the gaussian (width=0.006), but I can’t. I took a look in several examples, but none works for me. I’ve tryied g2->SetParameter(3,0.006), g2->FixParameter(3,0.006) and also total->SetParameter(5,0.006) and other combinations. Here is what I’m trying:

Double_t par[9]; g1 = new TF1("m1","pol2",1.523,1.631); g2 = new TF1("m2","gaus",1.637,1.661); //g2->SetParameter(3,0.006) g3 = new TF1("m3","pol2",1.667,1.775); total = new TF1("mctotal","pol2(0)+gaus(3)+pol2(6)",1.523,1.775); total->SetLineColor(4); gr1->Fit(g1,"R"); gr1->Fit(g2,"R+"); gr1->Fit(g3,"R+"); g1->GetParameters(&par[0]); g2->GetParameters(&par[3]); g3->GetParameters(&par[6]); total->SetParameters(par); total->SetParNames ("PL1","PL2","PL3","Counts","Mean","Width","PL1","PL2","PL3"); gr1->Fit(total,"R+"); g2->SetParameter(5,0.006); gr1->Fit(total,"","",1.523,1.775);

Does anyone knows how can a fix a specific parameter? Or two parameters?
Thanks

I’m running ROOT 4.00/08 in a Linux RH9.

Hi,
use TF1::FixParameter(int param, double value), and don’t forget to call TH1::Fit with option “B” (see root.cern.ch/root/html/TH1#TH1:Fit).
Axel.

Hi Axel,

Thank you for your fast replay. My problem is should I put g2->FixParameter(3,0.006) or total->FixParameter(5,0.006)? And is not clear to me how to use the “B” option. When I add this to:

gr1->Fit(total,“B”,"",1.523,1.775);

the parameter value is completly different.
Thanks.
Sergio

Hi,

[quote=“anefalos”]My problem is should I put g2->FixParameter(3,0.006) or total->FixParameter(5,0.006)? [/quote]Both. total doesn’t “inherit” anything from g1-3; total is just a fomula that has the same components (algorithmically) as g1-3, but no parameter values will be exchanged between the two. So you gotta fix it for both g1-3 and total.

[quote=“anefalos”]And is not clear to me how to use the “B” option. When I add this to:

gr1->Fit(total,“B”,"",1.523,1.775);

the parameter value is completly different.[/quote]You should doDouble_t par[9]; g1 = new TF1("m1","pol2",1.523,1.631); g2 = new TF1("m2","gaus",1.637,1.661); // you had index 3 - you probably mean 2, right? This is C++, we count from 0 :-) g2->FixParameter(2,0.006); g3 = new TF1("m3","pol2",1.667,1.775); total = new TF1("mctotal","pol2(0)+gaus(3)+pol2(6)",1.523,1.775); total->SetLineColor(4); gr1->Fit(g1,"R"); gr1->Fit(g2,"BR+"); gr1->Fit(g3,"R+"); g1->GetParameters(&par[0]); g2->GetParameters(&par[3]); g3->GetParameters(&par[6]); total->SetParameters(par); // the other params are initialized by their "solo" fits, this one is fixed total->FixParameter(3+2,0.006); total->SetParNames ("PL1","PL2","PL3","Counts","Mean","Width","PL1","PL2","PL3"); gr1->Fit(total,"BR+");If that doesn’t work we need Rene to find the problem :slight_smile:

Cheers, Axel.

Hi Axel,

I don’t think it is working. When I run ROOT with the modifications, the gaussian peak disappears. I can see only the two pol2. And when I look to the 9 parameters on the screen, the third gaussian parameter is 0.006, but the other two are zero. When I add the last line

gr1->Fit(total,"BR+","",1.523,1.775);

I can see the final result. It is a polynomial fit (“total” with all 9 pars), but without the gaussian.
If I run with the commands as I sent you before (all parameters free) I can see the pol+gaus fit.
If it helps I’m sending the macro with the data file.
Do you know what is wrong?

Sergio
file2.txt (4.53 KB)
fit_pgp.C (1.32 KB)