WW option for fit functions as the W option
- [ x ] Checked for duplicates
Describe the bug
When fitting a histogram using the "WW" option for TH1::Fit(), i.e.
hist->Fit(func,"WW");
The fit ignores bins with zero counts, i.e. the same as the "W" option.
Expected behavior
Fit should proceed with all bins with a weight of 1, even those with no counts.
To Reproduce
TF1 *func = new TF1("func", "[0]", 0, 100);
func->SetParameter(0, 1);
hist->FillRandom("func", 10); //add sparse counts
hist->Draw("hist");
hist->Fit(func, "WWR");
func->Draw("hist same");
std::cout << func->GetParameter(0) << std::endl;
Setup
- ROOT version 6.27/01
- MacOS 12.5.1
- ROOT compiled from source
Additional context
This is pretty clear from the ROOT::Fit::FitOptionsMake function here, where on line 728 the WW option is set (correctly), and then on line 780 the W option is checked for, and overwrites the WW option flag. A trivial check that the WW option is not present at line 780, or that fitOption.W1 != 2 fixes the issue, i.e. change line 780 to
if (!opt.Contains("WW") && opt.Contains("W")) fitOption.W1 = 1; // all non-empty bins have weight =1 (for chi2 fit)
or
if (fitOption.W1 !=2 && opt.Contains("W")) fitOption.W1 = 1; // all non-empty bins have weight =1 (for chi2 fit)
Thank you for reporting this problem and where it is caused. I will provide soon a PR fixing it
@lmoneta can this issue be assigned to the project 6.32 and be closed?