extractor#

class coffea.lookup_tools.extractor[source]#

Bases: object

This class defines a common entry point for defining functions that extract the inputs to build lookup tables from various kinds of files.

The files that can be converted are presently defined in the “file_converters” dict.

The file names are used to determine the converter that is used, i.e.:

something.TYPE.FORMAT will apply the TYPE extractor to a file of given FORMAT

If there is no file type specifier the ‘default’ value is used.

The extractor class supports a number of useful file formats by default:
  • .histo.root : 1,2, and 3 dimensional histograms in root files.

  • .histo.json : N-dimensional histograms stored in JSON format.

  • .ea.txt : CMS EGM effective area text files.

  • ‘.[jec, jersf, jr, junc].txt’ : CMS JME jet energy corrections and systematic error text files.

It is possible to extend the functionality of lookup_tools.extractor by editing coffea.lookup_tools.file_converters to add new types and formats.

You can add sets of lookup tables / weights by calling:

extractor.add_weight_set(<description>)

<description> is formatted like ‘<nickname> <name-in-file> <the file to extract>’

* can be used as a wildcard to import all available lookup tables in a file

Methods Summary

add_weight_set(local_name, thetype, weights)

Adds one extracted weight to the extractor.

add_weight_sets(weightsdescs)

Add multiple weight sets at once, coming from one or more files.

extract_from_file(thefile, name)

Import a file and then extract a lookup set

finalize([reduce_list])

Stop any further imports and, if requested, pare down the stored histograms to those specified in reduce_list.

import_file(thefile)

Cache the whole contents of a file for later processing

make_evaluator()

Produce an evaluator based on the finalized extractor

Methods Documentation

add_weight_set(local_name, thetype, weights)[source]#

Adds one extracted weight to the extractor.

Parameters:
  • local_name (str) – The name of the weight.

  • thetype (str) – The type of weight (eg: jme_standard_function).

  • weights (Varies) – The weights themselves. Type and structure depends on thetype.

add_weight_sets(weightsdescs)[source]#

Add multiple weight sets at once, coming from one or more files.

Parameters:

weightsdescs (Iterable[str]) – Expects a list of text lines to be formatted as ‘<local name> <name> <weights file>’. Allows * * <file> and <prefix> * <file> to do easy imports of whole file.

extract_from_file(thefile, name)[source]#

Import a file and then extract a lookup set

Parameters:
  • thefile (str) – The path to the file to import

  • name (str) – The name of the weights to extract, as named in the file

finalize(reduce_list=None)[source]#

Stop any further imports and, if requested, pare down the stored histograms to those specified in reduce_list.

Parameters:

reduce_list (list[str] or None, optional) – Reduce the weights contained in this extractor to only those with names in reduce_list. If not provided, no such reduction takes place.

import_file(thefile)[source]#

Cache the whole contents of a file for later processing

Parameters:

thefile (str) – The path to the file to be imported

make_evaluator()[source]#

Produce an evaluator based on the finalized extractor

Return type:

An evaluator based on the names, weight types, and weights of the finalized extractor.