# Fitting histogram with correlated systematic uncertainties

**URL:** <https://root-forum.cern.ch/t/fitting-histogram-with-correlated-systematic-uncertainties/53185>\
**Category:** Newbie\
**Created:** [January 20, 2023, 6:51am UTC](https://root-forum.cern.ch/t/fitting-histogram-with-correlated-systematic-uncertainties/53185 "2023-01-20T06:51:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srimoy\_Bhattacharya](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/srimoy_bhattacharya/32/30269_2.png) [@Srimoy\_Bhattacharya](https://root-forum.cern.ch/u/Srimoy_Bhattacharya)\
**Post date:** [January 20, 2023, 6:51am UTC](https://root-forum.cern.ch/t/fitting-histogram-with-correlated-systematic-uncertainties/53185/1 "2023-01-20T06:51:38Z")

</div>

Dear Experts,

I am a new user. I want to perform a fit of a histogram (with variable bin width) with correlated uncertainties among the bins with the data in Root. I am struggling to implement the correlation matrix (or covariance matrix) in my code.  
Is there any sample code regarding this in the repository?

Thanks a lot in advance.

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [January 20, 2023, 10:57am UTC](https://root-forum.cern.ch/t/fitting-histogram-with-correlated-systematic-uncertainties/53185/2 "2023-01-20T10:57:17Z")

</div>

Hi @Srimoy_Bhattacharya,

Take a look at the Manual section [Fitting histograms - ROOT](https://root.cern/manual/fitting/).

Cheers,  
J.

---

<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:** [January 20, 2023, 11:03am UTC](https://root-forum.cern.ch/t/fitting-histogram-with-correlated-systematic-uncertainties/53185/3 "2023-01-20T11:03:12Z")

</div>

@jalopezg So, which example there covers the “correlated uncertainties among the bins” case?

---

<div class="post-metadata">

**Author:** ![Srimoy\_Bhattacharya](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/srimoy_bhattacharya/32/30269_2.png) [@Srimoy\_Bhattacharya](https://root-forum.cern.ch/u/Srimoy_Bhattacharya)\
**Post date:** [January 20, 2023, 1:17pm UTC](https://root-forum.cern.ch/t/fitting-histogram-with-correlated-systematic-uncertainties/53185/4 "2023-01-20T13:17:44Z")

</div>

Hi @jalopezg , I checked the link you shared.

I am not talking about the correlation among the fit parameters. I want to know how to incorporate “correlated uncertainties among the bins”.

Unfortunately, I could not find any discussion regarding this over there.

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [January 22, 2023, 9:34pm UTC](https://root-forum.cern.ch/t/fitting-histogram-with-correlated-systematic-uncertainties/53185/5 "2023-01-22T21:34:28Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> @jalopezg So, which example there covers the “correlated uncertainties among the bins” case?

Sorry, I skipped over that part.

I am sure @moneta or @jonas can shed some light here.

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [January 24, 2023, 6:12pm UTC](https://root-forum.cern.ch/t/fitting-histogram-with-correlated-systematic-uncertainties/53185/6 "2023-01-24T18:12:46Z")

</div>

Hi,  
We don’t have at the moment examples of fitting data where the points have correlated errors.  
You need in this case to write yourself the Chi-square function using the correlation matrix.  
We have however some example on fitting a user provided method, like this one fitting a 3D line to 3D points ([ROOT: tutorials/fit/line3Dfit.C File Reference](https://root.cern.ch/doc/master/line3Dfit_8C.html)).

Best regards

Lorenzo
