From d60872d277553852874ec91463d7d8463404bbff Mon Sep 17 00:00:00 2001 From: voulot_d Date: Thu, 24 Aug 2017 08:59:58 +0200 Subject: [PATCH] Script execution --- script/Diagnostics/ICT_timing_fine.py | 63 +++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 script/Diagnostics/ICT_timing_fine.py diff --git a/script/Diagnostics/ICT_timing_fine.py b/script/Diagnostics/ICT_timing_fine.py new file mode 100644 index 0000000..b509c5a --- /dev/null +++ b/script/Diagnostics/ICT_timing_fine.py @@ -0,0 +1,63 @@ +import ch.psi.pshell.epics.ChannelDouble as ChannelDouble + +run("CPython/wrapper") + +#base_name = "SINEG01-DICT009" # "S10DI01-DICT113" "SARMA01-DICT482" "SARBD01-DICT599" +#dev_name = "SINEG01-DICT215" # "S10DI01-DICT025" "SARMA01-DICT090" "SARBD01-DICT030" +#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 = 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") + +t.initialize() +q.initialize() +V.initialize() + +t0 = t.read() + +start = 2.2 +stop = 12.7 +step = 0.1 +nb = 5 +lat = 0.150 + +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) + 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-10, 0), min(i_max+11, 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") + +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) +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)