Build Packages / Create release (push) Successful in 8s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m11s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 10m32s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 18m26s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 22m11s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 23m32s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 25m36s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 27m28s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 28m10s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 28m10s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 29m24s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 21m45s
Build Packages / Generate python client (push) Successful in 31s
Build Packages / Build documentation (push) Successful in 1m21s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 24m2s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 29m25s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 30m27s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 27m12s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 32m20s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 33m36s
Build Packages / Unit tests (push) Successful in 2h7m18s
Build Packages / Validation Battery (push) Successful in 33m19s
* Rugnux: Stills processing needs only the unit cell and space group beyond what the file records - detector distance, beam centre, tilt, panel placement, saturation level, gain and polarisation plane are found from the images - and is up to twice as fast. * Rugnux: Stills can be indexed without a GPU, with a CPU implementation of the fast-feedback indexer (macOS, computers without a GPU). * Rugnux: Rotation and stills data are integrated in the detector's own units with one gain model, improving data from CCD detectors. * Web frontend: The Rugnux live page shows the placed model with its electron density and anomalous difference map in a Mol* viewer. Reviewed-on: #90 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
115 lines
4.4 KiB
C++
115 lines
4.4 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "DiffractionSpot.h"
|
|
#include "DiffractionGeometry.h"
|
|
#include "RawToConvertedGeometry.h"
|
|
|
|
DiffractionSpot::DiffractionSpot(uint32_t col, uint32_t line, int64_t in_photons) {
|
|
if (in_photons < 0) in_photons = 0;
|
|
x = static_cast<int64_t>(col) * in_photons;
|
|
y = static_cast<int64_t>(line) * in_photons;
|
|
pixel_count = 1;
|
|
photons = in_photons;
|
|
max_photons = in_photons;
|
|
}
|
|
|
|
DiffractionSpot& DiffractionSpot::operator+=(const DiffractionSpot &other) {
|
|
this->x += other.x;
|
|
this->y += other.y;
|
|
this->photons += other.photons;
|
|
this->max_photons = std::max(this->max_photons, other.max_photons);
|
|
this->pixel_count += other.pixel_count;
|
|
return *this;
|
|
}
|
|
|
|
DiffractionSpot::DiffractionSpot(int64_t x_sum, int64_t y_sum, int64_t in_pixel_count,
|
|
int64_t in_photons, int64_t in_max_photons, int64_t in_panel)
|
|
: x(x_sum), y(y_sum), pixel_count(in_pixel_count), photons(in_photons), max_photons(in_max_photons),
|
|
panel(in_panel) {}
|
|
|
|
int64_t DiffractionSpot::Count() const {
|
|
return photons;
|
|
}
|
|
|
|
int64_t DiffractionSpot::MaxCount() const {
|
|
return max_photons;
|
|
}
|
|
|
|
Coord DiffractionSpot::RawCoord() const {
|
|
if (photons == 0)
|
|
return {0, 0, 0};
|
|
// In double: the sums run past what a float mantissa holds on a bright spot, and the centroid is
|
|
// wanted to better than the last pixel bit.
|
|
return {static_cast<float>(static_cast<double>(x) / static_cast<double>(photons)),
|
|
static_cast<float>(static_cast<double>(y) / static_cast<double>(photons)), 0};
|
|
}
|
|
|
|
int64_t DiffractionSpot::Panel() const {
|
|
return panel;
|
|
}
|
|
|
|
void DiffractionSpot::Panel(int64_t in_panel) {
|
|
panel = in_panel;
|
|
}
|
|
|
|
int64_t DiffractionSpot::PixelCount() const {
|
|
return pixel_count;
|
|
}
|
|
|
|
void DiffractionSpot::AddPixel(uint32_t col, uint32_t line, int64_t photons) {
|
|
this->x += static_cast<int64_t>(col) * photons;
|
|
this->y += static_cast<int64_t>(line) * photons;
|
|
this->photons += photons;
|
|
this->max_photons = std::max(this->max_photons, photons);
|
|
this->pixel_count += 1;
|
|
}
|
|
|
|
void DiffractionSpot::ConvertToImageCoordinates(const DiffractionExperiment &experiment, uint16_t module_number) {
|
|
// The raw -> image map is a signed axis swap (module axes are +/-1 along X or Y, never rotated -
|
|
// see DetectorGeometryModular::GetDirection) plus an integer translation: the module's origin in
|
|
// the assembled image, and the two-pixel multipixel gaps, which depend on where the centroid
|
|
// falls. Applied to the SUMS rather than to the centroid, it therefore leaves them exact
|
|
// integers; converting the centroid and multiplying it back by the photon count would put the
|
|
// rounding this class avoids straight back in.
|
|
const Coord centroid = RawCoord();
|
|
const Coord fast = experiment.GetModuleFastDirection(module_number);
|
|
const Coord slow = experiment.GetModuleSlowDirection(module_number);
|
|
// Everything the map adds on top of the axis swap - origin plus gap corrections, an integer.
|
|
const Coord shift = RawToConvertedCoordinate(experiment, module_number, centroid)
|
|
- fast * centroid.x - slow * centroid.y;
|
|
|
|
const int64_t x_raw = x, y_raw = y;
|
|
x = std::lround(shift.x) * photons + std::lround(fast.x) * x_raw + std::lround(slow.x) * y_raw;
|
|
y = std::lround(shift.y) * photons + std::lround(fast.y) * x_raw + std::lround(slow.y) * y_raw;
|
|
}
|
|
|
|
std::optional<SpotToSave> DiffractionSpot::Export(const DiffractionGeometry &geometry, int64_t image_num) const {
|
|
if (photons == 0)
|
|
return std::nullopt;
|
|
|
|
const Coord centroid = RawCoord();
|
|
auto d = geometry.PxlToRes(centroid.x, centroid.y);
|
|
|
|
float phi = 0.0f;
|
|
if (geometry.GetRotation()) {
|
|
// Rotation angle is considered as increment + half wedge.
|
|
// It ignores the starting angle.
|
|
phi = geometry.GetRotation()->GetAngle_deg(image_num) + geometry.GetRotation()->GetWedge_deg() / 2.0f;
|
|
}
|
|
|
|
return SpotToSave{
|
|
.x = centroid.x,
|
|
.y = centroid.y,
|
|
.phi = phi,
|
|
.intensity = static_cast<float>(photons),
|
|
.maxc = max_photons,
|
|
.lattice = -1,
|
|
.image = image_num,
|
|
.d_A = d,
|
|
.ice_ring = false,
|
|
.indexed = false,
|
|
.panel = static_cast<int16_t>(panel)
|
|
};
|
|
}
|