Boundaries in TH3::Interpolate()

Hello,

While playing with a TH3 and interpolate, I ran into some unexpected behaviour. If you have a two-bin dimension in your histogram, it will never successfully Interpolate. The reason is that edge cases have been explicitly removed.

This makes sense as you get a division by zero when you select the same bin twice in trilinear interpolation (as you naively would for an edge case). However, looking at the TH2::Interpolate() code, I see that there the difference of the bin center of the under/overflow bin with the boundary bin is used, while the bin content of the edge bin is used twice. This seems logical to me. Could something like this not also be done with TH3::Interpolate()? I have made the necessary changes to do so locally, and it seems to be working properly.

Either way, I think that the edge cases should either be excluded from both or included in both. I don’t see why they are being treated differently for different dimensionality. I personally prefer the option of being able to use the edge bins, and would be happy to provide my own code changes to modify TH3::Interpolate() if desired.

Beyond that, I would like to point out the other Interpolate problem I raised last week:
[Const TH*::Interpolate()

Thanks and best regards,
Steven

Hello again,

After further tests, it looks like such boundary cases are better treated by switching from trilinear interpolation to bilinear interpolation. That is, hold the boundary bin constant (or one of the boundary bins if it’s in a corner) and then apply 2D bilinear interpolation on the other two dimensions. This is performing quite well for me, and again allows for interpolation on the boundary bins of 3D histograms (which is especially important when you only have a couple bins for one of the dimensions). Is it possible to add such functionality to future versions of ROOT?

Thanks and best regards,
Steven