Bad design regarding the storage of statistics

Hi,

In the following code:

import ROOT

ROOT.gStyle.SetOptStat(0)
c=ROOT.TCanvas('c', '', 600, 600)
ROOT.gStyle.SetOptStat('mr')
h=ROOT.TH1F('h', '', 100, 0, 10) 
h.FillRandom('gaus', 10000)
h.Draw()
c.SaveAs('plot.png')

The statistics box is by deafault turned off initially. However after I make the canvas and before I make the histogram I request errors with the mean. I get, therefore, the plot I expect. However If I do:

import ROOT

ROOT.gStyle.SetOptStat(0)
c=ROOT.TCanvas('c', '', 600, 600)
h=ROOT.TH1F('h', '', 100, 0, 10) 
h.FillRandom('gaus', 10000)
ROOT.gStyle.SetOptStat('mr')
h.Draw()
c.SaveAs('plot.png')

the statistics box is not present. This suggests that the histogram constructor is checking the gStyle instance and either storing information to show the statistics box or not. Is this true? I do not have time to go through the code.

If so, by adding this SetOptStat line after the constructor, the information is not available anymore and the box would not appear even if requested. Calculating these seven or eight numbers should be done always, regarding of wether they are requested or not. At the end seven extra floats won’t occupy much space and allow for all these statistics to be available afterwards.

Cheers.f


Please read tips for efficient and successful posting and posting code

_ROOT Version:6.22.06
_Platform:x86_64-centos7
_Compiler:gcc8

You may want to draw some histograms with and some without the statistics box (the “default” behavior is set at the histogram’s creation time).

In your first macro, try:

h.SetStats(False); # we DO NOT WANT the statistics box for this histogram
h.Draw()

In your second macro, try:

h.SetStats(True); # we DO WANT the statistics box for this histogram
h.Draw()
1 Like

Hi,
what I see here is another example of why global variables are bad design. Fortunately, ROOT is going to move further away from them in future versions. Good that @Wile_E_Coyote 's code has no gStyle.
I’d also add that the question is not about storage of statistics, but rather about its presentation.

Hi,
yes we tried to learn from past design mistakes and the new (“ROOT7”) graphics that are being developed are where we are hope to correct them.

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