Startup
This commit is contained in:
@@ -2,14 +2,6 @@
|
||||
* Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved.
|
||||
*/
|
||||
|
||||
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;
|
||||
import ch.psi.pshell.scan.Scan;
|
||||
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;
|
||||
@@ -21,20 +13,8 @@ import javax.swing.JSpinner;
|
||||
*/
|
||||
public class GunScan extends Panel {
|
||||
|
||||
LinePlotErrorSeries seriesEnergy = new LinePlotErrorSeries("Energy");
|
||||
LinePlotErrorSeries seriesEnergySpread = new LinePlotErrorSeries("Energy Spread", null, 2);
|
||||
double dispersion;
|
||||
double energy0;
|
||||
|
||||
public GunScan() {
|
||||
initComponents();
|
||||
plot.setStyle(LinePlotJFree.Style.ErrorY);
|
||||
plot.addSeries(seriesEnergy);
|
||||
plot.addSeries(seriesEnergySpread);
|
||||
plot.getAxis(Plot.AxisId.X).setLabel("Gun Phase");
|
||||
plot.getAxis(Plot.AxisId.Y).setLabel("Energy (MeV)");
|
||||
plot.getAxis(Plot.AxisId.Y2).setLabel("Energy Spread (MeV)");
|
||||
plot.setLegendVisible(true);
|
||||
setPersistedComponents(SwingUtils.getComponentsByType(panelScanPars, JSpinner.class));
|
||||
}
|
||||
|
||||
@@ -63,51 +43,6 @@ public class GunScan extends Panel {
|
||||
protected void doUpdate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
getContext().addScanListener(scanListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
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())) {
|
||||
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_spread_mean = ((DescStatsDouble) record.getValues()[1]).getMean();
|
||||
double energy_spread_std = ((DescStatsDouble) record.getValues()[1]).getStdev();
|
||||
seriesEnergy.appendData(phase,
|
||||
energy0 * (1 + energy_mean / 1e6 / dispersion),
|
||||
energy0 * (energy_std / 1e6 / dispersion)
|
||||
);
|
||||
seriesEnergySpread.appendData(phase,
|
||||
energy0 * (energy_spread_mean / 1e6 / dispersion),
|
||||
energy0 * (energy_spread_std / 1e6 / dispersion)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanEnded(Scan scan, Exception ex) {
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
@@ -284,12 +219,16 @@ public class GunScan extends Panel {
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(panelScanPars, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(panelBeamPars, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonStart)
|
||||
.addGap(34, 34, 34)
|
||||
.addComponent(buttonAbort))
|
||||
.addComponent(panelScanPars, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(panelBeamPars, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonAbort)
|
||||
.addGap(15, 15, 15)))
|
||||
.addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 531, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
@@ -315,22 +254,20 @@ public class GunScan extends Panel {
|
||||
|
||||
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);
|
||||
parameters.add((Double) spinnerDispersion.getValue());
|
||||
parameters.add((Double) spinnerEnergy.getValue());
|
||||
parameters.add(plot);
|
||||
try {
|
||||
runAsync("RFscan/GunScan", parameters).handle((ret, ex) -> {
|
||||
if (ex != null) {
|
||||
getLogger().info("Exception executing scan: " + ex);
|
||||
showException((Exception) ex);
|
||||
} else {
|
||||
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user