Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#############################
# Read ROOT File
# Loop over event by event
# Print interested variables
#############################
import ROOT
# ROOT file that you read
fname = "input.root"
# Open file and get TTree
f = ROOT.TFile.Open(fname)
tree = f.Get("lAger")
print("=======")
print("Read in ROOT file: {}".format(fname))
# Total number of events in TTree
nevt = tree.GetEntries()
print ("total number of events: ",nevt)
# Loop over event by event
print("Loop over event by event")
for ievt in range(0,nevt):
# Access info of an event
tree.GetEntry(ievt)
if ievt % 5 == 0: # Printing
print("Processing event number: {}".format(ievt))
W = tree.W # invariant mass: sqrt(center of mass energy virtual photon + target (Helium-4))
Q2 = tree.Q2 # virtual photon mass: four-momentum transfer of electron
t = tree.t # four-momentum transfer of Helium-4
# Total number of particles in an event
nptls = tree.particles.GetEntries()
print (nptls)
ip = 0 # index of particles
# Loop over particles
for ptl in range(0,nptls):
# TODO: Access leaf and Save as in array
# infomration needed
# each particles have below info
# particles.fPdgCode / particles.fStatusCode / particles.fE / particles.fPx / particles.fPy / particles.fPz
# Not Working...
#PID = tree.particles[ptl].fPdgCode
#PID[ip] = tree.GetLeaf("particles.fPdgCode").GetValue(ptl)
ip += 1
#print (PID)
# Just checking the first 10 events
if ievt > 9:
break
pass
print("=======")