Belle II Software  release-05-01-25
__init__.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import basf2
5 from basf2 import *
6 from ROOT import Belle2
7 
8 
9 def add_svd_reconstruction(path, isROIsimulation=False, useNN=False, useCoG=True, applyMasking=False):
10 
11  if(useNN and useCoG):
12  print("WARNING! you can't select both NN and CoG for SVD reconstruction. Using the default algorithm (TB-equivalent)")
13  add_svd_reconstruction_tb(path, isROIsimulation)
14 
15  elif(not useNN and not useCoG):
16  add_svd_reconstruction_tb(path, isROIsimulation)
17 
18  elif(useNN):
19  add_svd_reconstruction_nn(path, isROIsimulation)
20 
21  elif(useCoG):
22  add_svd_reconstruction_CoG(path, isROIsimulation, applyMasking)
23 
24 
25 def add_svd_reconstruction_tb(path, isROIsimulation=False):
26 
27  if(isROIsimulation):
28  splitterName = '__ROISVDDigitSplitter'
29  sorterName = '__ROISVDDigitSorter'
30  clusterizerName = '__ROISVDClusterizer'
31  clusterName = '__ROIsvdClusters'
32  else:
33  splitterName = 'SVDDigitSplitter'
34  sorterName = 'SVDDigitSorter'
35  clusterizerName = 'SVDClusterizer'
36  clusterName = ""
37 
38  if splitterName not in [e.name() for e in path.modules()]:
39  splitter = register_module('SVDDigitSplitter')
40  splitter.set_name(splitterName)
41  path.add_module(splitter)
42 
43  if sorterName not in [e.name() for e in path.modules()]:
44  sorter = register_module('SVDDigitSorter')
45  sorter.set_name(sorterName)
46  path.add_module(sorter)
47 
48  if clusterizerName not in [e.name() for e in path.modules()]:
49  clusterizer = register_module('SVDClusterizer')
50  clusterizer.set_name(clusterizerName)
51  clusterizer.param('Clusters', clusterName)
52  path.add_module(clusterizer)
53 
54 
55 def add_svd_reconstruction_nn(path, isROIsimulation=False, direct=False):
56 
57  if direct:
58  if(isROIsimulation):
59  clusterizerName = '__ROISVDClusterizerDirect'
60  clusterName = '__ROIsvdClusters'
61  else:
62  clusterizerName = 'SVDClusterizerDirect'
63  clusterName = ""
64 
65  if clusterizerName not in [e.name() for e in path.modules()]:
66  clusterizer = register_module('SVDClusterizerDirect')
67  clusterizer.set_name(clusterizerName)
68  clusterizer.param('Clusters', clusterName)
69  path.add_module(clusterizer)
70  else:
71  if(isROIsimulation):
72  fitterName = '__ROISVDNNShapeReconstructor'
73  clusterizerName = '__ROISVDNNClusterizer'
74  clusterName = '__ROIsvdClusters'
75  else:
76  fitterName = 'SVDNNShapeReconstructor'
77  clusterizerName = 'SVDNNClusterizer'
78  clusterName = ''
79 
80  if fitterName not in [e.name() for e in path.modules()]:
81  fitter = register_module('SVDNNShapeReconstructor')
82  fitter.set_name(fitterName)
83  path.add_module(fitter)
84 
85  if clusterizerName not in [e.name() for e in path.modules()]:
86  clusterizer = register_module('SVDNNClusterizer')
87  clusterizer.set_name(clusterizerName)
88  clusterizer.param('Clusters', clusterName)
89  path.add_module(clusterizer)
90 
91 
92 def add_svd_reconstruction_CoG(path, isROIsimulation=False, applyMasking=False):
93 
94  if(isROIsimulation):
95  fitterName = '__ROISVDCoGTimeEstimator'
96  clusterizerName = '__ROISVDSimpleClusterizer'
97  dataFormatName = '__ROISVDDataFormat'
98  clusterName = '__ROIsvdClusters'
99  recoDigitsName = '__ROIsvdRecoDigits'
100  shaperDigitsName = ""
101  missingAPVsClusterCreatorName = '__ROISVDMissingAPVsClusterCreator'
102  else:
103  fitterName = 'SVDCoGTimeEstimator'
104  clusterizerName = 'SVDSimpleClusterizer'
105  dataFormatName = 'SVDDataFormat'
106  clusterName = ""
107  recoDigitsName = ""
108  shaperDigitsName = ""
109  missingAPVsClusterCreatorName = 'SVDMissingAPVsClusterCreator'
110 
111 # add strip masking if needed
112  if(applyMasking):
113  if(isROIsimulation):
114  shaperDigitsName = '__ROISVDShaperDigitsUnmasked'
115  maskingName = '__ROISVDStripMasking'
116  else:
117  shaperDigitsName = 'SVDShaperDigitsUnmasked'
118  maskingName = 'SVDStripMasking'
119 
120  if maskingName not in [e.name() for e in path.modules()]:
121  masking = register_module('SVDStripMasking')
122  masking.set_name(maskingName)
123  masking.param('ShaperDigitsUnmasked', shaperDigitsName)
124  path.add_module(masking)
125 
126  if dataFormatName not in [e.name() for e in path.modules()]:
127  dataFormat = register_module('SVDDataFormatCheck')
128  dataFormat.param('ShaperDigits', shaperDigitsName)
129 
130  if fitterName not in [e.name() for e in path.modules()]:
131  fitter = register_module('SVDCoGTimeEstimator')
132  fitter.set_name(fitterName)
133  fitter.param('RecoDigits', recoDigitsName)
134  path.add_module(fitter)
135 
136  if clusterizerName not in [e.name() for e in path.modules()]:
137  clusterizer = register_module('SVDSimpleClusterizer')
138  clusterizer.set_name(clusterizerName)
139  clusterizer.param('RecoDigits', recoDigitsName)
140  clusterizer.param('Clusters', clusterName)
141  clusterizer.param('useDB', True)
142  path.add_module(clusterizer)
143 
144  if missingAPVsClusterCreatorName not in [e.name() for e in path.modules()]:
145  missingAPVCreator = register_module('SVDMissingAPVsClusterCreator')
146  missingAPVCreator.set_name(missingAPVsClusterCreatorName)
147  path.add_module(missingAPVCreator)
148 
149  # Add SVDSpacePointCreator
150  add_svd_SPcreation(path, isROIsimulation)
151 
152 
153 def add_svd_reconstruction_nn(path, isROIsimulation=False, direct=False):
154 
155  if direct:
156  if(isROIsimulation):
157  clusterizerName = '__ROISVDClusterizerDirect'
158  clusterName = '__ROIsvdClusters'
159  else:
160  clusterizerName = 'SVDClusterizerDirect'
161  clusterName = ""
162 
163  if clusterizerName not in [e.name() for e in path.modules()]:
164  clusterizer = register_module('SVDClusterizerDirect')
165  clusterizer.set_name(clusterizerName)
166  clusterizer.param('Clusters', clusterName)
167  path.add_module(clusterizer)
168  else:
169  if(isROIsimulation):
170  fitterName = '__ROISVDNNShapeReconstructor'
171  clusterizerName = '__ROISVDNNClusterizer'
172  clusterName = '__ROIsvdClusters'
173  else:
174  fitterName = 'SVDNNShapeReconstructor'
175  clusterizerName = 'SVDNNClusterizer'
176  clusterName = ''
177 
178  if fitterName not in [e.name() for e in path.modules()]:
179  fitter = register_module('SVDNNShapeReconstructor')
180  fitter.set_name(fitterName)
181  path.add_module(fitter)
182 
183  if clusterizerName not in [e.name() for e in path.modules()]:
184  clusterizer = register_module('SVDNNClusterizer')
185  clusterizer.set_name(clusterizerName)
186  clusterizer.param('Clusters', clusterName)
187  path.add_module(clusterizer)
188 
189 
190 def add_svd_simulation(path):
191 
192  svdevtinfoset = register_module("SVDEventInfoSetter")
193  path.add_module(svdevtinfoset)
194  digitizer = register_module('SVDDigitizer')
195  path.add_module(digitizer)
196 
197 
198 def add_svd_unpacker(path):
199 
200  unpacker = register_module('SVDUnpacker')
201  path.add_module(unpacker)
202 
203 
204 def add_svd_packer(path):
205 
206  packer = register_module('SVDPacker')
207  path.add_module(packer)
208 
209 
210 def add_svd_SPcreation(path, isROIsimulation=False):
211 
212  if(isROIsimulation):
213  svdSPCreatorName = '__ROISVDSpacePointCreator'
214  svd_clusters = '__ROIsvdClusters'
215  nameSPs = 'SVDSpacePoints__ROI'
216  else:
217  svdSPCreatorName = 'SVDSpacePointCreator'
218  svd_clusters = ''
219  nameSPs = 'SVDSpacePoints'
220 
221  if svdSPCreatorName not in [e.name() for e in path.modules()]:
222  spCreatorSVD = register_module('SVDSpacePointCreator')
223  spCreatorSVD.set_name(svdSPCreatorName)
224  spCreatorSVD.param('NameOfInstance', 'SVDSpacePoints')
225  spCreatorSVD.param('SpacePoints', nameSPs)
226  spCreatorSVD.param('SVDClusters', svd_clusters)
227  path.add_module(spCreatorSVD)