Subtracting fit from 2D Histogram

I have a dE/dx vs P histogram. I also have a fit for say, pions. I need to subtract the histogram from the fit and I cant find anywhere how to do that. I know that for 1D we use


Could someone tell me how do I subtract the a TF1 from a TH2?

Got it. Now that I think back, the premise of the question itself is absurd. I need to take projection of the 2D histogram so that I can compare apples to apples. Thanks.

I believe the method ‘void Add(TF1* f1, Double_t c1 = 1, Option_t* option = “”)’ will also work for two-dim TF2 and three-dim TF3 functions (for TH2 and TH3, respectively). So, if you have a two-dim function which you fitted, you should be able to subtract it from your two-dim histogram using something like “MyHisto2D->Add(MyFitFunction2D, -1);”.