Skip to content

Union_abs_logger_nD_scintillator: add table_dir parameter flexible data location - #2720

Open
tkittel wants to merge 1 commit into
mccode-dev:mainfrom
tkittel:scintillator-table-dir
Open

tkittel wants to merge 1 commit into
mccode-dev:mainfrom
tkittel:scintillator-table-dir

Conversation

@tkittel

@tkittel tkittel commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

This is needed so we can have SKADI using this component instead of a local copy (there might be other work needed as well, but this is a blocker).

The rest from claude:

Union_abs_logger_nD_scintillator: add table_dir parameter for the location of the tables

Union_abs_logger_nD_scintillator (new in McStas 3.8.8) reads its 10
pixel-hit-efficiency tables by fixed file names, e.g.
"true_pixel_hit_efficiency.txt" or
"true_pixel_hit_efficiency_high_resolution.txt". McStas looks for these, as
for other data files:

  • in the working directory;
  • next to the instrument file;
  • in the McStas data directories.

The tables are only shipped next to the test instrument
(examples/Tests_union/Test_abs_logger_nD_scintillator/). So every other
instrument using the component must copy the 10 tables next to itself. This
is inconvenient for instrument repositories that keep their data files in a
subdirectory. For example, in the standard layout of the ESS instrument model
repositories they go into localdata/, and the SKADI model (which uses this
component) needs exactly this.

This PR adds the parameter:

string table_dir=""

It gives the directory of the tables, e.g. table_dir="localdata", so that
the tables are looked up as localdata/true_pixel_hit_efficiency.txt etc.,
with the same search rules as before. The default "" keeps the previous
behaviour, so existing instruments are not affected.

The change is small: a short helper function, and the file names in the 10
Table_Read calls are wrapped in TABLE_FILE (...). The code was checked
with devel/bin/mccode-clangformat (no changes needed).

Testing

Tested with McStas 3.8.8 (conda-forge) and the test instrument
Test_abs_logger_nD_scintillator, with 1e6 rays and a fixed seed. The
component was placed next to the instrument, so it takes precedence:

Case Component Tables Result
A unmodified (main) next to the instrument reference
B this PR, table_dir not set next to the instrument identical to A
C this PR, table_dir="tables" for all 4 loggers in tables/ identical to A
D this PR, table_dir="nosuchdir" – fails (can not read the tables)

"Identical" means that all monitor values in mccode.sim are identical, and
that the list-mode output is identical apart from the ray number column. That
column differs even between two runs of the unmodified component with the same
seed. See the attached test output for details.

Possible follow-up

The tables could also be installed in the McStas data directory, so that
instruments find them without copies at all. They are specific to the SoNDe
detector type modelled by the component, so they are needed by every
instrument using it. This PR does not do that.

🤖 Generated with Claude Code

…ation 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 <noreply@anthropic.com>
@tkittel

tkittel commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Test output for the table_dir parameter of Union_abs_logger_nD_scintillator

McStas 3.8.8 (conda-forge), Test_abs_logger_nD_scintillator, mcrun -n 1e6 -s 1234, with the component placed next to the instrument.

Case C sets table_dir = "tables" for all four loggers (tables moved to tables/):

115: filename = "abs_logger_nD_scintillator", is_high_resolution = 0, table_dir = "tables")
127: filename = "abs_logger_nD_scintillator_con", is_high_resolution = 0, table_dir = "tables")
139: filename = "abs_logger_nD_scintillator_high_resolution", is_high_resolution = 1, table_dir = "tables")
151: filename = "abs_logger_nD_scintillator_list", is_high_resolution = 0, table_dir = "tables")

Monitor values (mccode.sim)

Case A:

filename: abs_logger_nD_scintillator.x_y	  values: 9.34949e-13 2.28608e-15 1.20586e+06
filename: abs_logger_nD_scintillator_con.x_y	  values: 9.38168e-13 2.28945e-15 1.21443e+06
filename: abs_logger_nD_scintillator_high_resolution.x_y	  values: 2.87904e-13 9.35543e-16 1.00217e+06
filename: abs_logger_nD_scintillator_list_list.p.x.y.n.id.t	  values: 0 0 0

Case B:

filename: abs_logger_nD_scintillator.x_y	  values: 9.34949e-13 2.28608e-15 1.20586e+06
filename: abs_logger_nD_scintillator_con.x_y	  values: 9.38168e-13 2.28945e-15 1.21443e+06
filename: abs_logger_nD_scintillator_high_resolution.x_y	  values: 2.87904e-13 9.35543e-16 1.00217e+06
filename: abs_logger_nD_scintillator_list_list.p.x.y.n.id.t	  values: 0 0 0

Case C:

filename: abs_logger_nD_scintillator.x_y	  values: 9.34949e-13 2.28608e-15 1.20586e+06
filename: abs_logger_nD_scintillator_con.x_y	  values: 9.38168e-13 2.28945e-15 1.21443e+06
filename: abs_logger_nD_scintillator_high_resolution.x_y	  values: 2.87904e-13 9.35543e-16 1.00217e+06
filename: abs_logger_nD_scintillator_list_list.p.x.y.n.id.t	  values: 0 0 0

List-mode output (abs_logger_nD_scintillator_list), compared to case A

A vs A2 (A2: unmodified component, rerun with the same seed): differs, without the ray number column n: identical
A vs B: differs, without the ray number column n: identical
A vs C: differs, without the ray number column n: identical

Case D (table_dir = "nosuchdir")

Union_abs_logger_nD_scintillator: abs_logger_nD_scintillator: can not read pixel hit efficiency file true_pixel_hit_efficiency.txt

@tkittel

tkittel commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

The failed job looks to be just the usual suspect.

@mads-bertelsen

Copy link
Copy Markdown
Contributor

Just for the record @MilanKlausz who contributed the component wrote me and asked for advise on where to place these datafiles, and since they are highly specific to one instrument I recommended the instrument folder, and then a simple one for the test case.

@tkittel

tkittel commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Right @mads-bertelsen that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants