This commit is contained in:
sfop
2017-01-24 10:24:17 +01:00
parent 607a4f934c
commit 807ec0da5c
3 changed files with 162 additions and 0 deletions

28
plugins/GunScan.form Normal file
View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="449" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="137" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Form>

56
plugins/GunScan.java Normal file
View File

@@ -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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

78
script/RFscan/GunScan.py Normal file
View File

@@ -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)