Belle II Software  release-08-01-10
HarvestingModule Class Reference
Inheritance diagram for HarvestingModule:
Collaboration diagram for HarvestingModule:

Public Member Functions

def __init__ (self, foreach, output_file_name, name=None, title=None, contact=None, expert_level=None, show_results=False)
 
def id (self)
 
def initialize (self)
 
def event (self)
 
def terminate (self)
 
def barn (self)
 
def gather (self)
 
def prepare (self)
 
def peel (self, crop)
 
def pick (self, crop)
 
def refine (self, crops)
 

Static Public Member Functions

def create_crop_part_collection ()
 
def iter_store_obj (store_obj)
 

Public Attributes

 foreach
 Name of the StoreArray or iterable StoreObjPtr that contains the objects to be harvested.
 
 output_file_name
 Name of the ROOT output file to be generated.
 
 title
 Name of this harvest. More...
 
 contact
 Contact email address to be displayed on the validation page.
 
 expert_level
 Integer expert level that controlls to detail of plots to be generated.
 
 refiners
 A list of additional refiner instances to be executed on top of the refiner methods that are members of this class.
 
 show_results
 Switch to show the result ROOT file in a TBrowser on terminate.
 
 stash
 stash of the harvested crops (start with those in the barn)
 
 raw_crops
 the dictionaries from peel as a numpy.array of doubles
 
 crops
 the dictionaries from peel
 

Static Public Attributes

int default_expert_level = 1
 The default value of expert_level if not specified explicitly by the caller.
 

Detailed Description

Python module to generate summary figures of merits, plots and/or trees
from on StoreArray.

It runs as a proper module in the main path and examines each object in a StoreArray
in each event.


Notes
-----
Methods to be overwritten
``prepare``
    Method called at the start of each event, that may prepare things
    (e.g. setup lookup tables or precomputed list) used in the following methods.
``pick``
    Method called with each object in the StoreArray.
    Returns a False value if the object should be skipped.

``peel``
    Method called with each object in the StoreArray.
    Extractes the parts relevant for analysis and
    returns them as MutableMapping (e.g. a dict) of part_name and values.
    Currently only float values or values convertable to floats are supported.
    If requested that can change in the future.

On termination all the collected values are recasted to numpy arrays and
the whole ``crops`` of the harvest are casted to MutableMapping of numpy.array
with the same part_name and the same MutableMapping class as returned from peel.

Also in the termination phase refiners a invoked with the aggregated crops.
Refiners can be given in two ways.

First way is as a class methods marked as refiners like

    @refiners.Refiner
    def plot(self, crops, tdirectory, **kwds):
        ...

where self is the module instance, crops is the MutableMapping of numpy arrays and tdirectory
is the current tdirectory to which the current output shall be written.
The additional kwds leave room for future additional arguments.

Second way is to define the refiner method (like plot) out of line and add it to
the harvesting module instance refiners list like harvesting_module.refiners.append(plot).

Other specialised decorators to mark a function as a Refiner such as

* refiners.filter
* refiners.select
* refiners.groupby

exist.

Predefined refiner functions exist in the refiners python module as well.
For instance

    save_tree = refiners.save_tree()

is a predefined method to output the MutableMapping of numpy arrays as a TTree.

Definition at line 95 of file harvesting.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  foreach,
  output_file_name,
  name = None,
  title = None,
  contact = None,
  expert_level = None,
  show_results = False 
)
Constructor of the harvesting module.

Parameters
----------
foreach : string
    Name of a StoreArray, which objects should be investigated
output_file_name : string
    Name of the ROOT file to which the results should be written.
    Giving an opened ROOT file is also allowed.
    If None is given write to the current ROOT file.
name : string, optional
    Name of the harvest that is used in the names of ROOT plots and trees.
    Defaults to the class name.
title : string, optional
    Name of the harvest that is used in the title of ROOT plots and trees.
    Defaults to the name.
contact : string, optional
    Contact email adress to be used in the validation plots contact. Defaults to None.
expert_level : int, optional
    Expert level that can be used to switch on more plots.
    Generally the higher the more detailed to analysis.
    Meaning depends entirely on the subclass implementing a certain policy.
    Defaults to default_expert_level.
show_results : bool, optional
   Indicator to show the refined results at termination of the path

Reimplemented in QueueHarvester.

Definition at line 160 of file harvesting.py.

Member Function Documentation

◆ barn()

def barn (   self)
Coroutine that receives the dictionaries of names and values from peel and store them.

Reimplemented in PickleHarvestingModule.

Definition at line 289 of file harvesting.py.

◆ create_crop_part_collection()

def create_crop_part_collection ( )
static
Create the storing objects for the crop values

Currently a numpy.array of doubles is used to store all values in memory.

Definition at line 281 of file harvesting.py.

◆ event()

def event (   self)
Event method of the module

* Does invoke the prepare method before the iteration starts.
* In each event fetch the StoreArray / iterable StoreObjPtr,
* Iterate through all instances
* Feed each instance to the pick method to deside it the instance is relevant
* Forward it to the peel method that should generated a dictionary of values
* Store each dictionary of values

Definition at line 241 of file harvesting.py.

◆ gather()

def gather (   self)
Iterator that yield the instances form the StoreArray / iterable StoreObj.

Yields
------
Object instances from the StoreArray, iterable StoreObj or the StoreObj itself
in case it is not iterable.

Definition at line 334 of file harvesting.py.

◆ id()

def id (   self)
Working around that name() is a method.

Exposing the name as a property using a different name

Definition at line 226 of file harvesting.py.

◆ initialize()

def initialize (   self)
Initialisation method of the module.

Prepares the receiver stash of objects to be harvestered.

Definition at line 233 of file harvesting.py.

◆ iter_store_obj()

def iter_store_obj (   store_obj)
static
Obtain a iterator from a StoreObj

Repeatly calls iter(store_obj) or store_obj.__iter__()
until the final iterator returns itself

Returns
-------
iterator of the StoreObj

Definition at line 452 of file harvesting.py.

◆ peel()

def peel (   self,
  crop 
)
Unpack the the instances and return and dictionary of names to values or
a generator of those dictionaries to be saved.

Returns
-------
dict(str -> float)
    Unpacked names and values
or

Yields
------
dict(str -> float)
    Unpacked names and values

Reimplemented in SummarizeTriggerVariables, WrongRLInfoCounter, ReconstructionPositionHarvester, SummarizeTriggerResults, VxdCdcMergerHarvesterPRSide, VxdCdcPartFinderHarvester, MCTrajectoryHarvester, VxdCdcMergerHarvester, MCParticleHarvester, VxdCdcMergerHarvesterMCSide, SegmentFinderParameterExtractorModule, SegmentFakeRatesModule, FitValidationModule, and SeedsAnalyser.

Definition at line 380 of file harvesting.py.

◆ pick()

def pick (   self,
  crop 
)
Indicate whether the instance should be forwarded to the peeling

Returns
-------
bool : Indicator if the instance is valueable in the current harverst.

Reimplemented in VxdCdcMergerHarvester, MCParticleHarvester, and VxdCdcMergerHarvesterMCSide.

Definition at line 398 of file harvesting.py.

◆ prepare()

def prepare (   self)
Default implementation of prepare.

Can be overridden by subclasses.

Reimplemented in FitValidationModule, and SegmentFakeRatesModule.

Definition at line 373 of file harvesting.py.

◆ refine()

def refine (   self,
  crops 
)
Receive the gathered crops and forward them to the refiners.

Reimplemented in PickleHarvestingModule.

Definition at line 407 of file harvesting.py.

◆ terminate()

def terminate (   self)
Termination method of the module.

Finalize the collected crops.
Start the refinement.

Definition at line 265 of file harvesting.py.

Member Data Documentation

◆ title

title

Name of this harvest.

Title particle of this harvest

Definition at line 210 of file harvesting.py.


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