Files
sf-op/script/RFscan/gun_scan1.py
2017-01-19 14:06:54 +01:00

43 lines
1.5 KiB
Python

import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
start = caget("SINEG01-RSYS:SET-SCAN-START")
stop = caget("SINEG01-RSYS:SET-SCAN-STOP")
step = caget("SINEG01-RSYS:SET-SCAN-STEP")
nb = caget("SINEG01-RSYS:SET-NUM-AVERAGE")
lat = caget("SINEG01-RSYS:SET-SCAN-WAIT-TIME")
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()
st = Stream("ICTstream", dispatcher)
q = st.addScalar("Charge", "SINEG01-DICT215:B1_CHARGE-SIM", 1, 0)
st.initialize()
#update the plot dynamically
arr_phase,arr_charge = [],[]
def after(rec):
global disp, energy0
arr_phase.append(rec.positions[0])
arr_charge.append(rec.values[1].mean)
caput("SINEG01-RSYS:GET-PHASE-ARRAY", to_array(arr_phase, 'd'))
caput("SINEG01-RSYS:GET-CHARGE-ARRAY", to_array(arr_charge,'d'))
try:
qb = create_averager(q, nb, 0.100)
r = lscan(phase, qb, start, stop, step, latency=lat, after_read = after)
rf_phase = r.getPositions(0)
charge = [val.mean for val in r.getReadable(0)]
caput("SINEG01-RSYS:GET-PHASE-ARRAY", to_array(rf_phase,'d'))
caput("SINEG01-RSYS:GET-CHARGE-ARRAY", to_array(charge, 'd'))
finally:
phase.close()
st.close()
# Here the user needs to pick a phase as reference phase onset of charge emission
phase_ref = 27.3
phase_offset = - phase_ref
caput("SINEG01-RSYS:CALC-VSUM-PHASE-OFFSET", phase_offset)