What is an alternative of SetBins for TH2?

Hi ROOTers,
I need to be able to update the number of bins and the range of X-axis of a histogram. In case of TH1 I use SetBins method:

myHisto1D->SetBins( n, x0, x1 );

Is there a way to change axis range and numbers of bins (of both axes) in case of using a TH2 histogram?


ROOT Version: 6.04.00
Platform: CentOS 7
Compiler: gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)


Hi,
you can use this overload of SetBins. The full class documentation for the latest releaes of ROOT is at https://root.cern.ch/doc/v620/classTH2.html. TH2 inherits most of its methods from TH1, so you need to expand “Public member functions inherited from TH1”.

Hope this helps!
Enrico

Yes, I didn’t expand the inherited methods in the class reference. This is because I didn’t expect that this method to be there :slight_smile: Thank you.

Can’t blame you! The search box at the top-right can be a boon in these cases.

Cheers,
Enrico

That box doesn’t help much. If you enter there “SetBins” there are no TH2::SetBins in popup results :slight_smile:

True but you at least can see all of the available signatures at a glance

It is in the search box: TH1::SetBins. TH2 Inherits from TH1

Well, it is a bit confusing to me seeing the following line in the description of SetBins function in TH1:

Reimplemented in TProfile2D, TProfile3D, and TProfile.

Should there be TH2 also? Otherwise it is not obvious that TH2 overloads that function.

It’s really a TH1 method. The inheritance and distribution of methods in the various classes is historically weird for histograms (the v7 histograms will be saner).

It does not overload that function. That’s the point. When you look at the help of a function, the documentation lists all the classes which overload that function in the section “Reimplemented in”. As you can see TH2 does not overload the TH1 version of SetBins. So all is correct.

Oh, I see the code for it in TH1.cxx. Now I got it. Design flaw I think: to have a member function that is not intended to be used. Really weird members distribution. I suppose that some internal design required that.

The 3rd implementation (3/6) is for 2D histograms (see the doc)

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