Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/constants.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# FIXME: implement the constants

"""
ELECTRON_MASS
ELECTRON_MASS

The mass of the electron in its rest frame, given as 0.51099895000 MeV

Expand All @@ -12,7 +10,7 @@ This value is taken from the PDG 2020 recommended values of the fundamental phys
- The Review of Particle Physics: P.A. Zyla et al. (Particle Data Group), Prog. Theor. Exp. Phys. 2020, 083C01 (2020)

"""
ELECTRON_MASS
const ELECTRON_MASS = 0.51099895000

"""
MUON_MASS
Expand All @@ -25,7 +23,7 @@ This value is taken from the PDG 2020 recommended values of the fundamental phys
- The Review of Particle Physics: P.A. Zyla et al. (Particle Data Group), Prog. Theor. Exp. Phys. 2020, 083C01 (2020)

"""
MUON_MASS
const MUON_MASS = 105.6583755

"""
ALPHA
Expand All @@ -38,4 +36,5 @@ This value is taken from the PDG 2020 recommended values of the fundamental phys
- The Review of Particle Physics: P.A. Zyla et al. (Particle Data Group), Prog. Theor. Exp. Phys. 2020, 083C01 (2020)

"""
ALPHA
const ALPHA = 0.0072973525643
const ALPHA_UNC = 0.0000000000011
28 changes: 15 additions & 13 deletions src/cross_section.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

@inline function _rho(E,m)
#
# FIXME: implement this!
#
@inline function _rho(E, m)
sqrt(E^2 - m^2)
end

"""
differential_cross_section(E_in::Real, cos_theta::Real)
differential_cross_section(E_in::Real, cos_theta::Real)

Calculates the differential cross section for the process ``e^+ e^- \\to \\mu^+ \\mu^-``
at tree level in quantum electrodynamics (QED). The calculation is performed in the center-of-momentum
Expand All @@ -32,7 +30,7 @@

# Example

```jldoctest

Check failure on line 33 in src/cross_section.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/cross_section.jl:33-43 ```jldoctest julia> E_in = 1e3 # MeV 1000.0 julia> cos_theta = 0.5 0.5 julia> differential_cross_section(E_in, cos_theta) 4.164686491998452e-12 SIMONE: this is wrong, correct value is 4.188129051838138e-12 ``` Subexpression: differential_cross_section(E_in, cos_theta) Evaluated output: 4.164686491998452e-12 Expected output: 4.164686491998452e-12 SIMONE: this is wrong, correct value is 4.188129051838138e-12 diff = Warning: Diff output requires color. 4.164686491998452e-12 SIMONE: this is wrong, correct value is 4.188129051838138e-124.164686491998452e-12

Check failure on line 33 in src/cross_section.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/cross_section.jl:33-43 ```jldoctest julia> E_in = 1e3 # MeV 1000.0 julia> cos_theta = 0.5 0.5 julia> differential_cross_section(E_in, cos_theta) 4.164686491998452e-12 SIMONE: this is wrong, correct value is 4.188129051838138e-12 ``` Subexpression: differential_cross_section(E_in, cos_theta) Evaluated output: 4.164686491998452e-12 Expected output: 4.164686491998452e-12 SIMONE: this is wrong, correct value is 4.188129051838138e-12 diff = Warning: Diff output requires color. 4.164686491998452e-12 SIMONE: this is wrong, correct value is 4.188129051838138e-124.164686491998452e-12
julia> E_in = 1e3 # MeV
1000.0

Expand All @@ -40,20 +38,22 @@
0.5

julia> differential_cross_section(E_in, cos_theta)
4.164686491998452e-12
4.164686491998452e-12
SIMONE: this is wrong, correct value is 4.188129051838138e-12
```

# References
- Schwartz 2014: M.D. Schwartz, "Quantum Field Theory and the Standard Model", Cambridge University Press, New York (2014)
"""
function differential_cross_section(E_in, cos_theta)
#
# FIXME: fill me in
#
rho_e = _rho(E_in, ELECTRON_MASS)
rho_mu = _rho(E_in, MUON_MASS)
tmp = (E_in^4 + rho_e^2 * rho_mu^2 * (cos_theta)^2 + E_in^2 * (ELECTRON_MASS^2+MUON_MASS^2))
return tmp * ALPHA^2 * rho_mu / (16.0 * E_in^6) / rho_e
end

"""
total_cross_section(E_in::Real)
total_cross_section(E_in::Real)

Calculates the total cross section for the process ``e^+ e^- \\to \\mu^+ \\mu^-`` at tree level,
as a function of the initial electron energy `E_in`.
Expand Down Expand Up @@ -85,9 +85,11 @@
```
"""
function total_cross_section(E_in)
#
# FIXME: fill me in
#
rho_e = _rho(E_in, ELECTRON_MASS)
rho_mu = _rho(E_in, MUON_MASS)
pref = pi * (ALPHA^2) * rho_mu / (8.0 * E_in^6) / rho_e
tmp = (2.0 * E_in^4 + 2.0 * rho_e^2 * rho_mu^2 / 3.0 + 2.0 * E_in^2 * (ELECTRON_MASS^2+MUON_MASS^2))
return pref * tmp
end


Expand Down
85 changes: 68 additions & 17 deletions src/four_momentum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
FourMomentum(en = 4.0, x = 1.0, y = 2.0, z = 3.0)
```
"""
struct FourMomentum{T<:Real}
#
# FIXME: fill me in
#
struct FourMomentum{T<:Real}
en::T # Energy component
x::T # Spatial component in the x-direction
y::T # Spatial component in the y-direction
z::T # Spatial component in the z-direction
end
# type promotion on construction
FourMomentum(en,x,y,z) = FourMomentum(promote(en,x,y,z)...)

# return the element type
function Base.eltype(::FourMomentum{T}) where T
#
# FIXME:
#
return T
end

# Overload Base.show for pretty printing of FourMomentum; plain text version
Expand Down Expand Up @@ -72,7 +71,8 @@
"""
function Base.:+(p1::FourMomentum, p2::FourMomentum)

# FIXME: fill me in
#element-wise addition of the four-momentum components
return FourMomentum(p1.en + p2.en, p1.x + p2.x, p1.y + p2.y, p1.z + p2.z)

end

Expand All @@ -98,7 +98,8 @@
```
"""
function Base.:-(p1::FourMomentum, p2::FourMomentum)
# FIXME: fill me in
# element-wise subtraction of the four-momentum components
return FourMomentum(p1.en - p2.en, p1.x - p2.x, p1.y - p2.y, p1.z - p2.z)
end


Expand All @@ -120,7 +121,8 @@
```
"""
function Base.:*(a::Real, p::FourMomentum)
# FIXME: fill me in
# scalar multiplication of the four-momentum components
return FourMomentum(a * p.en, a * p.x, a * p.y, a * p.z)
end


Expand Down Expand Up @@ -149,17 +151,35 @@
"""
function minkowski_dot(p1::FourMomentum, p2::FourMomentum)
# Minkowski metric: (+,-,-,-)
# FIXME: fill me in
return p1.en * p2.en - p1.x * p2.x - p1.y * p2.y - p1.z * p2.z
end

function _construct_moms_from_coords(E_in, cos_theta, phi)
#
# FIXME: fill me in
#
# Calculate the energy and momentum components for the electron-positron pair
E = E_in / 2 # Each particle has half the total energy in the center-of-mass frame
p = sqrt(E^2 - ELECTRON_MASS) # Assuming electron mass is 0.511 MeV/c^2

# Calculate the spatial components based on the scattering angle and azimuthal angle
px = p * sqrt(1 - cos_theta^2) * cos(phi)
py = p * sqrt(1 - cos_theta^2) * sin(phi)
pz = p * cos_theta

# Construct four-momenta for e-, e+, mu-, mu+
e_minus = FourMomentum(E, px, py, pz)
e_plus = FourMomentum(E, -px, -py, -pz)
mu_minus = FourMomentum(E, px, py, pz)
mu_plus = FourMomentum(E, -px, -py, -pz)

return Dict("e-" => e_minus, "e+" => e_plus, "mu-" => mu_minus, "mu+" => mu_plus)
end

# TODO:
# consider using NamedTuples instead





"""
coords_to_dict(E_in::Real, cos_theta::Real, phi::Real)

Expand All @@ -172,7 +192,7 @@

# Example

```jldoctest

Check failure on line 195 in src/four_momentum.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/four_momentum.jl:195-217 ```jldoctest julia> mom_dict = coords_to_dict(1e3,0.9,pi/4) Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… julia> mom_dict["e-"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) julia> mom_dict["e+"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) julia> mom_dict["mu-"] FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) julia> mom_dict["mu+"] FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) ``` Subexpression: mom_dict = coords_to_dict(1e3,0.9,pi/4) Evaluated output: Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (500.0, -154.110193, -154.110193, -449.99954)… "mu-" => (500.0, 154.110193, 154.110193, 449.99954)… "e+" => (500.0, -154.110193, -154.110193, -449.99954)… "e-" => (500.0, 154.110193, 154.110193, 449.99954)… Expected output: Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… diff = Warning: Diff output requires color. Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… (500.0, -154.110193, -154.110193, -449.99954)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… (500.0, 154.110193, 154.110193, 449.99954)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… (500.0, -154.110193, -154.110193, -449.99954)… "e-" => (1000.0, 0.0, 0.0, 999.999869)…(500.0, 154.110193, 154.110193, 449.99954)…

Check failure on line 195 in src/four_momentum.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/four_momentum.jl:195-217 ```jldoctest julia> mom_dict = coords_to_dict(1e3,0.9,pi/4) Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… julia> mom_dict["e-"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) julia> mom_dict["e+"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) julia> mom_dict["mu-"] FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) julia> mom_dict["mu+"] FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) ``` Subexpression: mom_dict["e-"] Evaluated output: FourMomentum(en = 500.0, x = 154.11019257368977, y = 154.11019257368974, z = 449.99954010071) Expected output: FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) diff = Warning: Diff output requires color. FourMomentum(en = 1000.0, 500.0, x = 0.0, 154.11019257368977, y = 0.0, 154.11019257368974, z = 999.999869440028)449.99954010071)

Check failure on line 195 in src/four_momentum.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/four_momentum.jl:195-217 ```jldoctest julia> mom_dict = coords_to_dict(1e3,0.9,pi/4) Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… julia> mom_dict["e-"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) julia> mom_dict["e+"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) julia> mom_dict["mu-"] FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) julia> mom_dict["mu+"] FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) ``` Subexpression: mom_dict["e+"] Evaluated output: FourMomentum(en = 500.0, x = -154.11019257368977, y = -154.11019257368974, z = -449.99954010071) Expected output: FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) diff = Warning: Diff output requires color. FourMomentum(en = 1000.0, 500.0, x = 0.0, -154.11019257368977, y = 0.0, -154.11019257368974, z = -999.999869440028)-449.99954010071)

Check failure on line 195 in src/four_momentum.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/four_momentum.jl:195-217 ```jldoctest julia> mom_dict = coords_to_dict(1e3,0.9,pi/4) Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… julia> mom_dict["e-"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) julia> mom_dict["e+"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) julia> mom_dict["mu-"] FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) julia> mom_dict["mu+"] FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) ``` Subexpression: mom_dict["mu-"] Evaluated output: FourMomentum(en = 500.0, x = 154.11019257368977, y = 154.11019257368974, z = 449.99954010071) Expected output: FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) diff = Warning: Diff output requires color. FourMomentum(en = 1000.0, 500.0, x = 306.4954310103767, 154.11019257368977, y = 306.49543101037665, 154.11019257368974, z = 894.9622389946002)449.99954010071)

Check failure on line 195 in src/four_momentum.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/four_momentum.jl:195-217 ```jldoctest julia> mom_dict = coords_to_dict(1e3,0.9,pi/4) Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… julia> mom_dict["e-"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) julia> mom_dict["e+"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) julia> mom_dict["mu-"] FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) julia> mom_dict["mu+"] FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) ``` Subexpression: mom_dict["mu+"] Evaluated output: FourMomentum(en = 500.0, x = -154.11019257368977, y = -154.11019257368974, z = -449.99954010071) Expected output: FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) diff = Warning: Diff output requires color. FourMomentum(en = 1000.0, 500.0, x = -306.4954310103767, -154.11019257368977, y = -306.49543101037665, -154.11019257368974, z = -894.9622389946002)-449.99954010071)

Check failure on line 195 in src/four_momentum.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/four_momentum.jl:195-217 ```jldoctest julia> mom_dict = coords_to_dict(1e3,0.9,pi/4) Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… julia> mom_dict["e-"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) julia> mom_dict["e+"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) julia> mom_dict["mu-"] FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) julia> mom_dict["mu+"] FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) ``` Subexpression: mom_dict = coords_to_dict(1e3,0.9,pi/4) Evaluated output: Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (500.0, -154.110193, -154.110193, -449.99954)… "mu-" => (500.0, 154.110193, 154.110193, 449.99954)… "e+" => (500.0, -154.110193, -154.110193, -449.99954)… "e-" => (500.0, 154.110193, 154.110193, 449.99954)… Expected output: Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… diff = Warning: Diff output requires color. Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… (500.0, -154.110193, -154.110193, -449.99954)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… (500.0, 154.110193, 154.110193, 449.99954)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… (500.0, -154.110193, -154.110193, -449.99954)… "e-" => (1000.0, 0.0, 0.0, 999.999869)…(500.0, 154.110193, 154.110193, 449.99954)…

Check failure on line 195 in src/four_momentum.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/four_momentum.jl:195-217 ```jldoctest julia> mom_dict = coords_to_dict(1e3,0.9,pi/4) Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… julia> mom_dict["e-"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) julia> mom_dict["e+"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) julia> mom_dict["mu-"] FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) julia> mom_dict["mu+"] FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) ``` Subexpression: mom_dict["e-"] Evaluated output: FourMomentum(en = 500.0, x = 154.11019257368977, y = 154.11019257368974, z = 449.99954010071) Expected output: FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) diff = Warning: Diff output requires color. FourMomentum(en = 1000.0, 500.0, x = 0.0, 154.11019257368977, y = 0.0, 154.11019257368974, z = 999.999869440028)449.99954010071)

Check failure on line 195 in src/four_momentum.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/four_momentum.jl:195-217 ```jldoctest julia> mom_dict = coords_to_dict(1e3,0.9,pi/4) Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… julia> mom_dict["e-"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) julia> mom_dict["e+"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) julia> mom_dict["mu-"] FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) julia> mom_dict["mu+"] FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) ``` Subexpression: mom_dict["e+"] Evaluated output: FourMomentum(en = 500.0, x = -154.11019257368977, y = -154.11019257368974, z = -449.99954010071) Expected output: FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) diff = Warning: Diff output requires color. FourMomentum(en = 1000.0, 500.0, x = 0.0, -154.11019257368977, y = 0.0, -154.11019257368974, z = -999.999869440028)-449.99954010071)

Check failure on line 195 in src/four_momentum.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/four_momentum.jl:195-217 ```jldoctest julia> mom_dict = coords_to_dict(1e3,0.9,pi/4) Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… julia> mom_dict["e-"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) julia> mom_dict["e+"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) julia> mom_dict["mu-"] FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) julia> mom_dict["mu+"] FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) ``` Subexpression: mom_dict["mu-"] Evaluated output: FourMomentum(en = 500.0, x = 154.11019257368977, y = 154.11019257368974, z = 449.99954010071) Expected output: FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) diff = Warning: Diff output requires color. FourMomentum(en = 1000.0, 500.0, x = 306.4954310103767, 154.11019257368977, y = 306.49543101037665, 154.11019257368974, z = 894.9622389946002)449.99954010071)

Check failure on line 195 in src/four_momentum.jl

View workflow job for this annotation

GitHub Actions / Documentation

doctest failure in src/four_momentum.jl:195-217 ```jldoctest julia> mom_dict = coords_to_dict(1e3,0.9,pi/4) Dict{String, FourMomentum{Float64}} with 4 entries: "mu+" => (1000.0, -306.495431, -306.495431, -894.962239)… "mu-" => (1000.0, 306.495431, 306.495431, 894.962239)… "e+" => (1000.0, 0.0, 0.0, -999.999869)… "e-" => (1000.0, 0.0, 0.0, 999.999869)… julia> mom_dict["e-"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = 999.999869440028) julia> mom_dict["e+"] FourMomentum(en = 1000.0, x = 0.0, y = 0.0, z = -999.999869440028) julia> mom_dict["mu-"] FourMomentum(en = 1000.0, x = 306.4954310103767, y = 306.49543101037665, z = 894.9622389946002) julia> mom_dict["mu+"] FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) ``` Subexpression: mom_dict["mu+"] Evaluated output: FourMomentum(en = 500.0, x = -154.11019257368977, y = -154.11019257368974, z = -449.99954010071) Expected output: FourMomentum(en = 1000.0, x = -306.4954310103767, y = -306.49543101037665, z = -894.9622389946002) diff = Warning: Diff output requires color. FourMomentum(en = 1000.0, 500.0, x = -306.4954310103767, -154.11019257368977, y = -306.49543101037665, -154.11019257368974, z = -894.9622389946002)-449.99954010071)
julia> mom_dict = coords_to_dict(1e3,0.9,pi/4)
Dict{String, FourMomentum{Float64}} with 4 entries:
"mu+" => (1000.0, -306.495431, -306.495431, -894.962239)…
Expand All @@ -197,7 +217,38 @@
```
"""
function coords_to_dict(E_in,cos_theta,phi)
#
# FIXME: fill me in
#

# Validate input types
if !(isa(E_in, Real) && isa(cos_theta, Real) && isa(phi, Real))
throw(ArgumentError("All inputs must be of type Real."))
end

# Validate ranges
if cos_theta < -1 || cos_theta > 1
throw(ArgumentError("cos_theta must be in the range [-1, 1]."))
end
if phi < 0 || phi >= 2 * pi
throw(ArgumentError("phi must be in the range [0, 2π)."))
end

return _construct_moms_from_coords(E_in, cos_theta, phi)



end

function extractThreeMomentum(p::FourMomentum)

return (p.x, p.y, p.z)
end

function extractEnergy(p::FourMomentum)

return p.en
end

function extractNegativeThreeMomentum(p::FourMomentum)

return (-p.x, -p.y, -p.z)
end

Loading