# Bin navigation and assignment for TH3D

**URL:** <https://root-forum.cern.ch/t/bin-navigation-and-assignment-for-th3d/35634>\
**Category:** Newbie\
**Created:** [August 14, 2019, 8:53am UTC](https://root-forum.cern.ch/t/bin-navigation-and-assignment-for-th3d/35634 "2019-08-14T08:53:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dave](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://root-forum.cern.ch/u/dave)\
**Post date:** [August 14, 2019, 8:53am UTC](https://root-forum.cern.ch/t/bin-navigation-and-assignment-for-th3d/35634/1 "2019-08-14T08:53:16Z")

</div>

Hi. I’m trying to retrieve information from a 3D histogram and getting confused with the output.

So I’m using the code below to generate a 2x2x2 histogram and fill one of the bins positioned at (0,1,0) with 1.  
To output the contents (included below) I get the number of bins (64 due to overflow in this case) and output the centre position and content of the bins.  
But the bin with the value of 1 returns a position of (40.5, 41.5, 40.5) instead of somewhere close to (0,1,0). Also I would of expected the maximum range to be 3 from overflow not 63.5.

Can someone explain how the positions are assigned for TH3D?

Thanks!

```auto
{
	int noBins3Dx = 2;
	int noBins3Dy = 2;
	int noBins3Dz = 2;
 
	double min3Dx = -1.;
	double max3Dx = 1.;
	double min3Dy = 0;
	double max3Dy = 2.;
	double min3Dz = -1.;
	double max3Dz = 1.;
 
  TH3D* edep3D = new TH3D("e1", "edep3D", noBins3Dx, min3Dx, max3Dx, noBins3Dy, min3Dy,max3Dy, noBins3Dz, min3Dz, max3Dz);
  double value = 1;
  edep3D->Fill(0.,1.,0.,value);
  
  int noOfBins = edep3D->GetSize();
  cout << "No of bins = " << noOfBins << endl;
  for (int i = 1; i <= noOfBins; i++)
  {
    cout << edep3D->GetXaxis()->GetBinCenter(i)<< "\t" << edep3D->GetYaxis()->GetBinCenter(i) << "\t" <<edep3D->GetZaxis()->GetBinCenter(i) << "\t" << edep3D->GetBinContent(i) << endl;
  }
}

```

```auto
-0.5 0.5 -0.5 0
0.5 1.5 0.5 0
1.5 2.5 1.5 0
2.5 3.5 2.5 0
3.5 4.5 3.5 0
4.5 5.5 4.5 0
5.5 6.5 5.5 0
6.5 7.5 6.5 0
7.5 8.5 7.5 0
8.5 9.5 8.5 0
9.5 10.5 9.5 0
10.5 11.5 10.5 0
11.5 12.5 11.5 0
12.5 13.5 12.5 0
13.5 14.5 13.5 0
14.5 15.5 14.5 0
15.5 16.5 15.5 0
16.5 17.5 16.5 0
17.5 18.5 17.5 0
18.5 19.5 18.5 0
19.5 20.5 19.5 0
20.5 21.5 20.5 0
21.5 22.5 21.5 0
22.5 23.5 22.5 0
23.5 24.5 23.5 0
24.5 25.5 24.5 0
25.5 26.5 25.5 0
26.5 27.5 26.5 0
27.5 28.5 27.5 0
28.5 29.5 28.5 0
29.5 30.5 29.5 0
30.5 31.5 30.5 0
31.5 32.5 31.5 0
32.5 33.5 32.5 0
33.5 34.5 33.5 0
34.5 35.5 34.5 0
35.5 36.5 35.5 0
36.5 37.5 36.5 0
37.5 38.5 37.5 0
38.5 39.5 38.5 0
39.5 40.5 39.5 0
40.5 41.5 40.5 1
41.5 42.5 41.5 0
42.5 43.5 42.5 0
43.5 44.5 43.5 0
44.5 45.5 44.5 0
45.5 46.5 45.5 0
46.5 47.5 46.5 0
47.5 48.5 47.5 0
48.5 49.5 48.5 0
49.5 50.5 49.5 0
50.5 51.5 50.5 0
51.5 52.5 51.5 0
52.5 53.5 52.5 0
53.5 54.5 53.5 0
54.5 55.5 54.5 0
55.5 56.5 55.5 0
56.5 57.5 56.5 0
57.5 58.5 57.5 0
58.5 59.5 58.5 0
59.5 60.5 59.5 0
60.5 61.5 60.5 0
61.5 62.5 61.5 0
62.5 63.5 62.5 0

```

---

<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:** [August 14, 2019, 8:55am UTC](https://root-forum.cern.ch/t/bin-navigation-and-assignment-for-th3d/35634/2 "2019-08-14T08:55:39Z")

</div>

Search for “global bin” in the [TH1](https://root.cern.ch/doc/master/classTH1.html) class reference.

---

<div class="post-metadata">

**Author:** ![dave](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://root-forum.cern.ch/u/dave)\
**Post date:** [August 14, 2019, 9:31am UTC](https://root-forum.cern.ch/t/bin-navigation-and-assignment-for-th3d/35634/3 "2019-08-14T09:31:22Z")

</div>

Ohh I see… Thanks!
