# Histogram with \[x,y) bin and store in tree

**URL:** <https://root-forum.cern.ch/t/histogram-with-x-y-bin-and-store-in-tree/44045>\
**Category:** Newbie\
**Created:** [March 18, 2021, 5:25am UTC](https://root-forum.cern.ch/t/histogram-with-x-y-bin-and-store-in-tree/44045 "2021-03-18T05:25:54Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![matt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/matt/32/30804_2.png) [@matt](https://root-forum.cern.ch/u/matt)\
**Post date:** [March 22, 2021, 1:08pm UTC](https://root-forum.cern.ch/t/histogram-with-x-y-bin-and-store-in-tree/44045/22 "2021-03-22T13:08:56Z")

</div>

Yes, the “TEXT” option are centred.  
Okay, let me try again.  
But, I think GetBinCenter(i) on “he” after SetBinContent( ) doesn’t seems to work.  
It shows an error "use of undeclared identifier ‘i’.

Thank you very much.

---

<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 22, 2021, 4:58pm UTC](https://root-forum.cern.ch/t/histogram-with-x-y-bin-and-store-in-tree/44045/23 "2021-03-22T16:58:41Z")

</div>

Try with:

```cpp
unsigned long n_stats_error = sizeof(stats_error) / sizeof(double);
std::cout << "Number of errors data points :" << n_stats_error << std::endl;

if (n_stats_error != (n_pz_bins * n_pT_bins)) {
  std::cout << "Error: incorrect number of data points." << std::endl;
  return;
}

for (int k = 1; k <= n_pz_bins; k++)
  for (int l = 1; l <= n_pT_bins; l++)
    he->SetBinContent(k, l, stats_error[((k - 1) * n_pT_bins + (l - 1))]);

he->SetStats(kFALSE);
Double_t xmin = he->GetXaxis()->GetXmin();
Double_t xmax = he->GetXaxis()->GetXmax();
Double_t ymin = he->GetYaxis()->GetXmin();
Double_t ymax = he->GetYaxis()->GetXmax();

#if 0 /* 0 or 1 */
xmin = 0.30, xmax = 0.999999 * 68.00;
xmin = he->GetXaxis()->GetBinLowEdge(he->GetXaxis()->FindFixBin(xmin));
xmax = he->GetXaxis()->GetBinUpEdge(he->GetXaxis()->FindFixBin(xmax));
he->GetXaxis()->SetRangeUser(xmin, xmax);
ymin = 0.00, ymax = 0.999999 * 0.50;
ymin = he->GetYaxis()->GetBinLowEdge(he->GetYaxis()->FindFixBin(ymin));
ymax = he->GetYaxis()->GetBinUpEdge(he->GetYaxis()->FindFixBin(ymax));
he->GetYaxis()->SetRangeUser(ymin, ymax);
#endif /* 0 or 1 */

c2->cd();
gStyle->SetPalette(70);
he->Draw("COLZ");

for (int k = 1; k <= n_pz_bins; k++)
  for (int l = 1; l <= n_pT_bins; l++) {
    Double_t v = he->GetBinContent(k, l);
    if (!(v > 0.0)) continue; // skip "empty" bins
    Double_t x = he->GetXaxis()->GetBinCenter(k);
    Double_t y = he->GetYaxis()->GetBinCenter(l);
    if ((x < xmin) || (x > xmax) || (y < ymin) || (y > ymax)) continue;
    Int_t marker = kFullCircle;
    Double_t size = 0.7;
    if (v >= 5.0) {
      marker = kPlus; size = 0.6;
    } else if (v >= 2.5) {
      marker = kCircle; size = 0.6;
    }
    TMarker *m = new TMarker(x, y, marker);
    m->SetMarkerSize(size);
    m->Draw();
  }

c2->Modified(); c2->Update();

```

---

<div class="post-metadata">

**Author:** ![matt](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/matt/32/30804_2.png) [@matt](https://root-forum.cern.ch/u/matt)\
**Post date:** [March 22, 2021, 6:45pm UTC](https://root-forum.cern.ch/t/histogram-with-x-y-bin-and-store-in-tree/44045/24 "2021-03-22T18:45:30Z")

</div>

I’m really grateful for you help.

Thank you very much.  
Appreciate it.

[Previous page](https://root-forum.cern.ch/t/histogram-with-x-y-bin-and-store-in-tree/44045.md?page=1)
