accelmo.momentum_reference¶
Fit bends and quads to closed orbit + phase, and hand back a closed-orbit reference.
Purpose¶
A transverse-momentum reconstruction requires the closed-orbit angle px/py
at every BPM. BPMs measure position only, so the angle must come from a model. A
nominal model without the machine’s magnet errors gives an incorrect angle; on PSB
ring 3 with realistic dipole errors the nominal angle error equals the true angle.
Fitting the errors to a closed-orbit measurement corrects this, subject to three requirements:
Regularisation. With 80 knobs against 17 BPMs at realistic resolution, an unregularised fit recovers an error vector ~6x larger than the true one, because noise is absorbed into compensating magnet errors, so
knob_sigmas(a Gaussian prior of the expected error size) is required.Knob families matched to observables. The closed orbit is insensitive to gradient errors (a quadrupole on a centred orbit produces no deflection), so free quadrupole knobs in an orbit-only fit worsen the result by ~2.6x. Phase advance responds to gradients; with phase included the same knobs improve it ~4x.
More than one momentum. At a single momentum the per-magnet Jacobians are degenerate.
Observables¶
The default observables are closed orbit and phase advance. Phase requires no
amplitude calibration and, unlike beta-from-amplitude or a model-derived
DPX/DPY, does not feed a modelled quantity back into the model fit. Beta
and dispersion can be selected through observables when the measurement supports
them.
Consuming the result¶
MomentumReference is plain data: fitted knob values and a per-BPM
closed-orbit frame with x/y/px/py. A downstream reconstruction can
use it without importing from this package.
The reference is a momentum origin as well as an orbit. A reconstruction expressed
against MomentumReference.closed_orbit requires the offset from
MomentumReference.reference_pt, not the measurement’s absolute pt. For
a reference \(3\times10^{-3}\) off the origin, using the absolute pt as the
offset degrades the reconstructed px from 4.741e-4 to 7.702e-2, against
1.162e-3 for the offset. First order cancels either way; the error enters through
the second-order dispersion term and is therefore absent on a linear lattice.
The subtraction is not performed here.
- accelmo.momentum_reference.ORBIT_AND_PHASE: tuple[str, ...] = ('x', 'y', 'mu1', 'mu2')¶
the observables that need no amplitude calibration and no model-derived intermediate. See the module docstring.
- Type:
Closed orbit and phase advance
- accelmo.momentum_reference.GRADIENT_SENSITIVE: frozenset[str] = frozenset({'betx', 'bety', 'dx', 'dy', 'mu1', 'mu2'})¶
Observables that carry quadrupole-gradient information. The closed orbit does not: a gradient error on a centred orbit produces no deflection.
- accelmo.momentum_reference.REFERENCE_COLUMNS: tuple[str, ...] = ('x', 'y', 'px', 'py')¶
Columns of the returned closed-orbit reference.
- class accelmo.momentum_reference.MomentumReference(magnet_strengths, uncertainties, closed_orbit, reference_pt, observables, knob_sigmas, momentum_points, bpm_coverage, fit_settings=dict(), diagnostics=dict())[source]¶
Bases:
objectA fitted lattice and the closed-orbit reference it implies.
- Variables:
magnet_strengths (
dict[str,float]) – Fitted knob values, keyed by MAD knob name (BR.BHZ11.dk0l,BR.QFO11.dk1l, …). Apply these to a model of the same sequence to reproduce the fitted machine.closed_orbit (
DataFrame) – Per-BPMx/y/px/pyof the fitted machine’s closed orbit atreference_pt, indexed by BPM name.x/yare a cross-check against the measurement;px/pyare the part that cannot be measured and is the reason this class exists.reference_pt (
float) – MAD-NGptat which the reference was evaluated. This is the momentum origin ofclosed_orbit; momenta handed to a reconstruction against this reference are offsets from it, not absoluteptvalues.observables (
tuple[str,...]) – Observables the fit actually used.knob_sigmas (
dict[str,float]) – Gaussian prior widths used.
- Parameters:
magnet_strengths (dict[str, float])
uncertainties (dict[str, float])
closed_orbit (pd.DataFrame)
reference_pt (float)
observables (tuple[str, ...])
knob_sigmas (dict[str, float])
momentum_points (tuple[float, ...])
bpm_coverage (dict[float, tuple[str, ...]])
fit_settings (dict[str, Any])
diagnostics (dict[str, Any])
- magnet_strengths: dict[str, float]¶
- uncertainties: dict[str, float]¶
- closed_orbit: DataFrame¶
- reference_pt: float¶
- observables: tuple[str, ...]¶
- knob_sigmas: dict[str, float]¶
- momentum_points: tuple[float, ...]¶
- bpm_coverage: dict[float, tuple[str, ...]]¶
- fit_settings: dict[str, Any]¶
- diagnostics: dict[str, Any]¶
- accelmo.momentum_reference.closed_orbit_at(accelerator, magnet_strengths, pt=0.0, *, machine_state=None)[source]¶
Closed orbit and its angles at the BPMs, for a model carrying magnet_strengths.
ptis pinned on the initial condition, so this is the periodic solution at that momentum rather than an on-momentum orbit with a momentum offset added.- Return type:
DataFrame- Parameters:
accelerator (Accelerator)
magnet_strengths (Mapping[str, float] | None)
pt (float)
machine_state (Path | Mapping[str, float] | None)
- accelmo.momentum_reference.fit_momentum_reference(accelerator, measurements, *, observables=ORBIT_AND_PHASE, knob_sigmas, reference_pt=0.0, sequence_config=None, lm_config=None, initial_knob_strengths=None, machine_state=None, output_config=None)[source]¶
Fit magnet errors to measured optics, and return the closed-orbit reference.
- Parameters:
accelerator (
Accelerator) – Configured accelerator. Enable the knob families you intend to fit (bendk0and, if the observables can constrain them, quadrupolek1) via itserrorsselection.measurements (
Mapping[float,DataFrame]) – Measured optics keyed by the known MAD-NGptthe measurement was taken at. At least two momenta are required: at one momentum the per-magnet Jacobians are degenerate.observables (
Sequence[str]) – What to fit. Defaults to closed orbit plus phase advance.knob_sigmas (
Mapping[str,float]) – Gaussian prior widths towards zero magnet error, by knob name or terminal attribute (seeknob_sigma_array()).reference_pt (
float) – MAD-NGptat which to evaluate the returned closed orbit.sequence_config (
SequenceConfig|None) – Sequence range; defaults to the full ring.lm_config (
LevenbergMarquardtConfig|None) – Optimiser settings.initial_knob_strengths (
Mapping[str,float] |None) – Starting point, if resuming a previous fit.
- Return type:
- Returns:
- Raises:
ValueError – If fewer than two momenta are supplied.
- Parameters:
accelerator (Accelerator)
measurements (Mapping[float, pd.DataFrame])
observables (Sequence[str])
knob_sigmas (Mapping[str, float])
reference_pt (float)
sequence_config (SequenceConfig | None)
lm_config (LevenbergMarquardtConfig | None)
initial_knob_strengths (Mapping[str, float] | None)
machine_state (Path | Mapping[str, float] | None)
output_config (OutputConfig | None)