Belle II Software  release-08-01-10
unpack_cdctrigger.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 
15 
16 # usage: basf2 SOME_PATH/unpack_cdctrigger.py -i inputFile.[s]root [-o outputFile.root]
17 # (items in the square brackets [] are optional)
18 
19 import basf2 as b2
20 from ROOT import Belle2
21 
22 # whether we will also unpack CDC data
23 unpack_CDCHit = True
24 # don't save the event in the output if it doesn't contain trg data
25 skim_dummy_trg = True
26 
27 input_files = Belle2.Environment.Instance().getInputFilesOverride()
28 if not input_files.empty() and input_files.front().endswith(".sroot"):
29  root_input = b2.register_module('SeqRootInput')
30 else:
31  root_input = b2.register_module('RootInput')
32 
33 main = b2.create_path()
34 main.add_module(root_input)
35 
36 if unpack_CDCHit:
37  # Set Database
38  b2.use_database_chain()
39  b2.use_local_database(Belle2.FileSystem.findFile("data/framework/database.txt"))
40  cdc_unpacker = b2.register_module('CDCUnpacker')
41  cdc_unpacker.param('enableStoreCDCRawHit', True)
42  main.add_module(cdc_unpacker)
43 
44 unpacker = b2.register_module('CDCTriggerUnpacker')
45 unpacker.logging.log_level = b2.LogLevel.DEBUG
46 # increase this value to get debug mesages in more detail
47 unpacker.logging.debug_level = 10
48 unpacker.logging.set_info(b2.LogLevel.DEBUG, b2.LogInfo.LEVEL | b2.LogInfo.MESSAGE)
49 # size (number of words) of the Belle2Link header
50 unpacker.param('headerSize', 3)
51 # unpack the data from the 2D tracker and save its Bitstream
52 unpacker.param('unpackTracker2D', True)
53 # make CDCTriggerTrack and CDCTriggerSegmentHit objects from the 2D output
54 unpacker.param('decode2DFinderTrack', True)
55 # make CDCTriggerSegmentHit objects from the 2D input
56 unpacker.param('decode2DFinderInput', True)
57 # it seems the B2L for 2D0 and 2D1 are swapped
58 unpacker.param('2DNodeId', [
59  [0x11000001, 1],
60  [0x11000001, 0],
61  [0x11000002, 0],
62  [0x11000002, 1]])
63 unpacker.param('2DNodeId_pcie40', [
64  [0x10000001, 0],
65  [0x10000001, 1],
66  [0x10000001, 2],
67  [0x10000001, 3]])
68 
69 main.add_module(unpacker)
70 
71 if skim_dummy_trg:
72  # don't save the output if there are no trigger data in the event
73  empty_path = b2.create_path()
74  unpacker.if_false(empty_path)
75 
76 # save the output root file with specified file name
77 main.add_module('RootOutput',
78  outputFileName='unpackedCDCTrigger.root',
79  excludeBranchNames=['RawCDCs',
80  'RawECLs',
81  'RawKLMs',
82  'RawSVDs',
83  'RawPXDs',
84  'RawTOPs'])
85 b2.process(main)
86 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