Files
Jungfraujoch/image_analysis/geom_refinement/BeamCenterFromSpots.h
T
leonarski_f 538f3504d3
Build Packages / build:windows:nocuda (push) Successful in 20m4s
Build Packages / Unit tests (push) Skipped
Build Packages / build:viewer-tgz:cpu (push) Successful in 16m5s
Build Packages / build:viewer-tgz:cuda (push) Successful in 17m26s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 27m46s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 20m17s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 26m13s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 23m17s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 28m11s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 19m30s
Build Packages / build:rpm (rocky8) (push) Successful in 24m34s
Build Packages / build:rpm (rocky9) (push) Successful in 21m30s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 23m33s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 20m18s
Build Packages / DIALS test (push) Successful in 18m23s
Build Packages / XDS test (durin plugin) (push) Successful in 11m30s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 10m16s
Build Packages / XDS test (neggia plugin) (push) Successful in 8m2s
Build Packages / Generate python client (push) Successful in 49s
Build Packages / Build documentation (push) Successful in 1m21s
Build Packages / Create release (push) Skipped
Build Packages / build:windows:cuda (push) Successful in 29m45s
v1.0.0.rc-161 (#71)
This is an UNSTABLE release. It includes many experimental features, as well as many AI generated fixes. We recommend using rc.152 for production use.

* **rugnux: significantly better quality of results, and faster.** A large rework of integration, scaling, merging, geometry refinement and space-group determination, together with measurements the program previously made no attempt at - the direct beam before indexing, the beam stop, the goniometer rotation scale, and the stretches of a sweep the crystal did not deliver. A rotation dataset typically gains observations at better <I/sigma> and R_meas, and every `mx` and `scale` run writes a `<prefix>_report.txt` results report modelled on XDS's `CORRECT.LP`. Many defaults moved with it: spot detection is self-calibrating, beam-stop detection and rotation geometry post-refinement are on, resolution limits default to as far as the detector reaches, and ice-ring handling engages only where the crystal is measured to have ice.
* **jfjoch_viewer:** the beam-stop shadow, the detector calibration and the beam-centre measurement are reachable from "Analyze dataset"; the settings panel reports how the sample moved and how polarized the beam was; image rendering and interaction are faster.
* **Performance:** bitshuffle+LZ4 images are decoded on the GPU rather than on the host, with the bitshuffle inverse fused into preprocessing so the decompressed frame is never held in device memory.
* **Broker, writer, packaging and build:** image-slot lifetime and locking fixes, per-image datasets sized by the images actually written, the Debian/Ubuntu broker package renamed to `jfjoch`, and `image_analysis` compiling under MSVC again.

**Breaking change to the rugnux command line:**
* `--azint-only` and `--scale` are **removed**, replaced by `--mode azint` and `--mode scale`; the full pipeline is `--mode mx` and remains the default. A script passing the old flags now fails with the list of valid modes rather than silently running the wrong one.
* `-t`/`--stride` is **refused on rotation data**: skipping frames cuts every reflection's rocking curve, so the combined fulls and their partiality would be measured over frames the sweep never recorded. Select a contiguous range with `-s`/`-e` instead. `--mode azint` and `--force-still` still take a stride.

**Breaking changes to OpenAPI** - regenerate the client (`jfjoch-client` 1.0.0-rc.161, `frontend/src/client`) or read the affected fields as optional:
* `image_scale_b` is removed from the `plot_type` enum, so a client requesting that plot now gets an error rather than a curve.
* `azim_int_settings.high_q_recipA`, `spot_finding_settings.high_resolution_limit` and `spot_finding_settings.low_resolution_limit` are no longer `required`. All three mean "no limit at that end" when unset and are omitted from the response instead of carrying a placeholder value, which raises in a client generated from an rc.160-or-earlier spec. A value of 0 is still accepted and means the same thing.

**Breaking changes to the stored formats** - a consumer reading these fields must treat them as optional:
* The per-image image-scale B factor is no longer computed, so `/entry/MX/imageScaleBFactor` is absent from newly written HDF5 files and the corresponding key is absent from the CBOR DataMessage and END blocks. Files written by rc.160 and earlier still contain it and still open; nothing in the pipeline reads it any more.
* `_reflns.jfjoch_diffrn_ISa` now carries the whole-range `1/sqrt(a*b)` that XDS's ISa denotes, and the error-model `a` and `b` are reported in XDS's convention; the strong-reflection asymptote moves to `_reflns.jfjoch_diffrn_ISa_asymptotic`. **A file written by an earlier version carries the asymptote under the plain `ISa` name.**

Reviewed-on: #71
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-08-13 17:03:10 +02:00

78 lines
4.5 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <cmath>
#include <optional>
#include <vector>
#include "BeamCenterFromBackground.h"
#include "../../common/DiffractionExperiment.h"
// One spot of the pre-scan sample: its position in image pixels, its photon count, and which of the
// sampled frames it came from (an index into the angles the estimator is given).
struct BeamCenterSpot {
float x = 0.0f;
float y = 0.0f;
float intensity = 0.0f;
int frame = 0;
};
// Where the spindle really points. The goniometer axis in the file is a nominal - every master of
// the regression set writes it as exactly a lab axis, and no beamline can hold one there - so the
// two angles the beam-centre estimator cannot do without are measured from the spots instead.
//
// AZIMUTH: the spindle turned about the beam. Both mirror lines turn with it, and a mirror taken
// about the nominal one instead leaves a residual of twice the azimuth times the other detector
// coordinate - which does not bias the vote but spreads it until the wrong tooth wins.
//
// TIP: the spindle tipped out of the plane perpendicular to the beam, i.e. the part that makes it
// not perpendicular at all. The Friedel mate is then no longer in diffracting condition at exactly
// phi+180, and the compensating rotation leaves a purely radial residual along the mirrored
// coordinate. The crossing axis does not see it; only the Friedel one does.
//
// Both are angles of the spindle, not of the detector, and neither is ever written to the geometry.
struct SpindleEstimate {
float azimuth_rad = NAN; // fitted rotation of the spindle about the beam
float tip_rad = NAN; // fitted rotation of the spindle towards the beam
float vote_excess = NAN; // the Friedel vote's tallest tooth there
float vote_excess_nominal = NAN; // and at the nominal spindle, for comparison
};
// Beam centre from the symmetry of a rotation sweep's spot positions, before anything is indexed.
// Nothing here uses the background, a ring, a unit cell or an orientation matrix - only where the
// spots are, and two facts that hold exactly for any crystal on a single-axis goniometer.
//
// Friedel. Rotating the crystal 180 deg about the spindle m and taking -h negates the scattering
// vector's component ALONG m and leaves the rest untouched, so the spots on the frame at phi+180 are
// the exact mirror image, in that lab component, of the spots on the frame at phi. Mirroring one
// frame's spots onto its partner's therefore measures the beam coordinate along m.
//
// Second crossing. Along the sweep |q| and q.m are both constant and the Ewald condition fixes the
// component along the beam, so the remaining one can only change sign: every reflection is recorded
// twice, at positions mirrored in the coordinate PERPENDICULAR to m. That gives the other coordinate.
//
// The estimate is of the physical direct beam; it is returned in the PONI parametrisation the rest of
// the geometry uses, so the caller can put it straight into DiffractionExperiment.
//
// `sigma_pxl` is what the caller gates on, and it is the larger of two things: the scatter of what
// the individual frame pairs said, and how far the answer moves when the search is started
// elsewhere. The second is what matters. The vote sees only +-30 px about wherever it starts, so a
// header far enough out leaves the true peak outside the window and a false one wins it with a
// perfectly small scatter - a precision, not an accuracy. Only a start somewhere else finds that.
//
// The sweep has to reach 180 deg for the first and about a full turn for the second, which is why
// this cannot serve stills, screening wedges or short sweeps - the background estimator does, on
// three frames. `frame_angle_deg` is the rotation angle of each sampled frame, and the estimator
// pairs them itself; `spots` is the pooled spot list of those frames.
//
// std::nullopt when the sweep, or the diffraction on it, does not support the measurement.
// A non-null `spindle` is what asks for the spindle to be fitted and applied; with a null pointer
// this is exactly the estimator that was here before.
std::optional<BeamCenterEstimate>
FindBeamCenterFromSpotSymmetry(const DiffractionExperiment &experiment,
const std::vector<float> &frame_angle_deg,
const std::vector<BeamCenterSpot> &spots,
SpindleEstimate *spindle = nullptr);