Script execution
This commit is contained in:
@@ -14,17 +14,16 @@ bpm_ch = caget(prefix + ":DBPM")
|
||||
disp = caget(bpm_ch + ":DISPERSION")
|
||||
energy0 = caget(bpm_ch + ":ENERGY")
|
||||
|
||||
rf_phase_var = ControlledVariable("Phase", prefix + ":SET-VSUM-PHASE-SIM", prefix + ":GET-VSUM-PHASE-SIM")
|
||||
rf_phase_var.config.minValue =-45.0
|
||||
rf_phase_var.config.maxValue = 360.0
|
||||
rf_phase_var.config.resolution = 0.5
|
||||
rf_phase_var.initialize()
|
||||
phase = ControlledVariable("Phase", prefix + ":SET-VSUM-PHASE-SIM", prefix + ":GET-VSUM-PHASE-SIM")
|
||||
phase.config.minValue =-45.0
|
||||
phase.config.maxValue = 360.0
|
||||
phase.config.resolution = 0.5
|
||||
phase.initialize()
|
||||
|
||||
rf_ampl_rbk = Channel(prefix + ":GET-VSUM-AMPLT-SIM", type = 'd', alias='Amplitude Readback')
|
||||
#rf_ampl_rbk.write(1.0)
|
||||
rf_power_rbk = Channel(prefix + ":GET-KLY-POWER-SIM", type = 'd', alias='Power Readback')
|
||||
V = Channel(prefix + ":GET-VSUM-AMPLT-SIM", type = 'd', alias='Amplitude Readback')
|
||||
P = Channel(prefix + ":GET-KLY-POWER-SIM", type = 'd', alias='Power Readback')
|
||||
|
||||
bpm_x = Channel(bpm_ch + ":X1-SIMU", type = 'd', alias='BPM-X')
|
||||
x = Channel(bpm_ch + ":X1-SIMU", type = 'd', alias='BPM-X')
|
||||
|
||||
caput(prefix + ":GET-FIT-PHASE-ARRAY", to_array([0.0],'d'))
|
||||
caput(prefix + ":GET-FIT-ENERGY-ARRAY", to_array([0.0],'d'))
|
||||
@@ -41,17 +40,17 @@ arr_phase,arr_energy = [],[]
|
||||
def after(rec):
|
||||
global arrpos, arrval, disp, energy0
|
||||
arr_phase.append(rec.positions[0])
|
||||
arr_energy.append(rec.values[1]/1000.0/disp*energy0)
|
||||
caput(prefix + ":GET-ENERGY-ARRAY", to_array(arr_energy,'d'))
|
||||
arr_energy.append(rec.values[1]/1000.0/disp*energy0)
|
||||
caput(prefix + ":GET-ENERGY-ARRAY", to_array(arr_energy,'d'))
|
||||
caput(prefix + ":GET-PHASE-ARRAY", to_array(arr_phase,'d'))
|
||||
|
||||
try:
|
||||
av_ampl = create_averager(rf_ampl_rbk, nb, lat)
|
||||
av_x = create_averager(bpm_x, nb, lat)
|
||||
|
||||
r = lscan(rf_phase_var, [(av_ampl, av_ampl.samples), (av_x, av_x.samples)], start, stop, step , latency=lat, after_read = after)
|
||||
try:
|
||||
Vb = create_averager(V, nb, lat)
|
||||
xb = create_averager(x, nb, lat)
|
||||
|
||||
r = lscan(phase, [V, x], start, stop, step , latency=lat, after_read = after)
|
||||
rf_phase = r.getPositions(0)
|
||||
energy = [x/1000.0/disp*energy0 for x in r.getReadable(1)]
|
||||
energy = [x/1000.0/disp*energy0 for x in r.getReadable(1)]
|
||||
caput(prefix + ":GET-ENERGY-ARRAY", to_array(energy,'d'))
|
||||
caput(prefix + ":GET-PHASE-ARRAY", to_array(rf_phase,'d'))
|
||||
phase_fit_max = None
|
||||
@@ -66,25 +65,25 @@ try:
|
||||
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")
|
||||
rf_phase_var.write(phase_fit_max)
|
||||
phase.write(phase_fit_max)
|
||||
time.sleep(lat)
|
||||
ampl = rf_ampl_rbk.read()
|
||||
power = rf_power_rbk.read()
|
||||
caput(prefix + ":GET-ONCREST-VSUM-AMPLT", ampl)
|
||||
caput(prefix + ":GET-ONCREST-KLY-POWER", power)
|
||||
V = V.read()
|
||||
P = P.read()
|
||||
caput(prefix + ":GET-ONCREST-VSUM-AMPLT", V)
|
||||
caput(prefix + ":GET-ONCREST-KLY-POWER", P)
|
||||
finally:
|
||||
rf_phase_var.close()
|
||||
rf_ampl_rbk.close()
|
||||
rf_power_rbk.close()
|
||||
bpm_x.close()
|
||||
phase.close()
|
||||
V.close()
|
||||
P.close()
|
||||
x.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)
|
||||
amplitude_scale = energy_gain / V
|
||||
power_scale = P / math.pow(V,2)
|
||||
|
||||
caput(prefix + ":CALC-VSUM-PHASE-OFFSET", phase_offset)
|
||||
caput(prefix + ":CALC-VSUM-AMPLT-SCALE" , amplitude_scale)
|
||||
|
||||
Reference in New Issue
Block a user