# Relative error of the ratio

**URL:** <https://root-forum.cern.ch/t/relative-error-of-the-ratio/51317>\
**Category:** Newbie\
**Created:** [August 24, 2022, 1:29pm UTC](https://root-forum.cern.ch/t/relative-error-of-the-ratio/51317 "2022-08-24T13:29:21Z")\
**Posts on this page:** 1\
**Showing post:** 6

<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:** [August 24, 2022, 2:43pm UTC](https://root-forum.cern.ch/t/relative-error-of-the-ratio/51317/6 "2022-08-24T14:43:53Z")

</div>

```cpp
TH2F *h_ratio_error = (TH2F*)h_ratio->Clone("h_ratio_error");
for (int i = 0; i < h_ratio_error->GetSize(); i++)
  h_ratio_error->GetArray()[i] = (h_ratio_error->GetBinContent(i) ? h_ratio_error->GetBinError(i) / h_ratio_error->GetBinContent(i) : 0.);
h_ratio_error->Sumw2(kFALSE);
// h_ratio_error->ResetStats();

```

BTW. See also the older thread: “[Error calculation of 2D histogram](https://root-forum.cern.ch/t/error-calculation-of-2d-histogram/50712/3)”

---

_[View the full topic](https://root-forum.cern.ch/t/relative-error-of-the-ratio/51317)._
