-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_wireplanes.py
298 lines (255 loc) · 10.7 KB
/
view_wireplanes.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
from __future__ import print_function
import os,sys,argparse
if "DLLEE_UNIFIED_BASEDIR" in os.environ or "DLLEE_UNIFIED_DIR" in os.environ:
print("DLLEE UNIFIED DETECTED")
REPO = "UNIFIED"
elif "UBDL_BASEDIR" in os.environ:
print("UBDL DETECTED")
REPO = "UBDL"
else:
print("Must setup either DLLEE_UNIFIED or UBDL repository")
sys.exit(0)
parser = argparse.ArgumentParser("test_3d lardly viewer w/ DL Merged File")
parser.add_argument("-i","--input-file",required=True,type=str,help="dlmerged file")
parser.add_argument("-e","--entry",required=True,type=int,help="Entry to load")
parser.add_argument("-lf","--larflow",type=str,default=None,help="Provide input larflow file (optional)")
parser.add_argument("-crt","--has-crt",default=False,action='store_true',help="Plot CRT information (assumed to be available)")
parser.add_argument("-ns","--no-shower",default=True,action='store_false',help="No shower")
parser.add_argument("-mc","--mc-tracks",default=False,action='store_true',help="Plot MC Tracks")
parser.add_argument("-p","--port",default=8050,type=int,help="Set Port. Default (8050)")
args = parser.parse_args(sys.argv[1:])
import os
import json
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from larlite import larlite
from larcv import larcv
from ROOT import larutil
import numpy as np
#print(larcv.load_pyutil)
#larcv.load_pyutil
import lardly
ientry = args.entry
HAS_TRACKS = True
HAS_SHOWERS = args.no_shower
HAS_PIXELS = False
HAS_LARMATCH = False
PLOT_COSMIC_TAGGER = False
if args.larflow is not None:
HAS_LARMATCH = True
FLIP_IMAGE2D = False
if REPO=="UNIFIED":
FLIP_IMAGE2D = True
USE_NEW_SHOWER=True
# ======================================
# IO
# --
# LARLITE
io_ll = larlite.storage_manager(larlite.storage_manager.kREAD)
io_ll.add_in_filename( args.input_file )
# BONUS: larflow hits
if HAS_LARMATCH:
io_ll.add_in_filename( args.larflow )
io_ll.open()
io_ll.go_to(ientry)
# LARCV
if REPO=="UBDL":
io_cv = larcv.IOManager(larcv.IOManager.kREAD,"larcv",larcv.IOManager.kTickBackward)
else:
io_cv = larcv.IOManager(larcv.IOManager.kREAD,"larcv")
io_cv.add_in_file( args.input_file )
if REPO=="UBDL":
io_cv.reverse_all_products()
io_cv.initialize()
io_cv.read_entry(ientry)
# ======================================
# TRACE CONTAINERS
traces3d = []
traces2d = {0:[],1:[],2:[]}
ev_adc = io_cv.get_data( larcv.kProductImage2D, "wire" )
img_v = ev_adc.Image2DArray()
# OPFLASH
evopflash_beam = io_ll.get_data(larlite.data.kOpFlash,"simpleFlashBeam")
evopflash_cosmic = io_ll.get_data(larlite.data.kOpFlash,"simpleFlashCosmic")
# VERTEX
if True:
# vertices: 2d
ev_pgraph = io_cv.get_data( larcv.kProductPGraph, "test" )
ev_pclust = io_cv.get_data( larcv.kProductPixel2D, "test_ctor" )
print("Number of vertices: ",ev_pgraph.PGraphArray().size())
pgraph_traces2d = lardly.data.visualize2d_larcv_pgraph( ev_pgraph, event_contour_pixels=ev_pclust )
for p in range(3):
traces2d[p] += pgraph_traces2d[p]
# 3D vertices
pgraph_traces3d = lardly.data.visualize3d_larcv_pgraph( ev_pgraph )
traces3d += pgraph_traces3d
# PATICLE TRACK
if True:
evtrack = io_ll.get_data(larlite.data.kTrack,"trackReco")
evtrack_sce = io_ll.get_data(larlite.data.kTrack,"trackReco_sceadded")
print("number of tracks: ",evtrack.size())
traces3d += [ lardly.data.visualize_larlite_track( evtrack_sce[i], color=(255,165,0) ) for i in range(evtrack_sce.size()) ]
for itrack in range(evtrack.size()):
track_traces = lardly.data.visualize2d_larlite_track( evtrack[itrack], img_v, color=(255,165,0) )
for p in range(3):
traces2d[p].append( track_traces[p] )
# SHOWER
if HAS_SHOWERS:
# 3D Showers
if not USE_NEW_SHOWER:
ev_shower = io_ll.get_data( larlite.data.kShower, "showerreco" )
print("number of showers (showerreco): ",ev_shower.size())
shower_traces = [ lardly.data.visualize3d_larlite_shower( ev_shower.at(x) ) for x in range(ev_shower.size()) ]
traces3d += shower_traces
shower2d_traces = [ lardly.data.visualize2d_larlite_shower( ev_shower.at(x) ) for x in range(ev_shower.size()) ]
for shower2d_trace in shower2d_traces:
print("shower trace: ",shower2d_trace)
for p in range(3):
traces2d[p].append( shower2d_trace[p] )
else:
ev_shower = io_ll.get_data( larlite.data.kShower, "ssnetshowerreco" )
print("number of showers (ssnetshowerreco): ",ev_shower.size())
pixheight = img_v[0].meta().pixel_height()
for ishr in xrange(ev_shower.size()):
ll_shr = ev_shower.at(ishr)
shower_angle = np.arctan2( ll_shr.Direction()[1], ll_shr.Direction()[0] )
tick = ll_shr.ShowerStart()[0]/larutil.LArProperties.GetME().DriftVelocity()/0.5+3200
wire = larutil.Geometry.GetME().WireCoordinate( ll_shr.ShowerStart(), ll_shr.best_plane() )
row = img_v[0].meta().row(tick)
np_shr = np.zeros( (4,2) )
np_shr[0,1] = tick
np_shr[0,0] = wire
row1 = int(row) - int(ll_shr.Length()*np.sin( shower_angle+ll_shr.OpeningAngle() ))
row2 = int(row) - int(ll_shr.Length()*np.sin( shower_angle-ll_shr.OpeningAngle() ))
if row1<0 or row2<0:
print("invalid shower[idx={}] rows: row1={} row2={}".format(ishr,row1,row2))
if row1<0:
row1 = 0
if row2<0:
row2 = 0
np_shr[1,1] = img_v[0].meta().pos_y( row1 )
np_shr[1,0] = wire + ll_shr.Length()*np.cos( shower_angle+ll_shr.OpeningAngle() )
np_shr[2,1] = img_v[0].meta().pos_y( row2 )
np_shr[2,0] = wire + ll_shr.Length()*np.cos( shower_angle-ll_shr.OpeningAngle() )
np_shr[3,:] = np_shr[0,:]
shower2d_trace = {
"x":np_shr[:,0],
"y":np_shr[:,1],
"name":"vtx[%d]"%(ll_shr.ID()),
"mode":"lines",
"line":{"color":"rgb(255,155,255)"},
}
traces2d[ll_shr.best_plane()].append( shower2d_trace )
# COSMIC TRACKS
if PLOT_COSMIC_TAGGER:
ev_cosmics = io_ll.get_data(larlite.data.kTrack,"mergedthrumu3d")
if ev_cosmics.size()>0:
traces3d += [ lardly.data.visualize_larlite_track( ev_cosmics[i], color=(255,0,0) ) for i in range(ev_cosmics.size()) ]
# MCTRACK
if args.mc_tracks:
print("VISUALIZE MCTRACKS")
mctrack_v = lardly.data.visualize_larlite_event_mctrack( io_ll.get_data(larlite.data.kMCTrack, "mcreco"))
traces3d += mctrack_v
# LARFLOW HITS
if HAS_LARMATCH:
print("Visualize LArFlow Hits")
ev_lfhits = io_ll.get_data(larlite.data.kLArFlow3DHit,"larmatch")
print(" num larflow hits: ",ev_lfhits.size())
lfhits_v = [ lardly.data.visualize_larlite_larflowhits( ev_lfhits, "larmatch" ) ]
traces3d += lfhits_v
# CRT
if args.has_crt:
print("Visualize CRT")
ev_crthits = io_ll.get_data(larlite.data.kCRTHit,"crthitcorr")
crthit_v = [ lardly.data.visualize_larlite_event_crthit( ev_crthits, "crthitcorr") ]
#filtered_crthit_v = lardly.ubdl.filter_crthits_wopreco( evopflash_beam, evopflash_cosmic, ev_crthits )
#vis_filtered_crthit_v = [ lardly.data.visualize_larlite_crthit( x ) for x in filtered_crthit_v ]
traces3d += crthit_v
min_crt_ns = 1.0e9
max_crt_ns = -1.0e9
for ihit in range(ev_crthits.size()):
ns = ev_crthits[ihit].ts2_ns
min_crt_ns = min(min_crt_ns,ns)
max_crt_ns = max(max_crt_ns,ns)
print("Min CRT time (usec): ",min_crt_ns*0.001," Max CRT time (usec): ",max_crt_ns*0.001)
# CRT TRACKS
evtracks = io_ll.get_data(larlite.data.kCRTTrack,"crttrack")
crttrack_v = lardly.data.visualize_larlite_event_crttrack( evtracks, "crttrack")
traces3d += crttrack_v
# IMAGE2D
ev_img = io_cv.get_data( larcv.kProductImage2D, "wire" )
img2d_v = ev_img.Image2DArray()
if False:
ev_pix = io_cv.get_data( larcv.kProductPixel2D, "allreco" )
pix_meta_v = [ ev_pix.ClusterMetaArray(p) for p in range(3) ]
pix_arr_v = [ ev_pix.Pixel2DClusterArray()[p] for p in range(3) ]
pixtraces = [ lardly.data.visualize_larcv_pixel2dcluster( pix_arr_v[0][i], pix_meta_v[0][0] ) for i in range(pix_arr_v[0].size()) ]
detdata = lardly.DetectorOutline()
app = dash.Dash(
__name__,
meta_tags=[{"name": "viewport", "content": "width=device-width, initial-scale=1"}],
)
server = app.server
axis_template = {
"showbackground": True,
"backgroundcolor": "#141414",
"gridcolor": "rgb(255, 255, 255)",
"zerolinecolor": "rgb(255, 255, 255)",
}
plot_layout = {
"title": "",
"height":800,
"margin": {"t": 0, "b": 0, "l": 0, "r": 0},
"font": {"size": 12, "color": "white"},
"showlegend": False,
"plot_bgcolor": "#141414",
"paper_bgcolor": "#141414",
"scene": {
"xaxis": axis_template,
"yaxis": axis_template,
"zaxis": axis_template,
#"aspectratio": {"x": 1, "y": 1, "z": 4},
"camera": {"eye": {"x": 2, "y": 2, "z": 2},
"up":dict(x=0, y=1, z=0)},
"annotations": [],
},
}
testline = {
"type":"scattergl",
"x":[200,400,400,800],
"y":[3200,3400,3800,4400],
"mode":"markers",
#"line":{"color":"rgb(255,255,255)","width":4},
"marker":dict(size=10, symbol="triangle-up",color="rgb(255,255,255)"),
}
app.layout = html.Div( [
html.Div( [
dcc.Graph(
id="det3d",
figure={
"data": detdata.getlines()+traces3d,
"layout": plot_layout,
},
config={"editable": True, "scrollZoom": False},
)],
className="graph__container"),
html.Div( [
dcc.Graph(
id="image2d_plane0",
figure={"data":[ lardly.data.visualize_larcv_image2d( img2d_v[0], reverse_ticks=FLIP_IMAGE2D )]+traces2d[0],
"layout":{"height":800} }),
dcc.Graph(
id="image2d_plane1",
figure={"data":[lardly.data.visualize_larcv_image2d( img2d_v[1], reverse_ticks=FLIP_IMAGE2D )]+traces2d[1],
"layout":{"height":800}}),
dcc.Graph(
id="image2d_plane2",
figure={"data":[lardly.data.visualize_larcv_image2d( img2d_v[2], reverse_ticks=FLIP_IMAGE2D )]+traces2d[2],
"layout":{"height":800}}),
] ),
] )
if __name__ == "__main__":
app.run_server(port=args.port,debug=True)