Draw 3 histograms with 3 box stats

Dear experts,

I have 3 histograms and I want to draw the stats box for all of them. I look at the tutorial, but I still can’t draw the box stats. Bellow is macro [1] that I’m using, do you see what I’m doing wrong?

Regards

[1]

void func(){

TF1 *func = new TF1(“fit”, fnc_dscb, -2, 2 , 7);
TF1 *func_up = new TF1(“fit”, fnc_dscb, -2, 2 , 7);
TF1 *func_down = new TF1(“fit”, fnc_dscb, -2, 2 , 7);

func_up ->SetParameters( v10_up[0], … v10_up[6]);
func_up ->SetLineColor(kGreen);
func ->SetParameters( v[0], … v[6]);
func ->SetLineColor(kRed);
func_down ->SetParameters( v10_down[0], … v10_down[6]);
func_down ->SetLineColor(kBlue);

TCanvas *c1 = new TCanvas;

TH1 *hist_up = func_up->GetHistogram();
hist_up->SetLineColor(kGreen);
gStyle->SetOptFit();
hist_up->Draw();
c1->Update();

TH1 *hist = func->GetHistogram();
hist->SetLineColor(kRed);
gStyle->SetOptFit();
hist->Draw(“same”);
c1->Update();

TH1 *hist_down = func_down->GetHistogram();
hist_down->SetLineColor(kBlue);
gStyle->SetOptFit();
hist_down->Draw(“same”);
c1->Update();

TPaveStats p = (TPaveStats)hist_down->FindObject(“stats”);
p->SetY1NDC(0.05);
p->SetY2NDC(0.45);
p->SetTextColor(kRed);
c1->Modified();

}

[url=https://root-forum.cern.ch/t/how-to-move-statistics-box-when-using-draw-sames/5139/1 hist_down->Draw(“SAMES”);[/url]

Dear Coyote,

thank you. I added the SAMES option in the Draw command, but my code still crash. Actually I have a
*** Break *** segmentation violation because the pointor *p in:
TPaveStats p = (TPaveStats)hist_down->FindObject(“stats”);
does not point properly. Do you see what is still missing?

Regards

Maybe you need the global setting:
gStyle->SetOptStat(1111);
or for each histogram, before drawing:
Histogram->SetStats(kTRUE);

Hello,
the att macro works for me (root 6.05.02 on U 14.04.03)
Note the lines:

	h2->Draw("sames");
	gPad->Modified();	// make sure 
	gPad->Update();		// both hists are drawn

Cheers
Otto
thsames.C (777 Bytes)

Dear Coyote and Otto,

thank you very much for your help. It works.

Regards