Belle II Software light-2406-ragdoll
NumBestChecker Class Reference
Inheritance diagram for NumBestChecker:
Collaboration diagram for NumBestChecker:

Public Member Functions

def __init__ (self)
 
def param (self, kwargs)
 
def initialize (self)
 
def event (self)
 

Public Attributes

 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
 

Detailed Description

Check if 'numBest' works correctly

Definition at line 106 of file best_candidate_selection.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self)
Initializing the parameters.

Definition at line 109 of file best_candidate_selection.py.

109 def __init__(self):
110 """Initializing the parameters."""
111 super().__init__()
112
113 self.num_best = None
114
115 self.allow_multirank = False
116

Member Function Documentation

◆ event()

def event (   self)
Check if 'e-:numBest' and 'e-:numBestMultiRank' have the expected size

Definition at line 132 of file best_candidate_selection.py.

132 def event(self):
133 """Check if 'e-:numBest' and 'e-:numBestMultiRank' have the expected size"""
134
135 size = self.plist.getListSize()
136 if self.allow_multirank:
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),
140 1)}
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}!"
145
146 else:
147 # The test fails if size > numBest_value as this is passed as a parameter into the module
148 assert size <= self.num_best, f"numBest test failed: there are too many Particles ({size}) in the list!"
149
150
151# fixed random numbers

◆ initialize()

def initialize (   self)
Create particle list 'e-:numBest(MultiRank)' object, depending on parameter choice.

Definition at line 123 of file best_candidate_selection.py.

123 def initialize(self):
124 """Create particle list 'e-:numBest(MultiRank)' object, depending on parameter choice."""
125 if self.allow_multirank:
126
127 self.plist = Belle2.PyStoreObj('e-:numBestMultiRank')
128 else:
129
130 self.plist = Belle2.PyStoreObj('e-:numBest')
131
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67

◆ param()

def param (   self,
  kwargs 
)
Checking for module parameters to distinguish between the different test cases.

Definition at line 117 of file best_candidate_selection.py.

117 def param(self, kwargs):
118 """Checking for module parameters to distinguish between the different test cases."""
119 self.num_best = kwargs.pop('numBest')
120 self.allow_multirank = kwargs.pop('allowMultiRank', False)
121 super().param(kwargs)
122

Member Data Documentation

◆ allow_multirank

allow_multirank

MultiRank option switch.

Definition at line 115 of file best_candidate_selection.py.

◆ num_best

num_best

Number of candidates to keep (must be given as parameter, otherwise assert will fail).

Definition at line 113 of file best_candidate_selection.py.

◆ plist

plist

particle list object

Definition at line 127 of file best_candidate_selection.py.


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