# TH3F Binning

Hi every body,

I’m using TH3F with weighted bins to get some spatial distribution…

Then I use TH3F -> GetBinContent(x,y,z) to read my weight back…
But this function always return 1 and not the value.

Then I tried to save my TH3 as a macro c1.C
In the macro I can see TH3F->SetBinContent(binnumber,weight);

So I have two questions:

1. Why does the first function return 1
2. What is the correlation between binnumber and bin number in x, y and z?

Thank you for your help

Could you provide the shortest possible RUNNING script showing your problem?
see doc of TH1 at :http://root.cern.ch/root/html/TH1.html
and see section “Convention for numbering bins”

Rene

Here are more details:

In my case I cover a region of space with:
-160 < x < 100 mm with 261 bins
-180 < y < 20 mm with 201 bins
-40 < z < 100 mm with 141 bins.

I need the bin content for a position (x,y,z)

So I should do:

binnumber = TH3F -> GetBin(binx,biny,binz);

bincontent = TH3F -> GetBinContent(binnumber);

or directly

bincontent = TH3F -> GetBincontent(binx,biny,binz);

But in each case bincontent is always 1. Why?

Then I used the fact:
Spatial->SetBinContent(47236,8.651172); (obtained from the saving to c1.C)

So I did:
binnumber = TH3F -> GetBin(binx,biny,binz); for all binx, biny, binz
bincontent = TH3F -> GetBinContent(binnumber);

if(binnumber == 47236) cout << bincontent << endl;

But no bincontent appear in terminal…

Here is the code it self:

TH1 *Spatial = new TH3F(“Spatial”,“Distribution spatiale de puissance”,261,-160,100,201,-180,20,121,-40,80);
Spatial->SetBinContent(47236,8.651172);

Spatial->SetEntries(1.172108e+07);

Double_t binc(0.);
Double_t binc2(0.);
Int_t binno(0.), binno2(0.);
for(int x=1; x < 262; x++)
{
for(int y=1; y < 202; y++)
{
for(int z=1; z < 192; z++)
{
binno = Spatial->GetBin(x,y,z);
//cout << binno << endl;
//binc = (Double_t)Spatial -> GetBinContent(x,y,z);
binc2 = (Double_t)Spatial -> GetBinContent(binno);

``````       if(binno == 47236) cout << "The Binc : " << binc2 << endl;
//cout << binc << endl;
if(binc =! 0. && binno2==0)
{
cout << (x) << "\t" << (y) << "\t" << (z) << "\t" << binc << endl;  // give the position in bin number
cout << (x-160) << "\t" << (y-180) << "\t" << (z-40) << "\t" << binc << endl; // give the position in mm
//outputfile << (x-160) << "\t" << (y-180) << "\t" << (z-40) << "\t" << binc << endl;
binno2=1;
}
}
}
}
``````

outputfile.close();
c2.C (1.52 KB)

My problem seems to be fixed…

But I’m unable to say why…

Sorry

Sincerely