Files
Jungfraujoch/reader/JFJochReaderDataset.h
T
leonarski_fandClaude Opus 5 db908c6ec1 _process.h5: record the change of basis, and the space group
A _process.h5 was internally inconsistent whenever the space group re-seated
the lattice. The per-image reflections and lattices go to file as each image
is processed, but the conventional setting is only chosen afterwards, so the
file kept pre-reindex indices beside a post-reindex cell. Measured on an
affected dataset, max|d_file - d(hkl, stored cell)| was 18.6 A. --mode scale
then compared each frame's lattice against the stored cell, found none of
1800 acceptable, rejected every observation and died in the merge with
"resolution calculation failed".

/entry/MX/reindexMatrix now carries M with hkl_cell = M . hkl_written, and
the reader applies it, so everything it hands out is in the setting of
/entry/sample/unit_cell. Absent means the identity, so a file written before
this reads exactly as before. On the affected dataset M comes out
[[1,1,0],[0,1,1],[1,0,1]], det 2 - the primitive-to-body-centred basis its
volume ratio implied - and the same measure falls from 18.6 A to 1.8e-5.

Writing the reflections in the final setting instead was rejected: the
per-image writer is shared with the broker, which streams and cannot buffer a
run; and h,k,l, predicted_x/y and the per-image lattice are one consistent
statement about one image, which retro-editing the indices would silently
break.

Two things turned up while fixing it. There are three re-seat sites, not one
- the space-group search's own centred-lattice test re-seats too, and logged
nothing - so the matrix composes over all of them. And the space group itself
was never written: it was set only on the arm that searches, while a two-pass
rotation run reuses pass 1's group and takes the other arm, so the canonical
file carried a cell but no group and --mode scale merged in P1.

--mode scale now reproduces --mode mx on the affected dataset: same space
group and cell, 39329 unique reflections both, 100% of reflections common,
CC 0.99985, sum|dI|/sum|I| = 0.0081. The residual is three reflections in
11.09 M crossing an ice-band edge, because mx carries the integrator's d and
scale recomputes it from the cell. An unaffected dataset is byte-identical in
.mtz, .hkl and .cif.

An older affected file still cannot merge - M is not recoverable from it -
but now says so in 51 s, naming both cells and the -S/-C override to use,
instead of failing inside the merge.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CHMmeM1d489zvNFT7ZMN2P
2026-08-25 21:21:55 +02:00

106 lines
4.5 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <string>
#include <array>
#include <optional>
#include <vector>
#include <map>
#include <memory>
#include "../common/DiffractionGeometry.h"
#include "../common/DiffractionExperiment.h"
#include "../common/PixelMask.h"
#include "../common/AzimuthalIntegrationMapping.h"
struct JFJochReaderDataset {
std::string arm_date;
DiffractionExperiment experiment;
// Shared, not copied, across dataset snapshots: the mask is constant for a run, so a per-frame
// dataset refresh / mutable copy must not clone the full-detector (~tens of MB) mask. Held as
// shared_ptr<const>; the rare edit (user mask) builds a fresh mask (copy-on-write). Never null.
std::shared_ptr<const PixelMask> pixel_mask = std::make_shared<const PixelMask>();
std::optional<int64_t> error_value;
// The master file's detect_ice_rings key, kept as written rather than collapsed to a bool, so a
// consumer can tell "the file asked for this" from "the file said nothing". Offline processing
// defaults ice handling by geometry when the file is silent (see rugnux_cli).
std::optional<bool> file_detect_ice_rings;
std::string jfjoch_release;
// Change of basis (3x3 integers, row major) from the setting the per-image reflections and
// lattices in this file were written in to the setting of experiment's unit cell and space group:
// hkl_cell = M . hkl_written. The per-image data are written as each image is processed, but the
// space group - and the conventional setting that comes with it - is only settled after the merge,
// so the two are not always the same setting. Empty means they are. Read straight from
// /entry/MX/reindexMatrix; the reader applies it, so everything this class hands out is already in
// the cell's setting.
std::optional<std::array<int32_t, 9>> reindex_matrix;
std::vector<float> az_int_bin_to_q;
std::vector<float> az_int_bin_to_phi;
size_t azimuthal_bins = 0;
size_t q_bins = 0;
std::vector<float> spot_count;
std::vector<float> spot_count_indexed;
std::vector<float> spot_count_low_res;
std::vector<float> spot_count_ice_rings;
std::vector<float> spot_count_ice_control;
std::vector<float> indexing_result;
std::vector<float> indexing_lattice_count;
std::vector<float> bkg_estimate;
std::vector<float> ice_ring_score;
std::vector<float> resolution_estimate;
std::vector<float> efficiency;
std::vector<float> profile_radius;
std::vector<float> mosaicity_deg;
std::vector<float> b_factor;
std::vector<float> integrated_reflections;
std::vector<float> image_scale_factor;
std::vector<float> image_scale_cc;
std::vector<int64_t> max_value;
// Per-image sweep-quality code from /entry/MX/sweepQuality: 0 = the image is in no flagged range,
// otherwise a 1-based index into sweep_quality_reasons (the vocabulary stored beside it, so the
// codes read back without this source). Both empty when the file carries no sweep quality, which
// means the run never looked - not that every image was clean.
std::vector<uint8_t> sweep_quality;
std::vector<std::string> sweep_quality_reasons;
// Maps this dataset's image index -> the original/collected image number it came from.
// Empty means identity (image i == original image i). Lets a dataset be a subset (or strided
// selection) of the truly collected images: reprocessing snapshots over a sub-range, and (in
// future) a main dataset that was filtered on-the-fly during collection.
std::vector<int> source_image_number;
std::vector<std::string> roi;
std::vector<std::vector<int64_t>> roi_sum;
std::vector<std::vector<int64_t>> roi_sum_sq;
std::vector<std::vector<int64_t>> roi_max;
std::vector<std::vector<int64_t>> roi_npixel;
std::vector<std::vector<float>> roi_x;
std::vector<std::vector<float>> roi_y;
// ROI definitions stored in the master file. The logical definitions populate
// experiment.ROI() (they re-derive with the current geometry); roi_map is the
// per-pixel bitmask as written (constant footprint), with roi_bit_index mapping
// each ROI name to its bit.
std::vector<uint16_t> roi_map;
std::map<std::string, uint16_t> roi_bit_index;
std::vector<std::string> calibration_data;
JFJochReaderDataset() = default;
JFJochReaderDataset(const JFJochReaderDataset &other) = default;
};