Null TPaveStats object

Hi, I’m trying to move a TPave stat object so that I can observe the stats from multiple plots in the same canvas. However, when I try to retrieve the TPaveStats object, it comes back NULL. For example the following script:

  TH1F * hist = new TH1F("hist","histogram", 20, -10,10);
  hist->Fill(4,10);
  hist->Fill(-1,3);

  hist->Draw();

  TPaveStats *st = (TPaveStats*)hist->FindObject("stats");

  cout << "value of st: " << st << endl;

  st->SetX1NDC(.40);
  st->SetX2NDC(.60);

Has the output:

Oddly, if I try to do this in CINT, it seems to work.

As a side question, I have a legend showing the different colors of the graph lines. It would look much better to have the elements of this legend placed into the TPaveStat boxes, with each line style shown next to the plot statistics. I don’t suppose there is a simple way to do this?

Thanks,
Caleb[/quote][/code]

After “hist->Draw” add

gPad->Update(); to force the generation of the “stats” object.

You can move the “stats” object with eg:

Root > TPaveStats *st = (TPaveStats*)h->FindObject("stats") Root > st->SetX1NDC(newx1); //new x start position Root > st->SetX2NDC(newx2); //new x end position
Rene

Hi, so I did that, and its not complaining about a NULL pointer anymore. Thanks.

However, changing the values put into the new coordinates doesn’t seem to be changing the location of the stat box. The code I used in my script is below, and the attached is the resulting plot. NDC coordinates correspond to a percentage across the page, right? So I’d expect this to be on the left side of the screen. I’ve changed the coordinates, and the box doesn’t budge.

  TCanvas  * cnv  = new TCanvas("c1","c1", 800,570);

  TH1F * hist = new TH1F("hist","histogram", 20, -10,10);
  hist->Fill(4,10);
  hist->Fill(-1,3);

  hist->Draw();

  cnv->Update();

  TPaveStats *st = (TPaveStats*)hist->FindObject("stats");

  cout << "value of st: " << st << endl;

  st->SetX1NDC(.10);
  st->SetX2NDC(.40);

  cnv->Update();


Replace your last cnv->Update() by cnv->Modified()

Rene