Showing fit parameters in Fit

I am new to ROOT, but read the userguide. And still I have the following problem. I can;t get fit parameters shown in the fit. Page 72 of the userguide said I have to use gStyle->SetOptFit() for this, so i did. But still no parameters in the fit.

I use the following code where i read a file called data.root, define a 5 parameter function and set the parameters with a first guess.

[code]{
gStyle->SetOptFit(2);

TFile *f = new TFile(“data.root”);
TF1 *fit = new TF1(“fit”,"[0]exp(-x/[1])(1+[2]*cos([3]*x+[4]))",0,700e3);

fit->SetLineColor(kRed); fit->SetNpx(500);
fit->SetParameters(1001e3,6.43947e4,-0.3141,2*3.141592/4784.67,3.141592);
h->Fit(fit);
}[/code]

Hi,

When you are reading histograms from a root file and want to change those kind of option settings you need to call h->UseCurrentStyle(), i.e.[code]{
gStyle->SetOptFit(2);

TFile *f = new TFile(“data.root”);
TF1 *fit = new TF1(“fit”,"[0]exp(-x/[1])(1+[2]*cos([3]*x+[4]))",0,700e3);

fit->SetLineColor(kRed); fit->SetNpx(500);
fit->SetParameters(1001e3,6.43947e4,-0.3141,2*3.141592/4784.67,3.141592);
h->UseCurrentStyle();
h->Fit(fit);
}[/code]Cheers, Ilka

Your histogram was saved in the file with a different (probably default style, ie no fit).
You must force the current style by calling

h->UseCurrentStyle(); h->Fit(fit);
or alternatively, call

gStyle->SetOptFit(2); gROOT>ForceStyle(); .. h->Fit(fit);
Rene

That worked, thanks.