diff --git a/image_analysis/bragg_integration/BraggPrediction.cpp b/image_analysis/bragg_integration/BraggPrediction.cpp index e7491c46..7073be7a 100644 --- a/image_analysis/bragg_integration/BraggPrediction.cpp +++ b/image_analysis/bragg_integration/BraggPrediction.cpp @@ -8,6 +8,7 @@ std::multimap CalcBraggPredictions(const DiffractionExperimen float high_res_A, float ewald_dist_cutoff, int max_hkl) { + // Assumption: Scattering vector is (0,0,1) std::multimap reflections; auto geom = experiment.GetDiffractionGeometry(); @@ -17,6 +18,8 @@ std::multimap CalcBraggPredictions(const DiffractionExperimen float one_over_dmax = 1.0f / high_res_A; float one_over_dmax_sq = one_over_dmax * one_over_dmax; + float one_over_wavelength = 1.0f/ geom.GetWavelength_A(); + Coord Astar = lattice.Astar(); Coord Bstar = lattice.Bstar(); Coord Cstar = lattice.Cstar(); @@ -42,23 +45,30 @@ std::multimap CalcBraggPredictions(const DiffractionExperimen float recip_y = AhBk_y + Cstar.y * l; float recip_z = AhBk_z + Cstar.z * l; - float dot = recip_x * recip_x + recip_y * recip_y + recip_z * recip_z; + // Check resolution (actually through 1/d^2) + float dot_xy = recip_y * recip_y + recip_z * recip_z; + float dot = dot_xy + recip_x * recip_x; if (dot > one_over_dmax_sq) continue; - float d = 1.0f / sqrtf(dot); - Coord recip(recip_x, recip_y, recip_z); + // Get Distance from Ewald sphere, to check if reflection is in diffracting condition + float S_z = recip_z + one_over_wavelength; + float S_len = sqrtf(dot_xy + S_z * S_z); - float dist_ewald_sphere = std::fabs(geom.DistFromEwaldSphere(recip)); + float dist_ewald_sphere = std::fabs(S_len - one_over_wavelength); if (!std::isfinite(dist_ewald_sphere) || dist_ewald_sphere > ewald_dist_cutoff ) continue; + Coord recip(recip_x, recip_y, recip_z); + auto [x,y] = geom.RecipToDector(recip); if ((x < 0) || (x >= det_width_pxl) || (y < 0) || (y >= det_height_pxl)) continue; + float d = 1.0f / sqrtf(dot); + reflections.insert(std::make_pair(dist_ewald_sphere, Reflection{ .h = h, .k = k,