columnflow.histogramming#

Tools for producing histograms and event-wise weights.

Classes:

HistProducer(*args, **kwargs)

Base class for all histogram producers, i.e., functions that control the creation of histograms, event weights, and optional post-processing.

Functions:

hist_producer([func, bases, mc_only, data_only])

Decorator for creating a new HistProducer subclass with additional, optional bases and attaching the decorated function to it as call_func().

class HistProducer(*args, **kwargs)[source]#

Bases: TaskArrayFunction

Base class for all histogram producers, i.e., functions that control the creation of histograms, event weights, and optional post-processing.

create_hist_func#

type: callable

The registered function performing the custom histogram creation.

fill_hist_func#

type: callable

The registered function performing the custom histogram filling.

post_process_hist_func#

type: callable

The registered function for performing an optional post-processing of histograms before they are saved.

post_process_merged_hist_func#

type: callable

The registered function for performing an optional post-processing of histograms after they are merged.

Attributes:

Methods:

hist_producer([func, bases, mc_only, data_only])

Decorator for creating a new HistProducer subclass with additional, optional bases and attaching the decorated function to it as call_func().

create_hist(func)

Decorator to wrap a function func that should be registered as create_hist_func().

fill_hist(func)

Decorator to wrap a function func that should be registered as fill_hist_func().

post_process_hist(func)

Decorator to wrap a function func that should be registered as post_process_hist_func().

post_process_merged_hist(func)

Decorator to wrap a function func that should be registered as post_process_merged_hist_func().

run_create_hist(variables, task)

Invokes the create_hist_func() of this instance and returns its result, forwarding all arguments.

run_fill_hist(h, data, task)

Invokes the fill_hist_func() of this instance and returns its result, forwarding all arguments.

run_post_process_hist(h, task)

Invokes the post_process_hist_func() of this instance and returns its result, forwarding all arguments.

run_post_process_merged_hist(h, task)

Invokes the post_process_merged_hist_func() of this instance and returns its result, forwarding all arguments.

skip_compatibility_check = False#
exposed = True#
classmethod hist_producer(func=None, bases=(), mc_only=False, data_only=False, **kwargs)[source]#

Decorator for creating a new HistProducer subclass with additional, optional bases and attaching the decorated function to it as call_func().

When mc_only (data_only) is True, the hist producer is skipped and not considered by other task array functions in case they are evaluated on a order.Dataset (using the dataset_inst attribute) whose is_mc (is_data) attribute is False.

All additional kwargs are added as class members of the new subclasses.

Parameters:
  • func (Callable | None, default: None) – Function to be wrapped and integrated into new HistProducer class.

  • bases (tuple, default: ()) – Additional bases for the new hist producer.

  • mc_only (bool, default: False) – Boolean flag indicating that this hist producer should only run on Monte Carlo simulation and skipped for real data.

  • data_only (bool, default: False) – Boolean flag indicating that this hist producer should only run on real data and skipped for Monte Carlo simulation.

Return type:

DerivableMeta | Callable

Returns:

New hist producer subclass.

classmethod create_hist(func)[source]#

Decorator to wrap a function func that should be registered as create_hist_func(). The function should accept two arguments: :rtype: None

  • variables, a list of order.Variable instances (usually one).

  • task, the invoking task instance.

The return value of the function should be a histogram object or a container with histogram objects. The decorator does not return the wrapped function.

classmethod fill_hist(func)[source]#

Decorator to wrap a function func that should be registered as fill_hist_func(). The function should accept three arguments: :rtype: None

  • h, the histogram (or a container with histograms) to fill.

  • data, a dictionary with data to fill.

  • task, the invoking task instance.

The decorator does not return the wrapped function.

classmethod post_process_hist(func)[source]#

Decorator to wrap a function func that should be registered as post_process_hist_func(). The function should accept two arguments: :rtype: None

  • h, the histogram (or a container with histograms) to post process.

  • task, the invoking task instance.

The decorator does not return the wrapped function.

classmethod post_process_merged_hist(func)[source]#

Decorator to wrap a function func that should be registered as post_process_merged_hist_func(). The function should accept two arguments: :rtype: None

  • h, the histogram (or a container with histograms) to post process.

  • task, the invoking task instance.

The return value of the function should be a histogram object. The decorator does not return the wrapped function.

create_hist_func = None#
fill_hist_func = None#
post_process_hist_func = None#
post_process_merged_hist_func = None#
run_create_hist(variables, task)[source]#

Invokes the create_hist_func() of this instance and returns its result, forwarding all arguments.

Return type:

Any

cache_instances = True#
run_fill_hist(h, data, task)[source]#

Invokes the fill_hist_func() of this instance and returns its result, forwarding all arguments.

Return type:

None

run_post_process_hist(h, task)[source]#

Invokes the post_process_hist_func() of this instance and returns its result, forwarding all arguments.

Return type:

Any

run_post_process_merged_hist(h, task)[source]#

Invokes the post_process_merged_hist_func() of this instance and returns its result, forwarding all arguments.

hist_producer(func=None, bases=(), mc_only=False, data_only=False, **kwargs)#

Decorator for creating a new HistProducer subclass with additional, optional bases and attaching the decorated function to it as call_func().

When mc_only (data_only) is True, the hist producer is skipped and not considered by other task array functions in case they are evaluated on a order.Dataset (using the dataset_inst attribute) whose is_mc (is_data) attribute is False.

All additional kwargs are added as class members of the new subclasses.

Parameters:
  • func (Callable | None, default: None) – Function to be wrapped and integrated into new HistProducer class.

  • bases (tuple, default: ()) – Additional bases for the new hist producer.

  • mc_only (bool, default: False) – Boolean flag indicating that this hist producer should only run on Monte Carlo simulation and skipped for real data.

  • data_only (bool, default: False) – Boolean flag indicating that this hist producer should only run on real data and skipped for Monte Carlo simulation.

Return type:

DerivableMeta | Callable

Returns:

New hist producer subclass.