Files
Jungfraujoch/image_analysis/bragg_prediction/RotationColumnRange.h
T
leonarski_f 8261b7354e
Build Packages / Create release (push) Successful in 9s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m8s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 11m12s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 16m43s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 20m56s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 22m4s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 26m57s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 28m24s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 27m58s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 29m29s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 18m23s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 19m55s
Build Packages / Generate python client (push) Successful in 32s
Build Packages / Build documentation (push) Successful in 1m32s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 27m20s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 29m27s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 32m41s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 34m46s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 37m25s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 35m56s
Build Packages / Unit tests (push) Successful in 2h8m44s
Build Packages / Validation Battery (push) Successful in 33m35s
v1.0.0-rc.176 (#86)
* jfjoch_broker: Optional live Rugnux analysis of DECTRIS rotation collections inside the broker, with merged data, maps and the placed model written beside the master file, the rotation lattice in the scan result, and a "Rugnux live" tab and dashboard row in the web frontend.
* Rugnux: Faster processing, with molecular replacement and model validation spread over several GPUs and run on the Apple GPU on macOS.
* Rugnux: The polarization stated in miniCBF and d*TREK headers is used, twinned crystals' space groups are decided more reliably, and a run that finds no lattice still reports every image.

Reviewed-on: #86
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-10-19 07:03:28 +02:00

72 lines
3.4 KiB
C

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
// Which l of an (h, k) column a rotation predictor needs to walk, shared by the CPU and the GPU predictor
// (BraggPredictionRot.cpp explains the bound) so that both walk the same l.
#include <cmath>
#include "../../common/JFJochMath.h"
#ifdef __CUDACC__
#define ROTATION_COLUMN_HD __host__ __device__ inline
#else
#define ROTATION_COLUMN_HD inline
#endif
// The largest |phi| at which a solution can still pass the rocking-curve test: a solution further from
// the frame has zeta (|phi| - half wedge) above the test's limit for every zeta >= min_zeta, the rocking
// width being largest at the resolution limit. With a 1e-3 rad margin, far above float rounding.
// -1 = nothing is bounded (no min_zeta, or a bound past pi).
ROTATION_COLUMN_HD double RotationPhiLimit(float min_zeta, float mos_angle_rad, float bandwidth_sigma,
float half_wavelength_A, float one_over_dmax,
float half_wedge_angle_rad, float mosaicity_multiplier) {
if (!(min_zeta > 0.0f))
return -1.0;
double mos_max_rad = mos_angle_rad;
if (bandwidth_sigma > 0.0f) {
const double sin_theta = half_wavelength_A * static_cast<double>(one_over_dmax);
const double dphi_bw = sin_theta < 1.0
? bandwidth_sigma * sin_theta / sqrt(1.0 - sin_theta * sin_theta)
: INFINITY;
mos_max_rad = sqrt(mos_max_rad * mos_max_rad + dphi_bw * dphi_bw);
}
const double phi_limit = half_wedge_angle_rad + (mosaicity_multiplier * mos_max_rad + 1e-5) / min_zeta + 1e-3;
return phi_limit < PI ? phi_limit : -1.0;
}
// The l of a column to walk: f(l) = C_C l^2 + b l + c <= f_max on [l_lo, l_hi], and f(l) < -f_max strictly
// inside (skip_lo, skip_hi), which may be empty. False where no l of the column can pass. inv_2C_C is
// 1 / (2 C_C): a product rather than four divisions, which on a GPU are each a sequence of double
// operations; the whole-index widening of each end covers the difference in rounding.
struct RotationColumn {
int l_lo, l_hi, skip_lo, skip_hi;
};
ROTATION_COLUMN_HD bool RotationColumnRange(double C_C, double inv_2C_C, double b, double c, double f_max,
int max_l, RotationColumn &col) {
// A root of the quadratic as an index, held inside the box first so the conversion cannot overflow.
const auto to_l = [max_l](double v) {
const double lo = -max_l - 2.0, hi = max_l + 2.0;
return static_cast<int>(v < lo ? lo : (v > hi ? hi : v));
};
col = {-max_l, max_l, max_l + 1, max_l + 1};
const double disc_hi = b * b - 4.0 * C_C * (c - f_max);
if (!(disc_hi >= 0.0))
return false;
const double r_hi = sqrt(disc_hi);
const int lo = to_l(ceil((-b - r_hi) * inv_2C_C)) - 1;
const int hi = to_l(floor((-b + r_hi) * inv_2C_C)) + 1;
col.l_lo = lo > col.l_lo ? lo : col.l_lo;
col.l_hi = hi < col.l_hi ? hi : col.l_hi;
const double disc_lo = b * b - 4.0 * C_C * (c + f_max);
if (disc_lo > 0.0) {
const double r_lo = sqrt(disc_lo);
col.skip_lo = to_l(floor((-b - r_lo) * inv_2C_C)) + 2;
col.skip_hi = to_l(ceil((-b + r_lo) * inv_2C_C)) - 2;
}
return true;
}