Commit 0bf17bd1 authored by Marin Collonge's avatar Marin Collonge
Browse files

Merge branch 'sus_dev' into ESRFTesting

parents edcbd566 745decf1
......@@ -246,6 +246,13 @@
<Attr Name="UsedIn" Val="simulation"/>
</FileInfo>
</File>
<File Path="$PPRDIR/../hdl/src/subframe_start_delay.sv">
<FileInfo>
<Attr Name="UsedIn" Val="synthesis"/>
<Attr Name="UsedIn" Val="implementation"/>
<Attr Name="UsedIn" Val="simulation"/>
</FileInfo>
</File>
<File Path="$PPRDIR/../hdl/src/ASICControl/telegram_sender.sv">
<FileInfo>
<Attr Name="UsedIn" Val="synthesis"/>
......@@ -461,6 +468,7 @@
<Step Id="post_route_phys_opt_design"/>
<Step Id="write_bitstream" PostStepTclHook="$PPRDIR/write_svf.tcl"/>
</Strategy>
<GeneratedRun Dir="$PRUNDIR" File="gen_run.xml"/>
<ReportStrategy Name="Vivado Implementation Default Reports" Flow="Vivado Implementation 2018"/>
<Report Name="ROUTE_DESIGN.REPORT_METHODOLOGY" Enabled="1"/>
<RQSFiles/>
......
......@@ -17,19 +17,19 @@ module push_data_provider (
import Readout::cIDLE_WORD;
bit [5:0] current_word;
bit [7:0] current_word;
always_ff @(posedge WORD_CLK) begin
if (current_word >= DATA_IN.pattern_length - 1) begin
current_word <= 6'd0;
current_word <= 8'd0;
if (!RESET_STATS) SENT_COUNT <= SENT_COUNT + 1'd1;
end else current_word <= current_word + 6'd1;
end else current_word <= current_word + 8'd1;
if (RESET_STATS) SENT_COUNT <= 16'd0;
end
assign SUBFRAME_START = (current_word == 6'b0) ? 1'b1 : 1'b0;
assign SUBFRAME_START = (current_word == 8'b0) ? 1'b1 : 1'b0;
always_comb DATA_OUT = ENABLE ? DATA_IN.data[current_word] : cIDLE_WORD;
......
......@@ -29,8 +29,8 @@ package Readout;
} pattern_word_t;
typedef struct packed {
pattern_word_t [63:0] data;
logic [5:0] pattern_length;
pattern_word_t [255:0] data;
logic [7:0] pattern_length;
} pattern_t;
......
......@@ -78,11 +78,10 @@ module XIDer_top (
.VAL({subframe_start_delay, daq_reset, long_frames, init_link, reset, asic_seq_run}),
.UPDATED_TOGGLE()
);
jtag_reg #(
.P_JTAG_CHAIN(2),
.P_LENGTH($bits(pattern)),
.P_INIT_VALUE(pattern_t'{data : {{64{cIDLE_WORD}}}, pattern_length : 6'd4})
.P_INIT_VALUE(pattern_t'{data : {{256{cIDLE_WORD}}}, pattern_length : 8'd4})
) jtag2_I (
.VAL(pattern),
.UPDATED_TOGGLE()
......
......@@ -18,8 +18,6 @@ from collections import OrderedDict
def line(x, m, c):
return m*x+c
def errfunc(x,A,mu,sig):
return A*scipy.special.erfc((x-mu)/(sig*np.sqrt(2)))
......@@ -39,6 +37,8 @@ def getFECntsFromHdf5(hdf5InputFile, pathToDataset, scaling):
#print("pathToDataset", pathToDataset)
inputData = hdf5InputFile[pathToDataset]
keys = inputData.keys()
#print("FEkeys", keys)
#print("scaling", scaling)
FE_cnts = {}
for i in np.arange(len(keys)):
if(re.match(r"^FE\d\d?$", list(keys)[i])):
......@@ -80,21 +80,20 @@ def drawPlotIntoHdf5File(fig, path, hdf5OutputFile):
idata = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
idata = idata.reshape(fig.canvas.get_width_height()[::-1] + (3,))
testset = hdf5OutputFile.create_dataset(path, data=idata, dtype='uint8',chunks=True)
testset.attrs.create('CLASS', 'IMAGE')
testset.attrs.create('IMAGE_VERSION', '1.2')
testset.attrs.create('IMAGE_SUBCLASS', 'IMAGE_TRUECOLOR')
testset.attrs.create('INTERLACE_MODE', 'INTERLACE_PIXEL')
plt.close(fig)
#plt.close(fig)
def plotDataVsXSingle(FEname, FEdata, DAC, xlabel, FEStdevs=[-1]):
print(FEdata)
print(FEStdevs)
#print(FEdata)
#print(FEStdevs)
if(np.array_equal(FEStdevs, [-1])):
print("was here 2")
FEStdevs = np.zeros(len(FEdata))
xaxis = DAC
......@@ -108,6 +107,10 @@ def plotDataVsXSingle(FEname, FEdata, DAC, xlabel, FEStdevs=[-1]):
capsize = 0
else:
capsize = 2
#print("xaxis", xaxis)
#print("FEdata", FEdata)
#print(FEStdevs)
ax.errorbar(xaxis, FEdata, fmt = 'o', yerr = FEStdevs, label = FEname + " counts", markersize=0.1, capsize=capsize)
#xlabel = "COMP0_Vthresh_p"
ax.set_xlabel(xlabel)
......@@ -119,16 +122,15 @@ def plotDataVsXSingle(FEname, FEdata, DAC, xlabel, FEStdevs=[-1]):
def plotDataVsXAll(FEAvgs, DAC, xlabel, FEStdevs = [-1]):
keys = FEAvgs.keys()
print("was here")
print("FEStdevs", FEStdevs)
print(keys)
#print("FEStdevs", FEStdevs)
#print(keys)
figs = {}
for i in np.arange(len(keys)):
FEname = keys[i]
FEdata = FEAvgs[FEname]
if(FEStdevs != [-1]):
FEStdevs = FEStdevs[FEname]
print("FEStdevs", FEStdevs)
#print("FEStdevs", FEStdevs)
fig = plotDataVsXSingle(FEname, FEdata, DAC, xlabel, FEStdevs)
figs[FEname] = fig
return figs
......@@ -144,7 +146,9 @@ def plotAndFitSCurveAll(FEAvgs, DAC, DAC_name, hdf5OutputFile, stdevFactor=1, pa
FEname = list(keys)[i]
FEdata = FEAvgs[FEname]
#print(FEname,FEdata)
print(FEname)
#print(FEname)
# if(FEname == "FE8"):
# print(FEdata)
fig = plotDataVsXSingle(FEname, FEdata, DAC, DAC_name)
edge = findEdge(FEdata, DAC)
......@@ -164,9 +168,14 @@ def plotAndFitSCurveAll(FEAvgs, DAC, DAC_name, hdf5OutputFile, stdevFactor=1, pa
elif(((FEdata_fit[j+1]-FEdata_fit[j]) > 0.2) and ((FEdata_fit[j-1]-FEdata_fit[j]) > 0.2)):
rejected_indices = np.append(rejected_indices, j)
rejected_indices = np.int_(rejected_indices)
DAC_fit = np.copy(DAC)
#print("FEdata_it", FEdata_fit)
#print(rejected_indices)
FEdata_fit = np.delete(FEdata_fit, rejected_indices)
DAC_fit = np.delete(DAC_fit, rejected_indices)
baseline = -1
baseline_error = 0
try:
#popt1, pcov1 = curve_fit(errfunc, DAC_fit, FEdata_fit, p0 = [1/3., edge, 3])
popt1, pcov1 = curve_fit(errfunc, DAC_fit, FEdata_fit, p0 = [1., edge, 3])
......@@ -208,14 +217,16 @@ def plotAndReturnStdDevsAndBaseAcrossFEs(hdf5OutputFile, pathToDataset):
baselines_str = str(hdf5OutputFile[pathToDataset].attrs['baselines'])
print(baselines_str)
#print(baselines_str)
baselines = ast.literal_eval(baselines_str)
x = np.array(stdevs.keys())
x = list(stdevs.keys())
#print("x", x)
#print(x)
#values = np.array(stdevs.items())[:,1]
values_std = np.array(stdevs.values())
values_base = np.array(baselines.values())
values_std = np.array(list(stdevs.values()))
values_base = np.array(list(baselines.values()))
#print(values_std, values_base)
#print(values)
y_std = values_std[:,0]
y_base = values_base[:,0]
......@@ -236,7 +247,7 @@ def plotAndReturnStdDevsAndBaseAcrossFEs(hdf5OutputFile, pathToDataset):
sorted_y_std = np.float_(sorted_y_std)
sorted_y_base = np.float_(sorted_y_base)
# print(sorted_x)
# print_x)
# print(sorted_y)
for i in np.arange(len(sorted_x)):
......@@ -264,6 +275,7 @@ def plotAndReturnStdDevsAndBaseAcrossFEs(hdf5OutputFile, pathToDataset):
def plotAndDrawToHDF5File(x,xlabel,y,ylabel,hdf5OutputFile, path, plotType = 'line'):
fig, ax = plt.subplots(dpi=150)
if(plotType == 'line'):
ax.plot(x, y)
......@@ -281,6 +293,7 @@ def plotAndDrawToHDF5File(x,xlabel,y,ylabel,hdf5OutputFile, path, plotType = 'li
drawPlotIntoHdf5File(fig, path, hdf5OutputFile)
def plotAndDrawToHDF5FileError(x,xlabel,y,yerror,ylabel,hdf5OutputFile, path, plotType = 'line'):
print("PATH", path)
fig, ax = plt.subplots(dpi=150)
ax.errorbar(x, y, yerr=yerror, fmt=' ', marker='o', markersize=2, capsize=4, elinewidth=2)
......
This diff is collapsed.
......@@ -53,7 +53,9 @@ def configSigSweep_recursive_Splot( hdf5File,
scaling = 8
else:
scaling = 1
print("pathToDataset", pathToDataset)
FE_cnts = base.getFECntsFromHdf5(hdf5InputFile, pathToDataset, scaling)
print("FE_cnts",FE_cnts)
FE_names = FE_cnts.keys()
#print("FE_cnts", FE_cnts)
FE_avgs, FE_stdevs = base.calcAvgsAndStdDevsSingleAll(FE_cnts)
......@@ -61,6 +63,7 @@ def configSigSweep_recursive_Splot( hdf5File,
match_regEx = re.compile('Edge Finder*')
match_found = 0
match = ''
DAC_key = "COMP0_Vthresh_p"
for i in np.arange(len(tmp)):
if(match_regEx.match(tmp[i])):
match_found = match_regEx.match(tmp[i])
......@@ -69,15 +72,28 @@ def configSigSweep_recursive_Splot( hdf5File,
#print(re.compile('FE*').match(hdf5InputFile[pathToDataset].keys())
# print(re.compile('FE*').match(hdf5InputFile[pathToDataset].keys())
DAC_keys = np.array([])
if(match_found):
DAC_data = hdf5InputFile[pathToDataset + '/' + match]
print("was here")
else:
DAC_key = list(hdf5InputFile.keys())[-1]
DAC_data = hdf5InputFile[DAC_key]
# print("hdf5File keys", hdf5InputFile["DAC Sweep"].keys())
keys = list(hdf5InputFile["DAC Sweep"].keys())
DAC_regEx = re.compile('DAC Values*')
for i in np.arange(len(keys)):
if(DAC_regEx.match(keys[i])):
DAC_keys = np.append(DAC_keys, keys[i])
print(DAC_keys)
DAC_key = DAC_keys[-1]
DAC_data = hdf5InputFile["DAC Sweep/" + DAC_key]
print("was here2")
print("DAC_data", DAC_data)
# print(hdf5OutputFile)
stdevs_tmp,baselines_tmp = base.plotAndFitSCurveAll(FE_avgs, DAC_data, hdf5OutputFile, stdevFactor=stdevFactor, pathToDataset=pathToDataset)
#stdevs_tmp,baselines_tmp = base.plotAndFitSCurveAll(FE_avgs, DAC_data, hdf5OutputFile, stdevFactor=stdevFactor, pathToDataset=pathToDataset)
stdevs_tmp,baselines_tmp = base.plotAndFitSCurveAll(FE_avgs, DAC_data, DAC_key, hdf5OutputFile, stdevFactor=1, pathToDataset=pathToDataset)
stdevs = stdevs.update({pathToDataset: stdevs_tmp})
baselines = baselines.update({pathToDataset: baselines_tmp})
......@@ -184,7 +200,8 @@ except:
hdf5InputFile = h5py.File(pathToMeasurement, 'r')
sweptSigs = hdf5InputFile.attrs['Swept DACs']
topGroup = hdf5InputFile['DAC Sweep']
sweptSigs = topGroup.attrs['Swept DACs']
sweptSigs_dict = OrderedDict()
......@@ -196,11 +213,12 @@ hdf5OutputFile = h5py.File(hdf5OutputFileName, 'w')
if(len(sweptSigs) > 0):
for i in np.arange(len(sweptSigs)):
#print(hdf5InputFile['DAC Values ' + str(sweptSigs[i])])
DACvalues = hdf5InputFile['DAC Values ' + sweptSigs[i]]
#DACvalues = hdf5InputFile['DAC Values ' + sweptSigs[i]]
DACvalues = topGroup['DAC Values ' + sweptSigs[i]]
sweptSigs_dict[sweptSigs[i]] = DACvalues.value
stdevs = {}
baselines = {}
configSigSweep_recursive_Splot(hdf5InputFile, sweptSigs_dict, pathToDataset="DAC Sweep", hdf5OutputFile=hdf5OutputFile, stdevFactor=stdevFactor, stdevs=stdevs, baselines=baselines)
configSigSweep_recursive_Splot(hdf5InputFile, sweptSigs_dict, pathToDataset="/DAC Sweep", hdf5OutputFile=hdf5OutputFile, stdevFactor=stdevFactor, stdevs=stdevs, baselines=baselines)
#print("stdevs", stdevs)
......
......@@ -2,22 +2,35 @@ import numpy as np
import h5py
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.gridspec as gridspec
import matplotlib as mpl
import re
from scipy.optimize import curve_fit
import scipy
import pickle
import io
from collections import OrderedDict
import base
import sys
def calcSatPhotAmount(Cf, photEnergy, satVoltage):
elemCharge_C = 1.60218e-19
ehCreationEnergyCdTe_eV = 4.43
satPhotAmount = Cf*satVoltage/(photEnergy/ehCreationEnergyCdTe_eV*elemCharge_C)
return satPhotAmount
def calcPhotsFromInjectDAC(DAC_vals, injectCapa_F):
elemCharge_C = 1.60218e-19
ehCreationEnergyCdTe_eV = 4.43
photonEnergy_eV = 30e3
#electronsPerPhoton = photonEnergy_eV/ehCreationEnergyCdTe_eV
electronsPerPhoton = 6000
electronsPerPhoton = photonEnergy_eV/ehCreationEnergyCdTe_eV
# electronsPerPhoton = 6000
chargePerPhoton_C = electronsPerPhoton*elemCharge_C
injectedCharge_C = DAC_vals*1000./1023.*1e-3*injectCapa_F
......@@ -31,7 +44,8 @@ def configSigSweep_recursive_injectPlot( hdf5InputFile,
pathToDataset='',
currIndex=0,
#hdf5OutputFile = h5py.File("basetest.h5", 'w')
hdf5OutputFile = h5py.File("test.h5", 'w')
hdf5OutputFile = h5py.File("test.h5", 'w'),
isDualInject=0
):
last_iteration = len(sigs) - 1
if (iteration < last_iteration):
......@@ -44,7 +58,7 @@ def configSigSweep_recursive_injectPlot( hdf5InputFile,
if (iteration < last_iteration):
pathToDataset += '/' \
+ currUniqueSigName + ' ' + str(currSigValues[i])
configSigSweep_recursive_Splot(
configSigSweep_recursive_injectPlot(
hdf5InputFile,
sigs,
iteration=iteration + 1,
......@@ -72,47 +86,246 @@ def configSigSweep_recursive_injectPlot( hdf5InputFile,
# print(hdf5OutputFile)
FE_figs = base.plotDataVsXAll(FE_avgs, DAC_data, DAC_key)
FE_figs_calcPhotsX = base.plotDataVsXAll(FE_avgs, calcInjectedPhotons, xlabel, FEStdevs=FE_stdevs)
FE_figs_calcPhotsX_wfit = base.plotDataVsXAll(FE_avgs, calcInjectedPhotons, xlabel, FEStdevs=FE_stdevs)
for i in np.arange(len(FE_figs)):
print(FE_figs.keys()[i])
base.drawPlotIntoHdf5File(FE_figs[FE_figs.keys()[i]], pathToDataset, hdf5OutputFile)
base.drawPlotIntoHdf5File(FE_figs_calcPhotsX[FE_figs_calcPhotsX.keys()[i]], pathToDataset + '_calculated_injected_photons', hdf5OutputFile)
popt, pcov = curve_fit(base.line, calcInjectedPhotons[0:300], FE_avgs[FE_avgs.keys()[i]][0:300])
m = popt[0]
c = popt[1]
fitPlot = FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]].axes[0]
fitPlot.plot(calcInjectedPhotons, base.line(calcInjectedPhotons, m, c), label = "m = {:.2f}".format(m) + "\nc = {:.2f}".format(c))
plt.legend()
# FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]].axes[0].plot(calcInjectedPhotons, base.line(calcInjectedPhotons, m, c), label = "m = " + str(m) + "\nc = " + str(c))
base.drawPlotIntoHdf5File(FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]], pathToDataset + '_calculated_injected_photons with linear Fit', hdf5OutputFile)
gs = gridspec.GridSpec(5,1)
# fitPlot.change_geometry(5,1,(1,4))
fitPlot.set_position(gs[0:4].get_position(FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]]))
residualPlot = FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]].add_subplot(gs[4])
residuals = base.line(calcInjectedPhotons, m, c) - FE_avgs[FE_avgs.keys()[i]]
residualPlot.plot(calcInjectedPhotons, residuals)
satPhotAmount = calcSatPhotAmount(50e-15, 30e3, 800e-3)
fitPlot.axvline(x=satPhotAmount, ymin = -0.1, c='red', linewidth=1, linestyle = 'dashed', zorder=0, clip_on=False)
fitPlot.text(satPhotAmount+2, 0.95*fitPlot.get_yticks()[-1], "CSA Saturation", color = 'red', clip_on=False)
residualPlot.axvline(x=satPhotAmount, ymin = 0, ymax = 1, c='red', linewidth=1, linestyle = 'dashed', zorder=0, clip_on=False)
residualPlot.set_xlabel(xlabel)
residualPlot.set_ylabel("Residuals")
plt.minorticks_on()
plt.grid(which='major', linestyle='-', linewidth=0.6, color='grey')
plt.grid(which='minor', linestyle=':', linewidth=0.4, color='grey')
fitPlot.set_xlabel("")
fitPlot.set_xticklabels([])
base.drawPlotIntoHdf5File(FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]], pathToDataset + '_calculated_injected_photons with linear Fit And Residuals', hdf5OutputFile)
def configSigSweep_Fit(FE_avgs, FE_figs, calcInjectedPhotons, FE_figs_calcPhotsX, FE_figs_calcPhotsX_wfit, hdf5OutputFile, pathToDataset, fitLimits = [0,300]):
xlabel = "Injected 30keV Photons"
for i in np.arange(len(FE_figs)):
print(FE_figs.keys()[i])
base.drawPlotIntoHdf5File(FE_figs[FE_figs.keys()[i]], pathToDataset + '/plot', hdf5OutputFile)
base.drawPlotIntoHdf5File(FE_figs_calcPhotsX[FE_figs_calcPhotsX.keys()[i]], pathToDataset + '/calculated_injected_photons', hdf5OutputFile)
popt, pcov = curve_fit(base.line, calcInjectedPhotons[0:300], FE_avgs[FE_avgs.keys()[i]][0:300])
popt, pcov = curve_fit(base.line, calcInjectedPhotons[fitLimits[0]:fitLimits[1]], FE_avgs[FE_avgs.keys()[i]][fitLimits[0]:fitLimits[1]])
m = popt[0]
c = popt[1]
fitPlot = FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]].axes[0]
fitPlot.plot(calcInjectedPhotons, base.line(calcInjectedPhotons, m, c), label = "m = {:.2f}".format(m) + "\nc = {:.2f}".format(c))
plt.legend()
# FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]].axes[0].plot(calcInjectedPhotons, base.line(calcInjectedPhotons, m, c), label = "m = " + str(m) + "\nc = " + str(c))
base.drawPlotIntoHdf5File(FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]], pathToDataset + '/calculated_injected_photons with linear Fit', hdf5OutputFile)
gs = gridspec.GridSpec(5,1)
# fitPlot.change_geometry(5,1,(1,4))
fitPlot.set_position(gs[0:4].get_position(FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]]))
residualPlot = FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]].add_subplot(gs[4])
residuals = base.line(calcInjectedPhotons, m, c) - FE_avgs[FE_avgs.keys()[i]]
residualPlot.plot(calcInjectedPhotons, residuals)
satPhotAmount = calcSatPhotAmount(50e-15, 30e3, 800e-3)
fitPlot.axvline(x=satPhotAmount, ymin = -0.1, c='red', linewidth=1, linestyle = 'dashed', zorder=0, clip_on=False)
fitPlot.text(satPhotAmount+2, 0.95*fitPlot.get_yticks()[-1], "CSA Saturation", color = 'red', clip_on=False)
residualPlot.axvline(x=satPhotAmount, ymin = 0, ymax = 1, c='red', linewidth=1, linestyle = 'dashed', zorder=0, clip_on=False)
residualPlot.set_xlabel(xlabel)
residualPlot.set_ylabel("Residuals")
plt.minorticks_on()
plt.grid(which='major', linestyle='-', linewidth=0.6, color='grey')
plt.grid(which='minor', linestyle=':', linewidth=0.4, color='grey')
pathToMeasurement = '../measurements/DAQ.h5'
fitPlot.set_xlabel("")
fitPlot.set_xticklabels([])
hdf5InputFile = h5py.File(pathToMeasurement, 'r')
sweptSigs = hdf5InputFile.attrs['Swept DACs']
base.drawPlotIntoHdf5File(FE_figs_calcPhotsX_wfit[FE_figs_calcPhotsX_wfit.keys()[i]], pathToDataset + '/calculated_injected_photons with linear Fit And Residuals', hdf5OutputFile)
hdf5OutputFile[pathToDataset + '/xaxis'] = calcInjectedPhotons[:]
hdf5OutputFile[pathToDataset + '/yaxis'] = FE_avgs[FE_avgs.keys()[i]]
sweptSigs_dict = OrderedDict()
hdf5OutputFileName = 'basetest.h5'
hdf5OutputFile = h5py.File(hdf5OutputFileName, 'w')
def configSigSweep_dual(hdf5InputFiles, basePath="DAC Sweep/", outputFile=None):
print("basePath " + str(basePath))
#INJECT0_DACs = hdf5InputFile["DAC Sweep/DAC Values DACs:INJECT0_p"]
INJECT0_DACs = hdf5InputFile[basePath + "DAC Values DACs:INJECT0_p"]
INJECT1_DACs = hdf5InputFile[basePath + "DAC Values DACs:INJECT1_p"]
#INJECT1_DACs = hdf5InputFile["DAC Sweep/DAC Values DACs:INJECT1_p"]
xaxis = np.append(INJECT0_DACs, INJECT0_DACs[-1]+INJECT1_DACs[1:])
print(len(xaxis))
#calcInjectedPhotons = calcPhotsFromInjectDAC(xaxis, 200e-15)
xlabel = "Injected 30keV Photons"
for i in np.arange(len(sweptSigs)):
DACvalues = hdf5InputFile['DAC Values ' + sweptSigs[i]]
sweptSigs_dict[sweptSigs[i]] = DACvalues.value
pathToInject0 = basePath + "DACs:INJECT0_p/"
pathToInject1 = basePath + "DACs:INJECT1_p/"
configSigSweep_recursive_injectPlot(hdf5InputFile, sweptSigs_dict, pathToDataset="DAC Sweep", hdf5OutputFile=hdf5OutputFile)
Inject0_y = base.getFECntsFromHdf5(hdf5InputFile, pathToInject0, 1)
Inject0_y_avgs, Inject0_y_stdevs = base.calcAvgsAndStdDevsSingleAll(Inject0_y)
#else:
inject1_exists = 1
try:
Inject1_y = base.getFECntsFromHdf5(hdf5InputFile, pathToInject1, 1)
except:
inject1_exists = 0
if(inject1_exists):
Inject1_y_avgs, Inject1_y_stdevs = base.calcAvgsAndStdDevsSingleAll(Inject1_y)
yaxis = {"FE15": np.append(Inject0_y_avgs.values()[0], Inject1_y_avgs.values()[0][1:])}
yaxis_err = {"FE15" : np.append(Inject0_y_stdevs.values()[0], Inject1_y_stdevs.values()[0][1:])}
else:
yaxis = {"FE15": Inject0_y_avgs.values()[0]}
yaxis_err = {"FE15" : Inject0_y_stdevs.values()[0]}
calcInjectedPhotons = calcPhotsFromInjectDAC(xaxis, 180e-15)
print(np.shape(yaxis.values()))
print(yaxis.values())
print(len(yaxis_err.values()[0]))
print(yaxis_err.values()[0])
FE_figs = base.plotDataVsXAll(yaxis, calcInjectedPhotons, xlabel, FEStdevs = yaxis_err)
#hdf5OutputFile = hdf5InputFile.filename.split('/')[-1].split('.')[0] + '.png'
hdf5OutputFile = ""
if(outputFile == None):
hdf5OutputFileName = "DAQ_ana.h5"
hdf5OutputFile = h5py.File(hdf5OutputFileName, "w")
else:
hdf5OutputFile = outputFile
DAC_data = xaxis
FE_figs_calcPhotsX = base.plotDataVsXAll(yaxis, calcInjectedPhotons, xlabel, FEStdevs=yaxis_err)
FE_figs_calcPhotsX_wfit = base.plotDataVsXAll(yaxis, calcInjectedPhotons, xlabel, FEStdevs=yaxis_err)
configSigSweep_Fit(yaxis, FE_figs, calcInjectedPhotons, FE_figs_calcPhotsX, FE_figs_calcPhotsX_wfit, hdf5OutputFile, basePath, fitLimits = [20,300])
return calcInjectedPhotons, yaxis, yaxis_err
# plt.show()
# plt.savefig(hdf5InputFile.filename.split('/')[-1].split('.')[0] + '.png')
def configSigSweep_dual_Vref_And_InpCap_Sweep(hdf5InputFiles, basePath = "DAC Sweep/"):
InpCaps = hdf5InputFile[basePath + "DAC Values Input Capacitance"]
VREF_DACs = hdf5InputFile[basePath + "DAC Values DACs:AMP_Vref_p"]
pathCap = ""
pathVref = ""
hdf5OutputFile = h5py.File("DAQ_ana.h5", "w")
for i in np.arange(len(InpCaps)):
pathCap = basePath + "Input Capacitance " + str(InpCaps[i]) + "/"
yaxes = {}
fig, ax = plt.subplots(dpi=150)
for k in np.arange(len(VREF_DACs)):
pathVref = pathCap + "DACs:AMP_Vref_p " + str(VREF_DACs[k]) + "/"
xaxis, yaxis, yaxis_err = configSigSweep_dual(hdf5InputFiles, outputFile = hdf5OutputFile, basePath=pathVref)
plt.minorticks_on()
plt.grid(which='major', linestyle='-', linewidth=0.6, color='grey')
plt.grid(which='minor', linestyle=':', linewidth=0.4, color='grey')
#ax.scatter(xaxis, FEdata, label = FEname + " counts", s = 3)
# if(np.array_equal(FEStdevs, np.zeros(len(FEdata)))):
# capsize = 0
# else:
# capsize = 2
#print("xaxis", xaxis)
#print("FEdata", FEdata)
#print(FEStdevs)
#ax.errorbar(xaxis, yaxis['FE15'], fmt = 'o', yerr = yaxis_err['FE15'], label = "Vref =" + str(VREF_DACs[k]) + " mV", markersize=0.1, capsize=capsize)
ax.errorbar(xaxis, yaxis['FE15'], fmt = 'o', yerr = yaxis_err['FE15'], label = "Vref =" + str(VREF_DACs[k]) + " mV", markersize=0.1)
#print(xaxis)
#print(yaxis)
#print(yaxis_err)
# ax.errorbar(xaxis, yaxis['FE15'], yerr = yaxis_err['FE15'], label )
#xlabel = "COMP0_Vthresh_p"
xlabel = "Injected 30keV Photons"
ax.set_xlabel(xlabel)
ax.set_ylabel('Counted Photons')
ax.grid(which='major', linestyle='-', linewidth=0.6, color='grey')
ax.grid(which='minor', linestyle=':', linewidth=0.4, color='grey')
ax.legend()
print(pathCap)
base.drawPlotIntoHdf5File(fig, pathCap + "CombinedPlot", hdf5OutputFile)
if __name__=="__main__":
#
# FE_cnts = base.getFECntsFromHdf5(hdf5InputFile, 'DAC Sweep', 1)
# FE_names = FE_cnts.keys()
# print(FE_cnts)