pocket_coffea.lib.weights package#
Subpackages#
Submodules#
pocket_coffea.lib.weights.test_weights_mechanism module#
pocket_coffea.lib.weights.weights module#
- class pocket_coffea.lib.weights.weights.WeightData(name: str, nominal: numpy.ndarray, up: numpy.ndarray = None, down: numpy.ndarray = None)#
Bases:
object
- down: ndarray = None#
- name: str#
- nominal: ndarray#
- up: ndarray = None#
- class pocket_coffea.lib.weights.weights.WeightDataMultiVariation(name: str, nominal: numpy.ndarray, variations: List[str], up: List[numpy.ndarray], down: List[numpy.ndarray] = None)#
Bases:
object
- down: List[ndarray] = None#
- name: str#
- nominal: ndarray#
- up: List[ndarray]#
- variations: List[str]#
- class pocket_coffea.lib.weights.weights.WeightLambda(params=None, metadata=None)#
Bases:
WeightWrapper
Class to create a weight using a lambda function. The lambda function takes as input the parameters, metadata, events, size and shape_variations.
The output can be: - WeightData or WeightDataMultiVariation object: in that case the name is overwritten by the framework - 3 arrays (nominal, up, down) -> WeightData is created - 1 array (nominal), list of variations [str] , 2 lists of arrays (up, down) -> WeightDataMultiVariation is created
- compute(events, size, shape_variation)#
Method to compute the weights for the given events. The method calls the lambda function with the given parameters. The output can be: - WeightData or WeightDataMultiVariation object: in that case the name is overwritten by the framework - 3 arrays (nominal, up, down) -> WeightData is created - 1 array (nominal), list of variations [str] , 2 lists of arrays (up, down) -> WeightDataMultiVariation is created
- class pocket_coffea.lib.weights.weights.WeightWrapper(params=None, metadata=None)#
Bases:
ABC
Base class creating a schema creating Weights for the analysis. The class allows the user to define weights with variations that depends on the params and metadata of the specific chunk. WeightWrapper instances are passed to the WeightsManager and stored. During the processing, the processor object creates a WeightsManager object which uses the WeightWrapper object to get the weights. In that step, the constructor function is called to customize the weights computation depending on the current parameters and chunk metadata (like era, year, isMC, isData..). The variations are dynamically computed by the WeightWrapper object. The variations can be customized by parameters and metadata with the WeightWrapper. Doing so different years can have different names for the variations for example. The HistManager will ask the WeightsManager to have the available weights variations for the current chunk and will store them in the output file.
The variations should be the ones available when running over the nominal shape_variation. The HistManager will ask the WeightsManager only the nominal weights when shape_variation!=”nominal”. The WeightsManager will load the WeightsWrappers, then the histManager will use the available_weight_variations to create the histogram axis.
The name class attribute is used in the configuration to define the weight. The metaclass registration mechanism checks if the user defines more than once the same weight class.
If the Weight has a single variation: has_variations = True, _variations is empty.
- abstract compute(events, size, shape_variation)#
- has_variations: ClassVar[bool] = False#
- isMC_only: ClassVar[bool] = True#
- name: ClassVar[str] = 'base_weight'#
- serialize(src_code=False)#
- property variations#
- class pocket_coffea.lib.weights.weights.WeightWrapperMeta(name, bases, clsdict)#
Bases:
ABCMeta
- get_weight_class_from_name(weight_name: str)#
Retrieve the WeightWrapper class defining the requested weight_name
- weight_classes = {}#
- wrap_func(name: str, function: Callable[[Any, int, str], Any], has_variations=False, variations=None, isMC_only=True)#
Method to create a new WeightLambda class with the given function. The lambda function takes as input the parameters, metadata, events, size and shape_variations. The output can be: - WeightData or WeightDataMultiVariation object: in that case the name is overwritten by the framework - 3 arrays (nominal, up, down) -> WeightData is created - 1 array (nominal), list of variations [str] , 2 lists of arrays (up, down) -> WeightDataMultiVariation is created
pocket_coffea.lib.weights.weights_manager module#
- class pocket_coffea.lib.weights.weights_manager.WeightsManager(params, weightsConf, weightsWrappers, metadata, storeIndividual=False)#
Bases:
object
The WeightManager class handles the weights. Both centrally defined weights and user-defined weights are handled by the WeightWrapper class.
It handles inclusive or bycategory weights for each sample. Weights can be inclusive or by category. Moreover, different samples can have different weights, as defined in the weights_configuration.
Each WeightWrapper object defines the available variation for the weights depending on the sample, datataking period and other parameters.
The configuration of samples/categories is handled by the configuration, but the availability of the weight is defined in the WeightWrapper class.
- add_weight(name, nominal, up=None, down=None, category=None)#
Add manually a weight to a specific category
- compute(events, size, shape_variation='nominal')#
Load the weights for the current chunk following the user configuration. This created different Weights objects for the inclusive and bycategory weights.
- get_available_modifiers_bycategory(category=None)#
Return the available modifiers for the specific category
- get_available_modifiers_byweight(weight: str)#
Return the available modifiers for the specific weight
- get_weight(category=None, modifier=None)#
The function returns the total weights stored in the processor for the current sample. If category==None the inclusive weight is returned. If category!=None but weights_split_bycat=False, the inclusive weight is returned. Otherwise the inclusive*category specific weight is returned. The requested variation==modifier must be available or in the inclusive weights, or in the bycategory weights.