From ca1555696484215daceb93f93e53ead6d4cef269 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Mon, 19 Jun 2023 20:06:11 +0200 Subject: [PATCH] DiffractionGeometry: Add DistFromEwaldSphere function --- common/DiffractionGeometry.h | 5 +++++ tests/DiffractionGeometryTest.cpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/common/DiffractionGeometry.h b/common/DiffractionGeometry.h index 9ee0ee29..7f341448 100644 --- a/common/DiffractionGeometry.h +++ b/common/DiffractionGeometry.h @@ -51,6 +51,11 @@ inline float ResToPxl(const DiffractionExperiment& experiment, float d) { return tan_2theta * experiment.GetDetectorDistance_mm() / experiment.GetPixelSize_mm(); } +inline float DistFromEwaldSphere(const DiffractionExperiment& experiment, const Coord& recip) { + auto S = recip + experiment.GetScatteringVector(); + return fabsf(S.Length() - (1.0f/experiment.GetWavelength_A())); +} + inline float CalcRadIntSolidAngleCorr(const DiffractionExperiment& experiment, float q) { float sin_theta = q * experiment.GetWavelength_A() / (4 * static_cast(M_PI)); float cos_2theta = 1.0f - 2.0f * sin_theta * sin_theta; // cos(2*alpha) = 1 - 2 * sin(alpha)^2 diff --git a/tests/DiffractionGeometryTest.cpp b/tests/DiffractionGeometryTest.cpp index 6c5ce37f..a014290e 100644 --- a/tests/DiffractionGeometryTest.cpp +++ b/tests/DiffractionGeometryTest.cpp @@ -15,6 +15,7 @@ TEST_CASE("RecipToDetector_1", "[LinearAlgebra][Coord]") { REQUIRE(proj_x == Approx(pos_x)); REQUIRE(proj_y == Approx(pos_y)); REQUIRE((recip - DetectorToRecip(x, proj_x, proj_y)).Length() < 0.00000001f); + REQUIRE(DistFromEwaldSphere(x, recip) < 4e-4); } TEST_CASE("RecipToDetector_2", "[LinearAlgebra][Coord]") { @@ -27,6 +28,7 @@ TEST_CASE("RecipToDetector_2", "[LinearAlgebra][Coord]") { REQUIRE(proj_x == Approx(pos_x)); REQUIRE(proj_y == Approx(pos_y)); REQUIRE((recip - DetectorToRecip(x, proj_x, proj_y)).Length() < 0.00000001f); + REQUIRE(DistFromEwaldSphere(x, recip) < 4e-4); } TEST_CASE("RecipToDetector_3", "[LinearAlgebra][Coord]") { @@ -39,6 +41,7 @@ TEST_CASE("RecipToDetector_3", "[LinearAlgebra][Coord]") { REQUIRE(proj_x == Approx(pos_x)); REQUIRE(proj_y == Approx(pos_y)); REQUIRE((recip - DetectorToRecip(x, proj_x, proj_y)).Length() < 0.00000001f); + REQUIRE(DistFromEwaldSphere(x, recip) < 4e-4); } TEST_CASE("Phi","") {