279 """
280 Drives the processing and plotting.
281 """
282
283 args = parse()
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
293
294 linear = args.linear
295 log = args.log
296
297
298 if (not linear) and (not log):
299 linear = True
300 log = True
301
303
304
305 if len(data.get_fragment_paths()) == 0:
306 print("File doesn't contain any TriggerActivity fragments.")
307 return 1
308
309
310 if start_frag == 0 and end_frag == -1:
311 data.read_all_fragments()
312 else:
313 if end_frag != 0:
314 frag_paths = data.get_fragment_paths()[start_frag:end_frag]
315 elif end_frag == 0:
316 frag_paths = data.get_fragment_paths()[start_frag:]
317
318 for path in frag_paths:
319 data.read_fragment(path)
320
321
322 save_name = find_save_name(data.run_id, data.file_index, overwrite)
323
324 print(f"Number of TAs: {data.ta_data.shape[0]}")
325
326
327
328 if not no_anomaly:
329 anomaly_filename = f"{save_name}.txt"
330 print(f"Writing descriptive statistics to {anomaly_filename}.")
331 if os.path.isfile(anomaly_filename):
332
333 os.remove(anomaly_filename)
334
335 time_label = "Time (s)" if seconds else "Time (Ticks)"
336
337
338 plot_hist_dict = {
339 'adc_integral': {
340 'title': "ADC Integral Histogram",
341 'xlabel': "ADC Integral",
342 'ylabel': "Count",
343 'linear': linear,
344 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
345 'log': log,
346 'log_style': dict(color='#EE442F', alpha=0.6, label='Log')
347 },
348 'adc_peak': {
349 'title': "ADC Peak Histogram",
350 'xlabel': "ADC Count",
351 'ylabel': "Count",
352 'linear': linear,
353 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
354 'log': log,
355 'log_style': dict(color='#EE442F', alpha=0.6, label='Log')
356 },
357 'algorithm': {
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',
361 'ylabel': "Count",
362 'linear': True,
363 'linear_style': dict(color='k'),
364 'log': False,
365 'xticks': {
366 'labels': ALGORITHM_LABELS,
367 'ticks': ALGORITHM_TICKS,
368 'fontsize': 6,
369 'rotation': 60,
370 'ha': 'right'
371 }
372 },
373
374
375
376
377 'channel_end': {
378 'title': "Channel End Histogram",
379 'xlabel': "Channel Number",
380 'ylabel': "Count",
381 'linear': linear,
382 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
383 'log': log,
384 'log_style': dict(color='#EE442F', alpha=0.6, label='Log')
385 },
386 'channel_peak': {
387 'title': "Channel Peak Histogram",
388 'xlabel': "Channel Number",
389 'ylabel': "Count",
390 'linear': linear,
391 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
392 'log': log,
393 'log_style': dict(color='#EE442F', alpha=0.6, label='Log')
394 },
395 'channel_start': {
396 'title': "Channel Start Histogram",
397 'xlabel': "Channel Number",
398 'ylabel': "Count",
399 'linear': linear,
400 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
401 'log': log,
402 'log_style': dict(color='#EE442F', alpha=0.6, label='Log')
403 },
404 'detid': {
405 'title': "Detector ID Histogram",
406 'xlabel': "Detector IDs",
407 'ylabel': "Count",
408 'linear': linear,
409 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
410 'log': log,
411 'log_style': dict(color='#EE442F', alpha=0.6, label='Log'),
412 'use_integer_xticks': True
413 },
414 'num_tps': {
415 'title': "Number of TPs per TA Histogram",
416 'xlabel': "Number of TPs",
417 'ylabel': "Count",
418 'linear': linear,
419 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
420 'log': log,
421 'log_style': dict(color='#EE442F', alpha=0.6, label='Log')
422 },
423 'time_activity': {
424 'title': "Relative Time Activity Histogram",
425 'xlabel': time_label,
426 'ylabel': "Count",
427 'linear': linear,
428 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
429 'log': log,
430 'log_style': dict(color='#EE442F', alpha=0.6, label='Log')
431 },
432 'time_end': {
433 'title': "Relative Time End Histogram",
434 'xlabel': time_label,
435 'ylabel': "Count",
436 'linear': linear,
437 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
438 'log': log,
439 'log_style': dict(color='#EE442F', alpha=0.6, label='Log')
440 },
441 'time_peak': {
442 'title': "Relative Time Peak Histogram",
443 'xlabel': time_label,
444 'ylabel': "Count",
445 'linear': linear,
446 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
447 'log': log,
448 'log_style': dict(color='#EE442F', alpha=0.6, label='Log')
449 },
450 'time_start': {
451 'title': "Relative Time Start Histogram",
452 'xlabel': time_label,
453 'ylabel': "Count",
454 'linear': linear,
455 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
456 'log': log,
457 'log_style': dict(color='#EE442F', alpha=0.6, label='Log')
458 },
459 'type': {
460 'bins': np.sort(np.array([(tick-0.45, tick+0.45) for tick in TYPE_TICKS]).flatten()),
461 'title': "Type Histogram",
462 'xlabel': "Type",
463 'ylabel': "Count",
464 'linear': True,
465 'linear_style': dict(color='k'),
466 'log': False,
467 'xticks': {
468 'labels': TYPE_LABELS,
469 'ticks': TYPE_TICKS,
470 'fontsize': 6,
471 'rotation': 60,
472 'ha': 'right'
473 }
474 },
475 'trigger_number': {
476 'title': "Trigger Number Histogram",
477 'xlabel': "Trigger Number",
478 'ylabel': "Count",
479 'linear': linear,
480 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
481 'log': log,
482 'log_style': dict(color='#EE442F', alpha=0.6, label='Log')
483 },
484 'version': {
485 'title': "Version Histogram",
486 'xlabel': "Versions",
487 'ylabel': "Count",
488 'linear': linear,
489 'linear_style': dict(color='#63ACBE', alpha=0.6, label='Linear'),
490 'log': log,
491 'log_style': dict(color='#EE442F', alpha=0.6, label='Log'),
492 'use_integer_xticks': True
493 }
494 }
495
496 pdf_plotter = PDFPlotter(f"{save_name}.pdf")
497
498 for ta_key in data.ta_data.dtype.names:
499 if 'time' in ta_key:
500 time = data.ta_data[ta_key]
501 if seconds:
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])
505 if not no_anomaly:
506 write_summary_stats(time - min_time, anomaly_filename, ta_key)
507 continue
508
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])
512 if not no_anomaly:
513 write_summary_stats(plot_data, anomaly_filename, ta_key)
514 del plot_data
515 continue
516
517 pdf_plotter.plot_histogram(data.ta_data[ta_key], plot_hist_dict[ta_key])
518 if not no_anomaly:
519 write_summary_stats(data.ta_data[ta_key], anomaly_filename, ta_key)
520
521
522 pdf = pdf_plotter.get_pdf()
523
524 if linear:
525 plot_pdf_time_delta_histograms(data.ta_data, data.tp_data, pdf, time_label, False)
526 if log:
527 plot_pdf_time_delta_histograms(data.ta_data, data.tp_data, pdf, time_label, True)
528
529
530
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))
535
536 time_peak -= ta_min_time
537 time_end -= ta_min_time
538 time_start -= ta_min_time
539
540 if seconds:
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
545
546 yerr = np.array([time_peak - time_start, time_end - time_peak]).astype(np.int64)
547 time_unit = "Seconds" if seconds else "Ticks"
548 time_spans_dict = {
549 'title': "TA Relative Time Spans",
550 'xlabel': "TA",
551 'ylabel': time_label,
552 'errorbar_style': {
553 'yerr': yerr,
554 'capsize': 4,
555 'color': 'k',
556 'ecolor': "#EE442F",
557 'label': f"Avg {time_unit} / TA: {(time_peak[-1] - time_peak[0]) / len(time_peak):.2f}",
558 'mec': "#EE442F",
559 'mfc': "#EE442F",
560 'marker': 'h',
561 'markersize': 4.00
562 }
563 }
564 ta_count = np.arange(len(time_peak))
565 pdf_plotter.plot_errorbar(ta_count, time_peak, time_spans_dict)
566
567 pdf_plotter.close()
568
569 if not no_displays:
570 plot_all_event_displays(data.tp_data, data.ta_data, data.run_id, data.file_index, seconds)
571
572 return None
573
574
int main(int argc, char *argv[])