#!/usr/bin/env python3
import json, hashlib, math
from pathlib import Path
R=Path(__file__).resolve().parent
f=R/'PROTON_ORIGIN_CLS_RGI_QUARK_HARDENING_V2_2026-08-16.json'
d=R/'PROTON_ORIGIN_CLS_RGI_QUARK_HARDENING_V2_POSTFREEZE_DIAGNOSTICS_2026-08-16.json'
c=R/'PROTON_ORIGIN_RESULT04_FINAL_CLOSEOUT_V2_2026-08-16.json'
r=json.loads(f.read_text()); dg=json.loads(d.read_text()); cl=json.loads(c.read_text())
h=hashlib.sha256(f.read_bytes()).hexdigest()
assert h==cl['forward_sha256']==dg['forward_sha256']
assert r['holdout_used'] is False
assert dg['no_post_freeze_retuning'] is True
assert abs(sum(x['weight'] for x in r['models'].values())-1)<1e-12
wm=sum(x['weight']*x['M_GeV'] for x in r['models'].values())
assert abs(wm-r['model_avg_central_GeV'])<1e-14
assert cl['verdict']=='PASS_TARGET_ISOLATED_ISOQCD_NUCLEON_MASS_CLOSURE'
print('RESULT04_V2_VERIFY_PASS')
print(f"M_N_isoQCD = {1000*r['model_avg_central_GeV']:.6f} +/- {1000*r['MC']['sigma_GeV']:.6f} MeV")
print('forward_sha256 =',h)
