Fit TH2Poly - Fit data is empty

Is it possible to fit a TH2Poly ?

void th2polyHoneycomb(){
   TH2Poly *hc = new TH2Poly();
   hc->SetTitle("Honeycomb example");
   hc->Honeycomb(0,0,.1,25,25);
   TRandom ran;
   hc->Sumw2();
   for (int i = 0; i<30000; i++) {
   hc->Fill(ran.Gaus(2.,1), ran.Gaus(2.,1),ran.Gaus(2,1));
   }
   TF1 * f = new TF1("f","pol1");
   hc->Fit("f");
   hc->Draw("colz");
}

Gets a warning of “Fit data is empty”.

But if I chage the TH2Poly by a TH2F it works as below.

void th2ffit(){
  TH2F *hc = new TH2F("h","h",10,0,10,10,0,10);
  TRandom ran;
  hc->Sumw2();
  for (int i = 0; i<30000; i++) {
    hc->Fill(ran.Gaus(2.,1), ran.Gaus(2.,1),ran.Gaus(2,1));
  }
  TF1 * f = new TF1("f","pol1");
  hc->Fit("f");
  hc->Draw("colz");
}

Th2Poly bins can have any shapes like ins this example. Bins may even be build of several distinct parts. Doing fitting in these conditions does not make sense. The honeycomb case is special because it is very regular and seems close to a normal TH2. But it is consider as any TH2Poly by ROOT and fitting does not apply.

I understand that for some cases, fitting would not make sense, however, the option to fit could have been kept available for the regular binning case like the honeycomb.
Thanks.

“kept” is not the right word as TH2Poly does not have fitting for the reasons I explained. It would be a special implementation for honeycomb. May be @moneta can comment on that.

HI,

The problem is that a TH2Poly has no builti-in concept of regular binning and one cannot check if the bins are all the same.
One could eventually perform a fit, by computing the integral of the function in the bin, but it is very complicated to implement and it will be very time consuming.

The simplest solution for you is to fill a TGraph2D (or TGraph2DErrors) with the bin center positions from the TH2Poly and you fit that object

Lorenzo

Thanks for the suggestions.
Best.

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