Hi sorry for the simple question, but I haven’t been able to figure out the solution for this issue yet.
I have some data from ROOT files that I have split up and grouped into several different TChains using dictionaries in Python. I want to find the mean of a variable in those different TChains. For example by doing
his = ROOT.TH1F()
for i in range(1,4):
chain_dict["chain_%s"% (i)].Draw("variable>>his")
mean_value = his.GetMean()
print(mean_value)
ROOT.his.Reset()
where each object in chain_dict
is a TChain of several chained ROOT files, and variable
is the variable I want to get the mean of (with the name changed on here for brevity).
However rather than printing the mean as I expect, instead 0
is printed. This is also the case if one of the chains is examined outside the loop, even though the Draw
part of the code works fine and produces a canvas with the correct plot and histogram.
A way I tried to fix this was by changing the code as below
for i in range(1,4):
chain_dict["chain_%s"% (i)].Draw("variable>>his")
his = ROOT.gDirectory.Get("his")
mean_value = his.GetMean()
print(eventsec_mean)
del his
However in this case instead of printing 0
's, the first mean printed is correct, the second is too small, and subsequent means are all printed as 0
. Although here the correct mean is printed for all chains if the process is done individually outside the loop. This is true when getting any value from the histogram, for example his.Integral()
and others.
I assume there is something simple I have missed that is causing this issue but since I can’t work out what it is any help would be much apprecieted.