Retrieving 2D histogram fitting parameters

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Hi, I have been using frequently the Fit function in general, but mostly with 1D histograms. I usually set the option ā€œSā€, to get the fit return to a TFitResultPtr object, from where I can get the parameters.
Now I am trying to do the same with a 2D histogram but seems the syntaxis is not the same as for 1D.

for 1D I do:

TH1D* h1;
TFitResultPtr fitPtr = h1->Fit("myF","SNQ","",x0,x1);

How do I do something equivalent??

I tried:

TH2D* h2;
TFitResultPtr fitPtr = h2->Fit("xygaus","SNQ","",x0,x1,y0,y1);
TH2D* h2;
TFitResultPtr fitPtr = h2->Fit("xygaus","SNQ");

and others, but none seems to be correct.

I got the fit working by simply writing:

TH2D* h2;
TFitResultPtr fitPtr = h2->Fit("xygaus");

but I do not know how to retrieve the results in the code. I do this fit repeatedly, and dealing with the console output is tedious.

Help pls.

Thanks in advance

  TF2 *f = new TF2("xygaus", "xygaus", -10., 10., -10., 10.);
  f->SetParameters(1., -2., 1., -1., 2.);
  TH2D *h = new TH2D("h", "h;X;Y;Z", 30, -5., 5., 30, -5., 5.);
  TFitResultPtr p = h->Fit("xygaus", "SNQ");
  if (p.Get()) {
    h->Draw("colz"); f->Draw("same");
1 Like

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