Files
Jungfraujoch/broker/gen/model/Spot_finding_settings.cpp
T
leonarski_fandClaude Opus 5 16bf3408f0 Address code-review findings; make detection limits detector-driven
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>
2026-07-27 09:07:00 +02:00

389 lines
12 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.160
* 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.02f;
m_High_res_gap_Q_recipA = 1.5f;
m_High_res_gap_Q_recipAIsSet = 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;";
}
}
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()))
;
}
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;
}
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;
}
}
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;
}
} // namespace org::openapitools::server::model