-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sofia Calgaro
committed
Dec 30, 2024
1 parent
5685f6e
commit 138636a
Showing
9 changed files
with
280 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,8 @@ Pages = [ | |
"installation.md", | ||
"config.md", | ||
"inputs.md", | ||
"toys.md" | ||
"toys.md", | ||
"tutorial.md" | ||
] | ||
Depth = 1 | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
using Test | ||
|
||
Test.@testset "likelihood" begin | ||
Test.@testset "statistics" begin | ||
include("test_get_signal_pdf.jl") | ||
include("test_get_mu_s_b.jl") | ||
include("test_build_likelihood_zero_obs_evts.jl") | ||
include("test_build_likelihood_per_partition.jl") | ||
include("test_inverse_uniform_cdf.jl") | ||
include("test_generate_disjoint_uniform_samples.jl") | ||
include("test_get_bkg_info.jl") | ||
end |
102 changes: 102 additions & 0 deletions
102
test/statistics/test_generate_disjoint_uniform_samples.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using Pkg | ||
Pkg.activate(".") | ||
Pkg.instantiate() | ||
using Random | ||
include("../../src/ZeroNuFit.jl") | ||
using .ZeroNuFit | ||
include("../../main.jl") | ||
include("../../src/utils.jl") | ||
|
||
@testset "test_generate_disjoint_uniform_samples" begin | ||
|
||
@info "Testing function for getting random 'n' energies (function 'generate_disjoint_uniform_samples' in src/utils.jl)" | ||
|
||
# fixed seed (1 energy, 1 range) | ||
one_energy = nothing | ||
fit_range = [[1920.0,1930.0]] | ||
try | ||
one_energy = ZeroNuFit.generate_disjoint_uniform_samples(1, fit_range; seed=123) | ||
catch e | ||
@error "Error in 'generate_disjoint_uniform_samples' evaluation: $e" | ||
throw(e) | ||
end | ||
|
||
@testset "Check one_energy is valid (fixed seed)" begin | ||
@test !isnothing(one_energy) | ||
end | ||
|
||
expected_value = [1925.212137955354] | ||
@testset "Check energy accuracy (fixed seed)" begin | ||
@test one_energy == expected_value | ||
end | ||
|
||
function check_in_ranges(energies, fit_range) | ||
return [any(e >= r[1] && e <= r[2] for r in fit_range) for e in energies] | ||
end | ||
|
||
@testset "Check energy containment in fit range (fixed seed)" begin | ||
contained = check_in_ranges(one_energy, fit_range) | ||
@test all(contained) | ||
end | ||
|
||
# random seed generator (1 energy, 1 range) | ||
one_energy = nothing | ||
try | ||
one_energy = ZeroNuFit.generate_disjoint_uniform_samples(1, fit_range) | ||
catch e | ||
@error "Error in 'generate_disjoint_uniform_samples' evaluation: $e" | ||
throw(e) | ||
end | ||
|
||
@testset "Check one_energy is valid (random seed)" begin | ||
@test !isnothing(one_energy) | ||
end | ||
|
||
expected_value = [1925.212137955354] | ||
@testset "Check energy accuracy (random seed, 1 energy)" begin | ||
@test one_energy != expected_value | ||
end | ||
|
||
@testset "Check energy containment in fit range (random seed, 1 energy)" begin | ||
contained = check_in_ranges(one_energy, fit_range) | ||
@test all(contained) | ||
end | ||
|
||
# random seed generator (more energies, 1 range) | ||
more_energies = nothing | ||
try | ||
more_energies = ZeroNuFit.generate_disjoint_uniform_samples(10, fit_range) | ||
catch e | ||
@error "Error in 'generate_disjoint_uniform_samples' evaluation: $e" | ||
throw(e) | ||
end | ||
|
||
@testset "Check more_energies is valid (random seed, more energies)" begin | ||
@test !isnothing(more_energies) | ||
end | ||
|
||
@testset "Check energy containment in fit range (random seed, more energies)" begin | ||
contained = check_in_ranges(more_energies, fit_range) | ||
@test all(contained) | ||
end | ||
|
||
# random seed generator (more energies, more ranges) | ||
more_energies = nothing | ||
fit_range = [[1920.0,1930.0], [1970.0,1980.0], [2100.0,2250.0]] | ||
try | ||
more_energies = ZeroNuFit.generate_disjoint_uniform_samples(10, fit_range) | ||
catch e | ||
@error "Error in 'generate_disjoint_uniform_samples' evaluation: $e" | ||
throw(e) | ||
end | ||
|
||
@testset "Check more_energies is valid (random seed, more energies, more ranges)" begin | ||
@test !isnothing(more_energies) | ||
end | ||
|
||
@testset "Check energy containment in fit range (random seed, more energies, more ranges)" begin | ||
contained = check_in_ranges(more_energies, fit_range) | ||
@test all(contained) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Pkg | ||
Pkg.activate(".") | ||
Pkg.instantiate() | ||
using Random | ||
include("../../src/ZeroNuFit.jl") | ||
using .ZeroNuFit | ||
include("../../main.jl") | ||
|
||
@testset "test_get_bkg_info" begin | ||
|
||
@info "Testing gaussian signal for one partition and one close event @ 2039.05 keV (function 'get_bkg_info' in src/fitting.jl)" | ||
|
||
# default modeling, i.e. flat | ||
config = Dict( | ||
"bkg" => Dict() | ||
) | ||
|
||
bkg_shape = nothing | ||
bkg_shape_pars = nothing | ||
try | ||
bkg_shape,bkg_shape_pars = ZeroNuFit.get_bkg_info(config) | ||
catch e | ||
@error "Error in 'get_bkg_info' evaluation: $e" | ||
throw(e) | ||
end | ||
|
||
expected_value = :uniform | ||
@testset "Check bkg_shape accuracy" begin | ||
@test bkg_shape == expected_value | ||
end | ||
expected_value = nothing | ||
@testset "Check bkg_shape_pars accuracy" begin | ||
@test bkg_shape_pars == expected_value | ||
end | ||
|
||
# linear modeling | ||
config = Dict("bkg" => Dict("shape" => Dict("name" => "linear", "pars" => Dict("slope" => [-10, 10])))) | ||
|
||
bkg_shape = nothing | ||
bkg_shape_pars = nothing | ||
try | ||
bkg_shape,bkg_shape_pars = ZeroNuFit.get_bkg_info(config) | ||
catch e | ||
@error "Error in 'get_bkg_info' evaluation: $e" | ||
throw(e) | ||
end | ||
|
||
expected_value = :linear | ||
@testset "Check bkg_shape accuracy" begin | ||
@test bkg_shape == expected_value | ||
end | ||
expected_value = Dict("slope" => [-10, 10]) | ||
@testset "Check bkg_shape_pars accuracy" begin | ||
@test bkg_shape_pars == expected_value | ||
end | ||
|
||
# exponential modeling | ||
config = Dict("bkg" => Dict("shape" => Dict("name" => "exponential", "pars" => Dict("slope" => [-5, 5])))) | ||
|
||
bkg_shape = nothing | ||
bkg_shape_pars = nothing | ||
try | ||
bkg_shape,bkg_shape_pars = ZeroNuFit.get_bkg_info(config) | ||
catch e | ||
@error "Error in 'get_bkg_info' evaluation: $e" | ||
throw(e) | ||
end | ||
|
||
expected_value = :exponential | ||
@testset "Check bkg_shape accuracy" begin | ||
@test bkg_shape == expected_value | ||
end | ||
expected_value = Dict("slope" => [-5, 5]) | ||
@testset "Check bkg_shape_pars accuracy" begin | ||
@test bkg_shape_pars == expected_value | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Test | ||
|
||
Test.@testset "likelihood" begin | ||
include("test_get_range.jl") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Pkg | ||
Pkg.activate(".") # activate the environment | ||
Pkg.instantiate() # instantiate the environment | ||
include("../../src/ZeroNuFit.jl") | ||
using .ZeroNuFit | ||
include("../../main.jl") | ||
|
||
@testset "test_get_range" begin | ||
|
||
@info "Testing function to retrieve lower and upper range edges (function 'get_range' in src/fitting.jl)" | ||
|
||
# 1 entry in fit ranges | ||
fit_ranges = [[1930.0, 1950.0]] | ||
range_l = nothing | ||
range_h = nothing | ||
try | ||
range_l, range_h = ZeroNuFit.get_range(fit_ranges) | ||
catch e | ||
@error "Error in get_range: $e" | ||
throw(e) | ||
end | ||
|
||
@testset "Check range_l is valid" begin | ||
@test !isnothing(range_l) | ||
end | ||
@testset "Check range_h is valid" begin | ||
@test !isnothing(range_h) | ||
end | ||
|
||
expected_events=[1930.0] | ||
@testset "Check events accuracy" begin | ||
@test range_l == expected_events | ||
end | ||
expected_events=[1950.0] | ||
@testset "Check events accuracy" begin | ||
@test range_h == expected_events | ||
end | ||
|
||
# more entries in fit ranges | ||
fit_ranges = [[1930.0, 1950.0], [2100.0,2200.0], [1450.0, 1500.0]] | ||
range_l = nothing | ||
range_h = nothing | ||
try | ||
range_l, range_h = ZeroNuFit.get_range(fit_ranges) | ||
catch e | ||
@error "Error in get_range: $e" | ||
throw(e) | ||
end | ||
|
||
@testset "Check range_l is valid" begin | ||
@test !isnothing(range_l) | ||
end | ||
@testset "Check range_h is valid" begin | ||
@test !isnothing(range_h) | ||
end | ||
|
||
expected_events=[1450.0, 1930.0, 2100.0] | ||
@testset "Check events accuracy" begin | ||
@test range_l == expected_events | ||
end | ||
expected_events=[1500.0, 1950.0, 2200.0] | ||
@testset "Check events accuracy" begin | ||
@test range_h == expected_events | ||
end | ||
end | ||
|