From 6b9a35aa750fceddcb1554914d36d5325a2a4f34 Mon Sep 17 00:00:00 2001 From: EdoPro98 Date: Fri, 4 Feb 2022 11:44:28 +0100 Subject: [PATCH 1/2] Solved bug on sensor reset and better tests --- include/SiPMAnalogSignal.h | 2 +- tests/sensor.cpp | 48 +++++++++++++++++++++----------------- tests/test_python.py | 25 ++++++++++---------- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/include/SiPMAnalogSignal.h b/include/SiPMAnalogSignal.h index 662eedb..8d11b21 100644 --- a/include/SiPMAnalogSignal.h +++ b/include/SiPMAnalogSignal.h @@ -52,7 +52,7 @@ class SiPMAnalogSignal { /// @brief Returns the size of the vector containing the signal uint32_t size() const { return m_Waveform.size(); } /// @brief Clears all elements of the vector containing the signal - void clear() { return m_Waveform.clear(); } + void clear() { m_Waveform.clear(); m_peak = -1;} /// @brief Returns the sampling time of the signal in ns double sampling() const { return m_Sampling; } /// @brief Returns a std::vector containing the sampled waveform diff --git a/tests/sensor.cpp b/tests/sensor.cpp index 8232f72..b0e644f 100644 --- a/tests/sensor.cpp +++ b/tests/sensor.cpp @@ -7,49 +7,53 @@ using namespace sipm; struct TestSiPMSensor : public ::testing::Test { - SiPMSensor sut; - SiPMRandom rng; }; TEST_F(TestSiPMSensor, Constructor) { SiPMSensor sensor = SiPMSensor(); } TEST_F(TestSiPMSensor, AddPhoton) { static constexpr int N = 100000; + SiPMSensor sensor; for (int i = 0; i < 1000; ++i) { - sut.resetState(); - sut.addPhoton(10); + sensor.resetState(); + sensor.addPhoton(10); } } TEST_F(TestSiPMSensor, AddPhotons) { static constexpr int N = 100000; + SiPMSensor sensor; + SiPMRandom rng; for (int i = 0; i < N; ++i) { - sut.resetState(); - int n = rng.randInteger(100) + 1; + sensor.resetState(); + const int n = rng.randInteger(100) + 1; // n should be > 0 std::vector t = rng.randGaussian(100, 0.2, n); - sut.addPhotons(t); + sensor.addPhotons(t); } } TEST_F(TestSiPMSensor, AddPhotonWlen) { static constexpr int N = 100000; + SiPMSensor sensor; + SiPMRandom rng; for (int i = 0; i < 1000; ++i) { - sut.resetState(); - sut.addPhoton(rng.randGaussian(100, 0.2), rng.randGaussian(450, 20)); + sensor.resetState(); + sensor.addPhoton(rng.randGaussian(100, 0.2), rng.randGaussian(450, 20)); } } TEST_F(TestSiPMSensor, AddPhotonsWlen) { static constexpr int N = 100000; - sut.resetState(); + SiPMSensor sensor; + SiPMRandom rng; for (int i = 0; i < N; ++i) { - sut.resetState(); + sensor.resetState(); int n = rng.randInteger(100) + 1; // n should be > 0 std::vector t = rng.randGaussian(100, 0.2, n); std::vector w = rng.randGaussian(450, 20, n); - sut.addPhotons(t, w); + sensor.addPhotons(t, w); } } @@ -57,7 +61,6 @@ TEST_F(TestSiPMSensor, AddDcr) { static constexpr int N = 1000000; int ndcr = 0; SiPMSensor sensor; - sensor.rng().seed(); for (int i = 0; i < N; ++i) { sensor.resetState(); sensor.runEvent(); @@ -71,22 +74,23 @@ TEST_F(TestSiPMSensor, AddDcr) { TEST_F(TestSiPMSensor, SignalGeneration) { static constexpr int N = 25; static constexpr int R = 10000; - SiPMSensor lsut = SiPMSensor(); + SiPMSensor sensor; + SiPMRandom rng; // Almost no noise - lsut.properties().setXtOff(); - lsut.properties().setDcrOff(); - lsut.properties().setApOff(); - lsut.properties().setSnr(40); + sensor.properties().setXtOff(); + sensor.properties().setDcrOff(); + sensor.properties().setApOff(); + sensor.properties().setSnr(40); for (int i = 1; i < N; ++i) { // generate i photons std::vector t = rng.randGaussian(10, 0.1, i); double avg_max = 0; for (int j = 0; j < R; ++j) { - lsut.resetState(); - lsut.addPhotons(t); - lsut.runEvent(); - avg_max += lsut.signal().peak(0,20,0); + sensor.resetState(); + sensor.addPhotons(t); + sensor.runEvent(); + avg_max += sensor.signal().peak(0,20,0); } avg_max /= R; EXPECT_GE(avg_max + 0.5, i); diff --git a/tests/test_python.py b/tests/test_python.py index 2fa5deb..87c27b6 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -190,20 +190,19 @@ def test_RngSeed(self): def test_RngGeneration(self): rng = SiPM.SiPMRandom() - expected = ( - 2.6770408112497535e-10, - 2.2888317445790562e-05, - 0.5027885437448278, - 0.01176967815998986, - 0.3879451975033448, - 0.4092261985079124, - 0.9980280691448176, - 0.7526879616003483, - 0.570652454801827, - 0.12967310254649567, - ) + expected = (0.3385211885526973, + 0.6692720383681454, + 0.8803017983565893, + 0.6481967933987185, + 0.6752212145798044, + 0.1313980651231792, + 0.922863911678111, + 0.8573955726909455, + 0.8721560388241734, + 0.5158249832309119, + ) for i in range(N): - rng.seed(1234567890) + rng.seed(12345678901234567890) for e in expected: assert rng.Rand() == e From 3ea4cdee12d6645d58d255f0928df28c419e9a5a Mon Sep 17 00:00:00 2001 From: EdoPro98 Date: Fri, 4 Feb 2022 11:52:26 +0100 Subject: [PATCH 2/2] Changed version to 2.0.2 --- docs/Doxyfile | 2 +- include/SiPM.h | 2 +- setup.py | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/Doxyfile b/docs/Doxyfile index ef6f953..a79f71e 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = SimSipm # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 2.0.1-beta +PROJECT_NUMBER = 2.0.2 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/include/SiPM.h b/include/SiPM.h index aa9c067..7843120 100644 --- a/include/SiPM.h +++ b/include/SiPM.h @@ -1,7 +1,7 @@ #ifndef SIPM_SIPM_H #define SIPM_SIPM_H -#define SIPM_VERSION "2.0.1-beta" +#define SIPM_VERSION "2.0.2" #include "SiPMAdc.h" #include "SiPMAnalogSignal.h" diff --git a/setup.py b/setup.py index b418cc1..8b43df5 100644 --- a/setup.py +++ b/setup.py @@ -101,9 +101,13 @@ def __str__(self): zip_safe=False, license="MIT", classifiers=[ - "Development Status :: 4 - Beta", + "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: MIT License", "Topic :: Scientific/Engineering :: Physics", "Programming Language :: Python :: 3", + "Programming Language :: C++", + "Intended Audience :: Science/Research", + "Operating System :: POSIX :: Linux", + "Operating System :: MacOS", ], )