diff --git a/README.md b/README.md index 0d6ecb1..4b265c0 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,10 @@ The harness writes both simulations to temporary directories and compares the logical ROOT contents exactly. Set `MUSRSIM_ROOT_COMPARATOR` when the comparator is not available under `tests/` beside the candidate executable. +The same differential comparison is available for the GPS Mark-II setup: + + tests/compare_gps_versions.sh /path/to/baseline/musrSim /path/to/candidate/musrSim 500 + ### Running the simulations ### Prepare a file, `filename.mac`, with your beamline and spectrometer design following the instructions in the [musrSim manual](https://bitbucket.org/muonspin/musrsim/src/master/doc/musrSim.pdf). Create a folder `data` and then run the simulation diff --git a/tests/compare_gps_versions.sh b/tests/compare_gps_versions.sh new file mode 100755 index 0000000..9b3f027 --- /dev/null +++ b/tests/compare_gps_versions.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -euo pipefail + +script_directory=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +source_directory=$(cd "$script_directory/.." && pwd) + +exec "$script_directory/compare_musr_versions.sh" \ + "$source_directory/run/GPS/template_Mark-II.mac" \ + 95000 \ + 500 \ + "$@" diff --git a/tests/compare_lem_versions.sh b/tests/compare_lem_versions.sh index 3528d87..a526415 100755 --- a/tests/compare_lem_versions.sh +++ b/tests/compare_lem_versions.sh @@ -2,94 +2,11 @@ set -euo pipefail -usage() { - echo "usage: $0 [events]" >&2 - echo "set MUSRSIM_ROOT_COMPARATOR if the comparator is not beside the candidate build" >&2 -} - -if [[ $# -lt 2 || $# -gt 3 ]]; then - usage - exit 2 -fi - -baseline_binary=$(realpath "$1") -candidate_binary=$(realpath "$2") -events=${3:-500} - -if [[ ! -x "$baseline_binary" || ! -x "$candidate_binary" ]]; then - echo "both musrSim paths must be executable" >&2 - exit 2 -fi -if [[ ! "$events" =~ ^[1-9][0-9]*$ ]]; then - echo "event count must be a positive integer" >&2 - exit 2 -fi - script_directory=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) source_directory=$(cd "$script_directory/.." && pwd) -lem_directory="$source_directory/run/LEM" -source_macro="$lem_directory/4000_15kV_ModUniform_SR-10_ModRot0deg.mac" -if [[ -n ${MUSRSIM_ROOT_COMPARATOR:-} ]]; then - comparator=$(realpath "$MUSRSIM_ROOT_COMPARATOR") -else - candidate_directory=$(dirname "$candidate_binary") - comparator="$candidate_directory/tests/musrRootOutputCompare" -fi -if [[ ! -x "$comparator" ]]; then - echo "ROOT comparator not found at $comparator" >&2 - echo "build the musrRootOutputCompare target or set MUSRSIM_ROOT_COMPARATOR" >&2 - exit 2 -fi - -work_directory=$(mktemp -d "${TMPDIR:-/tmp}/musrsim-lem-compare.XXXXXX") -trap 'rm -rf "$work_directory"' EXIT -mkdir -p "$work_directory/baseline" "$work_directory/candidate" - -make_macro() { - local output_directory=$1 - local output_macro=$2 - awk -v events="$events" -v output_directory="$output_directory" ' - /^[[:space:]]*\/run\/beamOn[[:space:]]+/ { - ++beam_on_count - print "/musr/command rootOutputDirectoryName " output_directory - print "/musr/run/runID 94000" - print "/run/beamOn " events - next - } - { print } - END { - if (beam_on_count != 1) { - print "expected exactly one active /run/beamOn command" > "/dev/stderr" - exit 2 - } - } - ' "$source_macro" > "$output_macro" -} - -run_version() { - local label=$1 - local binary=$2 - local output_directory="$work_directory/$label" - local macro="$work_directory/$label.mac" - local log="$work_directory/$label.log" - - make_macro "$output_directory" "$macro" - if ! (cd "$lem_directory" && "$binary" "$macro") >"$log" 2>&1; then - echo "$label simulation failed; final log lines:" >&2 - tail -40 "$log" >&2 - exit 1 - fi - - local root_file="$output_directory/musr_94000.root" - if [[ ! -f "$root_file" ]]; then - echo "$label simulation did not create $root_file" >&2 - exit 1 - fi - echo "$root_file" -} - -baseline_output=$(run_version baseline "$baseline_binary") -candidate_output=$(run_version candidate "$candidate_binary") - -"$comparator" "$baseline_output" "$candidate_output" +exec "$script_directory/compare_musr_versions.sh" \ + "$source_directory/run/LEM/4000_15kV_ModUniform_SR-10_ModRot0deg.mac" \ + 94000 \ + 500 \ + "$@" diff --git a/tests/compare_musr_versions.sh b/tests/compare_musr_versions.sh new file mode 100755 index 0000000..4dbd0ec --- /dev/null +++ b/tests/compare_musr_versions.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env bash + +set -euo pipefail + +usage() { + echo "usage: ${MUSRSIM_COMPARE_COMMAND:-$0} [events]" >&2 + echo "set MUSRSIM_ROOT_COMPARATOR if the comparator is not beside the candidate build" >&2 +} + +if [[ $# -lt 5 || $# -gt 6 ]]; then + usage + exit 2 +fi + +source_macro=$(realpath "$1") +run_id=$2 +default_events=$3 +baseline_binary=$(realpath "$4") +candidate_binary=$(realpath "$5") +events=${6:-$default_events} + +if [[ ! -f "$source_macro" ]]; then + echo "source macro not found: $source_macro" >&2 + exit 2 +fi +if [[ ! -x "$baseline_binary" || ! -x "$candidate_binary" ]]; then + echo "both musrSim paths must be executable" >&2 + exit 2 +fi +if [[ ! "$run_id" =~ ^[1-9][0-9]*$ ]]; then + echo "run ID must be a positive integer" >&2 + exit 2 +fi +if [[ ! "$events" =~ ^[1-9][0-9]*$ ]]; then + echo "event count must be a positive integer" >&2 + exit 2 +fi + +macro_directory=$(dirname "$source_macro") + +if [[ -n ${MUSRSIM_ROOT_COMPARATOR:-} ]]; then + comparator=$(realpath "$MUSRSIM_ROOT_COMPARATOR") +else + candidate_directory=$(dirname "$candidate_binary") + comparator="$candidate_directory/tests/musrRootOutputCompare" +fi +if [[ ! -x "$comparator" ]]; then + echo "ROOT comparator not found at $comparator" >&2 + echo "build the musrRootOutputCompare target or set MUSRSIM_ROOT_COMPARATOR" >&2 + exit 2 +fi + +macro_name=$(basename "$source_macro" .mac) +work_directory=$(mktemp -d "${TMPDIR:-/tmp}/musrsim-${macro_name}-compare.XXXXXX") +trap 'rm -rf "$work_directory"' EXIT +mkdir -p "$work_directory/baseline" "$work_directory/candidate" + +make_macro() { + local output_directory=$1 + local output_macro=$2 + awk -v events="$events" -v output_directory="$output_directory" -v run_id="$run_id" ' + /^[[:space:]]*\/run\/beamOn[[:space:]]+/ { + ++beam_on_count + print "/musr/command rootOutputDirectoryName " output_directory + print "/musr/run/runID " run_id + print "/run/beamOn " events + next + } + { print } + END { + if (beam_on_count != 1) { + print "expected exactly one active /run/beamOn command" > "/dev/stderr" + exit 2 + } + } + ' "$source_macro" > "$output_macro" +} + +run_version() { + local label=$1 + local binary=$2 + local output_directory="$work_directory/$label" + local macro="$work_directory/$label.mac" + local log="$work_directory/$label.log" + + make_macro "$output_directory" "$macro" + if ! (cd "$macro_directory" && "$binary" "$macro") >"$log" 2>&1; then + echo "$label simulation failed; final log lines:" >&2 + tail -40 "$log" >&2 + exit 1 + fi + + local root_file="$output_directory/musr_${run_id}.root" + if [[ ! -f "$root_file" ]]; then + echo "$label simulation did not create $root_file" >&2 + exit 1 + fi + echo "$root_file" +} + +baseline_output=$(run_version baseline "$baseline_binary") +candidate_output=$(run_version candidate "$candidate_binary") + +"$comparator" "$baseline_output" "$candidate_output"