Skip to content

Commit

Permalink
Merge pull request #493 from Sinclert/fix-lhe-parsing
Browse files Browse the repository at this point in the history
Fix LHE `Observable` and `Cut` parsing
  • Loading branch information
Sinclert authored Oct 22, 2021
2 parents 2ad03d2 + a965994 commit b09df60
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions madminer/utils/interfaces/lhe.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def _parse_observations(observables: Dict[str, Observable], variables: Dict[str,
for name, observable in observables.items():
definition = observable.val_expression
default = observable.val_default
required = observable.is_required

try:
if isinstance(definition, str):
Expand All @@ -422,7 +423,7 @@ def _parse_observations(observables: Dict[str, Observable], variables: Dict[str,
else:
raise TypeError("Not a valid observable")
except (IndexError, NameError, RuntimeError, SyntaxError, TypeError, ZeroDivisionError):
passed_all = False
passed_all = False if required else True
value = default if default is not None else np.nan
finally:
observations.append(value)
Expand Down Expand Up @@ -474,16 +475,19 @@ def _parse_cuts(cuts, fail_cuts, observables, observations, pass_all_cuts, pass_

# Check cuts
for i_cut, cut in enumerate(cuts):
definition = cut.val_expression
required = cut.is_required

try:
cut_result = eval(cut, variables)
cut_result = eval(definition, variables)
if cut_result:
pass_cuts[i_cut] += 1
else:
fail_cuts[i_cut] += 1
pass_all_cuts = False

except (SyntaxError, NameError, TypeError, ZeroDivisionError, IndexError):
if cut.is_required:
if required:
pass_cuts[i_cut] += 1
else:
fail_cuts[i_cut] += 1
Expand Down

0 comments on commit b09df60

Please sign in to comment.