diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index aac9219..790b660 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,8 +1,8 @@ -#Mon Jul 10 21:46:52 CEST 2017 +#Tue Jul 11 15:08:20 CEST 2017 colormap=Flame colormapAutomatic=false -colormapMax=2871.0 -colormapMin=95.0 +colormapMax=280.0 +colormapMin=77.0 flipHorizontally=false flipVertically=false grayscale=false @@ -21,9 +21,9 @@ rotation=0.0 rotationCrop=false scale=1.0 serverURL=localhost\:10000 -spatialCalOffsetX=-1057.4895329398094 -spatialCalOffsetY=-1420.5549062527236 -spatialCalScaleX=-8.510638153514359 -spatialCalScaleY=-8.235817137431614 +spatialCalOffsetX=-861.4939970777481 +spatialCalOffsetY=-820.4883730911062 +spatialCalScaleX=-18.90359092620482 +spatialCalScaleY=-19.37984500632817 spatialCalUnits=mm transpose=false diff --git a/devices/camtool.properties b/devices/camtool.properties index 88b3efd..2f8810e 100644 --- a/devices/camtool.properties +++ b/devices/camtool.properties @@ -1,4 +1,4 @@ -#Mon Jul 10 21:28:43 CEST 2017 +#Tue Jul 11 14:06:09 CEST 2017 colormap=Flame colormapAutomatic=true colormapMax=578.797 @@ -18,9 +18,9 @@ roiY=0 rotation=0.0 rotationCrop=false scale=1.0 -spatialCalOffsetX=-861.4939970777481 -spatialCalOffsetY=-820.4883730911062 -spatialCalScaleX=-18.90359092620482 -spatialCalScaleY=-19.37984500632817 +spatialCalOffsetX=-633.6028650396007 +spatialCalOffsetY=-375.4578643259528 +spatialCalScaleX=-14.14677269345238 +spatialCalScaleY=-12.708499074710012 spatialCalUnits=mm transpose=false diff --git a/plugins/CameraConfigPanel.form b/plugins/CameraConfigPanel.form new file mode 100644 index 0000000..c638b68 --- /dev/null +++ b/plugins/CameraConfigPanel.form @@ -0,0 +1,28 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/CameraConfigPanel.java b/plugins/CameraConfigPanel.java new file mode 100644 index 0000000..d1459e9 --- /dev/null +++ b/plugins/CameraConfigPanel.java @@ -0,0 +1,44 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author gobbo_a + */ +public class CameraConfigPanel extends javax.swing.JPanel { + + /** + * Creates new form CameraConfigPanel + */ + public CameraConfigPanel() { + initComponents(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @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, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 300, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables +} diff --git a/plugins/ScreenPanel.java b/plugins/ScreenPanel.java index 1f1e2af..50a1045 100644 --- a/plugins/ScreenPanel.java +++ b/plugins/ScreenPanel.java @@ -1765,7 +1765,7 @@ public class ScreenPanel extends Panel { renderer.removeOverlays(calibrationOverlays); calibrationOverlays = null; calibrationDialolg = null; - if (calibrationMessage.getValue().equals(0)){ //If pressed OK + if ((calibrationMessage.getValue()!=null) && calibrationMessage.getValue().equals(0)){ //If pressed OK int x1 = Math.min(left.getPosition().x, right.getPosition().x); int x2 = Math.max(left.getPosition().x, right.getPosition().x); int y1 = Math.min(top.getPosition().y, bottom.getPosition().y); diff --git a/script/RFscan/GunScan.py b/script/RFscan/GunScan.py index 896f505..997ffd0 100644 --- a/script/RFscan/GunScan.py +++ b/script/RFscan/GunScan.py @@ -78,6 +78,8 @@ def after_sample(record, scan): #The scan loop try: + phase.write(start) + time.sleep(1.0) r = lscan(phase, [x_averager, dx_averager], start, stop, step , latency=lat, after_read = after_sample) finally: phase.write(phase0) diff --git a/script/test/phase_scan_caqtdm_test.py b/script/test/phase_scan_caqtdm_test.py new file mode 100644 index 0000000..6c7a5d0 --- /dev/null +++ b/script/test/phase_scan_caqtdm_test.py @@ -0,0 +1,112 @@ +import ch.psi.pshell.epics.Positioner as Positioner +import ch.psi.pshell.epics.ChannelDouble as ChannelDouble + +dry_run = False +do_elog = True + +if get_exec_pars().source == CommandSource.ui: + station = "STEST01" + bpm_ch = "SINBC02-DBPM140" +else: + station = args[0] + bpm_ch = args[1] + +start = caget(station + "-RSYS:SET-SCAN-START") +stop = caget(station + "-RSYS:SET-SCAN-STOP") +step = caget(station + "-RSYS:SET-SCAN-STEP") +lat = caget(station + "-RSYS:SET-SCAN-WAIT-TIME") +nb = caget(station + "-RSYS:SET-NUM-AVERAGE") +disp = caget(bpm_ch + ":DISPERSION") +energy0 = caget(bpm_ch + ":ENERGY") + +A = energy0 / disp / 1e3 +B = energy0 + +phase = Positioner("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE") +phase.config.minValue =-180.0 +phase.config.maxValue = 180.0 +phase.config.precision = 4 +phase.config.rotation = True +phase.config.resolution = 0.5 +phase.initialize() +V = ChannelDouble("Amplitude Readback", station + "-RSYS:GET-VSUM-AMPLT") +P = ChannelDouble("Power Readback", station + "-RSYS:GET-KLY-POWER") +if dry_run: + x = ChannelDouble("BPM-X", bpm_ch + ":X1-SIMU") +else: + x = ChannelDouble("BPM-X", bpm_ch + ":X1") +V.initialize() +P.initialize() +x.initialize() + +phase0 = phase.read() + +caput(station + "-RSYS:GET-FIT-PHASE-ARRAY", to_array([0.0],'d')) +caput(station + "-RSYS:GET-FIT-ENERGY-ARRAY", to_array([0.0],'d')) +caput(station + "-RSYS:GET-ONCREST-VSUM-PHASE", float('nan')) +caput(station + "-RSYS:GET-ONCREST-VSUM-AMPLT", float('nan')) +caput(station + "-RSYS:GET-ONCREST-E-GAIN", float('nan')) +caput(station + "-RSYS:GET-ONCREST-KLY-POWER", float('nan')) + +#update the plot dynamically +arr_phase,arr_energy = [],[] +def after(rec): + global A, B + arr_phase.append(rec.positions[0]) + arr_energy.append(A * rec.values[0].mean + B) + caput(station + "-RSYS:GET-PHASE-ARRAY", to_array(arr_phase, 'd')) + caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(arr_energy,'d')) + +try: + phase.write(start) + time.sleep(1.0) + x_averager = create_averager(x, nb, 0.100) + r = lscan(phase, x_averager, start, stop, step, latency=lat, after_read = after) + rf_phase = r.getPositions(0) + energy = [A * val.mean + B for val in r.getReadable(0)] + caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(energy, 'd')) + caput(station + "-RSYS:GET-PHASE-ARRAY", to_array(rf_phase,'d')) + try: + run("CPython/wrapper") + (fit_amplitude, fit_phase_deg, fit_offset, ph_crest, fit_x, fit_y) = hfitoff(energy , rf_phase) + except: + raise Exception("Fit failure") + plot([energy, fit_y], ["data", "fit"], [rf_phase, fit_x]) + caput(station + "-RSYS:GET-ONCREST-VSUM-PHASE", ph_crest) + caput(station + "-RSYS:GET-ONCREST-E-GAIN", fit_amplitude) + caput(station + "-RSYS:GET-FIT-PHASE-ARRAY", fit_x) + caput(station + "-RSYS:GET-FIT-ENERGY-ARRAY", fit_y) + phase_min, phase_max = min(rf_phase), max(rf_phase) + if not (phase_min <= ph_crest <= phase_max): + raise Exception("On-crest phase outside scan range") + phase.write(ph_crest) + time.sleep(lat) + Ampl = V.read() + Power = P.read() + caput(station + "-RSYS:GET-ONCREST-VSUM-AMPLT", Ampl) + caput(station + "-RSYS:GET-ONCREST-KLY-POWER", Power) +finally: + phase.write(phase0) + phase.close() + V.close() + P.close() + x.close() + +phase_offset = 90 - ph_crest +amplitude_scale = fit_amplitude / Ampl +power_scale = Power / math.pow(fit_amplitude,2) + +caput(station + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE-CALC", phase_offset) +caput(station + "-RSYS:SET-VSUM-AMPLT-SCALE-CALC", amplitude_scale) +caput(station + "-RSYS:SET-VOLT-POWER-SCALE-CALC", power_scale) + +if do_elog: + if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes": + title = "Phase scan" + station + log_msg = "Data file: " + get_exec_pars().path + "\n" + log_msg = log_msg + "Energy Gain: %0.3f" % energy_gain + "MeV\n" + log_msg = log_msg + "Phase Offset: %0.2f" % phase_offset + "deg\n" + log_msg = log_msg + "Amplitude Scale: %0.3f" % amplitude_scale + "MV\n" + log_msg = log_msg + "Power Scale: %0.3f" % power_scale + "MW/MV^2" + attachments = [] + elog(title, log_msg, attachments) diff --git a/script/test/scantestdv.py b/script/test/scantestdv.py new file mode 100644 index 0000000..dec7a80 --- /dev/null +++ b/script/test/scantestdv.py @@ -0,0 +1,87 @@ +import ch.psi.pshell.epics.Positioner as Positioner +import ch.psi.pshell.epics.ChannelDouble as ChannelDouble + +dry_run = True + +if get_exec_pars().source == CommandSource.ui: + start = -30.0 + stop = -10.0 + step = 1.0 + nb = 25 + lat = 0.1 + plt = None +else: + start = args[0] + stop = args[1] + step = args[2] + nb = int(args[3]) + lat = args[4] + plt = args[5] + +if plt is not None: + plt.clear() + #plt.setStyle(plt.Style.ErrorY) #Must be set by Plugin otherwise first scan is not shown + plt.addSeries(LinePlotErrorSeries("Values")) + plt.getAxis(plt.AxisId.X).setLabel("Gun Beam Phase (deg)") + plt.getAxis(plt.AxisId.Y).setLabel("SINEG01-DICT215:B1_CHARGE") + + +if dry_run: + bph = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM") + rph = ChannelDouble('RF phase', "SINEG01-RSYS:SET-VSUM-PHASE-SIM") + q = ChannelDouble("Charge", "SINEG01-DICT215:B1_CHARGE-SIM") + q.initialize() + q.monitored=True +else: + bph = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE") + rph = ChannelDouble('RF phase', "SINEG01-RSYS:SET-VSUM-PHASE") + #st = Stream("ICTstream", dispatcher) + #q = st.addScalar("Charge", "SINEG01-DICT215:B1_CHARGE", 1, 0) + #st.initialize() + #st.start() + #st.waitValueChange(10000) + q = ChannelDouble("Charge", "SINEG01-DICT215:B1_CHARGE") + q.initialize() + q.monitored=True + +bph.config.minValue = -360.0 +bph.config.maxValue = 360.0 +bph.config.precision = 3 +bph.config.rotation = False +bph.config.resolution = 0.01 +bph.config.save() +bph.initialize() +rph.initialize() +rph.monitored=True + +rph0 = rph.read() + +#Record callback: uptate of output plot +def after_sample(record, scan): + if plt is not None: + plt.getSeries(0).appendData(record.positions[0], record.values[1].mean, record.values[1].stdev) + +try: + rph_averager = create_averager(rph, nb, 0.1) # Set polling time to -1 for BS data to get all messages + q_averager = create_averager(q, nb, 0.1) + q_averager.monitored=True + r = lscan(bph, (rph_averager, q_averager), start, stop, step, latency=lat, after_read = after_sample) + beamphase = r.getPositions(0) + rfphase = [val.mean for val in r.getReadable(0)] + rfphaserms = [val.stdev for val in r.getReadable(0)] + charge = [val.mean for val in r.getReadable(1)] + chargerms = [val.stdev for val in r.getReadable(1)] +finally: + rph.write(rph0) + bph.close() + rph.close() + q.close() + +#Setting the return value +index_max = charge.index(max(charge)) +#bph_ref_guess = beamphase[index_max] - 80 +#rph_ref_guess = rfphase[index_max] - 80 + +bph_ref_guess = (start + stop)/2 + +set_return([bph_ref_guess])