Two things, both about telling one ice quantity from another. The ice score's spot channel had its own band half-width of 0.02 A^-1 while the spot finder marks ice rings at 0.03 (ice_ring_width_Q_recipA). The 0.02 was justified by a 5 pp specificity gain measured on the PYTHON PROTOTYPE, which used a fitted beam centre and a mask-derived coverage table; the shipped port, which takes the geometry's centre and the azimuthal profile's own live pixel count, does not reproduce it. Measured over the corpus by truth class rather than by directory label, at 0.02 vs 0.03 on the combined score: ice loops 62.13/62.19%, _icy protein 89.03/89.79%, _clean protein 16.51/16.31%, water 17.19/20.03%. The widths are indistinguishable except on water, where one of the four loops is independently known to carry a full hexagonal pattern. So the width is now a parameter and the pipeline's own value is passed in - one band width, not two. The 0.012 tolerance in the radial channel is NOT a second band width, and is renamed CENTRE_SMEAR_Q to say so: it is how far either side the channel looks for the bin a mis-set beam centre moved the ring to. The rest is naming. Three kinds of number were all called score, or built from things called count, and a reader could not tell from the name whether 1 meant "none" or "certain" - which are opposite. The convention, now stated in docs/CPU_DATA_ANALYSIS.md: *_score is bounded [0,1] and 1 is certainty, *_ratio is unbounded and 1 is nothing, *_count is a count. The C++ identifiers for the ice ring ratio follow it (ice_ring_score -> ice_ring_ratio, GetIceRingScore -> GetIceRingRatio, PlotType::IceRingScore -> IceRingRatio), and the local in the scaling gate that shadowed the new ice_score while meaning the ring ratio is renamed with them. Nothing outside the source moved: the CBOR keys ice_ring_score and ice_ring_score_mean, the datasets /entry/MX/iceRingScore and iceRingScoreMean, the ice_ring_score plot type and the --ice-min-score flag are all unchanged, and were checked to be after the rename. Renaming those changes stored files, the stream format, the REST API and a CLI flag, and is a separate decision. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFEJG6WBQv8th4UJFNe53N
58 lines
2.5 KiB
C++
58 lines
2.5 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <vector>
|
|
#include <mutex>
|
|
#include "MultiLinePlot.h"
|
|
|
|
#include "AzimuthalIntegrationMapping.h"
|
|
#include "../fpga/pcie_driver/jfjoch_fpga.h" // DeviceOutput
|
|
|
|
class AzimuthalIntegrationProfile {
|
|
mutable std::mutex m;
|
|
std::vector<float> sum;
|
|
std::vector<float> sum2;
|
|
std::vector<uint64_t> count;
|
|
std::vector<float> bin_to_q;
|
|
std::vector<float> bin_to_d;
|
|
std::vector<float> bin_to_2theta;
|
|
std::vector<float> bin_to_phi;
|
|
std::vector<float> bin_to_q_1d;
|
|
|
|
int32_t q_bins;
|
|
int32_t azim_bins;
|
|
std::string title;
|
|
|
|
const std::vector<float>& GetXAxis(PlotAzintUnit unit) const;
|
|
public:
|
|
explicit AzimuthalIntegrationProfile(const AzimuthalIntegrationMapping &mapping);
|
|
void Clear(const AzimuthalIntegrationMapping &mapping);
|
|
void SetTitle(const std::string& input);
|
|
void Add(const DeviceOutput &result);
|
|
void Add(const std::vector<float> &sum,
|
|
const std::vector<float> &sum2,
|
|
const std::vector<uint32_t> &count);
|
|
void Add(int64_t bin, int64_t value);
|
|
|
|
std::vector<float> GetResult() const;
|
|
std::vector<float> GetStd() const;
|
|
std::vector<uint64_t> GetPixelCount() const;
|
|
|
|
std::vector<float> GetResult1D() const;
|
|
|
|
float GetMeanValueOfBins(uint16_t min_bin, uint16_t max_bin) const;
|
|
float GetBkgEstimate(const AzimuthalIntegrationSettings& settings) const;
|
|
// Single per-image ice indicator: the strongest hexagonal-ice ring's intensity relative to the smooth
|
|
// radial background interpolated under it (1 = no ice, >1 = ice). See the .cpp for the background fit.
|
|
float GetIceRingRatio(const AzimuthalIntegrationSettings& settings, float half_width_q) const;
|
|
// The same score for a radial profile that is not this object's: the adaptive spot finder computes a
|
|
// peak-excluded per-ring background in these same bins, which is a much cleaner input (see the .cpp).
|
|
// profile is q_bins long, or q_bins x azimuthal bins, in which case it is averaged over azimuth first.
|
|
static float IceRingRatio(const std::vector<float>& profile, int32_t q_bins,
|
|
const AzimuthalIntegrationSettings& settings, float half_width_q);
|
|
MultiLinePlot GetPlot(bool force_1d = false, PlotAzintUnit plot_unit = PlotAzintUnit::Q_recipA) const;
|
|
AzimuthalIntegrationProfile& operator+=(const AzimuthalIntegrationProfile& profile); // Not thread safe
|
|
};
|