Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonReinhard committed May 24, 2024
1 parent 8923365 commit a99c302
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/cross_section/diff_cross_section.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If the given phase spaces are physical, return differential cross section evalua
"""
function differential_cross_section(phase_space_point::PhaseSpacePoint)
if !_is_in_phasespace(phase_space_point)
return zero(eltype(_eltype_from_psp(phase_space_point)))
return zero(eltype(_momentum_type(phase_space_point)))
end

return unsafe_differential_cross_section(phase_space_point)
Expand Down
9 changes: 0 additions & 9 deletions src/cross_section/total_cross_section.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,3 @@ function total_cross_section(in_psp::InPhaseSpacePoint)
I = 1 / (4 * _incident_flux(in_psp))
return I * _total_probability(in_psp)
end

"""
total_cross_section(in_psps::AbstractVector{InPhaseSpacePoint})
Return the total cross section for a given vector of [`InPhaseSpacePoint`](@ref).
"""
function _total_cross_section(in_psps::AbstractVector{<:InPhaseSpacePoint})
return _total_cross_section.(in_psps)
end
9 changes: 0 additions & 9 deletions src/cross_section/total_probability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,3 @@ Return the total probability of a given [`InPhaseSpacePoint`](@ref).
function total_probability(in_psp::InPhaseSpacePoint)
return _total_probability(in_psp)
end

"""
total_probability(in_psps::AbstractVector{InPhaseSpacePoint})
Return the total probability of a given vector of [`InPhaseSpacePoint`](@ref)s.
"""
function total_probability(in_psps::AbstractVector{<:InPhaseSpacePoint})
return _total_probability.(in_psps)
end
46 changes: 23 additions & 23 deletions src/phase_spaces/create.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ end
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
in_ps::NTuple{N,AbstractFourMomentum},
out_ps::NTuple{M,AbstractFourMomentum},
in_momenta::NTuple{N,QEDbase.AbstractFourMomentum},
out_momenta::NTuple{M,QEDbase.AbstractFourMomentum},
)
Construct the phase space point from given momenta of incoming and outgoing particles regarding a given process.
Expand All @@ -59,11 +59,11 @@ function PhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
in_ps::NTuple{N,ELEMENT},
out_ps::NTuple{M,ELEMENT},
) where {N,M,ELEMENT<:AbstractFourMomentum}
in_particles = _build_particle_statefuls(proc, in_ps, Incoming())
out_particles = _build_particle_statefuls(proc, out_ps, Outgoing())
in_momenta::NTuple{N,ELEMENT},
out_momenta::NTuple{M,ELEMENT},
) where {N,M,ELEMENT<:QEDbase.AbstractFourMomentum}
in_particles = _build_particle_statefuls(proc, in_momenta, Incoming())
out_particles = _build_particle_statefuls(proc, out_momenta, Outgoing())

return PhaseSpacePoint(proc, model, ps_def, in_particles, out_particles)
end
Expand All @@ -73,7 +73,7 @@ end
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
in_ps::NTuple{N,AbstractFourMomentum},
in_momenta::NTuple{N,QEDbase.AbstractFourMomentum},
)
Construct a [`PhaseSpacePoint`](@ref) with only input particles from given momenta. The result will be `<: InPhaseSpacePoint` but **not** `<: OutPhaseSpacePoint`.
Expand All @@ -82,9 +82,9 @@ function InPhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
in_ps::NTuple{N,ELEMENT},
) where {N,ELEMENT<:AbstractFourMomentum}
in_particles = _build_particle_statefuls(proc, in_ps, Incoming())
in_momenta::NTuple{N,ELEMENT},
) where {N,ELEMENT<:QEDbase.AbstractFourMomentum}
in_particles = _build_particle_statefuls(proc, in_momenta, Incoming())

return PhaseSpacePoint(proc, model, ps_def, in_particles, ())
end
Expand All @@ -94,7 +94,7 @@ end
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
out_ps::NTuple{N,AbstractFourMomentum},
out_momenta::NTuple{N,QEDbase.AbstractFourMomentum},
)
Construct a [`PhaseSpacePoint`](@ref) with only output particles from given momenta. The result will be `<: OutPhaseSpacePoint` but **not** `<: InPhaseSpacePoint`.
Expand All @@ -103,9 +103,9 @@ function OutPhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
out_ps::NTuple{N,ELEMENT},
) where {N,ELEMENT<:AbstractFourMomentum}
out_particles = _build_particle_statefuls(proc, out_ps, Outgoing())
out_momenta::NTuple{N,ELEMENT},
) where {N,ELEMENT<:QEDbase.AbstractFourMomentum}
out_particles = _build_particle_statefuls(proc, out_momenta, Outgoing())

return PhaseSpacePoint(proc, model, ps_def, (), out_particles)
end
Expand All @@ -117,8 +117,8 @@ end
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
in_ps::NTuple{N,Real},
out_ps::NTuple{M,Real},
in_coords::NTuple{N,Real},
out_coords::NTuple{M,Real},
)
Construct a [`PhaseSpacePoint`](@ref) from given coordinates by using the [`_generate_momenta`](@ref) interface.
Expand All @@ -127,10 +127,10 @@ function PhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
in_ps::NTuple{N,Real},
out_ps::NTuple{M,Real},
in_coords::NTuple{N,Real},
out_coords::NTuple{M,Real},
) where {N,M}
in_ps, out_ps = _generate_momenta(proc, model, ps_def, in_ps, out_ps)
in_ps, out_ps = _generate_momenta(proc, model, ps_def, in_coords, out_coords)
return PhaseSpacePoint(proc, model, ps_def, in_ps, out_ps)
end

Expand All @@ -139,7 +139,7 @@ end
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
in_ps::NTuple{N,Real},
in_coords::NTuple{N,Real},
)
Construct a [`PhaseSpacePoint`](@ref) from given coordinates by using the [`_generate_momenta`](@ref) interface. The result will be `<: InPhaseSpacePoint` but **not** `<: OutPhaseSpacePoint`.
Expand All @@ -151,8 +151,8 @@ function InPhaseSpacePoint(
proc::AbstractProcessDefinition,
model::AbstractModelDefinition,
ps_def::AbstractPhasespaceDefinition,
in_ps::NTuple{N,Real},
in_coords::NTuple{N,Real},
) where {N}
in_ps = _generate_incoming_momenta(proc, model, ps_def, in_ps)
in_ps = _generate_incoming_momenta(proc, model, ps_def, in_coords)
return InPhaseSpacePoint(proc, model, ps_def, in_ps)
end
18 changes: 9 additions & 9 deletions src/phase_spaces/types.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using QEDbase

import QEDbase: AbstractFourMomentum

abstract type AbstractCoordinateSystem end
struct SphericalCoordinateSystem <: AbstractCoordinateSystem end

Expand All @@ -28,15 +24,15 @@ Broadcast.broadcastable(ps_def::AbstractPhasespaceDefinition) = Ref(ps_def)
#
# Currently, elements can be either four-momenta, or real numbers,
# i.e. coordinates.
AbstractPhasespaceElement = Union{AbstractFourMomentum,Real}
AbstractPhasespaceElement = Union{QEDbase.AbstractFourMomentum,Real}

"""
ParticleStateful <: AbstractParticle
Representation of a particle with a state. It has four fields:
- `dir::ParticleDirection`: The direction of the particle, `QEDbase.Incoming()` or `QEDbase.Outgoing()`.
- `species::AbstractParticleType`: The species of the particle, `QEDbase.Electron()`, `QEDbase.Positron()` etc.
- `mom::AbstractFourMomentum`: The momentum of the particle.
- `mom::QEDbase.AbstractFourMomentum`: The momentum of the particle.
Overloads for `QEDbase.is_fermion`, `QEDbase.is_boson`, `QEDbase.is_particle`, `QEDbase.is_anti_particle`, `QEDbase.is_incoming`, `QEDbase.is_outgoing`, `QEDbase.mass`, and `QEDbase.charge` are provided, delegating the call to the correct field and thus implementing the `QEDbase.AbstractParticle` interface.
Expand All @@ -53,7 +49,9 @@ ParticleStateful: outgoing photon
```
"""
struct ParticleStateful{
DIR<:ParticleDirection,SPECIES<:AbstractParticleType,ELEMENT<:AbstractFourMomentum
DIR<:ParticleDirection,
SPECIES<:AbstractParticleType,
ELEMENT<:QEDbase.AbstractFourMomentum,
} <: AbstractParticle
dir::DIR
species::SPECIES
Expand All @@ -62,7 +60,9 @@ struct ParticleStateful{
function ParticleStateful(
dir::DIR, species::SPECIES, mom::ELEMENT
) where {
DIR<:ParticleDirection,SPECIES<:AbstractParticleType,ELEMENT<:AbstractFourMomentum
DIR<:ParticleDirection,
SPECIES<:AbstractParticleType,
ELEMENT<:QEDbase.AbstractFourMomentum,
}
return new{DIR,SPECIES,ELEMENT}(dir, species, mom)
end
Expand Down Expand Up @@ -109,7 +109,7 @@ struct PhaseSpacePoint{
PSDEF<:AbstractPhasespaceDefinition,
IN_PARTICLES<:Tuple{Vararg{ParticleStateful}},
OUT_PARTICLES<:Tuple{Vararg{ParticleStateful}},
ELEMENT<:AbstractFourMomentum,
ELEMENT<:QEDbase.AbstractFourMomentum,
}
proc::PROC
model::MODEL
Expand Down
30 changes: 10 additions & 20 deletions src/phase_spaces/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,45 +98,35 @@ end
end

"""
_eltype_from_psp_type(type::Type{PhaseSpacePoint})
_momentum_type(psp::PhaseSpacePoint)
_momentum_type(type::Type{PhaseSpacePoint})
Returns the element type of the [`PhaseSpacePoint`](@ref) type, e.g. `SFourMomentum`.
Returns the element type of the [`PhaseSpacePoint`](@ref) object or type, e.g. `SFourMomentum`.
```jldoctest
julia> using QEDprocesses; using QEDbase;
julia> psp = PhaseSpacePoint(Compton(), PerturbativeQED(), PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame()), Tuple(rand(SFourMomentum) for _ in 1:2), Tuple(rand(SFourMomentum) for _ in 1:2));
julia> QEDprocesses._eltype_from_psp_type(typeof(psp))
julia> QEDprocesses._momentum_type(psp)
SFourMomentum
julia> QEDprocesses._momentum_type(typeof(psp))
SFourMomentum
```
"""
@inline function _eltype_from_psp_type(
@inline function _momentum_type(
::Type{T}
) where {P,M,D,I,O,E,T<:PhaseSpacePoint{P,M,D,I,O,E}}
return E
end

"""
_eltype_from_psp(psp::PhaseSpacePoint)
Returns the element type of the [`PhaseSpacePoint`](@ref), e.g. `SFourMomentum`.
```jldoctest
julia> using QEDprocesses; using QEDbase;
julia> psp = PhaseSpacePoint(Compton(), PerturbativeQED(), PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame()), Tuple(rand(SFourMomentum) for _ in 1:2), Tuple(rand(SFourMomentum) for _ in 1:2));
julia> QEDprocesses._eltype_from_psp(psp)
SFourMomentum
```
"""
@inline _eltype_from_psp(::T) where {T<:PhaseSpacePoint} = _eltype_from_psp_type(T)
@inline _momentum_type(::T) where {T<:PhaseSpacePoint} = _momentum_type(T)

# convenience function building a type stable tuple of ParticleStatefuls from the given process, momenta, and direction
function _build_particle_statefuls(
proc::AbstractProcessDefinition, moms::NTuple{N,ELEMENT}, dir::ParticleDirection
) where {N,ELEMENT<:AbstractFourMomentum}
) where {N,ELEMENT<:QEDbase.AbstractFourMomentum}
N == number_particles(proc, dir) || throw(
InvalidInputError(
"expected $(number_particles(proc, dir)) $(dir) particles for the process but got $(N)",
Expand Down

0 comments on commit a99c302

Please sign in to comment.