Skip to content

Commit f703634

Browse files
szabo137Uwe Hernandez Acostatjungni
authored
Refactoring of differential cross section functionality (#38)
# Problem statement The current implementation only allows implementing `differential_cross_section` directly for given processes. Furthermore, the interface does not allow the implementation of different phase-space coordinate systems, e.g. to model $d\sigma/dE$ **and** $d\sigma/d\cos\theta$ for the same process. # Suggested solution ## Advanced process interface I suggest to disassemble the differential cross-sections interface into a more flexible interface: ```mermaid flowchart TD _differential_cross_section --> _differential_probability _differential_cross_section --> _incident_flux* _differential_probability --> _avg_matrix_element_square _differential_probability --> _phase_space_factor* _differential_probability -.-> _is_in_phasespace* _avg_matrix_element_square --> _matrix_element* _avg_matrix_element_square --> _avg_normalization* ``` where the functions with the asterisk give the new interface for the calculation of differential cross-sections: * `_matrix_element`: the matrix element of the process * `_phase_space_factor`: the value of the pre-differential factor of the phase-space measure * `_is_in_phasespace`: checks if a given input is physical, see below * `_incident_flux`: the incident particle flux, used to normalize the probability * `_avg_normalization`: normalization for averaging of squared matrix elements The underscore of those functions implies, that they are not exported, and no input validation check is performed. For the functions `_differential_cross_section` and `_differential_probability` there are versions `differential_cross_section` and `differential_probability`, where input validation is performed. ## Phase space definition To attack the original problem using different coordinate systems for the same process, this PR adds a simple system for coordinate systems and frames of reference. Those are propagated through a composite type: ```Julia PhasespaceDefinition{ CS<:AbstractCoordinateSystem, F<: AbstractFrameOfReference } ``` Currently, the given example implementations are very limited, but this deserves an interface in the future. A dedicated issue will be opened during the review process of this PR (see todos below). ## Phase space check **Not included** in the input validation is the check if given incoming and outgoing phase-spaces are physical, i.e. if all momenta are on-shell and fulfill some sort of energy-momentum conservation. Therefore, I suggest to add another interface function ```Julia _is_in_phasespace( in_ps_def::AbstractPhasespaceDefinition, in_ps::AbstractVector{T}, out_ps_def::AbstractPhasespaceDefinition, out_ps::AbstractVector{T}, ) where {T<:QEDbase.AbstractFourMomentum} ``` which returns `true` if the input is physical, and `false` otherwise. Consequently, there are unsafe versions of cross-sections and probabilities, which don't perform the check given by the function above, and safe versions, which return null if the condition given by `_is_in_phasespace` is not met. # Final remarks To conclude, the different versions of cross-section and probability functions, derived from the interface above, are ```Julia _unsafe_differential_cross_section # without input validation, without phase-space check _differential_cross_section # without input validation, with phase-space check unsafe_differential_cross_section # with input validation, without phase-space check differential_cross_section # with input validation, with phase-space check _unsafe_differential_probability # without input validation, without phase-space check _differential_probability # without input validation, with phase-space check unsafe_differential_probability # with input validation, without phase-space check differential_probability # with input validation, with phase-space check ``` where only the functions without an underscore are exported, for all of those functions, there are implementations for all combinations of vectors and matrices for the incoming and outgoing phase space. ## Todos: - [x] write tests for `(_(unsafe_))probability` - [x] make total cross-section an interface function - [x] make energy-momentum check for *safe implementations* an interface function - [ ] Write a gist about the broadcasted implementations - [x] rename `_[unsafe_]probability` to `_[unsafe]differential_probability` - [x] cleanup in Project.toml - [x] open issue on `PhasespaceDefinition` --------- Co-authored-by: Uwe Hernandez Acosta <[email protected]> Co-authored-by: Tom Jungnickel <[email protected]>
1 parent 152f71e commit f703634

18 files changed

+1616
-375
lines changed

Project.toml

-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ authors = ["Uwe Hernandez Acosta <[email protected]>", "Simeon Ehrig", "Klaus
44
version = "0.1.0"
55

66
[deps]
7-
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
87
QEDbase = "10e22c08-3ccb-4172-bfcf-7d7aa3d04d93"
98

109
[compat]
11-
DocStringExtensions = "0.9"
1210
QEDbase = "0.1"
1311
julia = "1.6"

src/QEDprocesses.jl

+16-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ export AbstractModelDefinition, fundamental_interaction_type
77
export AbstractProcessDefinition, incoming_particles, outgoing_particles
88
export in_phasespace_dimension, out_phasespace_dimension
99
export number_incoming_particles, number_outgoing_particles
10-
export differential_cross_section, total_cross_section
10+
11+
# probabilities
12+
export differential_probability, unsafe_differential_probability
13+
export total_probability
14+
15+
# differential cross section
16+
export differential_cross_section, unsafe_differential_cross_section
17+
export total_cross_section
1118

1219
# Abstract setup interface
1320
export AbstractComputationSetup, InvalidInputError, compute
@@ -16,12 +23,19 @@ export AbstractProcessSetup, scattering_process, physical_model
1623
# propagator
1724
export propagator
1825

19-
using DocStringExtensions
26+
# phase space
27+
export AbstractCoordinateSystem, SphericalCoordinateSystem
28+
export AbstractFrameOfReference, CenterOfMomentumFrame, ElectronRestFrame
29+
export AbstractPhasespaceDefinition, PhasespaceDefinition
30+
2031
using QEDbase
2132

2233
include("utils.jl")
2334
include("interfaces/model_interface.jl")
2435
include("interfaces/process_interface.jl")
2536
include("interfaces/setup_interface.jl")
2637
include("propagators.jl")
38+
include("phase_spaces.jl")
39+
include("probabilities.jl")
40+
include("cross_sections.jl")
2741
end

src/cross_sections.jl

+304
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
########################
2+
# differential cross sections and probabilities.
3+
#
4+
# This file contains default implementations for differential and total cross
5+
# sections based on the scattering process interface
6+
########################
7+
8+
############
9+
#
10+
# differential cross sections
11+
#
12+
############
13+
14+
# differential cross sections without energy momentum conservation check
15+
# single in phase space point/ single out phase space point
16+
function _unsafe_differential_cross_section(
17+
proc::AbstractProcessDefinition,
18+
model::AbstractModelDefinition,
19+
in_phase_space_def::AbstractPhasespaceDefinition,
20+
in_phase_space::AbstractVector{T},
21+
out_phase_space_def::AbstractPhasespaceDefinition,
22+
out_phase_space::AbstractVector{T},
23+
) where {T<:QEDbase.AbstractFourMomentum}
24+
I = 1 / (4 * _incident_flux(proc, model, in_phase_space))
25+
26+
return I * _unsafe_differential_probability(
27+
proc,
28+
model,
29+
in_phase_space_def,
30+
in_phase_space,
31+
out_phase_space_def,
32+
out_phase_space,
33+
)
34+
end
35+
36+
# differential cross sections without energy momentum conservation check
37+
# single in phase space point/ several out phase space points
38+
function _unsafe_differential_cross_section(
39+
proc::AbstractProcessDefinition,
40+
model::AbstractModelDefinition,
41+
in_phase_space_def::AbstractPhasespaceDefinition,
42+
in_phase_space::AbstractVector{T},
43+
out_phase_space_def::AbstractPhasespaceDefinition,
44+
out_phase_space::AbstractMatrix{T},
45+
) where {T<:QEDbase.AbstractFourMomentum}
46+
res = Vector{eltype(T)}(undef, size(out_phase_space, 2))
47+
for i in 1:size(out_phase_space, 2)
48+
res[i] = _unsafe_differential_cross_section(
49+
proc,
50+
model,
51+
in_phase_space_def,
52+
in_phase_space,
53+
out_phase_space_def,
54+
view(out_phase_space, :, i),
55+
)
56+
end
57+
return res
58+
end
59+
60+
# differential cross sections without energy momentum conservation check
61+
# several in phase space points/ one or several out phase space points
62+
function _unsafe_differential_cross_section(
63+
proc::AbstractProcessDefinition,
64+
model::AbstractModelDefinition,
65+
in_phase_space_def::AbstractPhasespaceDefinition,
66+
in_phase_space::AbstractMatrix{T},
67+
out_phase_space_def::AbstractPhasespaceDefinition,
68+
out_phase_space::AbstractVecOrMat{T},
69+
) where {T<:QEDbase.AbstractFourMomentum}
70+
res = Matrix{eltype(T)}(undef, size(in_phase_space, 2), size(out_phase_space, 2))
71+
for i in 1:size(in_phase_space, 2)
72+
res[i, :] .= _unsafe_differential_cross_section(
73+
proc,
74+
model,
75+
in_phase_space_def,
76+
view(in_phase_space, :, i),
77+
out_phase_space_def,
78+
out_phase_space,
79+
)
80+
end
81+
return res
82+
end
83+
84+
"""
85+
86+
function unsafe_differential_cross_section(
87+
proc::AbstractProcessDefinition,
88+
model::AbstractModelDefinition,
89+
in_phase_space_def::AbstractPhasespaceDefinition,
90+
in_phase_space::AbstractVecOrMat{T},
91+
out_phase_space_def::AbstractPhasespaceDefinition,
92+
out_phase_space::AbstractVecOrMat{T},
93+
) where {T<:QEDbase.AbstractFourMomentum}
94+
95+
Return the differential cross section without checking if the given phase space(s) are physical.
96+
"""
97+
function unsafe_differential_cross_section(
98+
proc::AbstractProcessDefinition,
99+
model::AbstractModelDefinition,
100+
in_phase_space_def::AbstractPhasespaceDefinition,
101+
in_phase_space::AbstractVecOrMat{T},
102+
out_phase_space_def::AbstractPhasespaceDefinition,
103+
out_phase_space::AbstractVecOrMat{T},
104+
) where {T<:QEDbase.AbstractFourMomentum}
105+
size(in_phase_space, 1) == number_incoming_particles(proc) || throw(
106+
DimensionMismatch(
107+
"The number of incoming particles <$(number_incoming_particles(proc))> is inconsistent with input size <$(size(in_phase_space,1))>",
108+
),
109+
)
110+
111+
size(out_phase_space, 1) == number_outgoing_particles(proc) || throw(
112+
DimensionMismatch(
113+
"The number of outgoing particles <$(number_outgoing_particles(proc))> is inconsistent with input size <$(size(out_phase_space,1))>",
114+
),
115+
)
116+
117+
return _unsafe_differential_cross_section(
118+
proc,
119+
model,
120+
in_phase_space_def,
121+
in_phase_space,
122+
out_phase_space_def,
123+
out_phase_space,
124+
)
125+
end
126+
127+
# differential cross sections with energy momentum conservation check
128+
# single in phase space point/ single out phase space point
129+
function _differential_cross_section(
130+
proc::AbstractProcessDefinition,
131+
model::AbstractModelDefinition,
132+
in_phase_space_def::AbstractPhasespaceDefinition,
133+
in_phase_space::AbstractVector{T},
134+
out_phase_space_def::AbstractPhasespaceDefinition,
135+
out_phase_space::AbstractVector{T},
136+
) where {T<:QEDbase.AbstractFourMomentum}
137+
if !_is_in_phasespace(
138+
proc,
139+
model,
140+
in_phase_space_def,
141+
in_phase_space,
142+
out_phase_space_def,
143+
out_phase_space,
144+
)
145+
return zero(eltype(T))
146+
end
147+
148+
return _unsafe_differential_cross_section(
149+
proc,
150+
model,
151+
in_phase_space_def,
152+
in_phase_space,
153+
out_phase_space_def,
154+
out_phase_space,
155+
)
156+
end
157+
158+
# differential cross sections with energy momentum conservation check
159+
# single in phase space point/ several out phase space points
160+
function _differential_cross_section(
161+
proc::AbstractProcessDefinition,
162+
model::AbstractModelDefinition,
163+
in_phase_space_def::AbstractPhasespaceDefinition,
164+
in_phase_space::AbstractVector{T},
165+
out_phase_space_def::AbstractPhasespaceDefinition,
166+
out_phase_space::AbstractMatrix{T},
167+
) where {T<:QEDbase.AbstractFourMomentum}
168+
res = Vector{eltype(T)}(undef, size(out_phase_space, 2))
169+
for i in 1:size(out_phase_space, 2)
170+
res[i] = _differential_cross_section(
171+
proc,
172+
model,
173+
in_phase_space_def,
174+
in_phase_space,
175+
out_phase_space_def,
176+
view(out_phase_space, :, i),
177+
)
178+
end
179+
return res
180+
end
181+
182+
# differential cross sections with energy momentum conservation check
183+
# several in phase space points/ one or several out phase space points
184+
function _differential_cross_section(
185+
proc::AbstractProcessDefinition,
186+
model::AbstractModelDefinition,
187+
in_phase_space_def::AbstractPhasespaceDefinition,
188+
in_phase_space::AbstractMatrix{T},
189+
out_phase_space_def::AbstractPhasespaceDefinition,
190+
out_phase_space::AbstractVecOrMat{T},
191+
) where {T<:QEDbase.AbstractFourMomentum}
192+
res = Matrix{eltype(T)}(undef, size(in_phase_space, 2), size(out_phase_space, 2))
193+
for i in 1:size(in_phase_space, 2)
194+
res[i, :] .= _differential_cross_section(
195+
proc,
196+
model,
197+
in_phase_space_def,
198+
view(in_phase_space, :, i),
199+
out_phase_space_def,
200+
out_phase_space,
201+
)
202+
end
203+
return res
204+
end
205+
206+
"""
207+
differential_cross_section(
208+
proc::AbstractProcessDefinition,
209+
model::AbstractModelDefinition,
210+
in_phase_space_def::AbstractPhasespaceDefinition,
211+
in_phase_space::AbstractVecOrMat{T},
212+
out_phase_space_def::AbstractPhasespaceDefinition,
213+
out_phase_space::AbstractVecOrMat{T},
214+
) where {T<:QEDbase.AbstractFourMomentum}
215+
216+
If the given phase spaces are physical, return differential cross section. Zero otherwise
217+
218+
"""
219+
function differential_cross_section(
220+
proc::AbstractProcessDefinition,
221+
model::AbstractModelDefinition,
222+
in_phase_space_def::AbstractPhasespaceDefinition,
223+
in_phase_space::AbstractVecOrMat{T},
224+
out_phase_space_def::AbstractPhasespaceDefinition,
225+
out_phase_space::AbstractVecOrMat{T},
226+
) where {T<:QEDbase.AbstractFourMomentum}
227+
size(in_phase_space, 1) == number_incoming_particles(proc) || throw(
228+
DimensionMismatch(
229+
"The number of incoming particles <$(number_incoming_particles(proc))> is inconsistent with input size <$(size(in_phase_space,1))>",
230+
),
231+
)
232+
233+
size(out_phase_space, 1) == number_outgoing_particles(proc) || throw(
234+
DimensionMismatch(
235+
"The number of outgoing particles <$(number_outgoing_particles(proc))> is inconsistent with input size <$(size(out_phase_space,1))>",
236+
),
237+
)
238+
239+
return _differential_cross_section(
240+
proc,
241+
model,
242+
in_phase_space_def,
243+
in_phase_space,
244+
out_phase_space_def,
245+
out_phase_space,
246+
)
247+
end
248+
249+
############
250+
# Total cross sections
251+
############
252+
253+
# total cross section on single phase space point
254+
function _total_cross_section(
255+
proc::AbstractProcessDefinition,
256+
model::AbstractModelDefinition,
257+
in_phase_space_def::AbstractPhasespaceDefinition,
258+
in_phase_space::AbstractVector{T},
259+
) where {T<:QEDbase.AbstractFourMomentum}
260+
I = 1 / (4 * _incident_flux(proc, model, in_phase_space))
261+
262+
return I * _total_probability(proc, model, in_phase_space_def, in_phase_space)
263+
end
264+
265+
# total cross section on several phase space points
266+
function _total_cross_section(
267+
proc::AbstractProcessDefinition,
268+
model::AbstractModelDefinition,
269+
in_phase_space_def::AbstractPhasespaceDefinition,
270+
in_phase_space::AbstractMatrix{T},
271+
) where {T<:QEDbase.AbstractFourMomentum}
272+
res = Vector{eltype(T)}(undef, size(in_phase_space, 2))
273+
for i in 1:size(in_phase_space, 2)
274+
res[i] = _total_cross_section(
275+
proc, model, in_phase_space_def, view(in_phase_space, :, i)
276+
)
277+
end
278+
return res
279+
end
280+
281+
"""
282+
total_cross_section(
283+
proc::AbstractProcessDefinition,
284+
model::AbstractModelDefinition,
285+
in_phase_space_def::AbstractPhasespaceDefinition,
286+
in_phase_space::AbstractVecOrMat{T},
287+
) where {T<:QEDbase.AbstractFourMomentum}
288+
289+
Return the total cross section for a given combination of scattering process and compute model.
290+
"""
291+
function total_cross_section(
292+
proc::AbstractProcessDefinition,
293+
model::AbstractModelDefinition,
294+
in_phase_space_def::AbstractPhasespaceDefinition,
295+
in_phase_space::AbstractVecOrMat{T},
296+
) where {T<:QEDbase.AbstractFourMomentum}
297+
size(in_phase_space, 1) == number_incoming_particles(proc) || throw(
298+
DimensionMismatch(
299+
"The number of incoming particles <$(number_incoming_particles(proc))> is inconsistent with input size <$(size(in_phase_space,1))>",
300+
),
301+
)
302+
303+
return _total_cross_section(proc, model, in_phase_space_def, in_phase_space)
304+
end

0 commit comments

Comments
 (0)