Belle II Software development
setup_modules.py
1#!/usr/bin/env python3
2
3
10
11
12
18
19
20import basf2 as b2
21from ROOT import Belle2
22
23import os
24
25# sets up the geometry. The file for the default geometry for Belle2 is geometry/Belle2.xml
26
27
28def setup_Geometry(path=None):
29 """
30 Sets the geometry. Should be used in all VXDTF2 related scripts to ensure to use the same geometry in all
31 trainings / validation steps!
32 param path: the path to append the geometry
33
34 """
35
36 b2.B2WARNING("This function is deprecated and should not be used anymore! The geometry should now be loaded from the DB")
37
38
39def setup_VXDTF2(path=None,
40 use_pxd=False,
41 use_svd=True,
42 filter_overlapping=True,
43 use_segment_network_filters=True,
44 observerType=0,
45 quality_estimator='circleFit',
46 overlap_filter='greedy',
47 sec_map_file=None,
48 setup_name='SVDOnlyDefault',
49 log_level=b2.LogLevel.INFO,
50 debug_level=1):
51 """
52 Convenience Method to setup the redesigned vxd track finding module chain.
53 Reuslt is a store array containing reco tracks called 'RecoTracks'.
54 :param path: basf2.Path
55 :param sec_map_file: training data for segment network.
56 :param setup_name: name of the setup within all the sectormaps in the sec_map_file which should be used,
57 :param use_pxd: if true use pxd hits. Default False.
58 :param use_svd: if true use svd hits. Default True.
59 :param quality_estimator: which fit to use to determine track quality. Options 'circle', 'random'. Default 'circle'.
60 :param filter_overlapping: if true overlapping tracks are reduced to a single track using the qualitiy indicator.
61 :param use_segment_network_filters: if true use filters for segmentMap training. Default True.
62 :param observe_network_filters: FOR DEBUG ONLY! If true results for FilterVariables are stored to a root file. Default False.
63 :param overlap_filter: which filter network to use. Options 'hopfield', 'greedy'. Default 'hopfield'.
64 :param log_level: LogLevel of all modules in the chain
65 :param debug_level: debug level of all modules in the chain.
66 :return:
67 """
68
69 # List containing all modules either to be added to the path or to be returned.
70 modules = []
71
72
76 if use_pxd:
77 spCreatorPXD = b2.register_module('PXDSpacePointCreator')
78 spCreatorPXD.logging.log_level = log_level
79 spCreatorPXD.logging.debug_level = debug_level
80 spCreatorPXD.param('NameOfInstance', 'PXDSpacePoints')
81 spCreatorPXD.param('SpacePoints', 'SpacePoints')
82 modules.append(spCreatorPXD)
83
84 if use_svd:
85 spCreatorSVD = b2.register_module('SVDSpacePointCreator')
86 spCreatorSVD.logging.log_level = log_level
87 spCreatorSVD.logging.debug_level = debug_level
88 spCreatorSVD.param('OnlySingleClusterSpacePoints', False)
89 spCreatorSVD.param('NameOfInstance', 'SVDSpacePoints')
90 spCreatorSVD.param('SpacePoints', 'SpacePoints')
91 modules.append(spCreatorSVD)
92
93 # SecMap Bootstrap
94 secMapBootStrap = b2.register_module('SectorMapBootstrap')
95 secMapBootStrap.param('ReadSectorMap', True)
96 if sec_map_file:
97 secMapBootStrap.param('SectorMapsInputFile', sec_map_file)
98 secMapBootStrap.param('WriteSectorMap', False)
99 secMapBootStrap.param('SetupToRead', "")
100 modules.append(secMapBootStrap)
101
102 # Register EventLevelTrackingInfo
103 regEventLevelTrackingInfo = b2.register_module('RegisterEventLevelTrackingInfo')
104 modules.append(regEventLevelTrackingInfo)
105
106
110
111 segNetProducer = b2.register_module('SegmentNetworkProducer')
112 # segNetProducer.param('CreateNeworks', 3)
113 segNetProducer.param('NetworkOutputName', 'test2Hits')
114 segNetProducer.param('allFiltersOff', not use_segment_network_filters)
115 segNetProducer.param('SpacePointsArrayNames', ['SpacePoints'])
116 segNetProducer.param('printNetworks', False)
117 segNetProducer.param('sectorMapName', setup_name)
118 segNetProducer.param('addVirtualIP', False)
119 # segNetProducer.param('observerType', observerType)
120 segNetProducer.logging.log_level = log_level
121 segNetProducer.logging.debug_level = debug_level
122 modules.append(segNetProducer)
123
124
128
129 cellOmat = b2.register_module('TrackFinderVXDCellOMat')
130 cellOmat.param('NetworkName', 'test2Hits')
131 cellOmat.param('SpacePointTrackCandArrayName', 'SPTCs')
132 cellOmat.param('printNetworks', False)
133 cellOmat.param('strictSeeding', True)
134 cellOmat.logging.log_level = log_level
135 cellOmat.logging.debug_level = debug_level
136 modules.append(cellOmat)
137
138
142
143 # Quality
144
145 qualityEstimator = b2.register_module('QualityEstimatorVXD')
146 qualityEstimator.param('EstimationMethod', quality_estimator)
147 qualityEstimator.param('SpacePointTrackCandsStoreArrayName', 'SPTCs')
148 qualityEstimator.logging.log_level = log_level
149 qualityEstimator.logging.debug_level = debug_level
150 modules.append(qualityEstimator)
151
152 maxCandidateSelection = b2.register_module('BestVXDTrackCandidatesSelector')
153 maxCandidateSelection.param('NameSpacePointTrackCands', 'SPTCs')
154 maxCandidateSelection.param('SubsetCreation', True)
155 maxCandidateSelection.param('NewNameSpacePointTrackCands', '')
156 maxCandidateSelection.logging.log_level = log_level
157 maxCandidateSelection.logging.debug_level = debug_level
158 modules.append(maxCandidateSelection)
159
160 # Properties
161 vIPRemover = b2.register_module('SPTCvirtualIPRemover')
162 vIPRemover.param('tcArrayName', '')
163 vIPRemover.param('maxTCLengthForVIPKeeping', 0) # want to remove virtualIP for any track length
164 vIPRemover.logging.log_level = log_level
165 vIPRemover.logging.debug_level = debug_level
166 modules.append(vIPRemover)
167
168
172
173 if filter_overlapping:
174 overlapResolver = b2.register_module('SVDOverlapResolver')
175 overlapResolver.logging.log_level = log_level
176 overlapResolver.logging.debug_level = debug_level
177 overlapResolver.param('NameSpacePointTrackCands', '')
178 overlapResolver.param('ResolveMethod', overlap_filter.lower())
179 overlapResolver.param('NameSVDClusters', '')
180 modules.append(overlapResolver)
181
182
186 momSeedRetriever = b2.register_module('SPTCmomentumSeedRetriever')
187 momSeedRetriever.param('tcArrayName', '')
188 momSeedRetriever.logging.log_level = log_level
189 momSeedRetriever.logging.debug_level = debug_level
190 modules.append(momSeedRetriever)
191
192 converter = b2.register_module('SPTC2RTConverter')
193 converter.param('spacePointsTCsStoreArrayName', '')
194 converter.logging.log_level = log_level
195 converter.logging.debug_level = debug_level
196 modules.append(converter)
197
198 if path:
199 for module in modules:
200 path.add_module(module)
201 else:
202 return modules
203
204
205def setup_RTCtoSPTCConverters(
206 path=0,
207 SVDSPscollection='SVDSpacePoints',
208 PXDSPscollection='PXDSpacePoints',
209 RTCinput='mcTracks',
210 sptcOutput='checkedSPTCs',
211 usePXD=True,
212 logLevel=b2.LogLevel.INFO,
213 debugVal=1,
214 useNoKick=False,
215 useOnlyFittedTracks=False):
216 """This function adds the modules needed to convert Reco-TCs to SpacePointTCs to given path.
217
218 @param path if set to 0 (standard) the created modules will not be added, but returned.
219 If a path is given, 'None' is returned but will be added to given path instead.
220
221 @param SPscollection the name of the storeArray containing SPs of both SVD and PXD.
222
223 @param RTCinput defines the name of input-Reco-TCs.
224
225 @param sptcOutput defines the name of output-SPTCs.
226
227 @param usePXD If False pxdClusters are ignored.
228
229 @param logLevel set to logLevel level of your choice.
230
231 @param debugVal set to debugLevel of choice - will be ignored if logLevel is not set to LogLevel.DEBUG
232
233 @param useNoKick enable the training sample selection based on track parameters (and produce a TFile of its effect)
234
235 @param useOnlyFittedTracks: if True only fitted RecoTracks will be transformed to SpacePointTrackCands
236 """
237 print("setup RTCtoSPTCConverters...")
238
239 spacePointNames = []
240 detectorTypes = []
241 trueHitNames = []
242 clusterNames = []
243 if usePXD:
244 detectorTypes.append('PXD')
245 # PXD SpacePoints and SVD SpacePoints are assumed to be in the same StoreArray
246 spacePointNames.append(PXDSPscollection)
247 trueHitNames.append('')
248 clusterNames.append('')
249 # PXD SpacePoints and SVD SpacePoints are assumed to be in the same StoreArray
250 spacePointNames.append(SVDSPscollection)
251 detectorTypes.append('SVD')
252 trueHitNames.append('')
253 clusterNames.append('')
254
255 # module to create relations between SpacePoints and TrueHits -> some of
256 # the following modules will be utilizing these relations!
257 sp2thConnector = b2.register_module('SpacePoint2TrueHitConnector')
258 sp2thConnector.logging.log_level = logLevel
259 sp2thConnector.param('DetectorTypes', detectorTypes)
260 sp2thConnector.param('TrueHitNames', trueHitNames)
261 sp2thConnector.param('ClusterNames', clusterNames)
262 sp2thConnector.param('SpacePointNames', spacePointNames)
263 sp2thConnector.param('outputSuffix', '_relTH')
264 sp2thConnector.param('storeSeperate', False)
265 sp2thConnector.param('registerAll', False)
266 sp2thConnector.param('maxGlobalPosDiff', 0.05)
267 sp2thConnector.param('maxPosSigma', 5)
268 sp2thConnector.param('minWeight', 0)
269 sp2thConnector.param('requirePrimary', True)
270 sp2thConnector.param('positionAnalysis', False)
271
272 # TCConverter, RecoTrack -> SPTC
273 recoTrackCandConverter = b2.register_module('RT2SPTCConverter')
274 recoTrackCandConverter.logging.log_level = logLevel
275 recoTrackCandConverter.param('RecoTracksName', RTCinput)
276 recoTrackCandConverter.param('SpacePointTCName', 'SPTracks')
277 recoTrackCandConverter.param('SVDSpacePointStoreArrayName', SVDSPscollection)
278 recoTrackCandConverter.param('PXDSpacePointStoreArrayName', None)
279 if usePXD:
280 recoTrackCandConverter.param('PXDSpacePointStoreArrayName', PXDSPscollection)
281 recoTrackCandConverter.param('useTrueHits', True)
282 recoTrackCandConverter.param('ignorePXDHits', not usePXD) # if True PXD hits will be ignored
283 recoTrackCandConverter.param('useSingleClusterSP', False)
284 recoTrackCandConverter.param('minSP', 3)
285 recoTrackCandConverter.param('skipProblematicCluster', False)
286 recoTrackCandConverter.param('convertFittedOnly', useOnlyFittedTracks)
287
288 if os.environ.get('USE_BEAST2_GEOMETRY'):
289 NoKickCuts = Belle2.FileSystem.findFile("data/tracking/NoKickCutsPhase2.root")
290 else:
291 NoKickCuts = Belle2.FileSystem.findFile("data/tracking/NoKickCuts.root")
292
293 if useNoKick:
294 recoTrackCandConverter.param('noKickCutsFile', NoKickCuts) # NoKickCuts applied
295 recoTrackCandConverter.param('noKickOutput', True) # produce output TFile of NoKickCuts
296 else:
297 recoTrackCandConverter.param('noKickCutsFile', "") # NoKickCuts not applied
298
299 # SpacePointTrackCand referee
300 sptcReferee = b2.register_module('SPTCReferee')
301 sptcReferee.logging.log_level = logLevel
302 sptcReferee.param('sptcName', 'SPTracks')
303 sptcReferee.param('newArrayName', sptcOutput)
304 sptcReferee.param('storeNewArray', True)
305 sptcReferee.param('checkCurling', True)
306 sptcReferee.param('splitCurlers', True)
307 sptcReferee.param('keepOnlyFirstPart', True)
308 sptcReferee.param('kickSpacePoint', True)
309 sptcReferee.param('checkSameSensor', True)
310 sptcReferee.param('useMCInfo', True)
311 # sptcReferee.logging.log_level = LogLevel.DEBUG
312
313 if path == 0:
314 return [sp2thConnector, recoTrackCandConverter, sptcReferee]
315 else:
316 path.add_module(sp2thConnector)
317 path.add_module(recoTrackCandConverter)
318 path.add_module(sptcReferee)
319 return None
320
321
322def setup_sim(path=0, useEDeposit=True, useMultipleScattering=True, allowDecay=True, verbose=False):
323 """This function adds the g4simulation to given path.
324
325 @param path if set to 0 (standard) g4sim will not be added, but returned.
326 If a path is given, 'None' is returned but will be added to given path instead.
327
328 @param useEDeposit if False, particles will not have eDeposit. WARMING: if you still want to get hits for that case:
329 useEDeposit: If you want to work w/o E-deposit, edit pxd/data/PXD.xml and svd/data/SVD.xml,
330 where you have to activate see neutrons = true.
331
332 @param useMultipleScattering if False, multiple scattering in matter is deactivated.
333
334 @param allowDecay if False, particles can not decay.
335
336 @param verbose if True, some extra debug output is given.
337 """
338 print("setup FullSim...")
339 g4sim = b2.register_module('FullSim')
340 g4sim.param('StoreAllSecondaries', True)
341 uiCommandList = []
342 if verbose:
343 uiCommandList.append('/process/list') # prints list of processes available
344 if allowDecay:
345 uiCommandList.append('/process/inactivate Decay all')
346 if not useEDeposit:
347 uiCommandList.append('/process/inactivate StepLimiter all')
348 uiCommandList.append('/process/inactivate muIoni all')
349 uiCommandList.append('/process/inactivate hIoni all')
350 uiCommandList.append('/process/inactivate ionIoni all')
351 uiCommandList.append('/process/inactivate eIoni all')
352 uiCommandList.append('/process/inactivate eBrem all')
353 uiCommandList.append('/process/inactivate hBrems all')
354 uiCommandList.append('/process/inactivate muBrems all')
355 uiCommandList.append('/process/inactivate hPairProd all')
356 uiCommandList.append('/process/inactivate muPairProd all')
357 uiCommandList.append('/process/inactivate annihil all')
358 uiCommandList.append('/process/inactivate phot all')
359 uiCommandList.append('/process/inactivate compt all')
360 uiCommandList.append('/process/inactivate conv all')
361 # uiCommandList.append('/process/inactivate PhotonInelastic')
362 # uiCommandList.append('/process/inactivate photonInelastic')
363 uiCommandList.append('/process/inactivate electronNuclear all')
364 uiCommandList.append('/process/inactivate positronNuclear all')
365 uiCommandList.append('/process/inactivate muonNuclear all')
366 uiCommandList.append('/process/inactivate photonNuclear all')
367 uiCommandList.append('/process/inactivate Decay all')
368 uiCommandList.append('/process/inactivate hadElastic all')
369 uiCommandList.append('/process/inactivate neutronInelastic all')
370 uiCommandList.append('/process/inactivate nCapture all')
371 uiCommandList.append('/process/inactivate nFission all')
372 uiCommandList.append('/process/inactivate protonInelastic all')
373 uiCommandList.append('/process/inactivate ionInelastic all')
374 uiCommandList.append('/process/inactivate pi+Inelastic all')
375 uiCommandList.append('/process/inactivate pi-Inelastic all')
376 uiCommandList.append('/process/inactivate kaon+Inelastic all')
377 uiCommandList.append('/process/inactivate kaon-Inelastic all')
378 uiCommandList.append('/process/inactivate kaon0LInelastic all')
379 uiCommandList.append('/process/inactivate kaon0SInelastic all')
380 uiCommandList.append('/process/inactivate anti_protonInelastic all')
381 uiCommandList.append('/process/inactivate anti_neutronInelastic all')
382 uiCommandList.append('/process/inactivate lambdaInelastic all')
383 uiCommandList.append('/process/inactivate anti-lambdaInelastic all')
384 uiCommandList.append('/process/inactivate sigma-Inelastic all')
385 uiCommandList.append('/process/inactivate anti_sigma-Inelastic all')
386 uiCommandList.append('/process/inactivate sigma+Inelastic all')
387 uiCommandList.append('/process/inactivate anti_sigma+Inelastic all')
388 uiCommandList.append('/process/inactivate xi-Inelastic all')
389 uiCommandList.append('/process/inactivate anti_xi-Inelastic all')
390 uiCommandList.append('/process/inactivate xi0Inelastic all')
391 uiCommandList.append('/process/inactivate anti_xi0Inelastic all')
392 uiCommandList.append('/process/inactivate omega-Inelastic all')
393 uiCommandList.append('/process/inactivate anti_omega-Inelastic all')
394 # uiCommandList.append('/process/inactivate CHIPSNuclearCaptureAtRest')
395 uiCommandList.append('/process/inactivate hFritiofCaptureAtRest all')
396 uiCommandList.append('/process/inactivate hBertiniCaptureAtRest all')
397 uiCommandList.append('/process/inactivate muMinusCaptureAtRest all')
398 uiCommandList.append('/process/inactivate dInelastic all')
399 uiCommandList.append('/process/inactivate anti_deuteronInelastic all')
400 uiCommandList.append('/process/inactivate tInelastic all')
401 uiCommandList.append('/process/inactivate anti_tritonInelastic all')
402 uiCommandList.append('/process/inactivate He3Inelastic all')
403 uiCommandList.append('/process/inactivate anti_He3Inelastic all')
404 uiCommandList.append('/process/inactivate alphaInelastic all')
405 uiCommandList.append('/process/inactivate anti_alphaInelastic all')
406 uiCommandList.append('/process/inactivate ExtEnergyLoss all')
407 uiCommandList.append('/process/inactivate OpAbsorption all')
408 uiCommandList.append('/process/inactivate OpRayleigh all')
409 uiCommandList.append('/process/inactivate OpMieHG all')
410 uiCommandList.append('/process/inactivate OpBoundary all')
411 uiCommandList.append('/process/inactivate OpWLS all')
412 uiCommandList.append('/process/inactivate Cerenkov all')
413 uiCommandList.append('/process/inactivate Scintillation all')
414
415 if not useMultipleScattering:
416 uiCommandList.append('/process/inactivate msc all')
417 uiCommandList.append('/process/inactivate CoulombScat all')
418 # uiCommandList.append('/process/inactivate muMsc')
419 # uiCommandList.append('/process/list')
420 # if (useMultipleScattering == False or useMultipleScattering == False):
421 if verbose:
422 uiCommandList.append('/particle/select pi+')
423 uiCommandList.append('/particle/process/dump')
424 uiCommandList.append('/particle/select pi-')
425 uiCommandList.append('/particle/process/dump')
426 uiCommandList.append('/particle/select e+')
427 uiCommandList.append('/particle/process/dump')
428 uiCommandList.append('/particle/select e-')
429 uiCommandList.append('/particle/process/dump')
430 uiCommandList.append('/particle/select mu+')
431 uiCommandList.append('/particle/process/dump')
432 uiCommandList.append('/particle/select mu-')
433 uiCommandList.append('/particle/select kaon+')
434 uiCommandList.append('/particle/process/dump')
435 uiCommandList.append('/particle/select kaon-')
436 uiCommandList.append('/particle/process/dump')
437 g4sim.param('UICommandsAtIdle', uiCommandList)
438
439 # print(uiCommandList)
440 if (path == 0):
441 return g4sim
442 else:
443 path.add_module(g4sim)
444 return None
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:151