diff --git a/csaxs_bec/device_configs/bl_detectors.yaml b/csaxs_bec/device_configs/bl_detectors.yaml index 3df5103..80a159e 100644 --- a/csaxs_bec/device_configs/bl_detectors.yaml +++ b/csaxs_bec/device_configs/bl_detectors.yaml @@ -13,8 +13,8 @@ eiger_9: description: Eiger 9M detector deviceClass: csaxs_bec.devices.jungfraujoch.eiger_9m.Eiger9M deviceConfig: - detector_distance: 100 - beam_center: [0, 0] + detector_distance: 2200 + beam_center: [870, 1203] onFailure: raise enabled: True readoutPriority: async diff --git a/csaxs_bec/device_configs/bl_endstation.yaml b/csaxs_bec/device_configs/bl_endstation.yaml index d9e6534..09e644a 100644 --- a/csaxs_bec/device_configs/bl_endstation.yaml +++ b/csaxs_bec/device_configs/bl_endstation.yaml @@ -1089,47 +1089,47 @@ bim_xbox3_slowrb: -# #################### -# ### Beamstop diode control for flight tube -# ### This requires galilrioft device. On top of that the gain control device is built as well as a slow voltage readback. -# #################### +#################### +### Beamstop diode control for flight tube +### This requires galilrioft device. On top of that the gain control device is built as well as a slow voltage readback. +#################### -# galilrioesft: -# description: Galil RIO for remote gain switching and slow reading FlightTube -# deviceClass: csaxs_bec.devices.omny.galil.galil_rio.GalilRIO -# deviceConfig: -# host: galilrioesft.psi.ch -# enabled: true -# onFailure: retry -# readOnly: false -# readoutPriority: baseline -# connectionTimeout: 20 +galilrioesft: + description: Galil RIO for remote gain switching and slow reading FlightTube + deviceClass: csaxs_bec.devices.omny.galil.galil_rio.GalilRIO + deviceConfig: + host: galilrioesft.psi.ch + enabled: true + onFailure: retry + readOnly: false + readoutPriority: baseline + connectionTimeout: 20 -# gain_beamstop_diode: -# description: Gain control for beamstop flightube -# deviceClass: csaxs_bec.devices.pseudo_devices.bpm_control.BPMControl -# deviceConfig: -# gain_lsb: galilrioesft.digital_out.ch0 # Pin 10 -> Galil ch0 -# gain_mid: galilrioesft.digital_out.ch1 # Pin 11 -> Galil ch1 -# gain_msb: galilrioesft.digital_out.ch2 # Pin 12 -> Galil ch2 -# coupling: galilrioesft.digital_out.ch3 # Pin 13 -> Galil ch3 -# speed_mode: galilrioesft.digital_out.ch4 # Pin 14 -> Galil ch4 -# enabled: true -# readoutPriority: baseline -# onFailure: retry -# needs: -# - galilrioesft +gain_beamstop_diode: + description: Gain control for beamstop flightube + deviceClass: csaxs_bec.devices.pseudo_devices.bpm_control.BPMControl + deviceConfig: + gain_lsb: galilrioesft.digital_out.ch0 # Pin 10 -> Galil ch0 + gain_mid: galilrioesft.digital_out.ch1 # Pin 11 -> Galil ch1 + gain_msb: galilrioesft.digital_out.ch2 # Pin 12 -> Galil ch2 + coupling: galilrioesft.digital_out.ch3 # Pin 13 -> Galil ch3 + speed_mode: galilrioesft.digital_out.ch4 # Pin 14 -> Galil ch4 + enabled: true + readoutPriority: baseline + onFailure: retry + needs: + - galilrioesft -# beamstop_intensity: -# description: Beamstop intensity from Galil analog input ch6 -# deviceClass: csaxs_bec.devices.pseudo_devices.signal_forwarder.SignalForwarder -# deviceConfig: -# signal: galilrioesft.analog_in.ch0 -# enabled: true -# readoutPriority: baseline -# onFailure: retry -# needs: -# - galilrioesft +beamstop_intensity: + description: Beamstop intensity from Galil analog input ch6 + deviceClass: csaxs_bec.devices.pseudo_devices.signal_forwarder.SignalForwarder + deviceConfig: + signal: galilrioesft.analog_in.ch0 + enabled: true + readoutPriority: monitored + onFailure: retry + needs: + - galilrioesft diff --git a/csaxs_bec/device_configs/bl_optics_hutch.yaml b/csaxs_bec/device_configs/bl_optics_hutch.yaml index 5d0edce..14bdaf3 100644 --- a/csaxs_bec/device_configs/bl_optics_hutch.yaml +++ b/csaxs_bec/device_configs/bl_optics_hutch.yaml @@ -264,6 +264,7 @@ scinx: # bl_smar_stage to use csaxs reference method. assign number according to axis channel init_position: -23 bl_smar_stage: 2 + in_position: -12.5 poly: description: polarizer holder in OPbox @@ -328,25 +329,25 @@ polrot: # readOnly: false # softwareTrigger: false -# #################### -# ### BPM and polarization diag XBox1 (optics hutch) -# ### This requires galilrioop device. On top of that the gain control devices and slow readback devices are built. -# ### dev.galilrioop.read() shows the analog inputs -# ### another example ...analog_in.ch0.get() -# ### dev.galilrioop.read_configuration() shows the digital channels -# ### example for direct access dev.galilrioesxbox.digital_out.ch1.put(0) -# #################### +#################### +### BPM and polarization diag XBox1 (optics hutch) +### This requires galilrioop device. On top of that the gain control devices and slow readback devices are built. +### dev.galilrioop.read() shows the analog inputs +### another example ...analog_in.ch0.get() +### dev.galilrioop.read_configuration() shows the digital channels +### example for direct access dev.galilrioesxbox.digital_out.ch1.put(0) +#################### -# galilrioop: -# description: Galil RIO for remote gain switching and slow reading XBox OP -# deviceClass: csaxs_bec.devices.omny.galil.galil_rio.GalilRIO -# deviceConfig: -# host: galilrioop.psi.ch -# enabled: true -# onFailure: retry -# readOnly: false -# readoutPriority: monitored -# connectionTimeout: 20 +galilrioop: + description: Galil RIO for remote gain switching and slow reading XBox OP + deviceClass: csaxs_bec.devices.omny.galil.galil_rio.GalilRIO + deviceConfig: + host: galilrioop.psi.ch + enabled: true + onFailure: retry + readOnly: false + readoutPriority: monitored + connectionTimeout: 20 # gain_bpm_xbox1: # description: Gain control for BPM XBox1 (OP hutch) @@ -377,42 +378,42 @@ polrot: # needs: # - galilrioop -# gain_diodes_xbox1: -# description: Gain control for diodes (horizontal and vertical) XBox1 -# deviceClass: csaxs_bec.devices.pseudo_devices.bpm_control.BPMControl -# deviceConfig: -# gain_lsb: galilrioop.digital_out.ch6 # Pin 10 -> Galil ch0 -# gain_mid: galilrioop.digital_out.ch7 # Pin 11 -> Galil ch1 -# gain_msb: galilrioop.digital_out.ch8 # Pin 12 -> Galil ch2 -# coupling: galilrioop.digital_out.ch9 # Pin 13 -> Galil ch3 -# speed_mode: galilrioop.digital_out.ch10 # Pin 14 -> Galil ch4 -# enabled: true -# readoutPriority: baseline -# onFailure: retry -# needs: -# - galilrioop +gain_diodes_xbox1: + description: Gain control for diodes (horizontal and vertical) XBox1 + deviceClass: csaxs_bec.devices.pseudo_devices.bpm_control.BPMControl + deviceConfig: + gain_lsb: galilrioop.digital_out.ch6 # Pin 10 -> Galil ch0 + gain_mid: galilrioop.digital_out.ch7 # Pin 11 -> Galil ch1 + gain_msb: galilrioop.digital_out.ch8 # Pin 12 -> Galil ch2 + coupling: galilrioop.digital_out.ch9 # Pin 13 -> Galil ch3 + speed_mode: galilrioop.digital_out.ch10 # Pin 14 -> Galil ch4 + enabled: true + readoutPriority: baseline + onFailure: retry + needs: + - galilrioop -# diode_horizontal_xbox1_slowrb: -# description: Slow readback diode horizontal XBox OP (polarization diagnostics) -# deviceClass: csaxs_bec.devices.pseudo_devices.signal_forwarder.SignalForwarder -# deviceConfig: -# signal: galilrioop.analog_in.ch6 -# enabled: true -# readoutPriority: baseline -# onFailure: retry -# needs: -# - galilrioop +diode_horizontal_xbox1_slowrb: + description: Slow readback diode horizontal XBox OP (polarization diagnostics) + deviceClass: csaxs_bec.devices.pseudo_devices.signal_forwarder.SignalForwarder + deviceConfig: + signal: galilrioop.analog_in.ch6 + enabled: true + readoutPriority: monitored + onFailure: retry + needs: + - galilrioop -# diode_vertical_xbox1_slowrb: -# description: Slow readback diode vertical XBox OP (polarization diagnostics) -# deviceClass: csaxs_bec.devices.pseudo_devices.signal_forwarder.SignalForwarder -# deviceConfig: -# signal: galilrioop.analog_in.ch7 -# enabled: true -# readoutPriority: baseline -# onFailure: retry -# needs: -# - galilrioop +diode_vertical_xbox1_slowrb: + description: Slow readback diode vertical XBox OP (polarization diagnostics) + deviceClass: csaxs_bec.devices.pseudo_devices.signal_forwarder.SignalForwarder + deviceConfig: + signal: galilrioop.analog_in.ch7 + enabled: true + readoutPriority: monitored + onFailure: retry + needs: + - galilrioop sl3xi: description: "slit 2 (optics) x ring" @@ -525,3 +526,339 @@ sl3ys: deviceTags: - cSAXS - optics + +kbvbendu: + description: "KB Vertical Focusing Mirror, bender upstream" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:BNDU" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbvbendd: + description: "KB Vertical Focusing Mirror, bender downstream" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:BNDD" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbvtrx: + description: "KB Vertical Focusing Mirror, translation X" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:TRX" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbvtry: + description: "KB Vertical Focusing Mirror, translation Y" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:TRY" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbvyaw: + description: "KB Vertical Focusing Mirror, yaw" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:YAW" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbvroll: + description: "KB Vertical Focusing Mirror, roll" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:ROLL" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbvpitch: + description: "KB Vertical Focusing Mirror, pitch" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:PITCH" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbvtrxu: + description: "KB Vertical Focusing Mirror, translation X upstream" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:TRXU" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbvtrxd: + description: "KB Vertical Focusing Mirror, translation X downstream" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:TRXD" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbvtryur: + description: "KB Vertical Focusing Mirror, translation Y upstream ring" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:TRYUR" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbvtryw: + description: "KB Vertical Focusing Mirror, translation Y wall" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:TRYW" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbvtrydr: + description: "KB Vertical Focusing Mirror, translation Y downstream ring" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-VFM:TRYDR" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhbendu: + description: "KB Horizontal Focusing Mirror, bender upstream" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:BNDU" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhbendd: + description: "KB Horizontal Focusing Mirror, bender downstream" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:BNDD" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhtrx: + description: "KB Horizontal Focusing Mirror, translation X" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:TRX" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhtry: + description: "KB Horizontal Focusing Mirror, translation Y" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:TRY" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhyaw: + description: "KB Horizontal Focusing Mirror, yaw" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:YAW" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhroll: + description: "KB Horizontal Focusing Mirror, roll" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:ROLL" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhpitch: + description: "KB Horizontal Focusing Mirror, pitch" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:PITCH" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhtrxu: + description: "KB Horizontal Focusing Mirror, translation X upstream" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:TRXU" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhtrxd: + description: "KB Horizontal Focusing Mirror, translation X downstream" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:TRXD" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhtryuw: + description: "KB Horizontal Focusing Mirror, translation Y upstream wall" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:TRYUW" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhtryr: + description: "KB Horizontal Focusing Mirror, translation Y ring" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:TRYR" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics + +kbhtrydw: + description: "KB Horizontal Focusing Mirror, translation Y downstream wall" + deviceClass: ophyd_devices.EpicsMotorEC + deviceConfig: + prefix: "X12SA-OP-HFM:TRYDW" + onFailure: raise + enabled: true + readoutPriority: baseline + readOnly: false + softwareTrigger: false + deviceTags: + - cSAXS + - optics diff --git a/csaxs_bec/devices/jungfraujoch/eiger.py b/csaxs_bec/devices/jungfraujoch/eiger.py index e8d94d2..eccb857 100644 --- a/csaxs_bec/devices/jungfraujoch/eiger.py +++ b/csaxs_bec/devices/jungfraujoch/eiger.py @@ -36,6 +36,7 @@ import os import time from typing import TYPE_CHECKING, Literal +import numpy as np import yaml from bec_lib.file_utils import get_full_path from bec_lib.logger import bec_logger @@ -117,6 +118,8 @@ class Eiger(PSIDeviceBase): self._full_path = "" self._num_triggers = 0 self._wait_for_on_complete = 20 # seconds + # Initial incident energy in keV, if restarted None + self._incident_energy: float | None = None if self.device_manager is not None: self.device_manager: DeviceManagerDS self.scan_parameters: ScanServerScanInfo | None = None @@ -272,7 +275,25 @@ class Eiger(PSIDeviceBase): # TODO: Check mono energy from device in BEC # Setting incident energy in keV - incident_energy = 12.0 + + try: + incident_energy = self._get_beam_energy(self.device_manager) + if self._incident_energy is None: + self._incident_energy = round(float(incident_energy), 3) + elif not np.isclose( + self._incident_energy, incident_energy, atol=0.01 + ): # 10 keV tolerance + logger.warning( + f"Incident energy changed from {self._incident_energy} keV to {incident_energy} keV for device {self.name}. " + ) + self._incident_energy = round(float(incident_energy), 3) + except Exception as e: + logger.warning(f"Failed to set up beam energy for {self.name}: {e}") + incident_energy = 12.0 # default to 12 keV if error occurs + self._incident_energy = round(float(incident_energy), 3) + + logger.info(f"Device {self.name} uses incident energy of {self._incident_energy} keV.") + # Setting up exp_time and num_triggers acquisition parameter exp_time = self.scan_parameters.exp_time if exp_time <= self._readout_time: # Exp_time must be at least the readout time @@ -417,3 +438,20 @@ class Eiger(PSIDeviceBase): self.jfj_preview_client.stop() self.on_stop() return super().on_destroy() + + def _get_beam_energy(self, device_manager: DeviceManagerDS) -> float: + """ + Fetch the beam energy from the device manager. + + Args: + device_manager (DeviceManagerDS): The device manager to fetch the beam energy from. + + Returns: + float: The beam energy in keV. + """ + if hasattr(device_manager, "devices") and hasattr(device_manager.devices, "ccm_energy"): + energy = device_manager.devices.ccm_energy.read()[ + device_manager.devices.ccm_energy.name + ]["value"] + + return energy