Skip to content
Closed
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
33 changes: 0 additions & 33 deletions doc/sphinx/source/vp/theorycov/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,39 +154,6 @@ a comprehensive set of plots and tables describing the covariance matrices.
{@plot_diag_cov_comparison@}
{@endwith@}

Experimental $\chi^2$
---------------------
{@with default_theory@}
{@total_experiments_chi2@}

Total (exp. + th.) $\chi^2$
---------------------------
{@chi2_impact_custom@}

Experimental $\chi^2$ by dataset
--------------------------------
{@experiments_chi2_table@}

Total (exp. + th.) $\chi^2$ by dataset
--------------------------------------
{@experiments_chi2_table_theory@}

$\chi^2$ including only diagonal theory elements
------------------------------------------------
{@chi2_diag_only@}

Impact of theory covariance matrix on $\chi^2$s
-----------------------------------------------
{@plot_datasets_chi2_theory@}
{@endwith@}

Scale variations as a function of the kinematics
------------------------------------------------
{@with matched_datasets_from_dataspecs@}
[Plots for {@dataset_name@}]({@dataset_report report@})
{@endwith@}


Validation report
-----------------

Expand Down
32 changes: 0 additions & 32 deletions validphys2/examples/theory_covariance/template_matrix_plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,3 @@ Diagonal elements of covariance matrices
{@with default_theory@}
{@plot_diag_cov_comparison@}
{@endwith@}

Experimental $\chi^2$
---------------------
{@with default_theory@}
{@total_chi2_per_point_data@}

Total (exp. + th.) $\chi^2$
---------------------------
{@chi2_impact_custom@}

Experimental $\chi^2$ by dataset
--------------------------------
{@procs_chi2_table@}

Total (exp. + th.) $\chi^2$ by dataset
--------------------------------------
{@procs_chi2_table_theory@}

$\chi^2$ including only diagonal theory elements
------------------------------------------------
{@chi2_diag_only@}

Impact of theory covariance matrix on $\chi^2$s
-----------------------------------------------
{@plot_datasets_chi2_theory@}
{@endwith@}

Scale variations as a function of the kinematics
------------------------------------------------
{@with matched_datasets_from_dataspecs@}
[Plots for {@dataset_name@}]({@dataset_report report@})
{@endwith@}
42 changes: 41 additions & 1 deletion validphys2/src/validphys/pdfgrids.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def distance_grids(pdfs, xplotting_grids, normalize_to: (int, str, type(None)) =
This method returns distance grids where the relative distance between both PDF
set is computed. At least one grid will be identical to zero.
"""

gr2_stats = xplotting_grids[normalize_to].grid_values
cv2 = gr2_stats.central_value()
sg2 = gr2_stats.std_error()
Expand Down Expand Up @@ -374,6 +374,46 @@ def distance_grids(pdfs, xplotting_grids, normalize_to: (int, str, type(None)) =

return newgrids

@check_pdf_normalize_to
def pull_grids(pdfs, xplotting_grids, normalize_to: (int, str, type(None)) = None):
"""Return an object containing the value of the distance PDF at the specified values
of x and flavour.

The parameter ``normalize_to`` identifies the reference PDF set with respect to the
distance is computed.

This method returns distance grids where the relative distance between both PDF
set is computed. At least one grid will be identical to zero.
"""

gr2_stats = xplotting_grids[normalize_to].grid_values
cv2 = gr2_stats.central_value()
sg2 = gr2_stats.std_error()
N2 = pdfs[normalize_to].get_members()

newgrids = []
for grid, pdf in zip(xplotting_grids, pdfs):
if pdf == pdfs[normalize_to]:
# Zero the PDF we are normalizing against
pdf_zero = pdf.stats_class(np.zeros_like(gr2_stats.data[0:1]))
newgrid = grid.copy_grid(grid_values=pdf_zero)
newgrids.append(newgrid)
continue

g_stats = grid.grid_values
cv1 = g_stats.central_value()
sg1 = g_stats.std_error()
N1 = pdf.get_members()

# Wrap the distance into a Stats (1, flavours, points)
distance = Stats([np.sqrt((cv1 - cv2) ** 2 / (sg1**2 + sg2**2))])

newgrid = grid.copy_grid(grid_values=distance)
newgrids.append(newgrid)

return newgrids

pull_grids_list = collect(pull_grids, ('pdfs_list',))

@check_pdf_normalize_to
def variance_distance_grids(pdfs, xplotting_grids, normalize_to: (int, str, type(None)) = None):
Expand Down
99 changes: 99 additions & 0 deletions validphys2/src/validphys/pdfplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,106 @@ def plot_pdf_uncertainties(
PDF's central value is plotted. Otherwise it is the absolute values."""
yield from UncertaintyPDFPlotter(pdfs, xplotting_grids, xscale, normalize_to, ymin, ymax)

class PullPDFPlotter(metaclass=abc.ABCMeta):
"""Auxiliary class which groups multiple pulls in one plot."""

def __init__(self, pdfs_list, pull_grids_list, xscale, normalize_to, ymin, ymax):
self.pdfs_list = pdfs_list
self.pull_grids_list = pull_grids_list
self._xscale = xscale
self.normalize_to = normalize_to
self.ymin = ymin
self.ymax = ymax
self.firstgrid = pull_grids_list[0][0]

def legend(self, flstate):
return flstate.ax.legend()

def get_ylabel(self):
return "Pull"

@property
def Q(self):
return self.firstgrid.Q

@property
def xscale(self):
if self._xscale is None:
return scale_from_grid(self.firstgrid)
return self._xscale

def get_title(self, flstate):
return '$%s$' % flstate.parton_name + f', Q={self.Q : .1f} GeV'

def draw(self, pdfs, grid, flstate):
ax = flstate.ax
flindex = flstate.flindex
color = ax._get_lines.get_next_color()

# The grid for the distance is (1, flavours, points)
# take only the flavour we are interested in
gv = grid.select_flavour(flindex).grid_values.data.squeeze()

ax.plot(grid.xgrid, gv, color=color, label = f'{pdfs[0].label}-{pdfs[1].label} pull')

return gv

def plot_call(self):
basis = self.firstgrid.basis
for flindex, fl in enumerate(self.firstgrid.flavours):
fig, ax = plotutils.subplots()
parton_name = basis.elementlabel(fl)
flstate = FlavourState(flindex=flindex, fl=fl, fig=fig, ax=ax, parton_name=parton_name)
ax.set_title(self.get_title(flstate))

all_vals = []
for pdf, grids in zip(self.pdfs_list, self.pull_grids_list):
limits = self.draw([pdf['pdfs'][0],pdf['pdfs'][1]], grids[1], flstate)
if limits is not None:
all_vals.append(np.atleast_2d(limits))

# Note these two lines do not conmute!
ax.set_xscale(self.xscale)
plotutils.frame_center(ax, self.firstgrid.xgrid, np.concatenate(all_vals))
if self.ymin is not None:
ax.set_ylim(ymin=self.ymin)
if self.ymax is not None:
ax.set_ylim(ymax=self.ymax)

ax.set_xlabel('$x$')
ax.set_xlim(self.firstgrid.xgrid[0])

ax.set_ylabel(self.get_ylabel())

ax.set_axisbelow(True)

self.legend(flstate)
yield fig, parton_name

def __call__(self):
for fig, parton_name in self.plot_call():
ax = fig.get_axes()[0]
ymin, _ = ax.get_ylim()
ax.set_ylim(max(0, ymin), None)
yield fig, parton_name


@figuregen
@check_scale('xscale', allow_none=True)
def plot_pdf_pulls(
pdfs_list,
pull_grids_list,
xscale: (str, type(None)) = None,
normalize_to: (int, str, type(None)) = None,
ymin=None,
ymax=None,
):
"""Plot the PDF standard deviations as a function of x.
If normalize_to is set, the ratio to that
PDF's central value is plotted. Otherwise it is the absolute values."""
yield from PullPDFPlotter(pdfs_list, pull_grids_list, xscale, normalize_to, ymin, ymax)()


class AllFlavoursPlotter(PDFPlotter):
"""Auxiliary class which groups multiple PDF flavours in one plot."""

Expand Down
Loading