Problem in doing Add of 2D histogram

Hi,

I am trying to add two 2D histogram but in the final histogram when I was trying to see the binContent of resultant histogram, it is showing the bincintent of last histogram. Here is the code:

import ROOT as r
file=['zzTo4L_controlPlot.root','TT_controlPlot.root']
var='2D_pt_distribution_of_Leading_#tau_SubLeading_#tau_with_totCharge!=0_in_tau1anti_iso_nofake_weight'
hist1_Mc = r.TH2F('tau1_Mc', '', 50,0,150,50,0,150)
for i in range(2) :
 f=r.TFile(file[i])
 hist = f.Get(var)
 for ibin in range(hist.GetNbinsX()) :
      print ibin+1, '\t',hist.ProjectionX().GetBinContent(ibin+1)

 hist1_Mc.Add(hist)

for ibin in range(hist1_Mc.GetNbinsX()) :
    print ibin+1,'\t',hist1_Mc.ProjectionX().GetBinContent(ibin+1)

I am getting output for 1st 10 bin, something like

1       0.0
2       0.0
3       0.0
4       0.0
5       0.0
6       0.0
7       0.0
8       0.0262326151133
9       0.0672479541972
10      0.0409734905697


1       0.0
2       0.0
3       0.0
4       0.0
5       0.0
6       0.0
7       0.258228719234
8       1.14812922478
9       1.08459419012
10      1.11708201282


1       0.0
2       0.0
3       0.0
4       0.0
5       0.0
6       0.0
7       0.258228719234
8       1.14812919497
9       1.08459419012
10      1.11708201282

For example, at bin #8 I expected the resultant bincontent would be 0.0262326151133+1.14812922478 = 1.17436184, but am getting 1.14812919497. Please point me where I am doing wrong. Thanks in advance

Saswati
1.14812919497

Hi,

This is strange. Can you post a full runnable macro reproducing this problem ?

Thanks

Lorenzo

Hi,

Thanks, for the reply. Is there any way to send/attach the root file which is required to run the code?
Please let me know.

Thanks,
Saswati

HI,

If the file is small you can attach it. If it is big I suggest you extract the histograms and save them in another ROOT file.

Lorenzo

TT_controlPlot.root (342.9 KB)
zzTo4L_controlPlot.root (411.9 KB)
Hi,

I have uploaded the files. But I just checked that when I am running the same code with same input file, in my own pc, I am getting correct answer, but when I move to fermilab lpc machine, it is giving wrong output. I also checked in lxplus mechine now, & it is working fine. Don’t understand what is wrong in lpc .

Thanks,
Saswati

HI,

It is maybe a bug present in an old ROOT version. Which version do you have at Fermilab ?

Lorenzo

Hi,

The version is 6.06/01

Thanks,
Saswati

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.