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