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

Simplify TemplateSource, CombinedSource and SpectrumTemplateSource #69

Merged
merged 25 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ec0bc27
Simplify TemplateSource
dachengx Jul 31, 2023
cd0a594
Update settings of utils, add SR2 to demo CombinedSource
dachengx Jul 31, 2023
1f9251b
Minor change
dachengx Jul 31, 2023
789e3f2
Set numpy version to less than 1.23.0
dachengx Jul 31, 2023
e1aac2a
Update docstring to Google style
dachengx Jul 31, 2023
ef53ff8
Check needed weighted parameters of CombinedSource
dachengx Aug 1, 2023
459c93b
Update docstring
dachengx Aug 1, 2023
e1cf100
Merge remote-tracking branch 'origin/main' into simplify_source
dachengx Aug 1, 2023
698e0ba
No need to use multiple inheritance
dachengx Aug 1, 2023
c7252e8
Merge branch 'main' into simplify_source
dachengx Aug 1, 2023
462fb5b
Raise error when there is no key in the json file
dachengx Aug 2, 2023
20b53de
Merge remote-tracking branch 'origin/main' into simplify_source
dachengx Aug 4, 2023
de2044d
Recover logging, update docstring
dachengx Aug 4, 2023
07fb1c0
Kill cache of coverage
dachengx Aug 4, 2023
6fd9c19
Test SpectrumTemplateSource
dachengx Aug 6, 2023
1356abb
Demo future callable uncertainty
dachengx Aug 6, 2023
52c2681
Use latest numpy
dachengx Aug 8, 2023
bf29d49
Rename histogram_multiplier to histogram_scale_factor
dachengx Aug 10, 2023
c2b0cf3
Merge remote-tracking branch 'origin/main' into simplify_source
dachengx Aug 16, 2023
b3955f3
Test template source separately in another test module
dachengx Aug 16, 2023
b063d6e
Remove double quotes if not necessary
dachengx Aug 16, 2023
4f5508a
Forget to upload this file
dachengx Aug 16, 2023
68d2a2a
tiny typo
kdund Aug 16, 2023
72b4e17
tiny docstring change
kdund Aug 16, 2023
acbd7db
Fix little typo
dachengx Aug 16, 2023
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![DOI](https://zenodo.org/badge/654100988.svg)](https://zenodo.org/badge/latestdoi/654100988)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/XENONnT/alea/HEAD?labpath=notebooks)
[![Test package](https://github.com/XENONnT/alea/actions/workflows/pytest.yml/badge.svg?branch=main)](https://github.com/XENONnT/alea/actions/workflows/pytest.yml)
[![Coverage Status](https://coveralls.io/repos/github/XENONnT/alea/badge.svg?branch=main)](https://coveralls.io/github/XENONnT/alea?branch=main)
[![Coverage Status](https://coveralls.io/repos/github/XENONnT/alea/badge.svg?branch=main&kill_cache=1)](https://coveralls.io/github/XENONnT/alea?branch=main&kill_cache=1)
[![PyPI version shields.io](https://img.shields.io/pypi/v/alea-inference.svg)](https://pypi.python.org/pypi/alea-inference/)
[![Readthedocs Badge](https://readthedocs.org/projects/alea/badge/?version=latest)](https://alea.readthedocs.io/en/latest/?badge=latest)
[![CodeFactor](https://www.codefactor.io/repository/github/xenonnt/alea/badge)](https://www.codefactor.io/repository/github/xenonnt/alea)
Expand All @@ -27,8 +27,8 @@ You are now ready to use alea!

## Getting started
The best way to get started is to check out the [documentation](https://alea.readthedocs.io/en/latest/) and have a look at our [tutorial notebooks](https://github.com/XENONnT/alea/tree/main/notebooks). To explore the notebooks interactively, you can use [Binder](https://mybinder.org/v2/gh/XENONnT/alea/HEAD?labpath=notebooks).
## Ackgnowledgements

## Ackgnowledgements
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acknowledgements :)

`alea` is a public package inherited the spirits of previously private XENON likelihood definition and inference construction code `binference` that based on the blueice repo https://github.com/JelleAalbers/blueice.

Binference was developed for XENON1T WIMP searches by Knut Dundas Morå, and for the first XENONnT results by Robert Hammann, Knut Dundas Morå and Tim Wolf.
10 changes: 10 additions & 0 deletions alea/examples/configs/test_cs1_spectrum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"coordinate_system": [
0.0,
100.0
],
"map": [
1.0,
1.0
]
}
52 changes: 11 additions & 41 deletions alea/examples/configs/unbinned_wimp_statistical_model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ parameter_definition:
livetime_sr2:
nominal_value: 0.5
fittable: false
description: Livetime of SR1 in years
description: Livetime of SR2 in years

livetime_sr3:
nominal_value: 1.0
fittable: false
description: Livetime of SR3 in years

wimp_rate_multiplier:
nominal_value: 1.0
Expand Down Expand Up @@ -58,7 +63,7 @@ parameter_definition:
er_band_shift:
nominal_value: 0
ptype: shape
uncertainty: null # 'scipy.stats.uniform(loc=-1, scale=2)'
uncertainty: null # stats.uniform(loc=0, scale=2)
# relative_uncertainty: false
fittable: true
blueice_anchors:
Expand All @@ -81,8 +86,8 @@ likelihood_config:
default_source_class: alea.template_source.TemplateSource
likelihood_type: blueice.likelihood.UnbinnedLogLikelihood
analysis_space:
- "cs1": 'np.arange(0, 102, 2)'
- "cs2": 'np.geomspace(100, 100000, 51)'
- cs1: np.linspace(0, 100, 51)
- cs2: np.geomspace(100, 100000, 51)
in_events_per_bin: true
livetime_parameter: livetime_sr0
slice_args: {}
Expand Down Expand Up @@ -112,8 +117,8 @@ likelihood_config:
default_source_class: alea.template_source.TemplateSource
likelihood_type: blueice.likelihood.UnbinnedLogLikelihood
analysis_space:
- "cs1": 'np.arange(0, 102, 2)'
- "cs2": 'np.geomspace(100, 100000, 51)'
- cs1: np.linspace(0, 100, 51)
- cs2: np.geomspace(100, 100000, 51)
in_events_per_bin: true
livetime_parameter: livetime_sr1
slice_args: {}
Expand All @@ -137,38 +142,3 @@ likelihood_config:
template_filename: wimp50gev_template.h5
apply_efficiency: True
efficiency_name: signal_efficiency

# SR2
- name: sr2
default_source_class: alea.template_source.TemplateSource
likelihood_type: blueice.likelihood.UnbinnedLogLikelihood
analysis_space:
- "cs1": 'np.arange(0, 102, 2)'
- "cs2": 'np.geomspace(100, 100000, 51)'
in_events_per_bin: true
livetime_parameter: livetime_sr2
slice_args: {}
sources:
- name: er
class: alea.template_source.CombinedSource
parameters:
- er_rate_multiplier
- er_band_shift
named_parameters:
- er_band_shift
fixed_weight: 0.2
weight_names: [fixed_weight, er_band_shift] # 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: 100 # absolute rate, /year
histogram_scale_factor: 2

- name: wimp
histname: wimp_template
parameters:
- wimp_rate_multiplier
- wimp_mass
- signal_efficiency
template_filename: wimp50gev_template.h5
apply_efficiency: True
efficiency_name: signal_efficiency
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ likelihood_config:
default_source_class: alea.template_source.TemplateSource
likelihood_type: blueice.likelihood.UnbinnedLogLikelihood
analysis_space:
- "cs1": 'np.arange(0, 102, 2)'
- "cs2": 'np.geomspace(100, 100000, 51)'
- cs1: np.arange(0, 102, 2)
- cs2: np.geomspace(100, 100000, 51)
in_events_per_bin: true
livetime_parameter: livetime
slice_args: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
parameter_definition:
wimp_mass:
nominal_value: 50
fittable: false
description: WIMP mass in GeV/c^2

livetime_sr2:
nominal_value: 0.5
fittable: false
description: Livetime of SR2 in years

livetime_sr3:
nominal_value: 1.0
fittable: false
description: Livetime of SR3 in years

wimp_rate_multiplier:
nominal_value: 1.0
ptype: rate
fittable: true
fit_limits:
- 0
- null
parameter_interval_bounds:
- 0
- null

er_rate_multiplier:
nominal_value: 1.0
ptype: rate
uncertainty: 0.2
relative_uncertainty: true
fittable: true
fit_limits:
- 0
- null
fit_guess: 1.0

signal_efficiency:
nominal_value: 1.0
ptype: efficiency
uncertainty: 0.1
relative_uncertainty: true
fittable: true
fit_limits:
- 0
- 10.
fit_guess: 1.0
description: Parameter to account for the uncertain signal expectation given a certain cross-section

er_band_shift:
nominal_value: 0
ptype: shape
uncertainty: null # stats.uniform(loc=0, scale=2)
# relative_uncertainty: false
fittable: true
blueice_anchors:
- -2
- -1
- 0
- 1
- 2
fit_limits:
- -2
- 2
description: ER band shape parameter (shifts the ER band up and down)

likelihood_config:
template_folder: null # will try to find the templates in alea
likelihood_terms:
# SR2
- name: sr2
default_source_class: alea.template_source.TemplateSource
likelihood_type: blueice.likelihood.UnbinnedLogLikelihood
analysis_space:
- cs1: np.linspace(0, 100, 51)
- cs2: np.geomspace(100, 100000, 51)
in_events_per_bin: true
livetime_parameter: livetime_sr2
slice_args: {}
sources:
- name: er
class: alea.template_source.CombinedSource
parameters:
- er_rate_multiplier
- er_band_shift
named_parameters:
- er_band_shift
fixed_weight: 0.2
weight_names: [fixed_weight, er_band_shift] # 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_scale_factor: 100 # absolute rate, /year

- name: wimp
histname: wimp_template
parameters:
- wimp_rate_multiplier
- wimp_mass
- signal_efficiency
template_filename: wimp50gev_template.h5
apply_efficiency: True
efficiency_name: signal_efficiency

# SR3
- name: sr3
default_source_class: alea.template_source.TemplateSource
likelihood_type: blueice.likelihood.UnbinnedLogLikelihood
analysis_space:
- cs1: np.linspace(0, 100, 51)
- cs2: np.geomspace(100, 100000, 51)
in_events_per_bin: true
livetime_parameter: livetime_sr3
slice_args: {}
sources:
- name: er
histname: er_template
parameters:
- er_rate_multiplier
- er_band_shift
named_parameters:
- er_band_shift
template_filename: er_template_{er_band_shift}.h5

- name: wimp
class: alea.template_source.SpectrumTemplateSource
histname: wimp_template
parameters:
- wimp_rate_multiplier
- wimp_mass
- signal_efficiency
template_filename: wimp50gev_template.h5
spectrum_name: test_cs1_spectrum.json
apply_efficiency: True
efficiency_name: signal_efficiency
8 changes: 1 addition & 7 deletions alea/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
from typing import Any, Dict, List, Tuple, Iterator, Optional, Union, cast
import pandas as pd

# These imports are needed to evaluate the uncertainty string
import numpy # noqa: F401
import scipy # noqa: F401

from alea.utils import within_limits, clip_limits

import scipy


class Parameter:
"""Represents a single parameter with its properties.
Expand Down Expand Up @@ -56,8 +50,8 @@ def __init__(
self.nominal_value = nominal_value
self.fittable = fittable
self.ptype = ptype
self.uncertainty = uncertainty
self.relative_uncertainty = relative_uncertainty
self.uncertainty = uncertainty
self.blueice_anchors = blueice_anchors
self.fit_limits = fit_limits
self.parameter_interval_bounds = parameter_interval_bounds
Expand Down
Loading