Years ago on RootTalk Rene explained how to get the “linearized
bin number” or “global bin number” from the 2D or 3D coordinates:
You can use these functions for all type of histograms and
all dimensions. In case of 2-d and 3-d histograms, however, you
must compute a “linearized bin number” before invoking these
functions. For example for a 3-d histogram, you can do:
Int_t bin = h3->GetBin(binx,biny,binz);
Float_t y = h3->GetBinContent(bin);
Is there not a method to reverse this? It looks like the linearization
is straightforward. So, I can say:
int biny = h2->GetMaximumBin() / ( h2->GetNbinsX() + 2);
int binx = h2->GetMaximumBin() % ( h2->GetNbinsX() + 2);
The case I mentioned is the first that comes to mind. There’s an existing
method, h2->GetMaximumBin(), which returns the linearized bin number
of the maximum value bin. But, I probably prefer to know the x and y bins, or the centers of those bins.
Or, if I want to loop through every bin in a histogram it could be
convenient to do this with the linearized bin number. But, then if
I decide a bin is interesting I would like to know its coordinates, not
its linearized bin number
Imagine looking for noisy cells in a detector, for example. You have
some monitoring plot, and you want to print out the coordinates
of interesting cells.
It’s not so hard for the user to do the bookkeeping themselves. But, since ROOT has so many methods to make life easier, I was a bit surprised it didn’t have a method for this back conversion of linearized bin.