Show two fit results

Hello.

I have a TProfile, and I fit it with two different functions (using the “+” and “same” options). When I draw the TProfile, both fitting funcitons are shown, but the stats box only shows the first fit result.

gStyle->SetOptFit(kTRUE) is at the begginging of the script.

How can I show both fit results?

I am using root 5.24/00b.

Thanks in advance!

Hi,

this is not really the most elegant solution, but you could just clone the histo before fitting it, fit the function to the two – identical – histograms and then draw the second one with the “sames” option and move the stat box. The piece of code below illustrates on how you could do this. Note that you need the c1->Update(), or alternatively, if you don’t explicitly create a canvas, a gPad->Update() to make sure you can access the stats boxes.

Hope this helps.

Erik

void fit()
{
  gStyle->SetOptFit(111111);
  TCanvas *c1 = new TCanvas("c1","Canvas",500,500);
  TH1D *p = new TH1D("p","Profile",1000,-5,5);
  p->FillRandom("gaus",10000);
  p->Draw();
  TH1D *p1 = (TH1D*)(p->Clone());
  p->Fit("pol4","","");
  TF1* pol4 = (TF1*)(p->FindObject("pol4"));
  pol4->SetLineColor(kBlue);
  p1->Fit("gaus","","sames");
  
  p1->Draw("sames");
  c1->Update();
  TPaveStats *stat = (TPaveStats*)(p->FindObject("stats"));
  TPaveStats *stat1 = (TPaveStats*)(p1->FindObject("stats"));
  if(stat && stat1) {
    stat->SetTextColor(kBlue);
    stat1->SetTextColor(kGreen);
    float height = stat1->GetY2NDC() - stat1->GetY1NDC();
    stat1->SetY1NDC(stat->GetY1NDC() - height);
    stat1->SetY2NDC(stat->GetY1NDC() );
    stat1->Draw();
  }
  return;
}

[quote] (using the “+” and “same” options).[/quote]Try with the “sames” option.

Cheers,
Philippe.