# Adding binomial Uncertainty in histogram

**URL:** <https://root-forum.cern.ch/t/adding-binomial-uncertainty-in-histogram/49201>\
**Category:** Newbie\
**Created:** [March 15, 2022, 5:12pm UTC](https://root-forum.cern.ch/t/adding-binomial-uncertainty-in-histogram/49201 "2022-03-15T17:12:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [March 15, 2022, 5:12pm UTC](https://root-forum.cern.ch/t/adding-binomial-uncertainty-in-histogram/49201/1 "2022-03-15T17:12:11Z")

</div>

Trying to add the binomial uncertainty in my histogram.

```cpp
for(ULong64_t i = 0; i < NumBins; i++)
    {
        Threshold = i;
        Int_t count = 0;

        for(ULong64_t e = 0; e < nEntries; e++)
            {
             currentAna->GetEntry(e);
            if( abs(Curr) < Threshold ) continue;
            {
                count++;
            }
        }
        beyondThreshold->SetBinContent(i+1, count*100/nEntries);
        cout << Threshold << "\t \t" << count << endl;
    }
    TCanvas* c2 = new TCanvas("c2");
    c2->SetLogy();
    beyondThreshold -> SetMarkerStyle(1);
    beyondThreshold->Draw();
    beyondThreshold->SetTitle("Percentage");
   // beyondThreshold->GetYaxis()->SetRangeUser(0, 0.5);
   // beyondThreshold->GetXaxis()->SetRangeUser(0, 5);
    c2->Update();

```

---

<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:** [March 15, 2022, 5:21pm UTC](https://root-forum.cern.ch/t/adding-binomial-uncertainty-in-histogram/49201/2 "2022-03-15T17:21:03Z")

</div>

> [@Plottiing a percentage in Y-axis instead of count](https://root-forum.cern.ch/t/plottiing-a-percentage-in-y-axis-instead-of-count/49158/5):
>
> At least: Double\_t(count) \* 100. / Double\_t(nEntries)

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [March 16, 2022, 5:24am UTC](https://root-forum.cern.ch/t/adding-binomial-uncertainty-in-histogram/49201/3 "2022-03-16T05:24:13Z")

</div>

I am looking to add binomial uncertainty at each threshold bins. How can I accomplish that?

---

<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:** [March 16, 2022, 8:24am UTC](https://root-forum.cern.ch/t/adding-binomial-uncertainty-in-histogram/49201/4 "2022-03-16T08:24:01Z")

</div>

I don’t really know what you want, but you can always:

```cpp
beyondThreshold->SetBinContent(i+1, Double_t(count) * 100. / Double_t(nEntries));
beyondThreshold->SetBinError(i+1, some_value_that_you_want);

```

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [March 24, 2022, 1:49am UTC](https://root-forum.cern.ch/t/adding-binomial-uncertainty-in-histogram/49201/5 "2022-03-24T01:49:56Z")

</div>

I wanted to insert a small vertical bar to show the uncertainty, but the code remove the histogram with the vertical line.

Thank You so much.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [March 24, 2022, 2:08am UTC](https://root-forum.cern.ch/t/adding-binomial-uncertainty-in-histogram/49201/6 "2022-03-24T02:08:13Z")

</div>

[https://root.cern/doc/master/classTHistPainter.html#HP09](https://root.cern/doc/master/classTHistPainter.html#HP09)

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [March 24, 2022, 2:26am UTC](https://root-forum.cern.ch/t/adding-binomial-uncertainty-in-histogram/49201/7 "2022-03-24T02:26:20Z")

</div>

Thank you for such quick response.  
It removed my histogram and give a vertical line from x-axis to point of error.
