diff --git a/config/plugins.properties b/config/plugins.properties index 65be863..f8765da 100644 --- a/config/plugins.properties +++ b/config/plugins.properties @@ -1,12 +1,8 @@ SchottkyScan.java=disabled -SchottkyScanSim.java=disabled -ReturnBug.java=disabled GunScan.java=disabled Correlation.java=disabled Cameras.java=disabled ScreenPanel.java=disabled Camtool.java=disabled LaserGunAlignment.java=disabled -test2.java=disabled GunSolenoidAlignment.java=disabled -test.java=disabled diff --git a/plugins/GunScan.form b/plugins/GunScan.form index a2032ca..faebcb9 100644 --- a/plugins/GunScan.form +++ b/plugins/GunScan.form @@ -41,9 +41,9 @@ - - - + + + @@ -211,7 +211,7 @@ - + @@ -313,11 +313,17 @@ + + + + + + diff --git a/plugins/GunScan.java b/plugins/GunScan.java index 582197e..77d438b 100644 --- a/plugins/GunScan.java +++ b/plugins/GunScan.java @@ -2,7 +2,9 @@ * Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved. */ +import ch.psi.jcae.ChannelException; import ch.psi.pshell.device.DescStatsDouble; +import ch.psi.pshell.epics.Epics; import ch.psi.pshell.plot.LinePlotErrorSeries; import ch.psi.pshell.plot.LinePlotJFree; import ch.psi.pshell.plot.Plot; @@ -11,22 +13,34 @@ import ch.psi.pshell.scan.ScanListener; import ch.psi.pshell.scan.ScanRecord; import ch.psi.pshell.ui.Panel; import ch.psi.utils.State; +import ch.psi.utils.swing.SwingUtils; +import java.util.ArrayList; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import java.util.logging.Level; +import java.util.logging.Logger; /** * */ public class GunScan extends Panel { - LinePlotErrorSeries series = new LinePlotErrorSeries("Values"); + + LinePlotErrorSeries seriesEnergy = new LinePlotErrorSeries("Energy"); + LinePlotErrorSeries seriesEnergySpread = new LinePlotErrorSeries("Energy Spread"); + double dispersion; + double energy0; public GunScan() { - initComponents(); + initComponents(); plot.setStyle(LinePlotJFree.Style.ErrorY); - plot.addSeries(series); + plot.addSeries(seriesEnergy); + plot.addSeries(seriesEnergySpread); plot.getAxis(Plot.AxisId.X).setLabel("Gun Phase"); plot.getAxis(Plot.AxisId.Y).setLabel("MeV"); + plot.setLegendVisible(true); } - //Overridable callbacks + //Overridable callbacks @Override public void onInitialize(int runCount) { } @@ -46,38 +60,58 @@ public class GunScan extends Panel { public void onExecutedFile(String fileName, Object result) { } - //Callback to perform update - in event thread @Override protected void doUpdate() { } - + @Override public void onStart() { super.onStart(); getContext().addScanListener(scanListener); + try { + spinnerDispersion.setValue(Epics.get("SINBD01-DSCR010:DISPERSION-SIM", Double.class)); + spinnerEnergy.setValue(Epics.get("SINBD01-DSCR010:ENERGY-SIM", Double.class)); + } catch (Exception ex) { + showException(ex); + } } @Override - public void onStop() { + public void onStop() { getContext().removeScanListener(scanListener); super.onStop(); } - + ScanListener scanListener = new ScanListener() { @Override - public void onScanStarted(Scan scan, String plotTitle) { - if ("GunScan".equals(getContext().getExecutionPars().getName())){ - series.clear(); - } - } - @Override - public void onNewRecord(Scan scan, ScanRecord record) { - if ("GunScan".equals(getContext().getExecutionPars().getName())){ - series.appendData((Double)record.getPositions()[0], ((DescStatsDouble)record.getValues()[0]).getMean(), - ((DescStatsDouble)record.getValues()[0]).getStdev()); + public void onScanStarted(Scan scan, String plotTitle) { + if ("GunScan".equals(getContext().getExecutionPars().getName())) { + seriesEnergy.clear(); + seriesEnergySpread.clear(); } } + + @Override + public void onNewRecord(Scan scan, ScanRecord record) { + if ("GunScan".equals(getContext().getExecutionPars().getName())) { + double phase = (Double) record.getPositions()[0]; + double energy_mean = ((DescStatsDouble) record.getValues()[0]).getMean(); + double energy_std = ((DescStatsDouble) record.getValues()[0]).getStdev(); + double energy_sp_mean = ((DescStatsDouble) record.getValues()[1]).getMean(); + double energy_sp_std = ((DescStatsDouble) record.getValues()[1]).getStdev(); + seriesEnergy.appendData(phase, + energy0 * (1 +energy_mean / 1e6 / dispersion), + 0 + ); + + seriesEnergySpread.appendData(phase, + energy0 * (energy_sp_mean / 1e6 / dispersion), + 0 + ); + } + } + @Override public void onScanEnded(Scan scan, Exception ex) { } @@ -133,7 +167,7 @@ public class GunScan extends Panel { spinnerLatency.setModel(new javax.swing.SpinnerNumberModel(0.1d, 0.0d, 5.0d, 0.01d)); spinnerLatency.setPreferredSize(new java.awt.Dimension(64, 20)); - spinnerStop.setModel(new javax.swing.SpinnerNumberModel(360.0d, -180.0d, 360.0d, 1.0d)); + spinnerStop.setModel(new javax.swing.SpinnerNumberModel(180.0d, -180.0d, 360.0d, 1.0d)); spinnerStop.setMinimumSize(new java.awt.Dimension(53, 20)); spinnerStop.setPreferredSize(new java.awt.Dimension(64, 20)); @@ -238,8 +272,18 @@ public class GunScan extends Panel { plot.setTitle(""); buttonStart.setText("Start"); + buttonStart.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonStartActionPerformed(evt); + } + }); buttonAbort.setText("Abort"); + buttonAbort.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAbortActionPerformed(evt); + } + }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); @@ -262,8 +306,8 @@ public class GunScan extends Panel { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(plot, javax.swing.GroupLayout.PREFERRED_SIZE, 419, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -278,6 +322,39 @@ public class GunScan extends Panel { jPanel1.getAccessibleContext().setAccessibleDescription(""); }// //GEN-END:initComponents + private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed + ArrayList parameters = new ArrayList(); + dispersion = (Double)spinnerDispersion.getValue(); + energy0 = (Double)spinnerEnergy.getValue(); + parameters.add(spinnerStart.getValue()); + parameters.add(spinnerStop.getValue()); + parameters.add(spinnerStep.getValue()); + parameters.add(spinnerSamples.getValue()); + parameters.add(spinnerLatency.getValue()); + parameters.add(dispersion); + parameters.add(energy0); + try { + runAsync("RFscan/GunScan", parameters).handle((ret, ex) -> { + if (ex != null) { + getLogger().info("Exception executing scan: " + ex); + } else { + + } + return ret; + }); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonStartActionPerformed + + private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed + try { + abort(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonAbortActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton buttonAbort; private javax.swing.JButton buttonStart; diff --git a/script/RFscan/GunScan.py b/script/RFscan/GunScan.py index 3f79761..f379b61 100644 --- a/script/RFscan/GunScan.py +++ b/script/RFscan/GunScan.py @@ -7,15 +7,17 @@ if get_exec_pars().source == CommandSource.ui: step = 20.0 nb = 5 lat = 1.0 + disp = caget("SINBD01-DSCR010:DISPERSION-SIM") + energy0 = caget("SINBD01-DSCR010:ENERGY-SIM") else: start = args[0] stop = args[1] step = args[2] nb = int(args[3]) lat = args[4] + disp = args[5] + energy0 = args[6] -disp = caget("SINBD01-DSCR010:DISPERSION-SIM") -energy0 = caget("SINBD01-DSCR010:ENERGY-SIM") phase = ControlledVariable("Phase", "SINEG01-RSYS:SET-VSUM-PHASE", "SINEG01-RSYS:SET-VSUM-PHASE") phase.config.minValue =-180.0 @@ -29,13 +31,11 @@ camtool.start("SINBD01-DSCR010") while camtool.stream.getChild("gr_x_fit_mean") == None: time.sleep(0.1) - x = camtool.stream.getChild("gr_x_fit_mean") dx = camtool.stream.getChild("gr_x_fit_standard_deviation") - try: - xb = create_averager(x, nb, -1) + xb = create_averager(x, nb, -1) # -1 event based, waits for the next value dxb = create_averager(dx, nb, -1) dxb.monitored=True # not blocking, will return last nb values r = lscan(phase, [xb, dxb], start, stop, step , latency=lat) @@ -44,6 +44,7 @@ try: dE = [energy0 * (val.mean / 1e6 / disp) for val in r.getReadable(1)] finally: phase.close() + camtool.stop() # stops camtool but does not close it camtool is a global object p = plot(None, title="Output")[0] p.clear() @@ -52,3 +53,5 @@ p.addSeries(LinePlotSeries("Energy spread")) p.getSeries(0).setData(to_array(rf_phase, 'd'), E) p.getSeries(1).setData(to_array(rf_phase, 'd'), dE) p.setLegendVisible(True) + +set_return([E,dE]) \ No newline at end of file