Hi,
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)
{
gStyle->SetOptFit(1);
TCanvas *c1 = new TCanvas("c1");
TH1F *h = new TH1F("h","test",100,-4,4);
h->FillRandom("gaus",3000);
if (fithist)
h->Fit("gaus");
else {
TGraphErrors *g = new TGraphErrors(h);
g->Fit("gaus");
g->Draw("AP");
h = g->GetHistogram();
}
c1->Update();
TPaveStats *ps = (TPaveStats*)c1->GetPrimitive("stats");
ps->SetName("mystats");
ps->SetFitFormat("4.1f");
ps->SetStatFormat("4.3f");
ps->SetTextSize(0.032);
TList *ll = ps->GetListOfLines();
TText *tconst = ps->GetLineWith("Constant");
tconst->SetTextColor(2);
if (sw) h->SetStats(0);
c1->Modified();
}
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:
- modstat(1,1): TH1F with final h->SetStats(0)
- modstat(0,1): TH1F w/o final h->SetStats(0)
- modstat(1,0): TGraphErrors with final h->SetStats(0)
- modstat(0,0): TGraphErrors w/o final h->SetStats(0)
What I observe now is:
- Text is modified, number format is not changed
- Text not modified, format is set correctly
- Text not modified, format is set correctly
- 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,
Klaus
ROOT Version: 6.24/04
Platform: Linux (Debian Buster)
Compiler: Not Provided