From e3bbddae181c707911090221e2032fe922a1f855 Mon Sep 17 00:00:00 2001 From: voulot_d Date: Thu, 19 Jan 2017 12:10:38 +0100 Subject: [PATCH] Script execution --- script/RFscan/gun_scan1.py | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 script/RFscan/gun_scan1.py diff --git a/script/RFscan/gun_scan1.py b/script/RFscan/gun_scan1.py new file mode 100644 index 0000000..e7f398d --- /dev/null +++ b/script/RFscan/gun_scan1.py @@ -0,0 +1,42 @@ +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)