-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSimpleAnalysis.py
executable file
·68 lines (54 loc) · 2.46 KB
/
SimpleAnalysis.py
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
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
# SimpleAnalysis.py
# 25-Jun-2024 William Seligman <[email protected]>
# To run this program, you can do something like this
# from your GramsSim build directory:
# ./scripts/SimpleAnalysis.py
# This macro assumes you have created a GramsSim build directory
# following the recipe in the documentation:
# https://github.com/wgseligman/GramsSim/blob/develop/README.md and
# are running the script with the above command in that directory. If
# you've moved the script, then you'll have to adjust the gSystem.Load
# lines below.
import platform, ROOT
# We'll also need the GramsSim custom dictionary for its data objects
# (see GramsSim/GramsDataObj/README.md and
# https://www.nevis.columbia.edu/~seligman/root-class/html/appendix/dictionary/index.html).
if ( platform.system() == "Darwin"):
ROOT.gSystem.Load("libDictionary.dylib")
else:
ROOT.gSystem.Load("libDictionary.so")
# Open the input file and access the n-tuple.
inputFile = ROOT.TFile("gramsg4.root")
tree = ROOT.gDirectory.Get( 'gramsg4' )
# For each row (or entry) in the tree:
for entry in tree:
# Did this event have any LAr hits?
numLArHits = len( tree.LArHits )
if numLArHits > 0:
# How many tracks were in this event?
numTracks = len( tree.TrackList )
# How many of those tracks were in the LAr? Look at each track
# in the list of Tracks.
numLArTracks = 0
for ( trackID, track ) in tree.TrackList:
# Look at the trajectory of this track.
trajectory = track.Trajectory()
# For this simple analysis, we want to look at tracks whose
# trajectories start in the LAr. Note that _none_ of the
# primary particles start in the LAr; they start outside the
# detector.
trajectoryPoint = trajectory[0]
identifier = trajectoryPoint.Identifier()
# In the Identifier scheme documented in GramsSim/grams.gdml,
# volume ID numbers in the LAr are seven-digit numbers that
# begin with 1.
volumeType = int( identifier / 1000000 )
if volumeType == 1:
numLArTracks += 1
# Display some counts, including those tracks that
# started in the active LAr.
print ("Event", tree.EventID.Index(), "has",
numLArHits, "hits and",
numTracks, "tracks;",
numLArTracks, "of these tracks started in the active LAr" )