echidna.test package¶
Submodules¶
echidna.test.physics_tests module¶
Physics tests are like unittests but for testing physics results.
Example
To run all physics tests:
$ python physics_tests.py
-
echidna.test.physics_tests.
test_function_float
(function, expected, tolerance=0.001, **kwargs)[source]¶ Tests a function that returns a physics result (float)
Parameters: - function (function) – An instance of the function/method. e.g.
caculator.get_n_atoms
- notice no parentheses. - expected (float) – Expected physics result of function.
- tolerance (float, optional) – Tolerance in agreement of results.
Evaluated as
tolerance*expected
, i.e. a tolerance of 0.001 ensures agreement to within 0.1% of expected value.
Returns: (bool, string): Tuple containing the result of the check True/ False for Pass/Fail and a message.
- function (function) – An instance of the function/method. e.g.
echidna.test.test_minimise module¶
Tests minimise module.
Tests the GridSearch.fin_minimum()
, method - an alternative to
calling numpy.argmin()
and numpy.nanmin()
, which are used
by default.
The main part of this test is verifying the GridSearch
class,
particularly the meth:`GridSearch.minimise method.
-
class
echidna.test.test_minimise.
TestGridSearch
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Tests for the class
echidna.limit.minimise.GridSearch
.-
_funct
(*args)[source]¶ Callable to pass to minimiser.
Fits A**2 + B**2 to C**2.
Returns: numpy.ndarray
: Test statistic values float: Penalty term - in this case always zero.
-
setUp
()[source]¶ Set up attributes for tests.
Variables: - _A (
spectra.Spectra
) – Test spectrum A - to use in test - _B (
spectra.Spectra
) – Test spectrum B - to use in test - _C (
spectra.Spectra
) – Test spectrum C - to use in test - _test_statistic (
test_statistic.BakerCousinsChi
) – Test statistic to use in test - _default_grid_search (
GridSearch
) – GridSearch using default method (numpy) for minimisation. - _grid_search (
GridSearch
) – GridSearch usingGridSearch.find_minimum()
, to find minimum.
- _A (
-
echidna.test.test_scale module¶
-
class
echidna.test.test_scale.
TestScale
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
-
fit_gaussian_energy
(spectrum)[source]¶ Fits a gausian to the energy of a spectrum.
Parameters: spectra ( spectra.Spectra
) – Spectrum to be fittedReturns: mean (float), sigma (float) and integral (float) of the spectrum. Return type: tuple
-
gaussian
(x, *p)[source]¶ A gaussian used for fitting.
Parameters: x (float) – Position the gaussian is calculated at. Returns: Value of gaussian at x for given parameters Return type: float
-
test_scale
()[source]¶ Tests the variable scaling method.
Creates a Gaussian spectra with mean energy 2.5 MeV and sigma 0.2 MeV. Radial values of the spectra have a uniform distribution. The “energy_mc” of the spectra is then scaled by a factor by 1.1. The scaled spectra is fitted with a Gaussian and the extracted mean and sigma are checked against expected values within 1 %. Integral of scaled spectrum is checked against original number of entries.
-
echidna.test.test_shift module¶
-
class
echidna.test.test_shift.
TestShift
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
-
fit_gaussian_energy
(spectrum)[source]¶ Fits a gausian to the energy of a spectrum.
Parameters: spectrum ( spectra.Spectra
) – Spectrum to be fittedReturns: mean (float), sigma (float) and integral (float) of the spectrum. Return type: tuple
-
gaussian
(x, *p)[source]¶ A gaussian used for fitting.
Parameters: x (float) – Position the gaussian is calculated at. Returns: Value of gaussian at x for given parameters Return type: float
-
test_shift
()[source]¶ Tests the variable shifting method.
Creates a Gaussian spectra with mean energy 2.5 MeV and sigma 0.2 MeV. Radial values of the spectra have a uniform distribution. The “energy_mc” of the spectra is then shifted by 0.111 MeV. The shifted spectra is fitted with a Gaussian and the extracted mean and sigma are checked against expected values within 1 %. Integral of shifted spectrum is checked against original number of entries. This is then repeated for a shift of 0.2 MeV to test the shift_by_bin method.
-
echidna.test.test_smear module¶
-
class
echidna.test.test_smear.
TestSmear
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
-
fit_gaussian_energy
(spectrum)[source]¶ Fits a gausian to the energy of a spectrum.
Parameters: spectrum ( spectra.Spectra
) – Spectrum to be smearedReturns: mean (float), sigma (float) and integral (float) of the spectrum. Return type: tuple
-
fit_gaussian_radius
(spectrum)[source]¶ Fits a gausian to the radius of a spectrum.
Parameters: spectrum ( spectra.Spectra
) – Spectrum to be smearedReturns: mean (float), sigma (float) and integral (float) Return type: tuple
-
fit_poisson_energy
(spectrum)[source]¶ Fits a gausian to the energy of a spectrum.
Parameters: spectrum ( spectra.Spectra
) – Spectrum to be smearedReturns: mean (float), sigma (float) and integral (float) of the spectrum. Return type: tuple
-
gaussian
(x, *p)[source]¶ A gaussian used for fitting.
Parameters: x (float) – Position the gaussian is calculated at. Returns: Value of gaussian at x for given parameters (float) Return type: float
-
poisson
(x, *p)[source]¶ A poisson used for fitting.
Parameters: x (float) – Position the gaussian is calculated at. Returns: Value of poisson at x for given parameters (float) Return type: float
-
test_random_energy_res_gauss
()[source]¶ Tests the random gaussian smearing method for energy resolution.
Creates a delta function and fits the mean and sigma after smearing. Mean and sigma are checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.
-
test_random_energy_res_poiss
()[source]¶ Tests the random gaussian smearing method for energy resolution.
Creates a delta function and fits the mean after smearing. Mean is checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.
-
test_random_radius
()[source]¶ Tests the random gaussian smearing method for radius.
Creates a delta function and fits the mean and sigma after smearing. Mean and sigma are checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.
-
test_weight_energy_ly_gauss
()[source]¶ Tests the weighted gaussian smearing method for energy by light yield.
Creates a delta function and fits the mean and sigma after smearing. Mean and sigma are checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.
-
test_weight_energy_ly_poiss
()[source]¶ Tests the weighted poisson smearing method for energy by light yield.
Creates a delta function and fits the mean after smearing. Mean is checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.
-
test_weight_energy_res_gauss
()[source]¶ Tests the weighted gaussian smearing method for energy resolution.
Creates a delta function and fits the mean and sigma after smearing. Mean and sigma are checked against set values within 1 %. Integral of smeared spectrum is checked against original number of entries.
-
echidna.test.test_spectra module¶
-
class
echidna.test.test_spectra.
TestSpectra
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
-
test_project
()[source]¶ Test the projection method of the spectra.
This creates projected spectra alongside the actual spectra.
-
echidna.test.test_store module¶
echidna.test.test_test_statistic module¶
-
class
echidna.test.test_test_statistic.
TestTestStatistic
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Tests for the
echidna.limit.test_statistic.TestStatistic
class and it’s derived classes.