# Plot Calculated Errors in an existing Histogram

**URL:** <https://root-forum.cern.ch/t/plot-calculated-errors-in-an-existing-histogram/51192>\
**Category:** Newbie\
**Created:** [August 15, 2022, 10:39am UTC](https://root-forum.cern.ch/t/plot-calculated-errors-in-an-existing-histogram/51192 "2022-08-15T10:39:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankur](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ankur/32/28486_2.png) [@Ankur](https://root-forum.cern.ch/u/Ankur)\
**Post date:** [August 15, 2022, 10:39am UTC](https://root-forum.cern.ch/t/plot-calculated-errors-in-an-existing-histogram/51192/1 "2022-08-15T10:39:04Z")

</div>

I plotted the histogram given below:

```auto

h221=(TH1D*)f->Get("hrate_all_rule0");

```

I calculated the errors (_not the one produced by GetBinError, default by ROOT_) for the above histogram and stored them in:

```auto

TH1D *errACP0NH_295 =(TH1D*)sumACP0NH_295->Clone("errACP0NH_295");

```

Now I want to call the BinContent from \*\* _errACP0NH\_295_\* and plot as vertical error bars for the histogram **h221** on the same pad.

How should I do it?  
_ROOT Version:_ 6.24/02  
_Platform:_ Focal Release 20.04  
_Compiler:_ C++

---

<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:** [August 15, 2022, 11:05am UTC](https://root-forum.cern.ch/t/plot-calculated-errors-in-an-existing-histogram/51192/2 "2022-08-15T11:05:32Z")

</div>

Hi @Ankur,

In this case, you have to explicitly set the errors of `h221` to be the content of `errACP0NH_2095`:

```c++
for(int i=0 ; i <= h221->GetNbinsX() ; i++){
    h221->SetBinError(i, errACP0NH_2095->GetBinContent(i));
}

```

If you don’t want to modify the original histogram, you can create a `Clone()` of it.

Hope this helps!  
Jonas

---

<div class="post-metadata">

**Author:** ![Ankur](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ankur/32/28486_2.png) [@Ankur](https://root-forum.cern.ch/u/Ankur)\
**Post date:** [August 15, 2022, 11:15am UTC](https://root-forum.cern.ch/t/plot-calculated-errors-in-an-existing-histogram/51192/4 "2022-08-15T11:15:11Z")

</div>

Thank you @jonas for your reply. Before proceeding, let me confirm if you mean ` errACP0NH_2095->GetBinContent` instead of `errACP0NH_2095->GetBinError(i)`? My idea is that the **errors for h221** are calculated and stored in **errACP0NH\_2095**.

---

<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:** [August 15, 2022, 11:15am UTC](https://root-forum.cern.ch/t/plot-calculated-errors-in-an-existing-histogram/51192/5 "2022-08-15T11:15:57Z")

</div>

Yes, sorry that’s what I meant! I have edited my post.

---

<div class="post-metadata">

**Author:** ![Ankur](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ankur/32/28486_2.png) [@Ankur](https://root-forum.cern.ch/u/Ankur)\
**Post date:** [August 15, 2022, 11:16am UTC](https://root-forum.cern.ch/t/plot-calculated-errors-in-an-existing-histogram/51192/6 "2022-08-15T11:16:28Z")

</div>

Thank you, Get back to you shortly.

---

<div class="post-metadata">

**Author:** ![Ankur](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ankur/32/28486_2.png) [@Ankur](https://root-forum.cern.ch/u/Ankur)\
**Post date:** [August 22, 2022, 8:33am UTC](https://root-forum.cern.ch/t/plot-calculated-errors-in-an-existing-histogram/51192/7 "2022-08-22T08:33:48Z")

</div>

@jonas Sorry for the late reply. I was adding few others into my code. The technique works perfectly fine. Thank You.
