From 481ba2bfa228888d238c27969716092b558c4162 Mon Sep 17 00:00:00 2001 From: salman Date: Mon, 31 Aug 2026 17:25:50 +0200 Subject: [PATCH] Add global-asymmetry reference fixtures for beta.3 baseline - global.generated.msr: hermetic buildMSR() golden for the AsymmetryGLB GaussianCos workflow over runs 2452-2460 with shared phase Phi. Verified byte-for-byte against the captured template. - global.fitted.msr: real fitted global result (37 params, shared Phi, 9 runs, chisq/NDF 1.034138, NDF 8198). The run-family THEORY shares params through mapN, which parseMSRTheoryModel safely refuses to reconstruct; the test asserts that refusal. --- tests/fixtures/reference/README.md | 11 +- tests/fixtures/reference/global.fitted.msr | 185 ++++++++++++++++++ tests/fixtures/reference/global.generated.msr | 51 +++++ tests/reference-fixtures.test.js | 89 ++++++++- 4 files changed, 334 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/reference/global.fitted.msr create mode 100644 tests/fixtures/reference/global.generated.msr diff --git a/tests/fixtures/reference/README.md b/tests/fixtures/reference/README.md index 2eb3361..822f746 100644 --- a/tests/fixtures/reference/README.md +++ b/tests/fixtures/reference/README.md @@ -19,8 +19,17 @@ The naming records the workflow: the reverse-parsing path: `tests/reference-fixtures.test.js` verifies that muSRFlow reads it back into GUI state (`parseMSRFitStatistic`, `parseMSRParameters`, `parseMSRTheoryModel`, `parseMSRGUISettings`). +- `global.generated.msr` — global-asymmetry fit (`AsymmetryGLB`, fittype 2) over + runs 2452-2460 with the `GaussianCos` model and a shared phase `Phi`. The + generator emits a single-RUN template (run 2452) that `msr2data` later expands + to all nine runs; the FITPARAMETER already carries the shared + per-run set. +- `global.fitted.msr` — the real **global fit result** over runs 2452-2460: + 37 fitted parameters (one shared `Phi` + 9 runs x `Alpha`/`Asy`/`Sgm`/`Frq`), + converged `chisq/NDF 1.034138` (NDF 8198). Because the run-family THEORY shares + parameters through `mapN`, `parseMSRTheoryModel` deliberately refuses to + reconstruct it (safe guard, editor-owned) — the test asserts that refusal. - *Pending:* `singlehist.generated.msr` (needs a detector-normalization model - to avoid `norm undefined`), `global.generated.msr`, `functions.generated.msr`, + to avoid `norm undefined`), `functions.generated.msr`, `missingdata.generated.msr`. ## Regenerating a fixture diff --git a/tests/fixtures/reference/global.fitted.msr b/tests/fixtures/reference/global.fitted.msr new file mode 100644 index 0000000..d73f10c --- /dev/null +++ b/tests/fixtures/reference/global.fitted.msr @@ -0,0 +1,185 @@ +100nm Li/Li6PS5Cl - 15 months aged, T=290.02 K, E=2.02 keV, B=~100(G)/17.30(A), Tr/Sa=15.00/12.29 kV, SR=-20.00 +############################################################### +FITPARAMETER +# No Name Value Step Pos_Error Boundaries + +# Common parameters for all runs + + 1 Phi 16.78 0.38 none + +# Specific parameters for run 2452 + + 2 Alpha_2452 0.9078 0.0016 none + 3 Asy_2452 0.0915 0.0016 none + 4 Sgm_2452 0.132 0.013 none + 5 Frq_2452 1.3665 0.0010 none + +# Specific parameters for run 2453 + + 6 Alpha_2453 0.9186 0.0016 none + 7 Asy_2453 0.0941 0.0016 none + 8 Sgm_2453 0.168 0.011 none + 9 Frq_2453 1.3702 0.0011 none + +# Specific parameters for run 2454 + + 10 Alpha_2454 0.9126 0.0016 none + 11 Asy_2454 0.1006 0.0017 none + 12 Sgm_2454 0.175 0.011 none + 13 Frq_2454 1.3686 0.0011 none + +# Specific parameters for run 2455 + + 14 Alpha_2455 0.9162 0.0016 none + 15 Asy_2455 0.1039 0.0017 none + 16 Sgm_2455 0.199 0.011 none + 17 Frq_2455 1.3709 0.0011 none + +# Specific parameters for run 2456 + + 18 Alpha_2456 0.9207 0.0016 none + 19 Asy_2456 0.1058 0.0017 none + 20 Sgm_2456 0.193 0.011 none + 21 Frq_2456 1.3703 0.0011 none + +# Specific parameters for run 2457 + + 22 Alpha_2457 0.9270 0.0017 none + 23 Asy_2457 0.1070 0.0017 none + 24 Sgm_2457 0.183 0.010 none + 25 Frq_2457 1.3716 0.0011 none + +# Specific parameters for run 2458 + + 26 Alpha_2458 0.9247 0.0017 none + 27 Asy_2458 0.1083 0.0017 none + 28 Sgm_2458 0.176 0.011 none + 29 Frq_2458 1.3721 0.0010 none + +# Specific parameters for run 2459 + + 30 Alpha_2459 0.9261 0.0017 none + 31 Asy_2459 0.1107 0.0017 none + 32 Sgm_2459 0.177 0.010 none + 33 Frq_2459 1.3715 0.0010 none + +# Specific parameters for run 2460 + + 34 Alpha_2460 0.9205 0.0019 none + 35 Asy_2460 0.1022 0.0019 none + 36 Sgm_2460 0.178 0.013 none + 37 Frq_2460 1.3773 0.0013 none + +############################################################### +THEORY +asymmetry map1 +simpleGss map2 (rate) +TFieldCos 1 map3 (phase frequency) + +############################################################### +# FUNCTIONS + +############################################################### +GLOBAL +fittype 2 (asymmetry fit) +fit 0.07 9 +packing 50 + +############################################################### + +# RUN blocks for run 2452 + +RUN /mnt/fake/lem/his/2026/lem26_his_2452 MUE4 PSI MUSR-ROOT (name beamline institute data-file-format) +alpha 2 +map 3 4 5 0 0 0 0 0 0 0 +forward 21 25 +backward 23 27 + +# RUN blocks for run 2453 + +RUN /mnt/fake/lem/his/2026/lem26_his_2453 MUE4 PSI MUSR-ROOT (name beamline institute data-file-format) +alpha 6 +map 7 8 9 0 0 0 0 0 0 0 +forward 21 25 +backward 23 27 + +# RUN blocks for run 2454 + +RUN /mnt/fake/lem/his/2026/lem26_his_2454 MUE4 PSI MUSR-ROOT (name beamline institute data-file-format) +alpha 10 +map 11 12 13 0 0 0 0 0 0 0 +forward 21 25 +backward 23 27 + +# RUN blocks for run 2455 + +RUN /mnt/fake/lem/his/2026/lem26_his_2455 MUE4 PSI MUSR-ROOT (name beamline institute data-file-format) +alpha 14 +map 15 16 17 0 0 0 0 0 0 0 +forward 21 25 +backward 23 27 + +# RUN blocks for run 2456 + +RUN /mnt/fake/lem/his/2026/lem26_his_2456 MUE4 PSI MUSR-ROOT (name beamline institute data-file-format) +alpha 18 +map 19 20 21 0 0 0 0 0 0 0 +forward 21 25 +backward 23 27 + +# RUN blocks for run 2457 + +RUN /mnt/fake/lem/his/2026/lem26_his_2457 MUE4 PSI MUSR-ROOT (name beamline institute data-file-format) +alpha 22 +map 23 24 25 0 0 0 0 0 0 0 +forward 21 25 +backward 23 27 + +# RUN blocks for run 2458 + +RUN /mnt/fake/lem/his/2026/lem26_his_2458 MUE4 PSI MUSR-ROOT (name beamline institute data-file-format) +alpha 26 +map 27 28 29 0 0 0 0 0 0 0 +forward 21 25 +backward 23 27 + +# RUN blocks for run 2459 + +RUN /mnt/fake/lem/his/2026/lem26_his_2459 MUE4 PSI MUSR-ROOT (name beamline institute data-file-format) +alpha 30 +map 31 32 33 0 0 0 0 0 0 0 +forward 21 25 +backward 23 27 + +# RUN blocks for run 2460 + +RUN /mnt/fake/lem/his/2026/lem26_his_2460 MUE4 PSI MUSR-ROOT (name beamline institute data-file-format) +alpha 34 +map 35 36 37 0 0 0 0 0 0 0 +forward 21 25 +backward 23 27 + +############################################################### +COMMANDS +MAX_LIKELIHOOD +MINIMIZE +HESSE +SAVE + +############################################################### +FOURIER +units Gauss # units either 'Gauss', 'Tesla', 'MHz', or 'Mc/s' +fourier_power 12 +apodization STRONG # NONE, WEAK, MEDIUM, STRONG +plot POWER # REAL, IMAG, REAL_AND_IMAG, POWER, PHASE, PHASE_OPT_REAL +range 0 11 + +############################################################### +PLOT 2 (asymmetry plot) +runs 1 2 3 4 5 6 7 8 9 +range 0 11 -0.3 0.3 +view_packing 500 + +############################################################### +STATISTIC --- 2026-08-31 17:16:16 + chisq = 8477.9, NDF = 8198, chisq/NDF = 1.034138 diff --git a/tests/fixtures/reference/global.generated.msr b/tests/fixtures/reference/global.generated.msr new file mode 100644 index 0000000..4187529 --- /dev/null +++ b/tests/fixtures/reference/global.generated.msr @@ -0,0 +1,51 @@ + +# Run Numbers: 2452-2460 +############################################################### +FITPARAMETER +############################################################### +# No Name Value Step PosErr Min Max + 1 Alpha_2452 0.9077 0.0016 + 2 Asy_2452 0.0915 0.0016 + 3 Sgm_2452 0.132 0.013 + 4 Phi 16.91 0.85 + 5 Frq_2452 1.3664 0.0012 + +############################################################### +THEORY +asymmetry 2 +simpleGss 3 +TFieldCos 4 5 + +GLOBAL +fittype 2 +fit 0.07 9 +packing 50 + +############################################################### +RUN /mnt/fake/lem/his/2026/lem26_his_2452 MUE4 PSI MUSR-ROOT +alpha 1 +forward 21 25 +backward 23 27 +############################################################### +COMMANDS +MAX_LIKELIHOOD +MINIMIZE +HESSE +SAVE +############################################################### +PLOT 2 +runs 1 2 3 4 5 6 7 8 9 +range 0 11 -0.3 0.3 +view_packing 500 + +############################################################### +FOURIER +units Gauss +fourier_power 12 +dc-corrected FALSE +apodization STRONG +plot power +range 0 11 + +############################################################### +# Created by muSRFlow (ZS https://bitbucket.org/zaher-salman/musrfit-gui) diff --git a/tests/reference-fixtures.test.js b/tests/reference-fixtures.test.js index 2fb3889..57128aa 100644 --- a/tests/reference-fixtures.test.js +++ b/tests/reference-fixtures.test.js @@ -79,9 +79,14 @@ function clone(obj) { return JSON.parse(JSON.stringify(obj)); } -function withConfig(overrides) { +function withConfig(overrides, rest) { const config = clone(baseConfig); Object.assign(config.all, overrides || {}); + if (rest) { + if (rest.funOptions) config.funOptions = rest.funOptions; + if (rest.funLines) config.funLines = rest.funLines; + if (rest.sharedFlags) config.sharedFlags = rest.sharedFlags; + } return config; } @@ -105,9 +110,53 @@ const fixtures = { t0BgCommonBgMode: "fixed", t0BgCommonBgFixF: "11", t0BgCommonBgFixB: "12" + }), + // Global-asymmetry fit over runs 2452-2460 with a shared phase (Phi). The + // generator emits a single-RUN template whose THEORY/FITPARAMETER cover the + // whole run family; muSR-ROOT msr2data expands it during the run. + "global": withConfig({ + fitAsyType: "AsymmetryGLB", + Tis: "0.07", + Tfs: "9", + BINS: "50", + minType: "MINIMIZE", + fitObjective: "MAX_LIKELIHOOD", + fftUnits: "Gauss", + fftType: "power", + fftPhase: "", + fftPhaseCorrection: "off", + fftxi: "0", + fftxf: "11", + Tpis: "0", + Tpfs: "11", + Ypis: "-0.3", + Ypfs: "0.3", + VIEWBINS: "500", + theoFunBlock: "asymmetry Asy\nsimpleGss Sgm\nTFieldCos Phi Frq", + runNumbers: "2452-2460", + selYear: "2026", + instrName: "LEM", + dataRoot: "/mnt/fake", + LRBF: "21 25,23 27", + minAlpha: "", maxAlpha: "", minAsy: "", maxAsy: "", + valAlpha_2452: "0.9077", errAlpha_2452: "0.0016", + valAsy_2452: "0.0915", errAsy_2452: "0.0016", + valSgm_2452: "0.132", errSgm_2452: "0.013", + valPhi: "16.91", errPhi: "0.85", + valFrq_2452: "1.3664", errFrq_2452: "0.0012" + }, { + funOptions: [ + { value: "Alpha", disabled: false }, + { value: "Asy", disabled: false }, + { value: "Sgm", disabled: false }, + { value: "Phi", disabled: false }, + { value: "Frq", disabled: false } + ], + sharedFlags: { Phi: true } }) }; + function referenceFixturePath(name) { return path.join(__dirname, "fixtures", "reference", name); } @@ -167,4 +216,42 @@ function testFittedSingleHist(lib) { } testFittedSingleHist(lib); + +function testFittedGlobal(lib) { + const msr = fs.readFileSync(referenceFixturePath("global.fitted.msr"), "utf8"); + + // Converged chi-square global fit over 9 runs (NDF 8198). + const stat = lib.parseMSRFitStatistic(msr); + assert.strictEqual(stat.found, true); + assert.strictEqual(stat.converged, true); + assert.strictEqual(stat.kind, "chisq"); + assert.strictEqual(stat.ndf, "8198"); + assert.strictEqual(stat.value, "1.034138"); + + // 37 fitted parameters: one shared Phi plus 9 runs x 4 run-specific + // (Alpha, Asy, Sgm, Frq). + const params = lib.parseMSRParameters(msr); + assert.strictEqual(params.length, 37); + const names = params.map(function(p) { return p.name; }); + assert.strictEqual(names.filter(function(n) { return n === "Phi"; }).length, 1); + for (const expected of ["Alpha_2452", "Asy_2460", "Sgm_2456", "Frq_2459", "Asy_2452"]) { + assert.ok(names.includes(expected), "expected fitted parameter " + expected); + } + + // GUI settings recover a global asymmetry, max-likelihood fit over the + // expanded run list. + const gui = lib.parseMSRGUISettings(msr); + assert.strictEqual(gui.values.fitAsyType, "AsymmetryGLB"); + assert.strictEqual(gui.values.fitObjective, "MAX_LIKELIHOOD"); + assert.strictEqual(gui.values.runNumbers, "2452,2453,2454,2455,2456,2457,2458,2459,2460"); + + // Multi-run asymmetric THEORY (shared params through mapN) is deliberately + // NOT reconstructed: the GUI refuses to guess a merely-similar model. The + // receiver must see the safe refusal, not a silently-corrupted model. + const theory = lib.parseMSRTheoryModel(msr); + assert.strictEqual(theory.ok, false); + assert.ok(theory.error.length > 0); +} + +testFittedGlobal(lib); console.log("reference fixture tests passed");