52 def event(self):
53 """And check all the ranks"""
54
55 px = []
56 py = []
57 einfo = defaultdict(list)
58 for particle in self.plist:
59 px.append(particle.getPx())
60 py.append(particle.getPy())
61
62
63 names = [str(n) for n in particle.getExtraInfoNames()]
64 for n in names:
65 einfo[n].append(particle.getExtraInfo(n))
66
67
68 print(list(einfo.keys()))
69 assert 'M_rank' in einfo.keys(), "Default name is not as expected"
70
71
72
73
74
75
76
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)}
81
82
83
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"
87
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"
91
92
93
94
95
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"
99
100
101
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"
104
105