71 lines
3.0 KiB
C++
71 lines
3.0 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "SpotAnalyze.h"
|
|
|
|
#include "geom_refinement/XtalOptimizer.h"
|
|
#include "spot_finding/SpotAnalysis.h"
|
|
#include "spot_finding/StrongPixelSet.h"
|
|
#include "bragg_integration/BraggIntegrate2D.h"
|
|
|
|
void SpotAnalyze(const DiffractionExperiment &experiment,
|
|
const SpotFindingSettings &spot_finding_settings,
|
|
const std::vector<DiffractionSpot> &spots,
|
|
const CompressedImage &image,
|
|
IndexerThreadPool *indexer,
|
|
DataMessage &output) {
|
|
|
|
std::vector<SpotToSave> spots_out;
|
|
|
|
auto geom = experiment.GetDiffractionGeometry();
|
|
for (const auto &spot: spots)
|
|
spots_out.push_back(spot.Export(geom));
|
|
|
|
CountSpots(output, spots_out, spot_finding_settings.cutoff_spot_count_low_res);
|
|
|
|
FilterSpotsByCount(experiment.GetMaxSpotCount(), spots_out, output.spots);
|
|
|
|
if ((indexer != nullptr) && spot_finding_settings.indexing) {
|
|
auto latt_f = indexer->Run(experiment, output);
|
|
auto latt = latt_f.get();
|
|
|
|
if (latt) {
|
|
DiffractionExperiment experiment_copy(experiment);
|
|
XtalOptimizerData data{
|
|
.geom = experiment_copy.GetDiffractionGeometry(),
|
|
.latt = latt.value()
|
|
};
|
|
switch (experiment.GetIndexingSettings().GetGeomRefinementAlgorithm()) {
|
|
case GeomRefinementAlgorithmEnum::None:
|
|
break;
|
|
case GeomRefinementAlgorithmEnum::BeamCenter:
|
|
XtalOptimizer(data, output.spots, false);
|
|
experiment_copy.BeamX_pxl(data.geom.GetBeamX_pxl()).BeamY_pxl(data.geom.GetBeamY_pxl());
|
|
output.beam_center_x = data.geom.GetBeamX_pxl();
|
|
output.beam_center_y = data.geom.GetBeamY_pxl();
|
|
latt = data.latt;
|
|
output.indexing_lattice = data.latt;
|
|
break;
|
|
case GeomRefinementAlgorithmEnum::BeamCenterTetragonal:
|
|
XtalOptimizer(data, output.spots, true);
|
|
experiment_copy.BeamX_pxl(data.geom.GetBeamX_pxl()).BeamY_pxl(data.geom.GetBeamY_pxl());
|
|
output.beam_center_x = data.geom.GetBeamX_pxl();
|
|
output.beam_center_y = data.geom.GetBeamY_pxl();
|
|
latt = data.latt;
|
|
output.indexing_lattice = data.latt;
|
|
break;
|
|
}
|
|
|
|
if (spot_finding_settings.quick_integration) {
|
|
auto res = BraggIntegrate2D(experiment_copy, image, latt.value());
|
|
|
|
float res_estimate = sqrtf((res.b_factor.value_or(12.0f) - 12.0f) / 4.0f);
|
|
if (res_estimate > 1.0 && res_estimate < 4.0)
|
|
output.resolution_estimate = res_estimate;
|
|
output.reflections = res.reflections;
|
|
output.b_factor = res.b_factor;
|
|
}
|
|
}
|
|
}
|
|
}
|