Stats box problems on histograms

Hi,

I’m trying to plot 2 histograms on the same pad, and stop the stats boxes from lying on top of each other. I’ve followed the advice in the manual, and on various root-talk pages, but it still doesn’t seem to work. This is basically what I have:

gammaCanv = new TCanvas("GammaCanvas","GammaCanvas");
gammaCanv -> Divide(2,2);
gammaCanv -> cd(1) 

plot1.Draw("");
plot2.Draw("SAMES");

gammaCanv ->Update();
TPaveStats *statsBox = (TPaveStats*)plot2.GetListOfFunctions()->FindObject("stats");
statsBox->SetY1NDC(0.67);
statsBox->SetY2NDC(0.83);
gammaCanv ->Modified();

The above code does actually change the stats box NDC co-ordinates, but on the histogram they still end up on top of one another. What am I missing?

My setup uses ROOT 4.04.02 on windows XP. I compile my code in Visual Studio 7.1, and link with the ROOT libraries as Fracois-Xavier Gentit’s site on the install file page describes.

Thanks in advance for any help!

Rob

I think the macro:

$ROOTSYS/tutorials/transpad.C

does what you want.

Hi,

Thanks for your suggestion, but i’d like to keep it simple if possible, without the complexity of and invisible pad, a stack, or some other interim object… I actually based my code around this rather than the code you suggested, which offers a similar method.

I don’t see any reason for what I’m doing not to work (after all, it says it should in the manual!), except that it appears that it isn’t updating the displayed canvas with the altered stats box setting. Does anyone know a way of sorting this code as is, or do I really need to use the TMultiGraph class, or an invisible pad?

Cheers,

Rob

Can you send a running macro showing your problem ?

Hiya,

Right, i’ve narrowed the problem down. It seems to be something to do with dividing the canvas up. The following macro works fine, but if you uncomment lines 2 & 3, the stats box stops getting repositioned when the canvas is divided into 4 pads.

{
  TCanvas * c1 = new TCanvas("Canv1","Canv1");
  //c1->Divide(2,2);
  //c1->cd(1);

  TH1F *h1 = new TH1F("h1","h1",100,-4,4);
  h1->FillRandom("gaus",20000);
  h1->SetFillColor(kRed);

  TH1F *h2 = new TH1F("h2","h2",100,-4,4);
  h2->FillRandom("gaus",15000);
  h2->SetFillColor(kBlue);

  h1->Draw("");
  h2->Draw("SAMES");

  c1->Update();
  TPaveStats *statsBox = (TPaveStats*)h2->GetListOfFunctions()->FindObject("stats");
  cout << "\nh2 stats box Y1NDC = " << statsBox->GetY1NDC() << endl;
  cout << "h2 stats box Y2NDC = " << statsBox->GetY2NDC() << endl;
  statsBox->SetY1NDC(0.67);
  statsBox->SetY2NDC(0.83);
  c1->Modified();
  cout << "\nNew h2 stats box Y1NDC = " << statsBox->GetY1NDC() << endl;
  cout << "New h2 stats box Y2NDC = " << statsBox->GetY2NDC() << endl;
}

There must be something I’m not updating, but I don’t know what it is.

Thanks in advance for any help!

Rob

Thanks for your example. I see what you mean now. I guess the following page is what you want:
root.cern.ch/root/roottalk/roottalk00/0016.html

Brilliant. Many thanks! :smiley:

Rob