How to fill 2d histo with function?

Hello everyone,

I have 2 TH2F histos, 1st one with data, 2nd one with background that I want to subtract from the data. After the second diagram has been fitted with function

Double_t fun2(Double_t *x, Double_t *par) {
Double_t z2 = x[0]*x[0]/par[0]/par[0] + x[1]*x[1]/par[1]/par[1];
z2 *= par[2]*par[2];
return -sqrt(z2) + par[3];

I want to subtract background, as I see here, I should fill TH2F using my function like this

for (int i=0;i<nb;i++)
   float x=h3->GetBinCenter(i);
   float y=fun->Eval(x);

–°an anyone tell me what this cycle looks like in my TH2F case?


Use the functions from TH2 here (Also note that TH2 derives from TH1. You can unfold the TH1 section.)

Make a TF2 from your fit function, and then use myHistogram->Add(myTF2, -1) to subtract the function from the histogram.