Files
Jungfraujoch/broker/gen/model/Spot_finding_settings.cpp
T
leonarski_fandClaude Opus 5 61a7c91b90 Ice: detect it on two channels, and only handle it when it is there
The per-image ice score was read off the PLAIN azimuthal profile. That profile is a
per-ring mean, so a few strong Bragg reflections landing in a ring's q bin lift it
exactly as ice would. Measured over 37 rotation crystals, that did not merely add
noise - it INVERTED the metric: the two highest-scoring crystals had no ice at all
(4.23 and 4.06), while a clean control read 1.57. A decoy null - the identical
statistic evaluated at q positions where hexagonal ice cannot be - reaches 1.51 at its
99th percentile and 2.70 at its maximum, so that metric cannot support any absolute
threshold whatsoever.

The adaptive spot finder already computes the right input for its own threshold: a
sigma-clipped per-resolution-ring background, in the same bins. A powder ring is
azimuthally smooth and survives the clip; Bragg peaks do not. On the clipped profile
the clean population tightens to 1.00-1.22 and the crystals with confirmed ice sit at
2.08-2.37, against a decoy null that never exceeds 1.29.

That channel is blind to one thing: ice in large crystallites diffracts as DISCRETE
spots and leaves the radial profile flat. So a second channel counts found spots on the
rings against the same q width of ice-free flanks beside them. The two barely overlap -
the smooth-ice crystals read 2.1-2.4 / ~1.0 and the textured ones ~1.1 / 3.8-17.6,
while a clean crystal reads 1.04 on both.

Both are then used as a GATE (--ice-min-score 1.5, --ice-min-spot-ratio 2.0, both
calibrated on the battery, 0 disables): the eleven fixed hexagonal bands cover 16-26 %
of the unique reflections at typical resolutions whether or not the crystal has ice, so
flagging, the exclusion from the scale fit and the merge-time CC1/2 ring mask are now
all skipped when neither channel sees any. The gate is applied in the full pipeline and
in --scale, which reads the stored per-image values back out of the _process.h5.

Also fixes the merge-time mask's control: the shoulder now excludes reflections that
are themselves on an ice ring. The rings are not evenly spaced - 1.947/1.916/1.882 A
sit 0.05-0.06 apart in q - so for those three the [w,3w) shoulder landed squarely on
the neighbours and the test compared ice against ice. Measured, that is the only thing
this changes: it removes firings on those three rings and leaves every other firing's
CC pair identical to three decimals.

And the online ice half-width, which was 0.02 in the API against 0.03 offline, so the
same data got a narrower band online than the measured ~0.06 ring FWHM justifies.

Battery (37 rotation crystals, against the previous behaviour): space groups 34/37 in
both and NO crystal's space group changes; 6 crystals gain unique reflections, 1 loses.
Best of them gains 7082 unique reflections with R_meas 16.0 -> 14.3, CC1/2 95.9 -> 97.3
and ISa 13.7 -> 19.0; another goes R_meas 54.9 -> 42.9, CC1/2 84.0 -> 90.4, ISa
3.9 -> 5.5; a third reaches CC1/2 99.4 from 95.7 at an unchanged reflection count. The
one crystal that loses reflections improves on both R_meas and CC1/2.

Not done here: the ScanResult/API/plot-type/frontend/viewer layers for the new
spot_count_ice_control (they need the OpenAPI regeneration). Message, CBOR, HDF5
write/read and the receiver plots are.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-06 16:17:23 +02:00

466 lines
15 KiB
C++

/**
* Jungfraujoch
* API to control Jungfraujoch developed by the Paul Scherrer Institute (Switzerland). Jungfraujoch is a data acquisition and analysis system for pixel array detectors, primarly PSI JUNGFRAU. Jungfraujoch uses FPGA boards to acquire data at high data rates. # License Clarification While this API definition is licensed under GPL-3.0, **the GPL copyleft provisions do not apply** when this file is used solely to generate OpenAPI clients or when implementing applications that interact with the API. Generated client code and applications using this API definition are not subject to the GPL license requirements and may be distributed under terms of your choosing. This exception is similar in spirit to the Linux Kernel's approach to userspace API headers and the GCC Runtime Library Exception. The Linux Kernel developers have explicitly stated that user programs that merely use the kernel interfaces (syscalls, ioctl definitions, etc.) are not derivative works of the kernel and are not subject to the terms of the GPL. This exception is intended to allow wider use of this API specification without imposing GPL requirements on applications that merely interact with the API, regardless of whether they communicate through network calls or other mechanisms.
*
* The version of the OpenAPI document: 1.0.0-rc.161
* Contact: filip.leonarski@psi.ch
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "Spot_finding_settings.h"
#include "Helpers.h"
#include <sstream>
namespace org::openapitools::server::model
{
Spot_finding_settings::Spot_finding_settings()
{
m_Enable = true;
m_Indexing = true;
m_Signal_to_noise_threshold = 0.0f;
m_Photon_count_threshold = 0L;
m_Min_pix_per_spot = 0L;
m_Max_pix_per_spot = 0L;
m_High_resolution_limit = 0.0f;
m_High_resolution_limitIsSet = false;
m_Low_resolution_limit = 0.0f;
m_High_resolution_limit_for_spot_count_low_res = 0.0f;
m_Quick_integration = false;
m_Ice_ring_width_q_recipA = 0.03f;
m_High_res_gap_Q_recipA = 1.5f;
m_High_res_gap_Q_recipAIsSet = false;
m_Adaptive_threshold = false;
m_Adaptive_thresholdIsSet = false;
m_False_pixels_per_frame = 100.0f;
m_False_pixels_per_frameIsSet = false;
}
void Spot_finding_settings::validate() const
{
std::stringstream msg;
if (!validate(msg))
{
throw org::openapitools::server::helpers::ValidationException(msg.str());
}
}
bool Spot_finding_settings::validate(std::stringstream& msg) const
{
return validate(msg, "");
}
bool Spot_finding_settings::validate(std::stringstream& msg, const std::string& pathPrefix) const
{
bool success = true;
const std::string _pathPrefix = pathPrefix.empty() ? "Spot_finding_settings" : pathPrefix;
/* Signal_to_noise_threshold */ {
const float& value = m_Signal_to_noise_threshold;
const std::string currentValuePath = _pathPrefix + ".signalToNoiseThreshold";
if (value < static_cast<float>(0))
{
success = false;
msg << currentValuePath << ": must be greater than or equal to 0;";
}
}
/* Photon_count_threshold */ {
const int64_t& value = m_Photon_count_threshold;
const std::string currentValuePath = _pathPrefix + ".photonCountThreshold";
if (value < 0ll)
{
success = false;
msg << currentValuePath << ": must be greater than or equal to 0;";
}
}
/* Min_pix_per_spot */ {
const int64_t& value = m_Min_pix_per_spot;
const std::string currentValuePath = _pathPrefix + ".minPixPerSpot";
if (value < 1ll)
{
success = false;
msg << currentValuePath << ": must be greater than or equal to 1;";
}
}
/* Max_pix_per_spot */ {
const int64_t& value = m_Max_pix_per_spot;
const std::string currentValuePath = _pathPrefix + ".maxPixPerSpot";
if (value < 1ll)
{
success = false;
msg << currentValuePath << ": must be greater than or equal to 1;";
}
}
/* High_resolution_limit_for_spot_count_low_res */ {
const float& value = m_High_resolution_limit_for_spot_count_low_res;
const std::string currentValuePath = _pathPrefix + ".highResolutionLimitForSpotCountLowRes";
if (value < static_cast<float>(2.0))
{
success = false;
msg << currentValuePath << ": must be greater than or equal to 2.0;";
}
if (value > static_cast<float>(8.0))
{
success = false;
msg << currentValuePath << ": must be less than or equal to 8.0;";
}
}
/* Ice_ring_width_q_recipA */ {
const float& value = m_Ice_ring_width_q_recipA;
const std::string currentValuePath = _pathPrefix + ".iceRingWidthQRecipA";
if (value < static_cast<float>(0.0))
{
success = false;
msg << currentValuePath << ": must be greater than or equal to 0.0;";
}
if (value > static_cast<float>(1.0))
{
success = false;
msg << currentValuePath << ": must be less than or equal to 1.0;";
}
}
if (highResGapQRecipAIsSet())
{
const float& value = m_High_res_gap_Q_recipA;
const std::string currentValuePath = _pathPrefix + ".highResGapQRecipA";
if (value < static_cast<float>(0.1))
{
success = false;
msg << currentValuePath << ": must be greater than or equal to 0.1;";
}
if (value > static_cast<float>(5.0))
{
success = false;
msg << currentValuePath << ": must be less than or equal to 5.0;";
}
}
if (falsePixelsPerFrameIsSet())
{
const float& value = m_False_pixels_per_frame;
const std::string currentValuePath = _pathPrefix + ".falsePixelsPerFrame";
if (value < static_cast<float>(1.0))
{
success = false;
msg << currentValuePath << ": must be greater than or equal to 1.0;";
}
if (value > static_cast<float>(100000.0))
{
success = false;
msg << currentValuePath << ": must be less than or equal to 100000.0;";
}
}
return success;
}
bool Spot_finding_settings::operator==(const Spot_finding_settings& rhs) const
{
return
(isEnable() == rhs.isEnable())
&&
(isIndexing() == rhs.isIndexing())
&&
(getSignalToNoiseThreshold() == rhs.getSignalToNoiseThreshold())
&&
(getPhotonCountThreshold() == rhs.getPhotonCountThreshold())
&&
(getMinPixPerSpot() == rhs.getMinPixPerSpot())
&&
(getMaxPixPerSpot() == rhs.getMaxPixPerSpot())
&&
((!highResolutionLimitIsSet() && !rhs.highResolutionLimitIsSet()) || (highResolutionLimitIsSet() && rhs.highResolutionLimitIsSet() && getHighResolutionLimit() == rhs.getHighResolutionLimit())) &&
(getLowResolutionLimit() == rhs.getLowResolutionLimit())
&&
(getHighResolutionLimitForSpotCountLowRes() == rhs.getHighResolutionLimitForSpotCountLowRes())
&&
(isQuickIntegration() == rhs.isQuickIntegration())
&&
(getIceRingWidthQRecipA() == rhs.getIceRingWidthQRecipA())
&&
((!highResGapQRecipAIsSet() && !rhs.highResGapQRecipAIsSet()) || (highResGapQRecipAIsSet() && rhs.highResGapQRecipAIsSet() && getHighResGapQRecipA() == rhs.getHighResGapQRecipA())) &&
((!adaptiveThresholdIsSet() && !rhs.adaptiveThresholdIsSet()) || (adaptiveThresholdIsSet() && rhs.adaptiveThresholdIsSet() && isAdaptiveThreshold() == rhs.isAdaptiveThreshold())) &&
((!falsePixelsPerFrameIsSet() && !rhs.falsePixelsPerFrameIsSet()) || (falsePixelsPerFrameIsSet() && rhs.falsePixelsPerFrameIsSet() && getFalsePixelsPerFrame() == rhs.getFalsePixelsPerFrame()))
;
}
bool Spot_finding_settings::operator!=(const Spot_finding_settings& rhs) const
{
return !(*this == rhs);
}
void to_json(nlohmann::json& j, const Spot_finding_settings& o)
{
j = nlohmann::json::object();
j["enable"] = o.m_Enable;
j["indexing"] = o.m_Indexing;
j["signal_to_noise_threshold"] = o.m_Signal_to_noise_threshold;
j["photon_count_threshold"] = o.m_Photon_count_threshold;
j["min_pix_per_spot"] = o.m_Min_pix_per_spot;
j["max_pix_per_spot"] = o.m_Max_pix_per_spot;
if(o.highResolutionLimitIsSet())
j["high_resolution_limit"] = o.m_High_resolution_limit;
j["low_resolution_limit"] = o.m_Low_resolution_limit;
j["high_resolution_limit_for_spot_count_low_res"] = o.m_High_resolution_limit_for_spot_count_low_res;
j["quick_integration"] = o.m_Quick_integration;
j["ice_ring_width_q_recipA"] = o.m_Ice_ring_width_q_recipA;
if(o.highResGapQRecipAIsSet())
j["high_res_gap_Q_recipA"] = o.m_High_res_gap_Q_recipA;
if(o.adaptiveThresholdIsSet())
j["adaptive_threshold"] = o.m_Adaptive_threshold;
if(o.falsePixelsPerFrameIsSet())
j["false_pixels_per_frame"] = o.m_False_pixels_per_frame;
}
void from_json(const nlohmann::json& j, Spot_finding_settings& o)
{
j.at("enable").get_to(o.m_Enable);
j.at("indexing").get_to(o.m_Indexing);
j.at("signal_to_noise_threshold").get_to(o.m_Signal_to_noise_threshold);
j.at("photon_count_threshold").get_to(o.m_Photon_count_threshold);
j.at("min_pix_per_spot").get_to(o.m_Min_pix_per_spot);
j.at("max_pix_per_spot").get_to(o.m_Max_pix_per_spot);
if(j.find("high_resolution_limit") != j.end())
{
j.at("high_resolution_limit").get_to(o.m_High_resolution_limit);
o.m_High_resolution_limitIsSet = true;
}
j.at("low_resolution_limit").get_to(o.m_Low_resolution_limit);
j.at("high_resolution_limit_for_spot_count_low_res").get_to(o.m_High_resolution_limit_for_spot_count_low_res);
j.at("quick_integration").get_to(o.m_Quick_integration);
j.at("ice_ring_width_q_recipA").get_to(o.m_Ice_ring_width_q_recipA);
if(j.find("high_res_gap_Q_recipA") != j.end())
{
j.at("high_res_gap_Q_recipA").get_to(o.m_High_res_gap_Q_recipA);
o.m_High_res_gap_Q_recipAIsSet = true;
}
if(j.find("adaptive_threshold") != j.end())
{
j.at("adaptive_threshold").get_to(o.m_Adaptive_threshold);
o.m_Adaptive_thresholdIsSet = true;
}
if(j.find("false_pixels_per_frame") != j.end())
{
j.at("false_pixels_per_frame").get_to(o.m_False_pixels_per_frame);
o.m_False_pixels_per_frameIsSet = true;
}
}
bool Spot_finding_settings::isEnable() const
{
return m_Enable;
}
void Spot_finding_settings::setEnable(bool const value)
{
m_Enable = value;
}
bool Spot_finding_settings::isIndexing() const
{
return m_Indexing;
}
void Spot_finding_settings::setIndexing(bool const value)
{
m_Indexing = value;
}
float Spot_finding_settings::getSignalToNoiseThreshold() const
{
return m_Signal_to_noise_threshold;
}
void Spot_finding_settings::setSignalToNoiseThreshold(float const value)
{
m_Signal_to_noise_threshold = value;
}
int64_t Spot_finding_settings::getPhotonCountThreshold() const
{
return m_Photon_count_threshold;
}
void Spot_finding_settings::setPhotonCountThreshold(int64_t const value)
{
m_Photon_count_threshold = value;
}
int64_t Spot_finding_settings::getMinPixPerSpot() const
{
return m_Min_pix_per_spot;
}
void Spot_finding_settings::setMinPixPerSpot(int64_t const value)
{
m_Min_pix_per_spot = value;
}
int64_t Spot_finding_settings::getMaxPixPerSpot() const
{
return m_Max_pix_per_spot;
}
void Spot_finding_settings::setMaxPixPerSpot(int64_t const value)
{
m_Max_pix_per_spot = value;
}
float Spot_finding_settings::getHighResolutionLimit() const
{
return m_High_resolution_limit;
}
void Spot_finding_settings::setHighResolutionLimit(float const value)
{
m_High_resolution_limit = value;
m_High_resolution_limitIsSet = true;
}
bool Spot_finding_settings::highResolutionLimitIsSet() const
{
return m_High_resolution_limitIsSet;
}
void Spot_finding_settings::unsetHigh_resolution_limit()
{
m_High_resolution_limitIsSet = false;
}
float Spot_finding_settings::getLowResolutionLimit() const
{
return m_Low_resolution_limit;
}
void Spot_finding_settings::setLowResolutionLimit(float const value)
{
m_Low_resolution_limit = value;
}
float Spot_finding_settings::getHighResolutionLimitForSpotCountLowRes() const
{
return m_High_resolution_limit_for_spot_count_low_res;
}
void Spot_finding_settings::setHighResolutionLimitForSpotCountLowRes(float const value)
{
m_High_resolution_limit_for_spot_count_low_res = value;
}
bool Spot_finding_settings::isQuickIntegration() const
{
return m_Quick_integration;
}
void Spot_finding_settings::setQuickIntegration(bool const value)
{
m_Quick_integration = value;
}
float Spot_finding_settings::getIceRingWidthQRecipA() const
{
return m_Ice_ring_width_q_recipA;
}
void Spot_finding_settings::setIceRingWidthQRecipA(float const value)
{
m_Ice_ring_width_q_recipA = value;
}
float Spot_finding_settings::getHighResGapQRecipA() const
{
return m_High_res_gap_Q_recipA;
}
void Spot_finding_settings::setHighResGapQRecipA(float const value)
{
m_High_res_gap_Q_recipA = value;
m_High_res_gap_Q_recipAIsSet = true;
}
bool Spot_finding_settings::highResGapQRecipAIsSet() const
{
return m_High_res_gap_Q_recipAIsSet;
}
void Spot_finding_settings::unsetHigh_res_gap_Q_recipA()
{
m_High_res_gap_Q_recipAIsSet = false;
}
bool Spot_finding_settings::isAdaptiveThreshold() const
{
return m_Adaptive_threshold;
}
void Spot_finding_settings::setAdaptiveThreshold(bool const value)
{
m_Adaptive_threshold = value;
m_Adaptive_thresholdIsSet = true;
}
bool Spot_finding_settings::adaptiveThresholdIsSet() const
{
return m_Adaptive_thresholdIsSet;
}
void Spot_finding_settings::unsetAdaptive_threshold()
{
m_Adaptive_thresholdIsSet = false;
}
float Spot_finding_settings::getFalsePixelsPerFrame() const
{
return m_False_pixels_per_frame;
}
void Spot_finding_settings::setFalsePixelsPerFrame(float const value)
{
m_False_pixels_per_frame = value;
m_False_pixels_per_frameIsSet = true;
}
bool Spot_finding_settings::falsePixelsPerFrameIsSet() const
{
return m_False_pixels_per_frameIsSet;
}
void Spot_finding_settings::unsetFalse_pixels_per_frame()
{
m_False_pixels_per_frameIsSet = false;
}
} // namespace org::openapitools::server::model