From ca1fc983538ddf1db04080b41d3d500f97567ec4 Mon Sep 17 00:00:00 2001 From: Christian Bespin Date: Thu, 12 Dec 2024 16:44:36 +0100 Subject: [PATCH 1/4] Add converter script for corryvreckan --- tjmonopix2/analysis/corryvreckan_converter.py | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 tjmonopix2/analysis/corryvreckan_converter.py diff --git a/tjmonopix2/analysis/corryvreckan_converter.py b/tjmonopix2/analysis/corryvreckan_converter.py new file mode 100644 index 0000000..728360c --- /dev/null +++ b/tjmonopix2/analysis/corryvreckan_converter.py @@ -0,0 +1,85 @@ +# +# ------------------------------------------------------------ +# Copyright (c) All rights reserved +# SiLab, Institute of Physics, University of Bonn +# ------------------------------------------------------------ +# + +from pathlib import Path + +import numpy as np +import tables as tb + + +def format_dut(input_filename: str | Path, output_filename: str | Path = None, trigger_mode: str = "AIDA") -> None: + """Format hit table to be compatible with corryvreckan EventLoaderHDF5 as of commit 149e937f + + Parameters + ---------- + input_filename : str | Path + Interpreted hit file with Hit and/or Event data depending on trigger_mode + output_filename : str | Path, optional + Output file name. If None, defaults to input_filename with suffix '_converted', by default None + trigger_mode : str, optional + Trigger mode during data taking. EUDET mode (with trigger handshake) and AIDA, mode (without + handshake only) are supported. In general, use `DATA_FORMAT=1` in `testbench.yaml` for data + taking. By default "AIDA" + + Raises + ------ + RuntimeError + Invalid trigger mode selected + """ + hit_dtype_converted = np.dtype([ + ("column", " Date: Fri, 13 Dec 2024 10:47:49 +0100 Subject: [PATCH 2/4] Add analysis capabilities to converter --- tjmonopix2/analysis/corryvreckan_converter.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tjmonopix2/analysis/corryvreckan_converter.py b/tjmonopix2/analysis/corryvreckan_converter.py index 728360c..f69f895 100644 --- a/tjmonopix2/analysis/corryvreckan_converter.py +++ b/tjmonopix2/analysis/corryvreckan_converter.py @@ -10,6 +10,8 @@ import numpy as np import tables as tb +from tjmonopix2.analysis import analysis + def format_dut(input_filename: str | Path, output_filename: str | Path = None, trigger_mode: str = "AIDA") -> None: """Format hit table to be compatible with corryvreckan EventLoaderHDF5 as of commit 149e937f @@ -82,4 +84,11 @@ def format_dut(input_filename: str | Path, output_filename: str | Path = None, t if __name__ == "__main__": input_file = "/path/to/file.h5" - format_dut(input_filename=input_file, trigger_mode="aida") + trigger_mode = "aida" + + if "_interpreted.h5" not in input_file: + with analysis.Analysis(raw_data_file=raw_data_file, store_hits=True, create_pdf=False, build_events=True if trigger_mode=="eudet" else False) as a: + a.analyze_data() + input_file = a.analyzed_data_file + + format_dut(input_filename=input_file, trigger_mode=trigger_mode) From 5abefeb886a8aeda9497027ce374d3d0a4141904 Mon Sep 17 00:00:00 2001 From: Christian Bespin Date: Fri, 13 Dec 2024 11:05:22 +0100 Subject: [PATCH 3/4] Codestyle --- tjmonopix2/analysis/corryvreckan_converter.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tjmonopix2/analysis/corryvreckan_converter.py b/tjmonopix2/analysis/corryvreckan_converter.py index f69f895..1b5cdbe 100644 --- a/tjmonopix2/analysis/corryvreckan_converter.py +++ b/tjmonopix2/analysis/corryvreckan_converter.py @@ -32,18 +32,14 @@ def format_dut(input_filename: str | Path, output_filename: str | Path = None, t RuntimeError Invalid trigger mode selected """ - hit_dtype_converted = np.dtype([ - ("column", " Date: Wed, 18 Dec 2024 10:40:44 +0100 Subject: [PATCH 4/4] Column and row numbers start at 0 in corryvreckan --- tjmonopix2/analysis/corryvreckan_converter.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tjmonopix2/analysis/corryvreckan_converter.py b/tjmonopix2/analysis/corryvreckan_converter.py index 1b5cdbe..c15675f 100644 --- a/tjmonopix2/analysis/corryvreckan_converter.py +++ b/tjmonopix2/analysis/corryvreckan_converter.py @@ -49,9 +49,8 @@ def format_dut(input_filename: str | Path, output_filename: str | Path = None, t hit_table_converted = np.zeros(len(hits_selected), dtype=hit_dtype_converted) with tb.open_file(output_filename, "w") as out_file: hit_table_out = out_file.create_table(out_file.root, name="Hits", description=hit_dtype_converted) - # Internal column and numbers start at 0 TODO: check with corry - hit_table_converted["column"] = hits_selected["col"] + 1 - hit_table_converted["row"] = hits_selected["row"] + 1 + hit_table_converted["column"] = hits_selected["col"] + hit_table_converted["row"] = hits_selected["row"] hit_table_converted["charge"] = (hits_selected["te"] - hits_selected["le"]) & 0x7F # calculate TOT hit_table_converted["timestamp"] = 25 * hits_selected["timestamp"].astype(np.uint64) # convert to ns hit_table_converted["trigger_number"] = 0