diff --git a/src/extra_redu/base/litfrm.py b/src/extra_redu/base/litfrm.py index 38eec9f195e81c650e417cc473d10a4f632c3525..4f1fc64cce68ac80b81f8925b8a1b28d03cfdf93 100644 --- a/src/extra_redu/base/litfrm.py +++ b/src/extra_redu/base/litfrm.py @@ -169,10 +169,9 @@ class AgipdLitFrameFinderBase: f"{self.ref.repetitionRate:.1f}"] * TICS_PER_PULSE shift = (self.ref.delay + self.ref.frame * frame_timestep - self.trigger_delay) - if self.motor_position is not None: - unit_coef = self.motor.unitConversionCoef.value - shift -= (unit_coef * (self.ref.position - - self.motor_position) / SPEED_OF_LIGHT) + if self.actual_position is not None: + shift -= (self.ref.position * .001 - + self.actual_position) / SPEED_OF_LIGHT shift = round(shift / TICS_PER_PULSE) ref_pulse = EVENT_PULSE[ diff --git a/src/extra_redu/litfrm/agipd_offline.py b/src/extra_redu/litfrm/agipd_offline.py index 1b4b437719c9ce0142141869eb94cdb227a5e435..19b66b164487718433a9182774ceecb4ddfce835 100644 --- a/src/extra_redu/litfrm/agipd_offline.py +++ b/src/extra_redu/litfrm/agipd_offline.py @@ -150,6 +150,8 @@ Motor = namedtuple('Motor', ['deviceId', 'positionProperty', class AgipdLitFrameFinderOffline(AgipdLitFrameFinderBase): + useDistanceDelay = AVal(False) + def __init__(self, dev_id, dc, ref_delays={}, align_method=None, **kwargs): self.dev_id = dev_id self.dc = dc @@ -187,6 +189,7 @@ class AgipdLitFrameFinderOffline(AgipdLitFrameFinderBase): self._agipd = agipd_class(self._detector, self) self.shutters_are_open = True + self.actual_position = None def _configure_v03(self, dc, dev_id): litfrm = ExtraDataProxy(dc, dev_id) @@ -230,6 +233,12 @@ class AgipdLitFrameFinderOffline(AgipdLitFrameFinderBase): ])) if ref.delay != -1: self._reference[event_code] = ref + try: + self.useDistanceDelay = litfrm.useDistanceDelay + self.detectorDistance = litfrm.detectorDistance + except AttributeError: + self.useDistanceDelay = AVal(True) + self.detectorDistance = AVal(0.0) def _read_run_values(self, dc): if self.alignMethod.value == "by reference delay": @@ -252,13 +261,16 @@ class AgipdLitFrameFinderOffline(AgipdLitFrameFinderBase): raise(NoReferenceDelay("Reference delay for marco event " f"{self.trigger_event} is not set.")) - try: - _motor = ExtraDataProxy(dc, self.motor.deviceId, - data_selector_id=self.data_selector_id) - key = self.motor.positionProperty.value - self.motor_position = _motor.get_value(key) - except SourceNotFound: - self.motor_position = None + if self.useDistanceDelay: + self.actual_position = self.detectorDistance.value * .001 + try: + _motor = ExtraDataProxy(dc, self.motor.deviceId, + data_selector_id=self.data_selector_id) + key = self.motor.positionProperty.value + unit_coef = self.motor.unitConversionCoef.value + self.actual_position += unit_coef * _motor.get_value(key) + except SourceNotFound: + pass def _read_pp_decoder(self, dc): pp_src = dc[self.pp_decoder_id] @@ -494,7 +506,7 @@ class AgipdLitFrameFinderMID(AgipdLitFrameFinderConfigureMID, class AgipdLitFrameFinderConfigureSPB: dev_id = 'SPB_IRU_AGIPD1M1/REDU/LITFRM' - data_selector_id = None + data_selector_id = 'SPB_IRU_AGIPD1M1/MDL/DATA_SELECTOR' detector_control_id = 'SPB_IRU_AGIPD1M1/MDL/FPGA_COMP' bunch_pattern_id = 'SPB_RR_SYS/TSYS/X2TIMER2:outputBunchPattern' @@ -506,9 +518,9 @@ class AgipdLitFrameFinderConfigureSPB: name=AVal("backTrg3") ) motor = Motor( - deviceId="", - positionProperty=AVal(""), - unitConversionCoef=AVal(1), + deviceId="SPB_IRU_AGIPD1M/MOTOR/Z_STEPPER", + positionProperty=AVal("encoderPosition"), + unitConversionCoef=AVal(1e-3), ) alignMethod = AVal('by first pulse') referenceFrame = AVal(1) diff --git a/src/extra_redu/litfrm/test/test_litfrm_agipd.py b/src/extra_redu/litfrm/test/test_litfrm_agipd.py index 71a3ea83a9b57be2776a760afbefd7efb5ff0bc4..54a76cee3cab80e35fee9d8d6c9e8291a3475036 100644 --- a/src/extra_redu/litfrm/test/test_litfrm_agipd.py +++ b/src/extra_redu/litfrm/test/test_litfrm_agipd.py @@ -250,7 +250,7 @@ def test_agipdlitframefinder_offline_alignment_by_reference_delay(): assert dev.trigger_delay == 6381900 assert dev.trigger_event == 181 - assert dev.motor_position == 132820.05 + assert dev.actual_position == pytest.approx(132.82005, 1e-5) tid_orig = fast[dev.bunch_pattern_id]['data.bunchPatternTable']['tid']