tdub.rex¶
A module for parsing TRExFitter results and producing additional plots/tables.
Class Summary¶
|
Fit parameter description as a dataclass. |
Function Summary¶
|
Get a list of available regions from a TRExFitter result directory. |
|
Get prefit \(\chi^2\) information from TRExFitter region. |
|
Generate nicely formatted text for \(\chi^2\) information. |
|
Compare nuisance parameter info between two fits. |
|
Compare uncertainty between two fits. |
|
Summarize a comparison of two fits. |
|
Get the histogram for the Data in a region from a TRExFitter result. |
|
Calculate difference between two fit parameters. |
|
Calculate difference of a POI between two results directories. |
|
Retrieve a parameter from fit result text file. |
|
Construct an axis label from metadata table. |
|
Construct a piece of text based on the region and fit stage. |
|
Extract a specific nuisance parameter from a fit. |
|
Extract a list of nuisance parameter impacts from a fit. |
|
Construct a DataFrame to organize impact plot ingredients. |
|
Plot the top 20 nuisance parameters based on impact. |
|
Plot all regions discovered in a TRExFitter result directory. |
|
Free (multiprocessing compatible) function to plot a region + stage. |
|
Get the prefit total MC prediction and uncertainty band for a region. |
|
Get a prefit histogram from a file. |
|
Retrieve sample prefit histograms for a region. |
|
Fix parameter label to look nice for plots. |
|
Check if TRExFitter result directory contains postFit information. |
|
Get the postfit total MC prediction and uncertainty band for a region. |
|
Get a postfit histogram from a file. |
|
Retrieve sample postfit histograms for a region. |
|
Perform a battery of standard stability tests. |
Perform a battery of parton shower impact stability tests. |
|
|
Create a pre- or post-fit plot canvas for a TRExFitter region. |
Reference¶
-
class
tdub.rex.
FitParam
(name='', label='', pre_down=0.0, pre_up=0.0, post_down=0.0, post_up=0.0, central=0.0, sig_lo=0.0, sig_hi=0.0, post_max=0.0)[source]¶ Fit parameter description as a dataclass.
-
tdub.rex.
available_regions
(rex_dir)[source]¶ Get a list of available regions from a TRExFitter result directory.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory
- Returns
Regions discovered in the TRExFitter result directory.
- Return type
-
tdub.rex.
chisq
(rex_dir, region, stage='pre')[source]¶ Get prefit \(\chi^2\) information from TRExFitter region.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory
region (str) – TRExFitter region name.
stage (str) – Drawing fit stage, (‘pre’ or ‘post’).
- Returns
-
tdub.rex.
chisq_text
(rex_dir, region, stage='pre')[source]¶ Generate nicely formatted text for \(\chi^2\) information.
Deploys
tdub.rex.chisq()
for grab the info.- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory
region (str) – TRExFitter region name.
stage (str) – Drawing fit stage, (‘pre’ or ‘post’).
- Returns
Formatted string showing the \(\chi^2\) information.
- Return type
-
tdub.rex.
compare_nuispar
(name, rex_dir1, rex_dir2, label1=None, label2=None, np_label=None, print_to=None)[source]¶ Compare nuisance parameter info between two fits.
- Parameters
name (str) – Name of the nuisance parameter.
rex_dir1 (str or os.PathLike) – Path of the first TRExFitter result directory.
rex_dir2 (str or os.PathLike) – Path of the second TRExFitter result directory.
label1 (str, optional) – Define label for the first fit (defaults to rex_dir1).
label2 (str, optional) – Define label for the second fit (defaults to rex_dir2).
np_label (str, optional) – Give the nuisance parameter a label other than its name.
print_to (io.TextIOBase, optional) – Where to print results (defaults to sys.stdout).
-
tdub.rex.
compare_uncertainty
(rex_dir1, rex_dir2, fit_name1='tW', fit_name2='tW', label1=None, label2=None, poi='SigXsecOverSM', print_to=None)[source]¶ Compare uncertainty between two fits.
- Parameters
rex_dir1 (str or os.PathLike) – Path of the first TRExFitter result directory.
rex_dir2 (str or os.PathLike) – Path of the second TRExFitter result directory.
fit_name1 (str) – Name of the first fit.
fit_name2 (str) – Name of the second fit.
label1 (str, optional) – Define label for the first fit (defaults to rex_dir1).
label2 (str, optional) – Define label for the second fit (defaults to rex_dir2).
poi (str) – Name of the parameter of interest.
print_to (io.TextIOBase, optional) – Where to print results (defaults to sys.stdout).
-
tdub.rex.
comparison_summary
(rex_dir1, rex_dir2, fit_name1='tW', fit_name2='tW', label1=None, label2=None, fit_poi='SigXsecOverSM', nuispars=None, nuispar_labels=None, print_to=None)[source]¶ Summarize a comparison of two fits.
- Parameters
rex_dir1 (str or os.PathLike) – Path of the first TRExFitter result directory.
rex_dir2 (str or os.PathLike) – Path of the second TRExFitter result directory.
fit_name1 (str) – Name of the first fit.
fit_name2 (str) – Name of the second fit.
label1 (str, optional) – Define label for the first fit (defaults to rex_dir1).
label2 (str, optional) – Define label for the second fit (defaults to rex_dir2).
fit_poi (str) – Name of the parameter of interest.
nuispars (list(str), optional) – Nuisance parameters to compare.
nuispar_labels (list(str), optional) – Labels to give each nuisance parameter other than the default name.
print_to (io.TextIOBase, optional) – Where to print results (defaults to sys.stdout).
-
tdub.rex.
data_histogram
(rex_dir, region, fit_name='tW')[source]¶ Get the histogram for the Data in a region from a TRExFitter result.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory
region (str) – TRExFitter region name.
fit_name (str) – Name of the Fit
- Returns
Histogram for the Data sample.
- Return type
-
tdub.rex.
delta_param
(param1, param2)[source]¶ Calculate difference between two fit parameters.
- Parameters
param1 (tdub.rex.FitParam) – First fit parameter.
param2 (tdub.rex.FitParam) – Second fit parameter.
- Returns
-
tdub.rex.
delta_poi
(rex_dir1, rex_dir2, fit_name1='tW', fit_name2='tW', poi='SigXsecOverSM')[source]¶ Calculate difference of a POI between two results directories.
The default arguments will perform a calculation of \(\Delta\mu\) between two different fits. Standard error propagation is performed on both the up and down uncertainties.
- Parameters
rex_dir1 (str or os.PathLike) – Path of the first TRExFitter result directory.
rex_dir2 (str or os.PathLike) – Path of the second TRExFitter result directory.
fit_name1 (str) – Name of the first fit.
fit_name2 (str) – Name of the second fit.
poi (str) – Name of the parameter of interest.
- Returns
-
tdub.rex.
fit_parameter
(fit_file, name, prettify=False)[source]¶ Retrieve a parameter from fit result text file.
- Parameters
fit_file (pathlib.PosixPath) – Path of the TRExFitter fit result text file.
name (str) – Name of desired parameter.
prettify (bool) – Prettify the parameter label using
tdub.rex.prettify_label()
.
- Raises
ValueError – If the parameter name isn’t discovered.
- Returns
Fit parameter description.
- Return type
-
tdub.rex.
plot_all_regions
(rex_dir, outdir, stage='pre', fit_name='tW', show_chisq=True, n_test=- 1, thesis=False)[source]¶ Plot all regions discovered in a TRExFitter result directory.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory
outdir (str or os.PathLike) – Path to save resulting files to
stage (str) – Fitting stage (“pre” or “post”).
fit_name (str) – Name of the Fit
show_chisq (bool) – Print \(\chi^2\) information on ratio canvas.
n_test (int) – Maximum number of regions to plot (for quick tests).
thesis (bool) – Flag for thesis label.
-
tdub.rex.
plot_region_stage_ff
(args)[source]¶ Free (multiprocessing compatible) function to plot a region + stage.
This function is designed to be used internally by
plot_all_regions()
, where it is sent to a multiprocessing pool. Not meant for generic usage.- Parameters
args (list(Any)) – Arguments passed to
stack_canvas()
.
-
tdub.rex.
meta_axis_label
(region, bin_width, meta_table=None)[source]¶ Construct an axis label from metadata table.
- Parameters
- Returns
str – x-axis label for the region.
str – y-axis label for the region.
-
tdub.rex.
meta_text
(region, stage)[source]¶ Construct a piece of text based on the region and fit stage.
-
tdub.rex.
nuispar_impact
(rex_dir, name, label=None)[source]¶ Extract a specific nuisance parameter from a fit.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory.
name (str) – Name of the nuisance parameter.
label (str, optional) – Give the nuisance parameter a label other than its name.
- Returns
Desired nuisance parameter summary.
- Return type
-
tdub.rex.
nuispar_impacts
(rex_dir, sort=True)[source]¶ Extract a list of nuisance parameter impacts from a fit.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory.
- Returns
The nuisance parameters.
- Return type
-
tdub.rex.
nuispar_impact_plot_df
(nuispars)[source]¶ Construct a DataFrame to organize impact plot ingredients.
- Parameters
- Returns
DataFrame describing the plot ingredients.
- Return type
-
tdub.rex.
nuispar_impact_plot_top20
(rex_dir, thesis=False)[source]¶ Plot the top 20 nuisance parameters based on impact.
- Parameters
rex_dir (str, os.PathLike) – Path of the TRExFitter result directory.
thesis (: bool) – Flag for thesis label.
-
tdub.rex.
prefit_total_and_uncertainty
(rex_dir, region)[source]¶ Get the prefit total MC prediction and uncertainty band for a region.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory.
region (str) – Region to get error band for.
- Returns
tdub.root.TH1
– The total MC expectation histogram.tdub.root.TGraphAsymmErrors
– The error TGraph.
-
tdub.rex.
prefit_histogram
(root_file, sample, region)[source]¶ Get a prefit histogram from a file.
- Parameters
root_file (uproot.reading.ReadOnlyDirectory) – File containing the desired prefit histogram.
sample (str) – Physics sample name.
region (str) – TRExFitter region name.
- Returns
Desired histogram.
- Return type
-
tdub.rex.
prefit_histograms
(rex_dir, samples, region, fit_name='tW')[source]¶ Retrieve sample prefit histograms for a region.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory
samples (Iterable(str)) – Physics samples of the desired histograms
region (str) – Region to get histograms for
fit_name (str) – Name of the Fit
- Returns
Prefit histograms.
- Return type
-
tdub.rex.
prettify_label
(label)[source]¶ Fix parameter label to look nice for plots.
Replace underscores with whitespace, TeXify some stuff, remove unnecessary things, etc.
-
tdub.rex.
postfit_available
(rex_dir)[source]¶ Check if TRExFitter result directory contains postFit information.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory
- Returns
True of postFit discovered
- Return type
-
tdub.rex.
postfit_total_and_uncertainty
(rex_dir, region)[source]¶ Get the postfit total MC prediction and uncertainty band for a region.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory.
region (str) – Region to get error band for.
- Returns
tdub.root.TH1
– The total MC expectation histogram.tdub.root.TGraphAsymmErrors
– The error TGraph.
-
tdub.rex.
postfit_histogram
(root_file, sample)[source]¶ Get a postfit histogram from a file.
- Parameters
root_file (uproot.reading.ReadOnlyDirectory) – File containing the desired postfit histogram.
sample (str) – Physics sample name.
- Returns
Desired histogram.
- Return type
-
tdub.rex.
postfit_histograms
(rex_dir, samples, region)[source]¶ Retrieve sample postfit histograms for a region.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory
region (str) – Region to get histograms for
samples (Iterable(str)) – Physics samples of the desired histograms
- Returns
Postfit histograms detected in the TRExFitter result directory.
- Return type
-
tdub.rex.
stability_test_standard
(umbrella, outdir=None, tests='all')[source]¶ Perform a battery of standard stability tests.
This function expects a rigid umbrella directory structure, based on the output of results that are generated by rexpy.
- Parameters
umbrella (pathlib.PosixPath) – Umbrella directory containing all fits run via rexpy’s standard fits.
outdir (pathlib.PosixPath, optional) – Directory to save results (defaults to current working directory).
Which tests to execute. (default is “all”). The possible tests include:
"sys-drops"
, which shows the stability test for dropping some systematics."indiv-camps"
, which shows the stability test for limiting the fit to individual campaigns."regions"
, which shows the stability test for limiting the fit to subsets of the analysis regions."b0-check"
, which shows the stability test for limiting the fit to individual analysis regions and checking the B0 eigenvector uncertainty.
-
tdub.rex.
stability_test_parton_shower_impacts
(herwig704, herwig713, outdir=None)[source]¶ Perform a battery of parton shower impact stability tests.
This function expects a rigid pair of Herwig 7.0.4 and 7.1.3 directories based on the output of results that are generated by rexpy.
- Parameters
herwig704 (pathlib.PosixPath) – Path of the Herwig 7.1.4 fit results
herwig713 (pathlib.PosixPath) – Path of the Herwig 7.1.3 fit results
outdir (pathlib.PosixPath, optional) – Directory to save results (defaults to current working directory).
-
tdub.rex.
stack_canvas
(rex_dir, region, stage='pre', fit_name='tW', show_chisq=True, meta_table=None, log_patterns=None, thesis=False)[source]¶ Create a pre- or post-fit plot canvas for a TRExFitter region.
- Parameters
rex_dir (str or os.PathLike) – Path of the TRExFitter result directory.
region (str) – Region to get error band for.
stage (str) – Drawing fit stage, (“pre” or “post”).
fit_name (str) – Name of the Fit
show_chisq (bool) – Print \(\chi^2\) information on ratio canvas.
meta_table (dict, optional) – Table of metadata for labeling plotting axes.
log_patterns (list, optional) – List of region patterns to use a log scale on y-axis.
thesis (bool) – Flag for thesis label.
- Returns
matplotlib.figure.Figure
– Figure for housing the plot.matplotlib.axes.Axes
– Main axes for the histogram stack.matplotlib.axes.Axes
– Ratio axes to show Data/MC.