90 lines
3.2 KiB
Python
90 lines
3.2 KiB
Python
# check_rock.com: a shell script to call idl routine to rock first or second crystal at X06DA
|
|
# when the flux is low
|
|
# purpose: to prevent crystal falls off the rocking curve when the temp of first crystal change.
|
|
# 20080506 meitian
|
|
# 20100621 mt & vo -> new CVD BPM in mono. check flux and ROCK, and then check vertical beam position and FBM
|
|
|
|
print "======"
|
|
print "check&rock"
|
|
print "======"
|
|
# get energy first with simple calculation (i.e. not very accurate)
|
|
THETA1 = th1.read()
|
|
THETA2 = th2.read()
|
|
ENERGY = get_energy()
|
|
if int(ENERGY) < 6:
|
|
raise Exception("No rocking optimization for lower energy for 3rd harmonics rejection")
|
|
|
|
# if theta1 and theta2 differ too much (>0.01deg), rock won't work well, sete should be used in this case
|
|
# 20130614, change threshold from 0.015 to 0.02
|
|
if abs(THETA1 + THETA2) > 0.02:
|
|
raise Exception("Two mono crystals are not synchronized, please use 'sete()'")
|
|
#
|
|
# check the flux
|
|
print "check and rock"
|
|
BPM1C1 = caget("X06DA-OP-BPM1:CHAN1", 'd')
|
|
BPM1C2 = caget("X06DA-OP-BPM1:CHAN2", 'd')
|
|
BPM1C3 = caget("X06DA-OP-BPM1:CHAN3", 'd')
|
|
BPM1C4 = caget("X06DA-OP-BPM1:CHAN4", 'd')
|
|
BPM1 = (BPM1C1 + BPM1C2 + BPM1C3 + BPM1C4) / 4
|
|
print "OP-BPM1 average = ", BPM1
|
|
# if the BPM1 reading is too low, means no beam, do not rock, and quit
|
|
# without beam, BPM1 and 2 readings are about 1.2-1.2 nA
|
|
if BPM1 <= 2:
|
|
raise Exception("Flux is too low, either no beam or FE shutter is not open.")
|
|
|
|
print "Current energy is ", ENERGY, ", mono theta2 is ", THETA2, "."
|
|
# 20080507 number for BPM1
|
|
# keV 7 8 9 10 11 12 13 14 15 16 17
|
|
# BPM1 with room light: 150 140 120 110 100 90 80 80 70 50 40
|
|
# BPM1 w/o room light: 134 123 111 95 81 70 61 54 47 40 20
|
|
# new CVD BPM 20100621
|
|
# 6 7 8 9 10 11 12.4 13 14 15 16 17
|
|
# 51 65 63 57 53 48 40 37 33 27 18 6
|
|
|
|
# get correct threshold for different energy
|
|
BPM1_limit = ["41", "52", "50", "44," "42", "39", "32", "30", "26", "21", "14", "4"]
|
|
i = 0
|
|
for i in range(12):
|
|
n = i + 6
|
|
if n == int(ENERGY):
|
|
print int(ENERGY), n, i, BPM1_limit[i] #TODO: There was bug indexing here?
|
|
BPM1_lowLimit = BPM1_limit[i]
|
|
|
|
|
|
# if flux is low, rock
|
|
if BPM1 <= BPM1_lowLimit:
|
|
print "BPM1 reading is lower than ", BPM1_lowLimit
|
|
print "lets rock."
|
|
rock()
|
|
time.sleep(2)
|
|
else :
|
|
print "BPM1 reading is higher than ", BPM1_lowLimit
|
|
print "nothing to do, quit."
|
|
print " "
|
|
#TODO: Should abort?
|
|
|
|
|
|
#==========================================================
|
|
print "======"
|
|
print "check and fbm"
|
|
# check the X06DA-ES-BPM1:POSV
|
|
|
|
if ( eh_shutter.read() == "NOT_OPEN" ):
|
|
raise Exception("ExpHutchShutter closed - program will exit")
|
|
|
|
BPM1POSV = es_beam_posv.read()
|
|
print "Vertical beam postion at ES-BPM1: ", BPM1POSV
|
|
# to get an integer (microns), 0.005 * 1000 / 1 with bc will do it.
|
|
POSV = int(BPM1POSV * 1000)
|
|
# if the POSV reading is not within +/- 8 microns means beam position is drifted, do FBM
|
|
|
|
# if flux is low, rock
|
|
if POSV <= -6 or POSV >= 6 :
|
|
print "Beam is not aligned at E-BOX BPM1"
|
|
print "lets fix it."
|
|
fbm()
|
|
time.sleep(2)
|
|
else :
|
|
print "Beam is aligned at E-BOX BPM1,"
|
|
print "nothing to do, quit."
|
|
print " " |