# How to find ex and ey in for error bar

**URL:** <https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426>\
**Category:** Newbie\
**Created:** [January 4, 2020, 1:50pm UTC](https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426 "2020-01-04T13:50:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abh](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c68b51/32.png) [@Abh](https://root-forum.cern.ch/u/Abh)\
**Post date:** [January 4, 2020, 1:50pm UTC](https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426/1 "2020-01-04T13:50:06Z")

</div>

HI !  
I am plotting graphs with error bars. I am following examples from internet. But I can not understand how to get the ex value and ey value to have the bars. I have given some of my codes here . Thanks

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [January 4, 2020, 2:13pm UTC](https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426/2 "2020-01-04T14:13:12Z")

</div>

Hi,  
first off, you use `ex` and `ey` in the constructor, but you never define these two:

> [@Abh](#):
>
> `TGraphErrors *g2=new TGraphErrors(4,bn,MEAN_N_P,ex,ey);`

Then you have to set errors manually for every single point you have, like e.g.  
`g2->SetPointError(i, ex[i], ey[i]);`

---

<div class="post-metadata">

**Author:** ![Abh](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c68b51/32.png) [@Abh](https://root-forum.cern.ch/u/Abh)\
**Post date:** [January 4, 2020, 2:28pm UTC](https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426/3 "2020-01-04T14:28:45Z")

</div>

ooo, Thanks.  
But I defined ex and ey like this;  
double ex[4] = {0.0,0.0,0.0,0.0};  
double ey[4] = {1, 0.5, 1, 0.5}; But clearly the bars are wrong.

---

<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 4, 2020, 2:34pm UTC](https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426/4 "2020-01-04T14:34:15Z")

</div>

Try: `g2->Draw("AP"); // "AP" or "APZ"`

---

<div class="post-metadata">

**Author:** ![Abh](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c68b51/32.png) [@Abh](https://root-forum.cern.ch/u/Abh)\
**Post date:** [January 4, 2020, 2:36pm UTC](https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426/5 "2020-01-04T14:36:00Z")

</div>

Thanks,  
but nope…the line is vanished.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [January 4, 2020, 2:39pm UTC](https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426/6 "2020-01-04T14:39:13Z")

</div>

What do you mean by “the error bars are wrong”? They seem perfectly fine to me…

---

<div class="post-metadata">

**Author:** ![Abh](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c68b51/32.png) [@Abh](https://root-forum.cern.ch/u/Abh)\
**Post date:** [January 4, 2020, 2:48pm UTC](https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426/7 "2020-01-04T14:48:11Z")

</div>

I mean I just gave the values like double ey[4] = {1, 0.5, 1, 0.5}; .  
I think I should get the errors somehow. Not like i put some values randomly.

---

<div class="post-metadata">

**Author:** ![Abh](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c68b51/32.png) [@Abh](https://root-forum.cern.ch/u/Abh)\
**Post date:** [January 4, 2020, 2:49pm UTC](https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426/8 "2020-01-04T14:49:27Z")

</div>

☹ Nope. The line get vanished.

---

<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 4, 2020, 2:55pm UTC](https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426/9 "2020-01-04T14:55:49Z")

</div>

Yes, it is YOUR responsibility to calculate / set proper errors.

---

<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 4, 2020, 3:36pm UTC](https://root-forum.cern.ch/t/how-to-find-ex-and-ey-in-for-error-bar/37426/11 "2020-01-04T15:36:39Z")

</div>

After creating histograms (and before filling them) add:

```cpp
  Multiplicity->Sumw2(kTRUE);
  Tvm->Sumw2(kTRUE);
  SingleTM->Sumw2(kTRUE);
  NPT->Sumw2(kTRUE);

```

For your graph, you could then use something like:

```cpp
x = histo->GetMean();
ex = histo->GetMeanError();
y = histo->GetStdDev();
ey = histo->GetStdDevError();

```
