From 1950694ef20509e568869a6bdc8fedb8645f32e6 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 29 Oct 2025 14:57:32 +0100 Subject: [PATCH] jfjoch_viewer: Add option to refine detector settings --- viewer/JFJochImageReadingWorker.cpp | 7 +++++-- viewer/JFJochImageReadingWorker.h | 3 ++- viewer/JFJochViewerSidePanel.cpp | 26 ++++++++++++++++++++++++-- viewer/JFJochViewerSidePanel.h | 3 ++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/viewer/JFJochImageReadingWorker.cpp b/viewer/JFJochImageReadingWorker.cpp index 83ba0d7c..250da652 100644 --- a/viewer/JFJochImageReadingWorker.cpp +++ b/viewer/JFJochImageReadingWorker.cpp @@ -234,7 +234,7 @@ void JFJochImageReadingWorker::Analyze() { emit imageLoaded(current_image_ptr); } -void JFJochImageReadingWorker::FindCenter(const UnitCell& calibrant) { +void JFJochImageReadingWorker::FindCenter(const UnitCell& calibrant, bool guess) { QMutexLocker locker(&m); if (!current_image_ptr) return; @@ -242,7 +242,10 @@ void JFJochImageReadingWorker::FindCenter(const UnitCell& calibrant) { DiffractionGeometry geom = current_image_ptr->Dataset().experiment.GetDiffractionGeometry(); try { - GuessGeometry(geom, current_image_ptr->ImageData().spots, calibrant); + if (guess) + GuessGeometry(geom, current_image_ptr->ImageData().spots, calibrant); + else + OptimizeGeometry(geom, current_image_ptr->ImageData().spots, calibrant); } catch (const JFJochException &e) { logger.ErrorException(e); return; diff --git a/viewer/JFJochImageReadingWorker.h b/viewer/JFJochImageReadingWorker.h index 19269499..5aa102ed 100644 --- a/viewer/JFJochImageReadingWorker.h +++ b/viewer/JFJochImageReadingWorker.h @@ -78,7 +78,8 @@ public slots: void UpdateDataset(const DiffractionExperiment& experiment); - void FindCenter(const UnitCell& calibrant); + void FindCenter(const UnitCell& calibrant, bool guess); + void Analyze(); void UpdateSpotFindingSettings(const SpotFindingSettings &settings, const IndexingSettings &indexing, int64_t max_spots, bool reanalyze); diff --git a/viewer/JFJochViewerSidePanel.cpp b/viewer/JFJochViewerSidePanel.cpp index c87bf27f..c373fb2e 100644 --- a/viewer/JFJochViewerSidePanel.cpp +++ b/viewer/JFJochViewerSidePanel.cpp @@ -126,10 +126,14 @@ JFJochViewerSidePanel::JFJochViewerSidePanel(QWidget *parent) : QWidget(parent) layout->addWidget(calibrantCombo); updateCalibrantList(); - auto findBeamCenterButton = new QPushButton("Calibrate detector", this); + auto findBeamCenterButton = new QPushButton("Guess detector calibration", this); connect(findBeamCenterButton, &QPushButton::clicked,this, &JFJochViewerSidePanel::findBeamCenterClicked); layout->addWidget(findBeamCenterButton); + auto optimizeBeamCenterButton = new QPushButton("Refine detector calibration", this); + connect(optimizeBeamCenterButton, &QPushButton::clicked,this, &JFJochViewerSidePanel::optimizeBeamCenterClicked); + layout->addWidget(optimizeBeamCenterButton); + // Add preset ice rings button below LaB6 calibration auto iceRingsButton = new QPushButton("Display ice rings", this); connect(iceRingsButton, &QPushButton::clicked, this, [this]() { @@ -159,6 +163,24 @@ void JFJochViewerSidePanel::updateCalibrantList() { calibrantCombo->setCurrentIndex(0); } +void JFJochViewerSidePanel::optimizeBeamCenterClicked() { + UnitCell uc(LAB6_CELL_A, LAB6_CELL_A, LAB6_CELL_A, 90, 90, 90); + switch (calibrantCombo->currentIndex()) { + case 1: + // T. C. Huang , H. Toraya, T. N. Blanton, Y. Wu, J. Appl. Cryst. 26 (1993), 180-184. + uc = UnitCell(5.1769, 4.7218, 58.380, 89.440, 89.634, 75.854); + break; + case 2: + if (sample_cell) + uc = sample_cell.value(); + break; + default: + break; + } + + emit findBeamCenter(uc, false); +} + void JFJochViewerSidePanel::findBeamCenterClicked() { UnitCell uc(LAB6_CELL_A, LAB6_CELL_A, LAB6_CELL_A, 90, 90, 90); switch (calibrantCombo->currentIndex()) { @@ -174,7 +196,7 @@ void JFJochViewerSidePanel::findBeamCenterClicked() { break; } - emit findBeamCenter(uc); + emit findBeamCenter(uc, true); } void JFJochViewerSidePanel::setRings(const QVector &v) { diff --git a/viewer/JFJochViewerSidePanel.h b/viewer/JFJochViewerSidePanel.h index 2c7f8f51..ae21092e 100644 --- a/viewer/JFJochViewerSidePanel.h +++ b/viewer/JFJochViewerSidePanel.h @@ -34,7 +34,7 @@ signals: void showSaturatedPixels(bool input); void showPredictions(bool input); void highlightIceRings(bool input); - void findBeamCenter(const UnitCell &input); + void findBeamCenter(const UnitCell &input, bool guess); void analyze(); void imageLoaded(std::shared_ptr image); @@ -53,6 +53,7 @@ private slots: void setRings(const QVector &v); void findBeamCenterClicked(); + void optimizeBeamCenterClicked(); void updateCalibrantList(); };