Skip to content

k4bench.runner.steering

k4bench.runner.steering

Reconcile a ddsim steering file with a patched geometry.

Steering files configure sensitive detectors by subdetector name. Most of those mappings tolerate a name that is not in the geometry: SIM.action.mapActions and SIM.filter.mapDetFilter are substring-matched against the sensitive detectors that actually exist, so a stale entry is simply never matched. SIM.geometry.regexSensitiveDetector is the exception — each key is resolved to a DetElement by Geant4RegexSensitivesConstruction, and a missing one aborts ddsim during kernel.initialize() with::

dd4hep: DetElement::child Unknown child with name: <detector>

Geometry sweeps remove subdetectors from the compact file, so any steering file naming a removed subdetector that way would fail. This module writes a copy of the steering file with a generated epilogue that drops the unresolvable entries, and leaves everything else untouched.

The copy is written into the run's log directory next to <label>.log so the exact configuration a run used stays inspectable after the fact.

Only patched runs are reconciled. Baseline runs use the original steering file verbatim, which keeps a genuine typo in a steering file a hard error rather than a silently dropped sensitive detector.

reconcile_steering_file

reconcile_steering_file(*, extra_args: list[str], present_detectors: set[str], log_dir: Path, label: str) -> list[str]

Return extra_args with --steeringFile pointing at a reconciled copy.

Returns extra_args unchanged when it carries no steering file, so callers can apply this to every patched run unconditionally.

Parameters:

Name Type Description Default
extra_args list[str]

ddsim arguments for this run, as passed through to the executor.

required
present_detectors set[str]

Subdetector names present in the patched geometry for this run.

required
log_dir Path

Directory the reconciled copy is written to.

required
label str

Run label; used as the filename stem.

required

Returns:

Type Description
list[str]

Arguments to hand to :func:k4bench.runner.executor.run_ddsim.

Source code in k4bench/runner/steering.py
def reconcile_steering_file(
    *,
    extra_args: list[str],
    present_detectors: set[str],
    log_dir: Path,
    label: str,
) -> list[str]:
    """Return *extra_args* with ``--steeringFile`` pointing at a reconciled copy.

    Returns *extra_args* unchanged when it carries no steering file, so callers
    can apply this to every patched run unconditionally.

    Parameters
    ----------
    extra_args:
        ddsim arguments for this run, as passed through to the executor.
    present_detectors:
        Subdetector names present in the patched geometry for this run.
    log_dir:
        Directory the reconciled copy is written to.
    label:
        Run label; used as the filename stem.

    Returns
    -------
    list[str]
        Arguments to hand to :func:`k4bench.runner.executor.run_ddsim`.
    """
    found = _find_steering(extra_args)
    if found is None:
        return extra_args
    idx, prefix, path = found

    original = Path(path)
    dest = log_dir / f"{label}_steering.py"
    dest.parent.mkdir(parents=True, exist_ok=True)
    dest.write_text(
        original.read_text() + _epilogue(original, label, present_detectors)
    )

    patched = list(extra_args)
    patched[idx] = f"{prefix}{dest}"
    return patched