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