Skip to content

Commit

Permalink
combine limits at more lower levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Radonirinaunimi committed Apr 18, 2024
1 parent 6fc3388 commit f06b519
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
12 changes: 6 additions & 6 deletions validphys2/src/validphys/dataplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from validphys.coredata import KIN_NAMES
from validphys.plotoptions.core import get_info, kitable, transform_result
from validphys.results import chi2_stat_labels, chi2_stats
from validphys.sumrules import POL_LIMS, polarized_sum_rules
from validphys.sumrules import POL_LIMS, partial_polarized_sum_rules
from validphys.utils import sane_groupby_iter, scale_from_grid, split_ranges

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -980,19 +980,19 @@ def _compute_ellipse(preds_x, preds_y, nstd=3):


@figure
def plot_polarized_momentum(pdf, Q, polarized_sum_rules, angular_momentum=False):
def plot_polarized_momentum(pdf, Q, partial_polarized_sum_rules, angular_momentum=False):
"""
Plot the correlated uncertainties for the truncated integrals of the polarized
gluon and singlet distributions.
"""
((xmina, xmaxa), (xminb, xmaxb)) = POL_LIMS
predictions = polarized_sum_rules[-1] # large-x
predictions = partial_polarized_sum_rules[-1] # large-x

if not angular_momentum:
xpreds = np.array(predictions["g"])
ypreds = np.array(predictions["singlet"]) / 2.0
else:
preds_low_x = polarized_sum_rules[0] # small-x
preds_low_x = partial_polarized_sum_rules[0] # small-x
xpreds = np.array(predictions["g"]) + np.array(predictions["singlet"]) / 2.0
xpreds = 1 / 2 - xpreds # substract the proton spin
ypreds = -(np.array(preds_low_x["g"]) + np.array(preds_low_x["singlet"]) / 2.0)
Expand Down Expand Up @@ -1051,11 +1051,11 @@ def plot_polarized_momentum(pdf, Q, polarized_sum_rules, angular_momentum=False)


@figure
def plot_orbital_momentum(pdf, Q, polarized_sum_rules):
def plot_orbital_momentum(pdf, Q, partial_polarized_sum_rules):
"""In addition to plotting the correlated spin moments as in `plot_polarized_momentum`,
it also plots the contributions from the Orbital Angular Momentum.
"""
return plot_polarized_momentum(pdf, Q, polarized_sum_rules, angular_momentum=True)
return plot_polarized_momentum(pdf, Q, partial_polarized_sum_rules, angular_momentum=True)


@figuregen
Expand Down
25 changes: 15 additions & 10 deletions validphys2/src/validphys/sumrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,30 @@ def _combine_limits(res: list[dict]):
return {k: np.sum([v[k] for v in res], axis=0) for k in res[0].keys()}


@check_positive('Q')
def partial_polarized_sum_rules(pdf: PDF, Q: numbers.Real, lims: tuple = POL_LIMS):
"""Compute the partial low- and large-x polarized sum rules. Return a SumRulesGrid
object with the list of values for each sum rule. The integration is performed with
absolute and relative tolerance of 1e-4."""
lpdf = pdf.load()
return _sum_rules(POLARIZED_SUM_RULES, lpdf, Q, lims=lims)


@check_positive('Q')
def sum_rules(pdf: PDF, Q: numbers.Real):
"""Compute the momentum, uvalence, dvalence, svalence and cvalence sum rules for
each member, at the energy scale ``Q``.
Return a SumRulesGrid object with the list of values for each sum rule.
The integration is performed with absolute and relative tolerance of 1e-4."""
lpdf = pdf.load()
return _sum_rules(KNOWN_SUM_RULES, lpdf, Q)
return _combine_limits(_sum_rules(KNOWN_SUM_RULES, lpdf, Q))


@check_positive('Q')
def polarized_sum_rules(pdf: PDF, Q: numbers.Real, lims: tuple = POL_LIMS):
"""Compute the polarized sum rules. Return a SumRulesGrid object with the list of
values for each sum rule. The integration is performed with absolute and relative
tolerance of 1e-4."""
lpdf = pdf.load()
return _sum_rules(POLARIZED_SUM_RULES, lpdf, Q, lims=lims)
def polarized_sum_rules(partial_polarized_sum_rules):
"""Compute the full polarized sum rules. The integration is performed with absolute
and relative tolerance of 1e-4."""
return _combine_limits(partial_polarized_sum_rules)


@check_positive('Q')
Expand All @@ -194,12 +201,11 @@ def unknown_sum_rules(pdf: PDF, Q: numbers.Real):
- T8
"""
lpdf = pdf.load()
return _sum_rules(UNKNOWN_SUM_RULES, lpdf, Q)
return _combine_limits(_sum_rules(UNKNOWN_SUM_RULES, lpdf, Q))


def _simple_description(d):
res = {}
d = _combine_limits(d)
for k, arr in d.items():
res[k] = d = {}
d["mean"] = np.mean(arr)
Expand All @@ -212,7 +218,6 @@ def _simple_description(d):

def _err_mean_table(d, polarized=False):
res = {}
d = _combine_limits(d)
for k, arr in d.items():
res[k] = d = {}
d["mean"] = np.mean(arr)
Expand Down

0 comments on commit f06b519

Please sign in to comment.