Problem Loading Histogram from a file

Hello all,

I have a very very strange problem that is making me completely crazy…

I have 1 TH3D in a root file. (this file has been produced with CMSSW_2_2_9). When I open the file with bare root, I can see the histogram and display it…

root out -l
TBrowser b
Then I draw my histo (and I see the 3D histogram → not empty histogram)

But when I am trying to load the histogram using a root macro :
I have problems…

I can open the file, and get the histograms without problem…
I can get the number of entries in the histograms (~10^7)…

but when I am scanning all the bins (including under and over flow bins) of the histograms in order to print out the content of the bins…
I always get 0 entries in the bin (for all the bins…) even if the Number of entries is not 1.
When I try to draw this histograms… I just have an empty canvas (with the yellow frame arround).

Do you have any Idea?

I tried to open a similar root file produced in CMSSW_3_1_0_pre6, and with this one I have no problems…
So I do not really understand the problem…
(and since I can plot the histo using a TBrowser I guess all the content is well in the file… so how can I acces it?)

Many thanks In advance for help,
Loic,

If you want to check the file :
It is available on my afs area on lxplus :
~querten/public/out.root

Hi,

What is the code you use to retrieve the histogram and scan its content?

Philippe.

Oooopps…
I forgot the code :wink:

Here it is :
(I tried different things that are now commented)

void Macro(){

    TFile* Input = new TFile("file:out.root");
    TH3D* Charge_Vs_Path = (TH3D*)Input->Get("Charge_Vs_Path");

// Charge_Vs_Path = (TH3D*)((TH3D*)(Input->FindObjectAny(“Charge_Vs_Path”)))->Clone();
printf(“LOADING AN HISTO WITH %g ENTRIES\n”,Charge_Vs_Path->GetEntries());

for(int ix=0; ix<Charge_Vs_Path->GetNbinsX(); ix++){
for(int iy=0; iy<Charge_Vs_Path->GetNbinsY(); iy++){
for(int iz=0; iz<Charge_Vs_Path->GetNbinsZ(); iz++){
if( Charge_Vs_Path->GetBinContent(ix,iy,iz)>0)printf("%i %i %i --> %f\n",ix,iy, iz, Charge_Vs_Path->GetBinContent(ix,iy,iz));
}
}
}

Charge_Vs_Path->Draw();

Input->Close();
}

do you also want the code I used to write the file?

The version of root is 5.18/00a in CMSSW_2_2_9 and 5.22/00a in CMSSW_3_1_X

[code]Charge_Vs_Path->Draw();

Input->Close();
} [/code]When you close the file, the histogram that are attached to the file are deleted … and by default histogram attached themselves to the current directory upon their creation and/or are attached to the file they are read from. In your case you probably simply detach the histogram:[code]Charge_Vs_Path->Draw();
Charge_Vs_Path->SetDirectory(0);

Input->Close();
} [/code]

Cheers,
Philippe.

Hello Philippe,

I can now indeed draw the histogram…

BUT

I still have no BinContent different than 0 for this histogram…
So when I do :
if( Charge_Vs_Path->GetBinContent(ix,iy,iz)>0)printf("%i %i %i --> %f\n",ix,iy, iz, Charge_Vs_Path->GetBinContent(ix,iy,iz));

Nothing is printed…
this is actually the major problem… (the draw was just there in order to figure out why GetBinContent(ix,iy,iz) returns 0 for every ix, iy, iz…

Thanks for helping me with this…

Best Regards,
Loic

Hi,

What does Charge_Vs_Path->Print(“all”)
shows?

Philippe.

it shows many stuff…

wich seems to be to be correct…
(at least I have some entries wich are not 0)


fSumw[0][9][401]=0, x=-4999.5, y=0.625, z=4005
fSumw[1][9][401]=309, x=4999.5, y=0.625, z=4005
fSumw[2][9][401]=0, x=14998.5, y=0.625, z=4005
fSumw[0][10][401]=0, x=-4999.5, y=0.675, z=4005
fSumw[1][10][401]=220, x=4999.5, y=0.675, z=4005
fSumw[2][10][401]=0, x=14998.5, y=0.675, z=4005
fSumw[0][11][401]=0, x=-4999.5, y=0.725, z=4005
fSumw[1][11][401]=143, x=4999.5, y=0.725, z=4005
fSumw[2][11][401]=0, x=14998.5, y=0.725, z=4005
fSumw[0][12][401]=0, x=-4999.5, y=0.775, z=4005
fSumw[1][12][401]=85, x=4999.5, y=0.775, z=4005
fSumw[2][12][401]=0, x=14998.5, y=0.775, z=4005
fSumw[0][13][401]=0, x=-4999.5, y=0.825, z=4005
fSumw[1][13][401]=40, x=4999.5, y=0.825, z=4005
fSumw[2][13][401]=0, x=14998.5, y=0.825, z=4005
fSumw[0][14][401]=0, x=-4999.5, y=0.875, z=4005
fSumw[1][14][401]=27, x=4999.5, y=0.875, z=4005
fSumw[2][14][401]=0, x=14998.5, y=0.875, z=4005
fSumw[0][15][401]=0, x=-4999.5, y=0.925, z=4005
fSumw[1][15][401]=12, x=4999.5, y=0.925, z=4005
fSumw[2][15][401]=0, x=14998.5, y=0.925, z=4005
fSumw[0][16][401]=0, x=-4999.5, y=0.975, z=4005

But why GetBinContent doesn’t work?

Loic,

Can you send me the root file?

Philippe.

Here it is :
fynu.ucl.ac.be/users/l.quert … P/out.root

Loic,

Hi,

You need:

for(int ix=0; ix<= (Charge_Vs_Path->GetNbinsX() + 1); ix++){ for(int iy=0; iy<= (Charge_Vs_Path->GetNbinsY() + 1); iy++){ for(int iz=0; iz<= (Charge_Vs_Path->GetNbinsZ() + 1); iz++){

Cheers,
Philippe.

Shame on me… :blush:
(I spent the day on this…)

Many Many thanks,

Loic