Skip to content
Open
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
19 changes: 9 additions & 10 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,24 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up
- name: Test suite
run: |
wget https://repo.anaconda.com/miniconda/Miniconda3-py312_24.9.2-0-Linux-x86_64.sh -O miniconda.sh
bash miniconda.sh -b -p $HOME/miniconda
source $HOME/miniconda/etc/profile.d/conda.sh

echo
echo ************************************
echo "************************************"
echo ----------Conda Installed-----------
echo ************************************
echo "************************************"
echo

source setup.sh

echo
echo ************************************
echo "************************************"
echo ---------------test-----------------
echo ************************************
echo
echo "************************************"
echo

PYTEST_ADDOPTS=--color=yes HYPOTHESIS_PROFILE=travis-ci python -m pytest -v

2 changes: 2 additions & 0 deletions packs/temporal_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_dummy():
pass
Empty file added packs/tools/__init__.py
Empty file.
59 changes: 59 additions & 0 deletions packs/tools/fit_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import numpy as np
import scipy.stats as scs


def finger_signal(xs : np.array,
bl : float ,
amp : float ,
gain : float ,
sigmabl : float ,
sigmaq : float ,
poismu : float ,
maxpercent : float = 0.999
) -> np.array:
'''
A function that returns a `finger plot' distribution; a
poissonian distribution convoluted with gaussians. This distribution
characterises the output expected from a PMT/SiPM charge histogram
where x is the charge or PEs and y is the number of counts.

Parameters
----------
xs : An array of 'x' values, typically PEs or ADCs
bl : The value beyond zero at which the poisson peaks occur [1]
amp : The amplitude applied to the poissonian peaks
gain : The gain (shift in x) applied to the poissonian peaks
sigmabl : The inherent sigma of each gaussian.
sigmaq : The sigma of each gaussian related to which poisson peak
it's related to.
maxpercent : The percentage of the poissonian distribution that is

Returns
-------
result : The expected y values that given (x,y) describe the
finger plot distribution.

Footnotes
---------
[1] Generally these peaks would initialise at begin at x = 0 but in
practice this isn't always the case
'''

# Collect the position and amplitudes of the finger plot peaks
if poismu != 0:
poispeaks_pos = np.arange(0, scs.poisson.ppf(maxpercent, poismu))
else:
poispeaks_pos = np.array([0])
realpeaks_pos = gain * poispeaks_pos + bl
realpeaks_amp = amp * scs.poisson.pmf(poispeaks_pos, poismu)

# start y values collection
result = np.zeros_like(xs)

# generate y values (results) that describe the poissonian distribution with
# gaussian convolution across each peak
for i in range(0, len(poispeaks_pos)):
result += realpeaks_amp[i] * scs.norm.pdf(xs, loc=realpeaks_pos[i],
scale=np.sqrt(sigmabl**2 + sigmaq**2 * i))

return result
19 changes: 19 additions & 0 deletions packs/tools/fit_functions_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import numpy as np
import scipy.stats as scs

from . fit_functions import finger_signal

from hypothesis import given
from hypothesis.strategies import floats

@given(floats(min_value = -10, max_value = 10),
floats(min_value = -500, max_value = 500),
floats(min_value = 1, max_value = 2),
floats(min_value = 0, max_value = 200))
def test_finger_signal_gaus_when_poisson_zero(bl, gain, sbl, sq):
xaux = np.linspace(-10, 10, 1000)
yres = finger_signal(xaux, bl, 1, gain, sbl, sq, 0)
ygau = scs.norm.pdf(xaux, loc=bl, scale=sbl)

assert np.array_equal(yres, ygau)