# \[question\] GetBinContent

**URL:** <https://root-forum.cern.ch/t/question-getbincontent/39118>\
**Category:** Newbie\
**Created:** [April 27, 2020, 9:41am UTC](https://root-forum.cern.ch/t/question-getbincontent/39118 "2020-04-27T09:41:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaggylee](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@Shaggylee](https://root-forum.cern.ch/u/Shaggylee)\
**Post date:** [April 27, 2020, 9:41am UTC](https://root-forum.cern.ch/t/question-getbincontent/39118/1 "2020-04-27T09:41:41Z")

</div>

![dd](https://root-forum.cern.ch/uploads/default/original/3X/e/9/e9cf69cd7b4f359791ae036e09172a242ffe16e6.png)  
Hello ROOTers…

```auto
TCanvas *c3 = new TCanvas("c3", "residual", 1200, 900);
TH1F *h1 = new TH1F("h1", "residual", 40, 400, 1200);
hQtot_Bi->SetNormFactor(1);
hQtot_Bi_d->SetNormFactor(1);
for(Int_t i=1; i<=1200; i++) {
    if (i<400) continue;
    Double_t res = ((hQtot_Bi_d->GetBinContent(i) - hQtot_Bi->GetBinContent(i))/hQtot_Bi->GetBinContent(i))*100;
    h1->SetBinContent(i, res);
    cout << "i = " << i << ", res = " << res << endl;
 }
 h1->SetLineColor(kBlack);
 h1->SetLineWidth(2);
 h1->SetStats(0);
 h1->Draw();

```

I want to get ‘res’ related to hQtot\_Bi(blue line) and hQtot\_Bi\_d(black dots) and plot them. I am trying to plot through ‘res’ of the code. However, when I output the res value, all the same values came out. How can it be solved?

ex) i = 400, res = -94.5654 … i = 1200, res = -94.5654

---

<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:** [April 27, 2020, 9:46am UTC](https://root-forum.cern.ch/t/question-getbincontent/39118/2 "2020-04-27T09:46:14Z")

</div>

`for(Int_t i = 1; i <= h1->GetNbinsX(); i++) {`

BTW. See “Convention for numbering bins” in: [TH1](https://root.cern/doc/master/classTH1.html)

---

<div class="post-metadata">

**Author:** ![Shaggylee](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@Shaggylee](https://root-forum.cern.ch/u/Shaggylee)\
**Post date:** [April 27, 2020, 9:54am UTC](https://root-forum.cern.ch/t/question-getbincontent/39118/3 "2020-04-27T09:54:12Z")

</div>

Oh… I got it.  
Thank you so much!!
