Files
Jungfraujoch/common/AzimuthalIntegrationProfile.h
T
leonarski_fandClaude Fable 5 5737d2e1d0 ice score: measure against a smooth whole-profile background, not shoulders
The score's baseline was two adjacent shoulder bins with a bin-overlap bug - the
ring's edge bins were counted in both the ring and the shoulder, since
GetMeanValueOfBins is inclusive. At the typical (coarse) azint binning (dq ~ 0.05
in q, wider than the 0.03 ring half-width) a shoulder is only ~1 bin, so the ratio
was noisy and poorly separated. Replace it with the ring intensity over a smooth
whole-profile background: a running median of the non-ice bins, interpolated under
each ring.

Clean crystals now sit at ~1.0 and ice separates far more cleanly on
/data/rotation_test: cytC 1.06->1.03, lysoC 1.23->2.77, EP_cs_01-17 1.67->4.51
(max 11.4). A z-score / abnormality probability was tried but is uninformative
here - with many photons any real ice ring is highly significant, so the useful
discriminator is the ice magnitude (this ratio), noted in CPU_DATA_ANALYSIS.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 17:05:39 +02:00

53 lines
2.0 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 GetIceRingScore(const AzimuthalIntegrationSettings& settings, float half_width_q) const;
MultiLinePlot GetPlot(bool force_1d = false, PlotAzintUnit plot_unit = PlotAzintUnit::Q_recipA) const;
AzimuthalIntegrationProfile& operator+=(const AzimuthalIntegrationProfile& profile); // Not thread safe
};