How to set empty bin's weight?

Dear expert,

I try to fit my histogram to gaussian function, the problem is how can I set weight of empty bin to 1 like Fit-Pannel…? I tried “W” and “WW” options but it is shows not same result…

Best regards,

If you are fitting your histogram in ROOT, with TH1::Fit by default empty bins are skipped. You can use the likelihood binned fit in case your histogram represent counts and in that case you have the correct treatment of empty bins. Otherwise you can use the Pearson chi-square method where as bin error the expected error is used (i.e. sqrt(function_value)).
The fit panel options corresponds to

  • h1->Fit("gaus","W") : all bin weights = 1 , i.e. ignoring histogram errors, but using only non-empty bins
  • h1->Fit("gaus","WW") : as above but including now the empty bins with a weight = 1.

There is no option where only the empty bins have a weight = 1. If you want to do this type of fit, just set the histogram errors to 1 for the empty bins by doing for example:

 for (int i = 1; i <= h1->GetNbinsX(); i++){ if (h1->GetBinContent(i) == 0) h1->SetBinError(i,1);}  



Dear Lorenzo

I work! so many thanks!

Best regards,

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