Belle II Software  release-05-02-19
RetentionCheck Class Reference
Inheritance diagram for RetentionCheck:
Collaboration diagram for RetentionCheck:

Public Member Functions

def __init__ (self, module_name='', module_number=0, particle_lists=[])
 
def event (self)
 
def terminate (self)
 
def print_results (cls)
 
def plot_retention (cls, particle_list, plot_title="", save_as=None, module_name_max_length=80)
 

Public Attributes

 module_name
 
 module_number
 
 candidate_count
 
 event_with_candidate_count
 
 particle_lists
 

Static Public Attributes

dictionary summary = {}
 
 output_override = None
 

Private Attributes

 _key
 

Detailed Description

Check the retention rate and the number of candidates for a given set of particle lists.

The module stores its results in the static variable "summary".

To monitor the effect of every module of an initial path, this module should be added after
each module of the path. A function was written (`skimExpertFunctions.pathWithRetentionCheck`) to do it:

>>> path = pathWithRetentionCheck(particle_lists, path)

After the path processing, the result of the RetentionCheck can be printed with

>>> RetentionCheck.print_results()

or plotted with (check the corresponding documentation)

>>> RetentionCheck.plot_retention(...)

and the summary dictionary can be accessed through

>>> RetentionCheck.summary

Authors:

    Cyrille Praz, Slavomira Stefkova

Parameters:

    module_name (str): name of the module after which the retention rate is measured
    module_number (int): index of the module after which the retention rate is measured
    particle_lists (list(str)): list of particle list names which will be tracked by the module

Definition at line 18 of file skimRetentionCheck.py.

Member Function Documentation

◆ plot_retention()

def plot_retention (   cls,
  particle_list,
  plot_title = "",
  save_as = None,
  module_name_max_length = 80 
)
Plot the result of the RetentionCheck for a given particle list.

Example of use (to be put after process(path)):

>>> RetentionCheck.plot_retention('B+:semileptonic','skim:feiSLBplus','retention_plots/plot.pdf')

Parameters:

    particle_list (str): particle list name
    title (str): plot title (overwritten by the -o argument in basf2)
    save_as (str): output filename (overwritten by the -o argument in basf2)
    module_name_max_length (int): if the module name length is higher than this value, do not display the full name

Definition at line 149 of file skimRetentionCheck.py.

149  def plot_retention(cls, particle_list, plot_title="", save_as=None, module_name_max_length=80):
150  """ Plot the result of the RetentionCheck for a given particle list.
151 
152  Example of use (to be put after process(path)):
153 
154  >>> RetentionCheck.plot_retention('B+:semileptonic','skim:feiSLBplus','retention_plots/plot.pdf')
155 
156  Parameters:
157 
158  particle_list (str): particle list name
159  title (str): plot title (overwritten by the -o argument in basf2)
160  save_as (str): output filename (overwritten by the -o argument in basf2)
161  module_name_max_length (int): if the module name length is higher than this value, do not display the full name
162  """
163  module_name = []
164  retention = []
165 
166  at_least_one_entry = False
167  for module, results in cls.summary.items():
168 
169  if particle_list not in results.keys():
170  b2.B2WARNING(particle_list + " is not present in the results of the RetentionCheck for the module {}."
171  .format(module))
172  return
173 
174  if results[particle_list]['retention_rate'] > 0 or at_least_one_entry:
175  at_least_one_entry = True
176  if len(module) > module_name_max_length and module_name_max_length > 3: # module name tool long
177  module = module[:module_name_max_length - 3] + "..."
178  module_name.append(module)
179  retention.append(100 * (results[particle_list]['retention_rate']))
180 
181  if not at_least_one_entry:
182  b2.B2WARNING(particle_list + " seems to have a zero retention rate when created (if created).")
183  return
184 
185  plt.figure()
186  bars = plt.barh(module_name, retention, label=particle_list, color=(0.67, 0.15, 0.31, 0.6))
187 
188  for bar in bars:
189  yval = bar.get_width()
190  plt.text(0.5, bar.get_y() + bar.get_height() / 2.0 + 0.1, str(round(yval, 3)))
191 
192  plt.gca().invert_yaxis()
193  plt.xticks(rotation=45)
194  plt.xlim(0, 100)
195  plt.axvline(x=10.0, linewidth=1, linestyle="--", color='k', alpha=0.5)
196  plt.xlabel('Retention Rate [%]')
197  plt.legend(loc='lower right')
198 
199  if save_as or cls.output_override:
200  if cls.output_override:
201  plot_title = (cls.output_override).split(".")[0]
202  save_as = plot_title + '.pdf'
203  if '/' in save_as:
204  os.makedirs(os.path.dirname(save_as), exist_ok=True)
205  plt.title(plot_title)
206  plt.savefig(save_as, bbox_inches="tight")
207  b2.B2RESULT("Retention rate results for list {} saved in {}."
208  .format(particle_list, os.getcwd() + "/" + save_as))
209 
210 

◆ print_results()

def print_results (   cls)
Print the results, should be called after the path processing.

Definition at line 107 of file skimRetentionCheck.py.


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