Commit 1bcd9f33 authored by Javier's avatar Javier

Obs structure deleted + lin_fit added

Obs -> Corr (meff and dec_const_pcvc return Vector{uwreal})
2 linear_fit methods added
parent d84bb9db
......@@ -29,8 +29,8 @@ function meff(obs::Vector{uwreal}, plat::Vector{Int64}; pl::Bool=true, data::Boo
return (mass, aux)
end
end
meff(corr::Obs, plat::Vector{Int64}; pl::Bool=true) =
Obs(meff(corr.obs, plat, pl=pl, data=false), corr)
meff(corr::Corr, plat::Vector{Int64}; pl::Bool=true, data::Bool=false) =
meff(corr.obs, plat, pl=pl, data=data)
## Decay constants
#TODO: test
......@@ -64,9 +64,5 @@ function dec_const_pcvc(obs::Vector{uwreal}, plat::Vector{Int64}, m::uwreal, mu:
return (f, R)
end
end
dec_const_pcvc(corr::Obs, plat::Vector{Int64}, m::uwreal; pl::Bool=true) =
Obs(dec_const_pcvc(corr.obs, plat, m,
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
dec_const_pcvc(corr::Corr, plat::Vector{Int64}, m::uwreal; pl::Bool=true, data::Bool=false) =
dec_const_pcvc(corr.obs, plat, m, corr.mu, corr.y0, pl=pl, data=data)
......@@ -27,7 +27,7 @@ function corr_obs(cdata::CData; real::Bool=true, rw::Union{Array{Float64, 2}, No
nt = size(data)[2]
obs = Vector{uwreal}(undef, nt)
[obs[x0] = uwreal(data_r[:, x0], cdata.id) for x0 = 1:nt]
return Obs(obs, cdata)
return Corr(obs, cdata)
end
#function corr_obs for R != 1
......@@ -55,5 +55,28 @@ 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]
return Obs(obs, cdata)
end
\ No newline at end of file
return Corr(obs, cdata)
end
#TODO: interpolation
function lin_fit(x::Vector{Float64}, v::Vector{Float64}, e::Vector{Float64})
sig2 = e .* e
S = sum(1 ./ sig2)
Sx = sum(x ./ sig2)
Sy = sum(v ./ sig2)
Sxy = sum(v .* x ./ sig2)
Sxx = sum(x .* x ./sig2)
delta = S * Sxx - Sx*Sx
par = [Sxx*Sy-Sx*Sxy, S*Sxy-Sx*Sy] ./delta
#C = [[Sxx/delta, -Sx/delta], [-Sx/delta, S/delta]]
return par
end
function lin_fit(x::Vector{Float64}, y::Vector{uwreal})
uwerr.(y)
par = lin_fit(x, value.(y), err.(y))
chisq(p, d) = sum((d .- p[1] .- p[2].*x).^2 ./ err.(y) .^2)
(fitp, csqexp) = fit_error(chisq, value.(par), y)
return (fitp, csqexp)
end
\ No newline at end of file
......@@ -110,24 +110,24 @@ mutable struct CData
end
Base.copy(a::CData) = CData(a.header, a.vcfg, a.re_data, a.im_data, a.id)
mutable struct Obs
mutable struct Corr
obs::Union{Vector{uwreal}, uwreal}
mu::Vector{Float64}
gamma::Vector{String}
y0::Int64
function Obs(a::Vector{uwreal}, b::CData)
function Corr(a::Vector{uwreal}, b::CData)
h = getfield(b, :header)
mu = [h.mu1, h.mu2]
gamma = [gamma_name[h.type1+1], gamma_name[h.type2+1]]
y0 = Int64(h.x0)
return new(a, mu, gamma, y0)
end
function Obs(a::Vector{uwreal}, b::Vector{CData})
function Corr(a::Vector{uwreal}, b::Vector{CData})
sym = [:mu1, :mu2, :type1, :type2, :x0]
h = getfield.(b, :header)
for s in sym
if !all(getfield.(h, s) .== getfield(h[1], s))
println("Obs: Parameter mismatch")
println("Corr: Parameter mismatch")
return nothing
end
end
......@@ -136,8 +136,6 @@ mutable struct Obs
y0 = Int64(h[1].x0)
return new(a, mu, gamma, y0)
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
function Base.show(io::IO, a::GHeader)
......
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