Skip to content

Commit 4452b48

Browse files
authored
Merge pull request #161 from NNPDF/issue_160
`kfactor` maintenance and documentation
2 parents c04f55f + d33d2f9 commit 4452b48

File tree

10 files changed

+338
-421
lines changed

10 files changed

+338
-421
lines changed

benchmarks/bench_cli.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,15 @@ def benchmark_scaffold_cli(test_empty_proj):
113113
assert "Success: All the folders are correctly configured" in res.output
114114

115115

116-
def benchmark_gen_sv_cli(test_files, tmp_path, test_pdf, lhapdf_path):
116+
def benchmark_gen_sv_cli(test_files, tmp_path):
117117
runner = CliRunner()
118-
pdf_name = "NNPDF40_nlo_as_01180"
119118
max_as = "2"
120119
nf = "5"
121120
name_grid = "ATLAS_TTB_8TEV_LJ_TRAP_norensv_fixed.pineappl.lz4"
122121
grid_path = test_files / "data" / "grids" / "400" / name_grid
123122
new_grid_path = tmp_path / name_grid
124123
target_path = tmp_path
125124
shutil.copy(grid_path, new_grid_path)
126-
with lhapdf_path(test_pdf):
127-
pdf = lhapdf.mkPDF(pdf_name)
128125
res = runner.invoke(
129126
command,
130127
["ren_sv_grid", str(new_grid_path), str(target_path), max_as, nf, "False"],
@@ -134,21 +131,23 @@ def benchmark_gen_sv_cli(test_files, tmp_path, test_pdf, lhapdf_path):
134131

135132
def benchmark_kfactor_cli(test_files, tmp_path):
136133
runner = CliRunner()
137-
grid_folder = test_files / "data" / "grids" / "400"
134+
conf_file = test_files / "pineko.toml"
135+
theory_id = 400
136+
dataset = "ATLAS_TTB_FAKE"
138137
kfolder = test_files / "data" / "kfactors"
139-
fake_yaml_path = test_files / "data" / "yamldb" / "ATLAS_TTB_FAKE.yaml"
140-
max_as = "3"
138+
order_to_update = "3"
141139
target_path = tmp_path
142140
res = runner.invoke(
143141
command,
144142
[
145143
"kfactor",
146-
str(grid_folder),
144+
"-c",
145+
str(conf_file),
146+
str(theory_id),
147+
str(dataset),
147148
str(kfolder),
148-
str(fake_yaml_path),
149149
str(target_path),
150-
max_as,
151-
"False",
150+
order_to_update,
152151
],
153152
)
154-
assert "The number of bins match the lenght of the k-factor" in res.output
153+
assert "The number of bins match the length of the kfactor" in res.output

benchmarks/bench_kfactor.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
import numpy as np
33
import pineappl
44

5-
from pineko import kfactor
5+
from pineko import configs, kfactor
66

77

88
def benchmark_kfactor_inclusion(test_files, tmp_path, test_pdf, lhapdf_path):
9-
fake_yaml_path = test_files / "data" / "yamldb" / "ATLAS_TTB_FAKE.yaml"
10-
max_as = 3
9+
10+
base_configs = configs.load(test_files / "pineko.toml")
11+
configs.configs = configs.defaults(base_configs)
12+
13+
pto_to_update = 3 # here we want to update NNLO
1114
pdf_name = "NNPDF40_nnlo_as_01180"
12-
kfactor.compute_k_factor_grid(
13-
test_files / "data" / "grids" / "400",
15+
kfactor.apply_to_dataset(
16+
400,
17+
"ATLAS_TTB_FAKE",
1418
test_files / "data" / "kfactors",
15-
fake_yaml_path,
16-
max_as,
17-
target_folder=tmp_path,
19+
pto_to_update,
20+
tmp_path,
1821
)
1922
pluskfactor_grid_path = tmp_path / "ATLAS_TTB_8TEV_LJ_TRAP.pineappl.lz4"
2023
with lhapdf_path(test_pdf):
@@ -46,7 +49,7 @@ def benchmark_kfactor_inclusion(test_files, tmp_path, test_pdf, lhapdf_path):
4649
np.array([], dtype=bool),
4750
sv_list,
4851
).reshape(bin_number, len(sv_list))
49-
centrals_kfactor, _ = kfactor.read_kfactor(
52+
centrals_kfactor, _ = kfactor.read_from_file(
5053
test_files / "data" / "kfactors" / "CF_QCD_ATLAS_TTB_8TEV_LJ_TRAP.dat"
5154
)
5255
rtol = 1.0e-15

docs/source/overview/running.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ handy utility functions:
6363

6464
- applying the :doc:`FONLL prescription</theory/fonll>`
6565
- applying the :doc:`scale variation prescription</theory/scalevar>`
66-
- burning the :doc:`K-factor</theory/kfactors>` into grids
66+
- burning the :doc:`Kfactor</theory/kfactors>` into grids
6767

6868

6969
Checking the grids
@@ -100,7 +100,7 @@ Using pineko with NNPDF
100100
"""""""""""""""""""""""
101101

102102
It is possible to use ``pineko`` without providing an explicit mapping between data and grids
103-
(i.e., without a ``yamldb`` database) or theory cards, by using the data declared in the NNPDF
103+
(i.e., without a ``ymldb`` database) or theory cards, by using the data declared in the NNPDF
104104
repository (which includes a data-theory mapping).
105105

106106
In order to do this you need to install ``pineko`` with the ``nnpdf`` extra, which installs

docs/source/theory/kfactors.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
K-Factors
1+
Kfactors
22
=========
33

44
Another useful tool that `pineko` includes is ``pineko kfactor`` which allows the embedding of a kfactor
55
as a proper order in a grid. The usage is the following::
66

7-
pineko kfactor GRIDS_FOLDER KFACTOR_FOLDER YAMLDB_PATH TARGET_FOLDER MAX_AS ORDER_EXISTS
7+
pineko kfactor THEORY_ID DATASET KFACTOR_FOLDER TARGET_FOLDER PTO_TO_UPDATE [--order_exists]
88

9-
where ``GRIDS_FOLDER`` is the folder containing the grids to update, ``KFACTOR_FOLDER`` is the folder
10-
containing the kfactor files and ``YAMLDB_PATH`` is the path to the yamldb file of the requested dataset.
11-
The other inputs have already been described in the previous section.
9+
where:
10+
11+
- ``THEORY_ID`` is the theory ID of the source grid,
12+
- ``DATASET`` is the dataset name,
13+
- ``KFACTOR_FOLDER`` is the folder containing the kfactor files,
14+
- ``TARGET_FOLDER`` is the folder where the new updated grids is going to be saved,
15+
- ``PTO_TO_UPDATE`` is the :math:`\alpha_s` perturbative order to update or create,
16+
with the convention that ``LO=1``, ``NLO=2`` and so on, irrespectively to the powers of :math:`\alpha_s`.
17+
Note also that this differs from the conventions by the NNPDF collaboration,
18+
but it is consistent with the pineappl convention.
19+
- ``--order_exists`` is a flag used to apply the kfactor to the specified perturbative order, insead of the next.
20+
21+
Note that only pure QCD kfactors are taken into account.
22+
For example to add the NNLO in a grid containing at most NLO one has to select ``PTO_TO_UPDATE=2``;
23+
nn the other hand to reweight the NNLO present in a grid with a kfactor,
24+
one should do ``PTO_TO_UPDATE=2 --order_exists``.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ authors = [
1111
"Alessandro Candido <[email protected]>",
1212
"Andrea Barontini <[email protected]>",
1313
"Felix Hekhorn <[email protected]>",
14+
"Giacomo Magni <[email protected]>",
15+
"Roy Stegeman <[email protected]>",
1416
"Juan Cruz-Martinez <[email protected]>",
1517
]
1618
classifiers = [

src/pineko/check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def check_grid_and_eko_compatible(pineappl_grid, operators, xif, max_as, max_al)
8888
xif : float
8989
factorization scale variation
9090
max_as: int
91-
max order of alpa_s
91+
max order of alpha_s
9292
max_al: int
9393
max order of alpha
9494

src/pineko/cli/kfactor.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,35 @@
55
import click
66

77
from .. import kfactor
8-
from ._base import command
8+
from ._base import command, config_option, load_config
99

1010

1111
@command.command("kfactor")
12-
@click.argument("grids_folder", type=click.Path(exists=True))
12+
@config_option
13+
@click.argument("theoryID", type=int)
14+
@click.argument("dataset", type=str)
1315
@click.argument("kfactor_folder", type=click.Path(exists=True))
14-
@click.argument("yamldb_path", type=click.Path(exists=True))
1516
@click.argument("target_folder", type=click.Path(exists=True))
16-
@click.argument("max_as", type=int)
17-
@click.argument("order_exists", type=bool)
18-
def k_factor_inclusion(
19-
grids_folder,
17+
@click.argument("pto_to_update", type=int)
18+
@click.option("--order_exists", is_flag=True, help="Overwrite an existing order.")
19+
def kfactor_inclusion(
20+
cfg,
21+
theoryid,
22+
dataset,
2023
kfactor_folder,
21-
yamldb_path,
2224
target_folder,
23-
max_as,
25+
pto_to_update,
2426
order_exists,
2527
):
26-
"""Construct new grid with k_factor included."""
27-
grids_folder = pathlib.Path(grids_folder)
28+
"""Construct new grid with kfactor included."""
29+
load_config(cfg)
2830
kfactor_folder = pathlib.Path(kfactor_folder)
29-
yamldb_path = pathlib.Path(yamldb_path)
3031
target_folder = pathlib.Path(target_folder)
31-
kfactor.compute_k_factor_grid(
32-
grids_folder,
32+
kfactor.apply_to_dataset(
33+
theoryid,
34+
dataset,
3335
kfactor_folder,
34-
yamldb_path,
35-
max_as,
36+
pto_to_update,
3637
target_folder=target_folder,
3738
order_exists=order_exists,
3839
)

0 commit comments

Comments
 (0)