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