From db22aa13b08247117f0e7336d5524290be5c5231 Mon Sep 17 00:00:00 2001 From: gobbo_a Date: Tue, 13 Jun 2017 14:30:43 +0200 Subject: [PATCH] Startup --- devices/CurrentCamera.properties | 20 ++--- devices/Phase.properties | 5 +- devices/camtool.properties | 10 +-- devices/gsrx.properties | 3 +- devices/gsry.properties | 3 +- devices/gsx.properties | 3 +- devices/gsy.properties | 3 +- devices/gun_phase.properties | 3 +- devices/gun_solenoid.properties | 3 +- plugins/GunScan.form | 18 ++-- plugins/GunScan.java | 87 +++----------------- script/Alignment/Gun_solenoid_alignment.py | 4 +- script/Alignment/Laser_gun_alignment.py | 4 +- script/RFscan/GunScan.py | 95 ++++++++++++++++------ script/RFscan/SchottkyScan_sim.py | 67 +++++++-------- 15 files changed, 158 insertions(+), 170 deletions(-) diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index ab24716..91b9bb5 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,16 +1,16 @@ -#Mon Jun 12 15:16:58 CEST 2017 +#Tue Jun 13 10:36:39 CEST 2017 colormap=Flame colormapAutomatic=true -colormapMax=20000.0 +colormapMax=0.0 colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=2160 -imageWidth=1936 +imageHeight=1680 +imageWidth=1744 invert=false -regionStartX=321 -regionStartY=1 +regionStartX=433 +regionStartY=241 rescaleFactor=1.0 rescaleOffset=0.0 roiHeight=-1 @@ -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=-569.4274826508778 +spatialCalOffsetY=-1010.5032289276822 +spatialCalScaleX=-7.6174468650216 +spatialCalScaleY=-7.774538383236796 spatialCalUnits=mm transpose=false diff --git a/devices/Phase.properties b/devices/Phase.properties index 8706a2d..15bf704 100644 --- a/devices/Phase.properties +++ b/devices/Phase.properties @@ -1,8 +1,9 @@ -#Tue Apr 25 10:33:55 CEST 2017 +#Tue Jun 13 14:21:33 CEST 2017 maxValue=360.0 -minValue=-180.0 +minValue=0.0 offset=0.0 precision=3 resolution=1.0 +rotation=true scale=1.0 unit=deg diff --git a/devices/camtool.properties b/devices/camtool.properties index 5d3d1e8..9bdce31 100644 --- a/devices/camtool.properties +++ b/devices/camtool.properties @@ -1,4 +1,4 @@ -#Mon Jun 12 11:22:00 CEST 2017 +#Tue Jun 13 12:10:28 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=-50.03909304143862 +spatialCalOffsetY=-50.048875855327466 +spatialCalScaleX=-1.0 +spatialCalScaleY=-1.0 spatialCalUnits=mm transpose=false diff --git a/devices/gsrx.properties b/devices/gsrx.properties index e6cb5eb..2324d5f 100644 --- a/devices/gsrx.properties +++ b/devices/gsrx.properties @@ -1,8 +1,9 @@ -#Tue Aug 30 17:48:06 CEST 2016 +#Tue Jun 13 10:51:13 CEST 2017 maxValue=1.0 minValue=-1.0 offset=0.0 precision=3 resolution=NaN +rotation=false scale=1.0 unit=mrad diff --git a/devices/gsry.properties b/devices/gsry.properties index e6cb5eb..2324d5f 100644 --- a/devices/gsry.properties +++ b/devices/gsry.properties @@ -1,8 +1,9 @@ -#Tue Aug 30 17:48:06 CEST 2016 +#Tue Jun 13 10:51:13 CEST 2017 maxValue=1.0 minValue=-1.0 offset=0.0 precision=3 resolution=NaN +rotation=false scale=1.0 unit=mrad diff --git a/devices/gsx.properties b/devices/gsx.properties index 28e6a3c..af3dd05 100644 --- a/devices/gsx.properties +++ b/devices/gsx.properties @@ -1,8 +1,9 @@ -#Tue Aug 30 17:48:06 CEST 2016 +#Tue Jun 13 10:51:13 CEST 2017 maxValue=1.0 minValue=-1.0 offset=0.0 precision=3 resolution=NaN +rotation=false scale=1.0 unit=mm diff --git a/devices/gsy.properties b/devices/gsy.properties index 28e6a3c..af3dd05 100644 --- a/devices/gsy.properties +++ b/devices/gsy.properties @@ -1,8 +1,9 @@ -#Tue Aug 30 17:48:06 CEST 2016 +#Tue Jun 13 10:51:13 CEST 2017 maxValue=1.0 minValue=-1.0 offset=0.0 precision=3 resolution=NaN +rotation=false scale=1.0 unit=mm diff --git a/devices/gun_phase.properties b/devices/gun_phase.properties index 5b67728..5491644 100755 --- a/devices/gun_phase.properties +++ b/devices/gun_phase.properties @@ -1,8 +1,9 @@ -#Tue May 10 09:59:44 CEST 2016 +#Tue Jun 13 10:51:13 CEST 2017 maxValue=180.0 minValue=-179.99 offset=0.0 precision=2 resolution=1.0 +rotation=false scale=1.0 unit=DEG diff --git a/devices/gun_solenoid.properties b/devices/gun_solenoid.properties index 8847a09..f42bcc8 100644 --- a/devices/gun_solenoid.properties +++ b/devices/gun_solenoid.properties @@ -1,8 +1,9 @@ -#Tue Jun 21 10:12:48 CEST 2016 +#Tue Jun 13 10:51:13 CEST 2017 maxValue=210.0 minValue=0.0 offset=0.0 precision=3 resolution=0.02 +rotation=false scale=1.0 unit=A diff --git a/plugins/GunScan.form b/plugins/GunScan.form index 283a5ed..1aa35fe 100644 --- a/plugins/GunScan.form +++ b/plugins/GunScan.form @@ -25,14 +25,20 @@ - - - + + + + + + + + + + + + - - - diff --git a/plugins/GunScan.java b/plugins/GunScan.java index b6eb8b7..182aa00 100644 --- a/plugins/GunScan.java +++ b/plugins/GunScan.java @@ -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") // //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; }); diff --git a/script/Alignment/Gun_solenoid_alignment.py b/script/Alignment/Gun_solenoid_alignment.py index dc51401..c590991 100755 --- a/script/Alignment/Gun_solenoid_alignment.py +++ b/script/Alignment/Gun_solenoid_alignment.py @@ -46,7 +46,8 @@ centroid_plot.addSeries(scan_series) scan_series.setLinesVisible(False) scan_series.setPointSize(4) -#Simulation +#Testing +""" camera_name = "SLG-LCAM-C041" def laser_on(): print "Laser On" @@ -56,6 +57,7 @@ def switch_off_magnets(magnets = None): pass add_device(DummyPositioner("gun_solenoid"), True) do_elog = False +""" laser_was_on = is_laser_on() original_gun_solenoid = gun_solenoid.read() diff --git a/script/Alignment/Laser_gun_alignment.py b/script/Alignment/Laser_gun_alignment.py index 2de2c69..2c83127 100755 --- a/script/Alignment/Laser_gun_alignment.py +++ b/script/Alignment/Laser_gun_alignment.py @@ -46,6 +46,7 @@ centroid_plot.addSeries(scan_series) scan_series.setLinesVisible(False) scan_series.setPointSize(4) +""" #Testing camera_name = "SLG-LCAM-C041" def laser_on(): @@ -56,7 +57,8 @@ def switch_off_magnets(magnets = None): pass add_device(DummyPositioner("gun_phase"), True) do_elog = False - +""" + laser_was_on = is_laser_on() original_phase = gun_phase.read() multiple_background = multiple_background and use_background diff --git a/script/RFscan/GunScan.py b/script/RFscan/GunScan.py index fb2e08c..814da05 100644 --- a/script/RFscan/GunScan.py +++ b/script/RFscan/GunScan.py @@ -1,6 +1,10 @@ -import ch.psi.pshell.epics.ControlledVariable as ControlledVariable +import ch.psi.pshell.epics.Positioner as Positioner import ch.psi.pshell.epics.Camtool as Camtool +#Parameters +dry_run = False +do_elog = True +camera_name = "SINBD01-DSCR010" if get_exec_pars().source == CommandSource.ui: start = 45.0 stop = 55.0 @@ -9,6 +13,7 @@ if get_exec_pars().source == CommandSource.ui: lat = 0.3 disp = -0.32 energy0 = 7.1 + plt = plot(None, title="Output")[0] else: start = args[0] stop = args[1] @@ -17,46 +22,84 @@ else: lat = args[4] disp = args[5] energy0 = args[6] + plt = args[7] -phase = ControlledVariable("Phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE") -#phase = ControlledVariable("Phase", "STEST01-RSYS:SET-BEAM-PHASE", "STEST01-RSYS:GET-BEAM-PHASE") -phase.config.minValue =-180.0 -phase.config.maxValue = 360.0 + +#Plot setup +plt.clear() +plt.setStyle(plt.Style.ErrorY) +plt.addSeries(LinePlotErrorSeries("Energy")) +plt.addSeries(LinePlotErrorSeries("Energy Spread", None, 2)) +plt.getAxis(plt.AxisId.X).setLabel("Gun Phase") +plt.getAxis(plt.AxisId.Y).setLabel("Energy (MeV)") +plt.getAxis(plt.AxisId.Y2).setLabel("Energy Spread (MeV)") +plt.setLegendVisible(True) + + +#Creating Phase positioner +if dry_run: + phase = Positioner("Phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM") + #phase = DummyPositioner("Phase") + camera_name = "SLG-LCAM-C041" + do_elog = False +else: + phase = Positioner("Phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE") +phase.config.minValue = -180.0 +phase.config.maxValue = 180.0 phase.config.precision = 3 phase.config.resolution = 1.0 +phase.config.rotation = True phase.config.save() phase.initialize() - phase0 = phase.read() +#Camtool setup #kill_camtool() check_camtool() -camtool.start("SINBD01-DSCR010") +camtool.start(camera_name) wait_camtool_message() - x = camtool.stream.getChild("x_fit_mean") dx = camtool.stream.getChild("x_fit_standard_deviation") + +#Creating averagers +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 + + +#Record callback: uptate of output plot +def after_sample(record, scan): + global energy0, disp + x_fit_mean, x_fit_mean_sigma, = record.values[0].mean, record.values[0].stdev + x_fit_std, x_fit_std_sigma = record.values[1].mean, record.values[1].stdev + E_mean, E_std = energy0 * (1 + x_fit_mean / 1e6 / disp), abs(energy0 * (x_fit_mean_sigma / 1e6 / disp)) + dE_mean, dE_std = abs(energy0 * (x_fit_std / 1e6 / disp)), abs(energy0 * (x_fit_std_sigma / 1e6 / disp)) + plt.getSeries(0).appendData(record.positions[0], E_mean, E_std) + plt.getSeries(1).appendData(record.positions[0], dE_mean, dE_std) + + +#The scan loop try: - 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 - time.sleep(1.0) - r = lscan(phase, [xb, dxb], start, stop, step , latency=lat) - rf_phase = r.getPositions(0) - E = [energy0 * (1 + val.mean / 1e6 / disp) for val in r.getReadable(0)] - dE = [abs(energy0 * (val.mean / 1e6 / disp)) for val in r.getReadable(1)] + r = lscan(phase, [xb, dxb], start, stop, step , latency=lat, after_read = after_sample) finally: phase.write(phase0) - #phase.close() - #camtool.stop() # stops camtool but does not close it camtool is a global object + phase.close() + camtool.stop() # stops camtool but does not close it camtool is a global object -p = plot(None, title="Output")[0] -p.clear() -p.addSeries(LinePlotSeries("Energy")) -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 +#Saving metadata +E = [energy0 * (1 + val.mean / 1e6 / disp) for val in r.getReadable(0)] +dE = [abs(energy0 * (val.mean / 1e6 / disp)) for val in r.getReadable(1)] +save_dataset(get_exec_pars().group + "/E", E) +save_dataset(get_exec_pars().group + "/dE", dE) + +if do_elog: + if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes": + log_msg = "Data file: " + get_exec_pars().path + #log_msg = log_msg + "\n\n" + r.print() + + sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition + file_name = os.path.abspath(get_context().setup.getContextPath() + "/GunScanPlot.png") + plt.saveSnapshot(file_name , "png") + elog("Gun scan", log_msg, [file_name,]) diff --git a/script/RFscan/SchottkyScan_sim.py b/script/RFscan/SchottkyScan_sim.py index bd202a1..c027e6a 100644 --- a/script/RFscan/SchottkyScan_sim.py +++ b/script/RFscan/SchottkyScan_sim.py @@ -1,11 +1,11 @@ import ch.psi.pshell.epics.ControlledVariable as ControlledVariable if get_exec_pars().source == CommandSource.ui: - start = -10.0 - stop = 180.0 + start = 20.0 + stop = 140.0 step = 5.0 - nb = 3 - lat = 0.300 + nb = 2 + lat = 0.100 else: start = args[0] stop = args[1] @@ -13,48 +13,39 @@ else: nb = int(args[3]) lat = args[4] -bphase = ControlledVariable("Beam phase", "SINEG01-RSYS:SET-VSUM-PHASE-SIM", "SINEG01-RSYS:GET-VSUM-PHASE-SIM") -bphase.config.minValue =-180.0 -bphase.config.maxValue = 360.0 -bphase.config.precision = 3 -bphase.config.resolution = 1.0 -bphase.config.save() -bphase.initialize() -st = Stream("Schottky stream", dispatcher) -#q = st.addScalar("Charge", "SINEG01-DICT215:B1_CHARGE", 1, 0) -#rphase = st.addScalar("RF phase", "SINEG01-RSYS:GET-VSUM-PHASE", 1, 0) -st.initialize() -st.start() -q = Channel("SINEG01-DICT215:B1_CHARGE-SIM", type = 'd', alias = 'ICT-Q') -rphase = Channel("SINEG01-RSYS:GET-BEAM-PHASE-SIM", type = 'd', alias = 'RF phase') +bph = ControlledVariable("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM") +bph.config.minValue =-180.0 +bph.config.maxValue = 360.0 +bph.config.precision = 3 +bph.config.resolution = 1.0 +bph.config.save() +bph.initialize() +rph = Channel("SINEG01-RSYS:SET-VSUM-PHASE-SIM", type = 'd', alias = 'RF phase') +q = Channel("SINEG01-DICT215:B1_CHARGE-SIM", type = 'd', alias = 'ICT-Q') -bphase0 = bphase.read() -print bphase0 -print q.read() -print rphase.read() +rph0 = rph.read() try: - q_averager = create_averager(q, nb, 0.100) - rphase_averager = create_averager(rphase, nb, 0.100) - r = lscan(bphase, (q_averager, rphase_averager), start, stop, step, latency=lat) + q_averager = create_averager(q, nb, 0.100) + rph_averager = create_averager(rph, nb, 0.100) + r = lscan(bph, (rph_averager, q_averager), start, stop, step, latency=lat) beamphase = r.getPositions(0) - charge = [val.mean for val in r.getReadable(0)] - chargerms = [val.stdev for val in r.getReadable(0)] - rfphase = [val.mean for val in r.getReadable(1)] - rfphaserms = [val.stdev for val in r.getReadable(1)] + 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: - bphase.write(bphase0) - bphase.close() - st.close() + rph.write(rph0) + bph.close() + rph.close() q.close() - rphase.close() #Setting the return value index_max = charge.index(max(charge)) -rphase_ref = rfphase[index_max] - 80 -bphase_ref = beamphase[index_max] - 80 +bph_ref = beamphase[index_max] - 80 +rph_ref = rfphase[index_max] - 80 -print rphase_ref -print bphase_ref +print bph_ref +print rph_ref -set_return(rphase_ref) +set_return(bph_ref, rph_ref)