-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotting.py
182 lines (149 loc) · 6.25 KB
/
plotting.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d as plt3d
import h5py
from utils import *
debug = False
def draw_boundaries(ax):
for ix in range(detector.TPC_BORDERS.shape[0]):
bounds = detector.TPC_BORDERS[ix]*10
ax.plot([bounds[0][0], bounds[0][1]],
[bounds[1][0], bounds[1][0]],
[bounds[2][0], bounds[2][0]],
color = 'black', ls = '--')
ax.plot([bounds[0][0], bounds[0][1]],
[bounds[1][1], bounds[1][1]],
[bounds[2][0], bounds[2][0]],
color = 'black', ls = '--')
ax.plot([bounds[0][0], bounds[0][1]],
[bounds[1][0], bounds[1][0]],
[bounds[2][1], bounds[2][1]],
color = 'black', ls = '--')
ax.plot([bounds[0][0], bounds[0][1]],
[bounds[1][1], bounds[1][1]],
[bounds[2][1], bounds[2][1]],
color = 'black', ls = '--')
ax.plot([bounds[0][0], bounds[0][0]],
[bounds[1][0], bounds[1][1]],
[bounds[2][0], bounds[2][0]],
color = 'black', ls = '--')
ax.plot([bounds[0][1], bounds[0][1]],
[bounds[1][0], bounds[1][1]],
[bounds[2][0], bounds[2][0]],
color = 'black', ls = '--')
ax.plot([bounds[0][0], bounds[0][0]],
[bounds[1][0], bounds[1][1]],
[bounds[2][1], bounds[2][1]],
color = 'black', ls = '--')
ax.plot([bounds[0][1], bounds[0][1]],
[bounds[1][0], bounds[1][1]],
[bounds[2][1], bounds[2][1]],
color = 'black', ls = '--')
ax.plot([bounds[0][0], bounds[0][0]],
[bounds[1][0], bounds[1][0]],
[bounds[2][0], bounds[2][1]],
color = 'black', ls = '--')
ax.plot([bounds[0][1], bounds[0][1]],
[bounds[1][0], bounds[1][0]],
[bounds[2][0], bounds[2][1]],
color = 'black', ls = '--')
ax.plot([bounds[0][0], bounds[0][0]],
[bounds[1][1], bounds[1][1]],
[bounds[2][0], bounds[2][1]],
color = 'black', ls = '--')
ax.plot([bounds[0][1], bounds[0][1]],
[bounds[1][1], bounds[1][1]],
[bounds[2][0], bounds[2][1]],
color = 'black', ls = '--')
ax.set_xlabel(r'x (horizontal) [mm]')
ax.set_ylabel(r'y (vertical) [mm]')
ax.set_zlabel(r'z (drift) [mm]')
def plot_hits(ax, hits, f, geometry, track = None):
if track:
t0 = track['t0']
else:
event = f['events'][hits[0]['event_ref']]
t0 = event['ts_start']
pos3d = hit_to_3d(geometry, hits, t0)
q = hits['q']
if debug:
color = ['blue' if hit['iogroup'] == 1 else 'red' if hit['iogroup'] == 2 else 'yellow'
for hit in hits]
else:
color = q
ax.scatter(*pos3d, c = color)
def plot_track(ax, track, f, geo):
start = np.array([track['start'][0] + geo.tpc_offsets[0][0]*10,
track['start'][1] + geo.tpc_offsets[0][1]*10,
track['start'][2] + geo.tpc_offsets[0][2]*10])
end = np.array([track['end'][0] + geo.tpc_offsets[0][0]*10,
track['end'][1] + geo.tpc_offsets[0][1]*10,
track['end'][2] + geo.tpc_offsets[0][2]*10])
ax.scatter(*start,
c = 'r')
ax.scatter(*end,
c = 'b')
ax.plot(*zip(start, end),
c = 'g')
def plot_selected_track(ax, track_start,track_end):
ax.plot(*zip(track_start, track_end),
c='k', alpha = 0.5)
def main(args):
global my_geometry
my_geometry = DetectorGeometry(args.d, args.g)
global f
f = h5py.File(args.infile, 'r')
fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')
draw_boundaries(ax)
if args.e > 0:
thisEvent = np.array(f['events'])[args.e]
print ("this event has " + str(thisEvent['n_ext_trigs']) + " external triggers")
hits = f['hits'][thisEvent['hit_ref']]
plot_hits(ax, hits, f, my_geometry)
for ti in range(thisEvent['ntracks']):
thisTrack = f['tracks'][thisEvent['track_ref']][ti]
plot_track(ax, thisTrack, f, my_geometry)
else:
rawTracks = np.array(f['tracks'])
trackMask = np.logical_and(rawTracks['length'] > 300,
rawTracks['nhit'] > 0) # more variables to cut on here
tracks = rawTracks[trackMask]
for thisTrack in tracks[:args.n]:
plot_track(ax, thisTrack, f, my_geometry)
hits = f['hits'][thisTrack['hit_ref']]
plot_hits(ax, hits, my_geometry, thisTrack)
if args.o:
plt.savefig(args.o, dpi = 300)
else:
plt.show()
if __name__ == '__main__':
# Plot 10 tracks that are > 30 cm.
# Assuming you downloaded a file from
# https://portal.nersc.gov/project/dune/data/Module0/TPC1+2/dataRuns/tracksData/
import argparse
parser = argparse.ArgumentParser(description='Plot the first N tracks from a given file')
parser.add_argument('infile',
help = 'intput larpix data with track reconstruction')
parser.add_argument('-e',
default = -1,
type = int,
help = 'plot the event with this evid (default, plot tracks)')
parser.add_argument('-n',
default = 10,
type = int,
help = 'plot the first n tracks (default 10)')
parser.add_argument('-g',
default = './pixel_layouts/multi_tile_layout-2.3.16.yaml',
type = str,
help = 'path to the pixel layout YAML')
parser.add_argument('-d',
default = './detector_properties/module0.yaml',
type = str,
help = 'path to the detector properties YAML')
parser.add_argument('-o',
default = '',
type = str,
help = 'save the output plot to a file')
args = parser.parse_args()
main(args)