156 lines
5.0 KiB
Python
156 lines
5.0 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 = 19950 / 10
|
|
MIN_GAIN, MAX_GAIN = 0.5, 1.1
|
|
OPT_STEP = 0.01
|
|
SCAN_RANGE_FACTOR = 6.0
|
|
|
|
|
|
#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 = 200
|
|
|
|
#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)
|
|
[rms_com, rms_sigma, com, sigma, pos_path, path] = ret
|
|
|
|
|
|
#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)
|
|
|
|
#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
|
|
|
|
|
|
|
|
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.addScalar("blm1_ws_mode", ws_blm + ":WS_RUNNING", int(100.0 / get_repetition_rate()), 0)
|
|
st.initialize()
|
|
st.start()
|
|
st.waitCacheChange(10000) #Wait stream be running before starting scan
|
|
|
|
|
|
def get_gain():
|
|
return caget(ws_blm + ":WS_PMT_GAIN_VOLTS")
|
|
|
|
def set_gain(val):
|
|
caput(ws_blm + ":WS_PMT_GAIN_VOLTS", float(val))
|
|
|
|
def get_loss():
|
|
global ch
|
|
samples = []
|
|
for i in range(10):
|
|
st.waitCacheChange(-1)
|
|
val = st.getValue(ch)
|
|
samples.append(val)
|
|
return max(samples)
|
|
|
|
|
|
start_gain = get_gain()
|
|
pos = start_val = get_loss()
|
|
loss = get_loss()
|
|
target = SATURATION * 0.8
|
|
|
|
print "Start Gain = ", start_gain
|
|
print "Start Loss = ", start_val
|
|
print "Target = ", target
|
|
|
|
def set_bml_ws_gain(gain):
|
|
set_gain(gain)
|
|
stop_blm_ws(ws_blm)
|
|
start_blm_ws(ws_blm, 600.0)
|
|
st.getChild("blm1_ws_mode").waitValue(1, SET_BLM_WS_BS_READBACK_TIMEOUT)
|
|
|
|
if start_val>target:
|
|
for pos in frange(start_gain, MIN_GAIN, -OPT_STEP, True):
|
|
set_bml_ws_gain(pos)
|
|
loss = get_loss()
|
|
print "Pos = ", pos, " Loss = ", loss
|
|
if loss<=target:
|
|
break
|
|
stop_blm_ws(ws_blm)
|
|
|
|
elif start_val<target:
|
|
for pos in frange(start_gain, MAX_GAIN, OPT_STEP, True):
|
|
set_bml_ws_gain(pos)
|
|
loss = get_loss()
|
|
print "Pos = ", pos, " Loss = ", loss
|
|
if loss>=target:
|
|
break
|
|
stop_blm_ws(ws_blm)
|
|
|
|
|
|
print "Final Gain = ", pos
|
|
print "Final Loss = ", loss
|
|
print get_gain()
|
|
print get_loss()
|
|
#set_gain(0.6)
|
|
#set_gain(0.5)
|
|
|
|
st.close()
|
|
|
|
|
|
|
|
|
|
#UPDATE X1 range
|
|
#WIRE = 1X, 2X, 1Y, 2Y
|
|
def set_wire_scan_range(wire, start, end):
|
|
start = min (max(start, -2000), 2000.0)
|
|
end = min (max(end, -2000), 2000.0)
|
|
caput((ws_prefix + ":W" + wire +"_START_SP"), x_range_min)
|
|
caput((ws_prefix + ":W" + wire +"_END_SP"), x_range_max)
|
|
|
|
|
|
#caget(ws_blm+":SAT_RAW_SUM")
|
|
|
|
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)
|
|
[rms_com, rms_sigma, com, sigma, pos_path, path] = ret
|
|
|
|
|
|
|
|
|
|
x_range_min, x_range_max = com - SCAN_RANGE_FACTOR * sigma, com + SCAN_RANGE_FACTOR * sigma
|
|
set_wire_scan_range("1X", x_range_min, x_range_max)
|
|
|
|
|
|
|
|
#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() |