From 1911875e1c7ec153efdd717b0d8979696a8bd2cd Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sat, 18 Jul 2026 10:23:17 +0200 Subject: [PATCH] integration: carry the box-sum observed centroid through the profile path Pass A (the box-sum) always computes an intensity-weighted centroid (the observed spot position), but it was only emitted in BoxSum mode. Rotation integration runs the profile path, so observed_x/y were left NAN there and no positional (detector<->reciprocal) residual was possible downstream. Emit the Pass-A centroid in the profile path too (CPU) and copy d_obs_x/d_obs_y back in all modes (GPU) - Pass A fills them regardless of integrator mode. observed_x/y are consumed only by the diagnostic HDF5 reflection table and the viewer read-back; nothing in scaling/merge reads them, so merged output is unchanged - the _process.h5 observed_x/y columns simply go from NAN to the real centroid. This makes the observed position available to post-refinement. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../bragg_integration/BraggIntegrationEngineCPU.cpp | 5 ++++- .../bragg_integration/BraggIntegrationEngineGPU.cu | 13 ++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/image_analysis/bragg_integration/BraggIntegrationEngineCPU.cpp b/image_analysis/bragg_integration/BraggIntegrationEngineCPU.cpp index c5f6f346..d4371d71 100644 --- a/image_analysis/bragg_integration/BraggIntegrationEngineCPU.cpp +++ b/image_analysis/bragg_integration/BraggIntegrationEngineCPU.cpp @@ -345,8 +345,11 @@ std::vector BraggIntegrationEngineCPU::RunImpl(const Sampler &img, I = rh.I; sigma = rh.sigma; } + // Carry the Pass-A box-sum intensity-weighted centroid (observed spot position) through the + // profile path too - post-refinement uses it as the observed position (beam-centre / distance). results[i] = {static_cast(I), static_cast(sigma), - static_cast(rh.bkg), 0.0f, 0.0f, true, false}; + static_cast(rh.bkg), + static_cast(rh.obs_x), static_cast(rh.obs_y), true, rh.has_obs}; } return Finalize(predicted, npredicted, results, image_number); diff --git a/image_analysis/bragg_integration/BraggIntegrationEngineGPU.cu b/image_analysis/bragg_integration/BraggIntegrationEngineGPU.cu index 36a62773..b0a3d6a5 100644 --- a/image_analysis/bragg_integration/BraggIntegrationEngineGPU.cu +++ b/image_analysis/bragg_integration/BraggIntegrationEngineGPU.cu @@ -518,12 +518,11 @@ std::vector BraggIntegrationEngineGPU::Run(const ImagePreprocessorBu cuda_err(cudaMemcpyAsync(h_sigma.data(), d_sigma, sizeof(float) * npredicted, cudaMemcpyDeviceToHost, *stream)); cuda_err(cudaMemcpyAsync(h_bkg.data(), d_bkg, sizeof(float) * npredicted, cudaMemcpyDeviceToHost, *stream)); cuda_err(cudaMemcpyAsync(h_ok.data(), d_ok, sizeof(uint8_t) * npredicted, cudaMemcpyDeviceToHost, *stream)); - const bool boxsum_mode = mode == IntegratorMode::BoxSum; - if (boxsum_mode) { - cuda_err(cudaMemcpyAsync(h_obs_x.data(), d_obs_x, sizeof(float) * npredicted, cudaMemcpyDeviceToHost, *stream)); - cuda_err(cudaMemcpyAsync(h_obs_y.data(), d_obs_y, sizeof(float) * npredicted, cudaMemcpyDeviceToHost, *stream)); - cuda_err(cudaMemcpyAsync(h_has_obs.data(), d_has_obs, sizeof(uint8_t) * npredicted, cudaMemcpyDeviceToHost, *stream)); - } + // Pass A always fills the box-sum centroid (observed spot position), so copy it back in all modes - + // post-refinement uses it as the observed position (beam-centre / distance). + cuda_err(cudaMemcpyAsync(h_obs_x.data(), d_obs_x, sizeof(float) * npredicted, cudaMemcpyDeviceToHost, *stream)); + cuda_err(cudaMemcpyAsync(h_obs_y.data(), d_obs_y, sizeof(float) * npredicted, cudaMemcpyDeviceToHost, *stream)); + cuda_err(cudaMemcpyAsync(h_has_obs.data(), d_has_obs, sizeof(uint8_t) * npredicted, cudaMemcpyDeviceToHost, *stream)); cuda_err(cudaStreamSynchronize(*stream)); for (size_t i = 0; i < npredicted; ++i) { @@ -532,7 +531,7 @@ std::vector BraggIntegrationEngineGPU::Run(const ImagePreprocessorBu results[i].sigma = h_sigma[i]; results[i].bkg = h_bkg[i]; results[i].ok = true; - if (boxsum_mode && h_has_obs[i]) { + if (h_has_obs[i]) { results[i].observed_x = h_obs_x[i]; results[i].observed_y = h_obs_y[i]; results[i].has_observed = true;