Segmentation Fault in TH1::Fit() Using "WL" Option in ROOT 6.30.x — Was the Poisson Likelihood Behavior Recently Made Stricter?

Hello,

I’m working on subrun-level fits of time histograms from an experiment, using the Weighted Log-Likelihood Estimation (WLLE) method with:

hist->Fit("myfunc", "R0WLS");

The data are weighted histograms, and the fit function includes a decaying cosine model. I’ve been running these fits successfully for years on ROOT 6.26.10, even when some bins had zero content or zero error (especially at large times, e.g., >220 µs, where data is sparse).

However, after updating to ROOT 6.30.x, I suddenly encounter a segmentation fault when running the exact same code and input files. After investigation, I found that the crash occurs in the Poisson likelihood fit when any bin error is zero. I confirmed this by printing warnings for bins with zero error, and replacing the fit option from "WL" to "L" avoids the crash.

This leads to my main question:
Was the internal behavior of TH1::Fit() with the “L” or “WL” options changed in ROOT 6.30.x to explicitly disallow bin errors of zero, resulting in segmentation faults?

I inspected the FitUtil.cxx source, especially near L1434, and found that the likelihood calculation now heavily depends on bin errors via 1/sigma². It looks like this could cause division-by-zero or undefined behavior, where older versions may have silently ignored or sanitized zero-error bins.

Let me know if you’d like a minimal reproducer or more context. Thank you for your work on ROOT — it’s an essential tool for us!

Best regards,
Byungchul Yu

Could you retry on ROOT 6.34 by downloading the binaries ?
It if still produces a segfault, please send a minimal reproducer, thanks!

Dear ROOT team and ferhue,

Thank you for quick response. I’m currently encountering a segmentation fault when attempting to fit a simple TH1D histogram using the WL (Weighted Likelihood) option in ROOT v6.30/02, even when only one bin has an error set to zero. This behavior appears to be new, since I ran a very similar script about two years ago without any issues on an older version of ROOT (around v6.26).

I’ve created a minimal reproducer that reliably triggers the issue:

// minimal_reproducer.C
void minimal_reproducer() {
  TH1D* h = new TH1D("h", "Example Histogram with Zero Bin Error", 10, 0, 10);

  // Set bin contents and errors
  for (int i = 1; i <= 10; ++i) {
    h->SetBinContent(i, 100.0);
    h->SetBinError(i, 10.0);
  }

  // Intentionally set a single bin error to zero
  h->SetBinError(5, 0);  // This seems to cause the crash

  // Fit with a constant function
  TF1* f = new TF1("f", "[0]", 0, 10);
  f->SetParameter(0, 100);

  // Attempt fitting with WL (Weighted Likelihood)
  h->Fit("f", "R0WL");  // <-- causes segmentation fault in ROOT 6.30/02

  // For comparison, this line with "L" only works fine
  h->Fit("f", "R0L");   // <-- runs fine, no crash

  h->Draw("E");
}

I saw your suggestion to retry using ROOT 6.34 binaries.
Unfortunately, I am working in a virtual machine environment on a shared system at a national lab, where installing or switching to custom binaries is very restricted and complicated. At the moment, testing on 6.34 is not feasible.
Here is my root version that I used for this WLLE method
ROOT Version: 6.30/02
Built for linuxx8664gcc on Dec 20 2023
From heads/master@tags/v6-30-02

  1. Has the internal behavior of TH1::Fit(..., "WL") changed in recent ROOT versions (e.g., 6.30+) such that it no longer tolerates σ = 0 and instead segfaults immediately?
  2. Was any fallback behavior removed recently that used to handle zero errors gracefully?
  3. Is it now recommended for users to manually enforce σ > 0 in all bins when using "WL"?

This issue did not occur two years ago in my earlier analysis. If this change is intentional, I will adopt a workaround. But if it is unintended, I hope the minimal example helps in debugging.

Thank you very much for your help and continued support!

Best regards,

For your reference, two years ago, I received expert advice on this method here:
:link: [ROOT Forum: Weighted Log-Likelihood Estimation for Low-Statistics Binned Histogram]([Weighted log likelihood estimation for low statistics binned histogram - #3 by moneta])

This issue is significant for our analysis because we are using Weighted Log-Likelihood Estimation (WLLE) on time histograms where bin entries are Poisson distributed counts with weighting. The WLLE method helps retain statistical power while accounting for per-bin uncertainties properly. So, I really need your help!

Thank you

Byungchul Yu

I tried your “minimal_reproducer” (with the ROOT binaries that I have here), and I can confirm that it works with “root_v6.26.10”, “root_v6.26.14”, “root_v6.26.16”, and then with “root_v6.30.08”, “root_v6.32.12”, and “root_v6.34.08”. It does not work with “root_v6.28.06”, “root_v6.28.12”, and “root_v6.30.04”.

The segfault you are seeing was fixed on [math][fitter] Fix crash when doing a weighted likelihood fit · root-project/root@65afe27 · GitHub (between Jan 30 2024 and Feb 1 2024).

So you have two solutions:

  • build from source 6.30.02 and apply this patch
  • Use 6.30.08 binary as @Wile_E_Coyote said