diff --git a/script/RFscan/phase_scan_caqtdm_dv.py b/script/RFscan/phase_scan_caqtdm_dv.py index a927fba..aa00aa7 100644 --- a/script/RFscan/phase_scan_caqtdm_dv.py +++ b/script/RFscan/phase_scan_caqtdm_dv.py @@ -6,6 +6,7 @@ stop = caget(prefix + ":SET-SCAN-STOP") step = caget(prefix + ":SET-SCAN-STEP") lat = caget(prefix + ":SET-SCAN-WAIT-TIME") bpm_ch = caget(prefix + ":BPM") +disp = caget(prefix + ":DISPERSION") print "Prefix = ", prefix print "Start = ", start @@ -20,8 +21,9 @@ rf_phase_var.config.maxValue = 180.0 rf_phase_var.config.resolution = 0.001 rf_phase_var.initialize() -rf_ampl_rbk = Channel(prefix + ":GET-VSUM-AMPLT", type = 'd', alias='Amplitude Readback') -bpm_x = Channel(bpm_ch, type = 'd', alias='BPM-X') +rf_ampl_rbk = Channel(prefix + ":GET-VSUM-AMPLT", type = 'd', alias='Amplitude Readback') +rf_power_rbk = Channel(prefix + ":GET-KLY-POWER", type = 'd', alias='Power Readback') +bpm_x = Channel(bpm_ch, type = 'd', alias='BPM-X') #TODO: update the plot dynamically def after(rec): @@ -30,43 +32,43 @@ def after(rec): try: r = lscan(rf_phase_var, [rf_ampl_rbk, bpm_x], start, stop, step , latency=lat, after_read = after) - phase = r.getPositions(0) - ampl = r.getReadable(0) - x = r.getReadable(1) + rf_phase = r.getPositions(0) + energy = r.getReadable(1) * disp - #plot(r.getReadable(1), xdata = r.getPositions(0), title = "data") phase_fit_max = None try: - (amplitude, angular_frequency, phase, phase_fit_max) = hfit(x , xdata = phase) + (energy_max, angular_frequency, phase0, phase_fit_max) = hfit(energy , xdata = rf_phase) except: raise Exception("Fit failure") - start,end = min(phase), max(phase) - if not (start <= phase_fit_max <= end): + phase_min, phase_max = min(phase), max(phase) + if not (phase_min <= phase_fit_max <= phase_max): raise Exception("Fit maximum outside scan range") rf_phase_var.write(phase_fit_max) time.sleep(lat) - a0 = rf_ampl_readback.read() - power = 1.0 #TODO + ampl = rf_ampl_readback.read() + power = rf_power_rbk.read() finally: rf_phase_var.close() rf_ampl_rbk.close() + rf_power_rbk.close() + bpm_x.close() print ("------------------------------------") print ("Valid fit") -energy_gain = amplitude +energy_gain = energy_max phase_offset = - phase_fit_max -amplitude_scale = energy_gain / a0 -power_scale = power / math.pow(a0,2) +amplitude_scale = energy_gain / ampl +power_scale = power / math.pow(ampl,2) caput(prefix + ":CALC-VSUM-PHASE-OFFSET", phase_offset) -caput(prefix + ":CALC-VSUM-AMPLT-SCALE", amplitude_scale) -caput(prefix + ":CALC-VOLT-POWER-SCALE", power_scale) +caput(prefix + ":CALC-VSUM-AMPLT-SCALE" , amplitude_scale) +caput(prefix + ":CALC-VOLT-POWER-SCALE" , power_scale) -set_return("Energy Gain: " + str(energy_gain) + - "\nPhase Offset: " + str(phase_offset) + - "\nAmplitude Scale: " + str(amplitude_scale) + - "\nPower Scale: " + str(power_scale)) +set_return("Energy Gain: " + str(energy_gain) + "\n" + + "Phase Offset: " + str(phase_offset) + "\n" + + "Amplitude Scale: " + str(amplitude_scale) + "\n" + + "Power Scale: " + str(power_scale))