TH1::operator[] documentation?

Hi, I just accidentally discovered that you can use [] on TH1 objects:

root [0] TH1D h("h","h",10,0,10)
root [1] h[0]
(Double_t)0.00000000000000000e+00
root [2] h[100]
Error in <TArrayD::operator[]>: index 100 out of bounds (size: 12, this: 0x7fb1ea89daa8)
(Double_t)0.00000000000000000e+00
root [3] h.Fill(2)
(Int_t)3
root [4] h[3]
(Double_t)1.00000000000000000e+00

However I notice that in the documentation, neither TH1 nor any of its base classes provide such an operator. What’s going on? Am I just reading the documentation wrong, or should this be a private method? TH1D have a protected TArrayD data member which has operator[], and it stores the weights in each bin, but why am I able to access it?

I think even if users are not supposed to use this, it should be documented somewhere.

Jean-François

Hi Jean-François,

See:



Cheers, Bertrand.

Ah thanks…this actually made me learn a new thing. I had never actually noticed that box on the right side, or I always overlooked it. Because of that, the specific TH1D.html page was never really useful and I automatically went to TH1.html whenever I wanted information about any kind of TH*. Now with “show inherited members”, I can start using TH1D.html more often, and not have to hunt down base classes for methods.

I am actually preparing a talk for my fellow graduate students, I will include this nugget of wisdom for sure.

Jean-François