Hi, I have a question with respect to transfering TTree into TH1F.
I have a TTree ROOT file, that I want to convert into TH1F to do Gaussian fit!
I attached the code of my pyROOT with my TTree Root file in this writing for consultation.
WIth my attempt however, I got into several problems.
1.In my pyROOT script below, I want to get number of entries for “chg” branch but it says
AttributeError: ‘ROOT.PyUShortBuffer’ object has no attribute ‘GetEntries’. How can I get number of entries for the specific branch?
2. When I try to write on existing B8D5.root, it gives me an error with message that it’s not writable. How can I fix the problem?
3. Any other or general advice for my newbie code please!
from ROOT import gSystem, TFile, TH1F, TCanvas, gRandom
from histutil import *
from array import array
import random
rootfile = '1FB8D5.root'
def main():
myfile = TFile("B8D5.root")
t2 = myfile.Get("mppc")
hdestep = TH1F("ADC Values","ADC Values",800,0,799)
now = getattr(t2,'chg')
nentries = now.GetEntries()
print(nentries)
for i in range(nentries):
npw = now.GetEntry(i)
hdestep.Fill(npw)
hfile = TFile(rootfile, "recreate")
hfile.cd()
hdestep.Write()
hfile.Close()
myfile.Close()
#-------------------------------------------------------------------------------
try:
main()
except KeyboardInterrupt:
print 'ciao!'
B8D5.root (88.5 KB)
Thank you.