Problem adding 2D histos

Hi,
I’ve tried to send this mail before, but I think it has not reached the forum. Sorry if you get it twice!
My problem is the following:
I have two files (pippo1.root pippo2.root) containing the same 2D histo.
When I try hadd pippo.root pippo1.root pippo2.root the result has not been
added. Is this normal?

First File:

root [1] gDirectory->ls() TFile** pippo1.root TFile* pippo1.root KEY: TH2F eff_MuNoIsoJetsL3PreFiltered:_NumMu_1_Num_Jets_1;1 Efficiency (%) vs HLT Pt threshold (GeV), label=MuNoIsoJetsL3PreFiltered:_NumMu_1_Num_Jets_1 root [2] TH2* histo = (TH2*) gDirectory->Get("eff_MuNoIsoJetsL3PreFiltered:_NumMu_1_Num_Jets_1;1") root [3] histo->GetBinContent(1,1) (const Double_t)1.97900000000000000e+03

Second File:

root [2] gDirectory->ls() TFile** pippo2.root TFile* pippo2.root KEY: TH2F eff_MuNoIsoJetsL3PreFiltered:_NumMu_1_Num_Jets_1;1 Efficiency (%) vs HLT Pt threshold (GeV), label=MuNoIsoJetsL3PreFiltered:_NumMu_1_Num_Jets_1 root [3] TH2* histo = (TH2*) gDirectory->Get("eff_MuNoIsoJetsL3PreFiltered:_NumMu_1_Num_Jets_1;1") root [4] histo->GetBinContent(1,1) (const Double_t)1.97900000000000000e+03

Then I do:
hadd pippo.root pippo1.root pippo2.root
If I look at the output file it contains only 1979 events in first bin,
not 1979*2 as it should.

root [1] gDirectory->ls() TFile** pippo.root TFile* pippo.root KEY: TH2F eff_MuNoIsoJetsL3PreFiltered:_NumMu_1_Num_Jets_1;1 Efficiency (%) vs HLT Pt threshold (GeV), label=MuNoIsoJetsL3PreFiltered:_NumMu_1_Num_Jets_1 root [2] TH2* histo = (TH2*) gDirectory->Get("eff_MuNoIsoJetsL3PreFiltered:_NumMu_1_Num_Jets_1;1") root [3] histo->GetBinContent(1,1) (const Double_t)1.97900000000000000e+03

If I load both files and add the histos “by hand” (histo->Add(histo2)) the
result is OK

root [15] histo->GetBinContent(1,1) (const Double_t)3.95800000000000000e+03

Does anybody know what the problem can be?

Thank you for any help,

Silvia

Could you post your pippo1 and pippo2.root files somewhere in a public readable place?

Rene

Hi,

Thanks for your reply!
I have copied the .root files in /afs/
~goys/public/root/

Silvia

Silvia,

I have no problems merging your 2 files. The resulting 2D plot has twice as many entries than in the original files.
Could you erase pippo.root and start again or similarly do

hadd -f pippo.root pippo1.root pippo2.root
Rene

Hi Rene,

I have just tried and still getting the same problem, files merge w/o warning but the entries and bincontent are still not doubled.
I am using
ROOTSYS=/afs/cern.ch/cms/sw/slc4_ia32_gcc345/lcg/root/5.14.00g-CMS18b/

which one are you using?

Thanks again,

Silvia

Hi Silvia,

Problem understood.
Your histogram has a name that includes a blank at the end

Root [3] histo.GetName() (const char* 0x4937fa0)"eff_MuNoIsoJetsL3PreFiltered:_NumMu_1_Num_Jets_1 "

We added support for this case (mismatch between the key name and object name) in version 5.18. You can use version 5.18 to merge your histograms with hadd, or alternatively remove the trailing blank in your histogram name.

Rene