// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include "BraggPrediction.h" std::multimap CalcBraggPredictions(const DiffractionExperiment& experiment, const CrystalLattice& lattice, float high_res_A, float ewald_dist_cutoff, int max_hkl) { std::multimap reflections; auto geom = experiment.GetDiffractionGeometry(); auto det_width_pxl = static_cast(experiment.GetXPixelsNum()); auto det_height_pxl = static_cast(experiment.GetYPixelsNum()); float one_over_dmax = 1.0f / high_res_A; float one_over_dmax_sq = one_over_dmax * one_over_dmax; Coord Astar = lattice.Astar(); Coord Bstar = lattice.Bstar(); Coord Cstar = lattice.Cstar(); for (int h = -max_hkl; h < max_hkl; h++) { for (int k = -max_hkl; k < max_hkl; k++) { for (int l = -max_hkl; l < max_hkl; l++) { // (000) is not too interesting if (h == 0 && k == 0 && l == 0) continue; Coord recip = Astar * static_cast(h) + Bstar * static_cast(k) + Cstar * static_cast(l); if (recip * recip > one_over_dmax_sq) continue; float d = 1.0f / recip.Length(); float dist_ewald_sphere = std::fabs(geom.DistFromEwaldSphere(recip)); if (!std::isfinite(dist_ewald_sphere) || dist_ewald_sphere > ewald_dist_cutoff ) continue; auto [x,y] = geom.RecipToDector(recip); if ((x < 0) || (x >= det_width_pxl) || (y < 0) || (y >= det_height_pxl)) continue; reflections.insert(std::make_pair(dist_ewald_sphere, Reflection{ .h = h, .k = k, .l = l, .predicted_x = x, .predicted_y = y, .d = d })); } } } return reflections; }