Re: trying to build 2d interpolator with TArrayF, TMatrix

Rene Brun (Rene.Brun@cern.ch)
Mon, 11 Jan 1999 12:32:59 +0100


Richard Dubois wrote:
>
> I need to make a 2d interpolator. For this I must specify two arrays of
> gridpoints and a matrix of the function values at those gridpoints.
>
> My idea was to use 2 TArrayF's to hold the gridpoints and
> TMath::BinarySearch to find the places on the grid for an input (x,y)
> point. I would use a TMatrix to hold the function values. This seemed
> nicer than managing my own arrays and matrix and keeping track of their
> sizes.
>
> I was then going to keep a TMap of such interpolators using TString as
> the key to name them.
>
> I wasn't able to do any of this! I've had to back off to defining my
> own arrays and pseudo-matrix.
>
> BinarySearch will not accept TArrayF's as input. I could not figure out
> how to set the matrix values in TMatrix - there is no Set-type member
> function. I assume it must be done via Apply in some way. I had set up
> code to access the TMatrix values and the compiler balked at matrix(i,j)
> syntax, though such an operator is defined.
>
> Finally, the compiler reminded me that TString is not a TObject, so
> TMap won't take it as a key.
>
> On the subject of TMaps, is it really necessary, if one wants a simple
> builtin type like Int_t or Float_t or char*, to create a new class which
> inherits from TObject and solely defines the type? As far as I can tell,
> this is the case.
>
> Can this interpolator be done with the T classes?
>
> Richard
> --

Hi Richard,
I believe that this functionality could be implemented via
the histogram classes. These classes already support variable bin size
for 1-d, 2-d and 3-d histograms.
One could imagine adding
TH1::Interpolate(float x, InterpolateMode mode)
TH2::Interpolate(float x, float y, InterpolateMode mode)
TH3::Interpolate(float x, float y, float z, InterpolateMode mode)
where
mode could be linear, quadratic, cubic, etc
This has the advantage that the original table can be visualized.

If there is sufficient interest for this proposal, I will implement it.
Let me know.

Meanwhile, you can already use (say TH2F) with variable binning
and use the functions TAxis::FindBin to locate a point in the lattice.

Rene Brun