Skip to content

Commit

Permalink
Merge pull request #69 from XENONnT/simplify_source
Browse files Browse the repository at this point in the history
Simplify TemplateSource, CombinedSource and SpectrumTemplateSource
  • Loading branch information
dachengx authored Aug 16, 2023
2 parents f073705 + acbd7db commit b61fffd
Show file tree
Hide file tree
Showing 9 changed files with 466 additions and 381 deletions.
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

## 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
]
}
20 changes: 15 additions & 5 deletions alea/examples/configs/unbinned_wimp_statistical_model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ parameter_definition:
fittable: false
description: Livetime of SR1 in years

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
Expand Down Expand Up @@ -53,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=-2, scale=4)
# relative_uncertainty: false
fittable: true
blueice_anchors:
Expand All @@ -76,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 @@ -107,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 Down
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=-2, scale=4)
# 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
6 changes: 1 addition & 5 deletions alea/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
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


Expand Down Expand Up @@ -54,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

0 comments on commit b61fffd

Please sign in to comment.