This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
import ch.psi.pshell.epics.Positioner as Positioner
|
||||
|
||||
dry_run = False
|
||||
do_elog = True
|
||||
is_panel = get_exec_pars().source != CommandSource.ui #must be check before run
|
||||
USE_SCREEN_PANEL = False
|
||||
|
||||
run("CPython/wrapper")
|
||||
#Parameters
|
||||
if is_panel:
|
||||
start = args[0]
|
||||
stop = args[1]
|
||||
step = args[2]
|
||||
nb = int(args[3])
|
||||
lat = args[4]
|
||||
disp = args[5]
|
||||
p0 = args[6]
|
||||
plt = args[7]
|
||||
thr = args[8]
|
||||
else:
|
||||
start = 85.0
|
||||
stop = 95.0
|
||||
step = 0.5
|
||||
nb = 3
|
||||
lat = 0.15
|
||||
disp = -0.387
|
||||
p0 = 7.1
|
||||
plt = plot(None, title="Output")[0]
|
||||
thr = 500
|
||||
|
||||
A = p0 / disp / 1e6
|
||||
B = p0
|
||||
|
||||
#Plot setup
|
||||
plt.clear()
|
||||
plt.removeMarker(None)
|
||||
plt.setStyle(plt.Style.ErrorY)
|
||||
plt.addSeries(LinePlotErrorSeries("Momentum", Color.red))
|
||||
plt.addSeries(LinePlotErrorSeries("Momentum Spread", Color.yellow, 2))
|
||||
plt.getAxis(plt.AxisId.X).setLabel("Gun Beam Phase (deg)")
|
||||
plt.getAxis(plt.AxisId.Y).setLabel("Momentum (MeV/c)")
|
||||
plt.getAxis(plt.AxisId.Y2).setLabel("Momentum Spread (MeV/c)")
|
||||
plt.setLegendVisible(True)
|
||||
|
||||
#Creating Phase positioner
|
||||
if dry_run:
|
||||
phase = Positioner("Gun Phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
|
||||
camera_name = "simulation"
|
||||
else:
|
||||
phase = Positioner("Gun Phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE")
|
||||
camera_name = "SINBD01-DSCR010"
|
||||
phase.config.minValue = -90.0
|
||||
phase.config.maxValue = 360.0
|
||||
phase.config.precision = 4
|
||||
phase.config.resolution = 0.5
|
||||
phase.config.rotation = True
|
||||
phase.config.save()
|
||||
phase.initialize()
|
||||
phase0 = phase.read() % 360
|
||||
|
||||
#Camera setup
|
||||
if USE_SCREEN_PANEL:
|
||||
cam_server.start(camera_name+"_sp1", True) #True for shared pipeline
|
||||
else:
|
||||
cam_server.start(camera_name)
|
||||
wait_cam_server_message()
|
||||
x = cam_server.stream.getChild("x_center_of_mass")
|
||||
dx = cam_server.stream.getChild("x_rms")
|
||||
cam_server.setThreshold(thr)
|
||||
cam_server.setBackgroundSubtraction(False)
|
||||
|
||||
#Creating averagers
|
||||
x_averager = create_averager(x, nb, -1) # -1 event based, waits for the next value
|
||||
dx_averager = create_averager(dx, nb, -1)
|
||||
dx_averager.monitored = True # not blocking, will return last nb values
|
||||
|
||||
#Record callback: uptate of output plot
|
||||
def after_sample(record, scan):
|
||||
global A, B, plt
|
||||
x_pos_mean, x_pos_stdev = record.values[0].mean, record.values[0].stdev
|
||||
x_width_mean, x_width_stdev = record.values[1].mean, record.values[1].stdev
|
||||
p_mean, p_stdev = A * x_pos_mean + B, abs(A) * x_pos_stdev
|
||||
dp_mean, dp_stdev = abs(A) * x_width_mean, abs(A) * x_width_stdev
|
||||
phase = ((record.positions[0] + 90) % 360) - 90 if start < 0 else record.positions[0]
|
||||
plt.getSeries(0).appendData(phase, p_mean, p_stdev)
|
||||
plt.getSeries(1).appendData(phase, dp_mean, dp_stdev)
|
||||
|
||||
#The scan loop
|
||||
try:
|
||||
phase.write(start)
|
||||
time.sleep(2.0)
|
||||
r = lscan(phase, [x_averager, dx_averager], start, stop, step , latency=lat, after_read = after_sample)
|
||||
finally:
|
||||
phase.write(phase0)
|
||||
phase.close()
|
||||
cam_server.stop() # stops cam_server but does not close it cam_server is a global object
|
||||
|
||||
ph = r.getPositions(0)
|
||||
if start < 0:
|
||||
ph = [((val + 90) % 360) -90 for val in ph ]
|
||||
p = [A * val.mean + B for val in r.getReadable(0)]
|
||||
dp = [abs(A) * val.mean for val in r.getReadable(1)]
|
||||
|
||||
#Fitting and plotting
|
||||
try:
|
||||
i = p.index(max(p))
|
||||
a, b = max(i-6, 0), min(i+6, len(p))
|
||||
(ph_p_max, p_max, ph_p_fit, p_fit, p_R2) = extremum(ph[a:b], p[a:b])
|
||||
i = dp.index(min(dp))
|
||||
a, b = max(i-6, 0), min(i+6, len(dp))
|
||||
(ph_dp_min, dp_min, ph_dp_fit, dp_fit, dp_R2) = extremum(ph[a:b], dp[a:b])
|
||||
plt.addSeries(LinePlotErrorSeries("Momentum Fit", plt.getSeries(0).color))
|
||||
plt.addSeries(LinePlotErrorSeries("Momentum Spread Fit", plt.getSeries(1).color, 2))
|
||||
plt.getSeries(2).setData(ph_p_fit, p_fit)
|
||||
plt.getSeries(3).setData(ph_dp_fit, dp_fit)
|
||||
plt.getSeries(2).setPointsVisible(False)
|
||||
plt.getSeries(3).setPointsVisible(False)
|
||||
plt.addMarker(ph_p_max, plt.AxisId.X, "%3.2f" % ph_p_max, plt.getSeries(0).color)
|
||||
plt.addMarker(ph_dp_min, plt.AxisId.X, "%3.2f" % ph_dp_min, plt.getSeries(1).color)
|
||||
except:
|
||||
raise Exception("Fit failure")
|
||||
|
||||
# Calculating laser offset in deg
|
||||
las_offset_deg = ph_dp_min - 90.0
|
||||
|
||||
#Saving metadata
|
||||
save_dataset( "scan 1/processed/p" , p )
|
||||
set_attribute( "scan 1/processed/p" , "p max" , p_max )
|
||||
set_attribute( "scan 1/processed/p" , "p max phase" , ph_p_max )
|
||||
set_attribute( "scan 1/processed/p" , "p fit R2" , p_R2 )
|
||||
set_attribute( "scan 1/processed/p" , "Unit" , "MeV" )
|
||||
|
||||
save_dataset( "scan 1/processed/dp" , dp )
|
||||
set_attribute( "scan 1/processed/dp" , "dp min" , dp_min )
|
||||
set_attribute( "scan 1/processed/dp" , "dp min phase" , ph_dp_min )
|
||||
set_attribute( "scan 1/processed/dp" , "dp fit R2" , dp_R2 )
|
||||
set_attribute( "scan 1/processed/dp" , "Unit" , "MeV" )
|
||||
|
||||
#Elog entry
|
||||
if do_elog:
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
title = "Gun Energy Scan"
|
||||
Laser = str(caget("SLG-LGEN:WHICH_LASER"))
|
||||
log_msg = "Data file: " + get_exec_pars().path + "\n\n"
|
||||
log_msg = log_msg + "Laser: " + Laser + "\n"
|
||||
if Laser == "Alcor":
|
||||
log_msg = log_msg + "Energy plate Alcor: %0.2f" % caget("SLGTH01-LMRM-M074:MOT.RBV") + " deg \n"
|
||||
elif Laser == "Jaguar":
|
||||
log_msg = log_msg + "Energy plate Jaguar: %0.2f" % caget("SLGJG-LMRM-M031:MOT.RBV") + " deg \n"
|
||||
elif Laser == "Both":
|
||||
log_msg = log_msg + "Energy plate Alcor: %0.2f" % caget("SLGTH01-LMRM-M074:MOT.RBV") + " deg \n"
|
||||
log_msg = log_msg + "Energy plate Jaguar: %0.2f" % caget("SLGJG-LMRM-M031:MOT.RBV") + " deg \n"
|
||||
if caget("SLGTV-LMTO-M053:MOT-ACT-POS") == "IRIS":
|
||||
log_msg = log_msg + "Collimator: IRIS %0.2f" % caget("SLGTV-LAPP:SIZE-GET") + " mm \n"
|
||||
else:
|
||||
log_msg = log_msg + "Collimator: " + str(caget("SLGTV-LMTO-M053:MOT-ACT-POS")) + "\n"
|
||||
log_msg = log_msg + "Charge B1: %0.2f" % caget("SINEG01-DICT215:B1_CHARGE-OP") + " pC at %0.2f" % phase0 + " deg beam phase\n"
|
||||
log_msg = log_msg + "Charge B2: %0.2f" % caget("SINEG01-DICT215:B2_CHARGE-OP") + " pC at %0.2f" % phase0 + " deg beam phase\n"
|
||||
log_msg = log_msg + "p-max: %0.2f" % p_max + " MeV/c at %0.2f" % ph_p_max + " deg beam phase\n"
|
||||
log_msg = log_msg + "dp-min: %0.4f" % dp_min + " MeV/c at %0.2f" % ph_dp_min + " deg beam phase\n"
|
||||
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
file_name = os.path.abspath(get_context().setup.getContextPath() + "/GunEnergyScanPlot.png")
|
||||
plt.saveSnapshot(file_name , "png")
|
||||
elog(title, log_msg, [file_name,])
|
||||
|
||||
set_return([ph_dp_min, las_offset_deg])
|
||||
@@ -0,0 +1,38 @@
|
||||
dry_run = False
|
||||
do_elog = True
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
las_offset_deg = 0.0
|
||||
plt = None
|
||||
else:
|
||||
las_offset_deg = args[0]
|
||||
plt = args[1]
|
||||
Laser = caget("SLG-LGEN:WHICH_LASER")
|
||||
cur_las_delay = 0.0
|
||||
if Laser == "Alcor":
|
||||
cur_las_delay = caget("SLGOS01-TSPL-ALC:CURR_DELTA_T")
|
||||
elif Laser == "Jaguar":
|
||||
cur_las_delay = caget("SLGJG-TSPL-JAG:CURR_DELTA_T")
|
||||
new_las_delay = cur_las_delay - 333.467 * las_offset_deg / 360.0
|
||||
if not dry_run:
|
||||
if Laser == "Alcor":
|
||||
caput("SLGOS01-TSPL-ALC:NEW_DELTA_T" , new_las_delay )
|
||||
caput("SLGOS01-TSPL-ALC:SET_NEW_PHASE.PROC" , 1 )
|
||||
elif Laser == "Jaguar":
|
||||
caput("SLGJG-TSPL-JAG:NEW_DELTA_T" , new_las_delay )
|
||||
caput("SLGJG-TSPL-JAG:SET_NEW_PHASE.PROC" , 1 )
|
||||
if do_elog:
|
||||
title = "Set laser delay"
|
||||
log_msg = ""
|
||||
if Laser == "Alcor":
|
||||
log_msg = "SLGOS01-TSPL-ALC:NEW_DELTA_T: %12.4f" % new_las_delay + " ps (was %12.4f" % cur_las_delay + " ps)\n"
|
||||
elif Laser == "Jaguar":
|
||||
log_msg = "SLGJG-TSPL-JAG:NEW_DELTA_T: %12.4f" % new_las_delay + " ps (was %12.4f" % cur_las_delay + " ps)\n"
|
||||
attachments = []
|
||||
if plt is not None:
|
||||
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
file_name = os.path.abspath(get_context().setup.getContextPath() + "/GunEnergyScanLasSet.png")
|
||||
plt.saveSnapshot(file_name , "png")
|
||||
attachments = [file_name]
|
||||
elog(title, log_msg, attachments)
|
||||
show_message("Success setting laser delay")
|
||||
@@ -65,10 +65,10 @@ else:
|
||||
wait_cam_server_message()
|
||||
x = cam_server.stream.getChild("x_center_of_mass")
|
||||
dx = cam_server.stream.getChild("x_rms")
|
||||
cam_server.setThreshold(500)
|
||||
cam_server.setThreshold(150)
|
||||
#cam_server.captureBackground(10) #Capturing background
|
||||
cam_server.setBackgroundSubtraction(False)
|
||||
#cam_server.setRoi([144,482,1431,706]) #X, Y, W, H # something wrong thereto be fixed
|
||||
#cam_server.setRoi([144,482,1431,706]) #X, Y, W, H # something wrong there to be fixed
|
||||
|
||||
#Creating averagers
|
||||
x_averager = create_averager(x, nb, -1) # -1 event based, waits for the next value
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
dry_run = False
|
||||
do_elog = True
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
bph_ref_user = 90.0
|
||||
plt = None
|
||||
else:
|
||||
bph_ref_user = args[0]
|
||||
plt = args[1]
|
||||
phase_offset_old = caget("SINEG01-RSYS:SET-VSUM-PHASE-OFFSET-BASE")
|
||||
phase_offset_new = phase_offset_old - (bph_ref_user - 90.0)
|
||||
if not dry_run:
|
||||
caput("SINEG01-RSYS:SET-VSUM-PHASE-OFFSET-BASE" , phase_offset_new )
|
||||
caput("SINEG01-RSYS:CMD-LOAD-CALIB-BEAM" , 1 )
|
||||
if do_elog:
|
||||
title = "Set gun phase"
|
||||
log_msg = "SINEG01-RSYS:SET-VSUM-PHASE-OFFSET-BASE: %8.2f" % phase_offset_new + " deg (was %8.2f" % phase_offset_old + " deg)\n"
|
||||
attachments = []
|
||||
if plt is not None:
|
||||
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
file_name = os.path.abspath(get_context().setup.getContextPath() + "/GunEnergyScanRfSet.png")
|
||||
plt.saveSnapshot(file_name , "png")
|
||||
attachments = [file_name]
|
||||
elog(title, log_msg, attachments)
|
||||
show_message("Success setting phase reference")
|
||||
@@ -0,0 +1,19 @@
|
||||
run("Devices/Elements")
|
||||
blms = get_blms() #["S10BC01-DBLM065"]
|
||||
|
||||
plots = []
|
||||
names = []
|
||||
for b in blms:
|
||||
try:
|
||||
b = b + ":LOSS_SIGNAL_RAW"
|
||||
plots.append(caget(b))
|
||||
names.append (b)
|
||||
except:
|
||||
print "Error reading " + str(b)
|
||||
|
||||
plot(plots, names)
|
||||
|
||||
|
||||
#plots = get_plot_snapshots()
|
||||
#print plots
|
||||
##elog("BLM PMT-waveform", "", plots)
|
||||
Reference in New Issue
Block a user