From 94bd9ce64ce085725ae696dacfcfd040bcd7e65a Mon Sep 17 00:00:00 2001 From: Thomas Kittelmann Date: Wed, 30 Sep 2026 21:17:54 +0000 Subject: [PATCH] Union_abs_logger_nD_scintillator: add table_dir parameter for the location of the tables The component reads its 10 pixel-hit-efficiency tables by fixed file names, which McStas looks up e.g. in the working directory and next to the instrument file. Since McStas only ships the tables next to the test instrument, other instruments must copy them next to themselves. The new parameter table_dir gives the directory of the tables (e.g. "localdata"), so instruments can keep them in a subdirectory. The default ("") keeps the previous behaviour. Co-Authored-By: Claude Opus 5.5 --- .../Union_abs_logger_nD_scintillator.comp | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/mcstas-comps/union/Union_abs_logger_nD_scintillator.comp b/mcstas-comps/union/Union_abs_logger_nD_scintillator.comp index 9335fe7a7..110c44bcb 100644 --- a/mcstas-comps/union/Union_abs_logger_nD_scintillator.comp +++ b/mcstas-comps/union/Union_abs_logger_nD_scintillator.comp @@ -150,6 +150,7 @@ * nowritefile: [1] If set, logger will skip writing to disk * nexus_bins: [1] NeXus mode only: store component BIN information
(-1 disable, 0 enable for list mode monitor, 1 enable for any montor) * is_high_resolution: [0|1] Selects the MAPMT pixel size (0: low resolution, 6 mm pixels; 1: high resolution, 3 mm pixels), and correspondingly which set of pixel-hit-efficiency table files is read. +* table_dir: [str] Directory of the table files (default: none) * * OUTPUT PARAMETERS: * @@ -173,7 +174,7 @@ SETTING PARAMETERS(string target_geometry="NULL", string options="NULL", string filename="NULL",string geometry="NULL", int nowritefile=0, int nexus_bins=0, string username0="NULL", string username1="NULL", string username2="NULL", string username3="NULL", string username4="NULL", string username5="NULL", string username6="NULL", string username7="NULL", string username8="NULL", string username9="NULL", - int is_high_resolution=0) + int is_high_resolution=0, string table_dir="") OUTPUT PARAMETERS () /* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */ @@ -185,6 +186,16 @@ SHARE #endif %include "monitor_nd-lib" + + // The file name, in the directory dir (if not empty): + char* + scintillator_table_file (char* buffer, size_t size, char* dir, char* file) { + if (dir && dir[0]) + snprintf (buffer, size, "%s/%s", dir, file); + else + snprintf (buffer, size, "%s", file); + return buffer; + } %include "read_table-lib" %include "interoff-lib" @@ -712,25 +723,27 @@ DECLARE INITIALIZE INHERIT Monitor_nD EXTEND %{ + char table_file[1024]; + #define TABLE_FILE(file) scintillator_table_file (table_file, sizeof (table_file), table_dir, file) if (is_high_resolution) { if (high_resolution_efficiency_tables_already_read == 0) { - if (Table_Read (&high_resolution_true_pixel_detection_efficiency_table, "true_pixel_hit_efficiency_high_resolution.txt", 0) <= 0) { + if (Table_Read (&high_resolution_true_pixel_detection_efficiency_table, TABLE_FILE ("true_pixel_hit_efficiency_high_resolution.txt"), 0) <= 0) { exit (fprintf (stderr, "Union_abs_logger_nD_scintillator: %s: can not read pixel hit efficiency file true_pixel_hit_efficiency_high_resolution.txt\n", NAME_CURRENT_COMP)); } - if (Table_Read (&high_resolution_up_pixel_detection_efficiency_table, "up_pixel_hit_efficiency_high_resolution.txt", 0) <= 0) { + if (Table_Read (&high_resolution_up_pixel_detection_efficiency_table, TABLE_FILE ("up_pixel_hit_efficiency_high_resolution.txt"), 0) <= 0) { exit (fprintf (stderr, "Union_abs_logger_nD_scintillator: %s: can not read pixel hit efficiency file up_pixel_hit_efficiency_high_resolution.txt\n", NAME_CURRENT_COMP)); } - if (Table_Read (&high_resolution_down_pixel_detection_efficiency_table, "down_pixel_hit_efficiency_high_resolution.txt", 0) <= 0) { + if (Table_Read (&high_resolution_down_pixel_detection_efficiency_table, TABLE_FILE ("down_pixel_hit_efficiency_high_resolution.txt"), 0) <= 0) { exit (fprintf (stderr, "Union_abs_logger_nD_scintillator: %s: can not read pixel hit efficiency file down_pixel_hit_efficiency_high_resolution.txt\n", NAME_CURRENT_COMP)); } - if (Table_Read (&high_resolution_left_pixel_detection_efficiency_table, "left_pixel_hit_efficiency_high_resolution.txt", 0) <= 0) { + if (Table_Read (&high_resolution_left_pixel_detection_efficiency_table, TABLE_FILE ("left_pixel_hit_efficiency_high_resolution.txt"), 0) <= 0) { exit (fprintf (stderr, "Union_abs_logger_nD_scintillator: %s: can not read pixel hit efficiency file left_pixel_hit_efficiency_high_resolution.txt\n", NAME_CURRENT_COMP)); } - if (Table_Read (&high_resolution_right_pixel_detection_efficiency_table, "right_pixel_hit_efficiency_high_resolution.txt", 0) <= 0) { + if (Table_Read (&high_resolution_right_pixel_detection_efficiency_table, TABLE_FILE ("right_pixel_hit_efficiency_high_resolution.txt"), 0) <= 0) { exit (fprintf (stderr, "Union_abs_logger_nD_scintillator: %s: can not read pixel hit efficiency file right_pixel_hit_efficiency_high_resolution.txt\n", NAME_CURRENT_COMP)); } @@ -738,22 +751,22 @@ INITIALIZE INHERIT Monitor_nD EXTEND } } else { if (low_resolution_efficiency_tables_already_read == 0) { - if (Table_Read (&low_resolution_true_pixel_detection_efficiency_table, "true_pixel_hit_efficiency.txt", 0) <= 0) { + if (Table_Read (&low_resolution_true_pixel_detection_efficiency_table, TABLE_FILE ("true_pixel_hit_efficiency.txt"), 0) <= 0) { exit ( fprintf (stderr, "Union_abs_logger_nD_scintillator: %s: can not read pixel hit efficiency file true_pixel_hit_efficiency.txt\n", NAME_CURRENT_COMP)); } - if (Table_Read (&low_resolution_up_pixel_detection_efficiency_table, "up_pixel_hit_efficiency.txt", 0) <= 0) { + if (Table_Read (&low_resolution_up_pixel_detection_efficiency_table, TABLE_FILE ("up_pixel_hit_efficiency.txt"), 0) <= 0) { exit (fprintf (stderr, "Union_abs_logger_nD_scintillator: %s: can not read pixel hit efficiency file up_pixel_hit_efficiency.txt\n", NAME_CURRENT_COMP)); } - if (Table_Read (&low_resolution_down_pixel_detection_efficiency_table, "down_pixel_hit_efficiency.txt", 0) <= 0) { + if (Table_Read (&low_resolution_down_pixel_detection_efficiency_table, TABLE_FILE ("down_pixel_hit_efficiency.txt"), 0) <= 0) { exit ( fprintf (stderr, "Union_abs_logger_nD_scintillator: %s: can not read pixel hit efficiency file down_pixel_hit_efficiency.txt\n", NAME_CURRENT_COMP)); } - if (Table_Read (&low_resolution_left_pixel_detection_efficiency_table, "left_pixel_hit_efficiency.txt", 0) <= 0) { + if (Table_Read (&low_resolution_left_pixel_detection_efficiency_table, TABLE_FILE ("left_pixel_hit_efficiency.txt"), 0) <= 0) { exit ( fprintf (stderr, "Union_abs_logger_nD_scintillator: %s: can not read pixel hit efficiency file left_pixel_hit_efficiency.txt\n", NAME_CURRENT_COMP)); } - if (Table_Read (&low_resolution_right_pixel_detection_efficiency_table, "right_pixel_hit_efficiency.txt", 0) <= 0) { + if (Table_Read (&low_resolution_right_pixel_detection_efficiency_table, TABLE_FILE ("right_pixel_hit_efficiency.txt"), 0) <= 0) { exit ( fprintf (stderr, "Union_abs_logger_nD_scintillator: %s: can not read pixel hit efficiency file right_pixel_hit_efficiency.txt\n", NAME_CURRENT_COMP)); } @@ -782,6 +795,8 @@ INITIALIZE INHERIT Monitor_nD EXTEND if (!this_abs_storage.temp_abs_nD_scintillator_data.elements) exit (fprintf (stderr, "Union_abs_logger_nD_scintillator: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); + #undef TABLE_FILE + this_abs_storage.pixel_size = is_high_resolution ? 0.003 : 0.006; // 3 mm for high resolution, 6 mm for low resolution if (is_high_resolution) {