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

support under-/overflows in YODA2 writer #56

Merged
merged 11 commits into from
Mar 12, 2024
Merged
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
14 changes: 14 additions & 0 deletions hepdata_converter/testsuite/test_yoda1writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ def test_parse_all(self, test_submissions):
options={'output_format': 'yoda1'})

self.assertNotEqual(os.stat(output_file_path).st_size, 0, 'output yoda file is empty')


@insert_path('yaml_inf')
@insert_data_as_file('yoda1/with_overflows.yoda')
def test_parse_with_overflows(self, yaml_simple_path, yoda_template):
output_file_path = os.path.join(self.current_tmp, 'datafile.yoda')
hepdata_converter.convert(yaml_simple_path, output_file_path,
options={'output_format': 'yoda1',
'validator_schema_version': '0.1.0',
'rivet_analysis_name': 'OVERFLOW_TEST'})

self.assertNotEqual(os.stat(output_file_path).st_size, 0, 'output yoda file is empty')
with open(output_file_path, 'r') as f:
self.assertMultiLineAlmostEqual(f, yoda_template)
15 changes: 14 additions & 1 deletion hepdata_converter/testsuite/test_yodawriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_parse_pattern_unmatch(self, yaml_simple_path, yoda_template):

@insert_path('yaml_no_independent')
@insert_data_as_file('yoda/no_independent.yoda')
def test_parse_no_dependent(self, yaml_simple_path, yoda_template):
def test_parse_no_independent(self, yaml_simple_path, yoda_template):
output_file_path = os.path.join(self.current_tmp, 'datafile.yoda')
hepdata_converter.convert(yaml_simple_path, output_file_path,
options={'output_format': 'yoda',
Expand All @@ -76,3 +76,16 @@ def test_parse_no_dependent(self, yaml_simple_path, yoda_template):
with open(output_file_path, 'r') as f:
self.assertMultiLineAlmostEqual(f, yoda_template)

@insert_path('yaml_inf')
@insert_data_as_file('yoda/with_overflows.yoda')
def test_parse_with_overflows(self, yaml_simple_path, yoda_template):
output_file_path = os.path.join(self.current_tmp, 'datafile.yoda')
hepdata_converter.convert(yaml_simple_path, output_file_path,
options={'output_format': 'yoda',
'validator_schema_version': '0.1.0',
'rivet_analysis_name': 'OVERFLOW_TEST'})

self.assertNotEqual(os.stat(output_file_path).st_size, 0, 'output yoda file is empty')
with open(output_file_path, 'r') as f:
self.assertMultiLineAlmostEqual(f, yoda_template)

121 changes: 121 additions & 0 deletions hepdata_converter/testsuite/testdata/yaml_inf/figure-aux_001.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
dependent_variables:
- header:
name: data
values:
- errors:
- asymerror:
minus: -0.00021168
plus: 0.00021174
label: statistical
value: 0.67909
- errors:
- asymerror:
minus: -6.4995e-05
plus: 6.5062e-05
label: statistical
value: 0.064024
- errors:
- asymerror:
minus: -6.4099e-05
plus: 6.4165e-05
label: statistical
value: 0.06227
- errors:
- asymerror:
minus: -6.2574e-05
plus: 6.264e-05
label: statistical
value: 0.059342
- errors:
- asymerror:
minus: -6.0748e-05
plus: 6.0814e-05
label: statistical
value: 0.055929
- errors:
- asymerror:
minus: -5.8675e-05
plus: 5.8741e-05
label: statistical
value: 0.052178
- errors:
- asymerror:
minus: -5.658e-05
plus: 5.6646e-05
label: statistical
value: 0.048517
- errors:
- asymerror:
minus: -5.4593e-05
plus: 5.4659e-05
label: statistical
value: 0.045169
- errors:
- asymerror:
minus: -5.2581e-05
plus: 5.2647e-05
label: statistical
value: 0.041901
- errors:
- asymerror:
minus: -5.0612e-05
plus: 5.0678e-05
label: statistical
value: 0.038823
- errors:
- asymerror:
minus: -4.8815e-05
plus: 4.8881e-05
label: statistical
value: 0.036114
- errors:
- asymerror:
minus: -4.7028e-05
plus: 4.7094e-05
label: statistical
value: 0.033519
- header:
name: $m_{{X}_\mathrm{dark}}$ = 1600 GeV, $m_{{\pi}_\mathrm{dark}}$ = 20 GeV,
$\kappa$ = 0.4
values:
- value: .nan
- value: .nan
- value: .nan
- value: .nan
- value: .nan
- value: .nan
- value: .nan
- value: .nan
- value: .nan
- value: .nan
- value: .nan
- value: .nan
independent_variables:
- header:
name: Event $H_\mathrm{T}$
units: GeV
values:
- high: 1200.0
low: -.inf
- high: 1220.0
low: 1200.0
- high: 1240.0
low: 1220.0
- high: 1260.0
low: 1240.0
- high: 1280.0
low: 1260.0
- high: 1300.0
low: 1280.0
- high: 1320.0
low: 1300.0
- high: 1340.0
low: 1320.0
- high: 1360.0
low: 1340.0
- high: 1380.0
low: 1360.0
- high: 1400.0
low: 1380.0
- high: .inf
low: 1400.0
52 changes: 52 additions & 0 deletions hepdata_converter/testsuite/testdata/yaml_inf/submission.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
additional_resources:
- description: Created with hepdata_lib 0.14.0
location: https://doi.org/10.5281/zenodo.1217998
- description: Webpage with all figures and tables
location: https://cms-results.web.cern.ch/cms-results/public-results/publications/EXO-22-015/
- description: Example Pythia8 card for signal model
location: cards.tar.gz
comment: A search for emerging jets produced in proton-proton collisions at a center-of-mass
energy of $13\,\text{TeV}$ is performed using data collected by the CMS experiment,
corresponding to an integrated luminosity of $138\,\text{fb}^{-1}$. This search
examines a hypothetical dark QCD sector that couples to the standard model (SM)
through a scalar mediator. The scalar mediator decays into a standard model quark
and a dark sector quark. As the dark sector quark showers and hadronizes, it produces
long-lived dark mesons that subsequently decay into SM particles, resulting in a
jet with multiple displaced vertices, known as an emerging jet. This search looks
for pair production of the scalar mediators at the LHC, yielding events with two
SM jets and two emerging jets. The results are interpreted using two dark sector
models and exclude mediator masses up to $1800\,\text{GeV}$ for an unflavored dark
QCD model, and up to $1950\,\text{GeV}$ for a flavored-aligned dark QCD model.
data_license:
description: The content can be shared and adapted but you must give
appropriate credit and cannot restrict access to others.
name: cc-by-4.0
url: https://creativecommons.org/licenses/by/4.0/
related_to_hepdata_records: []
---
additional_resources:
- description: Image file
location: Figure-aux_001.png
- description: Thumbnail image file
location: thumb_Figure-aux_001.png
data_file: figure-aux_001.yaml
description: Distribution of event $H_\mathrm{T}$ of CMS data, SM multijet MC events,
and various signal samples. Events are required to pass the trigger requirements
and also have 4 jets with $p_\mathrm{T}>100$GeV. The distribution from various processes
have their total count normalized to 1.
keywords:
- name: reactions
values:
- P P --> XX --> Qd Qd q q
- name: cmenergies
values:
- 13000.0
- name: phrases
values:
- LLP
- Long-Lived
- Emerging Jets
location: Example location
name: Figure-aux_001
related_to_table_dois: []
47 changes: 47 additions & 0 deletions hepdata_converter/testsuite/testdata/yoda/with_overflows.yoda
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
BEGIN YODA_ESTIMATE1D_V3 /REF/OVERFLOW_TEST/d01-x01-y01
IsRef: 1
Path: /REF/OVERFLOW_TEST/d01-x01-y01
Title: "Figure-aux_001"
Type: Estimate1D
---
Edges(A1): [1.200000e+03, 1.220000e+03, 1.240000e+03, 1.260000e+03, 1.280000e+03, 1.300000e+03, 1.320000e+03, 1.340000e+03, 1.360000e+03, 1.380000e+03, 1.400000e+03]
ErrorLabels: ["statistical"]
# value errDn(1) errUp(1)
6.790900e-01 -2.116800e-04 2.117400e-04
6.402400e-02 -6.499500e-05 6.506200e-05
6.227000e-02 -6.409900e-05 6.416500e-05
5.934200e-02 -6.257400e-05 6.264000e-05
5.592900e-02 -6.074800e-05 6.081400e-05
5.217800e-02 -5.867500e-05 5.874100e-05
4.851700e-02 -5.658000e-05 5.664600e-05
4.516900e-02 -5.459300e-05 5.465900e-05
4.190100e-02 -5.258100e-05 5.264700e-05
3.882300e-02 -5.061200e-05 5.067800e-05
3.611400e-02 -4.881500e-05 4.888100e-05
3.351900e-02 -4.702800e-05 4.709400e-05
END YODA_ESTIMATE1D_V3


BEGIN YODA_ESTIMATE1D_V3 /REF/OVERFLOW_TEST/d01-x01-y02
IsRef: 1
Path: /REF/OVERFLOW_TEST/d01-x01-y02
Title: "Figure-aux_001"
Type: Estimate1D
---
Edges(A1): [1.200000e+03, 1.220000e+03, 1.240000e+03, 1.260000e+03, 1.280000e+03, 1.300000e+03, 1.320000e+03, 1.340000e+03, 1.360000e+03, 1.380000e+03, 1.400000e+03]
# value
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
nan
END YODA_ESTIMATE1D_V3


40 changes: 40 additions & 0 deletions hepdata_converter/testsuite/testdata/yoda1/with_overflows.yoda
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
BEGIN YODA_SCATTER2D_V2 /REF/OVERFLOW_TEST/d01-x01-y01
IsRef: 1
Path: /REF/OVERFLOW_TEST/d01-x01-y01
Title: Figure-aux_001
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+
1.210000e+03 1.000000e+01 1.000000e+01 6.402400e-02 6.499500e-05 6.506200e-05
1.230000e+03 1.000000e+01 1.000000e+01 6.227000e-02 6.409900e-05 6.416500e-05
1.250000e+03 1.000000e+01 1.000000e+01 5.934200e-02 6.257400e-05 6.264000e-05
1.270000e+03 1.000000e+01 1.000000e+01 5.592900e-02 6.074800e-05 6.081400e-05
1.290000e+03 1.000000e+01 1.000000e+01 5.217800e-02 5.867500e-05 5.874100e-05
1.310000e+03 1.000000e+01 1.000000e+01 4.851700e-02 5.658000e-05 5.664600e-05
1.330000e+03 1.000000e+01 1.000000e+01 4.516900e-02 5.459300e-05 5.465900e-05
1.350000e+03 1.000000e+01 1.000000e+01 4.190100e-02 5.258100e-05 5.264700e-05
1.370000e+03 1.000000e+01 1.000000e+01 3.882300e-02 5.061200e-05 5.067800e-05
1.390000e+03 1.000000e+01 1.000000e+01 3.611400e-02 4.881500e-05 4.888100e-05
END YODA_SCATTER2D_V2


BEGIN YODA_SCATTER2D_V2 /REF/OVERFLOW_TEST/d01-x01-y02
IsRef: 1
Path: /REF/OVERFLOW_TEST/d01-x01-y02
Title: Figure-aux_001
Type: Scatter2D
---
# xval xerr- xerr+ yval yerr- yerr+
1.210000e+03 1.000000e+01 1.000000e+01 nan 0.000000e+00 0.000000e+00
1.230000e+03 1.000000e+01 1.000000e+01 nan 0.000000e+00 0.000000e+00
1.250000e+03 1.000000e+01 1.000000e+01 nan 0.000000e+00 0.000000e+00
1.270000e+03 1.000000e+01 1.000000e+01 nan 0.000000e+00 0.000000e+00
1.290000e+03 1.000000e+01 1.000000e+01 nan 0.000000e+00 0.000000e+00
1.310000e+03 1.000000e+01 1.000000e+01 nan 0.000000e+00 0.000000e+00
1.330000e+03 1.000000e+01 1.000000e+01 nan 0.000000e+00 0.000000e+00
1.350000e+03 1.000000e+01 1.000000e+01 nan 0.000000e+00 0.000000e+00
1.370000e+03 1.000000e+01 1.000000e+01 nan 0.000000e+00 0.000000e+00
1.390000e+03 1.000000e+01 1.000000e+01 nan 0.000000e+00 0.000000e+00
END YODA_SCATTER2D_V2


10 changes: 8 additions & 2 deletions hepdata_converter/writers/yoda1_writer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from hepdata_converter.common import Option
from hepdata_converter.writers.array_writer import ArrayWriter, ObjectWrapper, ObjectFactory
import yoda, yaml
import yoda, yaml, math


class ScatterYodaClass(ObjectWrapper):
Expand Down Expand Up @@ -39,12 +39,18 @@ def _create_scatter(self):
too_many_y_values = True
if too_many_y_values: break

skipPoint = False
vals = []; err_dn = []; err_up = []
for dim_i in range(self.dim):
if not math.isfinite(self.xval[dim_i][i]):
skipPoint = True
break
vals.append(self.xval[dim_i][i])
err_dn.append(self.xerr_minus[dim_i][i])
err_up.append(self.xerr_plus[dim_i][i])
vals.append(self.yval[i])
if skipPoint: continue
y = abs(self.yval[i]) if math.isnan(self.yval[i]) else self.yval[i]
vals.append(y)
err_dn.append(self.yerr_minus[i])
err_up.append(self.yerr_plus[i])
args = [ vals, err_dn, err_up ]
Expand Down
12 changes: 10 additions & 2 deletions hepdata_converter/writers/yoda_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def _create_estimate(self):
v = float(self.xval[dim_i][i])
m = float(self.xerr_minus[dim_i][i])
p = float(self.xerr_plus[dim_i][i])
if not math.isfinite(v):
continue
lo = v - m
hi = v + p
if dim_i in visRange:
Expand Down Expand Up @@ -134,7 +136,12 @@ def _create_estimate(self):
m = self.xerr_minus[dim_i][i]
p = self.xerr_plus[dim_i][i]
if isCAxis[dim_i]:
edges.append(float(v))
v = float(v)
if not math.isfinite(v):
lo = float(self.independent_variable_map[dim_i]['values'][i]['low'])
hi = float(self.independent_variable_map[dim_i]['values'][i]['high'])
v = hi - 0.5 if math.isinf(lo) else lo + 0.5
edges.append(v)
elif isIntAxis[dim_i]:
edges.append(int(v))
else:
Expand All @@ -146,7 +153,8 @@ def _create_estimate(self):
if idx not in global_indices:
global_indices.append(idx)
# construct Estimate
rtn.bin(idx).setVal(self.yval[i])
y = abs(self.yval[i]) if math.isnan(self.yval[i]) else self.yval[i]
rtn.bin(idx).setVal(y)
self._set_error_breakdown(i, rtn.bin(idx))
del global_indices
return rtn
Expand Down
Loading