madminer.analysis module

class madminer.analysis.DataAnalyzer(filename, disable_morphing=False, include_nuisance_parameters=True)[source]

Bases: object

Collects common functionality that is used when analysing data in the MadMiner file.

Parameters:
filename : str

Path to MadMiner file (for instance the output of madminer.delphes.DelphesProcessor.save()).

disable_morphing : bool, optional

If True, the morphing setup is not loaded from the file. Default value: False.

include_nuisance_parameters : bool, optional

If True, nuisance parameters are taken into account. Default value: True.

Methods

event_loader(self[, start, end, batch_size, …]) Yields batches of events in the MadMiner file.
weighted_events(self[, theta, nu, …]) Returns all events together with the benchmark weights (if theta is None) or weights for a given theta.
xsec_gradients(self, thetas[, nus, events, …]) Returns the gradient of total cross sections with respect to parameters.
xsecs(self[, thetas, nus, events, …]) Returns the total cross sections for benchmarks or parameter points.
event_loader(self, start=0, end=None, batch_size=100000, include_nuisance_parameters=None, generated_close_to=None, return_sampling_ids=False)[source]

Yields batches of events in the MadMiner file.

Parameters:
start : int, optional

First event index to load

end : int or None, optional

Last event index to load

batch_size : int, optional

Batch size

include_nuisance_parameters : bool, optional

Whether nuisance parameter benchmarks are included in the returned data

generated_close_to : None or ndarray, optional

If None, this function yields all events. Otherwise, it just yields just the events that were generated at the closest benchmark point to a given parameter point.

return_sampling_ids : bool, optional

If True, the iterator returns the sampling IDs in additioin to observables and weights.

Yields:
observations : ndarray

Event data

weights : ndarray

Event weights

sampling_ids : int

Sampling IDs (benchmark used for sampling for signal events, -1 for background events). Only returned if return_sampling_ids = True was set.

weighted_events(self, theta=None, nu=None, start_event=None, end_event=None, derivative=False, generated_close_to=None)[source]

Returns all events together with the benchmark weights (if theta is None) or weights for a given theta.

Parameters:
theta : None or ndarray or str, optional

If None, the function returns all benchmark weights. If str, the function returns the weights for a given benchmark name. If ndarray, it uses morphing to calculate the weights for this value of theta. Default value: None.

nu : None or ndarray, optional

If None, the nuisance parameters are set to their nominal values. Otherwise, and if theta is an ndarray, sets the values of the nuisance parameters.

start_event : int

Index (in the MadMiner file) of the first event to consider.

end_event : int

Index (in the MadMiner file) of the last unweighted event to consider.

derivative : bool, optional

If True and if theta is not None, the derivative of the weights with respect to theta are returned. Default value: False.

Returns:
x : ndarray

Observables with shape (n_unweighted_samples, n_observables).

weights : ndarray

If theta is None and derivative is False, benchmark weights with shape (n_unweighted_samples, n_benchmarks) in pb. If theta is not None and derivative is True, the gradient of the weight for the given parameter with respect to theta with shape (n_unweighted_samples, n_gradients) in pb. Otherwise, weights for the given parameter theta with shape (n_unweighted_samples,) in pb.

xsec_gradients(self, thetas, nus=None, events='all', test_split=0.2, gradients='all', batch_size=100000, generated_close_to=None)[source]

Returns the gradient of total cross sections with respect to parameters.

Parameters:
thetas : list of (ndarray or str), optional

If None, the function returns all benchmark cross sections. Otherwise, it returns the cross sections for a series of parameter points that are either given by their benchmark name (as a str), their benchmark index (as an int), or their parameter value (as an ndarray, using morphing). Default value: None.

nus : None or list of (None or ndarray), optional

If None, the nuisance parameters are set to their nominal values (0), i.e. no systematics are taken into account. Otherwise, the list has to have the same number of elements as thetas, and each entry can specify nuisance parameters at nominal value (None) or a value of the nuisance parameters (ndarray).

test_split : float, optional

Fraction of events reserved for testing. Default value: 0.2.

events : {“train”, “test”, “all”}, optional

Which events to use. Default: “all”.

gradients : {“all”, “theta”, “nu”}, optional

Which gradients to calculate. Default value: “all”.

batch_size : int, optional

Size of the batches of events that are loaded into memory at the same time. Default value: 100000.

Returns:
xsecs_gradients : ndarray

Calculated cross section gradients in pb with shape (n_gradients,).

xsecs(self, thetas=None, nus=None, events='all', test_split=0.2, include_nuisance_benchmarks=True, batch_size=100000, generated_close_to=None)[source]

Returns the total cross sections for benchmarks or parameter points.

Parameters:
thetas : None or list of (ndarray or str), optional

If None, the function returns all benchmark cross sections. Otherwise, it returns the cross sections for a series of parameter points that are either given by their benchmark name (as a str), their benchmark index (as an int), or their parameter value (as an ndarray, using morphing). Default value: None.

nus : None or list of (None or ndarray), optional

If None, the nuisance parameters are set to their nominal values (0), i.e. no systematics are taken into account. Otherwise, the list has to have the same number of elements as thetas, and each entry can specify nuisance parameters at nominal value (None) or a value of the nuisance parameters (ndarray).

include_nuisance_benchmarks : bool, optional

Whether to include nuisance benchmarks if thetas is None. Default value: True.

test_split : float, optional

Fraction of events reserved for testing. Default value: 0.2.

events : {“train”, “test”, “all”}, optional

Which events to use. Default: “all”.

batch_size : int, optional

Size of the batches of events that are loaded into memory at the same time. Default value: 100000.

Returns:
xsecs : ndarray

Calculated cross sections in pb.

xsec_uncertainties : ndarray

Cross-section uncertainties in pb. Basically calculated as sum(weights**2)**0.5.