23 tc_data_tas: list[NDArray],
24 ta_data: list[NDArray],
25 ta_data_tps: list[NDArray],
29 output_file: str |
None =
None) ->
None:
32 Plots all the event displays, one per TC.
34 Each event display will contain TriggerActivities (red boxes), and
35 TriggerPrimitives (black points) for each TriggerActivity.
38 tc_data (list[NDArray]): A list of TriggerCandidates
39 tc_data_tas (list[NDArray]): A list of TriggerActivityData per TriggerCandidate
40 ta_data (list[NDArray]): A full list of TriggerActivities
41 ta_data_tps (list[NDArray]): A list of TriggerPrimitives per TriggerActivity
42 run_id (int): Run ID number
43 file_index (int): File index
48 output_pdf = output_file
if output_file
is not None else f
"event_displays_{run_id}.{file_index:04}.pdf"
49 with PdfPages(output_pdf)
as pdf:
50 for tcdx, (tc, tas)
in tqdm(enumerate(zip(tc_data, tc_data_tas)), total=len(tc_data), desc=
"Saving event displays", disable=batch):
51 plt.figure(figsize=(6, 4))
53 yend = tc[
"time_end"] - tc[
"time_start"]
54 ta_times_starts = tas[
'time_start'] - tc[
"time_start"]
55 ta_times_ends = tas[
'time_end'] - tc[
"time_start"]
56 ta_times_peak = tas[
'time_peak'] - tc[
"time_start"]
57 ta_chan_peak = tas[
'channel_peak']
59 channel_start = np.min(tas[
'channel_start'])
60 channel_end = np.max(tas[
'channel_end'])
63 yexpansion = yend * 0.05
64 xexpansion = (channel_end - channel_start) * 0.05
66 currentAxis = plt.gca()
67 for tadx, ta
in enumerate(tas):
68 rectangle = mtp.patches.Rectangle((ta[
'channel_start'], ta_times_starts[tadx]), ta[
'channel_end'] - ta[
'channel_start'], ta_times_ends[tadx] - ta_times_starts[tadx], linewidth=1, edgecolor=
'r', facecolor=
'none')
69 currentAxis.add_patch(rectangle)
71 for tatmpdx, tatmp
in enumerate(ta_data):
72 if (tatmp[
'time_start'] == ta[
'time_start'])
and (tatmp[
'time_end'] == ta[
'time_end'])
and (tatmp[
'channel_start'] == ta[
'channel_start'])
and (tatmp[
'channel_end'] == ta[
'channel_end']):
73 time_starts = ta_data_tps[tatmpdx][
'time_start'] - tc[
"time_start"]
74 time_ends = ta_data_tps[tatmpdx][
'time_start']+32*ta_data_tps[tatmpdx][
'samples_over_threshold'] - tc[
"time_start"]
75 plt.vlines(ta_data_tps[tatmpdx][
'channel'], time_starts, time_ends)
78 plt.plot([ta[
'channel_peak']],[ta[
'time_peak']- tc[
"time_start"]], color=
'black', marker=
'x', markersize=10)
81 plt.title(f
'Run {run_id}.{file_index:04} Event Display: {tcdx:03}')
82 plt.ylabel(f
"Relative Start Time ({time_unit})")
84 plt.ylim(0 - yexpansion, yend + yexpansion)
85 plt.xlim(channel_start - xexpansion, channel_end + xexpansion)
91@click.command(help="Display diagnostic information for TCs for a given HDF5 file.")
92@click.argument("filename", type=click.Path(exists=True, dir_okay=False, path_type=str))
96 help=
"Increment the verbose level (errors, warnings, all). Save names and skipped writes are always printed. Default: 0.",
103 help=
"Starting fragment index to process from. Takes negative indexing (NOT SUPPORTED YET).",
110 help=
"Fragment index to stop processing (i.e. not inclusive). Takes negative indexing (NOT SUPPORTED YET).",
115 help=
"Run in batch mode (e.g. without loading bars/tqdm).",
118 "--output-file",
"-o",
119 type=click.Path(dir_okay=
False, path_type=str),
121 help=
"Output PDF file name. Defaults to event_displays_<run_id>.<file_index>.pdf.",
123def main(filename: str, verbose: int, start_frag: int, end_frag: int, batch: bool, output_file: str |
None) ->
None:
126 _ = (start_frag, end_frag)
130 ta_reader.read_all_fragments()
134 tc_reader.read_all_fragments()
143 tc_reader.file_index,
148 print(f
"From TCReader: number of TCs: {len(tc_reader.tc_data)}, all the TAs in TCs: {len(np.concatenate(tc_reader.ta_data))}")
149 print(f
"From TAReader: number of TAs: {len(ta_reader.tp_data)}")
None plot_all_event_displays(list[NDArray] tc_data, list[NDArray] tc_data_tas, list[NDArray] ta_data, list[NDArray] ta_data_tps, int run_id, int file_index, bool batch, str|None output_file=None)