Read a 2D histogram from a root file and make 1D plot, pyroot

i want to read a 2D histogram from a root file and make 1D histogram from it and save to a new root file. here is the code

Blockquote
import ROOT
import sys
if len(sys.argv) != 3:
print " USAGE : %s "%( sys.argv[0])
sys.exit (1)
inFileName = sys.argv[1]
outFileName = sys.argv[2]
print " Reading from “, inFileName , “and writing to”, outFileName
inFile = ROOT.TFile.Open( inFileName ,” READ “)
tree = inFile.Get(” EGamma_SF2D “)
mll = ROOT.TH2D (” data ",“m_{ll}, data " ,150 ,50.e3 ,200.e3, 150 ,50,200)
mll.Sumw2()
for entryNum in range (0, tree.GetEntries()):
tree.GetEntry( entryNum )
mll.Fill().ProjectionY()
inFile.Close()
outHistFile = ROOT.TFile.Open( outFileName ,” RECREATE ")
outHistFile.cd()
mll.Write()
outHistFile.Close()

however, i got error like AttributeError: ‘TObject’ object has no attribute ‘GetEntries’, idk what’s the problem? thanks a lot

GetEntry is a TTree method. What is tree in your example? According to the error message, it seems to be a TObject. TObject does not have such a method.

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