One changeset, developed together in response to a review of this branch, so the files carry several of the changes at once. Full test suite passes (733 cases). Spot finding - Split ImageSpotFinder into Detect() (flag strong pixels - the expensive per-pixel pass) and ExtractSpots() (CCL + min/max-pix + resolution mask), with Run() = both. The per-image min-pix escalation now detects ONCE and repeats only the cheap extraction, instead of re-running the whole finder four times per frame as it did on the default path. It also keeps the winning attempt's spot list rather than re-extracting it, so the frame that is integrated is exactly the frame that was scored - which a GPU re-extract could not guarantee (float atomic ordering). - spot_finding_time_s no longer swallows indexing time, and indexing_time_s now sums every escalation call instead of reporting only the last. Detection limits follow the detector - The azimuthal-integration upper q and the spot-finding high-resolution limit are now std::optional, in the C++ structs AND in the OpenAPI schema, and resolve to the detector's own maximum (DiffractionExperiment::GetDetectorMaxQ_ recipA). Adaptive detection reads a pixel's ring from the azimuthal bins, so a pixel outside that q range could never be strong - the integration range silently bounded what detection could see, regardless of the requested resolution limit. Regenerated the C++ and TypeScript clients; the viewer and the web frontend each gained a "to detector edge" switch. Detection defaults are now per workflow (measured, not assumed) - Stills: adaptive detection, min-pix chosen per image, no resolution clipping. - Rotation: fixed-threshold finder, min-pix 2, 1.5 A limit. On a 33-crystal rotation battery, adaptive detection helped four hard crystals but deterministically broke three (a lost space group, a halved indexing rate, a collapsed merge), and the detector-edge limit cost indexing on a strong rotation set (100.0 -> 96.8%). Each is still overridable by its flag, and --no-adaptive-spots is new. Indexer seed escalation - Stop escalating once a seed's lattice explains >= 90% of the seed spots. Previously any frame with >= 80 spots always paid three indexer calls, online broker included. Merge-consistency filter - --min-image-cc gated on a per-image CC computed BEFORE the stills partiality post-refinement and never refreshed; the refiner now recomputes it, so the reported CC describes the data that are actually merged. - Replaced the per-call cc_mask argument with one MergeOnTheFly flag, so the merge, the error model and MergeStats can no longer disagree about which images are in (the --scale path merged unfiltered while its statistics were filtered). Per-image B-factor refinement (-B) removed - Measured on four serial-stills datasets: it is a no-op where the per-image fit is well conditioned and actively harmful where it is not (CC1/2 -8.1, R_meas +23.2 on the weakest large-cell set, whose fits hit their [-50, 200] bounds on 14-25% of images). It had also been silently DISCARDED since the partiality post-refinement landed - reported but not applied. Rather than fix and keep a knob with no demonstrated benefit, the flag and the whole image_scale_b_factor chain are gone: setting, scaling fit, message field, CBOR, HDF5 write and read-back, per-image plot, OpenAPI enum, viewer column and checkbox, docs. ScaleOnTheFly no longer needs Ceres at all - the fit is a linear IRLS. (The Wilson per-image b_factor is a different quantity and stays.) Stills partiality width now fits both of its components - sigma^2 = gamma0^2 + (gamma_e*d*)^2 instead of a purely angular gamma_e*d* with gamma0 pinned to 0. Fitted per crystal by least squares of dist_ewald^2 on d*^2. The angular-only width is fitted over a d*^2-dense population, so it was pinned by the high-resolution edge and collapsed at low d*: median partiality 0.008 beyond 13 A for reflections that were plainly recorded, 55% of them under the merge's partiality floor, and the survivors divided by those values - which inflated the merged low-resolution intensity scale 3.6x (~ +9 A^2 of apparent B). Measured on 5000 stills: the ramp flattens to 0.89x, no observation is dropped any more (701750 -> 716811), shell-mean CC1/2 and R-free improve slightly. Note CC1/2, R_meas, completeness and a B-refining R-free are all blind to that ramp, which is why it survived earlier validation; the cost is high-resolution R_meas (98.5 -> 101.9 shell-averaged). Removed dead code from add-then-remove churn - Prediction-time "still partiality" (unreachable: no setter), the phantom IndexingSettings::min_indexed_spot_fraction knob (getter, no setter - now the constant it always was), StillsPartialityRefine's caller-less Settings constructor and its reference to a long-gone env var, ProcessImage's unread bool return, an unused include, and a dead viewer overlay hook. Also - Viewer: the magnifier compared a QImage with itself, so its scene rect was set once ever and it could not pan into a larger dataset; the hover tail timer could fire after leaveEvent and resurrect the resolution readout outside the image. - update_version.sh regenerated the frontend lock file BEFORE bumping the version (every release shipped an off-by-one lock), and did git rm/git add on a path that has not existed since the client moved to src/client - with no set -e, both failed silently. - fpga/pcie_driver/postinstall.sh tested "[ ! occurrences > 0 ]", which is a redirect, not a test, so dkms add never ran. - Unit tests for the adaptive-threshold host functions, which had none. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
132 lines
4.3 KiB
C++
132 lines
4.3 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <map>
|
|
#include <shared_mutex>
|
|
#include <string>
|
|
|
|
#include "StatusVector.h"
|
|
#include "Histogram.h"
|
|
#include "ADUHistogram.h"
|
|
#include "AutoIncrVector.h"
|
|
#include "DiffractionExperiment.h"
|
|
#include "AzimuthalIntegrationProfile.h"
|
|
#include "JFJochMessages.h"
|
|
#include "Plot.h"
|
|
#include "ScanResult.h"
|
|
|
|
struct MeanProcessingTime {
|
|
float compression;
|
|
float preprocessing;
|
|
float azint;
|
|
float spot_finding;
|
|
float indexing;
|
|
float refinement;
|
|
float integration;
|
|
float bragg_prediction;
|
|
float processing;
|
|
float indexing_analysis;
|
|
float image_scale;
|
|
};
|
|
|
|
class JFJochReceiverPlots {
|
|
mutable std::mutex m; // protects xfel_pulse_id, xfel_event_code and az_int_profile
|
|
|
|
std::optional<GoniometerAxis> goniometer;
|
|
std::optional<GridScanSettings> grid_scan;
|
|
int64_t default_binning = 1;
|
|
std::unique_ptr<AzimuthalIntegrationProfile> az_int_profile;
|
|
AutoIncrVector<uint64_t> xfel_pulse_id;
|
|
AutoIncrVector<uint64_t> xfel_event_code;
|
|
|
|
StatusVector bkg_estimate;
|
|
StatusVector ice_ring_score;
|
|
StatusVector spot_count;
|
|
StatusVector spot_count_low_res;
|
|
StatusVector spot_count_indexed;
|
|
StatusVector spot_count_ice;
|
|
|
|
StatusVector indexing_solution;
|
|
StatusVector indexing_lattice_count;
|
|
StatusVector indexing_uc_a;
|
|
StatusVector indexing_uc_b;
|
|
StatusVector indexing_uc_c;
|
|
StatusVector indexing_uc_alpha;
|
|
StatusVector indexing_uc_beta;
|
|
StatusVector indexing_uc_gamma;
|
|
StatusVector error_pixels;
|
|
StatusVector saturated_pixels;
|
|
StatusVector strong_pixels;
|
|
StatusVector receiver_delay;
|
|
StatusVector receiver_buf_available;
|
|
StatusVector receiver_buf_in_sending;
|
|
StatusVector receiver_buf_in_preparation;
|
|
StatusVector image_collection_efficiency;
|
|
StatusVector packets_received;
|
|
StatusVector max_value;
|
|
StatusVector resolution_estimate;
|
|
StatusVector integrated_reflections;
|
|
StatusVector image_scale_factor;
|
|
StatusVector image_scale_cc;
|
|
StatusVector compression_ratio;
|
|
|
|
// StatusVector objects are fully thread-safe (protected by internal mutex)
|
|
// It is OK to have concurrent access to StatusVector
|
|
// roi_m lock is needed to make sure that std::map<std::string, ROIStatus> is not mutable within critical section
|
|
// so no new elements added outside of a unique lock, but it is OK to modify ROIStatus under shared lock
|
|
struct ROIStatus {
|
|
StatusVector sum;
|
|
StatusVector max_count;
|
|
StatusVector pixels;
|
|
StatusVector x;
|
|
StatusVector y;
|
|
StatusVector mean;
|
|
};
|
|
mutable std::shared_mutex roi_m;
|
|
std::map<std::string, ROIStatus> roi_status;
|
|
|
|
StatusVector profile_radius;
|
|
StatusVector mosaicity_deg;
|
|
StatusVector b_factor;
|
|
StatusVector pixel_sum;
|
|
|
|
StatusVector beam_center_x;
|
|
StatusVector beam_center_y;
|
|
|
|
StatusVector spot_finding_time;
|
|
StatusVector indexing_time;
|
|
StatusVector refinement_time;
|
|
StatusVector integration_time;
|
|
StatusVector bragg_prediction_time;
|
|
StatusVector total_processing_time;
|
|
StatusVector preprocessing_time;
|
|
StatusVector compression_time;
|
|
StatusVector azint_time;
|
|
StatusVector indexing_analysis_time;
|
|
StatusVector image_scale_time;
|
|
|
|
MultiLinePlot GetROIPlot(PlotType type, int64_t nbins, float start, float incr,
|
|
const std::optional<float> &fill_value) const;
|
|
public:
|
|
void Setup(const DiffractionExperiment& experiment, const AzimuthalIntegrationMapping& mapping);
|
|
|
|
void Add(const DataMessage& msg, const AzimuthalIntegrationProfile &profile);
|
|
void AddEmptyImage(const DataMessage& msg);
|
|
MultiLinePlot GetPlots(const PlotRequest& request);
|
|
|
|
void GetXFELPulseID(std::vector<uint64_t>& v) const;
|
|
void GetXFELEventCode(std::vector<uint64_t>& v) const;
|
|
|
|
std::optional<float> GetIndexingRate() const;
|
|
std::optional<float> GetBkgEstimate() const;
|
|
|
|
std::vector<float> GetAzIntProfile() const;
|
|
MultiLinePlot GetAzIntProfilePlot(bool force_1d = false, PlotAzintUnit azint_unit = PlotAzintUnit::Q_recipA) const;
|
|
|
|
MeanProcessingTime GetMeanProcessingTime() const;
|
|
|
|
void GetPlotRaw(std::vector<float> &v, PlotType type, const std::string &roi);
|
|
};
|