11from collections
import defaultdict
12import modularAnalysis
as ma
13from ROOT
import Belle2
17 """Generate a list of 10 electrons which have stupid momenta just to sort
18 them later. And then add one electron where all momentum components are
22 """We need to register the mc particles"""
25 self.
mcp.registerInDataStore()
28 """And then we generate particles, ensuring some overlap in the momenta."""
31 px, py, pz = random.randrange(1, 5), random.randrange(1, 5), random.randrange(1, 5)
33 p = self.
mcp.appendNew()
36 p.setMomentum(px, py, pz)
38 p = self.
mcp.appendNew()
41 p.setMomentum(math.nan, math.nan, math.nan)
45 """Check if the ranks are actually what we want"""
48 """Create particle list object"""
53 """And check all the ranks"""
57 einfo = defaultdict(list)
58 for particle
in self.
plist:
59 px.append(particle.getPx())
60 py.append(particle.getPy())
63 names = [str(n)
for n
in particle.getExtraInfoNames()]
65 einfo[n].append(particle.getExtraInfo(n))
68 print(list(einfo.keys()))
69 assert 'M_rank' in einfo.keys(),
"Default name is not as expected"
77 px_value_ranks = {v: i
for i, v
in enumerate(sorted(set(px), reverse=
True,
78 key=
lambda v: -math.inf
if math.isnan(v)
else v), 1)}
79 py_value_ranks = {v: i
for i, v
in enumerate(sorted(set(py),
80 key=
lambda v: math.inf
if math.isnan(v)
else v), 1)}
84 for v, r
in zip(px, einfo[
"px_high_multi"]):
85 print(f
"Value: {v}, rank: {r}, should be: {px_value_ranks[v]}")
86 assert r == px_value_ranks[v],
"Rank is not correct"
88 for v, r
in zip(py, einfo[
"py_low_multi"]):
89 print(f
"Value: {v}, rank: {r}, should be: {py_value_ranks[v]}")
90 assert r == py_value_ranks[v],
"Rank is not correct"
96 simple_range = list(range(len(px)))
97 px_single_ranks = list(sorted(int(r) - 1
for r
in einfo[
"px_high_single"]))
98 assert simple_range == px_single_ranks,
"sorted ranks don't form a range from 1..n"
102 py_single_ranks = list(int(r) - 1
for r
in einfo[
"py_low_single"])
103 assert simple_range == py_single_ranks,
"ranks don't form a range from 1..n"
107 """Check if 'numBest' works correctly"""
110 """Initializing the parameters."""
118 """Checking for module parameters to distinguish between the different test cases."""
119 self.
num_best = kwargs.pop(
'numBest')
121 super().
param(kwargs)
124 """Create particle list 'e-:numBest(MultiRank)' object, depending on parameter choice."""
133 """Check if 'e-:numBest' and 'e-:numBestMultiRank' have the expected size"""
135 size = self.
plist.getListSize()
137 px = [particle.getPx()
for particle
in self.
plist]
138 px_value_ranks = {v: i
for i, v
in enumerate(sorted(set(px), reverse=
True,
139 key=
lambda v: -math.inf
if math.isnan(v)
else v),
141 remaining_particles = [v
for v
in px
if px_value_ranks[v] <= self.
num_best]
142 assert size <= len(remaining_particles),
"numBest test with multirank failed: " \
143 f
"there should be {len(remaining_particles)} Particles in the list " \
144 f
"instead of {size}!"
148 assert size <= self.
num_best, f
"numBest test failed: there are too many Particles ({size}) in the list!"
155path.add_module(
"EventInfoSetter", evtNumList=10)
159ma.fillParticleListFromMC(
"e-",
"", path=path)
161ma.rankByHighest(
"e-",
"M", path=path)
162ma.rankByHighest(
"e-",
"px", allowMultiRank=
False, outputVariable=
"px_high_single", path=path)
163ma.rankByHighest(
"e-",
"px", allowMultiRank=
True, outputVariable=
"px_high_multi", path=path)
164ma.rankByLowest(
"e-",
"py", allowMultiRank=
False, outputVariable=
"py_low_single", path=path)
165ma.rankByLowest(
"e-",
"py", allowMultiRank=
True, outputVariable=
"py_low_multi", path=path)
173ma.fillParticleListFromMC(
"e-:numBest",
"", path=path)
175ma.rankByHighest(
"e-:numBest",
"p", numBest=numBest_value, path=path)
180ma.fillParticleListFromMC(
"e-:numBestMultiRank",
"", path=path)
182ma.rankByHighest(
"e-:numBestMultiRank",
"px", numBest=numBest_value, allowMultiRank=
True, path=path)
184path.add_module(
NumBestChecker(), numBest=numBest_value, allowMultiRank=
True)
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
plist
particle list object
num_best
Number of candidates to keep (must be given as parameter, otherwise assert will fail).
allow_multirank
MultiRank option switch.
plist
particle list object