Re: [ROOT] 2 graphs, 2 fits, 2 fit stats boxes

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Jul 15 2002 - 21:33:25 MEST


Hi Mike,

Getting more than one "stats" box was problematic in case of TGraph.
I have improved the situation in the current development version in CVS.
With the new version, a TPaveStats objects is connected to the producer
(TH1, TGraph). The TPaveStats object is added to the list of functions.
For example, after painting a histogram, one can retrieve its stats box
with:
  TPaveStats *stats =
(TPaveStats*)h->GetListOfFunctions()->FindObject("stats");
The old form, getting the pointer via gPad->GetPrimitive("stats")
is still supported.
With the new way, it is not necessary to rename the existing "stats" box.
For example, the following 3 lines:
   h1->Draw();
   h2->Draw("sames");
   h3->Draw("sames");
will produce one "stats" box for each histogram.
You can modify the position of each box as usual, via the mouse
or via calls to stats->SetX1NDC(new x position), etc.

With the new version, previous problems experienced when redrawing
the canvas after a write/read operation are also fixed.

You will find below a new version of your example that is simpler
and gives correct results:

Rene Brun

{
gStyle->SetMarkerStyle(8);
gStyle->SetMarkerSize(.5);
gStyle->SetOptFit();

double x[5]={1.0, 2.0, 3.0, 4.0, 5.0};
double y[5];
double z[5];
{
   for(int i=0; i<5; i++){
  y[i]=x[i];
  z[i]=2*x[i];
}
}
TGraph* g1 = new TGraph(5, x, y); g1->SetName("g1");
g1->SetMarkerColor(2);
TGraph* g2 = new TGraph(5, x, z); g2->SetName("g2");
g2->SetMarkerColor(4);

TMultiGraph* mg = new TMultiGraph();
mg->Add(g1);
mg->Add(g2);
mg->Draw("ap");

gStyle->SetFuncColor(1);

g1->Fit("pol1");

g2->Fit("pol1");
gPad->Update();

TPaveStats* sb2=(TPaveStats
*)(g2->GetListOfFunctions()->FindObject("stats"));
sb2->SetX1NDC(.2);
sb2->SetX2NDC(.4);
sb2->SetY1NDC(.7);
sb2->SetY2NDC(.9);
sb2->SetTextColor(4);
gPad->Modified();

}



On Wed, 10 Jul 2002, Mike Kordosky wrote:

> Hi,
> 
> I am trying to do the following:
> 
> Make 2 graphs.  Put them on the same plot.  Fit them both.  Display the
> fit result boxes from both fits.
> 
> I cannot seem to get the last part right.  I include an example macro.
> The macro ends up drawing 4 stats boxes.  After doing the second fit, I
> call TPad::GetPrimitive() and somehow pick up the result from the first
> fit.
> 
> May I suggest that a HOWTO on "Overlaying Multiple Plots With Multiple
> Stats Boxes" would be very useful, as I've seen roottalk posts about this
> in the past.
> 
> Thanks,
> 
> Mike Kordosky
> 
> -- 
> Graduate Research Assistant  // High Energy Physics Lab
> kordosky@hep.utexas.edu     // University of Texas at Austin
> kordosky@fnal.gov	   //
> ph: (512) 471-8426 (RLM Lab, Office)
>     (512) 475-8673 (ENS Lab)
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:59 MET