A serial collection can be analysed on a fraction of its images, to keep up with a stream faster than the analysis. Not a stride, which is in step with periodic patterns of the stream (pump-probe on/off, storage cells, module or card interleave) and could take only the dark frames: each image is chosen on its own with probability 1/F from the SplitMix64 finaliser of its number, salted (StillsImageSelected), reproducible and the same on every thread and card. The first StillsGPUAnalysis::PREPASS_MAX_IMAGES (2000) images are all taken, as the pre-pass may use any of them. An image not chosen is counted as collected and skipped before the analysis, neither analysed nor written - as one the serial filter leaves out. - OpenAPI rugnux_settings / rugnux_status: stills_downsample (int64, >= 1, default 1); C++ model and frontend client regenerated; the Rugnux settings page gets the field. Kept by POST /initialize, as reserved_cpus. - JFJochReceiverService::RugnuxLive, JFJochStateMachine::SetRugnuxLive, JFJochReceiverRugnuxStills take it. - jfjoch_fpga_stills_test -k <F>, jfjoch_stills_gpu_replay -k <F>. - StillsSelectionTest: fraction within 5 sigma for F = 2, 3, 4, 10 over 400k images, every phase of a period-2 and a period-F pattern gets its share, deterministic, pre-pass images and F = 1 all taken. Measured (mock, 9M, 6000 images, -k 4): 2984 analysed = 0.497 (expected 0.5 with the first 2000 all in; 0.246 of the rest). Host-only replay of 10000 serial 8M images: 17.0 s -> 10.0 s in all, after the pre-pass 10.6 s -> 3.4 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UqXYdHHZ4cogS1mrGUtfN7
43 lines
1.9 KiB
C++
43 lines
1.9 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
#include <cmath>
|
|
|
|
#include "../receiver/StillsSelection.h"
|
|
|
|
TEST_CASE("StillsImageSelected_FractionAndPeriods", "[StillsSelection]") {
|
|
constexpr int64_t first = 2000;
|
|
constexpr int64_t images = 400000;
|
|
for (const int64_t factor: {2, 3, 4, 10}) {
|
|
INFO("factor " << factor);
|
|
const double p = 1.0 / static_cast<double>(factor);
|
|
int64_t selected = 0;
|
|
for (int64_t i = first; i < first + images; i++)
|
|
selected += StillsImageSelected(i, factor, first) ? 1 : 0;
|
|
// Within 5 standard deviations of the binomial
|
|
CHECK(std::abs(static_cast<double>(selected) / images - p) < 5 * std::sqrt(p * (1 - p) / images));
|
|
|
|
// Every phase of a period-2 and a period-F pattern (pump-probe on/off, a stride) gets its share
|
|
for (const int64_t period: {int64_t(2), factor}) {
|
|
for (int64_t phase = 0; phase < period; phase++) {
|
|
INFO("period " << period << " phase " << phase);
|
|
int64_t n = 0, s = 0;
|
|
for (int64_t i = first + phase; i < first + images; i += period) {
|
|
n++;
|
|
s += StillsImageSelected(i, factor, first) ? 1 : 0;
|
|
}
|
|
CHECK(std::abs(static_cast<double>(s) / n - p) < 5 * std::sqrt(p * (1 - p) / n));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_CASE("StillsImageSelected_DeterministicAndPrePass", "[StillsSelection]") {
|
|
for (int64_t i = 0; i < 10000; i++) {
|
|
CHECK(StillsImageSelected(i, 1, 0)); // factor 1: every image
|
|
CHECK(StillsImageSelected(i, 7, 10000)); // before all_before: every image
|
|
CHECK(StillsImageSelected(i, 7, 0) == StillsImageSelected(i, 7, 0));
|
|
}
|
|
}
|