File indexing completed on 2026-05-27 07:24:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 from .plot_detector_scan import (
0010 read_detector_scan_data,
0011 read_intersection_data,
0012 plot_intersection_points_xy,
0013 plot_intersection_points_rz,
0014 plot_intersection_pos_res,
0015 )
0016 from .plot_track_params import (
0017 read_track_data,
0018 compare_track_pos_xy,
0019 compare_track_pos_rz,
0020 plot_track_pos_dist,
0021 plot_track_pos_res,
0022 )
0023
0024
0025 import pandas as pd
0026 import os
0027
0028 """ Construct a string in the format of the output file names and compare it"""
0029
0030
0031 def __comp_filename(filename, det_name, file_stem, p_min="", p_max=""):
0032 check_file_stem = f"{det_name}_{file_stem}" in filename
0033 check_p_min = f"_{p_min}" in filename
0034 check_p_max = f"_{p_max}" in filename
0035
0036 return check_file_stem and check_p_min and check_p_max
0037
0038
0039 """ Read the detector scan data from files and prepare data frames """
0040
0041
0042 def read_scan_data(logging, inputdir, det_name, p_min, p_max):
0043
0044
0045 data_dir = os.fsencode(inputdir)
0046
0047 ray_scan_intersections_file = ray_scan_track_param_file = ""
0048 helix_scan_intersections_file = helix_scan_track_param_file = ""
0049
0050
0051 for file in os.listdir(data_dir):
0052 filename = os.fsdecode(file)
0053
0054 if __comp_filename(filename, det_name, "ray_scan_intersections"):
0055 ray_scan_intersections_file = inputdir + "/" + filename
0056 elif __comp_filename(filename, det_name, "ray_scan_track_parameters"):
0057 ray_scan_track_param_file = inputdir + "/" + filename
0058 elif __comp_filename(
0059 filename, det_name, "helix_scan_intersections", p_min, p_max
0060 ):
0061 helix_scan_intersections_file = inputdir + "/" + filename
0062 elif __comp_filename(
0063 filename, det_name, "helix_scan_track_parameters", p_min, p_max
0064 ):
0065 helix_scan_track_param_file = inputdir + "/" + filename
0066
0067
0068 ray_scan_df = read_detector_scan_data(
0069 ray_scan_intersections_file, ray_scan_track_param_file, logging
0070 )
0071
0072
0073 helix_scan_df = read_detector_scan_data(
0074 helix_scan_intersections_file, helix_scan_track_param_file, logging
0075 )
0076
0077 return ray_scan_df, helix_scan_df
0078
0079
0080 """ Read the recorded track positions from files and prepare data frames """
0081
0082
0083 def read_navigation_intersection_data(
0084 logging, inputdir, det_name, p_min, p_max, read_cuda
0085 ):
0086
0087
0088 data_dir = os.fsencode(inputdir)
0089
0090 ray_truth_file = ray_data_file = ray_data_cuda_file = ""
0091 helix_truth_file = helix_data_file = helix_data_cuda_file = ""
0092
0093
0094 for file in os.listdir(data_dir):
0095 filename = os.fsdecode(file)
0096
0097 if read_cuda and __comp_filename(
0098 filename, det_name, "ray_navigation_intersections_cuda"
0099 ):
0100 ray_data_cuda_file = inputdir + "/" + filename
0101 elif __comp_filename(filename, det_name, "ray_navigation_intersections"):
0102 ray_data_file = inputdir + "/" + filename
0103 elif __comp_filename(filename, det_name, "ray_truth_intersections"):
0104 ray_truth_file = inputdir + "/" + filename
0105 elif read_cuda and __comp_filename(
0106 filename, det_name, "helix_navigation_intersections_cuda", p_min, p_max
0107 ):
0108 helix_data_cuda_file = inputdir + "/" + filename
0109 elif __comp_filename(
0110 filename, det_name, "helix_navigation_intersections", p_min, p_max
0111 ):
0112 helix_data_file = inputdir + "/" + filename
0113 elif __comp_filename(
0114 filename, det_name, "helix_truth_intersections", p_min, p_max
0115 ):
0116 helix_truth_file = inputdir + "/" + filename
0117
0118 ray_df = read_intersection_data(ray_data_file, logging)
0119 ray_truth_df = read_intersection_data(ray_truth_file, logging)
0120 helix_df = read_intersection_data(helix_data_file, logging)
0121 helix_truth_df = read_intersection_data(helix_truth_file, logging)
0122
0123 ray_cuda_df = helix_cuda_df = pd.DataFrame({})
0124 if read_cuda:
0125 ray_cuda_df = read_intersection_data(ray_data_cuda_file, logging)
0126 helix_cuda_df = read_intersection_data(helix_data_cuda_file, logging)
0127
0128 return ray_df, ray_truth_df, ray_cuda_df, helix_df, helix_truth_df, helix_cuda_df
0129
0130
0131 """ Read the recorded track positions from files and prepare data frames """
0132
0133
0134 def read_navigation_track_data(logging, inputdir, det_name, p_min, p_max, read_cuda):
0135
0136
0137 data_dir = os.fsencode(inputdir)
0138
0139 ray_truth_file = ray_data_file = ray_data_cuda_file = ""
0140 helix_truth_file = helix_data_file = helix_data_cuda_file = ""
0141
0142
0143 for file in os.listdir(data_dir):
0144 filename = os.fsdecode(file)
0145
0146 if read_cuda and __comp_filename(
0147 filename, det_name, "ray_navigation_track_params_cuda"
0148 ):
0149 ray_data_cuda_file = inputdir + "/" + filename
0150 elif __comp_filename(filename, det_name, "ray_navigation_track_params"):
0151 ray_data_file = inputdir + "/" + filename
0152 elif __comp_filename(filename, det_name, "ray_truth_track_params"):
0153 ray_truth_file = inputdir + "/" + filename
0154 elif read_cuda and __comp_filename(
0155 filename, det_name, "helix_navigation_track_params_cuda", p_min, p_max
0156 ):
0157 helix_data_cuda_file = inputdir + "/" + filename
0158 elif __comp_filename(
0159 filename, det_name, "helix_navigation_track_params", p_min, p_max
0160 ):
0161 helix_data_file = inputdir + "/" + filename
0162 elif __comp_filename(
0163 filename, det_name, "helix_truth_track_params", p_min, p_max
0164 ):
0165 helix_truth_file = inputdir + "/" + filename
0166
0167 ray_df = read_track_data(ray_data_file, logging)
0168 ray_truth_df = read_track_data(ray_truth_file, logging)
0169 helix_df = read_track_data(helix_data_file, logging)
0170 helix_truth_df = read_track_data(helix_truth_file, logging)
0171
0172 ray_cuda_df = helix_cuda_df = pd.DataFrame({})
0173 if read_cuda:
0174 ray_cuda_df = read_track_data(ray_data_cuda_file, logging)
0175 helix_cuda_df = read_track_data(helix_data_cuda_file, logging)
0176
0177 return ray_df, ray_truth_df, ray_cuda_df, helix_df, helix_truth_df, helix_cuda_df
0178
0179
0180 """ Plot the intersection data gathered during the detector scan """
0181
0182
0183 def plot_detector_scan_data(
0184 args, det_name, plot_factory, data_type, df_scan, out_format="png"
0185 ):
0186
0187
0188 plot_intersection_points_xy(
0189 args, df_scan, det_name, data_type, plot_factory, out_format
0190 )
0191 plot_intersection_points_rz(
0192 args, df_scan, det_name, data_type, plot_factory, out_format
0193 )
0194
0195
0196 """ Plot the intersection data gathered during the navigation validation """
0197
0198
0199 def plot_navigation_intersection_data(
0200 args, det_name, plot_factory, data_type, df_scan, df_nav, label, out_format="png"
0201 ):
0202
0203 plot_intersection_pos_res(
0204 args,
0205 det_name,
0206 plot_factory,
0207 data_type,
0208 df_scan,
0209 "truth",
0210 df_nav,
0211 label,
0212 "loc_0",
0213 out_format,
0214 )
0215 plot_intersection_pos_res(
0216 args,
0217 det_name,
0218 plot_factory,
0219 data_type,
0220 df_scan,
0221 "truth",
0222 df_nav,
0223 label,
0224 "loc_1",
0225 out_format,
0226 )
0227
0228
0229 """ Plot the track data gathered during the navigation validation """
0230
0231
0232 def plot_navigation_track_data(
0233 args,
0234 det_name,
0235 plot_factory,
0236 data_type,
0237 df_truth,
0238 truth_name,
0239 df_ref,
0240 ref_name,
0241 out_format="png",
0242 ):
0243
0244
0245 compare_track_pos_xy(
0246 args,
0247 det_name,
0248 data_type,
0249 plot_factory,
0250 out_format,
0251 df_truth,
0252 truth_name,
0253 "r",
0254 df_ref,
0255 ref_name,
0256 "darkgrey",
0257 )
0258
0259 compare_track_pos_rz(
0260 args,
0261 det_name,
0262 data_type,
0263 plot_factory,
0264 out_format,
0265 df_truth,
0266 truth_name,
0267 "r",
0268 df_ref,
0269 ref_name,
0270 "darkgrey",
0271 )
0272
0273
0274 plot_track_pos_dist(
0275 args,
0276 det_name,
0277 data_type,
0278 plot_factory,
0279 out_format,
0280 df_truth,
0281 truth_name,
0282 df_ref,
0283 ref_name,
0284 )
0285
0286
0287 plot_track_pos_res(
0288 args,
0289 det_name,
0290 data_type,
0291 plot_factory,
0292 out_format,
0293 df_truth,
0294 truth_name,
0295 df_ref,
0296 ref_name,
0297 "x",
0298 )
0299 plot_track_pos_res(
0300 args,
0301 det_name,
0302 data_type,
0303 plot_factory,
0304 out_format,
0305 df_truth,
0306 truth_name,
0307 df_ref,
0308 ref_name,
0309 "y",
0310 )
0311 plot_track_pos_res(
0312 args,
0313 det_name,
0314 data_type,
0315 plot_factory,
0316 out_format,
0317 df_truth,
0318 truth_name,
0319 df_ref,
0320 ref_name,
0321 "z",
0322 )