Fit a 2D Histogram whit a linear function

Hi everybody,
I’m a student who wants to fit a 2D histogram whit a polynomial function.
Once I create the histogam, I use a pre-defined linear function to fit it, but it doesn’t work!

Here I define the function:

* 1. Double_t fun2(Double_t *x, Double_t *par) {

* 2. Double_t scale = par[0];
* 3. Double_t shift = par[1];

* 4.  return scale*(x[0] + x[1]) + shift;

* 5. }

And here I try to impement it:

* 1. const Int_t npar= 2;
* 2.   Double_t f2params[npar] =
* 3.      {1.0146,0.00016};

* 4.   TCanvas *c2 = new TCanvas("c2","c2");
* 5.   TF2 *f2 = new TF2("f2", fun2, 60,115,40,120, npar);
* 6.   f2->SetParameters(f2params);
* 7.   f2->SetParNames("scale","shift");
* 8.    h2->Fit("f2"); //"h2" is the name of the histogram
* 9.    f2->Draw("cont1 same");

* 10. }

This is my first request, so if I made a mistake in formulating it, please let me know!
(The histogram I want to fit is attached below )commodoro08.pdf (59.6 KB)
Thank’s :smiley::smiley:

Fitting 2D Histograms

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.