Skip to content

Commit 341bc8e

Browse files
author
Uwe Hernandez Acosta
committed
added tests for perturbative compton
1 parent 5054b76 commit 341bc8e

File tree

5 files changed

+210
-0
lines changed

5 files changed

+210
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
"""
3+
Klein-Nishina: differential cross section
4+
5+
source: Peskin, Schroeder. "Quantum field theory." (1995). eq: 5.91
6+
note: we compute d sigma/ d Omega, and *not* d sigma/ d cos theta (the difference is a factor 2 pi)
7+
8+
"""
9+
function _groundtruth_pert_compton_diffCS_spinsum_polsum(om, cth, mass)
10+
prefac = ALPHA_SQUARE / 2
11+
omp = QEDprocesses._pert_omega_prime(om, cth)
12+
sth_sq = 1 - cth^2
13+
return prefac * (omp / om)^2 * (omp / om + om / omp - sth_sq)
14+
end
15+
16+
function _groundtruth_pert_compton_diffCS_spinsum_xpol(omega, ctheta, phi, mass)
17+
om_prime = omega_prime(PerturbativeQED(), omega, ctheta; mass=mass)
18+
om_prime_over_om = om_prime / omega
19+
return 0.5 * ALPHA_SQUARE / mass^2 *
20+
om_prime_over_om^2 *
21+
(om_prime_over_om + 1.0 / om_prime_over_om - 2 * (1 - ctheta^2) * cos(phi)^2)
22+
end
23+
24+
function _groundtruth_pert_compton_diffCS_spinsum_ypol(omega, ctheta, phi, mass)
25+
return _groundtruth_pert_compton_diffCS_spinsum_xpol(omega, ctheta, phi + pi / 2, mass)
26+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
2+
using QEDbase
3+
using QEDprocesses
4+
using Random
5+
using StaticArrays
6+
using QuadGK
7+
8+
RNG = MersenneTwister(77697185)
9+
ATOL = eps()
10+
RTOL = sqrt(eps())
11+
12+
include("groundtruths.jl")
13+
14+
MODEL = PerturbativeQED()
15+
PS_DEF = PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame())
16+
OMEGAS = (1e-6 * rand(RNG), 1e-3 * rand(RNG), rand(RNG), 1e3 * rand(RNG))
17+
#OMEGAS = (rand(RNG),)
18+
19+
COS_THETAS = [-1.0, 2 * rand(RNG) - 1, 0.0, 1.0]
20+
PHIS = [0, 2 * pi, rand(RNG) * 2 * pi]
21+
22+
@testset "perturbative kinematics" begin
23+
PROC = Compton()
24+
@testset "momentum generation" begin
25+
@testset "$om, $cth, $phi" for (om, cth, phi) in
26+
Iterators.product(OMEGAS, COS_THETAS, PHIS)
27+
IN_COORDS = [om]
28+
OUT_COORDS = [cth, phi]
29+
IN_PS, OUT_PS = QEDprocesses._generate_momenta(
30+
PROC, MODEL, PS_DEF, IN_COORDS, PS_DEF, OUT_COORDS
31+
)
32+
in_mom_square = getMass2.(IN_PS)
33+
out_mom_square = getMass2.(OUT_PS)
34+
in_masses = mass.(incoming_particles(PROC)) .^ 2
35+
out_masses = mass.(outgoing_particles(PROC))
36+
@test isapprox(in_mom_square, SVector(in_masses))
37+
@test isapprox(out_mom_square, SVector(out_masses))
38+
end
39+
end
40+
end
41+
42+
@testset "perturbative cross section" begin
43+
@testset "$omega" for omega in OMEGAS
44+
@testset "differential cross section" begin
45+
@testset "spin and pol summed" begin
46+
PROC = Compton()
47+
48+
@testset "$cos_theta $phi" for (cos_theta, phi) in
49+
Iterators.product(COS_THETAS, PHIS)
50+
IN_COORDS = [omega]
51+
OUT_COORDS = [cos_theta, phi]
52+
groundtruth = _groundtruth_pert_compton_diffCS_spinsum_polsum(
53+
omega, cos_theta, 1.0
54+
)
55+
test_val = unsafe_differential_cross_section(
56+
PROC, MODEL, PS_DEF, IN_COORDS, PS_DEF, OUT_COORDS
57+
)
58+
@test isapprox(test_val, groundtruth, atol=ATOL, rtol=RTOL)
59+
end
60+
end
61+
62+
@testset "x-pol and spin summed" begin
63+
PROC = Compton(PolX())
64+
65+
@testset "$cos_theta $phi" for (cos_theta, phi) in
66+
Iterators.product(COS_THETAS, PHIS)
67+
IN_COORDS = [omega]
68+
OUT_COORDS = [cos_theta, phi]
69+
groundtruth = _groundtruth_pert_compton_diffCS_spinsum_xpol(
70+
omega, cos_theta, phi, 1.0
71+
)
72+
test_val = unsafe_differential_cross_section(
73+
PROC, MODEL, PS_DEF, IN_COORDS, PS_DEF, OUT_COORDS
74+
)
75+
@test isapprox(test_val, groundtruth, atol=ATOL, rtol=RTOL)
76+
end
77+
end
78+
79+
@testset "y-pol and spin summed" begin
80+
PROC = Compton(PolY())
81+
82+
@testset "$cos_theta $phi" for (cos_theta, phi) in
83+
Iterators.product(COS_THETAS, PHIS)
84+
IN_COORDS = [omega]
85+
OUT_COORDS = [cos_theta, phi]
86+
groundtruth = _groundtruth_pert_compton_diffCS_spinsum_ypol(
87+
omega, cos_theta, phi, 1.0
88+
)
89+
test_val = unsafe_differential_cross_section(
90+
PROC, MODEL, PS_DEF, IN_COORDS, PS_DEF, OUT_COORDS
91+
)
92+
@test isapprox(test_val, groundtruth, atol=ATOL, rtol=RTOL)
93+
end
94+
end
95+
end
96+
end
97+
# @testset "total cross section" begin
98+
# @testset "spin and pol summed" begin
99+
# PROC = Compton()
100+
# # Klein-Nishina: total cross section
101+
# function klein_nishina_total_cross_section(om, mass)
102+
# function func(x)
103+
# return differential_cross_section_on_coord(
104+
# Compton(), PerturbativeQED(), om, [x, 0.0]
105+
# )
106+
# end
107+
# res, err = quadgk(func, -1, 1)
108+
#
109+
# # note: mul by 2pi instead of the phi-integration
110+
# return 2 * pi * res
111+
# end
112+
#
113+
# groundtruth = klein_nishina_total_cross_section(OMEGA, MASS)
114+
# test_val = @inferred total_cross_section_on_coord(PROC, MODEL, OMEGA)
115+
# @test isapprox(test_val, groundtruth, atol=ATOL, rtol=RTOL)
116+
# end
117+
# end
118+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using QEDprocesses
2+
using Random
3+
using QEDbase
4+
using QEDprocesses
5+
6+
POLS = [PolX(), PolY(), AllPol()]
7+
SPINS = [SpinUp(), SpinDown(), AllSpin()]
8+
POL_AND_SPIN_COMBINATIONS = Iterators.product(SPINS, POLS, SPINS, POLS)
9+
POL_COMBINATIONS = Iterators.product(POLS, POLS)
10+
11+
@testset "constructor" begin
12+
@testset "default" begin
13+
proc = Compton()
14+
@test QEDprocesses._spin_or_pol(proc, Photon(), Incoming()) == AllPol()
15+
@test QEDprocesses._spin_or_pol(proc, Electron(), Incoming()) == AllSpin()
16+
@test QEDprocesses._spin_or_pol(proc, Photon(), Outgoing()) == AllPol()
17+
@test QEDprocesses._spin_or_pol(proc, Electron(), Outgoing()) == AllSpin()
18+
end
19+
20+
@testset "in_pol" begin
21+
@testset "$pol" for pol in POLS
22+
proc = Compton(pol)
23+
@test QEDprocesses._spin_or_pol(proc, Electron(), Incoming()) == AllSpin()
24+
@test QEDprocesses._spin_or_pol(proc, Photon(), Incoming()) == pol
25+
@test QEDprocesses._spin_or_pol(proc, Electron(), Outgoing()) == AllSpin()
26+
@test QEDprocesses._spin_or_pol(proc, Photon(), Outgoing()) == AllPol()
27+
end
28+
end
29+
30+
@testset "in_pol+out_pol" begin
31+
@testset "$in_pol, $out_pol" for (in_pol, out_pol) in POL_COMBINATIONS
32+
proc = Compton(in_pol, out_pol)
33+
@test QEDprocesses._spin_or_pol(proc, Electron(), Incoming()) == AllSpin()
34+
@test QEDprocesses._spin_or_pol(proc, Photon(), Incoming()) == in_pol
35+
@test QEDprocesses._spin_or_pol(proc, Electron(), Outgoing()) == AllSpin()
36+
@test QEDprocesses._spin_or_pol(proc, Photon(), Outgoing()) == out_pol
37+
end
38+
end
39+
@testset "all spins+pols" begin
40+
@testset "$in_spin, $in_pol, $out_spin, $out_pol" for (
41+
in_spin, in_pol, out_spin, out_pol
42+
) in POL_AND_SPIN_COMBINATIONS
43+
proc = Compton(in_spin, in_pol, out_spin, out_pol)
44+
@test QEDprocesses._spin_or_pol(proc, Electron(), Incoming()) == in_spin
45+
@test QEDprocesses._spin_or_pol(proc, Photon(), Incoming()) == in_pol
46+
@test QEDprocesses._spin_or_pol(proc, Electron(), Outgoing()) == out_spin
47+
@test QEDprocesses._spin_or_pol(proc, Photon(), Outgoing()) == out_pol
48+
end
49+
end
50+
end
51+
@testset "particle content" begin
52+
proc = Compton()
53+
@test incoming_particles(proc) == (Electron(), Photon())
54+
@test outgoing_particles(proc) == (Electron(), Photon())
55+
@test number_incoming_particles(proc) == 2
56+
@test number_outgoing_particles(proc) == 2
57+
end

test/processes/run_process_test.jl

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
@time @safetestset "general one photon compton" begin
3+
include("one_photon_compton/process.jl")
4+
end
5+
6+
@time @safetestset "perturbative one photon compton" begin
7+
include("one_photon_compton/perturbative.jl")
8+
end

test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ begin
2121
@time @safetestset "cross section & probability" begin
2222
include("cross_sections.jl")
2323
end
24+
include("processes/run_process_test.jl")
2425
end

0 commit comments

Comments
 (0)