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