Segment Violation Error in PyROOT

I am trying to run the code below in PyROOT but it keeps on giving an error. I tried the same style code in ROOT and it worked fine.

My code:

 3 import ROOT
  4 import sys
  5 import array as arr
  6 
  7 file = ROOT.TFile("js2rt.root", "READ")
  8 tree = file.Get("0")
  9 
 10 chn0 = arr.array('i')
 11 tree.SetBranchAddress("chn0", chn0)
 13 
 14 hist = ROOT.TH2D("Chn_adc_hist", "Time ticks vs ADC; ADC; Time ticks", 1000, 1100, 1200 ,1000, 0, 750 )
 15         
 16 entries = tree.GetEntries()
 17         
 18 for i in range(entries):
 19 
 20     tree.GetEntry(i)
 21     ticks = i #timeticks
 22     hist.Fill(chn0, ticks)
 23         
 24 hist.Draw("COLZ2")

Error message:

Please help me fix it. Thank you.

Hi,
Have you trying reading the TTree as following:

ticks = 0
for row in tree : 
   hist.Fill(row.chn0, ticks)
   ticks += 1

I am still getting a similar error message.

code:

Post the output of: tree.Print()

tree.Print() output:

I guess you need:
chn0 = arr.array('l', [0]) # one "Int_t"
and then:
hist.Fill(chn0[0], ticks)

Please do read the links given in this post: