56def plot_all_event_displays(tp_data: list[np.ndarray], ta_data: np.ndarray, run_id: int, file_index: int, seconds: bool =
False) ->
None:
58 Plot all event displays.
61 tp_data (list[np.ndarray]): List of TPs for each TA.
62 run_id (int): Run number.
63 file_index (int): File index of this run.
64 seconds (bool): If True, plot using seconds as units.
66 Saves event displays to a single PDF.
68 time_unit =
's' if seconds
else 'Ticks'
70 with PdfPages(f
"event_displays_{run_id}.{file_index:04}.pdf")
as pdf:
71 for tadx, (ta_event, tp_event)
in enumerate(zip(ta_data, tp_data)):
73 tp_event[
'time_start'] = tp_event[
'time_start'] * TICK_TO_SEC_SCALE
74 plt.figure(figsize=(6, 4))
76 times = tp_event[
'time_start'] - np.min(tp_event[
'time_start'])
77 plt.scatter(times, tp_event[
'channel'], c=
'k', s=2)
80 max_time = np.max(times)
81 min_time = np.min(times)
82 time_diff = max_time - min_time
86 plt.xlim((min_time - 0.1*time_diff, max_time + 0.1*time_diff))
88 plt.title(f
"Run {run_id}.{file_index:04} Event Display: {tadx:03} \n trigger record: {ta_event['trigger_number']}")
89 plt.xlabel(f
"Relative Start Time ({time_unit})")
101 tp_data: list[np.ndarray],
104 logarithm: bool) ->
None:
106 Plot the different time delta histograms to a PdfPages.
109 ta_data (np.ndarray): Array of TA data members.
110 tp_data (list[np.ndarray]): List of TPs per TA. tp_data[i] holds TP data for the i-th TA.
111 pdf (PdfPages): PdfPages object to append plot to.
112 time_label (str): Time label to plot with (ticks vs seconds).
113 logarithm (bool): Use logarithmic scaling if true.
116 Nothing. Mutates :pdf: with the new plot.
118 direct_diff = ta_data[
'time_end'] - ta_data[
'time_start']
119 last_tp_start_diff = []
120 last_tp_peak_diff = []
121 for idx, tp
in enumerate(tp_data):
122 last_tp_start_diff.append(np.max(tp[
'time_start']) - ta_data[idx][
'time_start'])
123 max_peak_arg = np.argmax(tp[
'samples_to_peak'])
126 max_peak_time = tp[max_peak_arg][
'samples_to_peak'].astype(np.uint64) * 32 + tp[max_peak_arg][
'time_start']
128 last_tp_peak_diff.append(max_peak_time + - ta_data[idx][
'time_start'])
130 last_tp_start_diff = np.array(last_tp_start_diff)
131 last_tp_peak_diff = np.array(last_tp_peak_diff)
134 if "Ticks" not in time_label:
135 direct_diff = direct_diff * TICK_TO_SEC_SCALE
136 last_tp_start_diff = last_tp_start_diff * TICK_TO_SEC_SCALE
137 last_tp_peak_diff = last_tp_peak_diff * TICK_TO_SEC_SCALE
141 plt.figure(figsize=(6, 4))
144 (direct_diff, last_tp_start_diff, last_tp_peak_diff),
147 "TA(End) - TA(Start)",
148 "Last TP(Start) - TA(Start)",
149 "Last TP(Peak) - TA(Start)"
162 plt.title(
"Time Difference Histograms")
163 plt.xlabel(time_label)
164 plt.legend(framealpha=0.4)
280 Drives the processing and plotting.
284 filename = args.filename
285 verbosity = args.verbose
286 no_displays = args.no_displays
287 start_frag = args.start_frag
288 end_frag = args.end_frag
289 no_anomaly = args.no_anomaly
290 seconds = args.seconds
291 overwrite = args.overwrite
292 batch_mode = args.batch_mode
298 if (
not linear)
and (
not log):
305 if len(data.get_fragment_paths()) == 0:
306 print(
"File doesn't contain any TriggerActivity fragments.")
310 if start_frag == 0
and end_frag == -1:
311 data.read_all_fragments()
314 frag_paths = data.get_fragment_paths()[start_frag:end_frag]
316 frag_paths = data.get_fragment_paths()[start_frag:]
318 for path
in frag_paths:
319 data.read_fragment(path)
322 save_name =
find_save_name(data.run_id, data.file_index, overwrite)
324 print(f
"Number of TAs: {data.ta_data.shape[0]}")
329 anomaly_filename = f
"{save_name}.txt"
330 print(f
"Writing descriptive statistics to {anomaly_filename}.")
331 if os.path.isfile(anomaly_filename):
333 os.remove(anomaly_filename)
335 time_label =
"Time (s)" if seconds
else "Time (Ticks)"
340 'title':
"ADC Integral Histogram",
341 'xlabel':
"ADC Integral",
344 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
346 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
349 'title':
"ADC Peak Histogram",
350 'xlabel':
"ADC Count",
353 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
355 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
358 'bins': np.sort(np.array([(tick-0.45, tick+0.45)
for tick
in ALGORITHM_TICKS]).flatten()),
359 'title':
"Algorithm Histogram",
360 'xlabel':
'Algorithm Type',
363 'linear_style': dict(color=
'k'),
366 'labels': ALGORITHM_LABELS,
367 'ticks': ALGORITHM_TICKS,
378 'title':
"Channel End Histogram",
379 'xlabel':
"Channel Number",
382 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
384 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
387 'title':
"Channel Peak Histogram",
388 'xlabel':
"Channel Number",
391 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
393 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
396 'title':
"Channel Start Histogram",
397 'xlabel':
"Channel Number",
400 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
402 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
405 'title':
"Detector ID Histogram",
406 'xlabel':
"Detector IDs",
409 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
411 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log'),
412 'use_integer_xticks':
True
415 'title':
"Number of TPs per TA Histogram",
416 'xlabel':
"Number of TPs",
419 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
421 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
424 'title':
"Relative Time Activity Histogram",
425 'xlabel': time_label,
428 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
430 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
433 'title':
"Relative Time End Histogram",
434 'xlabel': time_label,
437 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
439 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
442 'title':
"Relative Time Peak Histogram",
443 'xlabel': time_label,
446 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
448 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
451 'title':
"Relative Time Start Histogram",
452 'xlabel': time_label,
455 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
457 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
460 'bins': np.sort(np.array([(tick-0.45, tick+0.45)
for tick
in TYPE_TICKS]).flatten()),
461 'title':
"Type Histogram",
465 'linear_style': dict(color=
'k'),
468 'labels': TYPE_LABELS,
476 'title':
"Trigger Number Histogram",
477 'xlabel':
"Trigger Number",
480 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
482 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
485 'title':
"Version Histogram",
486 'xlabel':
"Versions",
489 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
491 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log'),
492 'use_integer_xticks':
True
496 pdf_plotter = PDFPlotter(f
"{save_name}.pdf")
498 for ta_key
in data.ta_data.dtype.names:
500 time = data.ta_data[ta_key]
502 time = time * TICK_TO_SEC_SCALE
503 min_time = np.min(time)
504 pdf_plotter.plot_histogram(time - min_time, plot_hist_dict[ta_key])
509 if ta_key ==
'algorithm' or ta_key ==
'type':
510 plot_data = np.array([datum.value
for datum
in data.ta_data[ta_key]], dtype=int)
511 pdf_plotter.plot_histogram(plot_data, plot_hist_dict[ta_key])
517 pdf_plotter.plot_histogram(data.ta_data[ta_key], plot_hist_dict[ta_key])
522 pdf = pdf_plotter.get_pdf()
531 time_peak = data.ta_data[
'time_peak']
532 time_end = data.ta_data[
'time_end']
533 time_start = data.ta_data[
'time_start']
534 ta_min_time = np.min((time_peak, time_end, time_start))
536 time_peak -= ta_min_time
537 time_end -= ta_min_time
538 time_start -= ta_min_time
541 ta_min_time = ta_min_time * TICK_TO_SEC_SCALE
542 time_peak = time_peak * TICK_TO_SEC_SCALE
543 time_end = time_end * TICK_TO_SEC_SCALE
544 time_start = time_start * TICK_TO_SEC_SCALE
546 yerr = np.array([time_peak - time_start, time_end - time_peak]).astype(np.int64)
547 time_unit =
"Seconds" if seconds
else "Ticks"
549 'title':
"TA Relative Time Spans",
551 'ylabel': time_label,
557 'label': f
"Avg {time_unit} / TA: {(time_peak[-1] - time_peak[0]) / len(time_peak):.2f}",
564 ta_count = np.arange(len(time_peak))
565 pdf_plotter.plot_errorbar(ta_count, time_peak, time_spans_dict)