Belle II Software  release-05-01-25
refiners.py
1 import functools
2 import numpy as np
3 import collections
4 import copy
5 
6 from tracking.validation.plot import ValidationPlot, compose_axis_label
7 from tracking.validation.fom import ValidationFiguresOfMerit
8 from tracking.validation.classification import ClassificationAnalysis
9 from tracking.validation.pull import PullAnalysis
10 from tracking.validation.tolerate_missing_key_formatter import TolerateMissingKeyFormatter
11 from tracking.root_utils import root_cd, root_save_name
12 
13 import ROOT
14 
15 import logging
16 
17 
18 def get_logger():
19  return logging.getLogger(__name__)
20 
21 
22 
23 formatter = TolerateMissingKeyFormatter()
24 
25 
26 class Refiner(object):
27  """Python module to refine a peeled dictionary"""
28 
29  def __init__(self, refiner_function=None):
30  """Constructor of the Refiner instance"""
31 
32  self.refiner_function = refiner_function
33 
34  def __get__(self, harvesting_module, cls=None):
35  """Getter of the Refiner instance"""
36  if harvesting_module is None:
37  # Class access
38  return self
39  else:
40  # Instance access
41  refine = self.refine
42 
43  def bound_call(*args, **kwds):
44  return refine(harvesting_module, *args, **kwds)
45  return bound_call
46 
47  def __call__(self, harvesting_module, crops=None, *args, **kwds):
48  """implementation of the function-call of the Refiner instance
49  r = Refiner()
50  r(harvester) # decoration
51  r(harvester, crops, args, keywords) # refinement
52  """
53  if crops is None:
54  # Decoration mode
55  harvesting_module.refiners.append(self)
56  return harvesting_module
57  else:
58  # Refining mode
59  return self.refine(harvesting_module, crops, *args, **kwds)
60 
61  def refine(self, harvesting_module, *args, **kwds):
62  """Apply the instance's refiner function"""
63  self.refiner_function(harvesting_module, *args, **kwds)
64 
65 
67  """Refiner for figures of merit"""
68 
69  default_name = "{module.id}_figures_of_merit{groupby_key}"
70 
71  default_title = "Figures of merit in {module.title}"
72 
73  default_contact = "{module.contact}"
74 
75  default_description = "Figures of merit are the {aggregation.__name__} of {keys}"
76 
77  default_check = "Check for reasonable values"
78 
79  default_key = "{aggregation.__name__}_{part_name}"
80 
81 
82  @staticmethod
83  def mean(xs):
84  return np.nanmean(xs)
85 
86 
87  default_aggregation = mean
88 
89  def __init__(self,
90  name=None,
91  title=None,
92  contact=None,
93  description=None,
94  check=None,
95  key=None,
96  aggregation=None,
97  ):
98  """Constructor for this refiner"""
99 
100  super(SaveFiguresOfMeritRefiner, self).__init__()
101 
102 
103  self.name = name
104 
105  self.title = title
106 
107 
108  self.description = description
109 
110  self.check = check
111 
112  self.contact = contact
113 
114 
115  self.key = key
116 
117  self.aggregation = aggregation
118 
119  def refine(self,
120  harvesting_module,
121  crops,
122  tdirectory=None,
123  groupby_part_name=None,
124  groupby_value=None,
125  **kwds):
126  """Process the figures of merit"""
127 
128  name = self.name or self.default_name
129  title = self.title or self.default_title
130  contact = self.contact or self.default_contact
131  description = self.description or self.default_description
132  check = self.check or self.default_check
133 
134  aggregation = self.aggregation or self.default_aggregation
135 
136  replacement_dict = dict(
137  refiner=self,
138  module=harvesting_module,
139  aggregation=aggregation,
140  groupby_key='_' + groupby_part_name + groupby_value if groupby_part_name else "",
141  groupby=groupby_part_name, # deprecated
142  groupby_value=groupby_value, # deprecated
143  )
144 
145  name = formatter.format(name, **replacement_dict)
146  title = formatter.format(title, **replacement_dict)
147  contact = formatter.format(contact, **replacement_dict)
148 
149  figures_of_merit = ValidationFiguresOfMerit(name,
150  contact=contact,
151  title=title)
152 
153  for part_name, parts in iter_items_sorted_for_key(crops):
154  key = self.key or self.default_key
155  key = formatter.format(key, part_name=part_name, **replacement_dict)
156  figures_of_merit[key] = aggregation(parts)
157 
158  keys = list(figures_of_merit.keys())
159 
160  description = formatter.format(description, keys=keys, **replacement_dict)
161  check = formatter.format(check, keys=keys, **replacement_dict)
162 
163  figures_of_merit.description = description
164  figures_of_merit.check = check
165 
166  if tdirectory:
167  figures_of_merit.write(tdirectory)
168 
169  print(figures_of_merit)
170 
171 
173  """Refiner for histograms"""
174 
175  default_name = "{module.id}_{part_name}_histogram{groupby_key}{stackby_key}"
176 
177  default_title = "Histogram of {part_name}{groupby_key}{stackby_key} from {module.title}"
178 
179  default_contact = "{module.contact}"
180 
181  default_description = "This is a histogram of {part_name}{groupby_key}{stackby_key}."
182 
183  default_check = "Check if the distribution is reasonable"
184 
185  def __init__(self,
186  name=None,
187  title=None,
188  contact=None,
189  description=None,
190  check=None,
191  lower_bound=None,
192  upper_bound=None,
193  bins=None,
194  outlier_z_score=None,
195  allow_discrete=False,
196  stackby="",
197  fit=None,
198  fit_z_score=None):
199  """Constructor for this refiner"""
200 
201  super(SaveHistogramsRefiner, self).__init__()
202 
203 
204  self.name = name
205 
206  self.title = title
207 
208 
209  self.description = description
210 
211  self.check = check
212 
213  self.contact = contact
214 
215 
216  self.lower_bound = lower_bound
217 
218  self.upper_bound = upper_bound
219 
220  self.bins = bins
221 
222 
223  self.outlier_z_score = outlier_z_score
224 
225  self.allow_discrete = allow_discrete
226 
227  self.stackby = stackby
228 
229 
230  self.fit = fit
231 
232  self.fit_z_score = fit_z_score
233 
234  def refine(self,
235  harvesting_module,
236  crops,
237  tdirectory=None,
238  groupby_part_name=None,
239  groupby_value=None,
240  **kwds):
241  """Process the histogram"""
242 
243  stackby = self.stackby
244  if stackby:
245  stackby_parts = crops[stackby]
246  else:
247  stackby_parts = None
248 
249  replacement_dict = dict(
250  refiner=self,
251  module=harvesting_module,
252  stackby_key=' stacked by ' + stackby if stackby else "",
253  groupby_key=' in group ' + groupby_part_name + groupby_value if groupby_part_name else "",
254  )
255 
256  contact = self.contact or self.default_contact
257  contact = formatter.format(contact, **replacement_dict)
258 
259  for part_name, parts in iter_items_sorted_for_key(crops):
260  name = self.name or self.default_name
261  title = self.title or self.default_title
262  description = self.description or self.default_description
263  check = self.check or self.default_check
264 
265  name = formatter.format(name, part_name=part_name, **replacement_dict)
266  title = formatter.format(title, part_name=part_name, **replacement_dict)
267  description = formatter.format(description, part_name=part_name, **replacement_dict)
268  check = formatter.format(check, part_name=part_name, **replacement_dict)
269 
270  histogram = ValidationPlot(name)
271  histogram.hist(parts,
272  lower_bound=self.lower_bound,
273  upper_bound=self.upper_bound,
274  bins=self.bins,
275  outlier_z_score=self.outlier_z_score,
276  allow_discrete=self.allow_discrete,
277  stackby=stackby_parts)
278 
279  histogram.title = title
280  histogram.contact = contact
281  histogram.description = description
282  histogram.check = check
283 
284  histogram.xlabel = compose_axis_label(part_name)
285 
286  if self.fit:
287  if self.fit_z_score is None:
288  kwds = dict()
289  else:
290  kwds = dict(z_score=self.fit_z_score)
291 
292  fit_method_name = 'fit_' + str(self.fit)
293  try:
294  fit_method = getattr(histogram, fit_method_name)
295  except AttributeError:
296  histogram.fit(str(fit), **kwds)
297  else:
298  fit_method(**kwds)
299 
300  if tdirectory:
301  histogram.write(tdirectory)
302 
303 
305  """Refiner for profile histograms and 2D scatterplots"""
306 
307  plot_kind = "profile"
308 
309  def __init__(self,
310  y,
311  x=None,
312  name=None,
313  title=None,
314  contact=None,
315  description=None,
316  check=None,
317  stackby=None,
318  y_unit=None,
319  y_binary=None,
320  y_log=None,
321  lower_bound=None,
322  upper_bound=None,
323  bins=None,
324  outlier_z_score=None,
325  fit=None,
326  fit_z_score=None,
327  skip_single_valued=False,
328  allow_discrete=False):
329  """Constructor for this refiner"""
330 
331  super().__init__()
332 
333 
334  self.name = name
335 
336  self.title = title
337 
338 
339  self.description = description
340 
341  self.check = check
342 
343  self.contact = contact
344 
345 
346  self.x = x
347 
348  self.y = y
349 
350  self.stackby = stackby
351 
352  self.y_unit = y_unit
353 
354 
355  self.lower_bound = lower_bound
356 
357  self.upper_bound = upper_bound
358 
359  self.bins = bins
360 
361  self.y_binary = y_binary
362 
363  self.y_log = y_log
364 
365 
366  self.outlier_z_score = outlier_z_score
367 
368  self.allow_discrete = allow_discrete
369 
370 
371  self.fit = fit
372 
373  self.fit_z_score = fit_z_score
374 
375 
376  self.skip_single_valued = skip_single_valued
377 
378  def refine(self,
379  harvesting_module,
380  crops,
381  tdirectory=None,
382  groupby_part_name=None,
383  groupby_value=None,
384  **kwds):
385  """Process the profile histogram / scatterplot"""
386 
387  stackby = self.stackby
388  if stackby:
389  stackby_parts = crops[stackby]
390  else:
391  stackby_parts = None
392 
393  replacement_dict = dict(
394  refiner=self,
395  module=harvesting_module,
396  stackby_key=' stacked by ' + stackby if stackby else "",
397  groupby_key=' in group ' + groupby_part_name + groupby_value if groupby_part_name else "",
398  )
399 
400  contact = self.contact or self.default_contact
401  contact = formatter.format(contact, **replacement_dict)
402 
403  y_crops = select_crop_parts(crops, select=self.y)
404  x_crops = select_crop_parts(crops, select=self.x, exclude=self.y)
405 
406  for y_part_name, y_parts in iter_items_sorted_for_key(y_crops):
407  for x_part_name, x_parts in iter_items_sorted_for_key(x_crops):
408 
409  if self.skip_single_valued and not self.has_more_than_one_value(x_parts):
410  get_logger().info('Skipping "%s" by "%s" profile because x has only a single value "%s"',
411  y_part_name,
412  x_part_name,
413  x_parts[0])
414  continue
415 
416  if self.skip_single_valued and not self.has_more_than_one_value(y_parts):
417  get_logger().info('Skipping "%s" by "%s" profile because y has only a single value "%s"',
418  y_part_name,
419  x_part_name,
420  y_parts[0])
421  continue
422 
423  name = self.name or self.default_name
424  title = self.title or self.default_title
425  description = self.description or self.default_description
426  check = self.check or self.default_check
427 
428  name = formatter.format(name,
429  x_part_name=x_part_name,
430  y_part_name=y_part_name,
431  **replacement_dict)
432 
433  title = formatter.format(title,
434  x_part_name=x_part_name,
435  y_part_name=y_part_name,
436  **replacement_dict)
437 
438  description = formatter.format(description,
439  x_part_name=x_part_name,
440  y_part_name=y_part_name,
441  **replacement_dict)
442 
443  check = formatter.format(check,
444  x_part_name=x_part_name,
445  y_part_name=y_part_name,
446  **replacement_dict)
447 
448  profile_plot = ValidationPlot(name)
449 
450  plot_kind = self.plot_kind
451  if plot_kind == "profile":
452  profile_plot.profile(x_parts,
453  y_parts,
454  lower_bound=self.lower_bound,
455  upper_bound=self.upper_bound,
456  bins=self.bins,
457  y_binary=self.y_binary,
458  y_log=self.y_log,
459  outlier_z_score=self.outlier_z_score,
460  allow_discrete=self.allow_discrete,
461  stackby=stackby_parts)
462 
463  if self.fit:
464  if self.fit_z_score is None:
465  kwds = dict()
466  else:
467  kwds = dict(z_score=self.fit_z_score)
468 
469  fit_method_name = 'fit_' + str(self.fit)
470  try:
471  fit_method = getattr(profile_plot, fit_method_name)
472  except BaseException:
473  profile_plot.fit(str(fit), **kwds)
474  else:
475  fit_method(**kwds)
476 
477  elif plot_kind == "scatter":
478  profile_plot.scatter(x_parts,
479  y_parts,
480  lower_bound=self.lower_bound,
481  upper_bound=self.upper_bound,
482  outlier_z_score=self.outlier_z_score,
483  stackby=stackby_parts)
484 
485  profile_plot.title = title
486  profile_plot.contact = contact
487  profile_plot.description = description
488  profile_plot.check = check
489 
490  profile_plot.xlabel = compose_axis_label(x_part_name)
491  profile_plot.ylabel = compose_axis_label(y_part_name, self.y_unit)
492 
493  if tdirectory:
494  profile_plot.write(tdirectory)
495 
496  @staticmethod
498  """check if a list has at least two unique values"""
499  first_x = xs[0]
500  for x in xs:
501  if x != first_x:
502  return True
503  else:
504  return False
505 
506 
508  """Refiner for profile histograms"""
509 
510  default_name = "{module.id}_{y_part_name}_by_{x_part_name}_profile{groupby_key}{stackby_key}"
511 
512  default_title = "Profile of {y_part_name} by {x_part_name} from {module.title}"
513 
514  default_contact = "{module.contact}"
515 
516  default_description = "This is a profile of {y_part_name} over {x_part_name}."
517 
518  default_check = "Check if the trend line is reasonable."
519 
520 
521  plot_kind = "profile"
522 
523 
525  """Refiner for 2D scatterplots"""
526 
527  default_name = "{module.id}_{y_part_name}_by_{x_part_name}_scatter{groupby_key}{stackby_key}"
528 
529  default_title = "Scatter of {y_part_name} by {x_part_name} from {module.title}"
530 
531  default_contact = "{module.contact}"
532 
533  default_description = "This is a scatter of {y_part_name} over {x_part_name}."
534 
535  default_check = "Check if the distributions is reasonable."
536 
537 
538  plot_kind = "scatter"
539 
540 
542  """Refiner for truth-classification analyses"""
543 
544 
545  default_contact = "{module.contact}"
546 
547 
548  default_truth_name = "{part_name}_truth"
549 
550  default_estimate_name = "{part_name}_estimate"
551 
552  def __init__(self,
553  part_name=None,
554  contact=None,
555  estimate_name=None,
556  truth_name=None,
557  cut_direction=None,
558  cut=None,
559  lower_bound=None,
560  upper_bound=None,
561  outlier_z_score=None,
562  allow_discrete=False,
563  unit=None):
564  """Constructor for this refiner"""
565 
566 
567  self.part_name = part_name
568 
569  self.contact = contact
570 
571  self.estimate_name = estimate_name
572 
573  self.truth_name = truth_name
574 
575 
576  self.cut = cut
577 
578  self.cut_direction = cut_direction
579 
580 
581  self.lower_bound = lower_bound
582 
583  self.upper_bound = upper_bound
584 
585  self.outlier_z_score = outlier_z_score
586 
587  self.allow_discrete = allow_discrete
588 
589  self.unit = unit
590 
591  def refine(self,
592  harvesting_module,
593  crops,
594  tdirectory=None,
595  groupby_part_name=None,
596  groupby_value=None,
597  **kwds):
598  """Process the truth-classification analysis"""
599 
600  replacement_dict = dict(
601  refiner=self,
602  module=harvesting_module,
603  groupby_key='_' + groupby_part_name + groupby_value if groupby_part_name else "",
604  groupby=groupby_part_name, # deprecated
605  groupby_value=groupby_value, # deprecated
606  )
607 
608  contact = self.contact or self.default_contact
609  contact = formatter.format(contact, **replacement_dict)
610 
611  if self.truth_name is not None:
612  truth_name = self.truth_name
613  else:
614  truth_name = self.default_truth_name
615 
616  truth_name = formatter.format(truth_name, part_name=self.part_name)
617  truths = crops[truth_name]
618 
619  if self.estimate_name is not None:
620  estimate_name = self.estimate_name
621  else:
622  estimate_name = self.default_estimate_name
623 
624  if isinstance(estimate_name, str):
625  estimate_names = [estimate_name, ]
626  else:
627  estimate_names = estimate_name
628 
629  for estimate_name in estimate_names:
630  estimate_name = formatter.format(estimate_name, part_name=self.part_name)
631  estimates = crops[estimate_name]
632 
633  classification_analysis = ClassificationAnalysis(quantity_name=estimate_name,
634  contact=contact,
635  cut_direction=self.cut_direction,
636  cut=self.cut,
637  lower_bound=self.lower_bound,
638  upper_bound=self.upper_bound,
639  outlier_z_score=self.outlier_z_score,
640  allow_discrete=self.allow_discrete,
641  unit=self.unit)
642 
643  classification_analysis.analyse(estimates, truths)
644 
645  if tdirectory:
646  classification_analysis.write(tdirectory)
647 
648 
650  """Refiner for pull analyses"""
651 
652 
653  default_name = "{module.id}_{quantity_name}"
654 
655  default_contact = "{module.contact}"
656 
657  default_title_postfix = " from {module.title}"
658 
659 
660  default_truth_name = "{part_name}_truth"
661 
662  default_estimate_name = "{part_name}_estimate"
663 
664  default_variance_name = "{part_name}_variance"
665 
666  def __init__(self,
667  name=None,
668  contact=None,
669  title_postfix=None,
670  part_name=None,
671  part_names=None,
672  truth_name=None,
673  estimate_name=None,
674  variance_name=None,
675  quantity_name=None,
676  aux_names=[],
677  unit=None,
678  outlier_z_score=None,
679  absolute=False,
680  which_plots=None):
681  """Constructor for this refiner"""
682 
683 
684  self.name = name
685 
686  self.contact = contact
687 
688  self.title_postfix = title_postfix
689 
690 
691  self.part_names = []
692  if part_names is not None:
693  self.part_names = part_names
694 
695  if part_name is not None:
696  self.part_names.append(part_name)
697 
698 
699  self.truth_name = truth_name
700 
701  self.estimate_name = estimate_name
702 
703  self.variance_name = variance_name
704 
705 
706  self.quantity_name = quantity_name
707 
708  self.unit = unit
709 
710 
711  self.aux_names = aux_names
712 
713 
714  self.outlier_z_score = outlier_z_score
715 
716  self.absolute = absolute
717 
718  self.which_plots = which_plots
719 
720  def refine(self,
721  harvesting_module,
722  crops,
723  tdirectory=None,
724  groupby_part_name=None,
725  groupby_value=None,
726  **kwds):
727  """Process the pull analysis"""
728 
729  replacement_dict = dict(
730  refiner=self,
731  module=harvesting_module,
732  # stackby_key='_' + stackby if stackby else "",
733  groupby_key='_' + groupby_part_name + groupby_value if groupby_part_name else "",
734  groupby=groupby_part_name, # deprecated
735  groupby_value=groupby_value, # deprecated
736  )
737 
738  contact = self.contact or self.default_contact
739  contact = formatter.format(contact, **replacement_dict)
740 
741  name = self.name or self.default_name
742 
743  if self.aux_names:
744  auxiliaries = select_crop_parts(crops, self.aux_names)
745  else:
746  auxiliaries = {}
747 
748  for part_name in self.part_names:
749  name = formatter.format(name, part_name=part_name, **replacement_dict)
750  plot_name = name + "_{subplot_name}"
751 
752  title_postfix = self.title_postfix
753  if title_postfix is None:
754  title_postfix = self.default_title_postfix
755 
756  title_postfix = formatter.format(title_postfix, part_name=part_name, **replacement_dict)
757  plot_title = "{subplot_title} of {quantity_name}" + title_postfix
758 
759  if self.truth_name is not None:
760  truth_name = self.truth_name
761  else:
762  truth_name = self.default_truth_name
763 
764  if self.estimate_name is not None:
765  estimate_name = self.estimate_name
766  else:
767  estimate_name = self.default_estimate_name
768 
769  if self.variance_name is not None:
770  variance_name = self.variance_name
771  else:
772  variance_name = self.default_variance_name
773 
774  truth_name = formatter.format(truth_name, part_name=part_name)
775  estimate_name = formatter.format(estimate_name, part_name=part_name)
776  variance_name = formatter.format(variance_name, part_name=part_name)
777 
778  truths = crops[truth_name]
779  estimates = crops[estimate_name]
780  try:
781  variances = crops[variance_name]
782  except KeyError:
783  variances = None
784 
785  quantity_name = self.quantity_name or part_name
786 
787  which_plots = self.which_plots
788 
789  pull_analysis = PullAnalysis(quantity_name,
790  unit=self.unit,
791  absolute=self.absolute,
792  outlier_z_score=self.outlier_z_score,
793  plot_name=plot_name,
794  plot_title=plot_title)
795 
796  pull_analysis.analyse(truths,
797  estimates,
798  variances,
799  auxiliaries=auxiliaries,
800  which_plots=which_plots)
801 
802  pull_analysis.contact = contact
803 
804  if tdirectory:
805  pull_analysis.write(tdirectory)
806 
807 
809  """Refiner for ROOT TTrees"""
810 
811 
812  default_name = "{module.id}_tree"
813 
814  default_title = "Tree of {module.id}"
815 
816  def __init__(self,
817  name=None,
818  title=None):
819  """Constructor for this refiner"""
820  super(SaveTreeRefiner, self).__init__()
821 
822 
823  self.name = name
824 
825  self.title = title
826 
827  def refine(self,
828  harvesting_module,
829  crops,
830  tdirectory=None,
831  groupby_part_name=None,
832  groupby_value=None,
833  **kwds):
834  """Process the TTree"""
835 
836  replacement_dict = dict(
837  refiner=self,
838  module=harvesting_module,
839  groupby_key='_' + groupby_part_name + groupby_value if groupby_part_name else "",
840  groupby=groupby_part_name, # deprecated
841  groupby_value=groupby_value, # deprecated
842  )
843 
844  with root_cd(tdirectory):
845  name = self.name or self.default_name
846  title = self.title or self.default_title
847 
848  name = formatter.format(name, **replacement_dict)
849  title = formatter.format(title, **replacement_dict)
850 
851  output_ttree = ROOT.TTree(root_save_name(name), title)
852  for part_name, parts in iter_items_sorted_for_key(crops):
853  self.add_branch(output_ttree, part_name, parts)
854 
855  output_ttree.FlushBaskets()
856  output_ttree.Write()
857 
858  def add_branch(self, output_ttree, part_name, parts):
859  """Add a TBranch to the TTree"""
860  input_value = np.zeros(1, dtype=float)
861 
862  branch_type_spec = '%s/D' % part_name
863  tbranch = output_ttree.Branch(part_name, input_value, branch_type_spec)
864 
865  if output_ttree.GetNbranches() == 1:
866  # On filling of the first branch we need to use the fill method of the TTree
867  # For all other branches we can use the one of the branch
868  # #justrootthings
869  for value in parts:
870  input_value[0] = value
871  output_ttree.Fill()
872 
873  else:
874  for value in parts:
875  input_value[0] = value
876  tbranch.Fill()
877 
878  output_ttree.GetEntry(0)
879  output_ttree.ResetBranchAddress(tbranch)
880  also_subbranches = True # No subbranches here but we drop the buffers just in case.
881  output_ttree.DropBranchFromCache(tbranch, also_subbranches)
882 
883 
885  """Refiner for filters"""
886 
887  def __init__(self, wrapped_refiner, filter=None, on=None):
888  """Constructor for this refiner"""
889 
890 
891  self.wrapped_refiner = wrapped_refiner
892 
893  if filter is None:
894 
895  self.filter = np.nonzero
896  else:
897  self.filter = filter
898 
899 
900  self.on = on
901 
902  def refine(self, harvesting_module, crops, *args, **kwds):
903  """Process this filter"""
904  filtered_crops = filter_crops(crops, self.filter, part_name=self.on)
905  self.wrapped_refiner(harvesting_module, filtered_crops, *args, **kwds)
906 
907 
909  """Refiner for selection"""
910 
911  def __init__(self, wrapped_refiner, select=[], exclude=[]):
912  """Constructor for this refiner"""
913 
914 
915  self.wrapped_refiner = wrapped_refiner
916 
917  self.select = select
918 
919  self.exclude = exclude
920 
921  def refine(self, harvesting_module, crops, *args, **kwds):
922  """Process this selection"""
923  selected_crops = select_crop_parts(crops, select=self.select, exclude=self.exclude)
924  self.wrapped_refiner(harvesting_module, selected_crops, *args, **kwds)
925 
926 
928  """Refiner for grouping"""
929 
930 
931  default_exclude_by = True
932 
933  def __init__(self,
934  wrapped_refiner,
935  by=[],
936  exclude_by=None):
937  """Constructor for this refiner"""
938 
939 
940  self.wrapped_refiner = wrapped_refiner
941 
942  self.by = by
943 
944  self.exclude_by = exclude_by if exclude_by is not None else self.default_exclude_by
945 
946  def refine(self,
947  harvesting_module,
948  crops,
949  groupby_part_name=None,
950  groupby_value=None,
951  *args,
952  **kwds):
953  """Process this grouping"""
954 
955  by = self.by
956 
957  # A single name to do the group by
958  if isinstance(by, str) or by is None:
959  part_name = by
960  # Wrap it into a list an continue with the general case
961  by = [part_name, ]
962 
963  for groupby_spec in by:
964  if groupby_spec is None:
965  # Using empty string as groupby_value to indicate that all values have been selected
966  value = None
967  self.wrapped_refiner(harvesting_module,
968  crops,
969  groupby_part_name=None,
970  groupby_value=value,
971  *args,
972  **kwds)
973  continue
974 
975  elif isinstance(groupby_spec, str):
976  part_name = groupby_spec
977  groupby_parts = crops[part_name]
978  unique_values, index_of_values = np.unique(groupby_parts, return_inverse=True)
979  groupby_values = [" = {value}]".format(value=value) for value in unique_values]
980 
981  elif isinstance(groupby_spec, tuple):
982  part_name = groupby_spec[0]
983  cuts = groupby_spec[1]
984 
985  groupby_parts = crops[part_name]
986 
987  # Take care of nans
988  digitization_cuts = list(np.sort(cuts))
989  if digitization_cuts[-1] != np.inf:
990  digitization_cuts.append(np.inf)
991  index_of_values = np.digitize(groupby_parts, digitization_cuts, right=True)
992 
993  groupby_values = ["below {upper_bound}".format(upper_bound=digitization_cuts[0])]
994  bin_bounds = list(zip(digitization_cuts[0:], digitization_cuts[1:]))
995  for lower_bound, upper_bound in bin_bounds:
996  if lower_bound == upper_bound:
997  # degenerated bin case
998  groupby_values.append("= {lower_bound}".format(lower_bound=lower_bound))
999  elif upper_bound == np.inf:
1000  groupby_values.append("above {lower_bound}".format(lower_bound=lower_bound))
1001  else:
1002  groupby_values.append("between {lower_bound} and {upper_bound}".format(lower_bound=lower_bound,
1003  upper_bound=upper_bound))
1004  groupby_values.append("is nan")
1005  assert len(groupby_values) == len(digitization_cuts) + 1
1006 
1007  else:
1008  raise ValueError("Unknown groupby specification %s" % groupby_spec)
1009 
1010  # Exclude the groupby variable if desired
1011  selected_crops = select_crop_parts(crops, exclude=part_name if self.exclude_by else None)
1012  for index_of_value, groupby_value in enumerate(groupby_values):
1013  indices_for_value = index_of_values == index_of_value
1014  if not np.any(indices_for_value):
1015  continue
1016 
1017  filtered_crops = filter_crops(selected_crops, indices_for_value)
1018 
1019  self.wrapped_refiner(harvesting_module,
1020  filtered_crops,
1021  groupby_part_name=part_name,
1022  groupby_value=groupby_value,
1023  *args,
1024  **kwds)
1025 
1026 
1028  """Refiner for change-directory"""
1029 
1030 
1031  default_folder_name = ""
1032 
1033  default_groupby_addition = "_groupby_{groupby}_{groupby_value}"
1034 
1035  def __init__(self,
1036  wrapped_refiner,
1037  folder_name=None,
1038  groupby_addition=None):
1039  """Constructor for this refiner"""
1040 
1042  self.wrapped_refiner = wrapped_refiner
1044  self.folder_name = folder_name
1045 
1046  self.groupby_addition = groupby_addition
1047 
1048  def refine(self,
1049  harvesting_module,
1050  crops,
1051  tdirectory=None,
1052  groupby_part_name=None,
1053  groupby_value=None,
1054  *args,
1055  **kwds):
1056  """Process the change-directory"""
1057 
1058  folder_name = self.folder_name
1059  if folder_name is None:
1060  if groupby_value is not None:
1061  folder_name = "{groupby_addition}"
1062  else:
1063  folder_name = self.default_folder_name
1064 
1065  groupby_addition = self.groupby_addition
1066 
1067  if groupby_addition is None:
1068  groupby_addition = self.default_groupby_addition
1069 
1070  if groupby_part_name is None and groupby_value is None:
1071  groupby_addition = ""
1072  else:
1073  groupby_addition = formatter.format(groupby_addition,
1074  groupby=groupby_part_name,
1075  groupby_value=groupby_value)
1076 
1077  folder_name = formatter.format(folder_name,
1078  groupby_addition=groupby_addition,
1079  groupby=groupby_part_name,
1080  groupby_value=groupby_value)
1081 
1082  folder_name = '/'.join(root_save_name(name) for name in folder_name.split('/'))
1083 
1084  with root_cd(tdirectory):
1085  with root_cd(folder_name) as tdirectory:
1086  self.wrapped_refiner(harvesting_module,
1087  crops,
1088  tdirectory=tdirectory,
1089  groupby_part_name=groupby_part_name,
1090  groupby_value=groupby_value,
1091  *args,
1092  **kwds)
1093 
1094 
1096  """Refiner for expert-level categorization"""
1097 
1098  def __init__(self, wrapped_refiner, above_expert_level=None, below_expert_level=None):
1099  """Constructor for this refiner"""
1100 
1101 
1102  self.wrapped_refiner = wrapped_refiner
1103 
1104  self.above_expert_level = above_expert_level
1105 
1106  self.below_expert_level = below_expert_level
1107 
1108  def refine(self, harvesting_module, crops, *args, **kwds):
1109  """Process the expert-level categorization"""
1110 
1111  above_expert_level = self.above_expert_level
1112  below_expert_level = self.below_expert_level
1113 
1114  proceed = True
1115  if above_expert_level is not None:
1116  proceed = proceed and harvesting_module.expert_level > above_expert_level
1117 
1118  if below_expert_level is not None:
1119  proceed = proceed and harvesting_module.expert_level < below_expert_level
1120 
1121  if proceed:
1122  self.wrapped_refiner(harvesting_module, crops, *args, **kwds)
1123 
1124 
1125 # Meta refiner decorators
1126 def groupby(refiner=None, **kwds):
1127  def group_decorator(wrapped_refiner):
1128  return GroupByRefiner(wrapped_refiner, **kwds)
1129  if refiner is None:
1130  return group_decorator
1131  else:
1132  return group_decorator(refiner)
1133 
1134 
1135 def select(refiner=None, **kwds):
1136  def select_decorator(wrapped_refiner):
1137  return SelectRefiner(wrapped_refiner, **kwds)
1138  if refiner is None:
1139  return select_decorator
1140  else:
1141  return select_decorator(refiner)
1142 
1143 
1144 def filter(refiner=None, **kwds):
1145  def filter_decorator(wrapped_refiner):
1146  return FilterRefiner(wrapped_refiner, **kwds)
1147  if refiner is None:
1148  return filter_decorator
1149  else:
1150  return filter_decorator(refiner)
1151 
1152 
1153 def cd(refiner=None, **kwds):
1154  def cd_decorator(wrapped_refiner):
1155  return CdRefiner(wrapped_refiner, **kwds)
1156  if refiner is None:
1157  return cd_decorator
1158  else:
1159  return cd_decorator(refiner)
1160 
1161 
1162 def context(refiner=None,
1163  above_expert_level=None, below_expert_level=None,
1164  folder_name=None, folder_groupby_addition=None,
1165  filter=None, filter_on=None,
1166  groupby=None, exclude_groupby=None,
1167  select=None, exclude=None):
1168 
1169  def context_decorator(wrapped_refiner):
1170  # Apply meta refiners in the reverse order that they shall be executed
1171  if exclude is not None or select is not None:
1172  wrapped_refiner = SelectRefiner(wrapped_refiner,
1173  select=select, exclude=exclude)
1174 
1175  if folder_name is not None or groupby is not None or folder_groupby_addition is not None:
1176  wrapped_refiner = CdRefiner(wrapped_refiner,
1177  folder_name=folder_name,
1178  groupby_addition=folder_groupby_addition)
1179 
1180  if groupby is not None:
1181  wrapped_refiner = GroupByRefiner(wrapped_refiner,
1182  by=groupby,
1183  exclude_by=exclude_groupby)
1184 
1185  if filter is not None or filter_on is not None:
1186  wrapped_refiner = FilterRefiner(wrapped_refiner,
1187  filter=filter,
1188  on=filter_on)
1189 
1190  if above_expert_level is not None or below_expert_level is not None:
1191  wrapped_refiner = ExpertLevelRefiner(wrapped_refiner,
1192  above_expert_level=above_expert_level,
1193  below_expert_level=below_expert_level)
1194 
1195  if not isinstance(wrapped_refiner, Refiner):
1196  wrapped_refiner = Refiner(wrapped_refiner)
1197 
1198  return wrapped_refiner
1199 
1200  if refiner is None:
1201  return context_decorator
1202  else:
1203  return functools.wraps(refiner)(context_decorator(refiner))
1204 
1205 
1206 def refiner_with_context(refiner_factory):
1207  @functools.wraps(refiner_factory)
1208  def module_decorator_with_context(above_expert_level=None, below_expert_level=None,
1209  folder_name=None, folder_groupby_addition=None,
1210  filter=None, filter_on=None,
1211  groupby=None, exclude_groupby=None,
1212  select=None, exclude=None,
1213  **kwds_for_refiner_factory):
1214 
1215  refiner = refiner_factory(**kwds_for_refiner_factory)
1216 
1217  return context(refiner,
1218  above_expert_level=above_expert_level, below_expert_level=below_expert_level,
1219  folder_name=folder_name, folder_groupby_addition=folder_groupby_addition,
1220  filter=filter, filter_on=filter_on,
1221  groupby=groupby, exclude_groupby=exclude_groupby,
1222  select=select, exclude=exclude)
1223 
1224  return module_decorator_with_context
1225 
1226 
1227 @refiner_with_context
1228 def save_fom(**kwds):
1229  return SaveFiguresOfMeritRefiner(**kwds)
1230 
1231 
1232 @refiner_with_context
1233 def save_histograms(**kwds):
1234  return SaveHistogramsRefiner(**kwds)
1235 
1236 
1237 @refiner_with_context
1238 def save_profiles(**kwds):
1239  return SaveProfilesRefiner(**kwds)
1240 
1241 
1242 @refiner_with_context
1243 def save_scatters(**kwds):
1244  return SaveScatterRefiner(**kwds)
1245 
1246 
1247 @refiner_with_context
1248 def save_classification_analysis(**kwds):
1249  return SaveClassificationAnalysisRefiner(**kwds)
1250 
1251 
1252 @refiner_with_context
1253 def save_pull_analysis(**kwds):
1254  return SavePullAnalysisRefiner(**kwds)
1255 
1256 
1257 @refiner_with_context
1258 def save_tree(**kwds):
1259  return SaveTreeRefiner(**kwds)
1260 
1261 
1262 def select_crop_parts(crops, select=[], exclude=[]):
1263  if isinstance(select, str):
1264  select = [select, ]
1265 
1266  if isinstance(exclude, str):
1267  exclude = [exclude, ]
1268 
1269  if isinstance(crops, collections.MutableMapping):
1270  part_names = list(crops.keys())
1271 
1272  if not select and not exclude:
1273  return crops
1274 
1275  if select:
1276  not_selected_part_names = [name for name in part_names if name not in select]
1277 
1278  # if the selection item is a callable function do not count it as not selectable yet
1279  select_not_in_part_names = [name for name in select
1280  if not isinstance(name, collections.Callable) and name not in part_names]
1281  if select_not_in_part_names:
1282  get_logger().warning("Cannot select %s, because they are not in crop part names %s",
1283  select_not_in_part_names, sorted(part_names))
1284  else:
1285  not_selected_part_names = []
1286 
1287  if exclude:
1288  excluded_part_names = [name for name in part_names if name in exclude]
1289  else:
1290  excluded_part_names = []
1291 
1292  excluded_part_names.extend(not_selected_part_names)
1293 
1294  # Make a shallow copy
1295  selected_crops = copy.copy(crops)
1296  for part_name in set(excluded_part_names):
1297  del selected_crops[part_name]
1298 
1299  if isinstance(select, collections.Mapping):
1300  # select is a rename mapping
1301  for part_name, new_part_name in list(select.items()):
1302  if isinstance(part_name, collections.Callable):
1303  selected_crops[new_part_name] = part_name(**crops)
1304  elif part_name in selected_crops:
1305  parts = selected_crops[part_name]
1306  del selected_crops[part_name]
1307  selected_crops[new_part_name] = parts
1308 
1309  return selected_crops
1310 
1311  else:
1312  raise ValueError("Unrecognised crop %s of type %s" % (crop, type(crop)))
1313 
1314 
1315 def filter_crops(crops, filter_function, part_name=None):
1316  if isinstance(filter_function, np.ndarray):
1317  filter_indices = filter_function
1318  else:
1319  parts = crops[part_name]
1320  filter_indices = filter_function(parts)
1321 
1322  if isinstance(crops, np.ndarray):
1323  return crops[filter_indices]
1324 
1325  elif isinstance(crops, collections.MutableMapping):
1326  # Make a shallow copy
1327  filtered_crops = copy.copy(crops)
1328  for part_name, parts in list(crops.items()):
1329  filtered_crops[part_name] = parts[filter_indices]
1330  return filtered_crops
1331 
1332  else:
1333  raise ValueError("Unrecognised crop %s of type %s" % (crop, type(crop)))
1334 
1335 
1336 def iter_items_sorted_for_key(crops):
1337  # is the type of crops is a dictionary assume, that it should be sorted
1338  # in all other cases the users class has to take care of the sorting
1339  if isinstance(crops, dict):
1340  keys = sorted(crops.keys())
1341  return ((key, crops[key]) for key in keys)
1342  else:
1343  return list(crops.items())
tracking.validation.fom.ValidationFiguresOfMerit
Definition: fom.py:11
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.contact
contact
cached contact person of the figure of merit
Definition: refiners.py:104
tracking.harvest.refiners.Plot2DRefiner.allow_discrete
allow_discrete
cached flag to allow discrete values for this profile histogram / scatterplot
Definition: refiners.py:349
tracking.harvest.refiners.SavePullAnalysisRefiner.which_plots
which_plots
cached list of plots produced by the pull analysis
Definition: refiners.py:704
tracking.harvest.refiners.Refiner.__init__
def __init__(self, refiner_function=None)
Definition: refiners.py:29
tracking.harvest.refiners.Plot2DRefiner.title
title
cached user-defined title for this profile histogram / scatterplot
Definition: refiners.py:317
tracking.harvest.refiners.GroupByRefiner.by
by
cached value of the group-by classifier
Definition: refiners.py:939
tracking.harvest.refiners.CdRefiner.default_groupby_addition
string default_groupby_addition
Default suffix for a groupby selection.
Definition: refiners.py:1033
tracking.validation.classification.ClassificationAnalysis
Definition: classification.py:19
tracking.harvest.refiners.Refiner.refine
def refine(self, harvesting_module, *args, **kwds)
Definition: refiners.py:61
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.part_name
part_name
cached part name for this truth-classification analysis
Definition: refiners.py:556
tracking.harvest.refiners.Plot2DRefiner.upper_bound
upper_bound
cached upper bound for this profile histogram / scatterplot
Definition: refiners.py:338
tracking.harvest.refiners.FilterRefiner.on
on
cached value of the part name to filter on
Definition: refiners.py:900
tracking.harvest.refiners.Plot2DRefiner.__init__
def __init__(self, y, x=None, name=None, title=None, contact=None, description=None, check=None, stackby=None, y_unit=None, y_binary=None, y_log=None, lower_bound=None, upper_bound=None, bins=None, outlier_z_score=None, fit=None, fit_z_score=None, skip_single_valued=False, allow_discrete=False)
Definition: refiners.py:309
tracking.harvest.refiners.ExpertLevelRefiner.refine
def refine(self, harvesting_module, crops, *args, **kwds)
Definition: refiners.py:1108
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.lower_bound
lower_bound
cached lower bound of estimates for this truth-classification analysis
Definition: refiners.py:570
tracking.validation.pull.PullAnalysis
Definition: pull.py:20
tracking.harvest.refiners.FilterRefiner.filter
filter
cached value of the filter
Definition: refiners.py:895
tracking.harvest.refiners.SavePullAnalysisRefiner.estimate_name
estimate_name
cached name for the pull analysis estimates collection
Definition: refiners.py:687
tracking.harvest.refiners.ExpertLevelRefiner
Definition: refiners.py:1095
tracking.harvest.refiners.Plot2DRefiner.refine
def refine(self, harvesting_module, crops, tdirectory=None, groupby_part_name=None, groupby_value=None, **kwds)
Definition: refiners.py:378
tracking.harvest.refiners.SaveTreeRefiner.__init__
def __init__(self, name=None, title=None)
Definition: refiners.py:816
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.check
check
cached user-check action of the figure of merit
Definition: refiners.py:102
tracking.harvest.refiners.Plot2DRefiner.stackby
stackby
cached stacking selection for this profile histogram / scatterplot
Definition: refiners.py:331
tracking.harvest.refiners.Plot2DRefiner.plot_kind
string plot_kind
by default, this refiner is for profile histograms
Definition: refiners.py:307
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.default_contact
string default_contact
default contact person for this refiner
Definition: refiners.py:73
tracking.harvest.refiners.Plot2DRefiner.bins
bins
cached number of bins for this profile histogram / scatterplot
Definition: refiners.py:340
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.upper_bound
upper_bound
cached upper bound of estimates for this truth-classification analysis
Definition: refiners.py:572
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.__init__
def __init__(self, name=None, title=None, contact=None, description=None, check=None, key=None, aggregation=None)
Definition: refiners.py:89
tracking.harvest.refiners.SaveTreeRefiner.default_title
string default_title
default title for this TTree
Definition: refiners.py:814
tracking.harvest.refiners.Plot2DRefiner.skip_single_valued
skip_single_valued
cached flag to skip single-valued bins for this profile histogram / scatterplot
Definition: refiners.py:357
tracking.harvest.refiners.SavePullAnalysisRefiner.refine
def refine(self, harvesting_module, crops, tdirectory=None, groupby_part_name=None, groupby_value=None, **kwds)
Definition: refiners.py:720
tracking.harvest.refiners.Plot2DRefiner.lower_bound
lower_bound
cached lower bound for this profile histogram / scatterplot
Definition: refiners.py:336
tracking.harvest.refiners.SaveTreeRefiner
Definition: refiners.py:808
tracking.harvest.refiners.SavePullAnalysisRefiner.aux_names
aux_names
cached auxiliary names for the pull analysis
Definition: refiners.py:697
tracking.validation.classification
Definition: classification.py:1
tracking.harvest.refiners.SavePullAnalysisRefiner.part_names
part_names
cached array of part names for this pull analysis
Definition: refiners.py:677
tracking.harvest.refiners.CdRefiner.folder_name
folder_name
cached value of the folder name
Definition: refiners.py:1041
tracking.harvest.refiners.CdRefiner.wrapped_refiner
wrapped_refiner
cached value of the wrapped refiner
Definition: refiners.py:1039
tracking.harvest.refiners.SaveHistogramsRefiner.stackby
stackby
cached stacking selection for this histogram
Definition: refiners.py:214
tracking.harvest.refiners.SaveHistogramsRefiner.default_name
string default_name
default name for this histogram
Definition: refiners.py:175
tracking.harvest.refiners.Plot2DRefiner.contact
contact
cached user-defined contact person for this profile histogram / scatterplot
Definition: refiners.py:324
tracking.harvest.refiners.SaveHistogramsRefiner.description
description
cached user-defined description for this histogram
Definition: refiners.py:196
tracking.harvest.refiners.SaveTreeRefiner.title
title
cached title for this TTree
Definition: refiners.py:823
Belle2::filter
std::map< ExpRun, std::pair< double, double > > filter(const std::map< ExpRun, std::pair< double, double >> &runs, double cut, std::map< ExpRun, std::pair< double, double >> &runsRemoved)
filter events to remove runs shorter than cut, it stores removed runs in runsRemoved
Definition: Splitter.cc:43
tracking.harvest.refiners.SavePullAnalysisRefiner.default_contact
string default_contact
default contact person for this pull analysis
Definition: refiners.py:655
tracking.harvest.refiners.SavePullAnalysisRefiner.variance_name
variance_name
cached name for the pull analysis variances collection
Definition: refiners.py:689
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.default_estimate_name
string default_estimate_name
default name for the truth-classification analysis estimates collection
Definition: refiners.py:550
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.cut
cut
cached threshold of estimates for this truth-classification analysis
Definition: refiners.py:565
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.title
title
cached title of the figure of merit
Definition: refiners.py:97
tracking.harvest.refiners.SaveHistogramsRefiner.__init__
def __init__(self, name=None, title=None, contact=None, description=None, check=None, lower_bound=None, upper_bound=None, bins=None, outlier_z_score=None, allow_discrete=False, stackby="", fit=None, fit_z_score=None)
Definition: refiners.py:185
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.mean
def mean(xs)
return the mean of the parts, ignoring NaNs
Definition: refiners.py:83
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.__init__
def __init__(self, part_name=None, contact=None, estimate_name=None, truth_name=None, cut_direction=None, cut=None, lower_bound=None, upper_bound=None, outlier_z_score=None, allow_discrete=False, unit=None)
Definition: refiners.py:552
tracking.harvest.refiners.Refiner.__get__
def __get__(self, harvesting_module, cls=None)
Definition: refiners.py:34
tracking.harvest.refiners.SaveFiguresOfMeritRefiner
Definition: refiners.py:66
tracking.harvest.refiners.Plot2DRefiner.name
name
cached user-defined name for this profile histogram / scatterplot
Definition: refiners.py:315
tracking.harvest.refiners.SaveTreeRefiner.default_name
string default_name
default name for this TTree
Definition: refiners.py:812
tracking.harvest.refiners.SaveHistogramsRefiner.default_contact
string default_contact
default contact person for this histogram
Definition: refiners.py:179
tracking.harvest.refiners.GroupByRefiner.wrapped_refiner
wrapped_refiner
cached value of the wrapped refiner
Definition: refiners.py:937
tracking.harvest.refiners.SaveHistogramsRefiner.check
check
cached user-defined user-check action for this histogram
Definition: refiners.py:198
tracking.harvest.refiners.CdRefiner.default_folder_name
string default_folder_name
Folder name to be used if a groupby selection is active.
Definition: refiners.py:1031
tracking.harvest.refiners.SavePullAnalysisRefiner
Definition: refiners.py:649
tracking.harvest.refiners.SaveProfilesRefiner
Definition: refiners.py:507
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.description
description
cached description of the figure of merit
Definition: refiners.py:100
tracking.validation.pull
Definition: pull.py:1
tracking.harvest.refiners.SavePullAnalysisRefiner.outlier_z_score
outlier_z_score
cached Z-score (for outlier detection) for the pull analysis
Definition: refiners.py:700
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.refine
def refine(self, harvesting_module, crops, tdirectory=None, groupby_part_name=None, groupby_value=None, **kwds)
Definition: refiners.py:591
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.key
key
cached copy of the figures-of-merit key
Definition: refiners.py:107
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.default_truth_name
string default_truth_name
default name for the truth-classification analysis truth-values collection
Definition: refiners.py:548
tracking.harvest.refiners.ExpertLevelRefiner.__init__
def __init__(self, wrapped_refiner, above_expert_level=None, below_expert_level=None)
Definition: refiners.py:1098
tracking.harvest.refiners.Plot2DRefiner.y_unit
y_unit
cached measurement unit for ordinate
Definition: refiners.py:333
tracking.harvest.refiners.Plot2DRefiner
Definition: refiners.py:304
tracking.harvest.refiners.SaveHistogramsRefiner.allow_discrete
allow_discrete
cached flag to allow discrete values for this histogram
Definition: refiners.py:212
tracking.harvest.refiners.Plot2DRefiner.x
x
cached value of abscissa
Definition: refiners.py:327
tracking.harvest.refiners.SelectRefiner
Definition: refiners.py:908
tracking.harvest.refiners.ExpertLevelRefiner.below_expert_level
below_expert_level
cached value of the lower range of the expert level
Definition: refiners.py:1106
tracking.harvest.refiners.SaveHistogramsRefiner.refine
def refine(self, harvesting_module, crops, tdirectory=None, groupby_part_name=None, groupby_value=None, **kwds)
Definition: refiners.py:234
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.default_title
string default_title
default title for this refiner
Definition: refiners.py:71
tracking.harvest.refiners.SaveHistogramsRefiner.upper_bound
upper_bound
cached upper bound for this histogram
Definition: refiners.py:205
tracking.harvest.refiners.GroupByRefiner.refine
def refine(self, harvesting_module, crops, groupby_part_name=None, groupby_value=None, *args, **kwds)
Definition: refiners.py:946
tracking.harvest.refiners.SelectRefiner.wrapped_refiner
wrapped_refiner
cached value of the wrapped refiner
Definition: refiners.py:915
tracking.validation.tolerate_missing_key_formatter
Definition: tolerate_missing_key_formatter.py:1
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.default_check
string default_check
default user-check action for this refiner
Definition: refiners.py:77
tracking.harvest.refiners.SavePullAnalysisRefiner.default_name
string default_name
default name for this pull analysis
Definition: refiners.py:653
tracking.harvest.refiners.Plot2DRefiner.check
check
cached user-defined user-check action for this profile histogram / scatterplot
Definition: refiners.py:322
tracking.harvest.refiners.Plot2DRefiner.outlier_z_score
outlier_z_score
cached Z-score (for outlier detection) for this profile histogram / scatterplot
Definition: refiners.py:347
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.default_aggregation
def default_aggregation
default aggregation is the mean of the parts
Definition: refiners.py:87
tracking.harvest.refiners.SaveHistogramsRefiner.lower_bound
lower_bound
cached lower bound for this histogram
Definition: refiners.py:203
tracking.harvest.refiners.SaveHistogramsRefiner.title
title
cached user-defined title for this histogram
Definition: refiners.py:193
tracking.harvest.refiners.FilterRefiner.refine
def refine(self, harvesting_module, crops, *args, **kwds)
Definition: refiners.py:902
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.refine
def refine(self, harvesting_module, crops, tdirectory=None, groupby_part_name=None, groupby_value=None, **kwds)
Definition: refiners.py:119
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.aggregation
aggregation
cached copy of the crops-aggregation method
Definition: refiners.py:109
tracking.harvest.refiners.ExpertLevelRefiner.above_expert_level
above_expert_level
cached value of the upper range of the expert level
Definition: refiners.py:1104
tracking.harvest.refiners.Refiner.refiner_function
refiner_function
cached copy of the instance's refiner function
Definition: refiners.py:32
tracking.harvest.refiners.SavePullAnalysisRefiner.quantity_name
quantity_name
cached name of the quantity for the pull analysis
Definition: refiners.py:692
tracking.harvest.refiners.SaveHistogramsRefiner.default_description
string default_description
default description for this histogram
Definition: refiners.py:181
tracking.harvest.refiners.GroupByRefiner
Definition: refiners.py:927
tracking.harvest.refiners.GroupByRefiner.exclude_by
exclude_by
cached value of the exclude-by classifier
Definition: refiners.py:941
tracking.harvest.refiners.Plot2DRefiner.y_log
y_log
cached flag for logarithmic y axis for this profile histogram / scatterplot
Definition: refiners.py:344
tracking.root_utils
Definition: root_utils.py:1
tracking.harvest.refiners.GroupByRefiner.default_exclude_by
bool default_exclude_by
default value of the exclude-by classifier
Definition: refiners.py:931
tracking.harvest.refiners.SaveHistogramsRefiner.name
name
cached user-defined name for this histogram
Definition: refiners.py:191
tracking.harvest.refiners.SavePullAnalysisRefiner.__init__
def __init__(self, name=None, contact=None, title_postfix=None, part_name=None, part_names=None, truth_name=None, estimate_name=None, variance_name=None, quantity_name=None, aux_names=[], unit=None, outlier_z_score=None, absolute=False, which_plots=None)
Definition: refiners.py:666
tracking.harvest.refiners.SaveHistogramsRefiner.default_check
string default_check
default user-check action for this histogram
Definition: refiners.py:183
tracking.harvest.refiners.SaveTreeRefiner.add_branch
def add_branch(self, output_ttree, part_name, parts)
Definition: refiners.py:858
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.default_name
string default_name
default name for this refiner
Definition: refiners.py:69
tracking.harvest.refiners.SaveHistogramsRefiner.contact
contact
cached user-defined contact person for this histogram
Definition: refiners.py:200
tracking.harvest.refiners.SavePullAnalysisRefiner.contact
contact
cached contact person for this pull analysis
Definition: refiners.py:672
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.default_key
string default_key
default key name for this refiner
Definition: refiners.py:79
tracking.validation.fom
Definition: fom.py:1
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.default_contact
string default_contact
default contact person for this truth-classification analysis
Definition: refiners.py:545
tracking.harvest.refiners.CdRefiner.groupby_addition
groupby_addition
cached value of the suffix for a groupby selection
Definition: refiners.py:1043
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.name
name
cached name of the figure of merit
Definition: refiners.py:95
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.truth_name
truth_name
cached truth-values-collection name for this truth-classification analysis
Definition: refiners.py:562
tracking.harvest.refiners.SavePullAnalysisRefiner.default_title_postfix
string default_title_postfix
default suffix for the title of this pull analysis
Definition: refiners.py:657
tracking.harvest.refiners.SavePullAnalysisRefiner.unit
unit
cached measurement unit for the pull analysis
Definition: refiners.py:694
tracking.harvest.refiners.SelectRefiner.__init__
def __init__(self, wrapped_refiner, select=[], exclude=[])
Definition: refiners.py:911
tracking.harvest.refiners.Plot2DRefiner.fit
fit
cached fit for this profile histogram / scatterplot
Definition: refiners.py:352
tracking.harvest.refiners.Plot2DRefiner.y_binary
y_binary
cached flag for probability y axis (range 0.0 .
Definition: refiners.py:342
tracking.harvest.refiners.GroupByRefiner.__init__
def __init__(self, wrapped_refiner, by=[], exclude_by=None)
Definition: refiners.py:933
tracking.harvest.refiners.SavePullAnalysisRefiner.default_estimate_name
string default_estimate_name
default name for the pull analysis estimates collection
Definition: refiners.py:662
tracking.harvest.refiners.SaveTreeRefiner.name
name
cached name for this TTree
Definition: refiners.py:821
tracking.validation.plot.ValidationPlot
Definition: plot.py:152
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.estimate_name
estimate_name
cached estimates-collection name for this truth-classification analysis
Definition: refiners.py:560
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.unit
unit
cached measurement unit of estimates for this truth-classification analysis
Definition: refiners.py:578
tracking.harvest.refiners.FilterRefiner.wrapped_refiner
wrapped_refiner
cached value of the wrapped refiner
Definition: refiners.py:891
tracking.harvest.refiners.SaveHistogramsRefiner.fit
fit
cached fit for this histogram
Definition: refiners.py:217
tracking.harvest.refiners.CdRefiner.refine
def refine(self, harvesting_module, crops, tdirectory=None, groupby_part_name=None, groupby_value=None, *args, **kwds)
Definition: refiners.py:1048
tracking.harvest.refiners.SaveHistogramsRefiner.fit_z_score
fit_z_score
cached fit Z-score (for outlier detection) for this histogram
Definition: refiners.py:219
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.outlier_z_score
outlier_z_score
cached Z-score (for outlier detection) of estimates for this truth-classification analysis
Definition: refiners.py:574
tracking.harvest.refiners.SelectRefiner.exclude
exclude
cached value of the exclusion flag
Definition: refiners.py:919
tracking.harvest.refiners.SavePullAnalysisRefiner.default_variance_name
string default_variance_name
default name for the pull analysis variances collection
Definition: refiners.py:664
tracking.harvest.refiners.SavePullAnalysisRefiner.truth_name
truth_name
cached name for the pull analysis truth-values collection
Definition: refiners.py:685
tracking.harvest.refiners.SaveClassificationAnalysisRefiner
Definition: refiners.py:541
tracking.harvest.refiners.Plot2DRefiner.y
y
cached value of ordinate
Definition: refiners.py:329
tracking.harvest.refiners.SavePullAnalysisRefiner.default_truth_name
string default_truth_name
default name for the pull analysis truth-values collection
Definition: refiners.py:660
tracking.harvest.refiners.SaveFiguresOfMeritRefiner.default_description
string default_description
default description for this refiner
Definition: refiners.py:75
tracking.harvest.refiners.Refiner
Definition: refiners.py:26
tracking.harvest.refiners.SelectRefiner.refine
def refine(self, harvesting_module, crops, *args, **kwds)
Definition: refiners.py:921
tracking.harvest.refiners.Plot2DRefiner.description
description
cached user-defined description for this profile histogram / scatterplot
Definition: refiners.py:320
tracking.harvest.refiners.Plot2DRefiner.has_more_than_one_value
def has_more_than_one_value(xs)
Definition: refiners.py:497
tracking.validation.plot
Definition: plot.py:1
tracking.harvest.refiners.SaveScatterRefiner
Definition: refiners.py:524
tracking.harvest.refiners.SaveTreeRefiner.refine
def refine(self, harvesting_module, crops, tdirectory=None, groupby_part_name=None, groupby_value=None, **kwds)
Definition: refiners.py:827
tracking.harvest.refiners.FilterRefiner.__init__
def __init__(self, wrapped_refiner, filter=None, on=None)
Definition: refiners.py:887
tracking.harvest.refiners.SaveHistogramsRefiner.outlier_z_score
outlier_z_score
cached Z-score (for outlier detection) for this histogram
Definition: refiners.py:210
tracking.harvest.refiners.SavePullAnalysisRefiner.name
name
cached name for this pull analysis
Definition: refiners.py:670
tracking.harvest.refiners.CdRefiner.__init__
def __init__(self, wrapped_refiner, folder_name=None, groupby_addition=None)
Definition: refiners.py:1035
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.cut_direction
cut_direction
cached cut direction (> or <) of estimates for this truth-classification analysis
Definition: refiners.py:567
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.allow_discrete
allow_discrete
cached discrete-value flag of estimates for this truth-classification analysis
Definition: refiners.py:576
tracking.harvest.refiners.SaveHistogramsRefiner.default_title
string default_title
default title for this histogram
Definition: refiners.py:177
tracking.harvest.refiners.Refiner.__call__
def __call__(self, harvesting_module, crops=None, *args, **kwds)
Definition: refiners.py:47
tracking.harvest.refiners.FilterRefiner
Definition: refiners.py:884
tracking.harvest.refiners.SelectRefiner.select
select
cached value of the selector
Definition: refiners.py:917
tracking.harvest.refiners.Plot2DRefiner.fit_z_score
fit_z_score
cached fit Z-score (for outlier detection) for this profile histogram / scatterplot
Definition: refiners.py:354
tracking.harvest.refiners.ExpertLevelRefiner.wrapped_refiner
wrapped_refiner
cached value of the wrapped refiner
Definition: refiners.py:1102
tracking.harvest.refiners.SaveHistogramsRefiner.bins
bins
cached number of bins for this histogram
Definition: refiners.py:207
tracking.harvest.refiners.SaveHistogramsRefiner
Definition: refiners.py:172
tracking.harvest.refiners.CdRefiner
Definition: refiners.py:1027
tracking.harvest.refiners.SavePullAnalysisRefiner.title_postfix
title_postfix
cached suffix for the title of this pull analysis
Definition: refiners.py:674
tracking.harvest.refiners.SavePullAnalysisRefiner.absolute
absolute
cached absolute-value-comparison flag for the pull analysis
Definition: refiners.py:702
tracking.harvest.refiners.SaveClassificationAnalysisRefiner.contact
contact
cached contact person for this truth-classification analysis
Definition: refiners.py:558