Belle II Software development
RankChecker Class Reference
Inheritance diagram for RankChecker:

Public Member Functions

def initialize (self)
 
def event (self)
 

Public Attributes

 plist
 particle list object
 

Detailed Description

Check if the ranks are actually what we want

Definition at line 44 of file best_candidate_selection.py.

Member Function Documentation

◆ event()

def event (   self)
And check all the ranks

Definition at line 52 of file best_candidate_selection.py.

52 def event(self):
53 """And check all the ranks"""
54 # make a list of all the values and a dict of all the extra infos
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 # get all names of existing extra infos but convert to a native list of python strings to avoid
62 # possible crashes if the std::vector returned by the particle goes out of scope
63 names = [str(n) for n in particle.getExtraInfoNames()]
64 for n in names:
65 einfo[n].append(particle.getExtraInfo(n))
66
67 # check the default name is set correctly if we don't specify an output variable
68 print(list(einfo.keys()))
69 assert 'M_rank' in einfo.keys(), "Default name is not as expected"
70
71 # Now determine the correct ranks if multiple values are allowed:
72 # create a dictionary which will be value -> rank for all unique values
73 # in theory we just need loop over the sorted(set(values)) but we have
74 # special treatment for nans which should go always to the end of the
75 # list so sort with a special key that replaces nan by inf or -inf
76 # depending on sort order
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 # Ok, test if the rank from extra info actually corresponds to what we
83 # want
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 # so we checked multiRank=True. But for multiRank=False this is more
93 # complicated because ranking a second time will destroy the order
94 # of the previous sorts. But we can at least check if all the ranks
95 # form a range from 1..n if we sort them
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 # but the second two rankings are on the same variable in the same
100 # order so they need to keep the order stable. so for py_low_single the
101 # ranks need to be the range without sorting
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

◆ initialize()

def initialize (   self)
Create particle list object

Definition at line 47 of file best_candidate_selection.py.

47 def initialize(self):
48 """Create particle list object"""
49
50 self.plist = Belle2.PyStoreObj("e-")
51
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67

Member Data Documentation

◆ plist

plist

particle list object

Definition at line 50 of file best_candidate_selection.py.


The documentation for this class was generated from the following file: