THistPainter determination of default options (Error bars)


I am wondering how THistPainter decides whether the default plot option for a histogram includes the “E” option to draw error bars. I had assumed that TH1::GetBinError would return 0 if TH1::Sumw2 had not been called, but was pleasantly surprised to see it compute the sqrt(N) errors. This leaves me perplexed as to how THistPainter decides if it should use the “E” option, one could assume that it could be used in all instances. In the end I would like to replicate this behavior and only do something if the errors have been set.


Search for “Sumw2” (and / or “Associated errors”) in the TH1 Class Reference.

I had done that previously, and just repeated the exercise. I found no indication of how to know if TH1::Sumw2 had been called or if the errors had been specified.

TH1::GetSumw2 -> TArray::GetSize

TH1::GetDefaultSumw2 seem to only tell me if the default is to enable Sumw2, it doesn’t specify if the user has called it. TH1::GetSumw2 returns a pointer to an array of the sums, but how do I know if they were calculated? What if calling that method actually performs the calculation first? The documentation here is lacking.

If the data structure holding the errors is present in the histogram, it is assumed the default option should be to show the errors.

So the appropriate way to check if the structure is there is to request the pointer to it using TH1::GetSumw2?

I let @moneta confirm

Thanks. In the meantime can I request that the documentation for TH1::GetSumw2 and TH1::GetSumw2N be updated? The latter has no description what so ever.

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