# Variable Bins

**URL:** <https://root-forum.cern.ch/t/variable-bins/49318>\
**Category:** Newbie\
**Created:** [March 23, 2022, 8:05am UTC](https://root-forum.cern.ch/t/variable-bins/49318 "2022-03-23T08:05:46Z")\
**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 23, 2022, 8:05am UTC](https://root-forum.cern.ch/t/variable-bins/49318/1 "2022-03-23T08:05:46Z")

</div>

I am new to root,  
I have used a variable bins in my histogram but instead the bins it shifted my histogram to right.  
‘’’  
const Int\_t NBINS = 42;  
Double\_t edges[NBINS + 1] =.  
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10,10,10,10,10,10,10,25,25,25,25,25,25};

```
TH1D* hist = new TH1D("hist", "",NBINS, 6, 250);

```

‘’’

---

<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 23, 2022, 8:34am UTC](https://root-forum.cern.ch/t/variable-bins/49318/2 "2022-03-23T08:34:49Z")

</div>

The bin `edges` should be: `{0., 1., 2., 3., ..., 200., 225., 250.}`  
Then: `TH1D("hist", "", NBINS, edges)`

---

<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 23, 2022, 8:49am UTC](https://root-forum.cern.ch/t/variable-bins/49318/3 "2022-03-23T08:49:46Z")

</div>

It didn’t help constructed the variable bins.

---

<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 23, 2022, 8:56am UTC](https://root-forum.cern.ch/t/variable-bins/49318/4 "2022-03-23T08:56:04Z")

</div>

```cpp
{
  Double_t edges[] = {0., 1., 2., 3., 10., 20., 30., 200., 225., 250.};
  const Int_t NBINS = sizeof(edges) / sizeof(Double_t) - 1;
  TH1D *hist = new TH1D("hist", "", NBINS, edges);
  hist->FillRandom("pol0", 1000);
  hist->Draw();
}

```

---

<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 23, 2022, 9:02pm UTC](https://root-forum.cern.ch/t/variable-bins/49318/5 "2022-03-23T21:02:24Z")

</div>

It helped construct the variable bin size but still shift the histogram to left.

Thank You.  
[CurrentAnalysis.C](https://root-forum.cern.ch/uploads/short-url/8TEENSvES5hAYoWrqt1I8pGUp2J.C) (2.1 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 24, 2022, 8:06am UTC](https://root-forum.cern.ch/t/variable-bins/49318/6 "2022-03-24T08:06:52Z")

</div>

We do not have your data file to run your macro.

---

<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:41pm UTC](https://root-forum.cern.ch/t/variable-bins/49318/8 "2022-03-24T14:41:26Z")

</div>

The file is larger than 3MB so could not upload it.

> **[Google Drive stellt sich vor – Alle Ihre Dateien an einem Ort](https://accounts.google.com/ServiceLogin?service=wise&passive=1209600&continue=https:%2F%2Fdrive.google.com%2Fdrive%2Ffolders%2F1YHbmzzlv1ox9jwBic5N6p12fBfJbsyEQ&followup=https:%2F%2Fdrive.google.com%2Fdrive%2Ffolders%2F1YHbmzzlv1ox9jwBic5N6p12fBfJbsyEQ)**
>
> Mit Google Drive können Sie Dateien kostenlos sichern und einfach auf Ihre Daten über ein Telefon, Tablet oder einen Computer zugreifen. Nutzen Sie kostenlos 15 GB Speicherplatz in Google.
