Files
sf-op/script/Diagnostics/ICT_timing_fine.py
root c73f2d0968
2017-10-19 11:31:51 +02:00

88 lines
3.3 KiB
Python

import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
dry_run = False
do_elog = True
base_name = "SINEG01-DICT009" # SINEG01-DICT009 S10DI01-DICT113 SARMA01-DICT482 SARBD01-DICT599
dev_name = "SINEG01-DICT215" # SINEG01-DICT215 S10DI01-DICT025 SARMA01-DICT090 SARBD01-DICT030
run("CPython/wrapper")
if dry_run:
t = ChannelDouble("fine delay (ns)", "SINEG01-DICT215:Pul1-Delay-SP-SIM")
q = ChannelDouble("charge (pC)", "SINEG01-DICT215:AL1-ICT-CHARGE-SIM")
V = ChannelDouble("DC output (V)", "SINEG01-DICT215:AL1-ICT-VOLTAGE-SIM")
else:
t = ChannelDouble("fine delay (ns)", base_name + "-EVR0:UnivDlyModule0-Delay0-SP")
q = ChannelDouble("charge (pC)", dev_name + ":B1_CHARGE")
V = ChannelDouble("DC output (V)", dev_name + ":B1_VOLTAGE")
t.initialize()
q.initialize()
V.initialize()
t0 = t.read()
start = 2.2
stop = 7.0
step = 0.1
nb = 10
lat = 0.150
plt = plot(None, title="Output")[0]
plt.clear()
plt.removeMarker(None)
plt.setStyle(plt.Style.ErrorY)
plt.addSeries(LinePlotErrorSeries("Charge", Color.red))
plt.addSeries(LinePlotErrorSeries("DC output", Color.yellow, 2))
plt.getAxis(plt.AxisId.X).setLabel("Fine delay (ns)")
plt.getAxis(plt.AxisId.Y).setLabel("Charge (pC)")
plt.getAxis(plt.AxisId.Y2).setLabel("DC output (V)")
plt.setLegendVisible(True)
def plot_point(record, scan):
global plt
q_mean, q_stdev = record.values[0].mean, record.values[0].stdev
V_mean, V_stdev = record.values[1].mean, record.values[1].stdev
plt.getSeries(0).appendData(record.positions[0], q_mean, q_stdev)
plt.getSeries(1).appendData(record.positions[0], V_mean, V_stdev)
try:
q_averager = create_averager(q, nb, lat)
V_averager = create_averager(V, nb, lat)
V_averager.monitored=True
r = lscan(t, (q_averager, V_averager), start, stop, step, latency=lat, after_read = plot_point)
delay = r.getPositions(0)
charge = [val.mean for val in r.getReadable(0)]
chargerms = [val.stdev for val in r.getReadable(0)]
volt = [val.mean for val in r.getReadable(1)]
voltrms = [val.stdev for val in r.getReadable(1)]
finally:
t.write(t0)
t.close()
q.close()
V.close()
try:
i_max = charge.index(max(charge))
min_i, max_i = max(i_max-30, 0), min(i_max+31, len(charge))
(delay_max, charge_max, delay_fit, charge_fit) = extremum(delay[min_i:max_i], charge[min_i:max_i])
print delay_max, charge_max
except:
raise Exception("Fit failure")
#update plot
plt.addSeries(LinePlotErrorSeries("Charge Fit", plt.getSeries(0).color))
plt.getSeries(2).setData(delay_fit, charge_fit)
plt.getSeries(2).setPointsVisible(False)
plt.addMarker(delay_max, plt.AxisId.X, "%3.2f" % delay_max, plt.getSeries(0).color)
#Elog entry
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 + "\n\n"
log_msg = log_msg + "delay_max: %8.3f" % delay_max + " ns \n"
log_msg = log_msg + "charge_max: %8.3f" % charge_max + " pC \n"
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() + "/ICT_timing_fine_Plot.png")
plt.saveSnapshot(file_name , "png")
elog("ICT timing scan fine", log_msg, [file_name,])