root icon indicating copy to clipboard operation
root copied to clipboard

WW option for fit functions as the W option

Open belmakier opened this issue 3 years ago • 1 comments

  • [ 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

  1. ROOT version 6.27/01
  2. MacOS 12.5.1
  3. 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)

belmakier avatar Sep 01 '22 18:09 belmakier

Thank you for reporting this problem and where it is caused. I will provide soon a PR fixing it

lmoneta avatar Sep 05 '22 15:09 lmoneta

@lmoneta can this issue be assigned to the project 6.32 and be closed?

dpiparo avatar Feb 05 '24 04:02 dpiparo