src: LHE module combine funcs
@@ -108,6 +108,27 @@ class LHEReader:
# Initialize nuisance parameters
self.nuisance_parameters = OrderedDict()
+ @staticmethod
+ def _check_sample_elements(this_elements, n_events=None):
+ """ Sanity checks """
+
+ # Check number of events in observables
+ for key, elems in this_elements.items():
+ this_n_events = len(elems)
+
+ if n_events is None:
+ n_events = this_n_events
+ logger.debug(f"Found {n_events} events")
+
+ if this_n_events != n_events:
+ raise RuntimeError(
+ f"Mismatching number of events for {key}: "f"{n_events} vs {this_n_events}")
+
+ if not np.issubdtype(elems.dtype, np.number):
+ logger.warning(f"For key {key} have non-numeric dtype {elems.dtype}.")
+
+ return n_events
+
def add_sample(
self,
lhe_filename,
@@ -716,8 +737,8 @@ class LHEReader:
return None, None
logger.debug("Found weights %s in LHE file", list(this_weights.keys()))
- # Sanity checks
- n_events = self._check_sample_observations_and_weights(this_observations, this_weights)
+ n_events = self._check_sample_elements(this_observations, None)
+ n_events = self._check_sample_elements(this_weights, None)
# Rescale nuisance parameters to reference benchmark
reference_weights = this_weights[reference_benchmark]
@@ -728,55 +749,6 @@ class LHEReader:
return this_observations, this_weights, n_events
- @staticmethod
- def _check_sample_observations_and_weights(this_observations, this_weights):
- """ Sanity checks """
-
- # Check number of events in observables, and their dtype
- n_events = None
- for key, obs in this_observations.items():
- this_n_events = len(obs)
- if n_events is None:
- n_events = this_n_events
- logger.debug("Found %s events", n_events)
-
- if this_n_events != n_events:
- raise RuntimeError(
- "Mismatching number of events in LHE observations for {}: {} vs {}".format(
- key, n_events, this_n_events
- )
- )
-
- if not np.issubdtype(obs.dtype, np.number):
- logger.warning(
- "Observations for observable %s have non-numeric dtype %s. This usually means something "
- "is wrong in the definition of the observable. Data: %s",
- key,
- obs.dtype,
- obs,
- )
- # Check number of events in weights, and thier dtype
- for key, weights in this_weights.items():
- this_n_events = len(weights)
- if n_events is None:
- n_events = this_n_events
- logger.debug("Found %s events", n_events)
-
- if this_n_events != n_events:
- raise RuntimeError(
- "Mismatching number of events in weights {}: {} vs {}".format(key, n_events, this_n_events)
- )
-
- if not np.issubdtype(weights.dtype, np.number):
- logger.warning(
- "Weights %s have non-numeric dtype %s. This usually means something "
- "is wrong in the definition of the observable. Data: %s",
- key,
- weights.dtype,
- weights,
- )
- return n_events
-
def save(self, filename_out, shuffle=True):
"""
Saves the observable definitions, observable values, and event weights in a MadMiner file. The parameter,
