Interpolating TH2 to a finer binning

Hello,

I have a TH2 that I would like to interpolate to have finer binning. There is no know function to fit the plane to. Currently I use TGraphDelaunay to achieve this but I would like a smoother interpolation. If my original histogram is h2_RealXSecs and my interpolated histogram with fine binning is h2_RealXSecsGrid_Interp then I obtain the second from the first by the following code:

TGraph2D *g2_RealXSecs = new TGraph2D(100000);
for(int i=Minm0; i<=Maxm0; i+=StepSize){
for(int j=Minm12; j<=Maxm12; j+=StepSize){
g2_RealXSecs->SetPoint(jcount,i,j,h2_RealXSecs->GetBinContent(h2_RealXSecs->FindBin(i,j)));
jcount++;
}
}

cout << "Doing Delaunay interpolation … " << endl;
TGraphDelaunay *g2_RealXSecs_Delaunay = new TGraphDelaunay(g2_RealXSecs);
for(int a=xfirst; a<=xlast; a++){
for(int b=yfirst; b<=ylast; b++){
h2_RealXSecsGrid_Interp->Fill(a,b,g2_RealXSecs_Delaunay->ComputeZ(a,b));
}
}

Is it possible to use better methods than this for the interpolation? eg Spline or Kriging. My figure of merit is smooth level curves. My interpolated histogram need not pass through the original points and I do have errors on the bins that I could use in the interpolation. Could you please give an example that would replace the above code?

Additionally, is ComputeZ() intended to be equivalent to Interpolate()? I ask because Interpolate() always returns 0.

Thank you,
Keith

Note that instead of doing the loop to fill the TGraph2D from the histogram you can use the constructor: TGraph2D(TH2* h2)
see: root.cern.ch/root/html/TGraph2D.html

Hello,

Yes I am aware of how the constructor works but doing it that way I was not sure that I would get the exact (x,y) values I calculated z for.

I am also aware that there is a Bilinear Interpolation available through TH2::Interpolate but I believe that is worse quality than a Delaney Interpolation. I would how ever entertain a Bicubic interpolation but I have not found such a method.

By the way, as this is my first time posting on RootTalk, I am not sure if I should have posted in the more general “ROOT Support” forum. Please advise.

Thanks,
Keith

This post is fine in “Stat and Math Tools”

Hi,

if you want to fit your points using polynomial, look at the class TMultiDimFit
( root.cern.ch/root/htmldoc/TMultiDimFit.html )

If you just want to smooth the histogram bins, we have also the function TH2::Smooth
( root.cern.ch/root/htmldoc/src/TH … tml#lD_u6B )

Unfortunately we do not have multi-simensional splines in ROOT. I had somewhere myself also code for Loess (local regression), but I never put it in ROOT. Eventually if you are interested I could send it to you

Best Regards

Lorenzo

Hi,

Since i have no idea what the true form of the underlying distribution is, I would not feel comfortable fitting a polynomial guess as it would very likely add a large bias. Also, any smoothing or Loess-like teqnique would only remove information. What I want is a rigerouse interpolation method. The delanuay and bilinear methods will have to do for now.

Is it possible to add an option to TH2::interpolate to choose Delanuay instead of bilinear? The implementation should be simple as it is already implemented in TGraph2D::Interpolate().

In principle further functionality is important and should be put into ROOT if one can find some open source. The differing interpolation methods are defined summarized here:
www.esri.com/news/arcuser/0704/files/interpolating.pdf

Thanks for the input I will let you guys know if I end up coding anything useful.
Keith

[quote=“kedmonds”]Hi,

Since i have no idea what the true form of the underlying distribution is, I would not feel comfortable fitting a polynomial guess as it would very likely add a large bias. Also, any smoothing or Loess-like teqnique would only remove information. What I want is a rigerouse interpolation method. The delanuay and bilinear methods will have to do for now. [/quote]

As an aside: As you don’t know what the underlying distribution is, it doesn’t really matter too much how you guess at it, that’s all you’re going to be doing. At the end of the day, it’s very difficult to increase the number of bins in a histogram as the information is already lost. Getting a finer binned histogram to start with is where I’d spend my effort.

good luck,
Charles