Polarization plane decided once, in the pre-scan, and followed by the integration too

The shadow finder already compares the background's cos 2phi harmonic with the profile a polarized
source gives it, and applies the stated degree in the plane the background shows where it shows
one clearly (correlation > 0.5, at least 0.3 of a fully polarized source's modulation). The
integration's Lorentz-polarization factor still assumed the plane along lab x, so on a run whose
background is suppressed along the image's y axis the two disagreed, and only a negative
--polarization made them agree.

ShadowFinder now reports what it applied (GetAppliedPolarization), the pre-scan writes it into the
experiment (and keeps it in the beam-stop memo with the mask), and everything built after the
pre-scan - the Bragg integration, the azimuthal mapping - reads the same plane. The degree is never
fitted; only the plane can turn, and only where the shadow finder already turned it. Where the plane
is not turned the experiment is not touched, so every other run is bit-identical: six rotation sets
give the same p.hkl md5 as rc178, and the stills sets that do not turn give the same R_free, R_split,
indexed fraction and d_min. On the one stills run whose plane turns, R_free and the resolution cut
are the ones a stated -0.998 gave before, now from a bare invocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
(cherry picked from commit f50bfe15f7dccf588bd8bdd6114a32e3ac9b36ed)
This commit is contained in:
leonarski_f committed 2026-10-23 17:56:51 +02:00
1 parent 0c12178371
commit c74678b06f
9 files changed
+54 -7

No files matched your search

+11 -1
View File
@@ -412,6 +412,7 @@ TEST_CASE("ShadowFinder_APolarizedBackgroundIsNotAShadow", "[ShadowFinder]") {
frame[I(x, y)] = static_cast<int32_t>(std::lround(LEVEL * factor / at_peak));
}
std::optional<float> applied;
auto mask_for = [&](const std::optional<float> &polarization) {
DiffractionExperiment x = TestExperiment();
x.DetectorDistance_mm(DISTANCE_MM).PolarizationFactor(polarization);
@@ -424,10 +425,12 @@ TEST_CASE("ShadowFinder_APolarizedBackgroundIsNotAShadow", "[ShadowFinder]") {
finder.AddImage(msg, buffer);
}
const auto mask = finder.GetMask();
applied = finder.GetAppliedPolarization();
return std::count(mask.begin(), mask.end(), 1u);
};
CHECK(mask_for(POLARIZATION) == 0);
CHECK(applied == POLARIZATION); // the plane the background shows is the stated one: kept as stated
CHECK(mask_for(std::nullopt) > static_cast<long>(W) * H / 20);
}
@@ -455,6 +458,7 @@ TEST_CASE("ShadowFinder_ThePolarizationPlaneIsTheOneTheBackgroundShows", "[Shado
frame[I(xi, y)] = stop[I(xi, y)] == 0 ? 0 : static_cast<int32_t>(std::lround(LEVEL * factor));
}
std::optional<float> applied; // what the run's other corrections take (GetAppliedPolarization)
auto mask_for = [&](const std::optional<float> &polarization) {
DiffractionExperiment x = TestExperiment();
x.DetectorDistance_mm(DISTANCE_MM).PolarizationFactor(polarization);
@@ -466,10 +470,13 @@ TEST_CASE("ShadowFinder_ThePolarizationPlaneIsTheOneTheBackgroundShows", "[Shado
msg.image = CompressedImage(frame, W, H);
finder.AddImage(msg, buffer);
}
return finder.GetMask();
const auto out = finder.GetMask();
applied = finder.GetAppliedPolarization();
return out;
};
const auto mask = mask_for(0.99f);
CHECK(applied == -0.99f); // the stated degree, in the plane shown
CHECK(mask[I(C, C)] == ShadowFinder::SHADOW); // the stop
CHECK(mask[I(W - 3, C)] == ShadowFinder::SHADOW); // and its arms, along x
CHECK(mask[I(C, 3)] == ShadowFinder::SHADOW); // and along y, inside the suppressed lobe
@@ -477,6 +484,9 @@ TEST_CASE("ShadowFinder_ThePolarizationPlaneIsTheOneTheBackgroundShows", "[Shado
CHECK(mask[I(C - 20, H - 4)] == 0);
CHECK(mask_for(0.998f) == mask);
CHECK(mask_for(-0.998f) == mask);
CHECK(applied == -0.998f);
mask_for(std::nullopt);
CHECK(!applied); // no stated degree, nothing to apply
}
// The plane is decided from the sector medians of each band: the cos 2phi harmonic has to follow the