Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions validphys2/examples/data_theory_comparison_w_sv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
meta:
title: "Example of comparison of data and theory including scale variations"
keywords: [data theory comparison, scale variations, example runcard]
author: "Validphys examples"

use_cuts: "internal"

theoryid: 717 # define the central theory
point_prescription: "3 point"
theoryids:
from_: scale_variation_theories
use_theorycovmat: true

use_pdferr: true

disable_pdferr:
use_pdferr: false

dataset_inputs:
- { dataset: ATLASWZRAP36PB }
- { dataset: BCDMSP }

dataspecs:
- pdf: NNPDF40_nnlo_lowprecision
speclabel: "pdf1"

- pdf: Basic_runcard_3replicas_lowprec_221130
speclabel: "pdf2"

# for the chi2 comparison
pdfs:
- Basic_runcard_3replicas_lowprec_221130
- NNPDF40_nnlo_lowprecision

datanorm:
normalize_to: data

template_text: |
Plots with scale variations
===========================

{@with matched_datasets_from_dataspecs@}

{@dataset_name@}
----------------
{@ with disable_pdferr @}
{@ plot_fancy_sv_dataspecs @}
{@ datanorm plot_fancy_sv_dataspecs @}
{@ endwith @}

### chi2 distributions per PDF
{@ with dataspecs @}
{@ plot_chi2dist_sv @}
{@ endwith @}

{@ endwith @}

Plots without scale variations
==============================

{@with matched_datasets_from_dataspecs@}

{@dataset_name@}
----------------
{@ with disable_pdferr @}
{@ plot_fancy_dataspecs @}
{@ datanorm plot_fancy_dataspecs @}
{@ endwith @}

### chi2 distributions per PDF
{@ with dataspecs @}
{@ plot_chi2dist @}
{@ endwith @}

{@ endwith @}

Chi2 Report per dataset
=======================

Without scale variations
------------------------
{@plot_datasets_pdfs_chi2@}

With scale variations
---------------------
{@plot_datasets_pdfs_chi2_sv@}


actions_:
- report(main=true)
6 changes: 6 additions & 0 deletions validphys2/src/validphys/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def check_pdf_is_montecarlo_or_hessian(pdf, **kwargs):
)


@make_argcheck
def check_using_theory_covmat(use_theorycovmat):
"""Check that the `use_theorycovmat` is set to True"""
check(use_theorycovmat, "Expecting `use_theorycovmat: true`")


@make_argcheck
def check_not_using_pdferr(use_pdferr=False, **kwargs):
check(
Expand Down
49 changes: 45 additions & 4 deletions validphys2/src/validphys/dataplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from matplotlib import colors as mcolors
from matplotlib import ticker as mticker
import numpy as np
import numpy.linalg as la
import pandas as pd
import scipy.stats as stats

Expand All @@ -26,8 +25,8 @@
from validphys.checks import check_not_using_pdferr
from validphys.core import CutsPolicy, MCStats, cut_mask
from validphys.coredata import KIN_NAMES
from validphys.plotoptions import get_info, kitable, transform_result
from validphys.results import chi2_stat_labels
from validphys.plotoptions.core import get_info, kitable, transform_result
from validphys.results import chi2_stat_labels, chi2_stats
from validphys.utils import sane_groupby_iter, scale_from_grid, split_ranges

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -59,6 +58,13 @@ def plot_chi2dist(dataset, abs_chi2_data, chi2_stats, pdf):
return fig


@figure
def plot_chi2dist_sv(dataset, abs_chi2_data_thcovmat, pdf):
"""Same as ``plot_chi2dist`` considering also the theory covmat in the calculation"""
chi2_stats_thcovmat = chi2_stats(abs_chi2_data_thcovmat)
return plot_chi2dist(dataset, abs_chi2_data_thcovmat, chi2_stats_thcovmat, pdf)


def _chi2_distribution_plots(chi2_data, stats, pdf, plot_type):
fig, ax = plotutils.subplots()
label = pdf.name
Expand Down Expand Up @@ -421,7 +427,6 @@ def plot_fancy(
See docs/plotting_format.md for details on the format of the PLOTTING
files.
"""

yield from _plot_fancy_impl(
results=one_or_more_results,
commondata=commondata,
Expand Down Expand Up @@ -516,6 +521,32 @@ def plot_fancy_dataspecs(
)


@_check_same_dataset_name
@_check_dataspec_normalize_to
@figuregen
def plot_fancy_sv_dataspecs(
dataspecs_results_with_scale_variations,
dataspecs_commondata,
dataspecs_cuts,
dataspecs_speclabel,
normalize_to: (str, int, type(None)) = None,
):
"""
Exactly the same as ``plot_fancy_dataspecs`` but the theoretical results passed down
are modified so that the 1-sigma error bands correspond to a combination of the
PDF error and the scale variations collected over theoryids

See: :py:func:`validphys.results.results_with_scale_variations`
"""
return plot_fancy_dataspecs(
dataspecs_results_with_scale_variations,
dataspecs_commondata,
dataspecs_cuts,
dataspecs_speclabel,
normalize_to=normalize_to,
)


def _scatter_marked(ax, x, y, marked_dict, *args, **kwargs):
kwargs['s'] = kwargs.get('s', 30) + 10
x = np.array(x, copy=False)
Expand Down Expand Up @@ -662,6 +693,16 @@ def plot_datasets_pdfs_chi2(data, each_dataset_chi2_pdfs, pdfs):
return fig


each_dataset_chi2_sv = collect("abs_chi2_data_thcovmat", ("data",))
each_dataset_chi2_pdfs_sv = collect("each_dataset_chi2_sv", ("pdfs",))


@figure
def plot_datasets_pdfs_chi2_sv(data, each_dataset_chi2_pdfs_sv, pdfs):
"""Same as ``plot_datasets_pdfs_chi2_sv`` with the chi²s computed including scale variations"""
return plot_datasets_pdfs_chi2(data, each_dataset_chi2_pdfs_sv, pdfs)


@figure
def plot_datasets_chi2_spider(groups_data, groups_chi2):
"""Plot the chi² of all datasets with bars."""
Expand Down
Loading