Hi, I’ve got this code which takes a number of .root files, each with 3 different TH1F histograms. It adds up all the root files, and outputs a .root file with the 3 different summed histograms. Here is the type error:
2 for filename in files[1:]:
3 f = TFile(filename)
----> 4 p_loss += TH1F(f.Get("PlossHisto"))
5 e_loss += TH1F(f.Get("ElossHisto"))
6 p_hits += TH1F(f.Get("PhitsHisto"))
TypeError: unsupported operand type(s) for +=: 'PyROOT_NoneType' and 'TH1F'
Now this is fair enough, except as shown below I’ve defined p_loss, e_loss and p_hits as type TH1F:
[code] #create clones of first histograms
#these are now the total histograms we add to
p_loss = TH1F.Clone(plosshis)
e_loss = TH1F.Clone(ehitshis)
p_hits = TH1F.Clone(phitshis)
if len(files) > 1:
for filename in files[1:]:
f = TFile(filename)
p_loss += TH1F(f.Get("PlossHisto"))
e_loss += TH1F(f.Get("ElossHisto"))
p_hits += TH1F(f.Get("PhitsHisto"))
f.Close()
[/code]
The operator ‘+=’ will work for two TH1F, but it appears the p_loss, e_loss and p_hits histograms lose their TH1F type and I don’t know why. Any insight offered would be greatly appreciated.