From 6d9132964db6b3fd4f618fc52392bc41451ceb84 Mon Sep 17 00:00:00 2001
From: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
Date: Mon, 4 May 2026 11:36:10 +0200
Subject: [hermes] fix stack detector distance first point

The first point was wrong, due to a bug in the code. Now read also the
first point for a stack

diff --git a/pynx/ptycho/runner/hermes.py b/pynx/ptycho/runner/hermes.py
index 9beccdc7..baaa16c8 100644
--- a/pynx/ptycho/runner/hermes.py
+++ b/pynx/ptycho/runner/hermes.py
@@ -824,20 +824,21 @@ class PtychoRunnerScanHermesStack(PtychoRunnerScanHermesBase):
             # energy stack depending if detector distance has been moved
             # (hard way: the detector distance changes) or not (software
             # way: maxsize changes)
-            if self.scan != self.params["scan"][0]:
-                if self.params["adaptq"] == 'soft':
+
+            if self.params["adaptq"] == 'soft':
+                if self.scan != self.params["scan"][0]:
                     self.params["maxsize"] = calc_roi(self.params["maxsizeini"],
                                                       self.params["detectordistance"],
                                                       self.params["startnrj"] * 1e3,
                                                       self.params["nrj"] * 1e3)
-                elif self.params["adaptq"] == 'hard':
-                    try:
-                        self.params["detectordistance"] = \
-                            hd5_scaninfo.get(H5PATH_SSD_DISTANCE)[self.scan - 1] * 1e-6
-                    except Exception:  # TODO use the right exception
-                        print("You wanted to use hard adaptq but the updated sample-detector distances \
-                        are not found in the hdf5 descriptor file, reconstruction will continue \
-                        without any q adaptation")
+            elif self.params["adaptq"] == 'hard':
+                try:
+                    self.params["detectordistance"] = \
+                        hd5_scaninfo.get(H5PATH_SSD_DISTANCE)[self.scan - 1] * 1e-6
+                except Exception:  # TODO use the right exception
+                    print("You wanted to use hard adaptq but the updated sample-detector distances \
+                    are not found in the hdf5 descriptor file, reconstruction will continue \
+                    without any q adaptation")
 
         self.set_roi()
         self.load_data_post_process()
