Skip to content

Commit

Permalink
Merge pull request #2269 from NNPDF/fix_yttb
Browse files Browse the repository at this point in the history
correct observable: CMS_TTBAR_13TEV_LJ_2016_DIF_YTTBAR -> YT
  • Loading branch information
RoyStegeman authored Feb 5, 2025
2 parents 2bd638c + afca9b5 commit 8896921
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black-pre-commit-mirror
rev: '24.10.0'
rev: '25.1.0'
hooks:
- id: black
args: ['--config=./pyproject.toml']

- repo: https://github.com/pycqa/isort
rev: '5.13.2'
rev: '6.0.0'
hooks:
- id: isort
args: ['--settings-path=./pyproject.toml']
11 changes: 5 additions & 6 deletions extra_tests/regression_fits/no_csr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ description: n3fit regression test
# ewk: apply ewk k-factors
# sys: systematics treatment (see systypes)
dataset_inputs:
- { dataset: NMC, frac: 0.5 }
- { dataset: SLACP, frac: 0.5}

- {dataset: NMC_NC_NOTFIXED_P_EM-SIGMARED, frac: 0.5, variant: legacy}
- {dataset: SLAC_NC_NOTFIXED_P_EM-F2, frac: 0.5, variant: legacy}

############################################################
datacuts:
Expand Down Expand Up @@ -69,12 +68,12 @@ fitting:
############################################################
positivity:
posdatasets:
- { dataset: POSF2U, maxlambda: 1e6 } # Positivity Lagrange Multiplier
- { dataset: POSDYS, maxlambda: 1e5 }
- {dataset: NNPDF_POS_2P24GEV_F2U, maxlambda: 1e6}
- {dataset: NNPDF_POS_2P24GEV_DYS, maxlambda: 1e5}

integrability:
integdatasets:
- {dataset: INTEGXT8, maxlambda: 1e2}
- {dataset: NNPDF_INTEG_3GEV_XT8, maxlambda: 1e2}

############################################################
debug: true
2 changes: 1 addition & 1 deletion n3fit/runcards/examples/nnpdf40-like.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ dataset_inputs:
- {dataset: CMS_TTBAR_5TEV_TOT_X-SEC, frac: 0.75, variant: legacy}
- {dataset: CMS_TTBAR_8TEV_2L_DIF_MTTBAR-YT-NORM, frac: 0.75, variant: legacy}
- {dataset: CMS_TTBAR_13TEV_2L_DIF_YT, frac: 0.75, variant: legacy}
- {dataset: CMS_TTBAR_13TEV_LJ_2016_DIF_YTTBAR, frac: 0.75, variant: legacy}
- {dataset: CMS_TTBAR_13TEV_LJ_2016_DIF_YT, frac: 0.75, variant: legacy}
- {dataset: CMS_SINGLETOP_7TEV_TCHANNEL-XSEC, frac: 0.75, variant: legacy}
- {dataset: CMS_SINGLETOP_8TEV_TCHANNEL-XSEC, frac: 0.75, variant: legacy}
- {dataset: CMS_SINGLETOP_13TEV_TCHANNEL-XSEC, frac: 0.75, variant: legacy}
Expand Down
2 changes: 1 addition & 1 deletion n3fit/runcards/hyperopt_studies/renew_hyperopt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ dataset_inputs:
- {dataset: CMS_TTBAR_5TEV_TOT_X-SEC, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_TTBAR_8TEV_2L_DIF_MTTBAR-YT-NORM, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_TTBAR_13TEV_2L_DIF_YT, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_TTBAR_13TEV_LJ_2016_DIF_YTTBAR, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_TTBAR_13TEV_LJ_2016_DIF_YT, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_SINGLETOP_7TEV_TCHANNEL-XSEC, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_SINGLETOP_8TEV_TCHANNEL-XSEC, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_SINGLETOP_13TEV_TCHANNEL-XSEC, frac: 0.75, cfac: [], variant: legacy}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ dataset_inputs:
- {dataset: CMS_TTBAR_5TEV_TOT_X-SEC, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_TTBAR_8TEV_2L_DIF_MTTBAR-YT-NORM, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_TTBAR_13TEV_2L_DIF_YT, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_TTBAR_13TEV_LJ_2016_DIF_YTTBAR, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_TTBAR_13TEV_LJ_2016_DIF_YT, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_SINGLETOP_7TEV_TCHANNEL-XSEC, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_SINGLETOP_8TEV_TCHANNEL-XSEC, frac: 0.75, cfac: [], variant: legacy}
- {dataset: CMS_SINGLETOP_13TEV_TCHANNEL-XSEC, frac: 0.75, cfac: [], variant: legacy}
Expand Down
5 changes: 2 additions & 3 deletions n3fit/src/n3fit/scripts/n3fit_exec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
"""
n3fit - performs fit using ml external frameworks
n3fit - performs fit using ml external frameworks
"""

import argparse
Expand All @@ -19,7 +19,7 @@
from validphys.core import FitSpec
from validphys.utils import yaml_safe

N3FIT_FIXED_CONFIG = dict(use_cuts='internal', use_t0=True, actions_=[])
N3FIT_FIXED_CONFIG = dict(use_cuts='internal', use_t0=True, actions_=[], allow_legacy_names=False)

FIT_NAMESPACE = "datacuts::theory::fitting "
CLOSURE_NAMESPACE = "datacuts::theory::closuretest::fitting "
Expand Down Expand Up @@ -159,7 +159,6 @@ def from_yaml(cls, o, *args, **kwargs):
N3FIT_FIXED_CONFIG['use_thcovmat_in_sampling'] = thconfig.get(
'use_thcovmat_in_sampling', True
)
# Fitting flag
file_content.update(N3FIT_FIXED_CONFIG)
return cls(file_content, *args, **kwargs)

Expand Down
17 changes: 17 additions & 0 deletions nnpdf_data/nnpdf_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from functools import lru_cache
import logging
import pathlib

import yaml

log = logging.getLogger(__name__)

path_vpdata = pathlib.Path(__file__).parent
path_commondata = path_vpdata / "commondata"

Expand All @@ -18,6 +21,13 @@
}


@lru_cache
def _warn_old_names():
log.warning(
"The usage of old names is deprecated and support will be dropped in future versions! Update your runcards"
)


@lru_cache
def legacy_to_new_map(dataset_name, sys=None):
"""Find the new dataset name and variant corresponding to an old dataset
Expand All @@ -35,6 +45,13 @@ def legacy_to_new_map(dataset_name, sys=None):
)
variant += f"_{sys}"

# Deprecation notice
_warn_old_names()
warn_text = f"Please change {dataset_name} to {new_name}"
if variant is None:
warn_text += f" (variant: {variant})"
log.warning(warn_text)

return new_name, variant


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bins:
- y_ttBar:
- y_t:
min: null
mid: 0.1
max: null
Expand All @@ -11,7 +11,7 @@ bins:
min: null
mid: 13000.0
max: null
- y_ttBar:
- y_t:
min: null
mid: 0.3
max: null
Expand All @@ -23,7 +23,7 @@ bins:
min: null
mid: 13000.0
max: null
- y_ttBar:
- y_t:
min: null
mid: 0.5
max: null
Expand All @@ -35,7 +35,7 @@ bins:
min: null
mid: 13000.0
max: null
- y_ttBar:
- y_t:
min: null
mid: 0.7
max: null
Expand All @@ -47,7 +47,7 @@ bins:
min: null
mid: 13000.0
max: null
- y_ttBar:
- y_t:
min: null
mid: 0.9
max: null
Expand All @@ -59,7 +59,7 @@ bins:
min: null
mid: 13000.0
max: null
- y_ttBar:
- y_t:
min: null
mid: 1.1
max: null
Expand All @@ -71,7 +71,7 @@ bins:
min: null
mid: 13000.0
max: null
- y_ttBar:
- y_t:
min: null
mid: 1.3
max: null
Expand All @@ -83,7 +83,7 @@ bins:
min: null
mid: 13000.0
max: null
- y_ttBar:
- y_t:
min: null
mid: 1.5
max: null
Expand All @@ -95,7 +95,7 @@ bins:
min: null
mid: 13000.0
max: null
- y_ttBar:
- y_t:
min: null
mid: 1.7
max: null
Expand All @@ -107,7 +107,7 @@ bins:
min: null
mid: 13000.0
max: null
- y_ttBar:
- y_t:
min: null
mid: 1.9
max: null
Expand All @@ -119,7 +119,7 @@ bins:
min: null
mid: 13000.0
max: null
- y_ttBar:
- y_t:
min: null
mid: 2.25
max: null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
setname: CMS_TTBAR_13TEV_LJ_2016_DIF
version: 1
version_comment: Port of old commondata
version: 2
version_comment: Port of old commondata, v2 corrected the observable_name
nnpdf_metadata:
nnpdf31_process: TOP
experiment: CMS
Expand All @@ -13,12 +13,12 @@ hepdata:
url: ''
version: -1
implemented_observables:
- observable_name: YTTBAR
- observable_name: YT
observable:
description: Heavy Quarks Production Single Quark Rapidity Distribution
label: CMS $t\bar{t}$ absolute $|y_t|$
units: ''
process_type: HQP_YQQ
process_type: HQP_YQ
tables: []
npoints: []
ndata: 11
Expand All @@ -27,16 +27,16 @@ implemented_observables:
y_label: $d\sigma_{t\bar{t}}/d|y_t|$ (fb)
figure_by:
- sqrts
plot_x: y_ttBar
plot_x: y_t
kinematic_coverage:
- y_ttBar
- y_t
- m_t2
- sqrts
kinematics:
variables:
y_ttBar:
description: Variable y_ttBar
label: y_ttBar
y_t:
description: Variable y_t
label: y_t
units: ''
m_t2:
description: Variable m_t2
Expand All @@ -46,7 +46,7 @@ implemented_observables:
description: Variable sqrts
label: sqrts
units: ''
file: kinematics_YTTBAR.yaml
file: kinematics_YT.yaml
theory:
conversion_factor: 0.575431971
operation: 'null'
Expand All @@ -56,6 +56,6 @@ implemented_observables:
variants:
legacy:
data_uncertainties:
- uncertainties_legacy_YTTBAR.yaml
data_central: data_legacy_YTTBAR.yaml
- uncertainties_legacy_YT.yaml
data_central: data_legacy_YT.yaml
ported_from: CMS_TTB_DIFF_13TEV_2016_LJ_TRAP
5 changes: 4 additions & 1 deletion nnpdf_data/nnpdf_data/commondata/dataset_names.yml
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ CMS_SINGLETOP_TCH_TOT_7TEV:
dataset: CMS_SINGLETOP_7TEV_TCHANNEL-XSEC
variant: legacy
CMS_TTB_DIFF_13TEV_2016_LJ_TRAP:
dataset: CMS_TTBAR_13TEV_LJ_2016_DIF_YTTBAR
dataset: CMS_TTBAR_13TEV_LJ_2016_DIF_YT
variant: legacy
POSDYS:
dataset: NNPDF_POS_2P24GEV_DYS
Expand Down Expand Up @@ -412,3 +412,6 @@ ATLAS_WJ_JET_8TEV_WM-PT:
ATLAS_WJ_JET_8TEV_WP-PT:
dataset: ATLAS_WJ_8TEV_WP-PT
variant: legacy
CMS_TTBAR_13TEV_LJ_2016_DIF_YTTBAR:
dataset: CMS_TTBAR_13TEV_LJ_2016_DIF_YT
variant: legacy
2 changes: 1 addition & 1 deletion validphys2/examples/future_test_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ dataset_inputs:
- {dataset: CMS_TTBAR_5TEV_TOT_X-SEC, custom_group: NNPDF40 datasets, cfac: [QCD], variant: legacy}
- {dataset: CMS_TTBAR_8TEV_2L_DIF_MTTBAR-YT-NORM, custom_group: NNPDF40 datasets, cfac: [QCD], variant: legacy}
- {dataset: CMS_TTBAR_13TEV_2L_DIF_YT, custom_group: NNPDF40 datasets, cfac: [QCD], variant: legacy}
- {dataset: CMS_TTBAR_13TEV_LJ_2016_DIF_YTTBAR, custom_group: NNPDF40 datasets, cfac: [QCD], variant: legacy}
- {dataset: CMS_TTBAR_13TEV_LJ_2016_DIF_YT, custom_group: NNPDF40 datasets, cfac: [QCD], variant: legacy}
- {dataset: CMS_SINGLETOP_7TEV_TCHANNEL-XSEC, custom_group: NNPDF40 datasets, cfac: [QCD], variant: legacy}
- {dataset: CMS_SINGLETOP_8TEV_TCHANNEL-XSEC, custom_group: NNPDF40 datasets, cfac: [QCD], variant: legacy}
- {dataset: CMS_SINGLETOP_13TEV_TCHANNEL-XSEC, custom_group: NNPDF40 datasets, cfac: [QCD], variant: legacy}
Expand Down
22 changes: 18 additions & 4 deletions validphys2/src/validphys/commondataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from validobj import ValidationError, parse_input
from validobj.custom import Parser

from nnpdf_data import new_to_legacy_map, path_commondata
from nnpdf_data import legacy_to_new_map, new_to_legacy_map, path_commondata
from nnpdf_data.utils import parse_yaml_inp
from validphys.coredata import KIN_NAMES, CommonData
from validphys.plotoptions.plottingoptions import PlottingOptions, labeler_functions
Expand Down Expand Up @@ -819,9 +819,23 @@ def select_observable(self, obs_name_raw):
try:
observable = self.allowed_observables[obs_name]
except KeyError:
raise ValueError(
f"The selected observable {obs_name_raw} does not exist in {self.setname}"
)
std_err = f"The selected observable {obs_name_raw} does not exist in {self.setname}"
# If the error is due to the usage of an old name, give some extra information
name = f"{self.setname}_{obs_name_raw}"
new_name, map_variant = legacy_to_new_map(name, None)
if new_name == name:
# It was just a mistake, raise the original error
raise ValueError(std_err)
if map_variant is None:
dinput_str = f"- {{ dataset: {new_name} }}"
else:
dinput_str = f"- {{ dataset: {new_name}, variant: {map_variant} }}"
std_err += f"""
It might be that you used an older name for the dataset: '{name}'.
If this is a mistake, please use '{new_name}' instead. E.g.,
{dinput_str}
"""
raise ValueError(std_err)

# Now burn the _parent key into the observable and apply checks
object.__setattr__(observable, "_parent", self)
Expand Down
24 changes: 12 additions & 12 deletions validphys2/src/validphys/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def produce_fitpdfandbasis(self, fitpdf, basisfromfit):
return {**fitpdf, **basisfromfit}

@element_of("dataset_inputs")
def parse_dataset_input(self, dataset: Mapping):
def parse_dataset_input(self, dataset: Mapping, allow_legacy_names: bool = True):
"""The mapping that corresponds to the dataset specifications in the fit files
This mapping is such that
Expand Down Expand Up @@ -458,17 +458,17 @@ def parse_dataset_input(self, dataset: Mapping):
if variant is not None and sysnum is not None:
raise ConfigError(f"The 'variant' and 'sys' keys cannot be used together ({name})")

# The old->new name can be used for two reasons:
# 1. To use the old names, in that case one recieves a name and, maybe a variant
# 2. To correct a wrong (but new-style) name.
# In both cases the varaint is overwritten if and only if the variant is None
name, map_variant = legacy_to_new_map(name, sysnum)
# legacy_dw trumps everything
if variant is None or map_variant == "legacy_dw":
variant = map_variant

if sysnum is not None:
log.warning("The key 'sys' is deprecated and will soon be removed")
# The old -> new name mapping can only be used with allow_legacy_names = True
# which from 4.1 will default to False.
# It can be used in order to be able to use old runcard but it is not recommended.
if allow_legacy_names:
name, map_variant = legacy_to_new_map(name, sysnum)
# legacy_dw trumps everything
if variant is None or map_variant == "legacy_dw":
variant = map_variant

if sysnum is not None:
log.warning("The key 'sys' is deprecated and will soon be removed")

return DataSetInput(
name=name,
Expand Down
Loading

0 comments on commit 8896921

Please sign in to comment.