Same TH1F fetched from different TFiles

hi all

i’m using root version 5.22/00d (or 5.24/00) and i’m encountering a mind-blasting conundrum. i have a c++ program which has the aim of reading a series of .root files, fetch histograms contained in those files, draw them on TCanvases and save them. for each plot it intends to make, the program will open each file and look for the corresponding histogram: mind that files have different names, but i look for histograms with the same name in each file.

i’m attaching a simple macro (micromacro.C) and two .root files. when loaded in interpreter mode, the macro works correctly and the two saved eps files show that the two histograms contained in the two files are different.

now, the problem arises when using the full c++ program. i’m attaching a tar with a simplified version of the program which reproduces the error. please follow these instructions:

tar xvf SAMETH1FPROBLEM.tar
make drawPhotonJet_2bkg
./drawPhotonJet_2bkg EG QCD_Spring10 PhotonJet_Summer1036X pf akt5 SHAPE

this will produce two eps files (h0 and h1) which (at least in my case) contain the same histogram.

if you check lines 201-215 of DrawBase.C (and compare to what is printed on the standard out while the program is running) the two histograms should be taken by two different files, and should therefore be different (just as micromacro.C does).

any ideas?

thanks
f
SAMETH1FPROBLEM.tar (250 KB)

Hi,

the problem is that you get the histogram from file EG in line DrawBase.C:171, while the current directory is set to the file Summer1036X. This registers the histogram from EG in Summer1036X; a subsequent Summer1036X->Get() will return the histogram from EG.

I also don’t like this auto-registration of histograms with their current directory (but it’s there for backward compatibility, historically motivated by PAW). You can simply turn it off by calling TH1::AddDirectory(kFALSE) at the beginning of your program. I checked, with that your code works just fine.

Cheers, Axel.

great! it works!

thanks a lot
f