Commit d84bb9db authored by Javier's avatar Javier

additional methods for meff and dec_const_pcvc

dec_const_pcvc is completed, new methods, Corr->Obs, Obs constructors added,  L normalization
parent b34b9fdd
...@@ -4,8 +4,7 @@ function plat_av(obs::Vector{uwreal}, plat::Vector{Int64}) ...@@ -4,8 +4,7 @@ function plat_av(obs::Vector{uwreal}, plat::Vector{Int64})
av = sum(w .* obs[plat[1]:plat[2]]) / sum(w) av = sum(w .* obs[plat[1]:plat[2]]) / sum(w)
return av return av
end end
#TODO: mu1, y0, gamma -> return? function meff(obs::Vector{uwreal}, plat::Vector{Int64}; pl::Bool=true, data::Bool=false )
function meff(obs::Vector{uwreal}, plat::Vector{Int64}; pl=true, data=false )
dim = length(obs) dim = length(obs)
aux = log.(obs[2:dim-2] ./ obs[3:dim-1]) aux = log.(obs[2:dim-2] ./ obs[3:dim-1])
mass = plat_av(aux, plat) mass = plat_av(aux, plat)
...@@ -30,30 +29,31 @@ function meff(obs::Vector{uwreal}, plat::Vector{Int64}; pl=true, data=false ) ...@@ -30,30 +29,31 @@ function meff(obs::Vector{uwreal}, plat::Vector{Int64}; pl=true, data=false )
return (mass, aux) return (mass, aux)
end end
end end
meff(corr::Corr, plat::Vector{Int64}; pl=true, data=false) = meff(corr.obs, plat, pl=pl, data=data) meff(corr::Obs, plat::Vector{Int64}; pl::Bool=true) =
Obs(meff(corr.obs, plat, pl=pl, data=false), corr)
## Decay constants ## Decay constants
#TODO: mu1, y0, gamma -> return?
#TODO: test #TODO: test
function dec_const_pcvc(obs::Vector{uwreal}, plat::Vector{Int64}, m::uwreal, mu::Vector{Float64}, y0::Int64 ; pl=true, data=false) function dec_const_pcvc(obs::Vector{uwreal}, plat::Vector{Int64}, m::uwreal, mu::Vector{Float64}, y0::Int64 ; pl::Bool=true, data::Bool=false)
""" """
compute the decay constant when the source is far from the boundaries compute the decay constant when the source is far from the boundaries
""" """
corr_pp = obs[2:end-1] corr_pp = obs[2:end-1]
dim = length(corr_pp) dim = length(corr_pp)
#m_array = Vector{uwreal}() aux = exp.((collect(1:dim) .- y0 ) .* [m for k in 1:dim])
#[push!(m_array, m) for k in 1:dim]
aux = exp.( (collect(1:dim) .- y0 ) .* [m for k in 1:dim] )
R = (aux .* corr_pp).^0.5 R = (aux .* corr_pp).^0.5
R_av = plat_av(R, plat) R_av = plat_av(R, plat)
f = sqrt(2) * (mu[1] + mu[2]) *R_av / m^1.5 f = sqrt(2) * (mu[1] + mu[2]) *R_av / m^1.5
uwerr(f) uwerr(f)
if pl == true if pl == true
uwerr(R_av)
v = value(R_av)
e = err(R_av)
uwerr.(R) uwerr.(R)
figure() figure()
errorbar(1:length(R), value.(R), err.(R), fmt="x") fill_between(plat[1]:plat[2], v-e, v+e, color="green", alpha=0.75)
errorbar(1:length(R), value.(R), err.(R), fmt="x", color="black")
ylabel(L"$R$") ylabel(L"$R$")
xlabel(L"$x_0$") xlabel(L"$x_0$")
display(gcf()) display(gcf())
...@@ -64,5 +64,9 @@ function dec_const_pcvc(obs::Vector{uwreal}, plat::Vector{Int64}, m::uwreal, mu: ...@@ -64,5 +64,9 @@ function dec_const_pcvc(obs::Vector{uwreal}, plat::Vector{Int64}, m::uwreal, mu:
return (f, R) return (f, R)
end end
end end
dec_const_pcvc(corr::Corr, plat::Vector{Int64}, m::uwreal; pl=true, data=false) = dec_const_pcvc(corr::Obs, plat::Vector{Int64}, m::uwreal; pl::Bool=true) =
dec_const_pcvc(corr.obs, plat, m, corr.mu, corr.y0, pl=pl, data=data) Obs(dec_const_pcvc(corr.obs, plat, m,
\ No newline at end of file corr.mu, corr.y0, pl=pl, data=false), corr)
dec_const_pcvc(corr::Obs, plat::Vector{Int64}, m::Obs; pl::Bool=true) =
Obs(dec_const_pcvc(corr.obs, plat, m.obs,
corr.mu, corr.y0, pl=pl, data=false), corr)
\ No newline at end of file
...@@ -70,7 +70,6 @@ function read_CHeader(path::String) ...@@ -70,7 +70,6 @@ function read_CHeader(path::String)
end end
function read_mesons(path::String, g1::Union{String, Nothing}=nothing, g2::Union{String, Nothing}=nothing; id::Union{Int, Nothing}=nothing) function read_mesons(path::String, g1::Union{String, Nothing}=nothing, g2::Union{String, Nothing}=nothing; id::Union{Int, Nothing}=nothing)
isnothing(g1) ? t1=nothing : t1 = findfirst(x-> x==g1, gamma_name) - 1 isnothing(g1) ? t1=nothing : t1 = findfirst(x-> x==g1, gamma_name) - 1
......
...@@ -19,20 +19,20 @@ function apply_rw(data::Array{Float64}, W::Array{Float64, 2}) ...@@ -19,20 +19,20 @@ function apply_rw(data::Array{Float64}, W::Array{Float64, 2})
return data_r return data_r
end end
function corr_obs(cdata::CData; real::Bool=true, rw::Union{Array{Float64, 2}, Nothing}=nothing) function corr_obs(cdata::CData; real::Bool=true, rw::Union{Array{Float64, 2}, Nothing}=nothing, L::Int64=1)
real ? data = cdata.re_data : data = cdata.im_data real ? data = cdata.re_data ./ L^3 : data = cdata.im_data ./ L^3
isnothing(rw) ? data_r = data : data_r = apply_rw(data, rw) isnothing(rw) ? data_r = data : data_r = apply_rw(data, rw)
nt = size(data)[2] nt = size(data)[2]
obs = Vector{uwreal}(undef, nt) obs = Vector{uwreal}(undef, nt)
[obs[x0] = uwreal(data_r[:, x0], cdata.id) for x0 = 1:nt] [obs[x0] = uwreal(data_r[:, x0], cdata.id) for x0 = 1:nt]
return Corr(obs, cdata) return Obs(obs, cdata)
end end
#function corr_obs for R != 1 #function corr_obs for R != 1
#TODO: vcfg with gaps #TODO: vcfg with gaps
function corr_obs(cdata::Array{CData, 1}; real::Bool=true, rw::Union{Array{Array{Float64, 2}, 1}, Nothing}=nothing) function corr_obs(cdata::Array{CData, 1}; real::Bool=true, rw::Union{Array{Array{Float64, 2}, 1}, Nothing}=nothing, L::Int64=1)
nr = length(cdata) nr = length(cdata)
id = getfield.(cdata, :id) id = getfield.(cdata, :id)
vcfg = getfield.(cdata, :vcfg) vcfg = getfield.(cdata, :vcfg)
...@@ -43,7 +43,7 @@ function corr_obs(cdata::Array{CData, 1}; real::Bool=true, rw::Union{Array{Array ...@@ -43,7 +43,7 @@ function corr_obs(cdata::Array{CData, 1}; real::Bool=true, rw::Union{Array{Array
return nothing return nothing
end end
real ? data = getfield.(cdata, :re_data) : data = getfield.(cdata, :im_data) real ? data = getfield.(cdata, :re_data) ./ L^3 : data = getfield.(cdata, :im_data) ./ L^3
isnothing(rw) ? data_r = data : data_r = apply_rw.(data, rw) isnothing(rw) ? data_r = data : data_r = apply_rw.(data, rw)
...@@ -55,5 +55,5 @@ function corr_obs(cdata::Array{CData, 1}; real::Bool=true, rw::Union{Array{Array ...@@ -55,5 +55,5 @@ function corr_obs(cdata::Array{CData, 1}; real::Bool=true, rw::Union{Array{Array
[obs[x0] = uwreal(tmp[:, x0], id[1], replica) for x0 = 1:nt] [obs[x0] = uwreal(tmp[:, x0], id[1], replica) for x0 = 1:nt]
return Corr(obs, cdata) return Obs(obs, cdata)
end end
\ No newline at end of file
...@@ -110,24 +110,24 @@ mutable struct CData ...@@ -110,24 +110,24 @@ mutable struct CData
end end
Base.copy(a::CData) = CData(a.header, a.vcfg, a.re_data, a.im_data, a.id) Base.copy(a::CData) = CData(a.header, a.vcfg, a.re_data, a.im_data, a.id)
mutable struct Corr mutable struct Obs
obs::Vector{uwreal} obs::Union{Vector{uwreal}, uwreal}
mu::Vector{Float64} mu::Vector{Float64}
gamma::Vector{String} gamma::Vector{String}
y0::Int64 y0::Int64
function Corr(a::Vector{uwreal}, b::CData) function Obs(a::Vector{uwreal}, b::CData)
h = getfield(b, :header) h = getfield(b, :header)
mu = [h.mu1, h.mu2] mu = [h.mu1, h.mu2]
gamma = [gamma_name[h.type1+1], gamma_name[h.type2+1]] gamma = [gamma_name[h.type1+1], gamma_name[h.type2+1]]
y0 = Int64(h.x0) y0 = Int64(h.x0)
return new(a, mu, gamma, y0) return new(a, mu, gamma, y0)
end end
function Corr(a::Vector{uwreal}, b::Vector{CData}) function Obs(a::Vector{uwreal}, b::Vector{CData})
sym = [:mu1, :mu2, :type1, :type2, :x0] sym = [:mu1, :mu2, :type1, :type2, :x0]
h = getfield.(b, :header) h = getfield.(b, :header)
for s in sym for s in sym
if !all(getfield.(h, s) .== getfield(h[1], s)) if !all(getfield.(h, s) .== getfield(h[1], s))
println("Corr: Parameter mismatch") println("Obs: Parameter mismatch")
return nothing return nothing
end end
end end
...@@ -136,7 +136,10 @@ mutable struct Corr ...@@ -136,7 +136,10 @@ mutable struct Corr
y0 = Int64(h[1].x0) y0 = Int64(h[1].x0)
return new(a, mu, gamma, y0) return new(a, mu, gamma, y0)
end end
Obs(a::uwreal, b::Obs) = new(a, b.mu, b.gamma, b.y0)
Obs(a::Vector{uwreal}, b::Obs) = new(a, b.mu, b.gamma, b.y0)
end end
function Base.show(io::IO, a::GHeader) function Base.show(io::IO, a::GHeader)
print(io, "ncorr = ", a.ncorr, "\t") print(io, "ncorr = ", a.ncorr, "\t")
print(io, "nnoise = ", a.nnoise, "\t") print(io, "nnoise = ", a.nnoise, "\t")
...@@ -145,6 +148,7 @@ function Base.show(io::IO, a::GHeader) ...@@ -145,6 +148,7 @@ function Base.show(io::IO, a::GHeader)
print(io, "\n") print(io, "\n")
end end
function Base.show(io::IO, a::CHeader) function Base.show(io::IO, a::CHeader)
fnames = fieldnames(CHeader) fnames = fieldnames(CHeader)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment