Belle II Software  release-06-02-00
particleloader.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """
13 A test of the ParticleLoader using a relatively large test file
14 (mdst14.root in the validation data)
15 """
16 
17 import basf2
18 import b2test_utils
19 
20 # make logging more reproducible by replacing some strings
22 basf2.set_random_seed("1337")
23 
24 fsps = ['e+', 'pi+', 'K+', 'p+', 'mu+', 'K_S0 -> pi+ pi-', 'Lambda0 -> p+ pi-', 'K_L0', 'gamma', 'n0']
25 
26 
28 testpath = basf2.create_path()
29 inputFile = b2test_utils.require_file('mdst14.root', 'validation')
30 testpath.add_module('RootInput', inputFileName=inputFile)
31 for fsp in fsps:
32  testpath.add_module('ParticleLoader', decayStrings=[fsp])
33 testpath.add_module('ParticleListManipulator', outputListName='gamma',
34  inputListNames=['gamma:all'], cut='isFromECL')
35 
36 # manipulate the string to remove the daughters in case of v0
37 for i in range(len(fsps)):
38  if " -> " in fsps[i]:
39  fsps[i] = fsps[i].split(' ->', 1)[0]
40 
41 # also load MC particles
42 mcps = [particle + ':MC' for particle in fsps + ['B0', 'D0']]
43 testpath.add_module('ParticleLoader', decayStrings=mcps, useMCParticles=True)
44 
45 # load photons from KLMCluster
46 testpath.add_module('ParticleListManipulator', outputListName='gamma:fromKLM',
47  inputListNames=['gamma:all'], cut='isFromKLM')
48 
49 # add RestOfEvents
50 signal_side = 'K_S0:V0'
51 roe_side = 'Upsilon(4S):ROE'
52 testpath.add_module('RestOfEventBuilder', particleList=signal_side,
53  particleListsInput=['pi+:all', 'gamma', 'K_L0:all'])
54 # Load RestOfEvents
55 testpath.add_module('ParticleLoader', decayStrings=[roe_side],
56  sourceParticleListName=signal_side, useROEs=True)
57 
58 for i in range(len(fsps)):
59  if 'K_S0' in fsps[i] or 'Lambda0' in fsps[i]:
60  fsps[i] = fsps[i] + ':V0'
61  elif "gamma" not in fsps[i]:
62  fsps[i] = fsps[i] + ':all'
63 
64 testpath.add_module('ParticleStats', particleLists=fsps)
65 testpath.add_module('ParticleStats', particleLists=mcps)
66 testpath.add_module('ParticleStats', particleLists=['gamma:fromKLM'])
67 testpath.add_module('ParticleStats', particleLists=[roe_side])
68 basf2.process(testpath)
69 
70 # process the first event (again) with the verbose ParticlePrinter
71 for fsp in fsps:
72  testpath.add_module('ParticlePrinter', listName=fsp, fullPrint=True)
73 testpath.add_module('ParticlePrinter', listName='gamma:fromKLM', fullPrint=True)
74 basf2.process(testpath, 1)
def configure_logging_for_tests(user_replacements=None)
Definition: __init__.py:106
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:54