Fit a 2D histogram

I have a TH2F histogram (energy vs. position) and I want to fit it as it was a TGraph object, so that I can use a polynomial function. How can I do it?

Have a look at the tutorial fit2dHist.C