From 170f13636c10418b5948f4cbfd93d37d7a3ee7b0 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Tue, 16 Dec 2025 13:23:20 +0100 Subject: [PATCH] BraggPrediction: Add SystematicAbsence header --- .../bragg_integration/BraggPrediction.cpp | 52 +------------------ .../bragg_integration/CMakeLists.txt | 1 + .../bragg_integration/SystematicAbsence.h | 26 ++++++++++ 3 files changed, 29 insertions(+), 50 deletions(-) create mode 100644 image_analysis/bragg_integration/SystematicAbsence.h diff --git a/image_analysis/bragg_integration/BraggPrediction.cpp b/image_analysis/bragg_integration/BraggPrediction.cpp index 498f78bb..3f8ec9ad 100644 --- a/image_analysis/bragg_integration/BraggPrediction.cpp +++ b/image_analysis/bragg_integration/BraggPrediction.cpp @@ -2,10 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include "BraggPrediction.h" - -inline bool odd(const int val) { - return (val & 1) != 0; -} +#include "SystematicAbsence.h" BraggPrediction::BraggPrediction(int max_reflections) : max_reflections(max_reflections), reflections(max_reflections) {} @@ -55,52 +52,7 @@ int BraggPrediction::Calc(const DiffractionExperiment &experiment, const Crystal const float AhBk_z = Ah_z + Bstar.z * k; for (int l = -settings.max_hkl; l < settings.max_hkl; l++) { - bool absent = false; - // (000) is not too interesting - if (h == 0 && k == 0 && l == 0) - absent = true; - - switch (settings.centering) { - case 'I': - // Body-centered: h + k + l must be even - if (odd(h + k + l)) - absent = true; - break; - case 'A': - // A-centered: k + l must be even - if (odd(k + l)) - absent = true; - break; - case 'B': - // B-centered: h + l must be even - if (odd(h + l)) - absent = true; - break; - case 'C': - // C-centered: h + k must be even - if (odd(h + k)) - absent = true; - break; - case 'F': { // Face-centered: h, k, l all even or all odd - if (odd(h+k) || odd(h+l) || odd(k+l)) - absent = true; - break; - } - case 'R': { - // Rhombohedral in hexagonal setting (hR, a_h=b_h, γ=120°): - // Reflection condition: -h + k + l = 3n (equivalently h - k + l = 3n) - int mod = (-h + k + l) % 3; - if (mod < 0) mod += 3; - if (mod != 0) - absent = true; - break; - } - default: - // P or unspecified: no systematic absences - break; - } - - if (absent) + if (systematic_absence(h, k, l, settings.centering)) continue; if (i >= max_reflections) diff --git a/image_analysis/bragg_integration/CMakeLists.txt b/image_analysis/bragg_integration/CMakeLists.txt index 95b9e4f4..3ff89fb2 100644 --- a/image_analysis/bragg_integration/CMakeLists.txt +++ b/image_analysis/bragg_integration/CMakeLists.txt @@ -8,6 +8,7 @@ ADD_LIBRARY(JFJochBraggIntegration STATIC CalcISigma.h BraggPredictionFactory.cpp BraggPredictionFactory.h + SystematicAbsence.h ) TARGET_LINK_LIBRARIES(JFJochBraggIntegration JFJochCommon) diff --git a/image_analysis/bragg_integration/SystematicAbsence.h b/image_analysis/bragg_integration/SystematicAbsence.h new file mode 100644 index 00000000..ea27ae32 --- /dev/null +++ b/image_analysis/bragg_integration/SystematicAbsence.h @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute +// SPDX-License-Identifier: GPL-3.0-only + +#ifndef JFJOCH_SYSTEMATICABSENCE_H +#define JFJOCH_SYSTEMATICABSENCE_H + +static inline bool odd_int(int v) { return (v & 1) != 0; } + +static inline bool systematic_absence(int h, int k, int l, char centering) { + if (h == 0 && k == 0 && l == 0) return true; + switch (centering) { + case 'I': return odd_int(h + k + l); + case 'A': return odd_int(k + l); + case 'B': return odd_int(h + l); + case 'C': return odd_int(h + k); + case 'F': return (odd_int(h + k) || odd_int(h + l) || odd_int(k + l)); + case 'R': { + int mod = (-h + k + l) % 3; + if (mod < 0) mod += 3; + return mod != 0; + } + default: return false; // P + } +} + +#endif //JFJOCH_SYSTEMATICABSENCE_H \ No newline at end of file