Skip to content
Snippets Groups Projects
Commit 980aea97 authored by Guenter Quast's avatar Guenter Quast
Browse files

mcpha.py: better factorization

parent 5a314ab4
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
"""mcpha: Multi-Channel Pulse Height Analyser
"""mcpha: Multi-Channel Pulse Height Analyser
Client script for displaying the output of the MCPHA application
running on a RedPitaya FPGA board
Modified version of mcphy.py by Pavel Demin
Client script for displaying the output of the MCPHA application
running on a RedPitaya FPGA board
"""
# differences w.r.t. original version marked with " # !gq"
import argparse # !gq
import os
......@@ -57,7 +61,10 @@ class MCPHA(QMainWindow, Ui_MCPHA):
# !gq get command line arguments
self.parse_args()
self.get_physical_units()
# !gq end
# initialize variables
self.idle = True
self.waiting = [False for i in range(3)]
......@@ -87,7 +94,6 @@ class MCPHA(QMainWindow, Ui_MCPHA):
self.rateValue.lineEdit().setAlignment(Qt.AlignRight)
for i in range(self.rateValue.count()):
self.rateValue.setItemData(i, Qt.AlignRight, Qt.TextAlignmentRole)
# !gq self.rateValue.setCurrentIndex(0)
self.rateValue.setCurrentIndex(1)
self.rateValue.currentIndexChanged.connect(self.set_rate)
# address validator
......@@ -110,7 +116,7 @@ class MCPHA(QMainWindow, Ui_MCPHA):
self.readTimer = QTimer(self)
self.readTimer.timeout.connect(self.read_timeout)
# !gq set defaults
# !gq set defaults and units
self.osc.levelValue.setValue(self.trigger_level)
# !gq end
......@@ -126,6 +132,14 @@ class MCPHA(QMainWindow, Ui_MCPHA):
self.ip_address = args.ip_address
# !gq end
def get_physical_units(self):
"""get physical units corresponding to ADC units and channel numbers
"""
# Voltages: 4096 channels/Volt
self.adc_unit = 1000/4096
# time per sample at sampling rate of 125 MHz / decimation_factor
self.time_bin = 0.008
def start(self):
self.socket.connectToHost(self.addrValue.text(), 1001)
self.startTimer.start(5000)
......@@ -433,12 +447,12 @@ class HstDisplay(QWidget, Ui_HstDisplay):
def adc2mV(self, c):
"""convert adc-count to Voltage in mV
"""
return c * 1000/4096 * self.factor
return c * self.mcpha.adc_unit * self.factor
def mV2adc(self, v):
"""convert voltage in mV to adc-count
"""
return v *4096/(1000 *self.factor)
return v / (self.mcpha.adc_unit * self.factor)
# !gq end helper
def start(self):
......@@ -687,8 +701,8 @@ class OscDisplay(QWidget, Ui_OscDisplay):
self.ax = self.figure.add_subplot(111)
self.ax.grid()
self.ax.set_ylim(-4500, 4500)
self.ax.set_xlabel("time bin")
self.ax.set_ylabel("ADC counts")
self.ax.set_xlabel("sample number")
self.ax.set_ylabel("ADC units")
# gq
self.ax_x2=self.ax.secondary_xaxis('top', functions=(self.tbin2t, self.t2tbin))
self.ax_x2.set_xlabel("time [µs]", color='grey', size='x-large')
......@@ -739,26 +753,26 @@ class OscDisplay(QWidget, Ui_OscDisplay):
def tbin2t(self, tbin):
"""convert time bin to time in µs
"""
idf = self.mcpha.rateValue.currentIndex()
df = 1 if idf == -1 else MCPHA.rates[idf]
return (tbin-self.pre)*df*0.008
dfi = self.mcpha.rateValue.currentIndex() # current decimation factor index
df = 4 if dfi == -1 else MCPHA.rates[dfi] # decimation factor
return (tbin-self.pre)*self.mcpha.time_bin * df
def t2tbin(self, t):
"""convert time in µs to time bin
"""
idf = self.mcpha.rateValue.currentIndex()
df = 1 if idf == -1 else MCPHA.rates[idf]
return t/(df*0.008)+self.pre
dfi = self.mcpha.rateValue.currentIndex() # current decimation factor index
df = 4 if dfi == -1 else MCPHA.rates[dfi] # decimation factor
return t/(self.mcpha.time_bin * df)+self.pre
def adc2mV(self, c):
"""convert adc-count to Voltage in mV
"""
return c * 1000/4096
return c * self.mcpha.adc_unit
def mV2adc(self, v):
"""convert voltage in mV to adc-count
"""
return v *4096/1000
return v / self.mcpha.adc_unit
# gq end
def start(self):
......@@ -888,14 +902,15 @@ class GenDisplay(QWidget, Ui_GenDisplay):
# gq
def adc2mV(self, c):
"""convert adc-count to Voltage in mV
"""convert adc-count to Voltage in mV
!!! there is a factor of two betwenn channel definition here and in hstDisplay !
"""
return c * 500/4096
return c * self.mcpha.adc_unit/2
def mV2adc(self, v):
"""convert voltage in mV to adc-count
"""
return v *4096/500
return v * self.mcpha.adc_unit*2
# gq end
def start(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment