Skip to content

Commit

Permalink
Add spectrum_axis configuration for SpectrumTemplateSource (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx authored Sep 18, 2024
1 parent 087ff3b commit b7dba09
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,5 @@ likelihood_config:
- signal_efficiency
template_filename: wimp50gev_template.ii.h5
spectrum_name: test_cs1_spectrum.json
spectrum_axis: 1
efficiency_name: signal_efficiency
6 changes: 3 additions & 3 deletions alea/template_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,14 @@ def build_histogram(self):

if "spectrum_name" not in self.config:
raise ValueError("spectrum_name not in config")
if "spectrum_axis" not in self.config:
raise ValueError("spectrum_axis not in config")
spectrum = self._get_json_spectrum(
self.config["spectrum_name"].format(**self.format_named_parameters)
)

# Perform scaling, the first axis is assumed to be reweighted
# The spectrum is assumed to be probability density (in per the unit of first axis).
axis = 0
# h = h.normalize(axis=axis)
axis = self.config["spectrum_axis"]
bin_edges = h.bin_edges[axis]
bin_centers = h.bin_centers(axis=axis)
slices = [None] * h.histogram.ndim
Expand Down
6 changes: 6 additions & 0 deletions alea/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ def dump_yaml(file_name: str, data: dict):
yaml.safe_dump(data, file)


def dump_json(file_name: str, data: dict):
"""Dump data to a json file."""
with open(file_name, "w") as file:
json.dump(data, file, indent=4)


def _get_abspath(file_name):
"""Get the abspath of the file.
Expand Down

0 comments on commit b7dba09

Please sign in to comment.