Skip to content

Commit

Permalink
promote the shifts flag to a first class theory flag
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed Oct 31, 2023
1 parent bf3b5c5 commit d03263c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
26 changes: 23 additions & 3 deletions validphys2/src/validphys/commondataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ class ValidApfelComb:
mapping with the single fktables which need to be normalized and the factor
note that when they are global factors they are promoted to conversion_factor
- shifts:
mapping with the single fktables and their respective shifts
necessary to create "gaps" that some cfactors or datasets might expect
this flag is left here for compatibility purposes but has been moved to TheoryMeta
"""

repetition_flag: Optional[list[str]] = None
Expand All @@ -143,6 +142,19 @@ class TheoryMeta:
The theory metadata must always contain a key ``FK_tables`` which defines
the fktables to be loaded.
The ``FK_tables`` is organized as a double list such that:
The inner list is concatenated
In practice these are different fktables that might refer to the same observable but
that are divided in subgrids for practical reasons.
The outer list instead are the operands for whatever operation needs to be computed
in order to match the experimental data.
In addition there are other flags that can affect how the fktables are read or used:
- operation: defines the operation to apply to the outer list
- shifts: mapping with the single fktables and their respective shifts
useful to create "gaps" so that the fktables and the respective experimental data
are ordered in the same way (for instance, when some points are missing from a grid)
Example
-------
Expand All @@ -161,19 +173,27 @@ class TheoryMeta:
... '''
... theory = yaml.safe_load(theory_raw)
... parse_input(theory, TheoryMeta)
TheoryMeta(FK_tables=[['fk1'], ['fk2', 'fk3']], operation='RATIO', conversion_factor=1.0, comment=None, apfelcomb=ValidApfelComb(repetition_flag=['fk3'], normalization=None, shifts=None))
TheoryMeta(FK_tables=[['fk1'], ['fk2', 'fk3']], operation='RATIO', shifts = None, conversion_factor=1.0, comment=None, apfelcomb=ValidApfelComb(repetition_flag=['fk3'], normalization=None))
"""

FK_tables: list[list]
operation: ValidOperation = "NULL"
conversion_factor: float = 1.0
comment: Optional[str] = None
shifts: Optional[dict] = None
apfelcomb: Optional[ValidApfelComb] = None
# The following options are transitional so that the yamldb can be used from the theory
appl: Optional[bool] = False
target_dataset: Optional[str] = None

def __post_init__(self):
"""If a ``shifts`` flag is found in the apfelcomb object, move it outside"""
if self.apfelcomb is not None:
if self.apfelcomb.shifts is not None and self.shifts is None:
self.shifts = self.apfelcomb.shifts
self.apfelcomb.shifts = None

def fktables_to_paths(self, grids_folder):
"""Given a source for pineappl grids, constructs the lists of fktables
to be loaded"""
Expand Down
24 changes: 11 additions & 13 deletions validphys2/src/validphys/pineparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ def pineko_apfelcomb_compatibility_flags(gridpaths, metadata):
repetition_flag:
grid_name
- shifts:
only for ATLASZPT8TEVMDIST
the points in this dataset are not contiguous so the index is shifted
shifts:
grid_name: shift_int
Returns
-------
Expand Down Expand Up @@ -108,12 +103,6 @@ def pineko_apfelcomb_compatibility_flags(gridpaths, metadata):
if any(op in apfelcomb.repetition_flag for op in operands):
raise ValueError(f"The yaml info for {metadata['target_dataset']} is broken")

# Check whether the dataset has shifts
# NOTE: this only happens for ATLASZPT8TEVMDIST, if that gets fixed we might as well remove it
if apfelcomb.shifts is not None:
shift_info = apfelcomb.shifts
ret["shifts"] = [shift_info.get(op, 0) for op in operands]

return ret


Expand Down Expand Up @@ -228,6 +217,14 @@ def pineappl_reader(fkspec):

apfelcomb = pineko_apfelcomb_compatibility_flags(fkspec.fkpath, fkspec.metadata)

# Process the shifts (if any), shifts is a dictionary with {fktable_name: shift_value}
# since this parser doesn't know about operations, we need to convert it to a list
# then we just iterate over the fktables and apply the shift in the right order
shifts = None
if (shift_info := fkspec.metadata.shifts) is not None:
fknames = [i.name.replace(f".{EXT}", "") for i in fkspec.fkpath]
shifts = [shift_info.get(fname, 0) for fname in fknames]

# fktables in pineapplgrid are for obs = fk * f while previous fktables were obs = fk * xf
# prepare the grid all tables will be divided by
if hadronic:
Expand Down Expand Up @@ -256,8 +253,9 @@ def pineappl_reader(fkspec):
raw_fktable = raw_fktable[0:1]
n = 1
protected = True
if apfelcomb.get("shifts") is not None:
ndata += apfelcomb["shifts"][i]

if shifts is not None:
ndata += shifts[i]

# Add empty points to ensure that all fktables share the same x-grid upon convolution
missing_x_points = np.setdiff1d(xgrid, p.x_grid(), assume_unique=True)
Expand Down

0 comments on commit d03263c

Please sign in to comment.