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!
{
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;
}
}
-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