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:

  1. 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.

  2. 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.

  3. 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: object

A 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-BPM x/y/px/py of the fitted machine’s closed orbit at reference_pt, indexed by BPM name. x/y are a cross-check against the measurement; px/py are the part that cannot be measured and is the reason this class exists.

  • reference_pt (float) – MAD-NG pt at which the reference was evaluated. This is the momentum origin of closed_orbit; momenta handed to a reconstruction against this reference are offsets from it, not absolute pt values.

  • 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.

pt is 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 (bend k0 and, if the observables can constrain them, quadrupole k1) via its errors selection.

  • measurements (Mapping[float, DataFrame]) – Measured optics keyed by the known MAD-NG pt the 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 (see knob_sigma_array()).

  • reference_pt (float) – MAD-NG pt at 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:

MomentumReference

Returns:

A MomentumReference.

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)