diff --git a/test/utils/groundtruths.jl b/test/utils/groundtruths.jl deleted file mode 100644 index 56882e3..0000000 --- a/test/utils/groundtruths.jl +++ /dev/null @@ -1,204 +0,0 @@ - -function _groundtruth_incident_flux(in_ps) - s = sum(in_ps) - return s * s -end - -function _groundtruth_matrix_element(in_ps, out_ps) - s_in = sum(in_ps) - s_out = sum(out_ps) - res = s_in * s_in + 1im * (s_out * s_out) - return (res, 2 * res, 3 * res) -end - -function _groundtruth_averaging_norm(proc) - return 1.0 / (number_incoming_particles(proc) + number_outgoing_particles(proc)) -end -function _groundtruth_is_in_phasespace(in_ps, out_ps) - if in_ps[1] == SFourMomentum(zeros(4)) - return false - end - return true -end - -function _groundtruth_phase_space_factor(in_ps, out_ps) - en_in = getE.(in_ps) - en_out = getE.(out_ps) - return 1 / (prod(en_in) * prod(en_out)) -end - -function _groundtruth_generate_momenta(ps_coords) - moms = _furl_moms(ps_coords) - return moms -end - -function _groundtruth_unsafe_probability(proc, in_ps, out_ps) - mat_el = _groundtruth_matrix_element(in_ps, out_ps) - mat_el_sq = abs2.(mat_el) - normalization = _groundtruth_averaging_norm(proc) - ps_fac = _groundtruth_phase_space_factor(in_ps, out_ps) - return sum(mat_el_sq) * ps_fac * normalization -end - -function _groundtruth_unsafe_probability( - proc, in_ps::AbstractVector, out_ps::AbstractMatrix -) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_unsafe_probability(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_unsafe_probability( - proc, in_ps::AbstractMatrix, out_ps::AbstractVector -) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_unsafe_probability(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_unsafe_probability( - proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix -) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_unsafe_probability( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -function _groundtruth_safe_probability(proc, in_ps, out_ps) - if !_groundtruth_is_in_phasespace(in_ps, out_ps) - return zero(Float64) - end - return _groundtruth_unsafe_probability(proc, in_ps, out_ps) -end - -function _groundtruth_safe_probability(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_safe_probability(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_safe_probability(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_safe_probability(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_safe_probability(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_safe_probability( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -function _groundtruth_unsafe_diffCS(proc, in_ps, out_ps) - init_flux = _groundtruth_incident_flux(in_ps) - return _groundtruth_unsafe_probability(proc, in_ps, out_ps) / (4 * init_flux) -end - -function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_unsafe_diffCS(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_unsafe_diffCS(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_unsafe_diffCS( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -function _groundtruth_safe_diffCS(proc, in_ps, out_ps) - if !_groundtruth_is_in_phasespace(in_ps, out_ps) - return zero(Float64) - end - return _groundtruth_unsafe_diffCS(proc, in_ps, out_ps) -end - -function _groundtruth_safe_diffCS(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_safe_diffCS(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_safe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_safe_diffCS(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_safe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_safe_diffCS( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -function _groundtruth_total_probability(in_ps::AbstractVector) - Ptot = sum(in_ps) - return Ptot * Ptot -end - -function _groundtruth_total_probability(in_ps::AbstractMatrix) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_total_probability(view(in_ps, :, i)) - end - return res -end - -function _groundtruth_total_cross_section(in_ps) - init_flux = _groundtruth_incident_flux(in_ps) - return _groundtruth_total_probability(in_ps) / (4 * init_flux) -end - -function _groundtruth_total_cross_section(in_ps::AbstractMatrix) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_total_cross_section(view(in_ps, :, i)) - end - return res -end diff --git a/test/utils/random_momenta.jl b/test/utils/random_momenta.jl deleted file mode 100644 index 3557943..0000000 --- a/test/utils/random_momenta.jl +++ /dev/null @@ -1,53 +0,0 @@ -""" -Return a vector of random four momenta, i.e. a random phase space point -""" -function _rand_momenta(rng::AbstractRNG, N) - moms = Vector{SFourMomentum}(undef, N) - for i in 1:N - moms[i] = SFourMomentum(rand(rng, 4)) - end - return moms -end -""" -Return a matrix of random four momenta, i.e. a collection of phase space points -""" -function _rand_momenta(rng::AbstractRNG, N1, N2) - moms = Matrix{SFourMomentum}(undef, N1, N2) - for i in 1:N1 - for j in 1:N2 - moms[i, j] = SFourMomentum(rand(rng, 4)) - end - end - return moms -end - -""" -Return a random phase space point, which is failing the phase space constraint, -i.e. the first entry of the vector is the null momentum. -""" -function _rand_momenta_failed(rng::AbstractRNG, N) - moms = _rand_momenta(rng, N) - moms[1] = SFourMomentum(zeros(4)) - return moms -end - -""" -Return a collection of phase space points, where the first point is failing the phase space constraint, -i.e. the first entry of the vector is the null momentum, but the others pass. -""" -function _rand_momenta_failed_mix(rng::AbstractRNG, N1, N2) - moms = _rand_momenta(rng, N1, N2) - moms[1, 1] = SFourMomentum(zeros(4)) - return moms -end - -""" -Return a collection of phase space points, where all points are failing the phase space constraint, -i.e. their first entries are null momenta. -""" -function _rand_momenta_failed_all(rng::AbstractRNG, N1, N2) - moms = _rand_momenta(rng, N1, N2) - moms[1, 1] = SFourMomentum(zeros(4)) - moms[1, 2] = SFourMomentum(zeros(4)) - return moms -end diff --git a/test/utils/test_implementations.jl b/test/utils/test_implementations.jl deleted file mode 100644 index 3a8ef8e..0000000 --- a/test/utils/test_implementations.jl +++ /dev/null @@ -1,93 +0,0 @@ - -# dummy particles -struct TestParticle1 <: AbstractParticle end -struct TestParticle2 <: AbstractParticle end -struct TestParticle3 <: AbstractParticle end -struct TestParticle4 <: AbstractParticle end - -PARTICLE_SET = [TestParticle1(), TestParticle2(), TestParticle3(), TestParticle4()] - -# dummy process + failing process -struct TestProcess <: AbstractProcessDefinition end -struct TestProcess_FAIL <: AbstractProcessDefinition end - -# dummy model + failing model -struct TestModel <: AbstractModelDefinition end -struct TestModel_FAIL <: AbstractModelDefinition end - -function QEDprocesses.in_phase_space_dimension(proc::TestProcess, ::TestModel) - return number_incoming_particles(proc) * 4 -end -function QEDprocesses.out_phase_space_dimension(proc::TestProcess, ::TestModel) - return number_outgoing_particles(proc) * 4 -end - -# dummy phase space definition + failing phase space definition -struct TestPhasespaceDef <: AbstractPhasespaceDefinition end -struct TestPhasespaceDef_FAIL <: AbstractPhasespaceDefinition end - -# dummy implementation of the process interface - -function QEDprocesses._incident_flux( - ::TestProcess, ::TestModel, in_ps::AbstractVector{T} -) where {T<:QEDbase.AbstractFourMomentum} - return _groundtruth_incident_flux(in_ps) -end - -function QEDprocesses._averaging_norm(proc::TestProcess) - return _groundtruth_averaging_norm(proc) -end - -function QEDprocesses._matrix_element( - ::TestProcess, ::TestModel, in_ps::AbstractVector{T}, out_ps::AbstractVector{T} -) where {T<:QEDbase.AbstractFourMomentum} - return _groundtruth_matrix_element(in_ps, out_ps) -end - -function QEDprocesses._is_in_phasespace( - ::TestProcess, - ::TestModel, - in_ps_def::TestPhasespaceDef, - in_ps::AbstractVector{T}, - out_ps_def::TestPhasespaceDef, - out_ps::AbstractVector{T}, -) where {T<:QEDbase.AbstractFourMomentum} - return _groundtruth_is_in_phasespace(in_ps, out_ps) -end - -function QEDprocesses._phase_space_factor( - ::TestProcess, - ::TestModel, - in_ps_def::TestPhasespaceDef, - in_ps::AbstractVector{T}, - out_ps_def::TestPhasespaceDef, - out_ps::AbstractVector{T}, -) where {T<:QEDbase.AbstractFourMomentum} - return _groundtruth_phase_space_factor(in_ps, out_ps) -end - -function QEDprocesses._generate_incoming_momenta( - proc::TestProcess, - model::TestModel, - in_phase_space_def::TestPhasespaceDef, - in_phase_space::AbstractVector{T}, -) where {T<:Real} - return _groundtruth_generate_momenta(in_phase_space) -end - -function QEDprocesses._generate_outgoing_momenta( - proc::TestProcess, - model::TestModel, - out_phase_space_def::TestPhasespaceDef, - out_phase_space::AbstractVector{T}, -) where {T<:Real} - return _groundtruth_generate_momenta(out_phase_space) -end -function QEDprocesses._total_probability( - proc::TestProcess, - model::TestModel, - in_ps_def::TestPhasespaceDef, - in_ps::AbstractVector{T}, -) where {T<:QEDbase.AbstractFourMomentum} - return _groundtruth_total_probability(in_ps) -end diff --git a/test/utils/utils.jl b/test/utils/utils.jl deleted file mode 100644 index 1500589..0000000 --- a/test/utils/utils.jl +++ /dev/null @@ -1,42 +0,0 @@ -include("random_momenta.jl") -include("groundtruths.jl") -include("test_implementations.jl") - -# Check if any failed type is containted -_any_fail(x...) = true -_any_fail(::TestProcess, ::TestModel) = false -_any_fail(::TestProcess, ::TestModel, ::TestPhasespaceDef, ::TestPhasespaceDef) = false - -# unrolls all elements of a list of four-momenta into vector of coordinates -function _unroll_moms(ps_moms::AbstractVector{T}) where {T<:QEDbase.AbstractFourMomentum} - return collect(Iterators.flatten(ps_moms)) -end - -function _unroll_moms(ps_moms::AbstractMatrix{T}) where {T<:QEDbase.AbstractFourMomentum} - res = Matrix{eltype(T)}(undef, size(ps_moms, 1) * 4, size(ps_moms, 2)) - for i in 1:size(ps_moms, 2) - res[:, i] .= _unroll_moms(view(ps_moms, :, i)) - end - return res -end - -flat_components(moms) = _unroll_moms(moms) - -# collect components of four-momenta from a vector of coordinates -function __furl_moms(ps_coords::AbstractVector{T}) where {T<:Real} - return SFourMomentum.(eachcol(reshape(ps_coords, 4, :))) -end - -function _furl_moms(ps_coords::AbstractVector{T}) where {T<:Real} - @assert length(ps_coords) % 4 == 0 - return __furl_moms(ps_coords) -end - -function _furl_moms(ps_coords::AbstractMatrix{T}) where {T<:Real} - @assert size(ps_coords, 1) % 4 == 0 - res = Matrix{SFourMomentum}(undef, Int(size(ps_coords, 1)//4), size(ps_coords, 2)) - for i in 1:size(ps_coords, 2) - res[:, i] .= __furl_moms(view(ps_coords, :, i)) - end - return res -end