changing energy now re-sets the transmission after changing bragg

This commit is contained in:
x10sa authored and perl_d committed 2026-10-20 16:07:54 +02:00
1 parent e98cd432ad
commit 199857fe94
1 file changed
+32 -33
+32 -33
View File
@@ -25,7 +25,7 @@ def get_current_energy():
"""
Returns the energy in eV from the current bragg angle.
"""
current_bragg_angle = dev.dcm_bragg.user_readback.get()
current_bragg_angle = dev.dcm_bragg.user_readback.get(cached=True)
current_energy = convert_from_bragg(current_bragg_angle, print_result=False)["energy_ev"]
return current_energy
@@ -88,8 +88,7 @@ def mono_pitch_scan(plot=True, window_name="Fitting", plot_widget=None):
# Set fine pitch to middle of its' travel range
scans.umv(EnergyDefaults.mono_fpitch, pos["dcm_fine_pitch"], relative=False)
# Move DCM pitch to starting value
scans.umv(EnergyDefaults.mono_pitch, pos["dcm_pitch"], relative=False)
scans.umv(EnergyDefaults.mono_pitch, pos["dcm_pitch"]-0.04, relative=False)
# Go to peak using default parameters from EnergyDefaults
if plot:
@@ -104,9 +103,9 @@ def mono_pitch_scan(plot=True, window_name="Fitting", plot_widget=None):
settle=0.01,
plot=True,
confirm=False,
min_fwhm_steps = 1.5,
min_fwhm_steps=1.1,
window_name=window_name,
plot_widget=plot_widget
plot_widget=plot_widget,
)
else:
print("Scanning monochromator pitch and moving to peak, without plotting.")
@@ -119,7 +118,7 @@ def mono_pitch_scan(plot=True, window_name="Fitting", plot_widget=None):
relative=True,
settle=0.01,
plot=False,
min_fwhm_steps = 1.5,
min_fwhm_steps=1.5,
confirm=False,
)
@@ -180,7 +179,13 @@ def get_dcm_motors_positions(energy_ev):
perp = calc_perp_position(energy_ev, print_result=False)
bragg_angle = convert_from_energy(energy_ev, print_result=False)["bragg_angle_mrad"]
dcm_motor_values.update(
{"bragg_angle": bragg_angle, "perp": perp, "dcm_pitch": pitch, "dcm_roll": roll, "dcm_fine_pitch": fpitch}
{
"bragg_angle": bragg_angle,
"perp": perp,
"dcm_pitch": pitch,
"dcm_roll": roll,
"dcm_fine_pitch": fpitch,
}
)
return dcm_motor_values
@@ -204,7 +209,7 @@ def move_dcm_motors(energy_ev):
# umv(EnergyDefaults.mono_pitch, dcm_pos["dcm_pitch"])
# umv(EnergyDefaults.mono_roll, dcm_pos["dcm_roll"])
# print("\n***DCM Roll movement is currently disabled ***\n")
scans.umv(EnergyDefaults.mono_fpitch,dcm_pos["dcm_fine_pitch"], relative=False )
scans.umv(EnergyDefaults.mono_fpitch, dcm_pos["dcm_fine_pitch"], relative=False)
scans.umv(
EnergyDefaults.energy,
dcm_pos["bragg_angle"],
@@ -218,12 +223,9 @@ def move_dcm_motors(energy_ev):
)
def bl_energy(energy_ev,
move_gap=True,
mono_scan=True,
plot=True,
window_name="Fitting",
plot_widget=None):
def bl_energy(
energy_ev, move_gap=True, mono_scan=True, plot=True, window_name="Fitting", plot_widget=None
):
"""
Adjusts the beamline's energy to the specified energy in electron volts (eV).
The function validates the target energy, checks the current energy, and makes
@@ -250,26 +252,29 @@ def bl_energy(energy_ev,
print(f"Energy change of {energy_diff:.2f} eV is too small, not changing energy.")
return
transmission = get_value(dev.transm)
# Step 1: Move the gap if needed.
move_gap_if_needed(energy_ev, move_gap)
# Step 2: Move and set the DCM motors.
move_dcm_motors(energy_ev)
# Step 3: Update the mirror stripe.
# Step 3: Reset the transmission after the energy change
print(f"Setting transmission to {transmission}")
dev.transm.put(transmission)
# Step 4: Update the mirror stripe.
set_mirror_stripe(energy_ev)
# Step 4: Perform DCM pitch scan and move to peak.
# Step 5: Perform DCM pitch scan and move to peak.
if mono_scan:
if plot:
result = mono_pitch_scan(plot=True,
window_name=window_name,
plot_widget=plot_widget)
result = mono_pitch_scan(plot=True, window_name=window_name, plot_widget=plot_widget)
return result
else:
mono_pitch_scan(plot=False)
# def new_calc_gap(energy_ev):
# """
@@ -303,6 +308,7 @@ def bl_energy(energy_ev,
# # raise ValueError(msg)
# return gap
def calc_gap(energy_ev, print_result=True):
"""Calculate the undulator gap for the given energy."""
@@ -316,13 +322,11 @@ def calc_gap(energy_ev, print_result=True):
if print_result:
harmonic = Gap.get_harmonic_by_energy(energy_ev)
print(
f"Calculated gap is {gap:.3f} mm "
f"using {harmonic}"
)
print(f"Calculated gap is {gap:.3f} mm " f"using {harmonic}")
return gap
def set_gap(energy_ev, print_result=False):
"""Set the undulator gap."""
@@ -333,16 +337,11 @@ def set_gap(energy_ev, print_result=False):
if print_result:
harmonic = Gap.get_harmonic_by_energy(energy_ev)
print(
f"Setting gap to {gap:.3f} mm "
f"using {harmonic}"
)
print(f"Setting gap to {gap:.3f} mm " f"using {harmonic}")
else:
raise ValueError(
f"Cannot calculate a valid gap for {energy_ev:.0f} eV. "
f"Calculated gap: {gap}"
)
raise ValueError(
f"Cannot calculate a valid gap for {energy_ev:.0f} eV. " f"Calculated gap: {gap}"
)
return gap