# Extracting global correlation causes a seg fault with SumW2Error

**URL:** <https://root-forum.cern.ch/t/extracting-global-correlation-causes-a-seg-fault-with-sumw2error/55138>\
**Category:** Roofit and RooStats\
**Tags:** bug, python\
**Created:** [June 1, 2023, 3:16pm UTC](https://root-forum.cern.ch/t/extracting-global-correlation-causes-a-seg-fault-with-sumw2error/55138 "2023-06-01T15:16:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [June 1, 2023, 3:16pm UTC](https://root-forum.cern.ch/t/extracting-global-correlation-causes-a-seg-fault-with-sumw2error/55138/1 "2023-06-01T15:16:03Z")

</div>

When I call `RooFitResult::globalCorr` for a variable after a fit using `SumW2Error`, I get a seg fault. I am using version 6.26/04 from the Anaconda distribution; I have only attempted this in pyROOT. Reproducer follows.

* * *

```python
import ROOT as r

ws = r.RooWorkspace("workspace")
model = ws.factory("Gaussian::model(x[0, 10], mu[5, 0, 10], sigma[2, 1, 10])")
data = model.generate(r.RooArgSet(ws.var("x")), 10_000)

res = model.fitTo(data, Save=True)
print(res.globalCorr("mu")) # no issue

res = model.fitTo(data, Save=True, SumW2Error=True)
print(res.globalCorr("mu")) # seg fault

```

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [June 1, 2023, 6:19pm UTC](https://root-forum.cern.ch/t/extracting-global-correlation-causes-a-seg-fault-with-sumw2error/55138/2 "2023-06-01T18:19:16Z")

</div>

While it’s true that there could be a clear error message, I’m afraid it’s not possible to get a sum-weights-squared-corrected version of the global correlation coefficients with the output that RooFit gets from Minuit.

As explained [in the docs](https://root.cern.ch/doc/master/classRooAbsPdf.html#a52c4a5926a161bcb72eab46890b0590e), “the corrected covariance matrix is calculated as V\_{corr} = VC^{-1}V, where V is the original covariance matrix and C is the inverse of the covariance matrix calculated using the squared weights”. So to get a corrected global correlation, you would need the full 2x2 global covariance matrices that relate to each parameter. However, we don’t know the diagonal terms, i.e. some hypothetical “global covariances”.

I guess if you _really_ need these coefficients, you could do some tedious manual procedure outside minuit, but are they absolutely required? As far as I understand, the global correlation coefficients are only used to check fit stability anyway, or am I missing something?

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [June 1, 2023, 8:34pm UTC](https://root-forum.cern.ch/t/extracting-global-correlation-causes-a-seg-fault-with-sumw2error/55138/3 "2023-06-01T20:34:32Z")

</div>

I have some fits where the parameters are often correlated, but it’s not always obvious in advance which parameters are going to have high correlations. When this happens, I wanted to pick which of them to fix (to improve fit stability/convergence) by checking which had the higher _global_ correlation.

If I understand your explanation, you cannot correct the global correlations from MINUIT because they do not comprise a correctable matrix, but couldn’t you just calculate corrected global correlations from the corrected matrix? From page 356 of the [original paper](https://www.sciencedirect.com/science/article/pii/0010465575900399), the global correlation coefficients are defined as  
\rho\_k^2 = 1 - [V\_{kk} \* (V^{-1})\_{kk}]^{-1},  
so couldn’t you just define the corrected correlation coefficients as  
(\rho\_{corr})\_k^2 = 1 - [(V\_{corr})\_{kk} \* (V\_{corr}^{-1})\_{kk}]^{-1}  
? Or does the formula break down in that case?

(In any case, yes, a sensible error would be nice. By the way, it would be nice if the `SumW2Error`-corrected errors and correlations were printed, not [just the uncorrected ones](https://root-forum.cern.ch/t/printed-error-differs-from-stored-error-when-using-sumw2error/46832/4)–it’s disorienting that the stored errors differ from the printed ones.)

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [June 1, 2023, 9:03pm UTC](https://root-forum.cern.ch/t/extracting-global-correlation-causes-a-seg-fault-with-sumw2error/55138/4 "2023-06-01T21:03:34Z")

</div>

Thanks for looking up this formula! Then my assumption of how to global correlations are computed were not correct.

So if indeed all you need to calculate them is the correlation matrix for all parameters (not some different correlation matrix after linearly combining the parameter as I thought before), then that’s certainly something we should implement in RooFit.

Can you open a GitHub issue in ROOT with a feature request on this, linking this forum thread? Then I’ll remember to implement it in the next days for the next ROOT patch release.

Thanks!

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [June 2, 2023, 12:43am UTC](https://root-forum.cern.ch/t/extracting-global-correlation-causes-a-seg-fault-with-sumw2error/55138/5 "2023-06-02T00:43:28Z")

</div>

[Done.](https://github.com/root-project/root/issues/12935)

---

<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:** [June 16, 2023, 12:43am UTC](https://root-forum.cern.ch/t/extracting-global-correlation-causes-a-seg-fault-with-sumw2error/55138/6 "2023-06-16T00:43:49Z")

</div>

Closed on June 16, 2023, 12:43am UTC

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