Files
x06da/script/sete.py
2016-04-15 15:24:36 +02:00

83 lines
2.2 KiB
Python

def error(msg):
caput(beam_err, (msg[:40]) if len(msg) > 40 else msg)
raise Exception (msg)
#def sete(e, all=True, wavelengt=False):
beam_err = BEAMLINE_XNAME + '-ES-DAQ:BEAM-ERROR'
beam_set = BEAMLINE_XNAME + '-ES-DAQ:BEAM-SET'
ring_current_cutoff = 300.0
if wavelength:
e = 12.39842/e
if e < 4.7 or e > 17.5:
error('ERROR:Energy out of range: 4.7 to 17.5 keV')
print time.strftime('%X %x')
print '... Setting energy to '+ str(e) +' keV.'
msg = 'Working... (aiming @ '+ str(e) +' keV)'
caput(beam_err, (msg[:40]) if len(msg) > 40 else msg)
if caget('ALIRF-GUN:CUR-LOWLIM', 'd') < ring_current_cutoff:
error('ERROR:Current is too low: < ' + str(ring_current_cutoff) + 'mA')
if fe_absorber.read()!= 'OPEN':
raise Exception ('FrontEndAbsorber closed') # FrontEnd absorber shutter state
if fe_shutter.read() != "OPEN":
raise Exception ('FrontendShutter closed')
e0 = get_energy(False);
dE = abs(e-e0)
print '... started to move monochromator motors'
print '... alignment will take some minutes '
act = 0
# do a setenergy to move theta 1 and 2 to calculated position in case they are not synchronized.
theta1 = th1.read() #TODO: setpoint?
etheta1 = a2e(abs(theta1),1,1,1,deg=True,ln=True)
theta2 = th2.read()
etheta2 = a2e(abs(theta2),1,1,1,deg=True,ln=False)
if abs (etheta1-etheta2) > 0.01:
set_energy(e)
while abs(e-e0) > 3e-5/math.tan(angle(e, deg=False)): #TODO: deg==false? WHILE ABS(e-e0) GT 3e-5/TAN(ANGLE(e)) DO BEGIN
set_energy(e)
e0 = get_energy(False)
#----- correcting theta2 if intensity is low or if the encoder -----
#----- differs by more than rocking curve width from theory --------
# -------- for sete, /all, remove all filters
if all:
filter1.write("None")
filter2.write("None")
filter3.write("None")
filter4.write("None")
time.sleep(0.5)
#-------- rock FIRST crystal until its peak is reached -------------
while rock(th1)==False: #TODO: #ROCK,1,dt = (dE>1.)*4e-2/e,ffail=ff
pass
# finer final rock
time.sleep(1.0)
print 'FINER FINAL ROCK'
rock()
e0 = get_energy()
print e0
mono_energy.write(e0)
print mono_energy.read()
caput(beam_err, 'Finito')
caput(beam_set, 'DONE')
print 'sete_done'