Belle II Software  release-08-01-10
rawdata.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2 as b2
12 from geometry import check_components
13 from pxd import add_pxd_packer, add_pxd_unpacker
14 from svd import add_svd_packer, add_svd_unpacker
15 from neurotrigger import add_neuro_2d_unpackers
16 
17 
18 def add_packers(path, components=None):
19  """
20  This function adds the raw data packer modules to a path.
21  """
22 
23  # Check components.
24  check_components(components)
25 
26  # Add Gearbox or geometry to path if not already there
27  if "Gearbox" not in path:
28  path.add_module("Gearbox")
29 
30  if "Geometry" not in path:
31  path.add_module("Geometry")
32 
33  # PXD
34  if components is None or 'PXD' in components:
35  add_pxd_packer(path)
36 
37  # SVD
38  if components is None or 'SVD' in components:
39  add_svd_packer(path)
40 
41  # CDC
42  if components is None or 'CDC' in components:
43  cdcpacker = b2.register_module('CDCPacker')
44  path.add_module(cdcpacker)
45 
46  # ECL
47  if components is None or 'ECL' in components:
48  eclpacker = b2.register_module('ECLPacker')
49  path.add_module(eclpacker)
50 
51  # TOP
52  if components is None or 'TOP' in components:
53  toppacker = b2.register_module('TOPPacker')
54  path.add_module(toppacker)
55 
56  # ARICH
57  if components is None or 'ARICH' in components:
58  arichpacker = b2.register_module('ARICHPacker')
59  path.add_module(arichpacker)
60 
61  # KLM
62  if components is None or 'KLM' in components:
63  klmpacker = b2.register_module('KLMPacker')
64  path.add_module(klmpacker)
65 
66 
67 def add_unpackers(path, components=None, writeKLMDigitRaws=False, addTOPRelations=False):
68  """
69  This function adds the raw data unpacker modules to a path.
70 
71  :param components: list of geometry components to include reconstruction for, or None for all components.
72  :param writeKLMDigitRaws: flag for creating the KLMDigitRaw object and storing it in the datastore. The KLMDQM
73  module needs it for filling some histograms.
74  :param addTOPRelations: flag for creating relations in TOPUnpacker and TOPRawDigitConverter
75  """
76 
77  # Check components.
78  check_components(components)
79 
80  # Add Gearbox or geometry to path if not already there
81  if "Gearbox" not in path:
82  path.add_module("Gearbox")
83 
84  if "Geometry" not in path:
85  path.add_module("Geometry")
86 
87  # TTD
88  if 'SimulateEventLevelTriggerTimeInfo' not in path:
89  path.add_module('TTDUnpacker')
90 
91  # PXD
92  if components is None or 'PXD' in components:
93  add_pxd_unpacker(path)
94 
95  # SVD
96  if components is None or 'SVD' in components:
97  add_svd_unpacker(path)
98 
99  # CDC
100  if components is None or 'CDC' in components:
101  cdcunpacker = b2.register_module('CDCUnpacker')
102  cdcunpacker.param('enableStoreCDCRawHit', True)
103  cdcunpacker.param('enablePrintOut', False)
104  path.add_module(cdcunpacker)
105 
106  # ECL
107  if components is None or 'ECL' in components:
108  eclunpacker = b2.register_module('ECLUnpacker')
109  eclunpacker.param("storeTrigTime", True)
110  path.add_module(eclunpacker)
111 
112  # TOP
113  if components is None or 'TOP' in components:
114  topunpacker = b2.register_module('TOPUnpacker')
115  topunpacker.param('addRelations', addTOPRelations)
116  path.add_module(topunpacker)
117  topconverter = b2.register_module('TOPRawDigitConverter')
118  topconverter.param('addRelations', addTOPRelations)
119  path.add_module(topconverter)
120 
121  # ARICH
122  if components is None or 'ARICH' in components:
123  arichunpacker = b2.register_module('ARICHUnpacker')
124  path.add_module(arichunpacker)
125 
126  # KLM
127  if components is None or 'KLM' in components:
128  klmunpacker = b2.register_module('KLMUnpacker')
129  klmunpacker.param('WriteDigitRaws', writeKLMDigitRaws)
130  path.add_module(klmunpacker)
131 
132  # TRG
133  if components is None or 'TRG' in components:
134 
135  trggdlunpacker = b2.register_module('TRGGDLUnpacker')
136  path.add_module(trggdlunpacker)
137  trggdlsummary = b2.register_module('TRGGDLSummary')
138  path.add_module(trggdlsummary)
139  trgeclunpacker = b2.register_module('TRGECLUnpacker')
140  path.add_module(trgeclunpacker)
141  trggrlunpacker = b2.register_module('TRGGRLUnpacker')
142  path.add_module(trggrlunpacker)
143  trgtopunpacker = b2.register_module('TRGTOPUnpacker')
144  path.add_module(trgtopunpacker)
145 
146  nmod_tsf = [0, 1, 2, 3, 4, 5, 6]
147  for mod_tsf in nmod_tsf:
148  path.add_module('TRGCDCTSFUnpacker', TSFMOD=mod_tsf)
149 
150  nmod_t3d = [0, 1, 2, 3]
151  for mod_t3d in nmod_t3d:
152  path.add_module('TRGCDCT3DUnpacker', T3DMOD=mod_t3d)
153 
154  # unpacker for neurotrigger
155  add_neuro_2d_unpackers(path)
156 
157 
158 def add_raw_output(path, filename='raw.root', additionalBranches=None):
159  """
160  This function adds an output module for raw data to a path.
161  """
162  if additionalBranches is None:
163  additionalBranches = []
164  output = b2.register_module('RootOutput')
165  output.param('outputFileName', filename)
166  branches = ['RawPXDs', 'RawSVDs', 'RawCDCs', 'RawTOPs', 'RawARICHs', 'RawECLs', 'RawKLMs']
167  branches += additionalBranches
168  output.param('branchNames', branches)
169  path.add_module(output)
170 
171 
172 def add_raw_seqoutput(path, filename='raw.sroot', additionalObjects=None, fileNameIsPattern=False):
173  """
174  This function adds an seqroot output module for raw data to a path.
175 
176  :param bool fileNameIsPattern: If true the filename needs to be a printf pattern with a placeholder for the
177  filenumber starting at 0, for example "raw-f%06d.root"
178  """
179  if additionalObjects is None:
180  additionalObjects = []
181  output = b2.register_module('SeqRootOutput')
182  output.param('outputFileName', filename)
183  output.param('fileNameIsPattern', fileNameIsPattern)
184  objects = ['EventMetaData', 'RawPXDs', 'RawSVDs', 'RawCDCs', 'RawTOPs', 'RawARICHs', 'RawECLs', 'RawKLMs']
185  objects += additionalObjects
186  output.param('saveObjs', objects)
187  path.add_module(output)