From 020976a22893811349aa505c67c4fbad0572628c Mon Sep 17 00:00:00 2001 From: bpalmeiro Date: Tue, 29 Oct 2024 19:49:44 +0000 Subject: [PATCH 1/8] Cosmetics on the github actions --- .github/workflows/testsuite.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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 - From ffcce96992fda8a8f49c33574ac508ea12bca654 Mon Sep 17 00:00:00 2001 From: bpalmeiro Date: Tue, 29 Oct 2024 19:56:20 +0000 Subject: [PATCH 2/8] Add a temporal test for allow merging --- packs/temporal_test.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 packs/temporal_test.py 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 From 7f9ad7beb993f098b6709e1ff19e5084f8f3c609 Mon Sep 17 00:00:00 2001 From: bpalmeiro Date: Tue, 29 Oct 2024 20:39:41 +0000 Subject: [PATCH 3/8] Add __init__.py in tools --- packs/tools/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 packs/tools/__init__.py diff --git a/packs/tools/__init__.py b/packs/tools/__init__.py new file mode 100644 index 0000000..e69de29 From 24634b0ce5bf0f1962e38dd7adf9721de06827b6 Mon Sep 17 00:00:00 2001 From: bpalmeiro Date: Tue, 29 Oct 2024 20:42:37 +0000 Subject: [PATCH 4/8] Add function --- packs/tools/fit_functions.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 packs/tools/fit_functions.py diff --git a/packs/tools/fit_functions.py b/packs/tools/fit_functions.py new file mode 100644 index 0000000..a2967b6 --- /dev/null +++ b/packs/tools/fit_functions.py @@ -0,0 +1,24 @@ +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: + poispeaks_pos = np.arange(0, scs.poisson.ppf(maxpercent, 1)) + realpeaks_pos = gain * poispeaks_pos + bl + realpeaks_amp = amp * scs.poisson.pmf(poispeaks_pos, poismu) + result = np.zeros_like(xs) + + result += realpeaks_amp[0] * scs.norm.pdf(xs, loc=realpeaks_pos[0], scale=sigmabl) + + for i in range(1, 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 From 73a2279ac498e2b08c0cc392b74aa7385b2ef09f Mon Sep 17 00:00:00 2001 From: bpalmeiro Date: Tue, 29 Oct 2024 20:43:48 +0000 Subject: [PATCH 5/8] Add test --- packs/tools/fit_functions_test.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 packs/tools/fit_functions_test.py 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) + From 9e48cd24095dd8f8fc5c25930a42b2dfcb8722f3 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Tue, 5 Nov 2024 18:17:53 +0000 Subject: [PATCH 6/8] add documentation & improve logic --- packs/tools/fit_functions.py | 40 ++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/packs/tools/fit_functions.py b/packs/tools/fit_functions.py index a2967b6..312eb50 100644 --- a/packs/tools/fit_functions.py +++ b/packs/tools/fit_functions.py @@ -11,14 +11,46 @@ def finger_signal(xs : np.array, 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 poispeaks_pos = np.arange(0, scs.poisson.ppf(maxpercent, 1)) realpeaks_pos = gain * poispeaks_pos + bl realpeaks_amp = amp * scs.poisson.pmf(poispeaks_pos, poismu) + + # start y values collection result = np.zeros_like(xs) - result += realpeaks_amp[0] * scs.norm.pdf(xs, loc=realpeaks_pos[0], scale=sigmabl) + # 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)) - for i in range(1, 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 From 5a1e2dc347c6793c3ad6e605c56b3edfff05a550 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Tue, 5 Nov 2024 18:36:52 +0000 Subject: [PATCH 7/8] Alter ppf function to reflect inputted poisson mu --- packs/tools/fit_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packs/tools/fit_functions.py b/packs/tools/fit_functions.py index 312eb50..0e36d85 100644 --- a/packs/tools/fit_functions.py +++ b/packs/tools/fit_functions.py @@ -40,7 +40,7 @@ def finger_signal(xs : np.array, ''' # Collect the position and amplitudes of the finger plot peaks - poispeaks_pos = np.arange(0, scs.poisson.ppf(maxpercent, 1)) + poispeaks_pos = np.arange(0, scs.poisson.ppf(maxpercent, poismu)) realpeaks_pos = gain * poispeaks_pos + bl realpeaks_amp = amp * scs.poisson.pmf(poispeaks_pos, poismu) From 255261cc85e5038acf5a3547456b668a7f61ae05 Mon Sep 17 00:00:00 2001 From: jwaiton Date: Tue, 5 Nov 2024 18:47:10 +0000 Subject: [PATCH 8/8] add case protection for when poismu is determined to be zero --- packs/tools/fit_functions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packs/tools/fit_functions.py b/packs/tools/fit_functions.py index 0e36d85..b8f1f96 100644 --- a/packs/tools/fit_functions.py +++ b/packs/tools/fit_functions.py @@ -40,7 +40,10 @@ def finger_signal(xs : np.array, ''' # Collect the position and amplitudes of the finger plot peaks - poispeaks_pos = np.arange(0, scs.poisson.ppf(maxpercent, poismu)) + 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)