Inconsistency in modifying statistics box


while trying to modify the statistic box after a fit, I stumbled across some inconsistencies which I wasn’t able to resolve. My example code looks like this:

void modstat(bool sw = true, bool fithist=true) 
  TCanvas *c1 = new TCanvas("c1");
  TH1F *h = new TH1F("h","test",100,-4,4);
  if (fithist) 
  else {
    TGraphErrors *g = new TGraphErrors(h);
    h = g->GetHistogram();

  TPaveStats *ps = (TPaveStats*)c1->GetPrimitive("stats");
  TList *ll = ps->GetListOfLines();
  TText *tconst = ps->GetLineWith("Constant");

  if (sw) h->SetStats(0);

The macro should modify the number format, text size, and the text lines being displayed in the box. I call the macro with root -n (to get rid of all logon settings), the parameters select the cases:

  1. modstat(1,1): TH1F with final h->SetStats(0)
  2. modstat(0,1): TH1F w/o final h->SetStats(0)
  3. modstat(1,0): TGraphErrors with final h->SetStats(0)
  4. modstat(0,0): TGraphErrors w/o final h->SetStats(0)

What I observe now is:

  1. Text is modified, number format is not changed
  2. Text not modified, format is set correctly
  3. Text not modified, format is set correctly
  4. Text not modified, format is set correctly

The text size is set correctly in all cases. So, using the recommended procedure, I can modify the text being displayed for TH1F, but not the number format, while skipping the final h->SetStats(0) set the number format, but does not show the text modification. For TGraph, the format setting works, but I’m not able to modify the text in the stat box.

In particular the last point I’d like to realize (change the stats box text after fitting a TGraphAsymmErrors), but I don’t know how.

Can somebody help me?

Best regards and thanks,

ROOT Version: 6.24/04
Platform: Linux (Debian Buster)
Compiler: Not Provided

Yes, the recommended “a posteriori” procedure acts only the graphical attributes not on the number formatting which is done “a priori” when the stat-box is created at fitting time. Therefore you should specify the number formatting before performing the fit.

Thanks for the explanation.

And what about the non-ability to modify the text items for the TGraph?

This ticks works for histograms only.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.