Skip to content

Commit 3f718a8

Browse files
authored
fixes docs 10- issue (#72)
* fixes docs 10- issue - Remove physical constraint validation in Invariants function - Use a default constant for border point generation in Dalitz plot - Standardize type parameter formatting in type definitions * remote !isphysical test * missing docstrings * docs: Improve docstrings and formatting in phase_space.jl and mandelstam.jl - Add proper docstring formatting for `σjofk` and `σiofk` functions - Standardize type parameter spacing in `MandelstamTuple` - Add cross-reference to related function using `[@ref]` * another ref * docs: Improve docstring for isphysical and related functions - Add return type annotations to function signatures - Reposition helper functions for better readability - Update docstring formatting and cross-references * docs: Enhance docstrings with more comprehensive examples and formatting - Add multiple examples to `Kallen`, `sqrtKallenFact`, `Kibble`, `breakup`, `aligned_four_vectors`, and `isphysical` functions - Improve docstring readability with `jldoctest` blocks - Include practical usage scenarios and edge case demonstrations - Update cross-references and formatting for consistency * typo in docstring * add setup * ; setup = :(using ThreeBodyDecays) * fixed isphysical test for n_provided == 3 * cspell, formatter
1 parent 18a62f0 commit 3f718a8

File tree

5 files changed

+159
-47
lines changed

5 files changed

+159
-47
lines changed

.cspell/project.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ helicities
1919
helicity
2020
imag
2121
issequential
22+
jldoctest
2223
JPAC
2324
Källén
2425
latexstring
@@ -46,6 +47,7 @@ sinθ
4647
subchannel
4748
sumrules
4849
typeof
50+
unphysical
4951
Utopic
5052
vcat
5153
wignerd

src/dalitz.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ polardalitz2invariants(θ, expansion_point::Tuple) =
2121
) .+ expansion_point
2222

2323
function invariants(σx, σy; iσx, iσy, ms)
24-
iσx == 1 && iσy == 2 && return Invariants(ms, σ1 = σx, σ2 = σy)
25-
iσx == 2 && iσy == 1 && return Invariants(ms, σ1 = σy, σ2 = σx)
26-
iσx == 1 && iσy == 3 && return Invariants(ms, σ1 = σx, σ3 = σy)
27-
iσx == 3 && iσy == 1 && return Invariants(ms, σ1 = σy, σ3 = σx)
28-
iσx == 3 && iσy == 2 && return Invariants(ms, σ2 = σy, σ3 = σx)
29-
return Invariants(ms, σ2 = σx, σ3 = σy) # σx = 2 && σy = 3
30-
# error()
24+
iσx == 1 && iσy == 2 && return Invariants(ms; σ1 = σx, σ2 = σy)
25+
iσx == 2 && iσy == 1 && return Invariants(ms; σ2 = σx, σ1 = σy)
26+
iσx == 1 && iσy == 3 && return Invariants(ms; σ1 = σx, σ3 = σy)
27+
iσx == 3 && iσy == 1 && return Invariants(ms; σ3 = σx, σ1 = σy)
28+
iσx == 3 && iσy == 2 && return Invariants(ms; σ3 = σx, σ2 = σy)
29+
# remaining case σx = 2 && σy = 3
30+
return Invariants(ms; σ2 = σx, σ3 = σy)
3131
end
3232

3333
"""
@@ -42,7 +42,7 @@ Calculate the border of the Dalitz plot.
4242
# Returns
4343
- `Vector{MandelstamTuple{T}}`: Points on the border
4444
"""
45-
function border(ms::MassTuple{T}; Nx::Int = 300) where {T}
45+
function border(ms::MassTuple{T}; Nx::Int = DEFAULT_BORDER_POINTS) where {T}
4646
# Calculate a physically valid expansion point
4747
expansion_point = let
4848
f = 0.5
@@ -93,8 +93,8 @@ end
9393
iσx = 1,
9494
iσy = 2,
9595
grid_size = 100,
96-
xlims = lims(iσx, ms),
97-
ylims = lims(iσy, ms),
96+
xlims = lims(ms; k = iσx),
97+
ylims = lims(ms; k = iσy),
9898
)
9999
#
100100
σxv = range(xlims..., length = grid_size + 1) |> shift_by_half

src/mandelstam.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ function Invariants(
4141
else
4242
σ2 = sum(ms^2) - σ3 - σ1
4343
end
44-
end
45-
46-
# Validate the invariants
47-
if !isphysical((σ1, σ2, σ3), ms)
48-
error("The provided invariants violate physical constraints")
44+
elseif n_provided == 3
45+
# Check if the invariants are physical
46+
if !isphysical((σ1, σ2, σ3), ms)
47+
error("The invariants violate mass constraints")
48+
end
4949
end
5050

5151
return MandelstamTuple{T}((σ1, σ2, σ3))

src/mass_types.jl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,31 @@ ThreeBodyMasses(; m1, m2, m3, m0) = ThreeBodyMasses(m1, m2, m3; m0)
3333
"""
3434
lims(ms::MassTuple; k::Int)
3535
lims(k::Int, ms::MassTuple)
36+
lims1(ms::MassTuple)
37+
lims2(ms::MassTuple)
38+
lims3(ms::MassTuple)
3639
37-
Calculate the kinematic limits for the k-th Mandelstam variable.
40+
Calculate the kinematic limits (boundaries) for the Mandelstam variables σᵢ in a three-body decay.
41+
For each pair of particles (i,j), the invariant mass squared σₖ = (pᵢ + pⱼ)² must lie within physical limits:
42+
- Lower bound: (mᵢ + mⱼ)² (threshold for producing particles i and j)
43+
- Upper bound: (M - mₖ)² (maximum energy available when particle k recoils)
3844
3945
# Arguments
40-
- `ms::MassTuple`: Masses of the system
41-
- `k::Int`: Index of the variable (1, 2, or 3)
46+
- `ms`: Tuple of masses (m₁,m₂,m₃,M)
47+
- `k`: Index specifying which pair of particles (1,2,3)
4248
4349
# Returns
44-
- `Tuple{T,T}`: Lower and upper limits for the variable
50+
- Tuple (min,max) of the allowed range for σₖ
51+
52+
# Example
53+
```julia
54+
ms = ThreeBodyMasses(1.0, 1.0, 1.0; m0=4.0)
55+
lims1(ms) # limits for σ₁ = (p₂ + p₃)²
56+
lims2(ms) # limits for σ₂ = (p₃ + p₁)²
57+
lims3(ms) # limits for σ₃ = (p₁ + p₂)²
58+
```
59+
60+
See also [`isphysical`](@ref), [`Kibble`](@ref).
4561
"""
4662
function lims(ms::MassTuple; k::Int)
4763
i, j = ij_from_k(k)

src/phase_space.jl

Lines changed: 122 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,80 @@ This function appears frequently in relativistic kinematics calculations.
1010
# Returns
1111
- The value of the Källén function
1212
13-
# Example
14-
```julia
15-
# For a decay A -> B + C, calculate λ(mA², mB², mC²)
16-
Kallen(10.0, 1.0, 1.0) # returns 64.0
13+
# Examples
14+
```jldoctest; setup = :(using ThreeBodyDecays)
15+
julia> Kallen(10.0, 1.0, 1.0) # For a decay A -> B + C, calculate λ(mA², mB², mC²)
16+
60.0
17+
18+
julia> Kallen(5.0, 1.0, 1.0) # Another example with different masses
19+
5.0
1720
```
1821
1922
See also [`sqrtKallenFact`](@ref), [`Kibble`](@ref).
2023
"""
2124
Kallen(x, y, z) = x^2 + y^2 + z^2 - 2x * y - 2y * z - 2z * x
25+
26+
"""
27+
sqrtKallenFact(a, b, c)
28+
29+
Calculate the square root of the Källén function λ(a,b,c) in factorized form.
30+
The Källén function is defined as λ(a,b,c) = a² + b² + c² - 2ab - 2bc - 2ca.
31+
This function returns √λ(a,b,c) in a factorized form to improve numerical stability:
32+
√(a-(b+c)) √(a-(b-c)) √(a+(b+c)) √(a+(b-c)).
33+
34+
# Arguments
35+
- `a`, `b`, `c`: Input values for the Källén function
36+
37+
# Returns
38+
- Square root of the Källén function in factorized form
39+
40+
# Examples
41+
```jldoctest; setup = :(using ThreeBodyDecays)
42+
julia> sqrtKallenFact(10.0, 1.0, 1.0) # √λ(10,1,1) = √9600
43+
97.97958971132714
44+
45+
julia> sqrtKallenFact(4.0, 1.0, 1.0) # √λ(4,1,1) = √192
46+
13.856406460551018
47+
```
48+
49+
See also [`Kallen`](@ref), [`Kibble`](@ref).
50+
"""
2251
sqrtKallenFact(a, b, c) =
2352
sqrt(a - (b + c)) * sqrt(a - (b - c)) * sqrt(a + (b + c)) * sqrt(a + (b - c))
53+
54+
"""
55+
Kibble(σs, msq)
56+
57+
Calculate the Kibble function φ(σ₁,σ₂,σ₃) for three-body decays, which is defined in terms of Källén functions.
58+
The Kibble function determines the physical boundaries of the three-body phase space.
59+
60+
The function is calculated as:
61+
φ(σ₁,σ₂,σ₃) = λ(λ₁,λ₂,λ₃)
62+
where λᵢ = λ(M², mᵢ², σᵢ) are Källén functions of the total mass squared M²,
63+
the i-th particle mass squared mᵢ², and the corresponding Mandelstam variable σᵢ.
64+
65+
# Arguments
66+
- `σs`: Tuple of Mandelstam variables (σ₁,σ₂,σ₃)
67+
- `msq`: Tuple of squared masses (m₁²,m₂²,m₃²,M²)
68+
69+
# Returns
70+
- Value of the Kibble function
71+
72+
# Examples
73+
```jldoctest; setup = :(using ThreeBodyDecays)
74+
julia> msq = (1.0, 1.0, 1.0, 16.0); # squared masses: m₁², m₂², m₃², M²
75+
76+
julia> σs = (2.0, 2.0, 2.0); # Mandelstam variables
77+
78+
julia> Kibble(σs, msq) # returns the Kibble function value
79+
-77763.0
80+
81+
julia> Kibble(σs, msq) < 0 # physical configuration if negative
82+
true
83+
```
84+
85+
See also [`Kallen`](@ref), [`isphysical`](@ref).
86+
"""
2487
Kibble(σs, msq) = Kallen(
2588
Kallen(msq[4], msq[1], σs[1]),
2689
Kallen(msq[4], msq[2], σs[2]),
@@ -29,15 +92,15 @@ Kibble(σs, msq) = Kallen(
2992

3093

3194
"""
32-
σjofk(z,σi,msq; k::Int)
95+
σjofk(z,σi,msq; k::Int)
3396
3497
Computes invariant σj = (p0-pj)² from
3598
the scattering angle z=cosθij in the rest from of (i,j),
3699
given the mass of the system m(i,j)² = σk
37100
38101
Explicit forms: `σ3of1`, `σ1of2`, `σ2of3`.
39102
40-
See also `σiofk(z,σj,msq; k)`
103+
See also [`σiofk`](@ref)
41104
"""
42105
function σjofk(z, σk, msq; k::Int)
43106
i, j = ij_from_k(k)
@@ -56,15 +119,15 @@ end
56119

57120

58121
"""
59-
σiofk(k,z,σj,msq)
122+
σiofk(k,z,σj,msq)
60123
61124
Computes invariant σi = (p0 - pi)² from
62125
the scattering angle z=cosθij in the rest from of (i,j),
63126
given the mass of the system m(i,j)² = σk
64127
65128
Explicit forms: `σ3of2`, `σ1of3`, `σ2of1`.
66129
67-
See also `σjofk(z,σk,msq; k)`
130+
See also [`σjofk`](@ref)
68131
"""
69132
function σiofk(z, σk, msq; k::Int)
70133
σj = σjofk(z, σk, msq; k)
@@ -120,15 +183,18 @@ Calculate the breakup momentum for a two-body system.
120183
# Returns
121184
- Break-up momentum magnitude
122185
123-
# Example
124-
```julia
186+
# Examples
187+
```jldoctest; setup = :(using ThreeBodyDecays)
125188
julia> ms = ThreeBodyMasses(1.0, 1.0, 1.0; m0=4.0);
126189
127190
julia> p = breakup_Rk(2.5^2, ms; k=1)
128191
0.897587913521567
129192
130193
julia> q = breakup_ij(2.5^2, ms; k=1)
131194
0.75
195+
196+
julia> breakup(4.0, 2.5, 1.0) # direct use of breakup function
197+
0.897587913521567
132198
```
133199
"""
134200
breakup(m, m1, m2) =
@@ -155,15 +221,22 @@ Computes the four-momenta of the three particles in the center of momentum frame
155221
- `k`: Index of the particle to be aligned with the -z-axis.
156222
157223
## Returns
158-
159224
A tuple of three four-momenta in the form of (px, py, pz, E).
160225
161-
## Example
162-
````julia
163-
ms = ThreeBodyMasses(1.0, 1.0, 1.0; m0=4.0)
164-
σs = x2σs([0.5, 0.5], ms; k=2)
165-
p1, p2, p3 = aligned_four_vectors(σs, ms; k=1)
166-
````
226+
## Examples
227+
```jldoctest; setup = :(using ThreeBodyDecays)
228+
julia> ms = ThreeBodyMasses(1.0, 1.0, 1.0; m0=4.0);
229+
230+
julia> σs = x2σs([0.5, 0.5], ms; k=2);
231+
232+
julia> p1, p2, p3 = aligned_four_vectors(σs, ms; k=1);
233+
234+
julia> p1[3] ≈ -breakup_Rk(σs[1], ms; k=1) # first particle aligned with -z axis
235+
true
236+
237+
julia> all(p -> abs(p[2]) < 1e-10, (p1, p2, p3)) # all momenta in x-z plane
238+
true
239+
```
167240
"""
168241
function aligned_four_vectors(σs, ms; k::Int)
169242
#
@@ -193,24 +266,45 @@ function aligned_four_vectors(σs, ms; k::Int)
193266
return circleorigin(-k, (pi, pj, pk))
194267
end
195268

269+
inrange(x, r) = r[1] < x < r[2]
270+
inphrange(σs, ms::MassTuple) = isphysical(σs, ms)
271+
196272
"""
197-
inrange(x, r)
198-
inphrange(σs::MandelstamTuple, ms::MassTuple)
199-
isphysical(σs::MandelstamTuple, ms::MassTuple)
273+
isphysical(σs::MandelstamTuple, ms::MassTuple) -> Bool
274+
inphrange(σs::MandelstamTuple, ms::MassTuple) -> Bool
275+
inrange(x, r) -> Bool
200276
201-
Check if values are within physical ranges.
277+
Check if a set of Mandelstam variables represents a physically valid configuration in the three-body phase space.
278+
A configuration is physical if:
279+
1. The Kibble function is negative (φ(σ₁,σ₂,σ₃) < 0)
280+
2. All Mandelstam variables are within their kinematically allowed ranges
202281
203282
# Arguments
204-
- `x`: Value to check
205-
- `r`: Range to check against
206-
- `σs`: Mandelstam variables
207-
- `ms`: Masses of the system
283+
- `σs::MandelstamTuple`: Tuple of Mandelstam variables (σ₁,σ₂,σ₃)
284+
- `ms::MassTuple`: Tuple of masses (m₁,m₂,m₃,M)
285+
- `x`: Value to check (for `inrange`)
286+
- `r`: Range tuple (min,max) to check against (for `inrange`)
208287
209288
# Returns
210-
- `Bool`: Whether the values are physical
289+
- `Bool`: `true` if the configuration is physical, `false` otherwise
290+
291+
# Examples
292+
```jldoctest; setup = :(using ThreeBodyDecays)
293+
julia> ms = ThreeBodyMasses(1.0, 1.0, 1.0; m0=4.0);
294+
295+
julia> σs = (6.25, 6.25, 6.5);
296+
297+
julia> isphysical(σs, ms) # checks if this configuration is physically possible
298+
true
299+
300+
julia> σs_unphysical = (20.0, 20.0, 20.0); # values outside allowed ranges
301+
302+
julia> isphysical(σs_unphysical, ms) # this configuration is not physical
303+
false
304+
```
305+
306+
See also [`Kibble`](@ref), [`lims`](@ref).
211307
"""
212-
inrange(x, r) = r[1] < x < r[2]
213-
inphrange(σs, ms::MassTuple) = isphysical(σs, ms)
214308
isphysical(σs, ms::MassTuple) =
215309
Kibble(σs, ms^2) < 0 &&
216310
inrange(σs[1], lims1(ms)) &&

0 commit comments

Comments
 (0)