Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L0 projections from command line #92

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
12 changes: 8 additions & 4 deletions docs/source/data_theory/projections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ and systematic uncertainties) as ``.yaml`` files in the standard SMEFiT format w

.. code-block:: bash

smefit PROJ --lumi <luminosity> /path/to/projection_runcard.yaml

where the desired luminosity in :math:`{\rm fb}^{-1}` can be specified by replacing ``<luminosity>``. The ``projection_runcard``
specifies which datasets need to be extrapolated, by which factor to reduce the systematics, and sets the necessary paths:
smefit PROJ --lumi <luminosity> --noise <noise level> /path/to/projection_runcard.yaml

where ``<luminosity>`` specifies the luminosity of the projection in :math:`{\rm fb}^{-1}`. The noise level ``<luminosity>``
can be either ``L0`` are ``L1`` corresponding to either level 0 or level 1 projections respectively. In level 0 projections,
the experimental central value coincides exactly with the theory prediction, while the experimental central values are fluctuated around
the theory prediction according to the experimental uncertainties in case of level 1. If ``<noise level>`` is not specified, level 0
is assumed. If ``<luminosity>`` is not specified, the original luminosities are kept and the uncertainties are not rescaled.
The ``projection_runcard`` specifies which datasets need to be extrapolated, by which factor to reduce the systematics, and sets the necessary paths:

.. code-block:: yaml

Expand Down
26 changes: 10 additions & 16 deletions src/smefit/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,24 +217,18 @@
type=float,
default=None,
required=False,
help="Adjusts the statistical uncertainties according to the specified luminosity",
help="Adjusts the statistical uncertainties according to the specified luminosity. If not specified, the original "

Check notice on line 220 in src/smefit/cli/__init__.py

View check run for this annotation

codefactor.io / CodeFactor

src/smefit/cli/__init__.py#L220

Line too long (119/100) (line-too-long)
"uncertainties are kept and the central values are fluctuates according to the specified noise level.",

Check notice on line 221 in src/smefit/cli/__init__.py

View check run for this annotation

codefactor.io / CodeFactor

src/smefit/cli/__init__.py#L221

Line too long (107/100) (line-too-long)
)
@click.option(
"--closure",
type=bool,
is_flag=True,
default=False,
help="Produces datasets under the SM",
"--noise",
type=str,
default="L0",
required=False,
help="Noise level for the projection, choose between L0 or L1. Assumes L0 by default.",
Comment on lines +224 to +228
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"--noise",
type=str,
default="L0",
required=False,
help="Noise level for the projection, choose between L0 or L1. Assumes L0 by default.",
"--noise",
type=click.Choice(["L0", "L1"], case_sensitive=True),
default="L0",
required=False,
help="Noise level for the projection, choose between L0 or L1. Assumes L0 by default.",

This should enforce that only L1 and L0 are recognised otherwise gives error, would be good to test it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the current implementation, I believe that if one gives --noise l1 with l lowercase, one would get L0 data.

)
def projection(projection_card: pathlib.Path, lumi: float, closure: bool):
def projection(projection_card: pathlib.Path, lumi: float, noise: str):
r"""Compute projection for specified dataset"""

if (lumi is not None) ^ closure:
projection_setup = Projection.from_config(projection_card)
projection_setup.build_projection(lumi, closure)
else:
print(lumi, closure)
print(
"Usage: specify exclusively either a luminosity in fb-1 after --lumi or run a SM closure test with --closure"
)
sys.exit()
projection_setup = Projection.from_config(projection_card)
projection_setup.build_projection(lumi, noise)
21 changes: 13 additions & 8 deletions src/smefit/projections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,18 @@
fred_stat = np.sqrt(lumi_old / lumi_new)
return stat * fred_stat

def build_projection(self, lumi_new, closure):
def build_projection(self, lumi_new=None, noise="L0"):

Check notice on line 186 in src/smefit/projections/__init__.py

View check run for this annotation

codefactor.io / CodeFactor

src/smefit/projections/__init__.py#L186

Too many branches (25/12) (too-many-branches)

Check notice on line 186 in src/smefit/projections/__init__.py

View check run for this annotation

codefactor.io / CodeFactor

src/smefit/projections/__init__.py#L186

Too many statements (90/50) (too-many-statements)

Check notice on line 186 in src/smefit/projections/__init__.py

View check run for this annotation

codefactor.io / CodeFactor

src/smefit/projections/__init__.py#L186

Too many local variables (36/22) (too-many-locals)
"""
Constructs runcard for projection by updating the central value and statistical and
systematic uncertainties

Parameters
----------
lumi_new: float
Adjusts the statistical uncertainties according to the specified luminosity
lumi_new: float, optional
Adjusts the statistical uncertainties according to the specified luminosity lumi_new. If not specified,

Check notice on line 194 in src/smefit/projections/__init__.py

View check run for this annotation

codefactor.io / CodeFactor

src/smefit/projections/__init__.py#L194

Line too long (115/100) (line-too-long)
the uncertainties are left unchanged and the central values are fluctuated according to the noise level

Check notice on line 195 in src/smefit/projections/__init__.py

View check run for this annotation

codefactor.io / CodeFactor

src/smefit/projections/__init__.py#L195

Line too long (115/100) (line-too-long)
noise: str
Noise level for the projection, choose between L0 or L1
closure: bool
Set to true for a L1 closure test (no rescaling, only cv gets fluctuated according to
original uncertainties)
Expand Down Expand Up @@ -266,7 +269,7 @@

th_covmat = self.datasets.ThCovMat[idxs, idxs]

if not closure:
if lumi_new is not None:
# if all stats are zero, we only have access to the total error which we rescale by 1/3 (compromise)
no_stats = not np.any(stat)
if no_stats:
Expand Down Expand Up @@ -310,8 +313,10 @@
if self.use_theory_covmat:
newcov += th_covmat

# add L1 noise to cv
cv_projection = np.random.multivariate_normal(cv[idxs], newcov)
# add Gaussian noise to central values in case of L1 and leave them unchanged in case of L0

Check notice on line 316 in src/smefit/projections/__init__.py

View check run for this annotation

codefactor.io / CodeFactor

src/smefit/projections/__init__.py#L316

Line too long (103/100) (line-too-long)
cv_projection = cv[idxs]
if noise == "L1":
cv_projection = np.random.multivariate_normal(cv[idxs], newcov)

# replace cv with updated central values
if len(cv_projection) > 1:
Expand All @@ -323,7 +328,7 @@
projection_folder.mkdir(exist_ok=True)

if projection_folder != self.commondata_path:
if not closure:
if lumi_new is not None:
with open(
f"{projection_folder}/{dataset_name}_proj.yaml", "w"
) as file:
Expand All @@ -338,7 +343,7 @@
sys.exit()

# copy corresponding theory predictions with _proj appended to filename
if not closure:
if lumi_new is not None:
shutil.copy(
self.theory_path / f"{dataset_name}.json",
self.theory_path / f"{dataset_name}_proj.json",
Expand Down
Loading