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

Add spectrum_axis configuration for SpectrumTemplateSource #212

Merged
merged 1 commit into from
Sep 18, 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
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
Loading