4 import modularAnalysis
as ma
5 from ROOT
import Belle2
11 class Generator(basf2.Module):
12 """Generate list of 10 electrons which have random momenta and one
13 electron where all momentum components are nan"""
16 """We need to register the mc particles"""
19 self.mcp.registerInDataStore()
22 """And then we generate particles"""
24 p = self.mcp.appendNew()
27 p.setMomentum(random.randrange(0, 5), random.randrange(0, 5), random.randrange(0, 5))
29 p = self.mcp.appendNew()
32 p.setMomentum(math.nan, math.nan, math.nan)
35 class MergingChecker(basf2.Module):
36 """Check if merging works correctly"""
39 """Create particle list objects"""
49 """Check if the particle lists have the expected size"""
50 allsize = self.all.getListSize()
51 below2size = self.below2.getListSize()
52 above3size = self.above3.getListSize()
53 onlyallsize = self.onlyall.getListSize()
54 goodmergesize = self.goodmerge.getListSize()
55 bestsize = self.best.getListSize()
57 assert onlyallsize == allsize
58 assert goodmergesize == below2size + above3size
59 assert bestsize == below2size + above3size
63 path.add_module(
"EventInfoSetter", evtNumList=10)
64 path.add_module(Generator())
66 ma.fillParticleListFromMC(
"e-:all",
"", path=path)
67 ma.variablesToExtraInfo(
'e-:all', {
'formula(0)':
'identifier',
'random':
'quality'}, path=path)
69 ma.fillParticleListFromMC(
"e-:below2",
"px < 2", path=path)
70 ma.variablesToExtraInfo(
'e-:below2', {
'formula(2)':
'identifier',
'formula(1 + random)':
'quality'}, path=path)
72 ma.fillParticleListFromMC(
"e-:above3",
"px > 3", path=path)
73 ma.variablesToExtraInfo(
'e-:above3', {
'formula(3)':
'identifier',
'formula(2 + random)':
'quality'}, path=path)
80 ma.copyLists(
'e-:onlyall', [
'e-:all',
'e-:below2',
'e-:above3'], path=path)
82 ma.printVariableValues(
'e-:onlyall', [
'extraInfo(identifier)'], path=path)
83 ma.applyCuts(
'e-:onlyall',
'extraInfo(identifier) == 0', path=path)
86 ma.copyLists(
'e-:goodmerge', [
'e-:below2',
'e-:above3',
'e-:all'], path=path)
91 ma.printVariableValues(
'e-:goodmerge', [
'extraInfo(identifier)'], path=path)
92 ma.applyCuts(
'e-:goodmerge',
'extraInfo(identifier) > 0', path=path)
95 path.add_module(
'ParticleListManipulator', outputListName=
'e-:best', inputListNames=[
'e-:all',
'e-:below2',
'e-:above3'],
96 variable=
'extraInfo(quality)', preferLowest=
False)
98 ma.printVariableValues(
'e-:best', [
'extraInfo(identifier)'], path=path)
99 ma.applyCuts(
'e-:best',
'extraInfo(identifier) > 0', path=path)
101 path.add_module(MergingChecker())