@@ -1600,10 +1600,10 @@ def _getGratingChoices(self):
16001600
16011601 return gchoices
16021602
1603- def GetGoffset (self ):
1603+ def GetGoffset (self ) -> float :
16041604 """
16051605 Checks the current grating and flip-mirror positions.
1606- Returns the grating offset, consisting of the grating_offset + the detector offset.
1606+ Returns the grating offset, consisting of the grating_offset + the detector offset (float) .
16071607
16081608 The detector offset is the equivalent grating offset that is needed to compensate for the change in
16091609 optical path length, introduced by the flip-mirrors.
@@ -2097,21 +2097,17 @@ def _doSetFlipper(self, flipper: int, pos: int, check: bool):
20972097 logging .warning ("Failed to update turret position, detector offset might be incorrect" , exc_info = True )
20982098 self ._updatePosition ()
20992099
2100-
2101- def _doSetGoffsetAbs (self , target_offset , * , allow_grating_offset = True , single_detector_mode = False ):
2102-
2103- """
2104- Change grating offset, by either changing the grating offset or the detector offset.
2105- :param target_offset (float): the new grating offset to set
2106- :param allow_grating_offset (bool): check to allow changing the grating offset, if false, only change
2107- detector offset.
2108- :param single_detector_mode (bool): if true, it will always change the grating offset,
2109- even if the output flipper is not in the direct port position.
2100+ def _doSetGoffsetAbs (self , target_offset : float ) -> None :
21102101 """
2102+ Sets the absolute grating offset (goffset) for the current configuration.
2103+ The goffset is the sum of the grating offset for the currently selected grating and
2104+ the detector offset associated with the current flip-mirror positions.
21112105
2106+ For the first detector to be calibrated (or if there's only one available) the grating offset is adjusted for
2107+ each grating. For the other detector, only the detector offset will be adjusted.
2108+ """
21122109 target_offset = int (round (target_offset )) # ensure that we get integers for steps
21132110 grating = self .GetGrating ()
2114- port_index = self .GetFlipperMirror (OUTPUT_FLIPPER )
21152111
21162112 if "flip-in" in self .axes :
21172113 flip_in_pos = self .GetFlipperMirror (INPUT_FLIPPER )
@@ -2123,38 +2119,55 @@ def _doSetGoffsetAbs(self, target_offset, *, allow_grating_offset=True, single_d
21232119 else :
21242120 flip_out_pos = DIRECT_PORT
21252121
2126- single_detector = bool (single_detector_mode )
21272122 current_grat_offset = self .GetGratingOffset (grating )
21282123 current_det_offset = self .GetDetectorOffset (flip_in_pos , flip_out_pos )
2124+
21292125 logging .debug ("Current goffset: %d (Grat: %d, Det: %d)" ,
21302126 (current_grat_offset + current_det_offset ),
21312127 current_grat_offset , current_det_offset )
21322128
2133- # The detector offset compensates for small naccuracies introduced by the flip-mirror mechanism.
2129+ # The detector offset compensates for small inaccuracies introduced by the flip-mirror mechanism.
21342130 # This value is normally stable and seldom requires re-adjustment.
21352131
2136- if port_index == 0 or single_detector :
2137- logging .debug (
2138- "Choosing grating offset update (port_index=%s single_detector=%s)" ,
2139- port_index , single_detector
2140- )
2132+ # Get all detectors
2133+ input_ports = [DIRECT_PORT ]
2134+ if "flip-in" in self .axes :
2135+ input_ports .append (self .GetFlipperMirror (INPUT_FLIPPER ))
21412136
2142- # primary detector -> modify grating offset
2143- if not allow_grating_offset :
2144- logging .debug ("Grating offset update disabled (grating=1, target=%d)" , target_offset , )
2145- else :
2146- grating_offset = target_offset - current_det_offset
2147- self .SetGratingOffset (grating , grating_offset )
2137+ output_ports = [DIRECT_PORT ]
2138+ if "flip-out" in self .axes :
2139+ output_ports .append (self .GetFlipperMirror (OUTPUT_FLIPPER ))
2140+
2141+ all_detectors = [(i , o ) for i in input_ports for o in output_ports ]
2142+
2143+ current_detector = (flip_in_pos , flip_out_pos )
2144+ reference_detector = all_detectors [0 ]
2145+ is_multi_detector = len (all_detectors ) > 1
2146+
2147+ # Apply offsets
2148+ # For the first detector (doesn't matter to which port it's connected), the grating offset is adjusted for
2149+ # all gratings. For the second detector, only the detector offset is adjusted.
2150+
2151+ if not is_multi_detector :
2152+ logging .debug ("Single detector system -> updating grating offset" )
2153+ self .SetGratingOffset (grating , target_offset )
2154+
2155+ elif current_detector == reference_detector :
2156+ logging .debug ("Reference detector -> updating grating offset" )
2157+ self .SetGratingOffset (grating , target_offset )
21482158
2149- # secondary detector (if multiple detectors) -> modify detector offset
21502159 else :
2151- logging .debug (
2152- "Choosing detector offset update (port_index=%s single_detector=%s)" ,
2153- port_index , single_detector
2154- )
2160+ logging .debug ("Secondary detector -> updating detector offset" )
21552161 detector_offset = target_offset - current_grat_offset
21562162 self .SetDetectorOffset (flip_in_pos , flip_out_pos , detector_offset )
21572163
2164+ new_grat_offset = self .GetGratingOffset (grating )
2165+ new_det_offset = self .GetDetectorOffset (flip_in_pos , flip_out_pos )
2166+
2167+ logging .info (
2168+ "Updated offsets -> Grating: %d, Detector: %d, Combined goffset: %d" ,
2169+ new_grat_offset , new_det_offset , new_grat_offset + new_det_offset )
2170+
21582171 self ._updatePosition ()
21592172
21602173 def _doSetGoffsetRel (self , shift ):
0 commit comments