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