diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index e94c1c4..32cd1da 100644 --- a/.github/workflows/testsuite.yml +++ b/.github/workflows/testsuite.yml @@ -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 - diff --git a/packs/temporal_test.py b/packs/temporal_test.py new file mode 100644 index 0000000..62e45ca --- /dev/null +++ b/packs/temporal_test.py @@ -0,0 +1,2 @@ +def test_dummy(): + pass \ No newline at end of file diff --git a/packs/tools/__init__.py b/packs/tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/packs/tools/fit_functions.py b/packs/tools/fit_functions.py new file mode 100644 index 0000000..b8f1f96 --- /dev/null +++ b/packs/tools/fit_functions.py @@ -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 \ No newline at end of file diff --git a/packs/tools/fit_functions_test.py b/packs/tools/fit_functions_test.py new file mode 100644 index 0000000..dd31525 --- /dev/null +++ b/packs/tools/fit_functions_test.py @@ -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) +