Skip to content

Commit

Permalink
Add assume :consistent for base_state functions
Browse files Browse the repository at this point in the history
This is dangerous and we should instead find the actual reason for the inconsistency
  • Loading branch information
AntonReinhard committed Oct 29, 2024
1 parent ce411db commit 3c5041a
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/particles/states.jl
Original file line number Diff line number Diff line change
@@ -1,74 +1,93 @@
function _booster_fermion(mom::AbstractFourMomentum, mass::Real)
@inline function _booster_fermion(mom::AbstractFourMomentum, mass::Real)
return (slashed(mom) + mass * one(DiracMatrix)) / (sqrt(abs(getT(mom)) + mass))
end

function _booster_antifermion(mom::AbstractFourMomentum, mass::Real)
@inline function _booster_antifermion(mom::AbstractFourMomentum, mass::Real)
return (mass * one(DiracMatrix) - slashed(mom)) / (sqrt(abs(getT(mom)) + mass))
end

function QEDbase.base_state(
particle::Fermion, ::Incoming, mom::AbstractFourMomentum, spin::AbstractDefiniteSpin
)
Base.@assume_effects :nothrow
Base.@assume_effects :consistent
booster = _booster_fermion(mom, mass(particle))
return BiSpinor(booster[:, QEDbase._spin_index(spin)])
return BiSpinor(@inbounds booster[:, QEDbase._spin_index(spin)])
end

function QEDbase.base_state(
particle::Fermion, ::Incoming, mom::AbstractFourMomentum, spin::AllSpin
)
Base.@assume_effects :nothrow
Base.@assume_effects :consistent
booster = _booster_fermion(mom, mass(particle))
return SVector(BiSpinor(booster[:, 1]), BiSpinor(booster[:, 2]))
return SVector(BiSpinor(@inbounds booster[:, 1]), BiSpinor(@inbounds booster[:, 2]))
end

function QEDbase.base_state(
particle::AntiFermion, ::Incoming, mom::AbstractFourMomentum, spin::AbstractDefiniteSpin
)
Base.@assume_effects :nothrow
Base.@assume_effects :consistent
booster = _booster_antifermion(mom, mass(particle))
return AdjointBiSpinor(BiSpinor(booster[:, QEDbase._spin_index(spin) + 2])) * GAMMA[1]
return AdjointBiSpinor(BiSpinor(@inbounds booster[:, QEDbase._spin_index(spin) + 2])) *
(@inbounds GAMMA[1])
end

function QEDbase.base_state(
particle::AntiFermion, ::Incoming, mom::AbstractFourMomentum, spin::AllSpin
)
Base.@assume_effects :nothrow
Base.@assume_effects :consistent
booster = _booster_antifermion(mom, mass(particle))
return SVector(
AdjointBiSpinor(BiSpinor(booster[:, 3])) * GAMMA[1],
AdjointBiSpinor(BiSpinor(booster[:, 4])) * GAMMA[1],
AdjointBiSpinor(@inbounds BiSpinor(booster[:, 3])) * (@inbounds GAMMA[1]),
AdjointBiSpinor(@inbounds BiSpinor(booster[:, 4])) * (@inbounds GAMMA[1]),
)
end

function QEDbase.base_state(
particle::Fermion, ::Outgoing, mom::AbstractFourMomentum, spin::AbstractDefiniteSpin
)
Base.@assume_effects :nothrow
Base.@assume_effects :consistent
booster = _booster_fermion(mom, mass(particle))
return AdjointBiSpinor(BiSpinor(booster[:, QEDbase._spin_index(spin)])) * GAMMA[1]
return AdjointBiSpinor(BiSpinor(@inbounds booster[:, QEDbase._spin_index(spin)])) *
(@inbounds GAMMA[1])
end

function QEDbase.base_state(
particle::Fermion, ::Outgoing, mom::AbstractFourMomentum, spin::AllSpin
)
Base.@assume_effects :nothrow
Base.@assume_effects :consistent
booster = _booster_fermion(mom, mass(particle))
return SVector(
AdjointBiSpinor(BiSpinor(booster[:, 1])) * GAMMA[1],
AdjointBiSpinor(BiSpinor(booster[:, 2])) * GAMMA[1],
AdjointBiSpinor(BiSpinor(@inbounds booster[:, 1])) * (@inbounds GAMMA[1]),
AdjointBiSpinor(BiSpinor(@inbounds booster[:, 2])) * (@inbounds GAMMA[1]),
)
end

function QEDbase.base_state(
particle::AntiFermion, ::Outgoing, mom::AbstractFourMomentum, spin::AbstractDefiniteSpin
)
Base.@assume_effects :nothrow
Base.@assume_effects :consistent
booster = _booster_antifermion(mom, mass(particle))
return BiSpinor(booster[:, QEDbase._spin_index(spin) + 2])
return BiSpinor(@inbounds booster[:, QEDbase._spin_index(spin) + 2])
end

function QEDbase.base_state(
particle::AntiFermion, ::Outgoing, mom::AbstractFourMomentum, spin::AllSpin
)
Base.@assume_effects :nothrow
Base.@assume_effects :consistent
booster = _booster_antifermion(mom, mass(particle))
return SVector(BiSpinor(booster[:, 3]), BiSpinor(booster[:, 4]))
return SVector(BiSpinor(@inbounds booster[:, 3]), BiSpinor(@inbounds booster[:, 4]))
end

function _photon_state(pol::AllPolarization, mom::AbstractFourMomentum)
Base.@assume_effects :nothrow
cth = getCosTheta(mom)
sth = sqrt(1 - cth^2)
cos_phi = getCosPhi(mom)
Expand All @@ -80,6 +99,7 @@ function _photon_state(pol::AllPolarization, mom::AbstractFourMomentum)
end

function _photon_state(pol::PolarizationX, mom::AbstractFourMomentum)
Base.@assume_effects :nothrow
cth = getCosTheta(mom)
sth = sqrt(1 - cth^2)
cos_phi = getCosPhi(mom)
Expand All @@ -88,6 +108,7 @@ function _photon_state(pol::PolarizationX, mom::AbstractFourMomentum)
end

function _photon_state(pol::PolarizationY, mom::AbstractFourMomentum)
Base.@assume_effects :nothrow
cos_phi = getCosPhi(mom)
sin_phi = getSinPhi(mom)
return SLorentzVector{Float64}(0.0, -sin_phi, cos_phi, 0.0)
Expand All @@ -96,6 +117,7 @@ end
@inline function QEDbase.base_state(
particle::Photon, ::ParticleDirection, mom::AbstractFourMomentum, pol::AllPolarization
)
Base.@assume_effects :consistent
return _photon_state(pol, mom)
end

Expand All @@ -105,5 +127,6 @@ end
mom::AbstractFourMomentum,
pol::AbstractPolarization,
)
Base.@assume_effects :consistent
return _photon_state(pol, mom)
end

0 comments on commit 3c5041a

Please sign in to comment.