Easy and elegant way to fit TH2 as a scatter plot?

Hi - I would like to have my 2D histogram interpreted as
a scatter plot (so, if a certain [x,y] bin contains n events,
I would like to interpret it as n points at the center of the bin).
This scatter plot I would then like to fit with a straight line, pol1.

From quick googling “fit TH2”, I have asummed that

TF1* f = new TF1(“f”,“pol1”,-10,10);
h2D->Fit(f,“R”);

will do the job. It does the fit, but when I look at the fitted line
on the top of the data I see that the result is obvoiusly not the
minimum chi-square of the data interpreted as a scatter plot.

Thinking a little I realized that I could write a short code that
takes the data from TH2 and puts it into TGraph, repeatingly
adding the same point if the number of the events in 2D bin
is greater then 1, and then fit TGraph with pol1, but is there
an more elegant way?

                                                          Regards, Emil

OK, I think I figured it out, fitting a profile histogram works

TProfile pp = hm2_ydca_180->ProfileX();
TF1
g0 = new TF1(“g0”,“pol1”,-10,10);
pp->Fit(g0,“R”);