Skip to content

Commit 7bb89cc

Browse files
author
AntonReinhard
committed
Rename init_phasespace and final_phasespace, format
1 parent 5a9631d commit 7bb89cc

File tree

5 files changed

+145
-76
lines changed

5 files changed

+145
-76
lines changed

src/compton/differential_cross_section.jl

+47-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function _differential_cross_section(
1616
in_phase_space::AbstractVector{NumericType},
1717
out_phase_space::AbstractVector{NumericType},
1818
)::Float64 where {NumericType<:QEDbase.AbstractFourMomentum}
19-
if (!isapprox(sum(in_phase_space), sum(out_phase_space); rtol=sqrt(eps())))
19+
if (!isapprox(sum(in_phase_space), sum(out_phase_space); rtol = sqrt(eps())))
2020
return zero(Float64)
2121
end
2222

@@ -26,13 +26,38 @@ function _differential_cross_section(
2626
electron_out = out_phase_space[2]
2727

2828
# get base states of the particles
29-
photon_in_bstate = base_state(Photon(), Incoming(), photon_in, _spin_or_pol(process, Photon(), Incoming()))
30-
electron_in_bstate = base_state(Electron(), Incoming(), electron_in, _spin_or_pol(process, Electron(), Incoming()))
31-
photon_out_bstate = base_state(Photon(), Outgoing(), photon_out, _spin_or_pol(process, Photon(), Outgoing()))
32-
electron_out_bstate = base_state(Electron(), Outgoing(), electron_out, _spin_or_pol(process, Electron(), Outgoing()))
29+
photon_in_bstate = base_state(
30+
Photon(),
31+
Incoming(),
32+
photon_in,
33+
_spin_or_pol(process, Photon(), Incoming()),
34+
)
35+
electron_in_bstate = base_state(
36+
Electron(),
37+
Incoming(),
38+
electron_in,
39+
_spin_or_pol(process, Electron(), Incoming()),
40+
)
41+
photon_out_bstate = base_state(
42+
Photon(),
43+
Outgoing(),
44+
photon_out,
45+
_spin_or_pol(process, Photon(), Outgoing()),
46+
)
47+
electron_out_bstate = base_state(
48+
Electron(),
49+
Outgoing(),
50+
electron_out,
51+
_spin_or_pol(process, Electron(), Outgoing()),
52+
)
3353

3454
# if the particles had AllSpin or AllPol, the base states can be vectors and we need to consider every combination of the base states with each other
35-
base_states_comb = Iterators.product(photon_in_bstate, electron_in_bstate, photon_out_bstate, electron_out_bstate)
55+
base_states_comb = Iterators.product(
56+
photon_in_bstate,
57+
electron_in_bstate,
58+
photon_out_bstate,
59+
electron_out_bstate,
60+
)
3661
matrix_elements = Vector{ComplexF64}()
3762
sizehint!(matrix_elements, length(base_states_comb))
3863
for (phin, ein, phout, eout) in base_states_comb
@@ -45,15 +70,28 @@ function _differential_cross_section(
4570
normalization = 1.0 / (length(photon_in_bstate) * length(electron_in_bstate))
4671
I = photon_in * electron_in
4772

48-
return I * normalization * sum(matrix_elements_sq) * _phase_space_factor(photon_in, electron_in, photon_out, electron_out)
73+
return I *
74+
normalization *
75+
sum(matrix_elements_sq) *
76+
_phase_space_factor(photon_in, electron_in, photon_out, electron_out)
4977
end
5078

51-
function _perturbative_compton_matrix(ph_in_bstate::SLorentzVector{ComplexF64}, el_in_bstate::BiSpinor, ph_out_bstate::SLorentzVector{ComplexF64}, el_out_bstate::AdjointBiSpinor)
79+
function _perturbative_compton_matrix(
80+
ph_in_bstate::SLorentzVector{ComplexF64},
81+
el_in_bstate::BiSpinor,
82+
ph_out_bstate::SLorentzVector{ComplexF64},
83+
el_out_bstate::AdjointBiSpinor,
84+
)
5285
# TODO
5386
return zero(ComplexF64)
5487
end
5588

56-
function _phase_space_factor(ph_in::NumericType, el_in::NumericType, ph_out::NumericType, el_out::NumericType) where {NumericType<:QEDbase.AbstractFourMomentum}
89+
function _phase_space_factor(
90+
ph_in::NumericType,
91+
el_in::NumericType,
92+
ph_out::NumericType,
93+
el_out::NumericType,
94+
) where {NumericType<:QEDbase.AbstractFourMomentum}
5795
# TODO
5896
return zero(ComplexF64)
5997
end

src/compton/scattering_process.jl

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
Type for a Compton scattering process. The Compton process is parametrized with the types of [`AbstractPolarization`](@ref) and [`AbstractSpin`](@ref) used for the incoming and outgoing particles.
1111
This type implements the [`AbstractScatteringProcess`](@ref) interface. It can be used with [`DifferentialCrossSection`](@ref) to calculate differential cross sections of Compton scattering events.
1212
"""
13-
struct Compton{InPhotonPol,InElectronSpin,OutPhotonPol,OutElectronSpin} <: AbstractScatteringProcess where {
13+
struct Compton{InPhotonPol,InElectronSpin,OutPhotonPol,OutElectronSpin} <:
14+
AbstractScatteringProcess where {
1415
InPhotonPol<:AbstractPolarization,
1516
InElectronSpin<:AbstractSpin,
1617
OutPhotonPol<:AbstractPolarization,
@@ -29,7 +30,13 @@ const ComptonDCS = DifferentialCrossSection{
2930
Compton{P1,S1,P2,S2},
3031
PerturbativeQED,
3132
PhaseSpace,
32-
} where {P1<:AbstractPolarization,S1<:AbstractSpin,P2<:AbstractPolarization,S2<:AbstractSpin,PhaseSpace<:AbstractArray{SFourMomentum}}
33+
} where {
34+
P1<:AbstractPolarization,
35+
S1<:AbstractSpin,
36+
P2<:AbstractPolarization,
37+
S2<:AbstractSpin,
38+
PhaseSpace<:AbstractArray{SFourMomentum},
39+
}
3340

3441
"""
3542
$(TYPEDSIGNATURES)

src/interfaces/process_interface.jl

+46-51
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ end
6262
_differential_cross_section(
6363
proc_def::AbstractScatteringProcess,
6464
model_def::AbstractModelDefinition,
65-
init_phasespace::AbstractVector{T},
66-
final_phasespace::AbstractVector{T},
65+
in_phasespace::AbstractVector{T},
66+
out_phasespace::AbstractVector{T},
6767
) where {T<:QEDbase.AbstractFourMomentum}
6868
6969
Interface function for the combination of scattering processes and physical models. Return the differential cross section of a
@@ -77,9 +77,9 @@ check if the length of the passed phase spaces match the respective number of pa
7777
7878
```julia
7979
80-
_differential_cross_section(proc_def, model_def, init_phasespace::AbstractVector{T}, final_phasespace::AbstractMatrix{T})
81-
_differential_cross_section(proc_def, model_def, init_phasespace::AbstractMatrix{T}, final_phasespace::AbstractVector{T})
82-
_differential_cross_section(proc_def, model_def, init_phasespace::AbstractMatrix{T}, final_phasespace::AbstractMatrix{T})
80+
_differential_cross_section(proc_def, model_def, in_phasespace::AbstractVector{T}, out_phasespace::AbstractMatrix{T})
81+
_differential_cross_section(proc_def, model_def, in_phasespace::AbstractMatrix{T}, out_phasespace::AbstractVector{T})
82+
_differential_cross_section(proc_def, model_def, in_phasespace::AbstractMatrix{T}, out_phasespace::AbstractMatrix{T})
8383
8484
```
8585
@@ -101,8 +101,8 @@ function _differential_cross_section end
101101
differential_cross_section(
102102
proc_def::AbstractScatteringProcess,
103103
model_def::AbstractModelDefinition,
104-
init_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
105-
final_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
104+
in_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
105+
out_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
106106
) where {T<:QEDbase.AbstractFourMomentum}
107107
108108
Return the differential cross section for a given combination of a scattering process
@@ -113,41 +113,36 @@ This function will eventually call the respective interface function [`_differen
113113
function differential_cross_section(
114114
proc_def::AbstractScatteringProcess,
115115
model_def::AbstractModelDefinition,
116-
init_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
117-
final_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
116+
in_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
117+
out_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
118118
) where {T<:QEDbase.AbstractFourMomentum}
119-
size(init_phasespace, 1) == number_incoming_particles(proc_def) || throw(
119+
size(in_phasespace, 1) == number_incoming_particles(proc_def) || throw(
120120
DimensionMismatch(
121-
"The number of momenta in the initial phasespace <{length(init_phasespace)}> does not match the number of incoming particles of the process <{number_incoming_particles(proc_def)}>.",
121+
"The number of momenta in the initial phasespace <{length(in_phasespace)}> does not match the number of incoming particles of the process <{number_incoming_particles(proc_def)}>.",
122122
),
123123
)
124-
size(final_phasespace, 1) == number_outgoing_particles(proc_def) || throw(
124+
size(out_phasespace, 1) == number_outgoing_particles(proc_def) || throw(
125125
DimensionMismatch(
126-
"The number of momenta in the final phasespace <{length(final_phasespace)}> does not match the number of outgoing particles of the process <{number_outgoing_particles(proc_def)}>.",
126+
"The number of momenta in the final phasespace <{length(out_phasespace)}> does not match the number of outgoing particles of the process <{number_outgoing_particles(proc_def)}>.",
127127
),
128128
)
129-
return _differential_cross_section(
130-
proc_def,
131-
model_def,
132-
init_phasespace,
133-
final_phasespace,
134-
)
129+
return _differential_cross_section(proc_def, model_def, in_phasespace, out_phasespace)
135130
end
136131

137132
# returns diffCS for single `initPS` and several `finalPS` points without input-check
138133
function _differential_cross_section(
139134
proc_def::AbstractScatteringProcess,
140135
model_def::AbstractModelDefinition,
141-
init_phasespace::AbstractVector{T},
142-
final_phasespace::AbstractMatrix{T},
136+
in_phasespace::AbstractVector{T},
137+
out_phasespace::AbstractMatrix{T},
143138
) where {T<:QEDbase.AbstractFourMomentum}
144-
res = Vector{_base_component_type(init_phasespace)}(undef, size(final_phasespace, 2))
145-
for i = 1:size(final_phasespace, 2)
139+
res = Vector{_base_component_type(in_phasespace)}(undef, size(out_phasespace, 2))
140+
for i = 1:size(out_phasespace, 2)
146141
res[i] = _differential_cross_section(
147142
proc_def,
148143
model_def,
149-
init_phasespace,
150-
view(final_phasespace, :, i),
144+
in_phasespace,
145+
view(out_phasespace, :, i),
151146
)
152147
end
153148
return res
@@ -156,16 +151,16 @@ end
156151
function _differential_cross_section(
157152
proc_def::AbstractScatteringProcess,
158153
model_def::AbstractModelDefinition,
159-
init_phasespace::AbstractMatrix{T},
160-
final_phasespace::AbstractVector{T},
154+
in_phasespace::AbstractMatrix{T},
155+
out_phasespace::AbstractVector{T},
161156
) where {T<:QEDbase.AbstractFourMomentum}
162-
res = Vector{_base_component_type(init_phasespace)}(undef, size(init_phasespace, 2))
163-
for i = 1:size(init_phasespace, 2)
157+
res = Vector{_base_component_type(in_phasespace)}(undef, size(in_phasespace, 2))
158+
for i = 1:size(in_phasespace, 2)
164159
res[i] = _differential_cross_section(
165160
proc_def,
166161
model_def,
167-
view(init_phasespace, :, i),
168-
final_phasespace,
162+
view(in_phasespace, :, i),
163+
out_phasespace,
169164
)
170165
end
171166
return res
@@ -174,21 +169,21 @@ end
174169
function _differential_cross_section(
175170
proc_def::AbstractScatteringProcess,
176171
model_def::AbstractModelDefinition,
177-
init_phasespace::AbstractMatrix{T},
178-
final_phasespace::AbstractMatrix{T},
172+
in_phasespace::AbstractMatrix{T},
173+
out_phasespace::AbstractMatrix{T},
179174
) where {T<:QEDbase.AbstractFourMomentum}
180-
res = Matrix{_base_component_type(init_phasespace)}(
175+
res = Matrix{_base_component_type(in_phasespace)}(
181176
undef,
182-
size(init_phasespace, 2),
183-
size(final_phasespace, 2),
177+
size(in_phasespace, 2),
178+
size(out_phasespace, 2),
184179
)
185-
for init_idx = 1:size(init_phasespace, 2)
186-
for final_idx = 1:size(final_phasespace, 2)
180+
for init_idx = 1:size(in_phasespace, 2)
181+
for final_idx = 1:size(out_phasespace, 2)
187182
res[init_idx, final_idx] = _differential_cross_section(
188183
proc_def,
189184
model_def,
190-
view(init_phasespace, :, init_idx),
191-
view(final_phasespace, :, final_idx),
185+
view(in_phasespace, :, init_idx),
186+
view(out_phasespace, :, final_idx),
192187
)
193188
end
194189
end
@@ -200,7 +195,7 @@ end
200195
_total_cross_section(
201196
proc_def::AbstractScatteringProcess,
202197
model_def::AbstractModelDefinition,
203-
init_phasespace::AbstractVector{T},
198+
in_phasespace::AbstractVector{T},
204199
) where {T<:QEDbase.AbstractFourMomentum} end
205200
206201
Interface function for the combination of scattering processes and physical models. Return the total cross section of a
@@ -214,7 +209,7 @@ check if the length of the passed initial phase spaces match number of incoming
214209
215210
```julia
216211
217-
_total_cross_section(proc_def,model_def,init_phasespace::AbstractMatrix{T})
212+
_total_cross_section(proc_def,model_def,in_phasespace::AbstractMatrix{T})
218213
219214
```
220215
@@ -234,11 +229,11 @@ function _total_cross_section end
234229
function _total_cross_section(
235230
proc_def::AbstractScatteringProcess,
236231
model_def::AbstractModelDefinition,
237-
init_phasespace::AbstractMatrix{T},
232+
in_phasespace::AbstractMatrix{T},
238233
) where {T<:QEDbase.AbstractFourMomentum}
239-
res = Vector{_base_component_type(init_phasespace)}(undef, size(init_phasespace, 2))
240-
for i = 1:size(init_phasespace, 2)
241-
res[i] = _total_cross_section(proc_def, model_def, view(init_phasespace, :, i))
234+
res = Vector{_base_component_type(in_phasespace)}(undef, size(in_phasespace, 2))
235+
for i = 1:size(in_phasespace, 2)
236+
res[i] = _total_cross_section(proc_def, model_def, view(in_phasespace, :, i))
242237
end
243238
return res
244239
end
@@ -248,7 +243,7 @@ end
248243
total_cross_section(
249244
proc_def::AbstractScatteringProcess,
250245
model_def::AbstractModelDefinition,
251-
init_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
246+
in_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
252247
) where {T<:QEDbase.AbstractFourMomentum}
253248
254249
Return the total cross section for a combination of a scattering process and a physical model evaluated on a given initial phase space.
@@ -259,12 +254,12 @@ This function will eventually call the respective interface function [`_total_cr
259254
function total_cross_section(
260255
proc_def::AbstractScatteringProcess,
261256
model_def::AbstractModelDefinition,
262-
init_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
257+
in_phasespace::Union{AbstractVector{T},AbstractMatrix{T}},
263258
) where {T<:QEDbase.AbstractFourMomentum}
264-
size(init_phasespace, 1) == number_incoming_particles(proc_def) || throw(
259+
size(in_phasespace, 1) == number_incoming_particles(proc_def) || throw(
265260
DimensionMismatch(
266-
"The number of momenta in the initial phasespace <{length(init_phasespace)}> does not match the number of incoming particles of the process <{number_incoming_particles(proc_def)}>.",
261+
"The number of momenta in the initial phasespace <{length(in_phasespace)}> does not match the number of incoming particles of the process <{number_incoming_particles(proc_def)}>.",
267262
),
268263
)
269-
return _total_cross_section(proc_def, model_def, init_phasespace)
264+
return _total_cross_section(proc_def, model_def, in_phasespace)
270265
end

test/compton.jl

+38-9
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,51 @@ end
3434
model = PerturbativeQED()
3535
proc = Compton()
3636

37-
momenta_2 = [zero(SFourMomentum) for _ in 1:2]
38-
momenta_3 = [zero(SFourMomentum) for _ in 1:3]
37+
momenta_2 = [zero(SFourMomentum) for _ = 1:2]
38+
momenta_3 = [zero(SFourMomentum) for _ = 1:3]
3939

4040
momenta_2_2 = Matrix{SFourMomentum}(undef, 2, 2)
4141
momenta_3_2 = Matrix{SFourMomentum}(undef, 3, 2)
4242

4343
# try compute single input with incorrect dimensions
44-
@test_throws DimensionMismatch differential_cross_section(proc, model, momenta_3, momenta_2)
44+
@test_throws DimensionMismatch differential_cross_section(
45+
proc,
46+
model,
47+
momenta_3,
48+
momenta_2,
49+
)
4550
@test_throws "incoming" differential_cross_section(proc, model, momenta_3, momenta_2)
46-
@test_throws DimensionMismatch differential_cross_section(proc, model, momenta_2, momenta_3)
51+
@test_throws DimensionMismatch differential_cross_section(
52+
proc,
53+
model,
54+
momenta_2,
55+
momenta_3,
56+
)
4757
@test_throws "outgoing" differential_cross_section(proc, model, momenta_2, momenta_3)
4858

4959
# try compute multiple inputs with incorrect dimensions
50-
@test_throws DimensionMismatch differential_cross_section(proc, model, momenta_3_2, momenta_2_2)
51-
@test_throws "incoming" differential_cross_section(proc, model, momenta_3_2, momenta_2_2)
52-
@test_throws DimensionMismatch differential_cross_section(proc, model, momenta_2_2, momenta_3_2)
53-
@test_throws "outgoing" differential_cross_section(proc, model, momenta_2_2, momenta_3_2)
60+
@test_throws DimensionMismatch differential_cross_section(
61+
proc,
62+
model,
63+
momenta_3_2,
64+
momenta_2_2,
65+
)
66+
@test_throws "incoming" differential_cross_section(
67+
proc,
68+
model,
69+
momenta_3_2,
70+
momenta_2_2,
71+
)
72+
@test_throws DimensionMismatch differential_cross_section(
73+
proc,
74+
model,
75+
momenta_2_2,
76+
momenta_3_2,
77+
)
78+
@test_throws "outgoing" differential_cross_section(
79+
proc,
80+
model,
81+
momenta_2_2,
82+
momenta_3_2,
83+
)
5484
end
55-

test/interfaces/process_interface.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ end
5858
function QEDprocesses._differential_cross_section(
5959
proc::TestProcess,
6060
model::TestModel,
61-
init_phasespace::AbstractVector{T},
62-
final_phasespace::AbstractVector{T},
61+
in_phasespace::AbstractVector{T},
62+
out_phasespace::AbstractVector{T},
6363
) where {T<:QEDbase.AbstractFourMomentum}
64-
_groundtruth_diffCS(init_phasespace, final_phasespace)
64+
_groundtruth_diffCS(in_phasespace, out_phasespace)
6565
end
6666

6767
function QEDprocesses._total_cross_section(
6868
proc::TestProcess,
6969
model::TestModel,
70-
init_phasespace::AbstractVector{T},
70+
in_phasespace::AbstractVector{T},
7171
) where {T<:QEDbase.AbstractFourMomentum}
72-
_groundtruth_totCS(init_phasespace)
72+
_groundtruth_totCS(in_phasespace)
7373
end
7474

7575
@testset "hard interface" begin

0 commit comments

Comments
 (0)