Files
x06da/script/rock.py
2019-03-06 11:35:18 +01:00

47 lines
1.7 KiB
Python

###################################################################################################
#
###################################################################################################
#from startup import * #Not needed: executed from local
def rock(axis = th1, tt = 0.2, seti0 = False, dx = None, noref = False):
"""
"""
#inject() #Not needed: executed from local
if axis is None:
axis = th1
if noref == False:
mono_beam_ref.write(-1.0)
e = get_energy()
if dx is None:
dx = 7.5e-2/e
# put 'Retry deadband' to 0.00004 and 'Retries Max' to 5
time.sleep(0.2)
caput(axis.channelName + '.RDBD',0.00004)
caput(axis.channelName + '.RTRY',5)
print time.strftime('%X %x')
axis_pos = axis.read()
result = lscan(axis, mono_beam, -dx, dx, 20, latency = 0.3, relative = True)
(ydata, xdata) = (result.getReadable(0), result.getPositions(0))
(norm, mean, sigma) = fit(ydata, xdata)
if (mean is not None) and (mean <= (axis_pos + dx)) and (mean >= (axis_pos - dx)):
axis.move(mean)
if seti0:
time.sleep(2)
run("setI0")
#add after_rock BPM1:SUM as reference for monitoring monochromator thermal drift
if (noref==False):
time.sleep(3) # wait a bit until mono theta finish moving
br = mono_beam.read()
mono_beam_ref.write(br)
print 'rock_success new mono beam at ' + str(br) + ' at ' + str(e) + ' keV'
return True
else:
max_x= xdata[ydata.index(max(ydata))]
print 'fit failed - centering on maximum: ' + str(max_x)
axis.move(max_x)
return False