This commit is contained in:
gobbo_a
2025-01-14 16:18:27 +01:00
parent 8beeb7dbc7
commit 7a0da7c48c
80 changed files with 1698 additions and 590 deletions
+25 -10
View File
@@ -6,24 +6,39 @@ else:
tds = "S30CB14"
run("Tools/BunchLengthTDSdata.py")
# stop the beam
caput("SIN-TIMAST-TMA:Beam-RF-OnDelay-Sel", 1)
caput("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
caput("SIN-TIMAST-TMA:Bunch-1-Freq-Sel", 10)
caput("SIN-TIMAST-TMA:Bunch-2-Freq-Sel", 10)
# stop the beam and set rates to 1 Hz
if tds == "SATMA02":
caput("SIN-TIMAST-TMA:Bunch-2-OnDelay-Sel", 1)
caput("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
caput("SIN-TIMAST-TMA:Bunch-2-Freq-Sel", 6)
else :
caput("SIN-TIMAST-TMA:Beam-RF-OnDelay-Sel", 1)
caput("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
caput("SIN-TIMAST-TMA:Bunch-1-Freq-Sel", 10)
caput("SIN-TIMAST-TMA:Bunch-2-Freq-Sel", 10)
# beam stopper and coll.
# set mode and coll.
gap_init = []
if tds == "SINDI01":
caput("S10CB01-RSYS:REQUIRED-OP", 0)
caput("S10CB02-RSYS:REQUIRED-OP", 0)
caput("S10DI01-MBND100:P-SET", 297.0)
time.sleep(10.0)
if tds == "S30CB14":
caput("SARMA02-MBNP100:REQUEST", 1)
#caput("SARCL01-DCOL030:GAP", 5.0)
caput("SARCL02-VCOL290:GAP", 8.0)
gap_init.append(caget("SARCL02-VCOL290:GAP"))
caputq("SARCL02-VCOL290:GAP", 8.0)
# switch BLMs off
blm = tds_data[tds]["BLM"]
for i in range(len(blm)):
caput(blm[i] + ":B1_ROI_ACTIVE_OP", 0)
caput(blm[i] + ":B2_ROI_ACTIVE_OP", 0)
# set optics
quads = tds_data[tds]["quads"]
k1l = tds_data[tds]["K1L-meas"]
k1l_meas = tds_data[tds]["K1L-meas"]
i_set_init = []
for i in range(len(quads)):
caput(quads[i] + ":K1L-SET", k1l[i])
i_set_init.append(caget(quads[i] + ":I-SET"))
caput(quads[i] + ":K1L-SET", k1l_meas[i])
+16 -11
View File
@@ -6,21 +6,26 @@ else:
tds = "S30CB14"
run("Tools/BunchLengthTDSdata.py")
# stop the beam
caput("SIN-TIMAST-TMA:Beam-RF-OnDelay-Sel", 1)
caput("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
caput("SIN-TIMAST-TMA:Bunch-1-Freq-Sel", 10)
caput("SIN-TIMAST-TMA:Bunch-2-Freq-Sel", 10)
# stop the beam and set rates to 1 Hz
if tds == "SATMA02":
caput("SIN-TIMAST-TMA:Bunch-2-OnDelay-Sel", 1)
caput("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
else :
caput("SIN-TIMAST-TMA:Beam-RF-OnDelay-Sel", 1)
caput("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
# beam stopper and coll.
# collimators
if tds == "S30CB14":
#caput("SARCL01-DCOL030:GAP", 5.0)
caput("SARCL02-VCOL290:GAP", 5.0)
caputq("SARCL02-VCOL290:GAP", gap_init[0])
# restore nominal optics
quads = tds_data[tds]["quads"]
k1l = tds_data[tds]["K1L-nom"]
for i in range(len(quads)):
caput(quads[i] + ":K1L-SET", k1l[i])
caput(quads[i] + ":I-SET", i_set_init[i])
caput(quads[i] + ":CYCLE", 2)
# show message: restore optics and coll.
#switch BLMs on
blm = tds_data[tds]["BLM"]
for i in range(len(blm)):
caput(blm[i] + ":B1_ROI_ACTIVE_OP", 1)
caput(blm[i] + ":B2_ROI_ACTIVE_OP", 1)
+71 -77
View File
@@ -6,6 +6,7 @@ dry_run = False
do_elog = True
USE_SCREEN_PANEL = True
MO_FREQ = 142.8e6 # MO = 142.8 MHz
FW_THRESHOLD = 0.20
is_panel = get_exec_pars().source != CommandSource.ui # run from panel
if is_panel:
start = args[0]
@@ -16,19 +17,25 @@ if is_panel:
thr = args[5]
tds = args[6]
bunch = args[7]
plt11 = args[8]
plt12 = args[9]
plt21 = args[10]
plt22 = args[11]
screen = args[8]
user_calib_enabled = args[9]
user_calib = args[10]
plt11 = args[11]
plt12 = args[12]
plt21 = args[13]
plt22 = args[14]
else:
start = -0.1
stop = 0.1 + 0.001
step = 0.05
nb = 5
lat = 2.0
thr = 250
tds = "S30CB14"
bunch = "Bunch1"
nb = 10
lat = 0.4
thr = 20
tds = "SATMA02"
bunch = "Bunch2"
screen = "SATBD01-DSCR120"
user_calib_enabled = False
user_calib = 1.0
plt11 = plot(None, title="Output")[0]
plt12 = plot(None, title="Output")[0]
plt21 = plot(None, title="Output")[0]
@@ -81,12 +88,11 @@ init_plots(plt12, plt22)
#Creating Phase positioner
if dry_run:
phase = DummyPositioner("TDS Phase")
camera_name = "simulation"
else:
phase = Positioner("TDS Phase", tds + "-RSYS:SET-BEAM-PHASE", tds + "-RSYS:SET-BEAM-PHASE")
camera_name = tds_data[tds]["screen"]
camera_name = screen
phase.config.minValue = -90.0
phase.config.maxValue = 270.0
phase.config.maxValue = 360.0
phase.config.precision = 4
phase.config.resolution = 0.05
phase.config.rotation = True
@@ -95,65 +101,57 @@ phase.initialize()
phase0 = phase.read() % 360
#Camera setup
if USE_SCREEN_PANEL:
cam_server.start(camera_name+"_sp1", True) # shared pipeline
else:
cam_server.start(camera_name) # generic pipeline
cam_server.setFunction("beam_full_width")
cam_server.setInstanceConfigValue("fw_threshold", 0.3)
cam_server.start(camera_name +"_sp", USE_SCREEN_PANEL)
cam_server.setFunction("bunch_length_op")
cam_server.setInstanceConfigValue("replace", True)
cam_server.setInstanceConfigValue("fw_threshold", FW_THRESHOLD)
cam_server.setThreshold(thr)
cam_server.setBackgroundSubtraction(False)
cam_server.setGoodRegion(0.1, 3.0)
print "Waiting for y_fw and y_fit"
cam_server.setGoodRegion(0.05, 5.0)
print "Waiting for fw and fit"
xy = tds_data[tds]["DEFAULTS"]["plane"]
timeout = 1.0
start_time = time.time()
while (True):
wait_cam_server_message()
y_fw = cam_server.stream.getChild("y_fw")
y_fit = cam_server.stream.getChild("gr_y_fit_standard_deviation")
if (y_fw is not None) and (y_fit is not None):
fw = cam_server.stream.getChild(xy + "_fw")
gr_fit = cam_server.stream.getChild("gr_" + xy + "_fit_standard_deviation")
if (fw is not None) and (gr_fit is not None):
break
if time.time() - start_time > timeout:
if y_fw is None:
raise Exception("y_fw not in camera stream")
if y_fit is None:
raise Exception("y_fit not in camera stream")
y_center_of_mass = cam_server.stream.getChild("y_center_of_mass")
y_rms = cam_server.stream.getChild("y_rms")
y_profile = cam_server.stream.getChild("y_profile")
y_axis = cam_server.stream.getChild("y_axis")
if fw is None:
raise Exception(xy + "_fw not in camera stream")
if gr_fit is None:
raise Exception(xy + "_fit not in camera stream")
com = cam_server.stream.getChild(xy + "_center_of_mass")
rms = cam_server.stream.getChild(xy + "_rms")
profile = cam_server.stream.getChild(xy + "_profile")
axis = cam_server.stream.getChild(xy + "_axis")
image = cam_server.getDataMatrix()
set_device_alias(image, "image")
#Creating averagers
com_averager = create_averager(y_center_of_mass, nb, -1) # -1 event based, waits for the next value
rms_averager = create_averager(y_rms, nb, -1)
fw_averager = create_averager(y_fw, nb, -1)
fit_averager = create_averager(y_fit, nb, -1)
com_averager = create_averager(com, nb, -1) # -1 event based, waits for the next value
rms_averager = create_averager(rms, nb, -1)
fw_averager = create_averager(fw, nb, -1)
fit_averager = create_averager(gr_fit, nb, -1)
rms_averager.monitored = True # not blocking, will return last nb values
fw_averager.monitored = True
fit_averager.monitored = True
#switch BLMs off
blm = tds_data[tds]["BLM"]
strg = ":B1_ROI_ACTIVE_OP" if bunch == "Bunch1" else ":B2_ROI_ACTIVE_OP"
for i in range(len(blm)):
if dry_run:
print(blm[i] + strg, 0)
else:
caput(blm[i] + strg, 0)
#The scan loop
try:
bunch1_charge = caget("SINEG01-DBPM340:Q1")
bunch2_charge = caget("SINEG01-DBPM340:Q2")
bunch_charge = bunch1_charge if bunch == "Bunch1" else bunch2_charge
sensor_list = [com_averager, rms_averager, fw_averager, fit_averager, y_axis, y_profile, y_center_of_mass]
sensor_list = [com_averager, rms_averager, fw_averager, fit_averager, axis, profile, com, image]
phase.write(start)
time.sleep(1.0)
time.sleep(3.0)
# get bs phase-jitter / screen position data for SATMA02 calib
r1 = lscan(phase, sensor_list, start, stop, step , latency=lat, after_read = update_plot_1)
start, stop = start + 180.0, stop + 180.0
phase.write(start)
time.sleep(10.0)
time.sleep(3.0)
r2 = lscan(phase, sensor_list, start, stop, step , latency=lat, after_read = update_plot_2)
finally:
phase.write(phase0)
@@ -161,20 +159,13 @@ finally:
cam_server.stop() # stops cam_server but does not close it cam_server is a global object
# stop the beam
if dry_run:
print("SIN-TIMAST-TMA:Beam-RF-OnDelay-Sel", 1)
print("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
else:
caput("SIN-TIMAST-TMA:Beam-RF-OnDelay-Sel", 1)
caput("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
#switch BLMs on
for i in range(len(blm)):
if dry_run:
print(blm[i] + strg, 1)
if not dry_run:
if bunch == "Bunch1":
caput("SIN-TIMAST-TMA:Bunch-1-OnDelay-Sel", 1)
else:
caput(blm[i] + strg, 1)
caput("SIN-TIMAST-TMA:Bunch-2-OnDelay-Sel", 1)
caput("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1)
#output
def write_output(r, plt):
phase_pos = r.getPositions(0)
@@ -184,21 +175,23 @@ def write_output(r, plt):
bunch_center_stdev = [val.stdev for val in r.getReadable(0)]
a0, a1 = fit_polynomial(time_pos, bunch_center, 1)
calib = abs(a1) # in fs/um
#calib = 1
if user_calib_enabled:
calib = rf_period * 1e15 / 360 / user_calib / 1000 # in fs/um
if dry_run: calib = 1
bunch_length_rms = [val.mean * calib for val in r.getReadable(1)]
bunch_length_rms_average = sum(bunch_length_rms) / len(bunch_length_rms)
bunch_length_fw = [val.mean * calib for val in r.getReadable(2)]
bunch_length_fw_average = sum(bunch_length_fw) / len(bunch_length_fw)
bunch_length_fit = [val.mean * calib for val in r.getReadable(3)]
bunch_length_fit_average = sum(bunch_length_fit) / len(bunch_length_fit)
profiles_um = r[y_axis]
profiles_dig = r[y_profile]
profiles_com = r[y_center_of_mass]
com = sum(profiles_com) / len(profiles_com)
profiles_um = r[axis]
profiles_dig = r[profile]
profiles_com = r[com]
com_avg = sum(profiles_com) / len(profiles_com)
profiles_fs = []
profiles_kA = []
for i in range(len(r[y_axis])):
delta_um = profiles_com[i] - com
for i in range(len(r[axis])):
delta_um = profiles_com[i] - com_avg
profiles_fs.append([(val - delta_um) * calib for val in profiles_um[i]])
step_fs = (max(profiles_fs[i]) - min(profiles_fs[i])) / (len(profiles_fs[i]) - 1)
total_dig = float(sum(profiles_dig[i]))
@@ -216,12 +209,13 @@ bunch_length_fit = (bunch_length_fit_average1 + bunch_length_fit_average2) / 2
calib = (calib1 + calib2) / 2
#archiver channels
if bunch == "Bunch1":
caput(tds + "-RTDS100:BD-BUNCH1-DURATION", bunch_length_fw)
caput(tds + "-RTDS100:BD-BUNCH1-CALIBRATION", 1 / calib)
else:
caput(tds + "-RTDS100:BD-BUNCH2-DURATION", bunch_length_fw)
caput(tds + "-RTDS100:BD-BUNCH2-CALIBRATION", 1 / calib)
if do_elog:
if bunch == "Bunch1":
caput(tds + "-RTDS100:BD-BUNCH1-DURATION", bunch_length_rms)
caput(tds + "-RTDS100:BD-BUNCH1-CALIBRATION", 1 / calib)
else:
caput(tds + "-RTDS100:BD-BUNCH2-DURATION", bunch_length_rms)
caput(tds + "-RTDS100:BD-BUNCH2-CALIBRATION", 1 / calib)
#Elog entry
if do_elog:
@@ -247,13 +241,13 @@ if do_elog:
log_msg = log_msg + "Calibration: %0.4f" % calib + " fs/um"
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
file_name1 = os.path.abspath(get_context().setup.getContextPath() + "/BunchLengthScanPlot1.png")
plt11.saveSnapshot(file_name1, "png")
plt11.saveSnapshot(file_name1, "png", Dimension(400, 300))
file_name2 = os.path.abspath(get_context().setup.getContextPath() + "/BunchLengthCurrent1.png")
plt21.saveSnapshot(file_name2, "png")
plt21.saveSnapshot(file_name2, "png", Dimension(400, 300))
file_name3 = os.path.abspath(get_context().setup.getContextPath() + "/BunchLengthScanPlot2.png")
plt12.saveSnapshot(file_name3, "png")
plt12.saveSnapshot(file_name3, "png", Dimension(400, 300))
file_name4 = os.path.abspath(get_context().setup.getContextPath() + "/BunchLengthCurrent2.png")
plt22.saveSnapshot(file_name4, "png")
plt22.saveSnapshot(file_name4, "png", Dimension(400, 300))
elog(title, log_msg, [file_name1, file_name2, file_name3, file_name4])
set_return([bunch_length_rms_average1, bunch_length_fw_average1, bunch_length_fit_average1, calib1,
+19 -24
View File
@@ -1,47 +1,42 @@
#tds config
tds_data = {'SINDI01': {"harm": 21, "screen": "SINDI02-DSCR075",
tds_data = {"SINDI01": {"harm": 21,
"quads":
["SINDI02-MQUA020", "SINDI02-MQUA030", "SINDI02-MQUA050",
"SINDI02-MQUA060"],
"K1L-nom":
[-0.020000, 0.050000, -0.165000,
0.200000],
"K1L-meas":
[-0.389776, 0.324016, 0.067305,
0.174710],
"BLM": []},
'S30CB14': {"harm": 40, "screen": "SARCL01-DSCR170",
[-0.391000, 0.325000, 0.067500,
0.175300],
"BLM": [],
"DEFAULTS" : {"Start": -2.0, "Stop": 2.0, "Step": 2.0, "Nb": 10, "Lat": 2.0,
"Thr": 25, "Scr": "SINDI02-DSCR075", "plane": "y"}},
"S30CB14": {"harm": 40,
"quads":
["S30CB10-MQUA430", "S30CB11-MQUA430", "S30CB12-MQUA430",
"S30CB13-MQUA430", "S30CB14-MQUA430", "S30CB15-MQUA430",
"SARCL01-MQUA020", "SARCL01-MQUA050", "SARCL01-MQUA080",
"SARCL01-MQUA100", "SARCL01-MQUA140", "SARCL01-MQUA190"],
"K1L-nom":
[-0.125000, 0.125000, -0.125000,
0.125000, -0.125000, 0.125000,
-0.070000, 0.010000, -0.145000,
0.155000, 0.415000, -0.490000],
"K1L-meas":
[-0.102751, -0.014919, 0.112685,
-0.064000, -0.053854, 0.048777,
0.104904, -0.039548, -0.005735,
0.005119, -0.027870, -0.011176],
"BLM":
["SARCL02-DBLM135", "SARCL02-DBLM355", "SARUN01-DBLM065",
["S30CB14-DBLM445",
"SARCL02-DBLM050", "SARCL02-DBLM355", "SARUN01-DBLM065",
"SARUN03-DBLM030", "SARUN04-DBLM030", "SARUN05-DBLM030",
"SARUN06-DBLM030", "SARUN07-DBLM030", "SARUN08-DBLM030",
"SARUN09-DBLM030", "SARUN10-DBLM030", "SARUN11-DBLM030",
"SARUN12-DBLM030", "SARUN13-DBLM030", "SARUN14-DBLM030",
"SARUN15-DBLM030", "SARUN15-DBLM035", "SARUN20-DBLM035"]},
'SATMA02': {"harm": 84, "screen": "SATBD01-DSCR120",
"SARUN15-DBLM030", "SARUN15-DBLM035", "SARUN20-DBLM035"],
"DEFAULTS" : {"Start": -0.15, "Stop": 0.15, "Step": 0.15, "Nb": 10, "Lat": 2.0,
"Thr": 200, "Scr": "SARCL01-DSCR170", "plane": "y"}},
"SATMA02": {"harm": 84,
"quads":
["SATBD01-MQUA010", "SATBD01-MQUA030", "SATBD01-MQUA050",
"SATBD01-MQUA070", "SATBD01-MQUA090"],
"K1L-nom":
[ 0.150000, -0.185000, 0.040000,
0.140000, -0.225000],
"SATBD01-MQUA070", "SATBD01-MQUA090", "SATBD02-MQUA030"],
"K1L-meas":
[-0.090111, 0.108271, 0.025250,
-0.072006, -0.382500],
"BLM": []}}
[ 0.152300, -0.185800, 0.039800,
0.142400, -0.223600, -0.315600],
"BLM": ["SATBD01-DBLM205", "SATUN22-DBLM005"],
"DEFAULTS" : {"Start": -0.2, "Stop": 0.2, "Step": 0.2, "Nb": 10, "Lat": 2.0,
"Thr": 300, "Scr": "SATBD02-DSCR050", "plane": "x"}}}
+2 -2
View File
@@ -42,7 +42,7 @@ def start_camera_correlation(dispatcer_channel, camera_channel, samples=50, modu
_dispatcher_stream.setBufferCapacity(500)
camera_name, camera_channel = camera_channel.split(" ")
shared = camera_name.endswith("_sp1")
shared = camera_name.endswith("_sp")
cam_server.start(camera_name, shared )
camera_stream = cam_server.stream
camera_stream.setBufferCapacity(500)
@@ -112,7 +112,7 @@ def stop_camera_correlation():
#Testing
start_camera_correlation("SINEG01-DICT215:B1_CHARGE", "SATES31-CAMS187-RIXS1_sp1 intensity", samples = 40, plt=plot(None)[0])
start_camera_correlation("SINEG01-DICT215:B1_CHARGE", "SATES31-CAMS187-RIXS1_sp intensity", samples = 40, plt=plot(None)[0])
try:
time.sleep(10.0)
finally:
+1 -1
View File
@@ -11,5 +11,5 @@ else:
phase_rf = caget(tds + "-RSYS:GET-VSUM-PHASE")
phase_corr = caget(tds + "-RSYS:GET-VSUM-PHASE-OFFSET-CORR")
phase_offset = phase - phase_rf - phase_corr
print(tds + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phase_offset)
caput(tds + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phase_offset)
caput(tds + "-RSYS:SET-BEAM-PHASE", phase)
Executable → Regular
+1 -1
View File
@@ -40,7 +40,7 @@ else:
_server = cam_server
try:
_server.start(camera_name + "_sp1" if shared else camera_name, shared)
_server.start(camera_name + "_sp", shared)
if roi is not None and len(roi.strip())>0:
roi = json.loads(roi)
Executable → Regular
+1 -5
View File
@@ -18,11 +18,7 @@ set_exec_pars(name="camera_snapshot")
path = "/image"
snapshotFile = None
if shared:
cam_server.start(camera_name + "_sp1", shared)
else:
cam_server.start(camera_name)
cam_server.start(camera_name + "_sp", shared)
cam_server.waitNext(10000)
stream_value = cam_server.stream.take()