5 from geometry
import check_components
6 from ROOT
import Belle2
7 from pxd
import add_pxd_simulation
8 from svd
import add_svd_simulation
9 from svd
import add_svd_reconstruction
10 from tracking
import add_tracking_for_PXDDataReduction_simulation
13 def check_simulation(path):
14 """Check if the minimum number of modules required for simulation are in
15 the path and in the correct order"""
16 required = [
'Gearbox',
'Geometry',
'FullSim']
20 for module
in path.modules():
21 module_type = module.type()
23 if module_type
in required:
25 if module_type
in found:
26 B2ERROR(
"Duplicate module in path: %s" % module_type)
28 found.append(module.type())
30 if len(required) != len(found):
34 B2ERROR(
"No '%s' module found but needed for simulation" % r)
36 elif required != found:
37 B2ERROR(
"Simulation modules in wrong order. Should be '%s' but is '%s'"
38 % (
", ".join(required),
", ".join(found)))
41 def add_PXDDataReduction(path, components, pxd_unfiltered_digits='pxd_unfiltered_digits',
42 doCleanup=True, overrideDB=False, usePXDDataReduction=True):
44 This function adds the standard simulation modules to a path.
45 @param pxd_unfiltered_digits: the name of the StoreArray containing the input PXDDigits
46 @param overrideDB: override settings from the DB with the value set in 'usePXDDataReduction'
47 @param usePXDDataReduction: if 'overrideDB==True', override settings from the DB
48 @param doCleanup: if 'doCleanup=True' temporary datastore objects are emptied
52 svd_cluster =
'__ROIsvdClusters'
53 add_svd_reconstruction(path, isROIsimulation=
True)
56 svd_reco_tracks =
'__ROIsvdRecoTracks'
58 add_tracking_for_PXDDataReduction_simulation(path, components, svd_cluster=
'__ROIsvdClusters')
60 add_roiFinder(path, svd_reco_tracks)
63 pxd_digifilter = register_module(
'PXDdigiFilter')
64 pxd_digifilter.param(
'ROIidsName',
'ROIs')
65 pxd_digifilter.param(
'PXDDigitsName', pxd_unfiltered_digits)
66 pxd_digifilter.param(
'PXDDigitsInsideROIName',
'PXDDigits')
67 pxd_digifilter.param(
'overrideDB', overrideDB)
68 pxd_digifilter.param(
'usePXDDataReduction', usePXDDataReduction)
69 path.add_module(pxd_digifilter)
73 datastore_cleaner = register_module(
'PruneDataStore')
74 datastore_cleaner.param(
'keepMatchedEntries',
False)
75 datastore_cleaner.param(
'matchEntries', [
'ROIs',
'__ROIsvdRecoDigits',
'__ROIsvdClusters',
'__ROIsvdRecoTracks',
76 'SPTrackCands__ROI',
'SpacePoints__ROI', pxd_unfiltered_digits,
78 'SegmentNetwork__ROI',
'PXDInterceptsToROIs',
79 'RecoHitInformationsTo__ROIsvdClusters',
80 'SpacePoints__ROITo__ROIsvdClusters',
'__ROIsvdClustersToMCParticles',
81 '__ROIsvdRecoDigitsToMCParticles',
82 '__ROIsvdClustersTo__ROIsvdRecoDigits',
'__ROIsvdClustersToSVDTrueHits',
83 '__ROIsvdClustersTo__ROIsvdRecoTracks',
'__ROIsvdRecoTracksToPXDIntercepts',
84 '__ROIsvdRecoTracksToRecoHitInformations',
85 '__ROIsvdRecoTracksToSPTrackCands__ROI'])
86 path.add_module(datastore_cleaner)
89 def add_roiFinder(path, reco_tracks):
91 Add the ROI finding to the path creating ROIs out of reco tracks by extrapolating them to the PXD volume.
92 :param path: Where to add the module to.
93 :param reco_tracks: Which tracks to use in the extrapolation step.
96 pxdDataRed = register_module(
'PXDROIFinder')
98 'recoTrackListName': reco_tracks,
99 'PXDInterceptListName':
'PXDIntercepts',
100 'ROIListName':
'ROIs',
101 'tolerancePhi': 0.15,
110 pxdDataRed.param(param_pxdDataRed)
111 path.add_module(pxdDataRed)
119 forceSetPXDDataReduction=False,
120 usePXDDataReduction=True,
121 cleanupPXDDataReduction=True,
122 generate_2nd_cdc_hits=False,
123 simulateT0jitter=False,
124 usePXDGatedMode=False):
126 This function adds the standard simulation modules to a path.
127 @param forceSetPXDDataReduction: override settings from the DB with the value set in 'usePXDDataReduction'
128 @param usePXDDataReduction: if 'forceSetPXDDataReduction==True', override settings from the DB
129 @param cleanupPXDDataReduction: if True the datastore objects used by PXDDataReduction are emptied
133 check_components(components)
136 if bkgfiles
is not None:
138 bkginput = register_module(
'BGOverlayInput')
139 bkginput.param(
'inputFileNames', bkgfiles)
140 path.add_module(bkginput)
142 bkgmixer = register_module(
'BeamBkgMixer')
143 bkgmixer.param(
'backgroundFiles', bkgfiles)
145 bkgmixer.param(
'components', components)
146 path.add_module(bkgmixer)
148 if components
is None or 'PXD' in components:
150 bkgmixer.param(
'minTimePXD', -20000.0)
151 bkgmixer.param(
'maxTimePXD', 20000.0)
153 pxd_veto_emulator = register_module(
'PXDInjectionVetoEmulator')
154 path.add_module(pxd_veto_emulator)
157 if 'Gearbox' not in path:
158 gearbox = register_module(
'Gearbox')
159 path.add_module(gearbox)
162 if 'Geometry' not in path:
163 path.add_module(
'Geometry', useDB=
True)
164 if components
is not None:
165 B2WARNING(
"Custom detector components specified: Will still build full geometry")
168 if simulateT0jitter
and 'EventT0Generator' not in path:
169 eventt0 = register_module(
'EventT0Generator')
170 path.add_module(eventt0)
173 if 'FullSim' not in path:
174 g4sim = register_module(
'FullSim')
175 path.add_module(g4sim)
177 check_simulation(path)
184 if components
is None or 'SVD' in components:
185 add_svd_simulation(path)
188 if components
is None or 'CDC' in components:
189 cdc_digitizer = register_module(
'CDCDigitizer')
190 cdc_digitizer.param(
"Output2ndHit", generate_2nd_cdc_hits)
191 path.add_module(cdc_digitizer)
195 if components
is None or 'PXD' in components:
196 if forceSetPXDDataReduction:
197 if usePXDDataReduction:
198 pxd_digits_name =
'pxd_unfiltered_digits'
199 add_pxd_simulation(path, digitsName=pxd_digits_name)
202 path_disableROI_Sim = create_path()
203 path_enableROI_Sim = create_path()
205 add_pxd_simulation(path_disableROI_Sim, digitsName=
'PXDDigits')
206 add_pxd_simulation(path_enableROI_Sim, digitsName=
'pxd_unfiltered_digits')
208 roi_condition_module_Sim = path.add_module(
"ROIfindingConditionFromDB")
209 roi_condition_module_Sim.if_true(path_enableROI_Sim, AfterConditionPath.CONTINUE)
210 roi_condition_module_Sim.if_false(path_disableROI_Sim, AfterConditionPath.CONTINUE)
213 if components
is None or 'TOP' in components:
214 top_digitizer = register_module(
'TOPDigitizer')
215 path.add_module(top_digitizer)
218 if components
is None or 'ARICH' in components:
219 arich_digitizer = register_module(
'ARICHDigitizer')
220 path.add_module(arich_digitizer)
223 if components
is None or 'ECL' in components:
224 ecl_digitizer = register_module(
'ECLDigitizer')
225 if bkgfiles
is not None:
226 ecl_digitizer.param(
'Background', 1)
227 path.add_module(ecl_digitizer)
230 if components
is None or 'KLM' in components:
231 klm_digitizer = register_module(
'KLMDigitizer')
232 path.add_module(klm_digitizer)
235 if bkgfiles
is not None and bkgOverlay:
236 if forceSetPXDDataReduction:
237 path.add_module(
'BGOverlayExecutor', PXDDigitsName=pxd_digits_name)
239 if components
is None or 'PXD' in components:
240 path.add_module(
"PXDDigitSorter", digits=pxd_digits_name)
243 if components
is None or 'SVD' in components:
244 path.add_module(
"SVDShaperDigitSorter")
246 path_disableROI_Bkg = create_path()
247 path_enableROI_Bkg = create_path()
249 path_disableROI_Bkg.add_module(
'BGOverlayExecutor', PXDDigitsName=
'PXDDigits')
250 if components
is None or 'PXD' in components:
251 path_disableROI_Bkg.add_module(
"PXDDigitSorter", digits=
'PXDDigits')
252 if components
is None or 'SVD' in components:
253 path_disableROI_Bkg.add_module(
"SVDShaperDigitSorter")
255 path_enableROI_Bkg.add_module(
'BGOverlayExecutor', PXDDigitsName=
'pxd_unfiltered_digits')
256 if components
is None or 'PXD' in components:
257 path_enableROI_Bkg.add_module(
"PXDDigitSorter", digits=
'pxd_unfiltered_digits')
258 if components
is None or 'SVD' in components:
259 path_enableROI_Bkg.add_module(
"SVDShaperDigitSorter")
261 roi_condition_module_Bkg = path.add_module(
"ROIfindingConditionFromDB")
262 roi_condition_module_Bkg.if_true(path_enableROI_Bkg, AfterConditionPath.CONTINUE)
263 roi_condition_module_Bkg.if_false(path_disableROI_Bkg, AfterConditionPath.CONTINUE)
266 if components
is None or 'PXD' in components:
267 if forceSetPXDDataReduction:
268 if usePXDDataReduction:
269 add_PXDDataReduction(path, components, pxd_digits_name, doCleanup=cleanupPXDDataReduction,
270 overrideDB=forceSetPXDDataReduction, usePXDDataReduction=usePXDDataReduction)
272 path_enableROI_Red = create_path()
273 add_PXDDataReduction(
276 pxd_unfiltered_digits=
'pxd_unfiltered_digits',
277 doCleanup=cleanupPXDDataReduction)
279 roi_condition_module_Red = path.add_module(
"ROIfindingConditionFromDB")
280 roi_condition_module_Red.if_true(path_enableROI_Red, AfterConditionPath.CONTINUE)
283 path.add_module(
'StatisticsSummary').set_name(
'Sum_Simulation')