From 3cf3622e3e47d29846436b6b2c1aa5faccd2cf83 Mon Sep 17 00:00:00 2001
From: Michael Daas <daas@physik.uni-bonn.de>
Date: Thu, 10 Jan 2019 13:12:01 +0100
Subject: [PATCH 1/8] FIX: Fix stuck while getting chip status bug

---
 bdaq53/rd53a.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/bdaq53/rd53a.py b/bdaq53/rd53a.py
index e6e2db56f..d6b216f65 100644
--- a/bdaq53/rd53a.py
+++ b/bdaq53/rd53a.py
@@ -1189,7 +1189,7 @@ class RD53A(Dut):
                         if len(userk_data) > 0:
                             break
                 else:
-                    logger.error('Timeout while waiting for chip status.')
+                    raise RuntimeError('Timeout while waiting for chip status.')
 
             for cmonitor in np.arange(0, 26, 1):
                 self.get_ADC(typ='I', address=cmonitor)
@@ -1202,8 +1202,8 @@ class RD53A(Dut):
                             break
                     time.sleep(0.1)
                 else:
-                    logger.error('Timeout while waiting for chip status.')
-        except:
+                    raise RuntimeError('Timeout while waiting for chip status.')
+        except Exception:
             logger.error('There was an error while receiving the chip status.')
 
         return voltages, currents
-- 
GitLab


From e787842797cafbf1d469743a7d56d1279fac7214 Mon Sep 17 00:00:00 2001
From: Michael Daas <daas@physik.uni-bonn.de>
Date: Thu, 10 Jan 2019 13:13:39 +0100
Subject: [PATCH 2/8] ENH: Use median instead of mean to be resistant to noisy
 pixels

---
 bdaq53/scans/meta_tune_local_threshold.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bdaq53/scans/meta_tune_local_threshold.py b/bdaq53/scans/meta_tune_local_threshold.py
index 5c59037b1..f5839c9bf 100755
--- a/bdaq53/scans/meta_tune_local_threshold.py
+++ b/bdaq53/scans/meta_tune_local_threshold.py
@@ -56,7 +56,7 @@ class MetaTDACTuning(MetaScanBase):
                                                          in_file.root.HistOcc.shape[2])
 
                 th_range = th[start_column:stop_column, start_row:stop_row]
-                mean = np.mean(th_range[th_range > 1])
+                mean = np.median(th_range[th_range > 1])
                 th_max = np.max(th_range[th_range < (kwargs.get('VCAL_HIGH_stop') - kwargs.get('VCAL_HIGH_start'))]) + 25
                 kwargs['VCAL_HIGH_stop'] = kwargs.get('VCAL_HIGH_start') + int(th_max)
 
-- 
GitLab


From f58cf13b60be83d703babbff76edf78ef77977ce Mon Sep 17 00:00:00 2001
From: Michael Daas <daas@physik.uni-bonn.de>
Date: Thu, 10 Jan 2019 13:15:00 +0100
Subject: [PATCH 3/8] ENH: Final threshold scan should not be part of tuning
 script

---
 bdaq53/scans/meta_tune_local_threshold.py | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/bdaq53/scans/meta_tune_local_threshold.py b/bdaq53/scans/meta_tune_local_threshold.py
index f5839c9bf..3c92869e5 100755
--- a/bdaq53/scans/meta_tune_local_threshold.py
+++ b/bdaq53/scans/meta_tune_local_threshold.py
@@ -139,17 +139,9 @@ class MetaTDACTuning(MetaScanBase):
 
         kwargs['TDAC'] = tdac
         self.TDAC_mask = tdac
-
-        kwargs['VCAL_HIGH_step'] = 2
-        self.logger.info('Running final threshold scan...')
-        scan = ThresholdScan(record_chip_status=False)
-        scan.logger.addHandler(self.fh)
-        scan.start(**kwargs)
-        scan.analyze(create_pdf=True)
-        scan.close()
+        self.save_tdac_mask()
 
         self.logger.info('Tuning finished!')
-        self.save_tdac_mask()
 
     def analyze(self, create_mask_file=True):
         pass
-- 
GitLab


From c71feb47861fe49c84db9e00ec242e4d0b2549cf Mon Sep 17 00:00:00 2001
From: Michael Daas <daas@physik.uni-bonn.de>
Date: Thu, 10 Jan 2019 13:15:39 +0100
Subject: [PATCH 4/8] FIX: Forgotten brackets

---
 bdaq53/scans/scan_noise_occupancy.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bdaq53/scans/scan_noise_occupancy.py b/bdaq53/scans/scan_noise_occupancy.py
index f4ed122cf..ad1fb1003 100755
--- a/bdaq53/scans/scan_noise_occupancy.py
+++ b/bdaq53/scans/scan_noise_occupancy.py
@@ -115,7 +115,7 @@ class NoiseOccScan(ScanBase):
             with plotting.Plotting(analyzed_data_file=a.analyzed_data_file) as p:
                 p.create_standard_plots()
 
-        return n_disabled_pixels, round(float(n_disabled_pixels) / float(self.n_pixels) * 100., 2), occupancy.sum, self.disable_mask
+        return n_disabled_pixels, round(float(n_disabled_pixels) / float(self.n_pixels) * 100., 2), occupancy.sum(), self.disable_mask
 
 
 if __name__ == "__main__":
-- 
GitLab


From e47bf7c61072df919712bbe0ddb689be13f72c89 Mon Sep 17 00:00:00 2001
From: Michael Daas <daas@physik.uni-bonn.de>
Date: Thu, 10 Jan 2019 13:27:44 +0100
Subject: [PATCH 5/8] ENH: Add measurements folder and irradiation scripts

---
 bdaq53/measurements/irradiation.yaml    |  13 +
 bdaq53/measurements/irradiation_loop.py | 296 +++++++++++++++++++++++
 bdaq53/measurements/irradiation_step.py | 308 ++++++++++++++++++++++++
 3 files changed, 617 insertions(+)
 create mode 100644 bdaq53/measurements/irradiation.yaml
 create mode 100644 bdaq53/measurements/irradiation_loop.py
 create mode 100644 bdaq53/measurements/irradiation_step.py

diff --git a/bdaq53/measurements/irradiation.yaml b/bdaq53/measurements/irradiation.yaml
new file mode 100644
index 000000000..cabdac44d
--- /dev/null
+++ b/bdaq53/measurements/irradiation.yaml
@@ -0,0 +1,13 @@
+transfer_layer:
+  - name     : Serial
+    type     : Serial
+    init     :
+        port     : /dev/ttyUSB0
+        read_termination : ""
+        baudrate : 115200
+        timeout : 2.0
+
+hw_drivers:
+  - name      : Thermohygrometer
+    type      : sensirion_ekh4
+    interface : Serial
diff --git a/bdaq53/measurements/irradiation_loop.py b/bdaq53/measurements/irradiation_loop.py
new file mode 100644
index 000000000..f573e95b9
--- /dev/null
+++ b/bdaq53/measurements/irradiation_loop.py
@@ -0,0 +1,296 @@
+#
+# ------------------------------------------------------------
+# Copyright (c) All rights reserved
+# SiLab, Institute of Physics, University of Bonn
+# ------------------------------------------------------------
+#
+
+'''
+    Irradiation scan looping script to keep the chip busy during irradiation steps
+'''
+
+import os
+import time
+import yaml
+import logging
+import copy
+import numpy as np
+
+from basil.dut import Dut
+from bdaq53 import rd53a
+from bdaq53.analysis import analysis_utils as au
+from bdaq53.scans.scan_threshold import ThresholdScan
+from bdaq53.scans.meta_tune_local_threshold import MetaTDACTuning
+
+
+output_dir = ''
+initial_maskfile_LIN = ''
+initial_maskfile_DIFF = ''
+
+configuration_untuned_coarse_threshold_scan = {
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 4000,
+    'VCAL_HIGH_step': 100,
+    'maskfile': None,
+    'mask_diff': False
+}
+
+configuration_untuned_fine_threshold_scan = {
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10,
+    'maskfile': None,
+    'mask_diff': False
+}
+
+configuration_initial_tuning_lin_threshold_scan = {
+    'start_column': 128,
+    'stop_column': 264,
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10,
+    'maskfile': initial_maskfile_LIN,
+    'mask_diff': False
+}
+
+configuration_initial_tuning_diff_threshold_scan = {
+    'start_column': 264,
+    'stop_column': 400,
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10,
+    'maskfile': initial_maskfile_DIFF,
+    'mask_diff': False
+}
+
+configuration_tuning_lin = {
+    'start_column': 128,
+    'stop_column': 264,
+    'maskfile': None,
+
+    'VCAL_MED': 500,
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10
+}
+
+configuration_tuned_lin_threshold_scan = {
+    'start_column': 128,
+    'stop_column': 264,
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10,
+    'maskfile': 'auto',
+    'mask_diff': False
+}
+
+configuration_tuning_diff = {
+    'start_column': 264,
+    'stop_column': 400,
+    'maskfile': None,
+
+    'VCAL_MED': 500,
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10
+}
+
+configuration_tuned_diff_threshold_scan = {
+    'start_column': 264,
+    'stop_column': 400,
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10,
+    'maskfile': 'auto',
+    'mask_diff': False
+}
+
+
+def append_data(scan, data):
+    timestamp = time.time()
+
+    try:
+        with open(out_file, 'r') as of:
+            old_data = yaml.load(of) or {}
+    except IOError:
+        old_data = {}
+
+    if not scan in old_data.keys():
+        old_data[scan] = {}
+
+    with open(out_file, 'w') as of:
+        old_data[scan][timestamp] = {}
+        for key in data.keys():
+            old_data[scan][timestamp][key] = data[key]
+        yaml.dump(old_data, of)
+
+
+if __name__ == "__main__":
+    try:
+        with open('../testbench.yaml', 'r') as tb:
+            config = yaml.load(tb)
+
+        config['output_directory'] = output_dir
+
+        with open('../testbench.yaml', 'w') as tb:
+            yaml.dump(config, tb)
+
+        logger = logging.getLogger('Irradiation')
+        logger.success = lambda msg, *args, **kwargs: logger.log(logging.SUCCESS, msg, *args, **kwargs)
+        logfile = os.path.join(output_dir, 'irradiation.log')
+        fh = logging.FileHandler(logfile)
+        fh.setLevel(logging.INFO)
+        fh.setFormatter(logging.Formatter("%(asctime)s - [%(name)-15s] - %(levelname)-7s %(message)s"))
+        logger.addHandler(fh)
+
+        dut = Dut('irradiation.yaml')
+        dut.init()
+
+        out_file = os.path.join(output_dir, 'irradiation.dat')
+
+        logger.info('Starting new irradiation loop at timestamp %1.6f...' % (time.time()))
+        while True:
+            try:    # Coarse untuned threshold scan
+                logger.info('Start coarse untuned threshold scan...')
+                scan = ThresholdScan()
+                mean_thr, mean_noise = scan.start(**configuration_untuned_coarse_threshold_scan)
+                scan.close()
+
+                append_data('threshold_scan_untuned_coarse', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+                logger.success('Coarse untuned threshold scan finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+            except Exception as e:
+                scan.close()
+                logger.exception('Exception during coarse untuned threshold scan: %s' % e)
+
+            try:    # Fine untuned threshold scan
+                logger.info('Start fine untuned threshold scan...')
+                scan = ThresholdScan()
+                mean_thr, mean_noise = scan.start(**configuration_untuned_fine_threshold_scan)
+                scan.close()
+
+                append_data('threshold_scan_untuned_fine', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+                logger.success('Fine untuned threshold scan finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+            except Exception as e:
+                scan.close()
+                logger.exception('Exception during fine untuned threshold scan: %s' % e)
+
+            try:    # Initial tuning threshold scan for LIN
+                logger.info('Start initial tuning threshold scan for LIN...')
+                scan = ThresholdScan()
+                mean_thr, mean_noise = scan.start(**configuration_initial_tuning_lin_threshold_scan)
+                scan.close()
+
+                append_data('threshold_scan_initial_tuning_LIN', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+                logger.success('Initial tuning threshold scan for LIN finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+            except Exception as e:
+                scan.close()
+                logger.exception('Exception during initial tuning LIN threshold scan: %s' % e)
+
+            try:    # Initial tuning threshold scan for DIFF
+                logger.info('Start initial tuning threshold scan for DIFF...')
+                scan = ThresholdScan()
+                mean_thr, mean_noise = scan.start(**configuration_initial_tuning_diff_threshold_scan)
+                scan.close()
+
+                append_data('threshold_scan_initial_tuning_DIFF', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+                logger.success('Initial tuning threshold scan for DIFF finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+            except Exception as e:
+                scan.close()
+                logger.exception('Exception during initial tuning DIFF threshold scan: %s' % e)
+
+            try:    # Tuning LIN
+                logger.info('Start threshold tuning for LIN...')
+                tuning = MetaTDACTuning()
+                tuning.start(**configuration_tuning_lin)
+                logger.success('LIN tuning finished!')
+            except Exception as e:
+                scan.close()
+                logger.exception('Exception during tuning of LIN: %s' % e)
+
+            try:    # Fine tuned threshold scan for LIN
+                logger.info('Start tuned threshold scan for LIN...')
+                scan = ThresholdScan()
+                mean_thr, mean_noise = scan.start(**configuration_tuned_lin_threshold_scan)
+                scan.close()
+
+                append_data('threshold_scan_tuned_LIN', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+                logger.success('Tuned threshold scan for LIN finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+            except Exception as e:
+                scan.close()
+                logger.exception('Exception during tuned LIN threshold scan: %s' % e)
+
+            try:    # Tuning DIFF
+                logger.info('Start threshold tuning for DIFF...')
+                tuning = MetaTDACTuning()
+                tuning.start(**configuration_tuning_diff)
+                logger.success('DIFF tuning finished!')
+            except Exception as e:
+                scan.close()
+                logger.exception('Exception during tuning of DIFF: %s' % e)
+
+            try:    # Fine tuned threshold scan for LIN
+                logger.info('Start tuned threshold scan for DIFF...')
+                scan = ThresholdScan()
+                mean_thr, mean_noise = scan.start(**configuration_tuned_diff_threshold_scan)
+                scan.close()
+
+                append_data('threshold_scan_tuned_DIFF', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+                logger.success('Tuned threshold scan for DIFF finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+            except Exception as e:
+                scan.close()
+                logger.exception('Exception during tuned DIFF threshold scan: %s' % e)
+
+            try:    # Read Ring Oscillators
+                chip = rd53a.RD53A()
+                chip.init()
+                chip.init_communication()
+
+                T_NTC = float(chip._measure_temperature_ntc_CERNFMC())
+                logger.info("Temperature with NTC is: %1.2f C", T_NTC)
+
+                T_Sens = dut['Thermohygrometer'].get_temperature()[0]
+                RH_Sens = dut['Thermohygrometer'].get_humidity()[0]
+                append_data('Temperature', {'NTC': T_NTC, 'Sensirion': T_Sens, 'Sensirion_RH': RH_Sens})
+
+                chip.enable_monitor_filter()
+                chip.enable_monitor_data()
+
+                oscillators = {}
+                for j in range(8):
+                    chip['FIFO']['RESET']
+                    time.sleep(0.1)
+                    indata = chip.write_sync(write=False) * 40
+                    indata += chip.write_register(register='RING_OSC_ENABLE', data=0b11111111, write=False)
+                    indata += chip.write_register(register='RING_OSC_' + str(j), data=0b0, write=False)
+                    indata += chip.write_register(register='GLOBAL_PULSE_ROUTE', data=0b0010000000000000, write=False)
+                    indata += chip.write_global_pulse(width=8, write=False)
+                    indata += chip.write_sync(write=False) * 40
+                    indata += chip.read_register(register='RING_OSC_' + str(j), write=False)
+                    indata += chip.write_sync(write=False) * 300
+                    chip.write_command(indata)
+
+                    for i in range(10):
+                        if chip['FIFO']['FIFO_SIZE'] > 0:
+                            words = chip['FIFO'].get_data()
+                            break
+                        time.sleep(0.1)
+                    else:
+                        raise Exception('No Data!')
+
+                    data = au.process_userk(au.interpret_userk_data(words))
+                    oscillators['RING_OSC_' + str(j)] = int('0b' + str(bin(data[0][-1]))[-12:], 2)
+
+                append_data('ring_oscillators', oscillators)
+                chip.close()
+            except Exception as e:
+                chip.close()
+                logger.exception('Exception during Ring Oscillator readout: %s' % e)
+
+    except:
+        logger.exception('Stopping irradiation loop at timestamp %1.6f...' % (time.time()))
diff --git a/bdaq53/measurements/irradiation_step.py b/bdaq53/measurements/irradiation_step.py
new file mode 100644
index 000000000..4f2c7238e
--- /dev/null
+++ b/bdaq53/measurements/irradiation_step.py
@@ -0,0 +1,308 @@
+#
+# ------------------------------------------------------------
+# Copyright (c) All rights reserved
+# SiLab, Institute of Physics, University of Bonn
+# ------------------------------------------------------------
+#
+
+'''
+    Irradiation measurement script to be performed at every dose step
+'''
+
+import os
+import time
+import yaml
+import logging
+import copy
+import numpy as np
+
+from basil.dut import Dut
+from bdaq53 import rd53a
+from bdaq53.analysis import analysis_utils as au
+from bdaq53.scans.scan_threshold import ThresholdScan
+from bdaq53.scans.meta_tune_local_threshold import MetaTDACTuning
+
+
+step = '0MRAD'
+
+output_dir = ''
+initial_maskfile_LIN = ''
+initial_maskfile_DIFF = ''
+
+
+configuration_untuned_coarse_threshold_scan = {
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 4000,
+    'VCAL_HIGH_step': 100,
+    'maskfile': None,
+    'mask_diff': False
+}
+
+configuration_untuned_fine_threshold_scan = {
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10,
+    'maskfile': None,
+    'mask_diff': False
+}
+
+configuration_initial_tuning_lin_threshold_scan = {
+    'start_column': 128,
+    'stop_column': 264,
+    'VCAL_HIGH_start': 550,
+    'VCAL_HIGH_stop': 850,
+    'VCAL_HIGH_step': 10,
+    'maskfile': initial_maskfile_LIN,
+    'mask_diff': False
+}
+
+configuration_initial_tuning_diff_threshold_scan = {
+    'start_column': 264,
+    'stop_column': 400,
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10,
+    'maskfile': initial_maskfile_DIFF,
+    'mask_diff': False
+}
+
+configuration_tuning_lin = {
+    'start_column': 128,
+    'stop_column': 264,
+    'maskfile': None,
+
+    'VCAL_MED': 500,
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10
+}
+
+configuration_tuned_lin_threshold_scan = {
+    'start_column': 128,
+    'stop_column': 264,
+    'VCAL_HIGH_start': 550,
+    'VCAL_HIGH_stop': 850,
+    'VCAL_HIGH_step': 10,
+    'maskfile': 'auto',
+    'mask_diff': False
+}
+
+configuration_tuning_diff = {
+    'start_column': 264,
+    'stop_column': 400,
+    'maskfile': None,
+
+    'VCAL_MED': 500,
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10
+}
+
+configuration_tuned_diff_threshold_scan = {
+    'start_column': 264,
+    'stop_column': 400,
+    'VCAL_HIGH_start': 500,
+    'VCAL_HIGH_stop': 800,
+    'VCAL_HIGH_step': 10,
+    'maskfile': 'auto',
+    'mask_diff': False
+}
+
+
+def append_data(scan, data):
+    timestamp = time.time()
+
+    try:
+        with open(out_file, 'r') as of:
+            old_data = yaml.load(of) or {}
+    except IOError:
+        old_data = {}
+
+    if not scan in old_data.keys():
+        old_data[scan] = {}
+
+    with open(out_file, 'w') as of:
+        old_data[scan][timestamp] = {}
+        for key in data.keys():
+            old_data[scan][timestamp][key] = data[key]
+        yaml.dump(old_data, of)
+
+
+if __name__ == "__main__":
+    try:
+        out_dir = os.path.join(output_dir, step)
+
+        with open('../testbench.yaml', 'r') as tb:
+            config = yaml.load(tb)
+
+        config['output_directory'] = out_dir
+
+        with open('../testbench.yaml', 'w') as tb:
+            yaml.dump(config, tb)
+
+        logger = logging.getLogger('Irradiation')
+        logger.success = lambda msg, *args, **kwargs: logger.log(logging.SUCCESS, msg, *args, **kwargs)
+
+        if os.path.isdir(out_dir):
+            logger.error('Output directory already exists!')
+            raise
+        else:
+            os.mkdir(out_dir)
+
+        logfile = os.path.join(out_dir, 'irradiation.log')
+        fh = logging.FileHandler(logfile)
+        fh.setLevel(logging.INFO)
+        fh.setFormatter(logging.Formatter("%(asctime)s - [%(name)-15s] - %(levelname)-7s %(message)s"))
+        logger.addHandler(fh)
+
+        dut = Dut('irradiation.yaml')
+        dut.init()
+
+        out_file = os.path.join(out_dir, 'irradiation.dat')
+
+        logger.info('Starting new irradiation step at timestamp %1.6f...' % (time.time()))
+
+        try:    # Coarse untuned threshold scan
+            logger.info('Start coarse untuned threshold scan...')
+            scan = ThresholdScan()
+            mean_thr, mean_noise = scan.start(**configuration_untuned_coarse_threshold_scan)
+            scan.close()
+
+            append_data('threshold_scan_untuned_coarse', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+            logger.success('Coarse untuned threshold scan finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+        except Exception as e:
+            scan.close()
+            logger.exception('Exception during coarse untuned threshold scan: %s' % e)
+
+        try:    # Fine untuned threshold scan
+            logger.info('Start fine untuned threshold scan...')
+            scan = ThresholdScan()
+            mean_thr, mean_noise = scan.start(**configuration_untuned_fine_threshold_scan)
+            scan.close()
+
+            append_data('threshold_scan_untuned_fine', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+            logger.success('Fine untuned threshold scan finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+        except Exception as e:
+            scan.close()
+            logger.exception('Exception during fine untuned threshold scan: %s' % e)
+
+        try:    # Initial tuning threshold scan for LIN
+            logger.info('Start initial tuning threshold scan for LIN...')
+            scan = ThresholdScan()
+            mean_thr, mean_noise = scan.start(**configuration_initial_tuning_lin_threshold_scan)
+            scan.close()
+
+            append_data('threshold_scan_initial_tuning_LIN', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+            logger.success('Initial tuning threshold scan for LIN finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+        except Exception as e:
+            scan.close()
+            logger.exception('Exception during initial tuning LIN threshold scan: %s' % e)
+
+        try:    # Initial tuning threshold scan for DIFF
+            logger.info('Start initial tuning threshold scan for DIFF...')
+            scan = ThresholdScan()
+            mean_thr, mean_noise = scan.start(**configuration_initial_tuning_diff_threshold_scan)
+            scan.close()
+
+            append_data('threshold_scan_initial_tuning_DIFF', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+            logger.success('Initial tuning threshold scan for DIFF finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+        except Exception as e:
+            scan.close()
+            logger.exception('Exception during initial tuning DIFF threshold scan: %s' % e)
+
+        try:    # Tuning LIN
+            logger.info('Start threshold tuning for LIN...')
+            tuning = MetaTDACTuning()
+            tuning.start(**configuration_tuning_lin)
+            logger.success('LIN tuning finished!')
+        except Exception as e:
+            scan.close()
+            logger.exception('Exception during tuning of LIN: %s' % e)
+
+        try:    # Fine tuned threshold scan for LIN
+            logger.info('Start tuned threshold scan for LIN...')
+            scan = ThresholdScan()
+            mean_thr, mean_noise = scan.start(**configuration_tuned_lin_threshold_scan)
+            scan.close()
+
+            append_data('threshold_scan_tuned_LIN', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+            logger.success('Tuned threshold scan for LIN finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+        except Exception as e:
+            scan.close()
+            logger.exception('Exception during tuned LIN threshold scan: %s' % e)
+
+        try:    # Tuning DIFF
+            logger.info('Start threshold tuning for DIFF...')
+            tuning = MetaTDACTuning()
+            tuning.start(**configuration_tuning_diff)
+            logger.success('DIFF tuning finished!')
+        except Exception as e:
+            scan.close()
+            logger.exception('Exception during tuning of DIFF: %s' % e)
+
+        try:    # Fine tuned threshold scan for LIN
+            logger.info('Start tuned threshold scan for DIFF...')
+            scan = ThresholdScan()
+            mean_thr, mean_noise = scan.start(**configuration_tuned_diff_threshold_scan)
+            scan.close()
+
+            append_data('threshold_scan_tuned_DIFF', {'threshold': float(mean_thr), 'noise': float(mean_noise)})
+
+            logger.success('Tuned threshold scan for DIFF finished! Mean threshold is %i, mean noise is %i.' % (mean_thr, mean_noise))
+        except Exception as e:
+            scan.close()
+            logger.exception('Exception during tuned DIFF threshold scan: %s' % e)
+
+        try:    # Read Ring Oscillators
+            chip = rd53a.RD53A()
+            chip.init()
+            chip.init_communication()
+
+            T_NTC = float(chip._measure_temperature_ntc_CERNFMC())
+            logger.info("Temperature with NTC is: %1.2f C", T_NTC)
+
+            T_Sens = dut['Thermohygrometer'].get_temperature()[0]
+            RH_Sens = dut['Thermohygrometer'].get_humidity()[0]
+            append_data('Temperature', {'NTC': T_NTC, 'Sensirion': T_Sens, 'Sensirion_RH': RH_Sens})
+
+            chip.enable_monitor_filter()
+            chip.enable_monitor_data()
+
+            oscillators = {}
+            for j in range(8):
+                chip['FIFO']['RESET']
+                time.sleep(0.1)
+                indata = chip.write_sync(write=False) * 40
+                indata += chip.write_register(register='RING_OSC_ENABLE', data=0b11111111, write=False)
+                indata += chip.write_register(register='RING_OSC_' + str(j), data=0b0, write=False)
+                indata += chip.write_register(register='GLOBAL_PULSE_ROUTE', data=0b0010000000000000, write=False)
+                indata += chip.write_global_pulse(width=8, write=False)
+                indata += chip.write_sync(write=False) * 40
+                indata += chip.read_register(register='RING_OSC_' + str(j), write=False)
+                indata += chip.write_sync(write=False) * 300
+                chip.write_command(indata)
+
+                for i in range(10):
+                    if chip['FIFO']['FIFO_SIZE'] > 0:
+                        words = chip['FIFO'].get_data()
+                        break
+                    time.sleep(0.1)
+                else:
+                    raise Exception('No Data!')
+
+                data = au.process_userk(au.interpret_userk_data(words))
+                oscillators['RING_OSC_' + str(j)] = int('0b' + str(bin(data[0][-1]))[-12:], 2)
+
+            append_data('ring_oscillators', oscillators)
+            chip.close()
+        except Exception as e:
+            chip.close()
+            logger.exception('Exception during Ring Oscillator readout: %s' % e)
+
+    except:
+        logger.exception('Stopping irradiation loop at timestamp %1.6f...' % (time.time()))
-- 
GitLab


From 5b0e3f4760da34f557a810d93d6e8231e98ae515 Mon Sep 17 00:00:00 2001
From: Michael Daas <daas@physik.uni-bonn.de>
Date: Thu, 10 Jan 2019 13:28:58 +0100
Subject: [PATCH 6/8] Cleanup: Move existing measurements from scans to
 measurements

---
 bdaq53/{scans => measurements}/meta_scan_shmoo.py                | 0
 bdaq53/{scans => measurements}/meta_scan_source_vs_bias.py       | 0
 bdaq53/{scans => measurements}/meta_scan_threshold_parametric.py | 0
 3 files changed, 0 insertions(+), 0 deletions(-)
 rename bdaq53/{scans => measurements}/meta_scan_shmoo.py (100%)
 rename bdaq53/{scans => measurements}/meta_scan_source_vs_bias.py (100%)
 rename bdaq53/{scans => measurements}/meta_scan_threshold_parametric.py (100%)

diff --git a/bdaq53/scans/meta_scan_shmoo.py b/bdaq53/measurements/meta_scan_shmoo.py
similarity index 100%
rename from bdaq53/scans/meta_scan_shmoo.py
rename to bdaq53/measurements/meta_scan_shmoo.py
diff --git a/bdaq53/scans/meta_scan_source_vs_bias.py b/bdaq53/measurements/meta_scan_source_vs_bias.py
similarity index 100%
rename from bdaq53/scans/meta_scan_source_vs_bias.py
rename to bdaq53/measurements/meta_scan_source_vs_bias.py
diff --git a/bdaq53/scans/meta_scan_threshold_parametric.py b/bdaq53/measurements/meta_scan_threshold_parametric.py
similarity index 100%
rename from bdaq53/scans/meta_scan_threshold_parametric.py
rename to bdaq53/measurements/meta_scan_threshold_parametric.py
-- 
GitLab


From 63d5dc9d758c7d32ef926e9e0ef2ee1a29652608 Mon Sep 17 00:00:00 2001
From: Michael Daas <daas@physik.uni-bonn.de>
Date: Thu, 10 Jan 2019 13:33:55 +0100
Subject: [PATCH 7/8] Fix code style

---
 bdaq53/measurements/irradiation_loop.py | 4 ++--
 bdaq53/measurements/irradiation_step.py | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/bdaq53/measurements/irradiation_loop.py b/bdaq53/measurements/irradiation_loop.py
index f573e95b9..52531d176 100644
--- a/bdaq53/measurements/irradiation_loop.py
+++ b/bdaq53/measurements/irradiation_loop.py
@@ -115,7 +115,7 @@ def append_data(scan, data):
     except IOError:
         old_data = {}
 
-    if not scan in old_data.keys():
+    if scan not in old_data.keys():
         old_data[scan] = {}
 
     with open(out_file, 'w') as of:
@@ -292,5 +292,5 @@ if __name__ == "__main__":
                 chip.close()
                 logger.exception('Exception during Ring Oscillator readout: %s' % e)
 
-    except:
+    except KeyboardInterrupt:
         logger.exception('Stopping irradiation loop at timestamp %1.6f...' % (time.time()))
diff --git a/bdaq53/measurements/irradiation_step.py b/bdaq53/measurements/irradiation_step.py
index 4f2c7238e..9f93fc92d 100644
--- a/bdaq53/measurements/irradiation_step.py
+++ b/bdaq53/measurements/irradiation_step.py
@@ -118,7 +118,7 @@ def append_data(scan, data):
     except IOError:
         old_data = {}
 
-    if not scan in old_data.keys():
+    if scan not in old_data.keys():
         old_data[scan] = {}
 
     with open(out_file, 'w') as of:
@@ -304,5 +304,5 @@ if __name__ == "__main__":
             chip.close()
             logger.exception('Exception during Ring Oscillator readout: %s' % e)
 
-    except:
+    except KeyboardInterrupt:
         logger.exception('Stopping irradiation loop at timestamp %1.6f...' % (time.time()))
-- 
GitLab


From 5c96e918b37f8c9e2f41b38a9567b1f0321ac4b4 Mon Sep 17 00:00:00 2001
From: Michael Daas <daas@physik.uni-bonn.de>
Date: Thu, 10 Jan 2019 13:58:28 +0100
Subject: [PATCH 8/8] FIX: No more bare except

---
 bdaq53/rd53a.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bdaq53/rd53a.py b/bdaq53/rd53a.py
index d6b216f65..655348035 100644
--- a/bdaq53/rd53a.py
+++ b/bdaq53/rd53a.py
@@ -1203,8 +1203,8 @@ class RD53A(Dut):
                     time.sleep(0.1)
                 else:
                     raise RuntimeError('Timeout while waiting for chip status.')
-        except Exception:
-            logger.error('There was an error while receiving the chip status.')
+        except RuntimeError as e:
+            logger.error('There was an error while receiving the chip status: %s' % e)
 
         return voltages, currents
 
-- 
GitLab