Skip to content

Commit

Permalink
Merge pull request #38 from SiLab-Bonn/ext_trigger_scan
Browse files Browse the repository at this point in the history
WIP: Add a dedicated external trigger scan
  • Loading branch information
lschall authored Feb 23, 2024
2 parents b67c6a6 + e0cb494 commit 9711935
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tjmonopix2/analysis/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def create_standard_plots(self):
else:
self.create_parameter_page()
self.create_occupancy_map()
if self.run_config['scan_id'] in ['simple_scan']:
if self.run_config['scan_id'] in ['source_scan', 'ext_trigger_scan']:
self.create_fancy_occupancy()
if self.run_config['scan_id'] in ['analog_scan', 'threshold_scan', 'global_threshold_tuning', 'simple_scan', 'calibrate_tot']:
if self.run_config['scan_id'] in ['analog_scan', 'threshold_scan', 'global_threshold_tuning', 'source_scan', 'ext_trigger_scan', 'calibrate_tot']:
self.create_hit_pix_plot()
self.create_tdac_plot()
self.create_tdac_map()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
}


class SimpleScan(ScanBase):
scan_id = 'simple_scan'
class ExtTriggerScan(ScanBase):
scan_id = 'ext_trigger_scan'

stop_scan = threading.Event()

def _configure(self, scan_timeout=10, max_triggers=False, start_column=0, stop_column=512, start_row=0, stop_row=512, **_):
def _configure(self, scan_timeout=False, max_triggers=1000, start_column=0, stop_column=512, start_row=0, stop_row=512, **_):
self.log.info('External trigger scan needs TLU running!')

if scan_timeout and max_triggers:
self.log.warning('You should only use one of the stop conditions at a time.')

Expand All @@ -39,9 +41,10 @@ def _configure(self, scan_timeout=10, max_triggers=False, start_column=0, stop_c
self.chip.masks.update()

self.daq.configure_tlu_veto_pulse(veto_length=500)
self.daq.configure_tlu_module(max_triggers=max_triggers)
if max_triggers:
self.daq.configure_tlu_module(max_triggers=max_triggers)

def _scan(self, scan_timeout=10, max_triggers=False, **_):
def _scan(self, scan_timeout=False, max_triggers=1000, **_):
def timed_out():
if scan_timeout:
current_time = time.time()
Expand Down Expand Up @@ -85,9 +88,7 @@ def timed_out():
self.log.info('Scan was stopped due to keyboard interrupt')

self.pbar.close()
if max_triggers:
self.daq.disable_tlu_module()

self.daq.disable_tlu_module()
self.log.success('Scan finished')

def _analyze(self):
Expand All @@ -104,5 +105,5 @@ def _analyze(self):


if __name__ == "__main__":
with SimpleScan(scan_config=scan_configuration) as scan:
with ExtTriggerScan(scan_config=scan_configuration) as scan:
scan.start()
84 changes: 84 additions & 0 deletions tjmonopix2/scans/scan_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#
# ------------------------------------------------------------
# Copyright (c) All rights reserved
# SiLab, Institute of Physics, University of Bonn
# ------------------------------------------------------------
#

import time
import threading
from tqdm import tqdm

from tjmonopix2.analysis import analysis, plotting
from tjmonopix2.system.scan_base import ScanBase

scan_configuration = {
'start_column': 0,
'stop_column': 224,
'start_row': 0,
'stop_row': 512,

'scan_timeout': 30, # Timeout for scan after which the scan will be stopped, in seconds; if False no limit on scan time

'tot_calib_file': None # path to ToT calibration file for charge to e⁻ conversion, if None no conversion will be done
}


class SourceScan(ScanBase):
scan_id = 'source_scan'

stop_scan = threading.Event()

def _configure(self, start_column=0, stop_column=512, start_row=0, stop_row=512, **_):
self.chip.masks['enable'][start_column:stop_column, start_row:stop_row] = True
self.chip.masks.apply_disable_mask()
self.chip.masks.update()

def _scan(self, scan_timeout=10, **_):
def timed_out():
if scan_timeout:
current_time = time.time()
if current_time - start_time > scan_timeout:
self.log.info('Scan timeout was reached')
return True
return False

self.pbar = tqdm(total=scan_timeout, unit='') # [s]
start_time = time.time()

with self.readout():
self.stop_scan.clear()

while not (self.stop_scan.is_set() or timed_out()):
try:
time.sleep(1)

# Update progress bar
try:
self.pbar.update(1)
except ValueError:
pass

except KeyboardInterrupt: # React on keyboard interupt
self.stop_scan.set()
self.log.info('Scan was stopped due to keyboard interrupt')

self.pbar.close()
self.log.success('Scan finished')

def _analyze(self):
tot_calib_file = self.configuration['scan'].get('tot_calib_file', None)
if tot_calib_file is not None:
self.configuration['bench']['analysis']['cluster_hits'] = True

with analysis.Analysis(raw_data_file=self.output_filename + '.h5', tot_calib_file=tot_calib_file, **self.configuration['bench']['analysis']) as a:
a.analyze_data()

if self.configuration['bench']['analysis']['create_pdf']:
with plotting.Plotting(analyzed_data_file=a.analyzed_data_file) as p:
p.create_standard_plots()


if __name__ == "__main__":
with SourceScan(scan_config=scan_configuration) as scan:
scan.start()

0 comments on commit 9711935

Please sign in to comment.