Commit 512b82f2 authored by Laurent Petre's avatar Laurent Petre
Browse files

Move the DAC scan tools in the gemos package

parent df1e102d
Pipeline #2952842 passed with stages
in 2 minutes and 45 seconds
import os
import argparse
import time
import numpy as np
from scipy.optimize import curve_fit
import pandas as pd
import matplotlib.pyplot as plt
from multiprocessing import Process
def determine_nom(data, nominal_ADC0):
val1=abs(data['value']-nominal_ADC0).idxmin()
return (data.iloc[val1].DAC_point)
def poly5(x,f, e, a, b, c, d):
return f *np.power(x,5) + e *np.power(x,4) + a *np.power(x,3) + b*np.power(x,2) + c*x + d
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Arguments to supply to dacscans.py')
parser.add_argument("infilename", type=str, help="Input file name")
parser.add_argument('-cal','--calfilename', type=str, help="Calibration file name")
parser.add_argument('-o','--outfilepath', type=str, default="DAC_op.txt", help="Path of output plots' destination")
args = parser.parse_args()
infilename=os.path.basename(args.infilename)
df = pd.read_csv(infilename,names=["OH", "DAC_reg", "vfat", "DAC_point","value"], sep=";")
df.insert(0, 'slot', 0)
df.insert(0, 'fed', 0)
calfilename=os.path.basename(args.calfilename)
Caldf=pd.read_csv(calfilename,names=["vfat", "slope", "intercept"], sep=";")
outfilepath = args.outfilepath
nominalDacValues = {
"CFG_CAL_DAC":(0,"uA"), # there is no nominal value
"CFG_BIAS_PRE_I_BIT":(150,"uA"),
"CFG_BIAS_PRE_I_BLCC":(25,"nA"),
"CFG_BIAS_PRE_I_BSF":(26,"uA"),
"CFG_BIAS_SH_I_BFCAS":(26,"uA"),
"CFG_BIAS_SH_I_BDIFF":(16,"uA"),
"CFG_BIAS_SD_I_BDIFF":(28,"uA"),
"CFG_BIAS_SD_I_BFCAS":(27,"uA"),
"CFG_BIAS_SD_I_BSF":(30,"uA"),
"CFG_BIAS_CFD_DAC_1":(20,"uA"),
"CFG_BIAS_CFD_DAC_2":(20,"uA"),
"CFG_HYST":(100,"nA"),
"CFG_THR_ARM_DAC":(64,"mV"),
"CFG_THR_ZCC_DAC":(5.5,"mV"),
"CFG_BIAS_PRE_VREF":(430,'mV'),
"CFG_VREF_ADC":(1.0,'V')
}
#: From Tables 12 and 13 from the VFAT3 manual
nominalDacScalingFactors = {
"CFG_CAL_DAC":10, # Valid only for currentPulse; if voltageStep this is 1
"CFG_BIAS_PRE_I_BIT":0.2,
"CFG_BIAS_PRE_I_BLCC":100,
"CFG_BIAS_PRE_I_BSF":0.25,
"CFG_BIAS_SH_I_BFCAS":1,
"CFG_BIAS_SH_I_BDIFF":1,
"CFG_BIAS_SD_I_BDIFF":1,
"CFG_BIAS_SD_I_BFCAS":1,
"CFG_BIAS_SD_I_BSF":0.25,
"CFG_BIAS_CFD_DAC_1":1,
"CFG_BIAS_CFD_DAC_2":1,
"CFG_HYST":5,
"CFG_THR_ARM_DAC":1,
"CFG_THR_ZCC_DAC":4,
"CFG_BIAS_PRE_VREF":1,
"CFG_ADC_VREF": 1
}
for fed in df.fed.unique():
sel1=df.fed==fed
datafed=df[sel1]
for slot in datafed.slot.unique():
sel2=df.slot==slot
dataslot=datafed[sel2]
for OH in dataslot.OH.unique():
sel3=dataslot.OH==OH
dataOH=dataslot[sel3]
for DAC_reg in dataOH.DAC_reg.unique():
sel4=dataOH.DAC_reg==DAC_reg
datareg=dataOH[sel4]
fig, axs = plt.subplots(4, 6, figsize=(30,20))
for vfat in datareg.vfat.unique():
sel5=datareg.vfat==vfat
datavfat=datareg[sel5].reset_index()
datavfat["value"]=nominalDacScalingFactors[DAC_reg]*(datavfat["value"]*Caldf.iloc[vfat].slope+ Caldf.iloc[vfat].intercept)
datavfat2=datavfat
xdata = datavfat['value'].to_numpy()
ydata = datavfat['DAC_point'].to_numpy()
f=vfat%6
i=int((vfat-f)/6)
axs[i,f].plot(datavfat.value, datavfat.DAC_point, 'o')
p1 = [1,1,1,1,1,min(ydata)]
popt2, pcov2 = curve_fit(poly5, xdata, ydata ,p1)
datavfat2['DAC_point']= pd.DataFrame(poly5(xdata, *popt2), columns=['DACpoint'])
axs[i,f].plot(xdata, poly5(xdata, *popt2), '.')
plt.setp(axs[-1, :], xlabel='ADC0 (mu A)')
plt.setp(axs[:, 0], ylabel="%str"%(DAC_reg))
opfname=outfilepath + "%i%i%i%str.png"%(fed,slot,OH,DAC_reg)
plt.savefig(opfname)
\ No newline at end of file
"""DAC scan analysis"""
import os
import argparse
import time
import numpy as np
from scipy.optimize import curve_fit
import pandas as pd
from multiprocessing import Process
import matplotlib.pyplot as plt
# From Tables 12 and 13 from the VFAT3 manual
nominalDacValues = {
"CFG_CAL_DAC":(0,"uA"), # There is no nominal value
"CFG_BIAS_PRE_I_BIT":(150,"uA"),
"CFG_BIAS_PRE_I_BLCC":(25,"nA"),
"CFG_BIAS_PRE_I_BSF":(26,"uA"),
"CFG_BIAS_SH_I_BFCAS":(26,"uA"),
"CFG_BIAS_SH_I_BDIFF":(16,"uA"),
"CFG_BIAS_SD_I_BDIFF":(28,"uA"),
"CFG_BIAS_SD_I_BFCAS":(27,"uA"),
"CFG_BIAS_SD_I_BSF":(30,"uA"),
"CFG_BIAS_CFD_DAC_1":(20,"uA"),
"CFG_BIAS_CFD_DAC_2":(20,"uA"),
"CFG_HYST":(100,"nA"),
"CFG_THR_ARM_DAC":(64,"mV"),
"CFG_THR_ZCC_DAC":(5.5,"mV"),
"CFG_BIAS_PRE_VREF":(430,'mV'),
"CFG_VREF_ADC":(1.0,'V'),
}
nominalDacScalingFactors = {
"CFG_CAL_DAC":10, # Valid only for currentPulse; if voltageStep this is 1
"CFG_BIAS_PRE_I_BIT":0.2,
"CFG_BIAS_PRE_I_BLCC":100,
"CFG_BIAS_PRE_I_BSF":0.25,
"CFG_BIAS_SH_I_BFCAS":1,
"CFG_BIAS_SH_I_BDIFF":1,
"CFG_BIAS_SD_I_BDIFF":1,
"CFG_BIAS_SD_I_BFCAS":1,
"CFG_BIAS_SD_I_BSF":0.25,
"CFG_BIAS_CFD_DAC_1":1,
"CFG_BIAS_CFD_DAC_2":1,
"CFG_HYST":5,
"CFG_THR_ARM_DAC":1,
"CFG_THR_ZCC_DAC":4,
"CFG_BIAS_PRE_VREF":1,
"CFG_ADC_VREF": 1,
}
def determine_nom(data, nominal_ADC0):
val1=abs(data['value']-nominal_ADC0).idxmin()
return (data.iloc[val1].DAC_point)
return data.iloc[val1].DAC_point
def poly5(x,f, e, a, b, c, d):
return f *np.power(x,5) + e *np.power(x,4) + a *np.power(x,3) + b*np.power(x,2) + c*x + d
if __name__ == "__main__":
def fit():
parser = argparse.ArgumentParser(description='Arguments to supply to dacscans.py')
parser.add_argument("infilename", type=str, help="Input file name")
parser.add_argument('-cal','--calfilename', type=str, help="Calibration file name")
......@@ -22,66 +62,28 @@ if __name__ == "__main__":
args = parser.parse_args()
infilename=os.path.basename(args.infilename)
df = pd.read_csv(infilename,names=["OH", "DAC_reg", "vfat", "DAC_point","value"], sep=";")
# df.insert(0, 'slot', 0)
# df.insert(0, 'fed', 0)
df = pd.read_csv(infilename,names=["OH", "DAC_reg", "vfat", "DAC_point","value"], sep=";")
df.insert(0, 'slot', 0)
df.insert(0, 'fed', 0)
calfilename=os.path.basename(args.calfilename)
Caldf=pd.read_csv(calfilename,names=["vfat", "slope", "intercept"], sep=";")
outfilename = args.outfilename
nominalDacValues = {
"CFG_CAL_DAC":(0,"uA"), # there is no nominal value
"CFG_BIAS_PRE_I_BIT":(150,"uA"),
"CFG_BIAS_PRE_I_BLCC":(25,"nA"),
"CFG_BIAS_PRE_I_BSF":(26,"uA"),
"CFG_BIAS_SH_I_BFCAS":(26,"uA"),
"CFG_BIAS_SH_I_BDIFF":(16,"uA"),
"CFG_BIAS_SD_I_BDIFF":(28,"uA"),
"CFG_BIAS_SD_I_BFCAS":(27,"uA"),
"CFG_BIAS_SD_I_BSF":(30,"uA"),
"CFG_BIAS_CFD_DAC_1":(20,"uA"),
"CFG_BIAS_CFD_DAC_2":(20,"uA"),
"CFG_HYST":(100,"nA"),
"CFG_THR_ARM_DAC":(64,"mV"),
"CFG_THR_ZCC_DAC":(5.5,"mV"),
"CFG_BIAS_PRE_VREF":(430,'mV'),
"CFG_VREF_ADC":(1.0,'V')
}
#: From Tables 12 and 13 from the VFAT3 manual
nominalDacScalingFactors = {
"CFG_CAL_DAC":10, # Valid only for currentPulse; if voltageStep this is 1
"CFG_BIAS_PRE_I_BIT":0.2,
"CFG_BIAS_PRE_I_BLCC":100,
"CFG_BIAS_PRE_I_BSF":0.25,
"CFG_BIAS_SH_I_BFCAS":1,
"CFG_BIAS_SH_I_BDIFF":1,
"CFG_BIAS_SD_I_BDIFF":1,
"CFG_BIAS_SD_I_BFCAS":1,
"CFG_BIAS_SD_I_BSF":0.25,
"CFG_BIAS_CFD_DAC_1":1,
"CFG_BIAS_CFD_DAC_2":1,
"CFG_HYST":5,
"CFG_THR_ARM_DAC":1,
"CFG_THR_ZCC_DAC":4,
"CFG_BIAS_PRE_VREF":1,
"CFG_ADC_VREF": 1
}
with open(outfilename,"w+") as file:
file.write("")
for fed in df.fed.unique():
sel1=df.fed==fed
datafed=df[sel1]
for slot in datafed.slot.unique():
sel2=df.slot==slot
dataslot=datafed[sel2]
for OH in dataslot.OH.unique():
sel3=dataslot.OH==OH
dataOH=dataslot[sel3]
for DAC_reg in dataOH.DAC_reg.unique():
sel4=dataOH.DAC_reg==DAC_reg
datareg=dataOH[sel4]
for vfat in datareg.vfat.unique():
file.write("")
for fed in df.fed.unique():
sel1=df.fed==fed
datafed=df[sel1]
for slot in datafed.slot.unique():
sel2=df.slot==slot
dataslot=datafed[sel2]
for OH in dataslot.OH.unique():
sel3=dataslot.OH==OH
dataOH=dataslot[sel3]
for DAC_reg in dataOH.DAC_reg.unique():
sel4=dataOH.DAC_reg==DAC_reg
datareg=dataOH[sel4]
for vfat in datareg.vfat.unique():
sel5=datareg.vfat==vfat
datavfat=datareg[sel5].reset_index()
datavfat["value"]=nominalDacScalingFactors[DAC_reg]*(datavfat["value"]*Caldf.iloc[vfat].slope+ Caldf.iloc[vfat].intercept)
......@@ -96,4 +98,50 @@ if __name__ == "__main__":
if nominal_ADC0 > max(datavfat.DAC_point) :
nominal_ADC0= max(datavfat.DAC_point)
file.write("%str:%i:%i\n"%(DAC_reg,vfat,nominal_ADC0))
def plot():
parser = argparse.ArgumentParser(description='Arguments to supply to dacscans.py')
parser.add_argument("infilename", type=str, help="Input file name")
parser.add_argument('-cal','--calfilename', type=str, help="Calibration file name")
parser.add_argument('-o','--outfilepath', type=str, default="DAC_op.txt", help="Path of output plots' destination")
args = parser.parse_args()
infilename=os.path.basename(args.infilename)
df = pd.read_csv(infilename,names=["OH", "DAC_reg", "vfat", "DAC_point","value"], sep=";")
df.insert(0, 'slot', 0)
df.insert(0, 'fed', 0)
calfilename=os.path.basename(args.calfilename)
Caldf=pd.read_csv(calfilename,names=["vfat", "slope", "intercept"], sep=";")
outfilepath = args.outfilepath
for fed in df.fed.unique():
sel1=df.fed==fed
datafed=df[sel1]
for slot in datafed.slot.unique():
sel2=df.slot==slot
dataslot=datafed[sel2]
for OH in dataslot.OH.unique():
sel3=dataslot.OH==OH
dataOH=dataslot[sel3]
for DAC_reg in dataOH.DAC_reg.unique():
sel4=dataOH.DAC_reg==DAC_reg
datareg=dataOH[sel4]
fig, axs = plt.subplots(4, 6, figsize=(30,20))
for vfat in datareg.vfat.unique():
sel5=datareg.vfat==vfat
datavfat=datareg[sel5].reset_index()
datavfat["value"]=nominalDacScalingFactors[DAC_reg]*(datavfat["value"]*Caldf.iloc[vfat].slope+ Caldf.iloc[vfat].intercept)
datavfat2=datavfat
xdata = datavfat['value'].to_numpy()
ydata = datavfat['DAC_point'].to_numpy()
f=vfat%6
i=int((vfat-f)/6)
axs[i,f].plot(datavfat.value, datavfat.DAC_point, 'o')
p1 = [1,1,1,1,1,min(ydata)]
popt2, pcov2 = curve_fit(poly5, xdata, ydata ,p1)
datavfat2['DAC_point']= pd.DataFrame(poly5(xdata, *popt2), columns=['DACpoint'])
axs[i,f].plot(xdata, poly5(xdata, *popt2), '.')
plt.setp(axs[-1, :], xlabel='ADC0 (mu A)')
plt.setp(axs[:, 0], ylabel="%str"%(DAC_reg))
opfname=outfilepath + "%i%i%i%str.png"%(fed,slot,OH,DAC_reg)
plt.savefig(opfname)
......@@ -907,6 +907,17 @@ urllib3 = ">=1.21.1,<1.27"
socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"]
use_chardet_on_py3 = ["chardet (>=3.0.2,<5)"]
[[package]]
name = "scipy"
version = "1.7.1"
description = "SciPy: Scientific Library for Python"
category = "main"
optional = false
python-versions = ">=3.7,<3.10"
[package.dependencies]
numpy = ">=1.16.5,<1.23.0"
[[package]]
name = "send2trash"
version = "1.8.0"
......@@ -1161,7 +1172,7 @@ python-versions = "*"
[metadata]
lock-version = "1.1"
python-versions = "~3.8.6" # EPEL 7/CentOS 8 Python 3.8 version
content-hash = "9b9037ec642f35c3e7dd32b373583e16f4505e388360a717f71e63481c51ded4"
content-hash = "40acdf369080b32a407977c5d8875a448fa044877a8bb4964b243815d2fe5b8b"
[metadata.files]
alabaster = [
......@@ -1868,6 +1879,27 @@ requests = [
{file = "requests-2.26.0-py2.py3-none-any.whl", hash = "sha256:6c1246513ecd5ecd4528a0906f910e8f0f9c6b8ec72030dc9fd154dc1a6efd24"},
{file = "requests-2.26.0.tar.gz", hash = "sha256:b8aa58f8cf793ffd8782d3d8cb19e66ef36f7aba4353eec859e74678b01b07a7"},
]
scipy = [
{file = "scipy-1.7.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:2a0eeaab01258e0870c4022a6cd329aef3b7c6c2b606bd7cf7bb2ba9820ae561"},
{file = "scipy-1.7.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3f52470e0548cdb74fb8ddf06773ffdcca7c97550f903b1c51312ec19243a7f7"},
{file = "scipy-1.7.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:787749110a23502031fb1643c55a2236c99c6b989cca703ea2114d65e21728ef"},
{file = "scipy-1.7.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:3304bd5bc32e00954ac4b3f4cc382ca8824719bf348aacbec6347337d6b125fe"},
{file = "scipy-1.7.1-cp37-cp37m-win32.whl", hash = "sha256:d1388fbac9dd591ea630da75c455f4cc637a7ca5ecb31a6b6cef430914749cde"},
{file = "scipy-1.7.1-cp37-cp37m-win_amd64.whl", hash = "sha256:d648aa85dd5074b1ed83008ae987c3fbb53d68af619fce1dee231f4d8bd40e2f"},
{file = "scipy-1.7.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:bc61e3e5ff92d2f32bb263621d54a9cff5e3f7c420af3d1fa122ce2529de2bd9"},
{file = "scipy-1.7.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a496b42dbcd04ea9924f5e92be63af3d8e0f43a274b769bfaca0a297327d54ee"},
{file = "scipy-1.7.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:d13f31457f2216e5705304d9f28e2826edf75487410a57aa99263fa4ffd792c2"},
{file = "scipy-1.7.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:90c07ba5f34f33299a428b0d4fa24c30d2ceba44d63f8385b2b05be460819fcb"},
{file = "scipy-1.7.1-cp38-cp38-win32.whl", hash = "sha256:efdd3825d54c58df2cc394366ca4b9166cf940a0ebddeb87b6c10053deb625ea"},
{file = "scipy-1.7.1-cp38-cp38-win_amd64.whl", hash = "sha256:71cfc96297617eab911e22216e8a8597703202e95636d9406df9af5c2ac99a2b"},
{file = "scipy-1.7.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:4ee952f39a4a4c7ba775a32b664b1f4b74818548b65f765987adc14bb78f5802"},
{file = "scipy-1.7.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:611f9cb459d0707dd8e4de0c96f86e93f61aac7475fcb225e9ec71fecdc5cebf"},
{file = "scipy-1.7.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:e101bceeb9e65a90dadbc5ca31283403a2d4667b9c178db29109750568e8d112"},
{file = "scipy-1.7.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:4729b41a4cdaf4cd011aeac816b532f990bdf97710cef59149d3e293115cf467"},
{file = "scipy-1.7.1-cp39-cp39-win32.whl", hash = "sha256:c9951e3746b68974125e5e3445008a4163dd6d20ae0bbdae22b38cb8951dc11b"},
{file = "scipy-1.7.1-cp39-cp39-win_amd64.whl", hash = "sha256:da9c6b336e540def0b7fd65603da8abeb306c5fc9a5f4238665cbbb5ff95cf58"},
{file = "scipy-1.7.1.tar.gz", hash = "sha256:6b47d5fa7ea651054362561a28b1ccc8da9368a39514c1bbf6c0977a1c376764"},
]
send2trash = [
{file = "Send2Trash-1.8.0-py3-none-any.whl", hash = "sha256:f20eaadfdb517eaca5ce077640cb261c7d2698385a6a0f072a4a5447fd49fa08"},
{file = "Send2Trash-1.8.0.tar.gz", hash = "sha256:d2c24762fd3759860a0aff155e45871447ea58d2be6bdd39b5c8f966a0c99c2d"},
......
......@@ -23,6 +23,7 @@ cbitstruct = "^1.0.7"
matplotlib = "^3.4.3"
numpy = "^1.19.5"
pandas = "^1.1.5"
scipy = "^1.7.1"
[tool.poetry.dev-dependencies]
Sphinx = "^4.1.2"
......@@ -35,7 +36,9 @@ sphinx-rtd-theme = "^0.5.2"
[tool.poetry.scripts]
gem-unpack = "gdh.unpacker:main"
gem-analyze-sbit-rate = "gemos.analysis.sbit_rate:main"
gem-sbit-rate-analyze = "gemos.analysis.sbit_rate:main"
gem-dac-scan-fit = "gemos.analysis.dac_scan:fit"
gem-dac-scan-plot = "gemos.analysis.dac_scan:plot"
[build-system]
requires = ["poetry-core>=1.0.0"]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment