From 1174730e537057374820b9a9e307a2326260c55a Mon Sep 17 00:00:00 2001 From: Fabian Zierler Date: Tue, 29 Jun 2021 15:13:36 +0200 Subject: [PATCH 1/2] Effective mass for Numbers and DataPoints including error propagation. Still needs tests. --- src/spectroscopy.jl | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/spectroscopy.jl b/src/spectroscopy.jl index 347c4f3..3827428 100644 --- a/src/spectroscopy.jl +++ b/src/spectroscopy.jl @@ -1 +1,38 @@ # This file should contain all spectroscopy specifc stuff like correlators, fits, effective masses, ... +function effectivemass(c) + N = length(c) + m = similar(c) + for i in 1:N + r = c[i]/c[mod1(i+1,N)] + m[i] = r > 0 ? abs(log(r)) : NaN + end + return m +end +function effectivemass_err(c,Δc;norm=1) + N = length(c) + Δm = similar(c) + for i in 1:N + j = mod1(i+1,N) + Δm[i] = norm(Δc[i]/c[i],Δc[j]/c[j],p=norm) + end + return Δm +end +effectivemass_err_sys(c,Δc) = effectivemass_err(c,Δc,norm=1) +effectivemass_err_stat(c,Δc) = effectivemass_err(c,Δc,norm=2) +""" + effectivemass(c) + +Returns the effectivemass ``m_\\text{eff}(t)`` of the data ```x``` given by `` +m_\\text{eff}(t) = \\left| \\log \\left( \\frac{x(t)}{x(t+1)} \\right) \\right| ``. If +```x``` is a vector of ```DataPoint```'s the statistical and systematic +uncertainties are propagated accordingly. If ```x <: Number``` only the the mean +value is calculated. In that case the unexported methods +```effectivemass_err_stat(x,Δx)``` and ```effectivemass_err_sys(x,Δx)``` can be +used for propagation of uncertainty. +""" +function effectivemass(c::Vector{DataPoint{T}}) where T + val = getfield.(c,:val) + stat = getfield.(c,:stat) + sys = getfield.(c,:sys) + return DataPoint.(effectivemass(val),effectivemass_err_stat(val,stat),effectivemass_err_sys(val,sys)) +end From f822800d5436ad955bb0c8929413db457835eb3e Mon Sep 17 00:00:00 2001 From: Fabian Zierler Date: Tue, 29 Jun 2021 19:38:44 +0200 Subject: [PATCH 2/2] cosh meff --- src/spectroscopy.jl | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/spectroscopy.jl b/src/spectroscopy.jl index 3827428..d6dd410 100644 --- a/src/spectroscopy.jl +++ b/src/spectroscopy.jl @@ -31,8 +31,27 @@ value is calculated. In that case the unexported methods used for propagation of uncertainty. """ function effectivemass(c::Vector{DataPoint{T}}) where T - val = getfield.(c,:val) - stat = getfield.(c,:stat) - sys = getfield.(c,:sys) + # here are some allocations that are not strictly needed + val = value.(c) + stat = staterr.(c) + sys = syserr.(c) return DataPoint.(effectivemass(val),effectivemass_err_stat(val,stat),effectivemass_err_sys(val,sys)) end +function effectivemass_cosh(c) + T = length(c) + t = 1:T + mid = div(T,2)+1 # 1-based indexing + return @. abs(acosh(c/c[mid])/(mid-t)) +end +_acoshderiv(x) = 1/sqrt(x^2 + 1) +function effectivemass_cosh_err(c,Δc;norm=1) + T = length(c) + mid = div(T,2) + 1 # 1-based indexing + Δm = similar(c) + for t in 1:T + err1 = _acoshderiv(c[t]/c[mid])*Δc[t]/c[mid] + err2 = _acoshderiv(c[t]/c[mid])*c[t]*Δc[mid]/c[mid]^2 + Δm[t] = LinearAlgebra.norm((err1,err2),norm)/abs(mid-t) + end + return Δm +end