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