The per-image geometry refinement is the largest stage of the image loop, and a third of it was arithmetic on numbers that never change. The residual derives the detector angles' sines and cosines, the goniometer's back-rotation - a three-argument hypot, a sine, a cosine and a division - and the reciprocal basis of the cell on every evaluation. On the rotation path the detector angles and the axis are held fixed and stored as plain doubles, so all of it is constant, not merely constant per block: there is one frame per image and one cell. Three solves an image, fifty iterations a solve and a thousand spots make it tens of thousands of repetitions of the same result. The frame's constants are now built once and handed in. The body they feed is the same body, split out rather than copied, so no expression is reassociated - in particular the reciprocal vector is still formed as the basis times the inverse volume, with the volume not folded into the basis. The spot confidence weights depend only on each spot's resolution and intensity, which no solver touches, and were recomputed identically for each of the three passes. They are computed once. The sort behind them ordered indices through a projection that chased a random eighty-byte-strided element per comparison; it now sorts a packed resolution and index, which makes the same comparisons in the same sequence and therefore the same permutation. The spot list itself was copied per image through an initializer list whose elements are const; it is passed as a view. The integration engine was the last one in the loop copying through pageable host memory - three transfers in and eight out per image, twenty-six bytes a reflection, while every other engine already page-locks its staging. A driver copy from pageable memory stages through its own pinned buffer on the calling thread, which is why an asynchronous copy was averaging a hundred and thirteen microseconds. Page-locked, the same seventeen thousand calls cost four hundred and thirty-two milliseconds instead of one and a half seconds, and the wait moves to the synchronisation point where it belongs. Two smaller ones: the reflections were copied into the per-image message for a process file that a merging run does not write, so the copy is made where a writer exists; and the intensity statistics and the Wilson estimate walked the same eighty-byte array twice to read twelve bytes, which is now one pass with each accumulation in its own order. Every reflection file is byte-identical on four crystals; the process file's reflections match dataset for dataset, and its azimuthal arrays differ no more between this build and the last than the last differs from itself. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EGpGdgmJ8MyY9pCGWjktyi
32 lines
1.6 KiB
C++
32 lines
1.6 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <limits>
|
|
#include <vector>
|
|
|
|
#include "../../common/JFJochMessages.h"
|
|
#include "../../common/Reflection.h"
|
|
|
|
void CalcISigma(DataMessage &msg);
|
|
void CalcWilsonBFactor(DataMessage &msg, bool replace_b = true);
|
|
|
|
void CalcISigma(DataMessage &msg, const std::vector<Reflection> &reflections);
|
|
void CalcWilsonBFactor(DataMessage &msg, const std::vector<Reflection> &reflections, bool replace_b = true);
|
|
// The two above in one pass over the reflections, for the per-image path that wants both.
|
|
void CalcISigmaAndWilsonBFactor(DataMessage &msg, const std::vector<Reflection> &reflections,
|
|
bool replace_b = true);
|
|
|
|
// Dataset-wide isotropic Wilson B-factor estimate from a log-linear fit of the shell-averaged merged
|
|
// intensity against 1/d^2 (B = -2*slope). Robust because it averages over the whole dataset - the
|
|
// per-image CalcWilsonBFactor above is a per-frame estimate and much noisier. Diagnostic only (like
|
|
// XDS's "WILSON LINE ... B="), not used in scaling. Returns b = NaN when it cannot be determined.
|
|
struct GlobalWilsonB {
|
|
double b = std::numeric_limits<double>::quiet_NaN(); // Wilson B-factor estimate (A^2)
|
|
double correlation = std::numeric_limits<double>::quiet_NaN(); // |correlation| of the log-linear fit
|
|
int n_shells = 0; // resolution shells actually used
|
|
};
|
|
GlobalWilsonB CalcGlobalWilsonB(const std::vector<MergedReflection> &merged);
|
|
|