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