Belle II Software  release-08-01-10
monitor.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2 as b2
13 from ROOT import Belle2
14 from monitor_module import Monitor
15 
16 # skip the event in the output if it doesn't contain trg data
17 skim_dummy_trg = True
18 # whether to save the output dst file
19 save_output = False
20 # use an input file that is already unpacked
21 from_unpacked = False
22 
23 input_files = Belle2.Environment.Instance().getInputFilesOverride()
24 if not input_files.empty() and input_files.front().endswith(".sroot"):
25  root_input = b2.register_module('SeqRootInput')
26 else:
27  root_input = b2.register_module('RootInput')
28 
29 main = b2.create_path()
30 main.add_module(root_input)
31 
32 if not from_unpacked:
33  main.add_module('Progress')
34  # unpack CDC data
35  # Set Database
36  b2.use_database_chain()
37  b2.use_local_database(Belle2.FileSystem.findFile("data/framework/database.txt"))
38  cdc_unpacker = b2.register_module('CDCUnpacker')
39  cdc_unpacker.param('enableStoreCDCRawHit', True)
40  main.add_module(cdc_unpacker)
41 
42  unpacker = b2.register_module('CDCTriggerUnpacker')
43  unpacker.logging.log_level = b2.LogLevel.DEBUG
44  # increase this value to get debug mesages in more detail
45  unpacker.logging.debug_level = 10
46  unpacker.logging.set_info(b2.LogLevel.DEBUG, b2.LogInfo.LEVEL | b2.LogInfo.MESSAGE)
47  # size (number of words) of the Belle2Link header
48  unpacker.param('headerSize', 3)
49  # unpack the data from the 2D tracker and save its Bitstream
50  unpacker.param('unpackTracker2D', True)
51  # make CDCTriggerSegmentHit objects from the 2D input
52  unpacker.param('decode2DFinderInput', True)
53  # it seems the B2L for 2D0 and 2D1 are swapped
54  unpacker.param('2DNodeId', [
55  [0x11000001, 1],
56  [0x11000001, 0],
57  [0x11000002, 0],
58  [0x11000002, 1]])
59  unpacker.param('2DNodeId_pcie40', [
60  [0x10000001, 0],
61  [0x10000001, 1],
62  [0x10000001, 2],
63  [0x10000001, 3]])
64 
65  main.add_module(unpacker)
66 
67  if skim_dummy_trg:
68  # skip if there are no trigger data in the event
69  empty_path = b2.create_path()
70  unpacker.if_false(empty_path)
71 
72  main.add_module('Gearbox')
73  main.add_module('Geometry', components=['BeamPipe',
74  'PXD', 'SVD', 'CDC',
75  'MagneticFieldConstant4LimitedRCDC'])
76  cdcdigitizer = b2.register_module('CDCDigitizer')
77  # ...CDCDigitizer...
78  # set digitizer to no smearing
79  param_cdcdigi = {'Fraction': 1,
80  'Resolution1': 0.,
81  'Resolution2': 0.,
82  'Threshold': -10.0}
83  cdcdigitizer.param(param_cdcdigi)
84  cdcdigitizer.param('AddInWirePropagationDelay', True)
85  cdcdigitizer.param('AddTimeOfFlight', True)
86  cdcdigitizer.param('UseSimpleDigitization', True)
87  main.add_module(cdcdigitizer)
88  main.add_module('CDCTriggerTSF',
89  InnerTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_Bkg_p0.70_b0.80.coe"),
90  OuterTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_Bkg_p0.70_b0.80.coe"),
91  TSHitCollectionName='TSimSegmentHits')
92 else:
93  save_output = False
94 
95 main.add_module(Monitor())
96 
97 if save_output:
98  # save the output root file with specified file name
99  output_name = input_files.front().split('/')[-1]
100  output_name = output_name[:output_name.rfind('.')] + '.unpacked.root'
101  main.add_module('RootOutput',
102  outputFileName=output_name,
103  excludeBranchNames=['RawCDCs',
104  'RawECLs',
105  'RawKLMs',
106  'RawSVDs',
107  'RawPXDs',
108  'RawTOPs'])
109 
110 b2.process(main)
111 print(b2.statistics)
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:148