94 ta_data: list[np.ndarray],
97 logarithm: bool) ->
None:
99 Plot the different time delta histograms to a PdfPages.
102 tc_data (np.ndarray): Array of TC data members.
103 ta_data (list[np.ndarray]): List of TAs per TC. ta_data[i] holds TA data for the i-th TC.
104 pdf (PdfPages): PdfPages object to append plot to.
105 time_label (str): Time label to plot with (ticks vs seconds).
106 logarithm (bool): Use logarithmic scaling if true.
109 Nothing. Mutates :pdf: with the new plot.
111 direct_diff = tc_data[
'time_end'] - tc_data[
'time_start']
112 last_ta_start_diff = []
113 last_ta_end_diff = []
115 for idx, ta
in enumerate(ta_data):
116 last_ta_start_diff.append(np.max(ta[
'time_start']) - tc_data[idx][
'time_start'])
117 last_ta_end_diff.append(np.max(ta[
'time_end']) - tc_data[idx][
'time_start'])
118 pure_ta_diff.append(np.max(ta[
'time_end']) - np.min(ta[
'time_start']))
120 last_ta_start_diff = np.array(last_ta_start_diff)
121 last_ta_end_diff = np.array(last_ta_end_diff)
122 pure_ta_diff = np.array(pure_ta_diff)
125 if "Ticks" not in time_label:
126 direct_diff = direct_diff * TICK_TO_SEC_SCALE
127 last_ta_start_diff = last_ta_start_diff * TICK_TO_SEC_SCALE
128 last_ta_end_diff = last_ta_end_diff * TICK_TO_SEC_SCALE
129 pure_ta_diff = pure_ta_diff * TICK_TO_SEC_SCALE
133 plt.figure(figsize=(6, 4))
136 (direct_diff, last_ta_start_diff, last_ta_end_diff, pure_ta_diff),
139 "TC(End) - TC(Start)",
140 "Last TA(Start) - TC(Start)",
141 "Last TA(End) - TC(Start)",
142 "Last TA(End) - First TA(Start)"
156 plt.title(
"Time Difference Histograms")
157 plt.xlabel(time_label)
158 plt.legend(framealpha=0.4)
269 Drives the processing and plotting.
273 filename = args.filename
274 verbosity = args.verbose
275 start_frag = args.start_frag
276 end_frag = args.end_frag
277 no_anomaly = args.no_anomaly
278 seconds = args.seconds
279 overwrite = args.overwrite
280 batch_mode = args.batch_mode
286 if (
not linear)
and (
not log):
293 if len(data.get_fragment_paths()) == 0:
294 print(
"File doesn't contain any TriggerCandidate fragments.")
298 if start_frag == 0
and end_frag == -1:
299 data.read_all_fragments()
302 frag_paths = data.get_fragment_paths()[start_frag:end_frag]
304 frag_paths = data.get_fragment_paths()[start_frag:]
306 for path
in frag_paths:
307 data.read_fragment(path)
310 save_name =
find_save_name(data.run_id, data.file_index, overwrite)
312 print(f
"Number of TCs: {data.tc_data.shape[0]}")
317 anomaly_filename = f
"{save_name}.txt"
319 print(f
"Writing descriptive statistics to {anomaly_filename}.")
320 if os.path.isfile(anomaly_filename):
322 os.remove(anomaly_filename)
324 time_label =
"Time (s)" if seconds
else "Time (Ticks)"
329 'bins': np.sort(np.array([(tick-0.45, tick+0.45)
for tick
in ALGORITHM_TICKS]).flatten()),
330 'title':
"Algorithm",
331 'xlabel':
'Algorithm Type',
334 'linear_style': dict(color=
'k'),
337 'labels': ALGORITHM_LABELS,
338 'ticks': ALGORITHM_TICKS,
345 'title':
"Detector ID",
346 'xlabel':
"Detector IDs",
349 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
351 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log'),
352 'use_integer_xticks':
True
355 'title':
"Number of TAs per TC",
356 'xlabel':
"Number of TAs",
359 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
361 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log'),
362 'use_integer_xticks':
True
365 'title':
"Relative Time Candidate",
366 'xlabel': time_label,
369 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
371 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
374 'title':
"Relative Time End",
375 'xlabel': time_label,
378 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
380 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
383 'title':
"Relative Time Peak",
384 'xlabel': time_label,
387 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
389 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
392 'title':
"Relative Time Start",
393 'xlabel': time_label,
396 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
398 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log')
401 'bins': np.sort(np.array([(tick-0.45, tick+0.45)
for tick
in TYPE_TICKS]).flatten()),
406 'linear_style': dict(color=
'k'),
409 'labels': TYPE_LABELS,
418 'xlabel':
"Versions",
421 'linear_style': dict(color=
'#63ACBE', alpha=0.6, label=
'Linear'),
423 'log_style': dict(color=
'#EE442F', alpha=0.6, label=
'Log'),
424 'use_integer_xticks':
True
428 pdf_plotter = PDFPlotter(save_name)
431 for tc_key
in data.tc_data.dtype.names:
433 time = data.tc_data[tc_key]
435 time = time * TICK_TO_SEC_SCALE
436 min_time = np.min(time)
437 pdf_plotter.plot_histogram(time - min_time, plot_hist_dict[tc_key])
442 if tc_key ==
'algorithm' or tc_key ==
'type':
443 plot_data = np.array([datum.value
for datum
in data.tc_data[tc_key]], dtype=int)
444 pdf_plotter.plot_histogram(plot_data, plot_hist_dict[tc_key])
450 pdf_plotter.plot_histogram(data.tc_data[tc_key], plot_hist_dict[tc_key])
454 pdf = pdf_plotter.get_pdf()
457 if np.sum(data.tc_data[
'num_tas']) > 0:
465 if np.sum(data.tc_data[
'num_tas']) > 0:
466 tc_adc_integrals = np.array([np.sum(tas[
'adc_integral'])
for tas
in data.ta_data])
467 adc_integrals_dict = {
468 'title':
"TC ADC Integrals",
469 'xlabel':
"ADC Integral",
472 pdf_plotter.plot_histogram(tc_adc_integrals, adc_integrals_dict)
476 if np.sum(data.tc_data[
'num_tas']) > 0:
477 integral_vs_num_tas_dict = {
478 'title':
"TC ADC Integral vs Number of TAs",
479 'xlabel':
"Number of TAs",
480 'ylabel':
"TC ADC Integral",
487 plot_pdf_scatter(data.tc_data[
'num_tas'], tc_adc_integrals, integral_vs_num_tas_dict, pdf)
491 time_candidate = data.tc_data[
'time_candidate']
492 time_end = data.tc_data[
'time_end']
493 time_start = data.tc_data[
'time_start']
494 tc_min_time = np.min((time_candidate, time_end, time_start))
496 time_candidate -= tc_min_time
497 time_end -= tc_min_time
498 time_start -= tc_min_time
501 tc_min_time = tc_min_time * TICK_TO_SEC_SCALE
502 time_candidate = time_candidate * TICK_TO_SEC_SCALE
503 time_end = time_end * TICK_TO_SEC_SCALE
504 time_start = time_start * TICK_TO_SEC_SCALE
506 yerr = np.array([time_candidate - time_start, time_end - time_candidate]).astype(np.int64)
507 time_unit =
"Seconds" if seconds
else "Ticks"
509 'title':
"TC Relative Time Spans",
511 'ylabel': time_label,
517 'label': f
"Avg {time_unit} / TC: "
518 f
"{(time_candidate[-1] - time_candidate[0]) / len(time_candidate):.2f}",
525 tc_count = np.arange(len(time_candidate))
526 pdf_plotter.plot_errorbar(tc_count, time_candidate, time_spans_dict)