TAxis FixedToVariable and VariableToFixed proposal

I would like to propose that two methods are added to the TAxis class: FixedToVariable and VariableToFixed.
So, an axis which was created as a “fixed bin sizes” one could be converted into a “variable bin sizes” one and the opposite.
Note: in case of the “VariableToFixed” method, we would not preserve bin widths, only the “low-edge”, the “upper-edge” and the number of bins would be used / preserved.

I guess I would like to have:

FixedToVariable(Double_t *xbins = 0)
FixedToVariable(Double_t xmin = 0., Double_t xmax = 0.)
VariableToFixed(Double_t xmin = 0., Double_t xmax = 0.)

If the user provides “xbins” or “xmin < xmax” then use them when calculating new bin edges / limits, otherwise calculate bin edges using the existing “low-edge” and “upper-edge” of the axis.

I don’t have any preference for what these methods should return, so maybe “void” is a good choice (or maybe better the “this” pointer).

Moreover, I think I would also like to propose that a “fixed bin sizes” axis is automatically converted into a “variable bin sizes” one as soon as the user calls “TAxis::GetXbins()” (which usually means that the user will want to get its “bin edges array” right away).

BTW. maybe you could also think about adding a “Scale” method:

I guess @moneta can comment about your suggestion.

Was @moneta able to comment on this? A similar question was asked:

Hi,
I agree getting the bin edges of a fixed size histogram is a useful thing and we could add such function, like TAxis::GetBinEdges which returns a new array.
It cannot be TAxis::GetXbins because it is better to avoid storing such array in teh histogram if it is fixed size.
The other functions I find less useful, also scaling the axis can be confusing, and I think is better creating a new histogram with the modified axis and then, only when it applies, one can copy explicitly the content.

Best regards

Lorenzo

Two typical cases that I have found many times in this forum …

  • One fills some histogram with some data, and then one needs to scale the axes, e.g., by some number (often “10^some_integer”, like switching units to “micro-”, “milli-”, “kilo-”, “mega-”, and so on) → a simple “Scale{XYZ}” method would be extremely useful.

  • One fills a simple “fixed bin sizes” histogram with some spectrum using uncalibrated raw “channel numbers”, then one fits the found peaks, and then one simply wants to apply the “calibration function” to the histogram’s axes → this often requires that the axes are first converted into “variable bin sizes” ones (as the “calibration function” is often non-linear) and then applying a “Scale{XYZ}” method.

I don’t find the idea of “creating a new histogram with the modified axis and then, only when it applies, one can copy explicitly the content” convincing. That is simply a tremendous burden cast upon a user (a.k.a. KMA).