ScaleAndMerge: clean-up (no log residual, no fixed mosaicity, return per-image values)

This commit is contained in:
2026-02-20 11:37:59 +01:00
parent 43c3402198
commit e6e0f5b2f0
5 changed files with 128 additions and 150 deletions
+12 -14
View File
@@ -17,6 +17,7 @@ IndexAndRefine::IndexAndRefine(const DiffractionExperiment &x, IndexerThreadPool
indexer_(indexer) {
if (indexer && x.IsRotationIndexing())
rotation_indexer = std::make_unique<RotationIndexer>(x, *indexer);
reflections.resize(x.GetImageNum());
}
IndexAndRefine::IndexingOutcome IndexAndRefine::DetermineLatticeAndSymmetry(DataMessage &msg) {
@@ -198,16 +199,15 @@ void IndexAndRefine::QuickPredictAndIntegrate(DataMessage &msg,
[](const Reflection& a, const Reflection& b) { return a.d < b.d; });
}
{
std::unique_lock ul(reflections_mutex);
reflections[msg.number] = refl_ret; // Image is not processed twice, so thread-safe in principle, but better safe than sorry :)
}
msg.reflections = std::move(refl_ret);
CalcISigma(msg);
CalcWilsonBFactor(msg);
// Append reflections to the class-wide reflections buffer (thread-safe)
{
std::unique_lock ul(reflections_mutex);
reflections.insert(reflections.end(), msg.reflections.begin(), msg.reflections.end());
}
}
void IndexAndRefine::ProcessImage(DataMessage &msg,
@@ -242,15 +242,13 @@ std::optional<RotationIndexerResult> IndexAndRefine::Finalize() {
}
std::optional<ScaleMergeResult> IndexAndRefine::ScaleRotationData(const ScaleMergeOptions &opts) const {
std::vector<Reflection> snapshot;
{
std::unique_lock ul(reflections_mutex);
snapshot = reflections; // cheap copy under lock
}
size_t nrefl = 0;
for (const auto &i: reflections)
nrefl += i.size();
// Need a reasonable number of reflections to make refinement meaningful
constexpr size_t kMinReflections = 20;
if (snapshot.size() < kMinReflections)
if (nrefl < kMinReflections)
return std::nullopt;
// Build options focused on mosaicity refinement but allow caller override
@@ -267,5 +265,5 @@ std::optional<ScaleMergeResult> IndexAndRefine::ScaleRotationData(const ScaleMer
options.space_group = *sg;
}
return ScaleAndMergeReflectionsCeres(snapshot, options);
}
return ScaleAndMergeReflectionsCeres(reflections, options);
}