Files
sf-op/script/RFscan/GunScan.py
2017-03-15 11:03:52 +01:00

60 lines
1.8 KiB
Python

import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
import ch.psi.pshell.epics.Camtool as Camtool
if get_exec_pars().source == CommandSource.ui:
start = 0.0
stop = 180.0
step = 5.0
nb = 2
lat = 0.100
else:
start = args[0]
stop = args[1]
step = args[2]
nb = int(args[3])
lat = args[4]
disp = caget("SINBD01-DSCR010:DISPERSION-SIM")
energy0 = caget("SINBD01-DSCR010:ENERGY-SIM")
phase = ControlledVariable("Phase", "SINEG01-RSYS:SET-VSUM-PHASE-SIM", "SINEG01-RSYS:GET-VSUM-PHASE-SIM")
phase.config.minValue =-45.0
phase.config.maxValue = 360.0
phase.config.resolution = 0.5
phase.initialize()
#my_camtool = Camtool("localhost:10000")
#Testing if camtool server is up:
#camtool.getCameras()
camtool.stop()
camtool.start("simulation")
#x = Channel("SINEG01-DSCR190:X-SIM", type = 'd', alias='SCR-X')
#dx = Channel("SINEG01-DSCR190:DX-SIM", type = 'd', alias='SCR-DX')
x = CamtoolValue("gr_x_fit_mean")
dx = CamtoolValue("gr_x_fit_standard_deviation")
#x = CamtoolValue("gr_x_com_egu")
#dx = CamtoolValue("gr_x_rms_egu")
try:
xb = create_averager(x, nb, 0.100)
dxb = create_averager(dx, nb, 0.100)
r = lscan(phase, [xb, dxb], start, stop, step , latency=lat)
rf_phase = r.getPositions(0)
E = [val.mean/1000.0/disp*energy0 for val in r.getReadable(0)]
dE = [val.mean/1000.0/disp*energy0 for val in r.getReadable(1)]
finally:
phase.close()
#my_camtool.close()
p = plot(None, title="Output")[0]
p.clear()
p.addSeries(LinePlotSeries("Energy"))
p.addSeries(LinePlotSeries("Energy spread"))
p.getSeries(0).setData(to_array(rf_phase, 'd'), E)
p.getSeries(1).setData(to_array(rf_phase, 'd'), dE)
p.setLegendVisible(True)
#plot((E, dE), xdata = rf_phase, title="Phase scan")