Build Packages / Create release (push) Successful in 17s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 4m41s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 20m49s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 13m6s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 23m44s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 7m28s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 11m50s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 14m9s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 16m25s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 15m42s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 20m50s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 20m36s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 22m18s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 23m29s
Build Packages / Generate python client (push) Successful in 30s
Build Packages / Build documentation (push) Successful in 1m10s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 21m38s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 17m8s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 23m10s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 19m16s
Build Packages / Unit tests (push) Successful in 2h8m4s
Build Packages / Validation Battery (push) Successful in 40m53s
* Rugnux: Processes serial crystallography data from XFELs - SACLA (MPCCD), PAL-XFEL and European XFEL (CXI), LCLS (XTC) and SwissFEL Alvra (JUNGFRAU with a CrystFEL module geometry) - with several files or Jungfraujoch master files merged in one run (`rugnux *_master.h5`). * Rugnux: Stills processing takes a known unit cell and space group as a starting point, finds the beam centre (and, with a cell, the detector distance) from the images, detects the saturation level in other facilities' files and refines the placement of individual detector panels. * Rugnux: The stills report gives R_split and CC1/2 from frame half-sets, comparable with CrystFEL. * jfjoch_viewer: Opens the same XFEL file formats. * Validation: A stills battery checks Rugnux against deposited structures from SACLA, PAL-XFEL, LCLS, European XFEL and SwissFEL. * Rugnux: More reliable convergence of rotation scaling, and live molecular replacement starts as soon as the model is uploaded. * jfjoch_broker: Initialize clears the previous dataset's bearer tokens, image buffer and live Rugnux status, and a slow CUDA JIT cache is reported at start. Reviewed-on: #88 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
71 lines
3.9 KiB
C++
71 lines
3.9 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "NXmxModules.h"
|
|
|
|
#include <cmath>
|
|
|
|
namespace {
|
|
|
|
// Internal frame (x = column, y = row downward, z = beam) -> McStas, a half turn about z.
|
|
std::vector<double> ToMcStas(const Coord &v) {
|
|
return {0.0 - v.x, 0.0 - v.y, 0.0 + v.z};
|
|
}
|
|
|
|
// A translation of `length` metres along v (pixels, internal frame), as NXmx writes one: the length as
|
|
// the value, the direction as a unit vector - and a zero translation with a unit vector all the same.
|
|
void SaveTranslation(HDF5Group &group, const std::string &name, const RotMatrix &delta, double dx_px, double dy_px,
|
|
double pixel_size_m, const std::string &depends_on) {
|
|
const double len_px = std::hypot(dx_px, dy_px);
|
|
const Coord dir = len_px > 0 ? Coord(static_cast<float>(dx_px / len_px), static_cast<float>(dy_px / len_px), 0)
|
|
: Coord(0, 0, 1);
|
|
SaveScalar(group, name, len_px * pixel_size_m)->
|
|
Transformation("m", depends_on, "", "", "translation", ToMcStas(delta * dir), {0, 0, 0}, "");
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void WriteNXmxModules(HDF5Object &file, const DetectorModules &modules, double pixel_size_m,
|
|
const DetectorOrientation &orientation, const std::string &depends_on) {
|
|
const RotMatrix delta = orientation.Matrix();
|
|
for (size_t n = 0; n < modules.size(); n++) {
|
|
const DetectorModule &m = modules[n];
|
|
const std::string path = "/entry/instrument/detector/module_" + std::to_string(n);
|
|
HDF5Group group(file, path);
|
|
group.NXClass("NXdetector_module");
|
|
group.SaveVector("data_origin", std::vector<int32_t>{static_cast<int32_t>(m.y0), static_cast<int32_t>(m.x0)});
|
|
group.SaveVector("data_size", std::vector<int32_t>{static_cast<int32_t>(m.height),
|
|
static_cast<int32_t>(m.width)});
|
|
SaveTranslation(group, "module_offset", delta, m.ox, m.oy, pixel_size_m, depends_on);
|
|
SaveTranslation(group, "fast_pixel_direction", delta, m.fx, m.fy, pixel_size_m, path + "/module_offset");
|
|
SaveTranslation(group, "slow_pixel_direction", delta, m.sx, m.sy, pixel_size_m, path + "/module_offset");
|
|
}
|
|
}
|
|
|
|
void WriteModuleGeometryFile(const std::string &path, const DetectorModules &modules,
|
|
const DiffractionGeometry &geom) {
|
|
HDF5File file(path);
|
|
HDF5Group(file, "/entry").NXClass("NXentry");
|
|
HDF5Group(file, "/entry/instrument").NXClass("NXinstrument");
|
|
HDF5Group(file, "/entry/instrument/detector").NXClass("NXdetector");
|
|
HDF5Group transformations(file, "/entry/instrument/detector/transformations");
|
|
transformations.NXClass("NXtransformations");
|
|
|
|
// Sample -> image pixel (0, 0), square to the beam: what the modules' offsets are measured from. The
|
|
// tilt, if any, is the master file's to state; this file carries the modules only.
|
|
const double pixel_m = geom.GetPixelSize_mm() / 1000.0;
|
|
const RotMatrix delta = geom.GetOrientation().Matrix();
|
|
const auto v = ToMcStas(delta * Coord(-geom.GetBeamX_pxl() * static_cast<float>(pixel_m),
|
|
-geom.GetBeamY_pxl() * static_cast<float>(pixel_m),
|
|
geom.GetDetectorDistance_mm() / 1000.0f));
|
|
const double len = std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
|
SaveScalar(transformations, "translation", len)->
|
|
Transformation("m", ".", "detector", "detector_arm", "translation",
|
|
std::vector<double>{v[0] / len, v[1] / len, v[2] / len});
|
|
SaveScalar(file, "/entry/instrument/detector/depends_on",
|
|
std::string("/entry/instrument/detector/transformations/translation"));
|
|
|
|
WriteNXmxModules(file, modules, pixel_m, geom.GetOrientation(),
|
|
"/entry/instrument/detector/transformations/translation");
|
|
}
|