Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various updates to event display #142

Merged
merged 9 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions event_display/interactive_event_display/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
dcc.Store(id="filename", storage_type="local", data=""),
dcc.Store(id="minerva-filename", storage_type="local", data=""),
dcc.Store(id="event-id", data=0),
dcc.Store(id="event-nhits", data=0),
dcc.Store(id="minerva-event-id", data=0),
dcc.Store(id="data-length", data=0),
dcc.Store(id="minerva-data-length", data=0),
dcc.Store(id="event-time", data=0),
dcc.Store(id="unix-time", data=0),
dcc.Store(id="sim-version", data=0),
# Header
html.Div(
Expand Down Expand Up @@ -105,7 +107,9 @@
html.Div(
[
html.Div(id="evid-div", style={"textAlign": "center", "display": "inline-block", "margin-right": "10px"}),
html.Div(children="", id="event-time-div", style={"display": "inline-block"}),
html.Div(children="", id="event-time-div", style={"display": "inline-block", "margin-right": "10px"}),
html.Div(children="", id="unix-time-div", style={"display": "inline-block", "margin-right": "10px"}),
html.Div(children="", id="event-nhits-div", style={"display": "inline-block"}),
]
),
],
Expand Down Expand Up @@ -338,20 +342,39 @@ def update_div(evid, max_value):

@app.callback(
Output("event-time-div", "children"),
Input("event-id", "data"),
Input("3d-graph", "figure"),
State("event-time", "data"),
)
def update_time(_, time):
"""Update the time display"""
return f"Event time: {time}"
return f"Event time (UTC): {time}"

@app.callback(
Output("unix-time-div", "children"),
Input("3d-graph", "figure"),
State("unix-time", "data"),
)
def update_unix_time(_, unix_time):
"""Update the time display"""
return f"unix time: {unix_time}"

@app.callback(
Output("event-nhits-div", "children"),
Input("3d-graph", "figure"),
State("event-nhits", "data"),
)
def update_nhits(_, nhits):
"""Update the nhits display"""
return f"Number of hits: {nhits}"

# Callback to display the event
# =============================
@app.callback(
Output("3d-graph", "figure"),
Output("sim-version", "data"),
Output("event-time", "data"),
Output("unix-time", "data"),
Output("event-nhits", "data"),
Input("filename", "data"),
Input("minerva-filename", "data"),
Input("event-id", "data"),
Expand All @@ -369,12 +392,16 @@ def update_graph(filename, minerva_filename, evid):
event_datetime = datetime.utcfromtimestamp(
data["charge/events", evid]["unix_ts"][0]
).strftime("%Y-%m-%d %H:%M:%S")
event_unix_time = data["charge/events", evid]["unix_ts"][0]
n_hits = data["charge/events",evid]["nhit"][0]
else:
raise PreventUpdate
return (
graph,
sim_version,
event_datetime,
event_unix_time,
n_hits
) # TODO: move to utils


Expand Down
178 changes: 172 additions & 6 deletions event_display/interactive_event_display/display_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def create_3d_figure(minerva_data, data, filename, evid):
# Select the hits for the current event
beam_triggers = get_all_beam_triggers(filename)
prompthits_ev = data["charge/events", "charge/calib_prompt_hits", evid]
packets_ev = data["charge/events", "charge/calib_prompt_hits", "charge/packets", evid]
try:
finalhits_ev = data["charge/events", "charge/calib_final_hits", evid]
except:
Expand Down Expand Up @@ -337,6 +338,8 @@ def create_3d_figure(minerva_data, data, filename, evid):
"xanchor": "left",
"x": 0,
},
"cmin": -1.,
"cmax": 4.,
},
name="prompt hits",
mode="markers",
Expand All @@ -347,6 +350,44 @@ def create_3d_figure(minerva_data, data, filename, evid):
)
fig.add_traces(prompthits_traces)

saturated_mask = packets_ev.data["dataword"].flatten() >= 255
if np.any(saturated_mask):
x = prompthits_ev.data["x"].flatten()[saturated_mask]
y = prompthits_ev.data["y"].flatten()[saturated_mask]
z = prompthits_ev.data["z"].flatten()[saturated_mask]
saturated_traces = go.Scatter3d(
x=x,
y=y,
z=z,
marker={
"size": 1.75,
"symbol": 'x',
"color": '17becf', #'#19D3F3',
},
mode="markers",
name="saturated hits",
)
fig.add_traces(saturated_traces)

negative_mask = prompthits_ev.data['Q'].flatten()<0.
if np.any(negative_mask):
x = prompthits_ev.data["x"].flatten()[negative_mask]
y = prompthits_ev.data["y"].flatten()[negative_mask]
z = prompthits_ev.data["z"].flatten()[negative_mask]
negative_traces = go.Scatter3d(
x=x,
y=y,
z=z,
marker={
"size": 1.75,
"symbol": 'x',
"color": '#2ca02c', #'#d62728',
},
mode="markers",
name="negative charge hits",
)
fig.add_traces(negative_traces)

# Plot the final hits
finalhits_traces = go.Scatter3d(
x=finalhits_ev.data["x"].flatten(),
Expand All @@ -358,14 +399,16 @@ def create_3d_figure(minerva_data, data, filename, evid):
"opacity": 0.9,
"colorscale": colorscale_charge,
"colorbar": {
"title": "Hit energy [MeV]",
"title": "Hit E [MeV]",
"titlefont": {"size": 12},
"tickfont": {"size": 10},
"thickness": 15,
"len": 0.5,
"xanchor": "left",
"x": 0,
},
"cmin": 0.,
"cmax": 5.,
},
name="final hits",
mode="markers",
Expand Down Expand Up @@ -1028,6 +1071,7 @@ def plot_2d_charge(data, evid):

# Select the hits for the current event
prompthits_ev = data["charge/events", "charge/calib_prompt_hits", evid]
packets_ev = data["charge/events", "charge/calib_prompt_hits", "charge/packets", evid]

# Define a colorscale and colorbar for the plots
colorbar = dict(
Expand All @@ -1038,12 +1082,19 @@ def plot_2d_charge(data, evid):
showticklabels=True,
)

prompt_2d_cmin = -1
prompt_2d_cmax = 4

# Add 2D projections of the prompt hits
prompthits_traces_xy = go.Scatter(
x=prompthits_ev.data["x"].flatten(),
y=prompthits_ev.data["y"].flatten(),
mode="markers",
legendgroup= "prompt_2d",
name="prompt hits",
marker=dict(
cmin=prompt_2d_cmin,
cmax=prompt_2d_cmax,
size=2,
opacity=0.9,
color=prompthits_ev.data["E"].flatten(),
Expand All @@ -1057,7 +1108,11 @@ def plot_2d_charge(data, evid):
x=prompthits_ev.data["z"].flatten(),
y=prompthits_ev.data["x"].flatten(),
mode="markers",
legendgroup="prompt_2d",
showlegend=False,
marker=dict(
cmin=prompt_2d_cmin,
cmax=prompt_2d_cmax,
size=2,
opacity=0.9,
color=prompthits_ev.data["E"].flatten(),
Expand All @@ -1071,7 +1126,11 @@ def plot_2d_charge(data, evid):
x=prompthits_ev.data["z"].flatten(),
y=prompthits_ev.data["y"].flatten(),
mode="markers",
legendgroup= "prompt_2d",
showlegend=False,
marker=dict(
cmin=prompt_2d_cmin,
cmax=prompt_2d_cmax,
size=2,
opacity=0.9,
color=prompthits_ev.data["E"].flatten(),
Expand All @@ -1087,6 +1146,8 @@ def plot_2d_charge(data, evid):
y=[None],
mode="markers",
marker=dict(
cmin=prompt_2d_cmin,
cmax=prompt_2d_cmax,
size=2,
opacity=0.7,
colorscale=colorscale_charge,
Expand All @@ -1097,29 +1158,33 @@ def plot_2d_charge(data, evid):
)

cathode_line_1 = go.Scatter(
x=[-63.931/2, -63.931/2],
x=[-(63.931+3.069)/2, -(63.931+3.069)/2],
y=[-63.931, 63.931],
mode="lines",
line=dict(color="white", width=1),
showlegend=False,
)
cathode_line_2 = go.Scatter(
x=[63.931/2, 63.931/2],
x=[(63.931+3.069)/2, (63.931+3.069)/2],
y=[-63.931, 63.931],
mode="lines",
line=dict(color="white", width=1),
showlegend=False,
)

cathode_line_3 = go.Scatter(
x=[-63.931, 63.931],
y=[-63.931/2, -63.931/2],
y=[-(63.931+3.069)/2, -(63.931+3.069)/2],
mode="lines",
line=dict(color="white", width=1),
showlegend=False,
)
cathode_line_4 = go.Scatter(
x=[-63.931, 63.931],
y=[63.931/2, 63.931/2],
y=[(63.931+3.069)/2, (63.931+3.069)/2],
mode="lines",
line=dict(color="white", width=1),
showlegend=False,
)

# Add traces to the subplots
Expand All @@ -1134,6 +1199,106 @@ def plot_2d_charge(data, evid):
dummy_trace, row=2, col=2
) # Add the dummy trace to one of the subplots

saturated_mask = packets_ev.data["dataword"].flatten() >= 255
if np.any(saturated_mask):
x = prompthits_ev.data["x"].flatten()[saturated_mask]
y = prompthits_ev.data["y"].flatten()[saturated_mask]
z = prompthits_ev.data["z"].flatten()[saturated_mask]

saturated_traces_xy = go.Scatter(
x=x,
y=y,
legendgroup= "saturated_2d",
name="saturated hits",
showlegend=True,
marker={
"size": 4.,
"symbol": 'x',
"color": '#17becf', #'#19D3F3',
},
mode="markers",
)

saturated_traces_xz = go.Scatter(
x=z,
y=x,
legendgroup= "saturated_2d",
showlegend=True,
marker={
"size": 4.,
"symbol": 'x',
"color": '#17becf', #'#19D3F3',
},
mode="markers",
)

saturated_traces_yz = go.Scatter(
x=z,
y=y,
legendgroup= "saturated_2d",
showlegend=True,
marker={
"size": 4.,
"symbol": 'x',
"color": '#17becf', #'#19D3F3',
},
mode="markers",
)

fig.add_trace(saturated_traces_xy, row=2, col=2)
fig.add_trace(saturated_traces_xz, row=1, col=1)
fig.add_trace(saturated_traces_yz, row=2, col=1)

negative_mask = prompthits_ev.data["Q"].flatten() <0.
if np.any(negative_mask):
x = prompthits_ev.data["x"].flatten()[negative_mask]
y = prompthits_ev.data["y"].flatten()[negative_mask]
z = prompthits_ev.data["z"].flatten()[negative_mask]

negative_traces_xy = go.Scatter(
x=x,
y=y,
legendgroup= "negative_2d",
name="negative hits",
showlegend=True,
marker={
"size": 4.,
"symbol": 'x',
"color": '#2ca02c', #'#d62728',
},
mode="markers",
)

negative_traces_xz = go.Scatter(
x=z,
y=x,
legendgroup= "negative_2d",
showlegend=True,
marker={
"size": 4.,
"symbol": 'x',
"color": '#2ca02c',# '#d62728',
},
mode="markers",
)

negative_traces_yz = go.Scatter(
x=z,
y=y,
legendgroup= "negative_2d",
showlegend=True,
marker={
"size": 4.,
"symbol": 'x',
"color": '#2ca02c', #'#d62728',
},
mode="markers",
)

fig.add_trace(negative_traces_xy, row=2, col=2)
fig.add_trace(negative_traces_xz, row=1, col=1)
fig.add_trace(negative_traces_yz, row=2, col=1)

# Add x and y axis labels to the subplots
fig.update_xaxes(
title_text="z [cm]",
Expand Down Expand Up @@ -1196,7 +1361,8 @@ def plot_2d_charge(data, evid):
)

fig.update_layout(
showlegend=False,
showlegend=True,
legend=dict(orientation="h"),
plot_bgcolor=bg_color,
autosize=False,
width=800,
Expand Down
Loading