Belle II Software development
perfect_match.py
1#!/usr/bin/env python3
2
3
10
11
17
18import basf2 as b2
19from ROOT import Belle2
20
21# Set the log level to show only error and fatal messages
22b2.set_log_level(b2.LogLevel.INFO)
23
24# Set Database
25b2.use_database_chain()
26b2.use_local_database(Belle2.FileSystem.findFile("data/framework/database.txt"))
27
28# Input file
29# Get type of input file to decide, which input module we want to use
30input_files = Belle2.Environment.Instance().getInputFilesOverride()
31if input_files.empty():
32 print('Please specify input file(s). Example usage:',
33 'basf2 perfect_match.py -i input.sroot')
34 exit(1)
35if input_files.front().endswith(".sroot"):
36 root_input = b2.register_module('SeqRootInput')
37else:
38 root_input = b2.register_module('RootInput')
39
40unpacker = b2.register_module('CDCUnpacker')
41unpacker.param('enableStoreCDCRawHit', True)
42# unpacker.param('enablePrintOut', True)
43output = b2.register_module('RootOutput')
44output.param('outputFileName', 'UnpackerOutput.root')
45output.param('branchNames', ['CDCHits', 'CDCRawHits'])
46
47
48class PrintTRGTime(b2.Module):
49 """
50 Print TRG time
51 """
52
53 def initialize(self):
54 """
55 set CDCHits and EventMetaData
56 """
57
58 self.event_info = Belle2.PyStoreObj('EventMetaData')
59
60 self.cdc_hit = Belle2.PyStoreArray('CDCHits')
61
62 def event(self):
63 """
64 Print TRG time of an event
65 """
66 b2.B2INFO(f'Event {self.event_info.getEvent()}:')
67 for hit in self.cdc_hit:
68 cdc_raw_hit = hit.getRelatedTo('CDCRawHits')
69 b2.B2INFO(f'Trigger time: {cdc_raw_hit.getTriggerTime()}')
70
71
72# Create main path
73main = b2.create_path()
74
75# Add modules to main path
76main.add_module(root_input)
77main.add_module(unpacker)
78main.add_module(PrintTRGTime())
79# main.add_module(output)
80
81# Process all events
82b2.print_path(main)
83b2.process(main)
84
85print(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:151
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67