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

**URL:** <https://root-forum.cern.ch/t/segmentation-fault-in-th1-fit-using-wl-option-in-root-6-30-x-was-the-poisson-likelihood-behavior-recently-made-stricter/63335>\
**Category:** ROOT\
**Created:** [April 8, 2025, 4:58pm UTC](https://root-forum.cern.ch/t/segmentation-fault-in-th1-fit-using-wl-option-in-root-6-30-x-was-the-poisson-likelihood-behavior-recently-made-stricter/63335 "2025-04-08T16:58:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Byungchul\_Yu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/byungchul_yu/32/31421_2.png) [@Byungchul\_Yu](https://root-forum.cern.ch/u/Byungchul_Yu)\
**Post date:** [April 8, 2025, 4:58pm UTC](https://root-forum.cern.ch/t/segmentation-fault-in-th1-fit-using-wl-option-in-root-6-30-x-was-the-poisson-likelihood-behavior-recently-made-stricter/63335/1 "2025-04-08T16:58:34Z")

</div>

Hello,

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

```auto
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](https://github.com/root-project/root/blob/master/math/mathcore/src/FitUtil.cxx#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

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [April 8, 2025, 6:09pm UTC](https://root-forum.cern.ch/t/segmentation-fault-in-th1-fit-using-wl-option-in-root-6-30-x-was-the-poisson-likelihood-behavior-recently-made-stricter/63335/2 "2025-04-08T18:09:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Byungchul\_Yu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/byungchul_yu/32/31421_2.png) [@Byungchul\_Yu](https://root-forum.cern.ch/u/Byungchul_Yu)\
**Post date:** [April 9, 2025, 8:35pm UTC](https://root-forum.cern.ch/t/segmentation-fault-in-th1-fit-using-wl-option-in-root-6-30-x-was-the-poisson-likelihood-behavior-recently-made-stricter/63335/3 "2025-04-09T20:35:29Z")

</div>

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:

```cpp
// 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,

---

<div class="post-metadata">

**Author:** ![Byungchul\_Yu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/byungchul_yu/32/31421_2.png) [@Byungchul\_Yu](https://root-forum.cern.ch/u/Byungchul_Yu)\
**Post date:** [April 9, 2025, 8:43pm UTC](https://root-forum.cern.ch/t/segmentation-fault-in-th1-fit-using-wl-option-in-root-6-30-x-was-the-poisson-likelihood-behavior-recently-made-stricter/63335/4 "2025-04-09T20:43:07Z")

</div>

For your reference, two years ago, I received expert advice on this method here:  
🔗 [ROOT Forum: [Weighted Log-Likelihood Estimation for Low-Statistics Binned Histogram](https://root-forum.cern.ch/t/weighted-log-likelihood-estimation-for-low-statistics-binned-histogram/58191/5)]([[Weighted log likelihood estimation for low statistics binned histogram - #3 by moneta](https://root-forum.cern.ch/t/weighted-log-likelihood-estimation-for-low-statistics-binned-histogram/58191/3)])

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

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 10, 2025, 6:42am UTC](https://root-forum.cern.ch/t/segmentation-fault-in-th1-fit-using-wl-option-in-root-6-30-x-was-the-poisson-likelihood-behavior-recently-made-stricter/63335/5 "2025-04-10T06:42:28Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [April 10, 2025, 6:44am UTC](https://root-forum.cern.ch/t/segmentation-fault-in-th1-fit-using-wl-option-in-root-6-30-x-was-the-poisson-likelihood-behavior-recently-made-stricter/63335/6 "2025-04-10T06:44:53Z")

</div>

The segfault you are seeing was fixed on [[math][fitter] Fix crash when doing a weighted likelihood fit · root-project/root@65afe27 · GitHub](https://github.com/root-project/root/commit/65afe2739e27ee6ccb7c65e73d3b2c0cf5a995c2) (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

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 24, 2025, 6:45am UTC](https://root-forum.cern.ch/t/segmentation-fault-in-th1-fit-using-wl-option-in-root-6-30-x-was-the-poisson-likelihood-behavior-recently-made-stricter/63335/7 "2025-04-24T06:45:22Z")

</div>

Closed on April 24, 2025, 6:45am UTC

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