Belle II Software  release-05-01-25
runTBC.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 #
4 # Steering file to produce the Time Base calibration out of a pulser run
5 # Called by the wrapper scripts runTBCpocket.sh and runTBClocal.sh, which
6 # sets the proper directories for the output.
7 #
8 # Note: check the global tag!
9 #
10 # Contributors: Marko Staric, Umberto Tamponi
11 #
12 
13 from basf2 import *
14 import os
15 import sys
16 
17 # read parameters
18 
19 argvs = sys.argv
20 if len(argvs) is not 5:
21  print('usage: basf2', argvs[0],
22  '-i <file_sroot> (pocket|local) <slot> <channel> <output_dir>')
23  sys.exit()
24 
25 datatype = argvs[1] # data type (pocket, local)
26 slot = int(argvs[2]) # slot number (1-16)
27 channel = int(argvs[3]) # calibration channel (0-7)
28 outdir = argvs[4] # output directory path
29 
30 print('data type:', datatype, ' slot:', slot, ' calibration channel:', channel,
31  ' output to:', outdir)
32 
33 # Define a global tag (note: the one given bellow can be out-dated!)
34 use_central_database('data_reprocessing_proc8')
35 
36 # Suppress messages and warnings during processing
37 set_log_level(LogLevel.ERROR)
38 
39 # Create path
40 main = create_path()
41 
42 # input
43 roinput = register_module('SeqRootInput')
44 main.add_module(roinput)
45 
46 # conversion from RawCOPPER or RawDataBlock to RawDetector objects
47 if datatype == 'pocket':
48  print('pocket DAQ data assumed')
49  converter = register_module('Convert2RawDet')
50  main.add_module(converter)
51 
52 # Initialize TOP geometry parameters (creation of Geant geometry is not needed)
53 main.add_module('TOPGeometryParInitializer')
54 
55 # Unpacking (format auto detection works now)
56 unpack = register_module('TOPUnpacker')
57 main.add_module(unpack)
58 
59 # Add multiple hits by running feature extraction offline
60 featureExtractor = register_module('TOPWaveformFeatureExtractor')
61 main.add_module(featureExtractor)
62 
63 # Convert to TOPDigits
64 converter = register_module('TOPRawDigitConverter')
65 converter.param('useSampleTimeCalibration', False)
66 converter.param('useChannelT0Calibration', False)
67 converter.param('useModuleT0Calibration', False)
68 converter.param('useCommonT0Calibration', False)
69 converter.param('calibrationChannel', channel) # if set, cal pulses will be flagged
70 converter.param('calpulseHeightMin', 450) # in [ADC counts]
71 converter.param('calpulseHeightMax', 900) # in [ADC counts]
72 converter.param('calpulseWidthMin', 2.0) # in [ns]
73 converter.param('calpulseWidthMax', 8.0) # in [ns]
74 converter.param('lookBackWindows', 29) # in number of windows
75 main.add_module(converter)
76 
77 # TB calibrator
78 calib = register_module('TOPTimeBaseCalibrator')
79 calib.param('moduleID', slot)
80 calib.param('method', 1) # Matrix inversion or iterative
81 calib.param('directoryName', outdir)
82 calib.logging.log_level = LogLevel.INFO
83 main.add_module(calib)
84 
85 # Show progress of processing
86 progress = register_module('Progress')
87 main.add_module(progress)
88 
89 # Process events
90 process(main)
91 
92 # Print call statistics
93 print(statistics)
94 print(statistics(statistics.TERM))