dumpTree.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import sys
4 import os.path
5 import ROOT
6 
7 # Get the input file.
8 if len(sys.argv) < 2: sys.exit()
9 fileName = sys.argv[1]
10 tFile = ROOT.TFile(fileName,"OLD")
11 
12 # Make sure the classes are available. If edepsim is in the path,
13 # this just makes (or loads) an empty library.
14 if os.path.exists("EDepSimEvents/EDepSimEvents.so"):
15  ROOT.gSystem.Load("EDepSimEvents/EDepSimEvents.so")
16 else:
17  tFile.MakeProject("EDepSimEvents","*","RECREATE++")
18 
19 # Get the geometry.
20 tFile.Get("EDepSimGeometry")
21 
22 # Get the event tree.
23 events = tFile.Get("EDepSimEvents")
24 
25 # Example of looping over the events.
26 for entry in events:
27  print "Have event", entry.Event.EventId
28  print "Have primaries", entry.Event.Primaries.size()
29  print "Have primaries", entry.Event.Primaries[0].GeneratorName
30 
31 # Set the branch address.
32 event = ROOT.TG4Event()
33 events.SetBranchAddress("Event",ROOT.AddressOf(event))
34 
35 # Get event zero.
36 events.GetEntry(0)
37 
38 print "event number", event.EventId
39 print "number of trajectories", event.Trajectories.size()
40 for traj in event.Trajectories:
41  print " Track Id: ", traj.TrackId
42  print " Parent Id:", traj.ParentId
43  print " Particle: ", traj.Name
44  print " PDG Code: ", traj.PDGCode
45  print " Points: ", traj.Points.size()
46 
47 print "number of segment detectors", event.SegmentDetectors.size()
48 for det in event.SegmentDetectors:
49  print "Detector name:", det.first, "Hits:", det.second.size()
50  hit = det.second[0]
51  print "First Hit:"
52  print " Primary Id: ", hit.PrimaryId
53  print " First Contributor ", hit.Contrib[0]
54  print " Energy Deposit: ", hit.EnergyDeposit
55  print " Secondary Deposit: ", hit.SecondaryDeposit
56  print " Track Length: ", hit.TrackLength
57  print " Start ", \
58  hit.Start.X(), hit.Start.Y(), hit.Start.Z()
59