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':
"Version Histogram",
477 'xlabel':
"Versions",
480 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
482 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log'),
483 'use_integer_xticks':
True
487 pdf_plotter = PDFPlotter(f
"{save_name}.pdf")
489 for ta_key
in data.ta_data.dtype.names:
491 time = data.ta_data[ta_key]
493 time = time * TICK_TO_SEC_SCALE
494 min_time = np.min(time)
495 pdf_plotter.plot_histogram(time - min_time, plot_hist_dict[ta_key])
500 if ta_key ==
'algorithm' or ta_key ==
'type':
501 plot_data = np.array([datum.value
for datum
in data.ta_data[ta_key]], dtype=int)
502 pdf_plotter.plot_histogram(plot_data, plot_hist_dict[ta_key])
508 pdf_plotter.plot_histogram(data.ta_data[ta_key], plot_hist_dict[ta_key])
513 pdf = pdf_plotter.get_pdf()
522 time_peak = data.ta_data[
'time_peak']
523 time_end = data.ta_data[
'time_end']
524 time_start = data.ta_data[
'time_start']
525 ta_min_time = np.min((time_peak, time_end, time_start))
527 time_peak -= ta_min_time
528 time_end -= ta_min_time
529 time_start -= ta_min_time
532 ta_min_time = ta_min_time * TICK_TO_SEC_SCALE
533 time_peak = time_peak * TICK_TO_SEC_SCALE
534 time_end = time_end * TICK_TO_SEC_SCALE
535 time_start = time_start * TICK_TO_SEC_SCALE
537 yerr = np.array([time_peak - time_start, time_end - time_peak]).astype(np.int64)
538 time_unit =
"Seconds" if seconds
else "Ticks"
540 'title':
"TA Relative Time Spans",
542 'ylabel': time_label,
548 'label': f
"Avg {time_unit} / TA: {(time_peak[-1] - time_peak[0]) / len(time_peak):.2f}",
555 ta_count = np.arange(len(time_peak))
556 pdf_plotter.plot_errorbar(ta_count, time_peak, time_spans_dict)