Re: Multiple stat boxes for multiple TF1s in a single histogram

From: Chris Schilling <cschill_at_slac.stanford.edu>
Date: Thu, 16 Mar 2006 00:31:53 -0800


Hi Rene,

Thanks. I have seen this solution, and I think that my case is complicated by the fact that I first store the histogram in a file with all n functions stored in the TH1. I then access the histograms from the file and do all the drawing. I guess it looks like my only choice is to either create the box manually or to refit the histograms using this procedure.

Thanks again
Chris

Rene Brun wrote:
> Hi Chris,
>
> There is only one "stats" box per histogram.
> To achieve what you want see example below.
>
> Rene Brun
>
>
> void fitmany() {
> TCanvas *c1 = new TCanvas;
> TH1F *h = new TH1F("h","test",100,-3,3);
> h->FillRandom("gaus",50000);
> gStyle->SetOptFit();
> TH1F *hf1 = (TH1F*)h->Clone("hf1");
> hf1->Fit("pol3","","",-3,-1);
> TH1F *hf2 = (TH1F*)h->Clone("hf2");
> hf2->Fit("gaus","","sames",-0.8,0.8);
> hf2->GetFunction("gaus")->SetLineColor(kRed);
> c1->Update(); //to force the generation of the stats box
> TPaveStats *p2 = (TPaveStats*)hf2->FindObject("stats");
> p2->SetY1NDC(0.05);
> p2->SetY2NDC(0.45);
> p2->SetTextColor(kRed);
> c1->Modified();
> }
>
>
>
> On Wed, 15 Mar 2006, Chris Schilling wrote:
>
>> Hi,
>>
>> I am fitting a TH1 with multiple functions (using the '+') option.
>> Then I store the histogram in a root file.
>>
>> I know how to access the various functions in the TH1, but I wonder
>> how to get the fit boxes belonging to each TF1 and plotting them on
>> the same Canvas.
>>
>> Currently the fit box for the first fit in the list of functions is
>> displayed, even though that is not necessarily the function I am
>> drawing. I would like to know how to draw the fit box corresponding
>> to the function that I am drawing.
>>
>> Thanks for the advice
>> Chris
>>
Received on Thu Mar 16 2006 - 09:32:06 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:57 MET