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