Files
sf-op/script/RFscan/SchottkyScan_sim.py
2017-06-02 08:52:46 +02:00

61 lines
1.8 KiB
Python

import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
if get_exec_pars().source == CommandSource.ui:
start = -10.0
stop = 180.0
step = 5.0
nb = 3
lat = 0.300
else:
start = args[0]
stop = args[1]
step = args[2]
nb = int(args[3])
lat = args[4]
bphase = ControlledVariable("Beam phase", "SINEG01-RSYS:SET-VSUM-PHASE-SIM", "SINEG01-RSYS:GET-VSUM-PHASE-SIM")
bphase.config.minValue =-180.0
bphase.config.maxValue = 360.0
bphase.config.precision = 3
bphase.config.resolution = 1.0
bphase.config.save()
bphase.initialize()
st = Stream("Schottky stream", dispatcher)
#q = st.addScalar("Charge", "SINEG01-DICT215:B1_CHARGE", 1, 0)
#rphase = st.addScalar("RF phase", "SINEG01-RSYS:GET-VSUM-PHASE", 1, 0)
st.initialize()
st.start()
q = Channel("SINEG01-DICT215:B1_CHARGE-SIM", type = 'd', alias = 'ICT-Q')
rphase = Channel("SINEG01-RSYS:GET-BEAM-PHASE-SIM", type = 'd', alias = 'RF phase')
bphase0 = bphase.read()
print bphase0
print q.read()
print rphase.read()
try:
q_averager = create_averager(q, nb, 0.100)
rphase_averager = create_averager(rphase, nb, 0.100)
r = lscan(bphase, (q_averager, rphase_averager), start, stop, step, latency=lat)
beamphase = r.getPositions(0)
charge = [val.mean for val in r.getReadable(0)]
chargerms = [val.stdev for val in r.getReadable(0)]
rfphase = [val.mean for val in r.getReadable(1)]
rfphaserms = [val.stdev for val in r.getReadable(1)]
finally:
bphase.write(bphase0)
bphase.close()
st.close()
q.close()
rphase.close()
#Setting the return value
index_max = charge.index(max(charge))
rphase_ref = rfphase[index_max] - 80
bphase_ref = beamphase[index_max] - 80
print rphase_ref
print bphase_ref
set_return(rphase_ref)