diff --git a/plugins/GunScan.form b/plugins/GunScan.form new file mode 100644 index 0000000..ff9cfab --- /dev/null +++ b/plugins/GunScan.form @@ -0,0 +1,28 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/GunScan.java b/plugins/GunScan.java new file mode 100644 index 0000000..aacbc55 --- /dev/null +++ b/plugins/GunScan.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved. + */ + +import ch.psi.pshell.ui.Panel; +import ch.psi.utils.State; + +/** + * + */ +public class GunScan extends Panel { + + public GunScan() { + initComponents(); + } + + //Overridable callbacks + @Override + public void onInitialize(int runCount) { + + } + + @Override + public void onStateChange(State state, State former) { + + } + + @Override + public void onExecutedFile(String fileName, Object result) { + } + + + //Callback to perform update - in event thread + @Override + protected void doUpdate() { + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 449, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 137, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables +} diff --git a/script/RFscan/GunScan.py b/script/RFscan/GunScan.py new file mode 100644 index 0000000..fe2296c --- /dev/null +++ b/script/RFscan/GunScan.py @@ -0,0 +1,78 @@ +import ch.psi.pshell.epics.ControlledVariable as ControlledVariable + +if get_exec_pars().source == CommandSource.ui: + start = 0.0 + stop = 360.0 + step = 5.0 + nb = 1 + lat = 0.100 +else: + start = args[0] + stop = args[1] + step = args[2] + nb = int(args[3]) + lat = args[4] + + +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() + +V = Channel("SINEG01-RSYS:GET-VSUM-AMPLT-SIM", type = 'd', alias='Amplitude Readback') +P = Channel("SINEG01-RSYS:GET-KLY-POWER-SIM", type = 'd', alias='Power Readback') + + +#camtool = Camtool(url) +#camtool.startPipeline(camera_name) +#camtool.startReceiver() +#x = camtool.getValue("x_fit_mean") +x = Channel("SINEG01-RSYS:GET-VSUM-AMPLT-SIM", type = 'd', alias='Amplitude Readback') +dx = Channel("SINEG01-RSYS:GET-KLY-POWER-SIM", type = 'd', alias='Power Readback') + + +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, after_read = after) + 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)] + caput("SINEG01-RSYS:GET-PHASE-ARRAY", to_array(rf_phase,'d')) + caput("SINEG01-RSYS:GET-CHARGE-ARRAY", to_array(charge, 'd')) + phase_fit_max = None + try: + (energy_max, angular_frequency, phase0, in_range, phase_fit_max, fit_x, fit_y) = hfit(energy , xdata = rf_phase) + except: + raise Exception("Fit failure") + caput("SINEG01-RSYS:GET-ONCREST-VSUM-PHASE", phase_fit_max) + caput("SINEG01-RSYS:GET-ONCREST-E-GAIN", energy_max) + caput("SINEG01-RSYS:GET-FIT-PHASE-ARRAY", fit_x) + caput("SINEG01-RSYS:GET-FIT-ENERGY-ARRAY", fit_y) + phase_min, phase_max = min(rf_phase), max(rf_phase) + if not (phase_min <= phase_fit_max <= phase_max): + raise Exception("Fit maximum outside scan range") + phase.write(phase_fit_max) + time.sleep(lat) + Ampl = V.read() + Power = P.read() + caput("SINEG01-RSYS:GET-ONCREST-VSUM-AMPLT", Ampl) + caput("SINEG01-RSYS:GET-ONCREST-KLY-POWER", Power) +finally: + phase.close() + V.close() + P.close() + st.close() + +print ("------------------------------------") +print ("Valid fit") + +energy_gain = energy_max +phase_offset = 90 - phase_fit_max +amplitude_scale = energy_gain / Ampl +power_scale = Power / math.pow(Ampl,2) + +caput("SINEG01-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phase_offset) +caput("SINEG01-RSYS:SET-VSUM-AMPLT-SCALE", amplitude_scale) +caput("SINEG01-RSYS:SET-VOLT-POWER-SCALE", power_scale)