Skip to content

Commit

Permalink
Generic function (#59)
Browse files Browse the repository at this point in the history
* replace strange rho and f2 by generic functions
* generic is called on dict
* compass, replace Katchaev Sigma by expression string
  • Loading branch information
mmikhasenko authored Jun 4, 2024
1 parent afcb173 commit eaf884c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 116 deletions.
20 changes: 10 additions & 10 deletions docs/julia/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ version = "1.10.8"

[[deps.HadronicLineshapes]]
deps = ["Parameters", "QuadGK", "StaticArrays"]
git-tree-sha1 = "be308739b5e513ab30b120aed74f7a86f029dd4e"
git-tree-sha1 = "bad0c37beb3c481eaafbffc3df166852a9eb462f"
repo-rev = "main"
repo-url = "https://github.com/mmikhasenko/HadronicLineshapes.jl"
uuid = "49c9d978-1f9d-4e96-a984-0a9783c0b9bf"
Expand Down Expand Up @@ -461,9 +461,9 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[deps.LogExpFunctions]]
deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"]
git-tree-sha1 = "18144f3e9cbe9b15b070288eef858f71b291ce37"
git-tree-sha1 = "a2d09619db4e765091ee5c6ffe8872849de0feea"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.3.27"
version = "0.3.28"

[deps.LogExpFunctions.extensions]
LogExpFunctionsChainRulesCoreExt = "ChainRulesCore"
Expand Down Expand Up @@ -669,9 +669,9 @@ version = "1.0.0"

[[deps.Polynomials]]
deps = ["LinearAlgebra", "RecipesBase", "Setfield", "SparseArrays"]
git-tree-sha1 = "89620a0b5458dca4bf9ea96174fa6422b3adf6f9"
git-tree-sha1 = "25e7f73d679e5214971620886d3416c1f5991ecc"
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
version = "4.0.8"
version = "4.0.9"

[deps.Polynomials.extensions]
PolynomialsChainRulesCoreExt = "ChainRulesCore"
Expand Down Expand Up @@ -898,17 +898,17 @@ uuid = "e6563dab-9ca1-5843-bde3-2ccf38d63843"
version = "0.11.3"

[[deps.ThreeBodyDecaysIO]]
deps = ["DataFrames", "HadronicLineshapes", "JSON", "OrderedCollections", "Parameters", "ThreeBodyDecays"]
git-tree-sha1 = "f6e8270e4ac158bfac8e510229f2b1954779d625"
deps = ["DataFrames", "HadronicLineshapes", "JSON", "MacroTools", "OrderedCollections", "Parameters", "ThreeBodyDecays"]
git-tree-sha1 = "84fbac13959f426213ae1bc5f49c46b17fab7e30"
repo-rev = "main"
repo-url = "https://github.com/mmikhasenko/ThreeBodyDecaysIO.jl"
uuid = "418e7ecf-680e-4cb5-ad61-5e2f006aefac"
version = "0.3.0"
version = "0.4.1"

[[deps.TranscodingStreams]]
git-tree-sha1 = "5d54d076465da49d6746c647022f3b3674e64156"
git-tree-sha1 = "a947ea21087caba0a798c5e494d0bb78e3a1a3a0"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.10.8"
version = "0.10.9"
weakdeps = ["Random", "Test"]

[deps.TranscodingStreams.extensions]
Expand Down
13 changes: 5 additions & 8 deletions docs/julia/lb2pkg-lhcb-2765817.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,12 @@ The code below defines a new `NonResonant` lineshape, and its deserialization me
```{julia}
struct Constant <: HadronicLineshapes.AbstractFlexFunc
end
(X::Constant)(σ) = 1
(X::Constant)(σ::Number) = 1
function ThreeBodyDecaysIO.dict2instance(::Type{Constant}, dict)
return Constant()
import ThreeBodyDecaysIO: dict2instance
function dict2instance(::Type{Constant}, dict)
return NamedArgFunc(Constant(), [""])
end
# type piracy, not good
(bw::HadronicLineshapes.BreitWigner)(x::Dict) = bw(first(values(x)))
(bw::HadronicLineshapes.MultichannelBreitWigner)(x::Dict) = bw(first(values(x)))
```

## Deserialization of Objects to a Workspace
Expand All @@ -78,7 +75,7 @@ end
for dist in distributions
@unpack name, type = dist
instance_type = eval(Symbol(type))
workspace[name] = dict2instance(instance_type, distributions[1]; workspace)
workspace[name] = dict2instance(instance_type, dist; workspace)
end
```

Expand Down
10 changes: 3 additions & 7 deletions docs/julia/lc2ppik-lhcb-2683025.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct BreitWignerWidthExpLikeBugg <: HadronicLineshapes.AbstractFlexFunc
Γ::Float64
γ::Float64
end
function (BW::BreitWignerWidthExpLikeBugg)(σ)
function (BW::BreitWignerWidthExpLikeBugg)(σ::Number)
mK = 0.493677
mπ = 0.13957018
σA = mK^2 - mπ^2 / 2
Expand All @@ -56,13 +56,9 @@ function (BW::BreitWignerWidthExpLikeBugg)(σ)
1 / (m^2 - σ - 1im * m * Γt)
end
function ThreeBodyDecaysIO.dict2instance(::Type{BreitWignerWidthExpLikeBugg}, dict)
@unpack mass, width, slope = dict
return BreitWignerWidthExpLikeBugg(mass, width, slope)
@unpack mass, width, slope, x = dict
return NamedArgFunc(BreitWignerWidthExpLikeBugg(mass, width, slope), [x])
end
# type piracy, not good
(bw::HadronicLineshapes.BreitWigner)(x::Dict) = bw(first(values(x)))
(bw::HadronicLineshapes.MultichannelBreitWigner)(x::Dict) = bw(first(values(x)))
```

## Deserialization of Objects to a Workspace
Expand Down
76 changes: 0 additions & 76 deletions docs/julia/x2pipipi-compass-1391643.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,82 +37,6 @@ theme(:wong2, frame=:box, grid=false, minorticks=true,
lab="")
```

## Function definitions

Non-standard lineshapes are used to model resonances that do not conform to a simple `BreitWigner` distributions, or a `MultichannelBreitWigner` has to be defined explicitly.
The code below defines a new lineshape, and its deserialization method.

```{julia}
@with_kw struct BreitWignerRhoNoSqrt <: HadronicLineshapes.AbstractFlexFunc
m::Float64
Γ::Float64
mπ::Float64
d::Float64
end
function (bw::BreitWignerRhoNoSqrt)(σ)
@unpack m, Γ, mπ, d = bw
p, p0 = sqrt(σ / 4 - mπ^2), sqrt(m^2 / 4 - mπ^2)
ff = BlattWeisskopf{1}(d)
mΓ = m * Γ * p / p0 * ff(p)^2 / ff(p0)^2
1 / (m^2 - σ - 1im * mΓ)
end
function ThreeBodyDecaysIO.dict2instance(::Type{BreitWignerRhoNoSqrt}, dict)
@unpack mass, width, mπ, d = dict
return BreitWignerRhoNoSqrt(mass, width, mπ, d)
end
@with_kw struct BreitWignerRho3XQrt <: HadronicLineshapes.AbstractFlexFunc
m::Float64
Γ::Float64
end
function (bw::BreitWignerRho3XQrt)(σ)
@unpack m, Γ = bw
sqrt(sqrt(σ)) / (m^2 - σ - 1im * m * Γ)
end
function ThreeBodyDecaysIO.dict2instance(::Type{BreitWignerRho3XQrt}, dict)
@unpack mass, width = dict
return BreitWignerRho3XQrt(mass, width)
end
@with_kw struct KatchaevSigma <: HadronicLineshapes.AbstractFlexFunc
poles::Vector{Float64}
residues::Vector{Float64}
nonpole_expansion_coeffs::Vector{Float64}
end
function (bw::KatchaevSigma)(σ)
mπ = 0.13956755
mπ2 = mπ^2
@unpack poles, residues, nonpole_expansion_coeffs = bw
M00 = 0.0
for i = 1:length(poles)
M00 += residues[i] / (σ - poles[i])
end
#
mK = 0.493677
mK0 = 0.497614
scale = (σ / (4 * ((mK + mK0) / 2.0)^2)) - 1.0
for (i, ci) in enumerate(nonpole_expansion_coeffs)
M00 += scale^(i - 1) * ci
end
rho00 = sqrt(Kallen(σ, mπ2, mπ2)) / σ
return 1.0 / (M00 - 1im * rho00)
end
function ThreeBodyDecaysIO.dict2instance(::Type{KatchaevSigma}, dict)
@unpack poles, residues, nonpole_expansion_coeffs = dict
return KatchaevSigma(poles, residues, nonpole_expansion_coeffs)
end
# type piracy, not good
(bw::HadronicLineshapes.BreitWigner)(x::Dict) = bw(first(values(x)))
(bw::HadronicLineshapes.MultichannelBreitWigner)(x::Dict) = bw(first(values(x)))
(bw::KatchaevSigma)(x::Dict) = bw(first(values(x)))
(bw::BreitWignerRho3XQrt)(x::Dict) = bw(first(values(x)))
(bw::BreitWignerRhoNoSqrt)(x::Dict) = bw(first(values(x)))
```

## Deserialization of Objects to a Workspace

Expand Down
21 changes: 6 additions & 15 deletions models/x2pipipi-compass-1391643.json
Original file line number Diff line number Diff line change
Expand Up @@ -986,27 +986,18 @@
"name": "R(1274)"
},
{
"type": "BreitWignerRho3XQrt",
"x": "m_12_sq",
"mass": 1.69,
"width": 0.19,
"type": "generic_function",
"expression": "sqrt(sqrt(m_12_sq)) / (1.69^2 - m_12_sq - 1im * 1.69 * 0.19)",
"name": "R(1690)"
},
{
"type": "KatchaevSigma",
"x": "m_12_sq",
"poles": [-0.0073999, 0.9828001],
"residues": [0.1131, 0.0],
"nonpole_expansion_coeffs": [0.0337, -0.3185, -0.0942, -0.5927],
"type": "generic_function",
"expression": "1.0 / (0.1131 / (m_12_sq + 0.0073999) + 0.0337 - 0.3185 * (m_12_sq / 0.982657846681 - 1.0) - 0.0942 * (m_12_sq / 0.982657846681 - 1.0)^2 -0.5927 * (m_12_sq / 0.982657846681 - 1.0)^3 - i * sqrt(1 - 4*0.13956755^2 / m_12_sq))",
"name": "R(600)"
},
{
"type": "BreitWignerRhoNoSqrt",
"x": "m_12_sq",
"mass": 0.7685,
"width": 0.1507,
"mπ": 0.13956755,
"d": 4.94,
"type": "generic_function",
"expression": "1 / (0.7685^2 - m_12_sq - i * 0.7685 * 0.1507 * sqrt(m_12_sq / 4 - 0.13956755^2)^3 / sqrt(0.7685^2 / 4 - 0.13956755^2)^3 * (1+sqrt(0.7685^2 / 4 - 0.13956755^2)^2*4.94^2) / (1+sqrt(m_12_sq / 4 - 0.13956755^2)^2*4.94^2))",
"name": "R(768)"
},
{
Expand Down

0 comments on commit eaf884c

Please sign in to comment.