Options->Show Fit Parameters for multiple fits

Hello,

I would like to fit a graph using multiple functions each for a given x-axis range, and to display the fit parameters on the canvas.

TF1 *fit_1 = new TF1(“fit_1”,“pol6”,1.e-9,10.);
fit_1->SetLineColor(kBlue);
TF1 *fit_2 = new TF1(“fit_2”,“pol3”,10.,1.e4);
fit_2->SetLineColor(kRed);

gr_neutron->Fit(fit_neutron_1,“R”);
gr_neutron->Fit(fit_neutron_2,“R+”);

I am obviously aware of using Options->Show Fit Parameters or the equivalent command line gStyle->SetOptFit(). But both result in displaying the fit parameters of the first fit function (in my case the pol6 function).

Is it possible to display BOTH fit parameters side by side (pol6 and pol3 in my case)?

Thank you,

Cristian

{
   TCanvas *c1 = new TCanvas;
   gStyle->SetOptFit(1);
   Double_t x[] = {1., 2., 3.};
   Double_t y[] = {2., 3., 2.};
   Double_t ex[] = {0., 0., 0.};
   Double_t ey[] = {0.2, 0.3, 0.2};
   TGraphErrors tge1(3, x, y, ex, ey);
   TGraphErrors tge2(3, x, y, ex, ey);
   tge1.Fit("gaus");
   tge1.Draw("A*");
   c1->Update();

   TPaveText *st = (TPaveText*)tge1.FindObject("stats");
   st->SetX1NDC(.15);
   st->SetX2NDC(.5);

   tge2.Fit("pol2");
   tge2.Draw("*");
}

Hello,

Thank you for your reply. Yes, but this is for two different graphs. While I have one graph, fitted with two functions over different x-axis ranges. So I modified your script a bit:

{
TCanvas *c1 = new TCanvas;
gStyle->SetOptFit(1);
Double_t x[] = {1., 2., 3.};
Double_t y[] = {2., 3., 2.};
Double_t ex[] = {0., 0., 0.};
Double_t ey[] = {0.2, 0.3, 0.2};
TGraphErrors tge1(3, x, y, ex, ey);
// TGraphErrors tge2(3, x, y, ex, ey);
TF1 *fun_1 = new TF1(“fun_1”,“gaus”,1.,2.);
TF1 fun_2 = new TF1(“fun_2”,“pol2”,2.,3.);
tge1.Fit(fun_1,“R”);
tge1.Fit(fun_2,“R+”);
tge1.Draw("A
");
c1->Update();

TPaveText st = (TPaveText)tge1.FindObject(“stats”);
st->SetX1NDC(.15);
st->SetX2NDC(.5);

// tge1.Fit(“pol2”);
// tge2.Draw("*");
}

and it does not show the two functions’ fit parameters, only the first fit.

Best regards,

Cristian

I think the trick is precisely that: having a clone of the first graph otherwise the new fit replace the previous one.

Oh I see. Thank you for your help.

Best wishes,

Cristian