109 lines
3.6 KiB
Python
109 lines
3.6 KiB
Python
import traceback
|
|
|
|
is_panel = get_exec_pars().source != CommandSource.ui #Must be checked before callin "run"
|
|
|
|
run("Devices/Elements")
|
|
run("Devices/WireScanner")
|
|
run("Diagnostics/sig_process_wrapper")
|
|
|
|
ws_prefix = args[0] if is_panel else "S10DI01-DWSC010" #"S10CB07-DWSC440" #"SINDI01-DWSC090" \\
|
|
plt = args[1] if is_panel else plot(None, title = "Wire Scan Calibration")[0]
|
|
ws_blm = get_wire_scanners_blms(ws_prefix )[0]
|
|
#S10DI01-DBLM113:AL1-WS-PMT-GAIN
|
|
|
|
SATURATION = 1000
|
|
OPT_STEP = 0.01
|
|
|
|
|
|
#2) Set the number of RF shots (N_shot) to be acquired during a single cycle WSC measurement (e.g.,N_shot=50)
|
|
n_shot = 50
|
|
|
|
#3) Set a test scanning range (e.g.,Xmin=-1000,Xmax=+1000um)
|
|
x_min, x_max = -1000.0, 1000.0
|
|
|
|
|
|
#4) For a given machine repetition-rate (RR), the scan speed is automatically set to WSC_speed=(Xmax- Xmin)*RR/N_shot
|
|
rr = get_repetition_rate()
|
|
ws_speed = (x_max- x_min)*rr/n_shot
|
|
|
|
#5) Proceed with a test scan (1 cycle) according to the above defined motor settings
|
|
args = [ ws_prefix , WireScanner.WireX1, [x_min, x_max, x_min, x_max], 1, ws_speed, [], [ws_blm], 10, plt, False,1]
|
|
ret = run("Diagnostics/WireScan", args)
|
|
|
|
|
|
#1) Select a BLM to be used in the WSC measurement and enable the WS_START so that it can be extracted out of the MPS and PMT-Gain and attenuation can be adjusted
|
|
#start_blm_ws(ws_blm, 600.0)
|
|
|
|
|
|
#6) Apply a gauss fit to the obtained WSC profile in order to determine X_CoM and standard deviation (sigma_Gauss)
|
|
[rms_com, rms_sigma, com, sigma, pos_path, path] = ret
|
|
#7) Move the wire to the X_CoM position and optimize the PMT-Gain so that the time-integral of the BLM voltage reaches a value equal to 90% of the Σsat level
|
|
|
|
offset = caget(ws_prefix + ":W1X_U0_SP")
|
|
motor_pos=offset - com * math.sqrt(2)
|
|
caput(ws_prefix+":MOTOR_1.VAL", motor_pos) #DVAL?
|
|
#LOPR:0.5 HOPR:1.1
|
|
|
|
def get_gain():
|
|
return caget(ws_blm + ":WS_PMT_GAIN_VOLTS")
|
|
|
|
def set_gain(val):
|
|
caput(ws_blm + ":WS_PMT_GAIN_VOLTS", float(val))
|
|
|
|
|
|
|
|
print "Starting stream..."
|
|
st = Stream("blm_stream", dispatcher)
|
|
ch = ws_blm + ":B1_LOSS"
|
|
st.addScalar(ch, ch, int(100.0 / get_repetition_rate()), 0)
|
|
st.initialize()
|
|
st.start()
|
|
st.waitCacheChange(10000) #Wait stream be running before starting scan
|
|
|
|
|
|
def get_loss():
|
|
return st.getValue(ch)
|
|
|
|
|
|
start_gain = get_gain()
|
|
pos = start_val = get_loss()
|
|
loss = get_loss()
|
|
target = SATURATION * 0.9
|
|
|
|
print "Start Gain = ", start_gain
|
|
print "Start Loss = ", start_val
|
|
print "Target = ", target
|
|
|
|
if start_val>target:
|
|
for pos in range(start_val, target, -OPT_STEP):
|
|
set_gain(pos)
|
|
loss = get_loss()
|
|
if loss<=target:
|
|
break
|
|
elif start_val<target:
|
|
for pos in range(start_val, target, OPT_STEP):
|
|
set_gain(pos)
|
|
loss = get_loss()
|
|
if loss()>=target:
|
|
break
|
|
|
|
print "Final Gain = ", pos
|
|
print "Final Loss = ", loss
|
|
print get_gain()
|
|
print get_loss()
|
|
#set_gain(0.6)
|
|
#set_gain(0.5)
|
|
|
|
|
|
#caget(ws_blm+":SAT_RAW_SUM")
|
|
|
|
#Att: caget(ws_blm + ":WS_PMT_ATT_VOLTS")
|
|
|
|
#8) Optimization of the scan interval: compare (Xmin, Xmax) with (X_CoM-N*sigma_Gauss , X_CoM+N*sigma_Gauss) where N is an integer value: N=5,6.
|
|
|
|
#9) Increase or decrease Xmin and/or Xmax by 10% and repeat the scan until the conditions [abs(Xmin)-abs(X_CoM- N*sigma_Gauss)]/abs(X_CoM-N*sigma_Gauss)<=0.1 and [abs(Xmax) - abs(X_CoM+N*sigma_Gauss)]/abs(X_CoM+N*sigma_Gauss) <=0.1 is reached
|
|
|
|
#10)Once condition 9) is reached, the flag: VALID_SCAN should be enabled and a WSC measurement can be performed according to the number of Cycles set in the control-panel and the optimized values of the scan interval and scan speed.
|
|
|
|
|
|
st.close() |