diff --git a/alea/examples/configs/unbinned_wimp_statistical_model.yaml b/alea/examples/configs/unbinned_wimp_statistical_model.yaml index fbaa4821..ab5c77c0 100644 --- a/alea/examples/configs/unbinned_wimp_statistical_model.yaml +++ b/alea/examples/configs/unbinned_wimp_statistical_model.yaml @@ -148,13 +148,13 @@ likelihood_config: class: alea.template_source.CombinedSource parameters: - er_rate_multiplier - weight_1: 0.2 - weight_-1: 0.3 - weight_names: [weight_1, weight_-1] - histnames: [er_template, er_template, er_template,] + weight_a: 0.2 + weight_b: 0.3 + weight_names: [weight_a, weight_b] # not meaningful, just an example + histnames: [er_template, er_template, er_template] template_filenames: [er_template_0.h5, er_template_1.h5, er_template_-1.h5] - histogram_multiplier: 200 - histogram_scale_factor: 3 + histogram_multiplier: 100 # absolute rate, /year + histogram_scale_factor: 2 - name: wimp histname: wimp_template diff --git a/alea/template_source.py b/alea/template_source.py index f3fd2fb5..71234ec7 100644 --- a/alea/template_source.py +++ b/alea/template_source.py @@ -7,7 +7,7 @@ from blueice import HistogramPdfSource from inference_interface import template_to_multihist -logging.basicConfig(level=logging.INFO) +logging.basicConfig(level=logging.debug) can_check_binning = True @@ -128,7 +128,7 @@ def apply_slice_args(self, h, slice_args=None): """ if slice_args is None: slice_args = self.config.get("slice_args", {}) - if type(slice_args) is dict: + if isinstance(slice_args, dict): slice_args = [slice_args] for sa in slice_args: @@ -231,6 +231,8 @@ class CombinedSource(TemplateSource, HistogramPdfSource): Source that inherits structure from TH2DSource by Jelle, but takes in lists of histogram names. The first histogram is the base histogram, and the rest are added to it with weights. + Currently the weights are hardcoded in the config, can not be changed in the fit. + In other words, the weight can not be shape parameter. :param weights: Weights of the 2nd to the last histograms. :param histnames: List of filenames containing the histograms. @@ -257,9 +259,9 @@ def build_histogram(self): "weights must be 1 shorter than histnames, templatenames") slice_args = self.config.get("slice_args", {}) - if type(slice_args) is dict: + if isinstance(slice_args, dict): slice_args = [slice_args] - if all(type(sa) is dict for sa in slice_args): + if all(isinstance(sa, dict) for sa in slice_args): # Recognize as a single slice_args for all histograms slice_argss = [slice_args] * len(histnames) else: @@ -310,17 +312,22 @@ def build_histogram(self): histograms[0] += h_comp * weights[i] h = histograms[0] + logging.debug("Setting zero for NaNs and Infs in combined template.") + h.histogram[np.isinf(h.histogram)] = 0. + h.histogram[np.isnan(h.histogram)] = 0. + h.histogram[h.histogram < 0] = 0. + # Set pdf values that are below 0 to zero: if np.min(h.histogram) < 0: raise AssertionError( f"There are bins for source {templatename} with negative entries.") - logging.info( + logging.debug( "Normalising combined template, " "the absolute rate is defined in histogram_multiplier") h = h / h.n h *= self.config.get("histogram_multiplier", 1) - logging.info("Applying slice fraction to combined template") + logging.debug("Applying slice fraction to combined template") h *= slice_fractions[0] # Fix the bin sizes @@ -364,7 +371,7 @@ def build_histogram(self): h = template_to_multihist(templatename, histname) spectrum = self.config["spectrum"] - if type(spectrum) is str: + if isinstance(spectrum, str): spectrum = self._get_json_spectrum(spectrum.format(**self.format_named_parameters)) # Perform E-scaling, assume first axis is energy