Commit 4a71479b authored by Alessandro 's avatar Alessandro

now the matching of the charm quark mass is performed as a simultaneous fit...

now the matching of the charm quark mass is performed as a simultaneous fit and not ensemble by ensemble as it was previously
parent ca1f199f
{}
\ No newline at end of file
......@@ -44,8 +44,8 @@ const ZM_tm_error = [42, 33, 42, 48, 55] .* 1e-4
#1608.08900
const t0_data = [2.86, 3.659, 5.164, 8.595]
const t0_error = [11, 16, 18, 29] .* 1e-3
const t0_ph_value = [0.413]
const t0_ph_error = ones(1,1) .* 5e-3
const t0_ph_value = [0.415]
const t0_ph_error = ones(1,1) .* 4e-3
# 1808.09236
const ZA_data = [0.75642, 0.76169, 0.76979, 0.78378, 0.79667]
const ZA_err = [72, 93, 43, 47, 47] .*1e-5
......
func_map = [Bool.([i,j,k,m,n]) for i=0:1 for j=0:1 for k=0:1 for m=0:1 for n=0:1]
basemodel(x,p) = p[1] .+ p[2] .* x[:,2] .+ p[3] .* x[:,3] .+ p[4] .* x[:,1]
a2phi2_2(x) = x[:,1] .* x[:,2].^2 #a^2/8t0*phi2^2
a2phi2(x) = x[:,1] .* x[:,2] # phi2*a^2/8t0
a2phih2(x) = x[:,1] .* x[:,3].^2 # phih^2*a^2/8t0
a3phih3(x) = x[:,1].^(4) .* x[:,3].^4 #phih^3*(a^2/8t0)^3/2
a3cutoff(x) = x[:,1].^(4) #(a^2/8t0)^4
func_list = [a2phi2_2, a2phi2, a2phih2, a3phih3, a3cutoff]
npar = 5 # number of extra parameters
n_lin_param = Vector(4:npar+4) #param for each functions
f_lin = Vector{Vector{Function}}(undef, npar+1) #f[i][j]-> i: number of extra parameters, j: combinations
f_lin[1] = Vector{Function}(undef, 1)
f_lin[1][1] = (x,p) -> basemodel(x,p)
for n = 2:npar+1
aux = filter(x->sum(x) == n-1, func_map)
f_lin[n] = Vector{Function}(undef, length(aux))
k=1
for a in aux
#vectorized function
f_lin[n][k] = (x,p) -> basemodel(x,p) .+ sum([p[i+4] for i=1:(n-1)] .* (fill(x,n-1) .|> func_list[a]))
k = k+1
end
end
f_non_lin = Vector{Vector{Function}}(undef, npar) #f[i][j]-> i: number of extra parameters, j: combinations
n_non_lin_param = Vector(5:npar+4) #param for each non-linear functions
for n = 1:npar
aux = filter(x->sum(x) == n, func_map)
f_non_lin[n] = Vector{Function}(undef, length(aux))
k=1
for a in aux
#vectorized function
f_non_lin[n][k] = (x,p) -> basemodel(x,p) .* (1 .+ sum([p[i+4] for i=1:(n)] .* (fill(x,n) .|> func_list[a])))
k = k+1
end
end
f_basemodel(x,p) = p[1] .+ p[2] .* x[:,2] .+ p[3] ./ sqrt.(x[:,3]) .+ p[4] .* x[:,1]
f_a2phi2_2(x) = x[:,1] .* x[:,2].^2 #a^2/8t0
f_a2phi2(x) = x[:,1] .* x[:,2] # phi2*a^2/8t0
f_a2phih2(x) = x[:,1] ./ x[:,3] # 1/phih*a^2/8t0
f_a3phih3(x) = x[:,1].^(4) ./ x[:,3].^2 #1/phih^3/2*(a^2/8t0)^3/2
f_a3cutoff(x) = x[:,1].^(3/2) #(a^2/8t0)^3/2
f_func_list = [f_a2phi2_2, f_a2phi2, f_a2phih2, f_a3phih3, f_a3cutoff]
f_npar = 5 # number of extra parameters
f_f_lin = Vector{Vector{Function}}(undef, npar+1) #f[i][j]-> i: number of extra parameters, j: combinations
f_f_lin[1] = Vector{Function}(undef, 1)
f_f_lin[1][1] = (x,p) -> basemodel(x,p)
for n = 2:npar+1
aux = filter(x->sum(x) == n-1, func_map)
f_f_lin[n] = Vector{Function}(undef, length(aux))
k=1
for a in aux
#vectorized function
f_f_lin[n][k] = (x,p) -> f_basemodel(x,p) .+ sum([p[i+4] for i=1:(n-1)] .* (fill(x,n-1) .|> f_func_list[a]))
k = k+1
end
end
f_f_non_lin = Vector{Vector{Function}}(undef, npar) #f[i][j]-> i: number of extra parameters, j: combinations
n_non_lin_param = Vector(5:npar+4) #param for each non-linear functions
for n = 1:npar
aux = filter(x->sum(x) == n, func_map)
f_f_non_lin[n] = Vector{Function}(undef, length(aux))
k=1
for a in aux
#vectorized function
f_f_non_lin[n][k] = (x,p) -> f_basemodel(x,p) .* (1 .+ sum([p[i+4] for i=1:(n)] .* (fill(x,n) .|> f_func_list[a])))
k = k+1
end
end
n_param = n_lin_param
append!(n_param, n_non_lin_param)
f = f_lin
append!(f, f_non_lin)
f_dec = f_f_lin
append!(f_dec, f_f_non_lin)
\ No newline at end of file
using Base: String
#using Core: Vector
using LaTeXStrings: length
using Revise, juobs, BDIO, DelimitedFiles, ADerrors, PyPlot, LaTeXStrings, LsqFit
##
rcParams = PyPlot.PyDict(PyPlot.matplotlib."rcParams")
rcParams["text.usetex"] = true
rcParams["mathtext.fontset"] = "cm"
rcParams["font.size"] =11
rcParams["axes.labelsize"] =16
plt.rc("text", usetex=true)
##
#============= SET UP VARIABLES ===========#
const path_data = "/media/alessandro/4277fef2-edc5-4e0d-89cb-f5d1d44fbc8c/data"
const path_plat = "/home/alessandro/automated-analysis/plat.txt"
const path_results = "/home/alessandro/Desktop/results_gevp"
#some problem with the pion mass in N203
const ensembles = ["J303", "H400", "N200" , "N202", "N300", "H101", "N203"]
const sector = Dict("ll"=>false, "ls"=>false, "lh"=>true, "ss"=>false, "sh"=>true, "hh"=>true )
const path_data = "/Volumes/Macintosh HD/Lattice/data"
const path_plat = "/Users/ale/automation/plat.txt"
const path_results = "/Users/ale/Desktop/results_gevp"
const path_rw = "/Users/ale/Desktop/data/ms1_dat"
const path_md = "/Users/ale/Desktop/data/md_dat"
const path_t0 = "/Users/ale/Desktop/data/t0_shifted.bdio"
const path_deltam = "/Users/ale/Desktop/data/deltam.bdio"
const ens_list = ["H101", "H102r001", "H102r002", "H400", "N202", "N200", "N203", "N300", "J303"]
const bdio_rec = [0, 2, 4, 6, 8, 10, 12, 14, 16 ]
#const ens_list = [ "H400", "N202", "N200", "N203", "N300", "J303"]
#const bdio_rec = [ 6, 8, 10, 12, 14, 16 ]
const sector = Dict("ll"=>true, "ls"=>false, "lh"=>true, "ss"=>false, "sh"=>true, "hh"=>true )
const tau = 3
const _t0 = 2
const range_t_fit = [2,5]
const rwf = false
const compute_t0 = false
const mass_shift = false #not implemented yet
const rwf = true
const compute_t0 = true
const mass_shift = true
#go to line 443 to change CL+chiral extrapolation fit model
#========= DO NOT CHANGE AFTER THIS LINE ==========#
include("types.jl")
include("tools.jl")
include("const.jl")
include("func_comb.jl")
#======== GET ENSEMBLE INFORMATION FROM DATABASE ==========#
ensinfo = Vector{EnsInfo}(undef, length(ensembles))
for i in 1:length(ensembles)
ens = ensembles[i]
ensinfo = Vector{EnsInfo}(undef, length(ens_list))
for i in 1:length(ens_list)
ens = ens_list[i]
try
ensinfo[i]= EnsInfo(ens, ens_db[ens])
catch
......@@ -35,11 +52,11 @@ end
##
#======== ANALYSIS ==========#
gen_mulist = Vector{Vector{Vector{Float64}}}(undef, length(ensembles))
gen_mulist = Vector{Vector{Vector{Float64}}}(undef, length(ens_list))
println("\n Building matrices \n")
@time begin
matinfo = Vector{Vector{MatInfo}}(undef,length(ensembles))
matinfo_vec = Vector{Vector{MatInfo}}(undef,length(ensembles))
matinfo = Vector{Vector{MatInfo}}(undef,length(ens_list))
matinfo_vec = Vector{Vector{MatInfo}}(undef,length(ens_list))
for i in 1:length(ensinfo)
@time begin
ens = ensinfo[i]
......@@ -56,12 +73,13 @@ println("\n Building matrices \n")
end
##
wpmm = Dict{Int64, Vector{Float64}}()
wpmm[303] = [-1.0, 1.5,-1.0, -1.0]
wpmm[303] = [-1.0, 2.0,-1.0, -1.0]
wpmm[300] = [-1.0, 1.5,-1.0, -1.0]
println("\n Computing observables \n")
@time begin
ensobs = Vector{EnsObs}(undef, length(ensembles))
ensobs = Vector{EnsObs}(undef, length(ens_list))
for i in 1:length(ensinfo)
@time begin
ens = ensinfo[i]
......@@ -96,360 +114,972 @@ println("\n Computing observables \n")
end
println("Total time:")
end
## ##################################### SO FAR SO GOOD
println("\n Matching Procedure \n")
## MASS SHIFTING
if mass_shift
println("Applying mass corrections")
# read deltam from BDIO
#deltam_tmp = []
#while BDIO_seek!(fb,2)
# aux = read_uwreal(fb)
# uwerr(aux)
# if ensembles(aux)[1] in ens_list
# push!(deltam_tmp, aux)
# end
#end
@time begin
#reading deltam values
for i in 1:length(ensobs)
ens = ensobs[i]
mul, mus, muh = get_mu(ens.mu_list, ens.ensinfo.deg)
if compute_t0
est_t0 = get_t0(ens.ensinfo, rw=rwf)
ens.t0 = est_t0
est_a = t0_ph[1] / sqrt(8 * ens.t0)
ens.a = est_a
else
ens.t0 = t0(ens.ensinfo.beta)
ens.a = a(ens.ensinfo.beta)
end
#target = ens.a * (2/3*M[1] + 1/3* M[3])/ hc
target = ens.a * M[5] / hc
if !ens.ensinfo.deg
#ens.muh_target = match_muc(muh, ens.m_lh, ens.m_sh, target)
ens.muh_target = match_muc_heavymass(muh, ens.m_hh, target)
else
#ens.muh_target = match_muc(muh, ens.m_lh, ens.m_sh, target)
ens.muh_target = match_muc_heavymass(muh, ens.m_hh, target)
end
uwerr(ens.muh_target)
println(t0, "\n", a, "\n", ens.muh_target)
# interpolate lh
if sector["lh"]
# m_lh
par, chi2exp = lin_fit(muh, ens.m_lh)
ens.m_lh_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.m_lh_match)
#m_lh_star
par, chi2exp = lin_fit(muh, ens.m_lh_vec)
ens.m_lh_vec_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.m_lh_vec_match)
# f_lh
par, chi2exp = lin_fit(muh, ens.f_lh)
ens.f_lh_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.f_lh_match)
#f_lh_star
par, chi2exp = lin_fit(muh, ens.f_lh_vec)
ens.f_lh_vec_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.f_lh_vec_match)
end
# interpolate sh
if sector["sh"]
if ens.ensinfo.deg
ens.m_sh_match = ens.m_lh_match
ens.m_sh_vec_match = ens.m_lh_vec_match
ens.f_sh_match = ens.f_lh_match
ens.f_sh_vec_match = ens.f_lh_vec_match
else
# m_sh
par, chi2exp = lin_fit(muh, ens.m_sh)
ens.m_sh_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.m_sh_match)
# m_sh_star
par, chi2exp = lin_fit(muh, ens.m_sh_vec)
ens.m_sh_vec_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.m_sh_vec_match)
# f_sh
par, chi2exp = lin_fit(muh, ens.f_sh)
ens.f_sh_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.f_sh_match)
# f_sh_star
par, chi2exp = lin_fit(muh, ens.f_sh_vec)
ens.f_sh_vec_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.f_sh_vec_match)
end
end
# interpolate hh
if sector["hh"]
# m_hh
par, chi2exp = lin_fit(muh, ens.m_hh)
ens.m_hh_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.m_hh_match)
# m_hh_vec
par, chi2exp = lin_fit(muh, ens.m_hh_vec)
ens.m_hh_vec_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.m_hh_vec_match)
# f_hh
par, chi2exp = lin_fit(muh, ens.f_hh)
ens.f_hh_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.f_hh_match)
# f_hh_vec
par, chi2exp = lin_fit(muh, ens.f_hh_vec)
ens.f_hh_vec_match = y_lin_fit(par, value(ens.muh_target))
uwerr(ens.f_hh_vec_match)
fb = BDIO_open(path_deltam, "r")
BDIO_seek!(fb)
if bdio_rec[i] != 0
BDIO_seek!(fb, bdio_rec[i])
end
println("ensemble ", ens.ensinfo.id)
println("bdio record ", bdio_rec[i])
ens.deltam = read_uwreal(fb)
BDIO_close!(fb)
end
println(" Total time:")
end
#========== MATCHING PLOTS ==========#
#applying mass shift to m_ll m_lh m_sh m_hh f_lh f_sh f_hh and vectorial counterpart
for i in 1:length(ensobs)
ens = ensobs[i]
md = read_mass_dev(ens.ensinfo.id)
#MASSES
#ll
println("m_ll")
println("unshift ", ens.m_ll)
mdl, mds = md_sea(ens.m_ll, md)
ens.m_ll += ens.deltam * (2*mdl + mds)
uwerr(ens.m_ll)
println("shifted ", ens.m_ll)
#lh pseudo
println("\nm_lh")
uwerr.(ens.m_lh)
println("unshift ", ens.m_lh)
mdl1, mds1 = md_sea(ens.m_lh[1], md)
mdl2, mds2 = md_sea(ens.m_lh[2], md)
mdl3, mds3 = md_sea(ens.m_lh[3], md)
ens.m_lh[1] += ens.deltam * (2*mdl1 + mds1)
ens.m_lh[2] += ens.deltam * (2*mdl2 + mds2)
ens.m_lh[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.m_lh)
println("shifted", ens.m_lh)
#lh vec
println("\nm_lh_vec")
uwerr.(ens.m_lh_vec)
println("unshift ", ens.m_lh_vec)
mdl1, mds1 = md_sea(ens.m_lh_vec[1], md)
mdl2, mds2 = md_sea(ens.m_lh_vec[2], md)
mdl3, mds3 = md_sea(ens.m_lh_vec[3], md)
ens.m_lh_vec[1] += ens.deltam * (2*mdl1 + mds1)
ens.m_lh_vec[2] += ens.deltam * (2*mdl2 + mds2)
ens.m_lh_vec[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.m_lh_vec)
println("shifted ", ens.m_lh_vec)
#sh pseudo
println("\nm_sh")
uwerr.(ens.m_sh)
println("unshift ", ens.m_sh)
mdl1, mds1 = md_sea(ens.m_sh[1], md)
mdl2, mds2 = md_sea(ens.m_sh[2], md)
mdl3, mds3 = md_sea(ens.m_sh[3], md)
ens.m_sh[1] += ens.deltam * (2*mdl1 + mds1)
ens.m_sh[2] += ens.deltam * (2*mdl2 + mds2)
ens.m_sh[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.m_sh)
println("shifted", ens.m_sh)
#sh vec
println("\nm_sh_vec")
uwerr.(ens.m_sh_vec)
println("unshift ", ens.m_sh_vec)
mdl1, mds1 = md_sea(ens.m_sh_vec[1], md)
mdl2, mds2 = md_sea(ens.m_sh_vec[2], md)
mdl3, mds3 = md_sea(ens.m_sh_vec[3], md)
ens.m_sh_vec[1] += ens.deltam * (2*mdl1 + mds1)
ens.m_sh_vec[2] += ens.deltam * (2*mdl2 + mds2)
ens.m_sh_vec[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.m_sh_vec)
println("shift", ens.m_sh_vec)
#hh pseudo
println("\nm_hh")
uwerr.(ens.m_hh)
println("unshift ", ens.m_hh)
mdl1, mds1 = md_sea(ens.m_hh[1], md)
mdl2, mds2 = md_sea(ens.m_hh[2], md)
mdl3, mds3 = md_sea(ens.m_hh[3], md)
ens.m_hh[1] += ens.deltam * (2*mdl1 + mds1)
ens.m_hh[2] += ens.deltam * (2*mdl2 + mds2)
ens.m_hh[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.m_hh)
println("shift ", ens.m_hh)
#hh vec
println("\nm_hh_vec")
uwerr.(ens.m_hh_vec)
println("unshift ", ens.m_hh_vec)
mdl1, mds1 = md_sea(ens.m_hh_vec[1], md)
mdl2, mds2 = md_sea(ens.m_hh_vec[2], md)
mdl3, mds3 = md_sea(ens.m_hh_vec[3], md)
ens.m_hh_vec[1] += ens.deltam * (2*mdl1 + mds1)
ens.m_hh_vec[2] += ens.deltam * (2*mdl2 + mds2)
ens.m_hh_vec[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.m_hh_vec)
println("shift ", ens.m_hh_vec)
#DECAYS
#lh pseudo
println("\nf_lh")
uwerr.(ens.f_lh)
println("unshift ", ens.f_lh)
mdl1, mds1 = md_sea(ens.f_lh[1], md)
mdl2, mds2 = md_sea(ens.f_lh[2], md)
mdl3, mds3 = md_sea(ens.f_lh[3], md)
ens.f_lh[1] += ens.deltam * (2*mdl1 + mds1)
ens.f_lh[2] += ens.deltam * (2*mdl2 + mds2)
ens.f_lh[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.f_lh)
println("shifted ", ens.f_lh)
#lh vec
println("\nf_lh_vec")
uwerr.(ens.f_lh_vec)
println("unshift ", ens.f_lh_vec)
mdl1, mds1 = md_sea(ens.f_lh_vec[1], md)
mdl2, mds2 = md_sea(ens.f_lh_vec[2], md)
mdl3, mds3 = md_sea(ens.f_lh_vec[3], md)
ens.f_lh_vec[1] += ens.deltam * (2*mdl1 + mds1)
ens.f_lh_vec[2] += ens.deltam * (2*mdl2 + mds2)
ens.f_lh_vec[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.f_lh_vec)
println("shift ", ens.f_lh_vec)
#sh pseudo
println("\nf_sh")
uwerr.(ens.f_sh)
println("unshift ", ens.f_sh)
mdl1, mds1 = md_sea(ens.f_sh[1], md)
mdl2, mds2 = md_sea(ens.f_sh[2], md)
mdl3, mds3 = md_sea(ens.f_sh[3], md)
ens.f_sh[1] += ens.deltam * (2*mdl1 + mds1)
ens.f_sh[2] += ens.deltam * (2*mdl2 + mds2)
ens.f_sh[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.f_sh)
println("shifted ", ens.f_sh)
#sh vec
println("\nf_sh_vec")
uwerr.(ens.f_sh_vec)
println("unshift ", ens.f_sh_vec)
mdl1, mds1 = md_sea(ens.f_sh_vec[1], md)
mdl2, mds2 = md_sea(ens.f_sh_vec[2], md)
mdl3, mds3 = md_sea(ens.f_sh_vec[3], md)
ens.f_sh_vec[1] += ens.deltam * (2*mdl1 + mds1)
ens.f_sh_vec[2] += ens.deltam * (2*mdl2 + mds2)
ens.f_sh_vec[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.f_sh_vec)
println("shifted ", ens.f_sh_vec)
#hh pseudo
println("\nf_hh")
uwerr.(ens.f_hh)
println("unshift ", ens.f_hh)
mdl1, mds1 = md_sea(ens.f_hh[1], md)
mdl2, mds2 = md_sea(ens.f_hh[2], md)
mdl3, mds3 = md_sea(ens.f_hh[3], md)
ens.f_hh[1] += ens.deltam * (2*mdl1 + mds1)
ens.f_hh[2] += ens.deltam * (2*mdl2 + mds2)
ens.f_hh[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.f_hh)
println("shifted ", ens.f_hh)
#hh vec
println("\nf_hh_vec")
uwerr.(ens.f_hh_vec)
println("unshift ", ens.f_hh_vec)
mdl1, mds1 = md_sea(ens.f_hh_vec[1], md)
mdl2, mds2 = md_sea(ens.f_hh_vec[2], md)
mdl3, mds3 = md_sea(ens.f_hh_vec[3], md)
ens.f_hh_vec[1] += ens.deltam * (2*mdl1 + mds1)
ens.f_hh_vec[2] += ens.deltam * (2*mdl2 + mds2)
ens.f_hh_vec[3] += ens.deltam * (2*mdl3 + mds3)
uwerr.(ens.f_hh_vec)
println("shifted ", ens.f_hh_vec)
end
println("\n Matchin Plots \n ")
check_folder = filter(x-> occursin("plots", x), readdir(path_results))
if !("plots" in check_folder)
mkdir(joinpath(path_results,"plots"))
end
path_plot = joinpath(path_results,"plots")
## COLLECT RESULTS AT FINITE LATTICE SPACING
muc = Vector{uwreal}(undef, 0)
phih_eta = Vector{uwreal}(undef, 0) # matching with eta_c
phih_fa = Vector{uwreal}(undef, 0) # matching with flavour average
phi2 = Vector{uwreal}(undef, 0)
t0arr = Vector{uwreal}(undef, 0)
phih_eta_ph = M_values[5] * t0_ph[1] / hc
phih_fa_ph = (2/3 * M_values[1] + 1/3 * M_values[3]) * t0_ph[1] / hc
phi2_ph = (t0_ph[1] * 139 / hc)^2 #134.8 isospin breaking pion mass
uwerr(phi2_ph)
uwerr(phih_eta_ph)
uwerr(phih_fa_ph)
#lh sector
m_D = Vector{uwreal}(undef, 0)
m_D_star =Vector{uwreal}(undef, 0)
f_D= Vector{uwreal}(undef, 0)
f_D_star =Vector{uwreal}(undef, 0)
#sh sector
m_Ds = Vector{uwreal}(undef, 0)
m_Ds_star =Vector{uwreal}(undef, 0)
f_Ds= Vector{uwreal}(undef, 0)
f_Ds_star =Vector{uwreal}(undef, 0)
# hh
m_etac = Vector{uwreal}(undef, 0)
m_jpsi =Vector{uwreal}(undef, 0)
f_etac= Vector{uwreal}(undef, 0)
f_jpsi =Vector{uwreal}(undef, 0)
#here i also load t0 from bdio if compute_t0==true, else i load from const.jl
for i in 1:length(ensobs)
ens = ensobs[i]
println(ens.ensinfo.id)
if compute_t0
fb = BDIO_open(path_t0, "r")
BDIO_seek!(fb)
if bdio_rec[i] != 0
BDIO_seek!(fb, bdio_rec[i])
end
ens.t0 = read_uwreal(fb)
BDIO_close!(fb)
ens.a = t0_ph[1] / sqrt(8 * ens.t0)
else
println("Keep in mind: t0 taken from const.jl - no correlation considered")
ens.t0 = t0(ens.ensinfo.beta)
ens.a = a(ens.ensinfo.beta)
end
#collect RGI muh and store in muc
mul, mus, muh = get_mu(ens.mu_list, ens.ensinfo.deg)
[push!(muc, zm_tm(ens.ensinfo.beta) * muh[i] * sqrt(8 * ens.t0)) for i in 1:length(muh)]
#collect t0 for 3 times and store in t0arr
[push!(t0arr, ens.t0) for i in 1:length(muh)]
#collect phih_fa and store in phih_fa
_8t0m_lh = (2/3 .* getfield(ens,:m_lh) .+ 1/3 .* getfield(ens,:m_sh))
[push!(phih_fa, _8t0m_lh[i] * sqrt(8 * ens.t0)) for i in 1:length(_8t0m_lh)]
#collect phih_eta and store in phih_eta
_8t0m_hh = getfield(ens, :m_hh)
[push!(phih_eta, _8t0m_hh[i] * sqrt(8 * ens.t0)) for i in 1:length(_8t0m_hh)]
#collect phi2 and store in phi2
sector["ll"] ? phi2_aux = 8 * ens.t0 * ens.m_ll^2 : phi2_aux = 8 * ens.t0 * ens.ensinfo.mpi^2
#phi2_aux = 8 * ens.t0 * ens.m_ll^2
[push!(phi2, phi2_aux) for i in 1:length(muh)]
if sector["lh"]
# masses
figure()
title(ens.ensinfo.id)
xlabel(L"$a\mu$")
ylabel(L"$aM$")
#m_lh
errorbar(muh, value.(ens.m_lh), yerr=err.(ens.m_lh), fmt="*", ms=5, mfc="none", capsize=2, c="tomato", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.m_lh_match), yerr=err(ens.m_lh_match), fmt="*", ms=5, mfc="none", capsize=2, c="darkred", lw=1)
#m_lh_star
errorbar(muh, value.(ens.m_lh_vec), yerr=err.(ens.m_lh_vec), fmt="*", ms=5, mfc="none", capsize=2, c="cornflowerblue", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.m_lh_vec_match), yerr=err(ens.m_lh_vec_match), fmt="*", ms=5, mfc="none", capsize=2, c="navy", lw=1)
legend([L"$m_D$", L"$\langle m_D \rangle$", L"$m_{D^*}$", L"$ \langle m_{D^*}\rangle $"])
display(gcf())
name = string(ens.ensinfo.id,"_match_mD_mDvec.pdf")
savefig(joinpath(path_plot, name))
close()
# decays
figure()
title(ens.ensinfo.id)
xlabel(L"$a\mu$")
ylabel(L"$af$")
#m_lh
errorbar(muh, value.(ens.f_lh), yerr=err.(ens.f_lh), fmt="*", ms=5, mfc="none", capsize=2, c="tomato", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.f_lh_match), yerr=err(ens.f_lh_match), fmt="*", ms=5, mfc="none", capsize=2, c="darkred", lw=1)
#m_lh_star
errorbar(muh, value.(ens.f_lh_vec), yerr=err.(ens.f_lh_vec), fmt="*", ms=5, mfc="none", capsize=2, c="cornflowerblue", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.f_lh_vec_match), yerr=err(ens.f_lh_vec_match), fmt="*", ms=5, mfc="none", capsize=2, c="navy", lw=1)
legend([L"$f_D$", L"$\langle f_D \rangle$", L"$f_{D^*}$", L"$ \langle f_{D^*}\rangle $"])
display(gcf())
name = string(ens.ensinfo.id,"_match_fD_fDvec.pdf")
savefig(joinpath(path_plot, name))
close()
end
if sector["sh"] && !ens.ensinfo.deg
# masses
figure()
title(ens.ensinfo.id)
xlabel(L"$a\mu$")
ylabel(L"$aM$")
#m_sh
errorbar(muh, value.(ens.m_sh), yerr=err.(ens.m_sh), fmt="*", ms=5, mfc="none", capsize=2, c="tomato", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.m_sh_match), yerr=err(ens.m_sh_match), fmt="*", ms=5, mfc="none", capsize=2, c="darkred", lw=1)
#m_sh_star
errorbar(muh, value.(ens.m_sh_vec), yerr=err.(ens.m_sh_vec), fmt="*", ms=5, mfc="none", capsize=2, c="cornflowerblue", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.m_sh_vec_match), yerr=err(ens.m_sh_vec_match), fmt="*", ms=5, mfc="none", capsize=2, c="navy", lw=1)
legend([L"$m_{D_s}$", L"$\langle m_{D_s} \rangle$", L"$m_{D^*_s}$", L"$ \langle m_{D^*_s}\rangle $"])
display(gcf())
name = string(ens.ensinfo.id,"_match_mDs_mDsvec.pdf")
savefig(joinpath(path_plot, name))
close()
# decays
figure()
title(ens.ensinfo.id)
xlabel(L"$a\mu$")
ylabel(L"$af$")
#f_sh
errorbar(muh, value.(ens.f_sh), yerr=err.(ens.f_sh), fmt="*", ms=5, mfc="none", capsize=2, c="tomato", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.f_sh_match), yerr=err(ens.f_sh_match), fmt="*", ms=5, mfc="none", capsize=2, c="darkred", lw=1)
#fsh_star
errorbar(muh, value.(ens.f_sh_vec), yerr=err.(ens.f_sh_vec), fmt="*", ms=5, mfc="none", capsize=2, c="cornflowerblue", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.f_sh_vec_match), yerr=err(ens.f_sh_vec_match), fmt="*", ms=5, mfc="none", capsize=2, c="navy", lw=1)
legend([L"$f_{D_s}$", L"$\langle f_{D_s} \rangle$", L"$f_{D^*_s}$", L"$ \langle f_{D^*_s}\rangle $"])
display(gcf())
name = string(ens.ensinfo.id,"_match_fDs_fDsvec.pdf")
savefig(joinpath(path_plot, name))
close()
end
if sector["hh"]
# masses
figure()
title(ens.ensinfo.id)
xlabel(L"$a\mu$")
ylabel(L"$aM$")
#m_hh
errorbar(muh, value.(ens.m_hh), yerr=err.(ens.m_hh), fmt="*", ms=5, mfc="none", capsize=2, c="tomato", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.m_hh_match), yerr=err(ens.m_hh_match), fmt="*", ms=5, mfc="none", capsize=2, c="darkred", lw=1)
#m_hh_star
errorbar(muh, value.(ens.m_hh_vec), yerr=err.(ens.m_hh_vec), fmt="*", ms=5, mfc="none", capsize=2, c="cornflowerblue", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.m_hh_vec_match), yerr=err(ens.m_hh_vec_match), fmt="*", ms=5, mfc="none", capsize=2, c="navy", lw=1)
legend([L"$m_{\eta_c}$", L"$\langle m_{\eta_c} \rangle$", L"$m_{J/\psi}$", L"$ \langle m_{J/\psi}\rangle $"])
display(gcf())
name = string(ens.ensinfo.id,"_match_metac_mJpsi.pdf")
savefig(joinpath(path_plot, name))
close()
# decays
figure()
title(ens.ensinfo.id)
xlabel(L"$a\mu$")
ylabel(L"$af$")
#f_hh
errorbar(muh, value.(ens.f_hh), yerr=err.(ens.f_hh), fmt="*", ms=5, mfc="none", capsize=2, c="tomato", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.f_hh_match), yerr=err(ens.f_hh_match), fmt="*", ms=5, mfc="none", capsize=2, c="darkred", lw=1)
#f_hh_star
errorbar(muh, value.(ens.f_hh_vec), yerr=err.(ens.f_hh_vec), fmt="*", ms=5, mfc="none", capsize=2, c="cornflowerblue", lw=1)
errorbar(value(ens.muh_target), xerr=err(ens.muh_target), value(ens.f_hh_vec_match), yerr=err(ens.f_hh_vec_match), fmt="*", ms=5, mfc="none", capsize=2, c="navy", lw=1)
legend([L"$f_{\eta_c}$", L"$\langle f_{\eta_c} \rangle$", L"$f_{J/\psi}$", L"$ \langle f_{J/\psi}\rangle $"])
display(gcf())
name = string(ens.ensinfo.id,"_match_fetac_fJpsi.pdf")
savefig(joinpath(path_plot, name))
close()
aux_lh = getfield(ens, :m_lh)
[push!(m_D, aux_lh[j] *sqrt(8*ens.t0)) for j in 1:length(aux_lh)]
aux_lh_vec = getfield(ens, :m_lh_vec)
[push!(m_D_star, aux_lh_vec[j] *sqrt(8*ens.t0)) for j in 1:length(aux_lh)]
aux_lh = getfield(ens, :f_lh)
[push!(f_D, aux_lh[j] *sqrt(8*ens.t0)) for j in 1:length(aux_lh)]
aux_lh_vec = getfield(ens, :f_lh_vec)
[push!(f_D_star, za(ens.ensinfo.beta) * aux_lh_vec[j] *sqrt(8*ens.t0)) for j in 1:length(aux_lh)]
end
if sector["sh"]
aux_sh = getfield(ens, :m_sh)
[push!(m_Ds, aux_sh[j] *sqrt(8*ens.t0)) for j in 1:length(aux_sh)]
aux_sh_vec = getfield(ens, :m_sh_vec)
[push!(m_Ds_star, aux_sh_vec[j] *sqrt(8*ens.t0)) for j in 1:length(aux_sh)]
aux_sh = getfield(ens, :f_sh)
[push!(f_Ds, aux_sh[j] *sqrt(8*ens.t0)) for j in 1:length(aux_sh)]
aux_sh_vec = getfield(ens, :f_sh_vec)
[push!(f_Ds_star, za(ens.ensinfo.beta) * aux_sh_vec[j] *sqrt(8*ens.t0)) for j in 1:length(aux_sh)]
end
if sector["hh"]
aux_hh = getfield(ens, :m_hh)
[push!(m_etac, aux_hh[j] *sqrt(8*ens.t0)) for j in 1:length(aux_hh)]
aux_hh_vec = getfield(ens, :m_hh_vec)
[push!(m_jpsi, aux_hh_vec[j] *sqrt(8*ens.t0)) for j in 1:length(aux_hh)]
aux_hh = getfield(ens, :f_hh)
[push!(f_etac, aux_hh[j] *sqrt(8*ens.t0)) for j in 1:length(aux_hh)]
aux_hh_vec = getfield(ens, :f_hh_vec)
[push!(f_jpsi, za(ens.ensinfo.beta) * aux_hh_vec[j] *sqrt(8*ens.t0)) for j in 1:length(aux_hh)]
end
end
# prepare observables for ensembles with beta>3.4
muc_sub = Vector{uwreal}(undef, 0)
phih_eta_sub = Vector{uwreal}(undef, 0) # matching with eta_c
phih_fa_sub = Vector{uwreal}(undef, 0) # matching with flavour average
phi2_sub = Vector{uwreal}(undef, 0)
t0arr_sub = Vector{uwreal}(undef, 0)
#lh sector
m_D_sub = Vector{uwreal}(undef, 0)
m_D_star_sub =Vector{uwreal}(undef, 0)
f_D_sub = Vector{uwreal}(undef, 0)
f_D_star_sub =Vector{uwreal}(undef, 0)
#sh sector
m_Ds_sub = Vector{uwreal}(undef, 0)
m_Ds_star_sub =Vector{uwreal}(undef, 0 )
f_Ds_sub = Vector{uwreal}(undef, 0)
f_Ds_star_sub =Vector{uwreal}(undef, 0)
# hh
m_etac_sub = Vector{uwreal}(undef, 0)
m_jpsi_sub =Vector{uwreal}(undef, 0)
f_etac_sub = Vector{uwreal}(undef, 0)
f_jpsi_sub =Vector{uwreal}(undef, 0)
# ensembles with beta>3.4
sub_ens_index = findall(x->x>3.4, getfield.(getfield.(ensobs,:ensinfo), :beta))
for index in sub_ens_index
[push!(muc_sub, muc[3*(index-1) + i]) for i in 1:3]
[push!(phih_eta_sub, phih_eta[3*(index-1) + i]) for i in 1:3]
[push!(phih_fa_sub, phih_fa[3*(index-1) + i]) for i in 1:3]
[push!(phi2_sub, phi2[3*(index-1) + i]) for i in 1:3]
[push!(t0arr_sub, t0arr[3*(index-1) + i]) for i in 1:3]
#lh sector
[push!(m_D_sub, m_D[3*(index-1) + i]) for i in 1:3]
[push!(m_D_star_sub, m_D_star[3*(index-1) + i]) for i in 1:3]
[push!(f_D_sub, f_D[3*(index-1) + i]) for i in 1:3]
[push!(f_D_star_sub, f_D_star[3*(index-1) + i]) for i in 1:3]
#sh sector
[push!(m_Ds_sub, m_Ds[3*(index-1) + i]) for i in 1:3]
[push!(m_Ds_star_sub, m_Ds_star[3*(index-1) + i]) for i in 1:3]
[push!(f_Ds_sub, f_Ds[3*(index-1) + i]) for i in 1:3]
[push!(f_Ds_star_sub, f_Ds_star[3*(index-1) + i]) for i in 1:3]
#hh sector
[push!(m_etac_sub, m_etac[3*(index-1) + i]) for i in 1:3]
[push!(m_jpsi_sub, m_jpsi[3*(index-1) + i]) for i in 1:3]
[push!(f_etac_sub, f_etac[3*(index-1) + i]) for i in 1:3]
[push!(f_jpsi_sub, f_jpsi[3*(index-1) + i]) for i in 1:3]
end
## #####################################
##
# Now i need to create different categories
# x values for fit_routine for different categories
x_fa = [1 ./(8 .* t0arr) phi2 phih_fa]
x_eta = [1 ./(8 .* t0arr) phi2 phih_eta]
x_fa_sub = [1 ./(8 .* t0arr_sub) phi2_sub phih_fa_sub]
x_eta_sub = [1 ./(8 .* t0arr_sub) phi2_sub phih_eta_sub]
# muc
cat_muc = Vector{Cat}(undef, 0)
push!(cat_muc, Cat(muc, x_fa , phih_fa_ph ,"muc, all_ens, fl_ave"))
push!(cat_muc, Cat(muc, x_eta , phih_eta_ph, "muc, all_ens, etac"))
push!(cat_muc, Cat(muc_sub, x_fa_sub , phih_fa_ph,"muc, sub_ens, fl_ave"))
push!(cat_muc, Cat(muc_sub, x_eta_sub , phih_eta_ph,"muc, sub_ens, etac"))
# m_etac
cat_m_eta = Vector{Cat}(undef, 0)
push!(cat_m_eta, Cat(m_etac, x_fa , phih_fa_ph ,"m_etac, all_ens, fl_ave"))
push!(cat_m_eta, Cat(m_etac, x_eta , phih_eta_ph, "m_etac, all_ens, etac"))
push!(cat_m_eta, Cat(m_etac_sub, x_fa_sub , phih_fa_ph,"m_etac, sub_ens, fl_ave"))
push!(cat_m_eta, Cat(m_etac_sub, x_eta_sub , phih_eta_ph,"m_etac, sub_ens, etac"))
# m_jpsi
cat_m_jpsi = Vector{Cat}(undef, 0)
push!(cat_m_jpsi, Cat(m_jpsi, x_fa , phih_fa_ph ,"m_jpsi, all_ens, fl_ave"))
push!(cat_m_jpsi, Cat(m_jpsi, x_eta , phih_eta_ph, "m_jpsi, all_ens, etac"))
push!(cat_m_jpsi, Cat(m_jpsi_sub, x_fa_sub , phih_fa_ph,"m_jpsi, sub_ens, fl_ave"))
push!(cat_m_jpsi, Cat(m_jpsi_sub, x_eta_sub , phih_eta_ph,"m_jpsi, sub_ens, etac"))
# m_D
cat_m_D = Vector{Cat}(undef, 0)
push!(cat_m_D, Cat(m_D, x_fa , phih_fa_ph ,"m_D, all_ens, fl_ave"))
push!(cat_m_D, Cat(m_D, x_eta , phih_eta_ph, "m_D, all_ens, etac"))
push!(cat_m_D, Cat(m_D_sub, x_fa_sub , phih_fa_ph,"m_D, sub_ens, fl_ave"))
push!(cat_m_D, Cat(m_D_sub, x_eta_sub , phih_eta_ph,"m_D, sub_ens, etac"))
# m_D_star
cat_m_D_star = Vector{Cat}(undef, 0)
push!(cat_m_D_star, Cat(m_D_star, x_fa , phih_fa_ph ,"m_D_star, all_ens, fl_ave"))
push!(cat_m_D_star, Cat(m_D_star, x_eta , phih_eta_ph, "m_D_star, all_ens, etac"))
push!(cat_m_D_star, Cat(m_D_star_sub, x_fa_sub , phih_fa_ph,"m_D_star, sub_ens, fl_ave"))
push!(cat_m_D_star, Cat(m_D_star_sub, x_eta_sub , phih_eta_ph,"m_D_star, sub_ens, etac"))
# m_Ds
cat_m_Ds = Vector{Cat}(undef, 0)
push!(cat_m_Ds, Cat(m_Ds, x_fa , phih_fa_ph ,"m_Ds, all_ens, fl_ave"))
push!(cat_m_Ds, Cat(m_Ds, x_eta , phih_eta_ph, "m_Ds, all_ens, etac"))
push!(cat_m_Ds, Cat(m_Ds_sub, x_fa_sub , phih_fa_ph,"m_Ds, sub_ens, fl_ave"))
push!(cat_m_Ds, Cat(m_Ds_sub, x_eta_sub , phih_eta_ph,"m_Ds, sub_ens, etac"))
# m_Ds_star
cat_m_Ds_star = Vector{Cat}(undef, 0)
push!(cat_m_Ds_star, Cat(m_Ds_star, x_fa , phih_fa_ph ,"m_Ds_star, all_ens, fl_ave"))
push!(cat_m_Ds_star, Cat(m_Ds_star, x_eta , phih_eta_ph, "m_Ds_star, all_ens, etac"))
push!(cat_m_Ds_star, Cat(m_Ds_star_sub, x_fa_sub , phih_fa_ph,"m_Ds_star, sub_ens, fl_ave"))
push!(cat_m_Ds_star, Cat(m_Ds_star_sub, x_eta_sub , phih_eta_ph,"m_Ds_star, sub_ens, etac"))
mass_cat = [cat_muc, cat_m_eta, cat_m_jpsi, cat_m_D, cat_m_D_star, cat_m_Ds, cat_m_Ds_star]
##
for elem in mass_cat
for i in 1:length(elem)
cat = elem[i]
println("\n", cat.info, "\n")
for j in 1:length(f) # looping over number of parameters
for k in 1:length(f[j]) # looping over combinations with fixed parameters
println(" j is :", j, " k is equal: ", k)
try
par, chi_corr = fit_routine(f[j][k],cat.x_tofit, cat.obs, n_param[j], covar=true, wpm=wpmm)
aux = par[1] + par[2]*phi2_ph + par[3]*cat.phih_ph
uwerr(aux)
push!(cat.fit_res, aux)
push!(cat.fit_param, par)
push!(cat.chi2_corr, chi_corr)
push!(cat.n_param, n_param[j])
push!(cat.aic, chi_corr +2*n_param[j])
catch
println("There was a problem... Probably the analysis failed for some error id.")
println("The result has been excluded from the category")
end
end
end
#======= RESULTS ==========#
# charm quark mass
muc = zm_tm.(getfield.(ensinfo,:beta)) .* getfield.(ensobs,:muh_target) .* sqrt.(8 * getfield.(ensobs,:t0))
uwerr.(muc)
# ll
m_pi = Vector{uwreal}(undef, length(ensembles))
m_rho =Vector{uwreal}(undef, length(ensembles))
f_pi = Vector{uwreal}(undef, length(ensembles))
f_rho =Vector{uwreal}(undef, length(ensembles))
if sector["ll"]
try
m_pi .= getfield.(ensobs, :m_ll) .* sqrt.(8 * getfield.(ensobs,:t0))
m_rho .= getfield.(ensobs, :m_ll_vec) .* sqrt.(8 * getfield.(ensobs,:t0))
f_pi .= getfield.(ensobs, :f_ll) .* sqrt.(8 * getfield.(ensobs,:t0))
f_rho .= getfield.(ensobs, :f_ll_vec) .* sqrt.(8 * getfield.(ensobs,:t0))
uwerr.(m_pi)
uwerr.(m_rho)
uwerr.(f_pi)
uwerr.(f_rho)
catch
error("Check ensobs[i].mu_list to see whether all the ensembles have a light-light sector.")
end
end
# ls
m_k = Vector{uwreal}(undef, length(ensembles))
m_k_star =Vector{uwreal}(undef, length(ensembles))
f_k= Vector{uwreal}(undef, length(ensembles))
f_k_star =Vector{uwreal}(undef, length(ensembles))
if sector["ls"]
try
m_k .= getfield.(ensobs, :m_ls) .* sqrt.(8 * getfield.(ensobs,:t0))
m_k_star .= getfield.(ensobs, :m_ls_vec) .* sqrt.(8 * getfield.(ensobs,:t0))
f_k .= getfield.(ensobs, :f_ls) .* sqrt.(8 * getfield.(ensobs,:t0))
f_k_star .= getfield.(ensobs, :f_ls_vec) .* sqrt.(8 * getfield.(ensobs,:t0))
uwerr.(m_k)
uwerr.(m_k_star)
uwerr.(f_k)
uwerr.(f_k_star)
catch
error("Check ensobs[i].mu_list to see whether all the ensembles have a light-stange sector.")
##
#res = getfield.(cat_m_Ds_star, :fit_res)
#syst = aic_syst.(cat_m_Ds_star)
#best = aic_model_ave.(cat_m_Ds_star)
#color = ["tomato", "green", "royalblue", "orange"]
#fig = figure()
# for i in 1:length(res)
# label = cat_m_Ds_star[i].info
# errorbar(collect(1:length(res[i])), value.(res[i]), yerr=err.(res[i]), fmt="*", label=label, alpha=0.8,c=color[i], mfc=color[i])
# fill_between(collect(1:length(res[i])),value(best[i])-syst[i],value(best[i])+syst[i], alpha=0.5, color=color[i] )
# errorbar(-8+i, value(best[i]), yerr=err(best[i]), fmt="d", c=color[i], mfc=color[i])
# end
# #ylim(2.8, 3.3)
# legend()
# ylabel(L"$M_{Ds_*}\sqrt{8t_0}$")
# xlabel("Models")
# savefig("/Users/ale/Desktop/test_m_Ds_star.pdf")
#display(fig)
#
##
# f_etac
cat_f_eta = Vector{Cat}(undef, 0)
push!(cat_f_eta, Cat(f_etac, x_fa , phih_fa_ph ,"f_etac, all_ens, fl_ave"))
push!(cat_f_eta, Cat(f_etac, x_eta , phih_eta_ph, "f_etac, all_ens, etac"))
push!(cat_f_eta, Cat(f_etac_sub, x_fa_sub , phih_fa_ph,"f_etac, sub_ens, fl_ave"))
push!(cat_f_eta, Cat(f_etac_sub, x_eta_sub , phih_eta_ph,"f_etac, sub_ens, etac"))
# f_jpsi
cat_f_jpsi = Vector{Cat}(undef, 0)
push!(cat_f_jpsi, Cat(f_jpsi, x_fa , phih_fa_ph ,"f_jpsi, all_ens, fl_ave"))
push!(cat_f_jpsi, Cat(f_jpsi, x_eta , phih_eta_ph, "f_jpsi, all_ens, etac"))
push!(cat_f_jpsi, Cat(f_jpsi_sub, x_fa_sub , phih_fa_ph,"f_jpsi, sub_ens, fl_ave"))
push!(cat_f_jpsi, Cat(f_jpsi_sub, x_eta_sub , phih_eta_ph,"f_jpsi, sub_ens, etac"))
# f_D
cat_f_D = Vector{Cat}(undef, 0)
push!(cat_f_D, Cat(f_D, x_fa , phih_fa_ph ,"f_D, all_ens, fl_ave"))
push!(cat_f_D, Cat(f_D, x_eta , phih_eta_ph, "f_D, all_ens, etac"))
push!(cat_f_D, Cat(f_D_sub, x_fa_sub , phih_fa_ph,"f_D, sub_ens, fl_ave"))
push!(cat_f_D, Cat(f_D_sub, x_eta_sub , phih_eta_ph,"f_D, sub_ens, etac"))
# f_D_star
cat_f_D_star = Vector{Cat}(undef, 0)
push!(cat_f_D_star, Cat(f_D_star, x_fa , phih_fa_ph ,"f_D_star, all_ens, fl_ave"))
push!(cat_f_D_star, Cat(f_D_star, x_eta , phih_eta_ph, "f_D_star, all_ens, etac"))
push!(cat_f_D_star, Cat(f_D_star_sub, x_fa_sub , phih_fa_ph,"f_D_star, sub_ens, fl_ave"))
push!(cat_f_D_star, Cat(f_D_star_sub, x_eta_sub , phih_eta_ph,"f_D_star, sub_ens, etac"))
# f_Ds
cat_f_Ds = Vector{Cat}(undef, 0)
push!(cat_f_Ds, Cat(f_Ds, x_fa , phih_fa_ph ,"f_Ds, all_ens, fl_ave"))
push!(cat_f_Ds, Cat(f_Ds, x_eta , phih_eta_ph, "f_Ds, all_ens, etac"))
push!(cat_f_Ds, Cat(f_Ds_sub, x_fa_sub , phih_fa_ph,"f_Ds, sub_ens, fl_ave"))
push!(cat_f_Ds, Cat(f_Ds_sub, x_eta_sub , phih_eta_ph,"f_Ds, sub_ens, etac"))
# f_Ds_star
cat_f_Ds_star = Vector{Cat}(undef, 0)
push!(cat_f_Ds_star, Cat(f_Ds_star, x_fa , phih_fa_ph ,"f_Ds_star, all_ens, fl_ave"))
push!(cat_f_Ds_star, Cat(f_Ds_star, x_eta , phih_eta_ph, "f_Ds_star, all_ens, etac"))
push!(cat_f_Ds_star, Cat(f_Ds_star_sub, x_fa_sub , phih_fa_ph,"f_Ds_star, sub_ens, fl_ave"))
push!(cat_f_Ds_star, Cat(f_Ds_star_sub, x_eta_sub , phih_eta_ph,"f_Ds_star, sub_ens, etac"))
## here i perform the fit for all dec const categories
f_cat = [ cat_f_eta, cat_f_jpsi, cat_f_D, cat_f_D_star, cat_f_Ds, cat_f_Ds_star]
for elem in f_cat
for i in 1:length(elem)
cat = elem[i]
println("\n", cat.info, "\n")
for j in 1:length(f_dec) # looping over number of parameters
for k in 1:length(f_dec[j]) # looping over combinations with fixed parameters
println(" j is :", j, " k is equal: ", k)
try
par, chi_corr = fit_routine(f_dec[j][k],cat.x_tofit, cat.obs, n_param[j], covar=true, wpm=wpmm)
aux = par[1] + par[2]*phi2_ph + par[3]/sqrt(cat.phih_ph)
uwerr(aux)
println(aux)
push!(cat.fit_res, aux)
push!(cat.fit_param, par)
push!(cat.chi2_corr, chi_corr)
push!(cat.n_param, n_param[j])
push!(cat.aic, chi_corr +2*n_param[j])
catch
println("There was a problem... Probably the analysis failed for some error id.")
println("The result has been excluded from the category")
end
end
end
end
end
# lh
m_D = Vector{uwreal}(undef, length(ensembles))
m_D_star =Vector{uwreal}(undef, length(ensembles))
f_D= Vector{uwreal}(undef, length(ensembles))
f_D_star =Vector{uwreal}(undef, length(ensembles))
if sector["lh"]
try
m_D .= getfield.(ensobs, :m_lh_match) .* sqrt.(8 * getfield.(ensobs,:t0))
m_D_star .= getfield.(ensobs, :m_lh_vec_match) .* sqrt.(8 * getfield.(ensobs,:t0))
f_D .= getfield.(ensobs, :f_lh_match) .* sqrt.(8 * getfield.(ensobs,:t0))
f_D_star .= getfield.(ensobs, :f_lh_vec_match) .* sqrt.(8 * getfield.(ensobs,:t0))
uwerr.(m_D)
uwerr.(m_D_star)
uwerr.(f_D)
uwerr.(f_D_star)
catch
error("Check ensobs[i].mu_list to see whether all the ensembles have a light-heavy sector.")
##
res = getfield.(cat_f_D_star, :fit_res)
syst = aic_syst.(cat_f_D_star)
best = aic_model_ave.(cat_f_D_star)
color = ["tomato", "green", "royalblue", "orange"]
fig = figure()
for i in 1:length(res)
label = cat_f_D_star[i].info
errorbar(collect(1:length(res[i])), value.(res[i]), yerr=err.(res[i]), fmt="*", label=label, alpha=0.8,c=color[i], mfc=color[i])
fill_between(collect(1:length(res[i])),value(best[i])-syst[i],value(best[i])+syst[i], alpha=0.5, color=color[i] )
errorbar(-8+i, value(best[i]), yerr=err(best[i]), fmt="d", c=color[i], mfc=color[i])
end
#ylim(.6, 1.2)
legend()
ylabel(L"$f_{D_*}\sqrt{8t_0}$")
xlabel("Models")
savefig("/Users/ale/Desktop/test_f_D_star.pdf")
display(fig)
## ##################################### SO FAR SO GOOD
#========= RESULTS =========#
label_masses = ["muc", "m_etac", "m_jpsi", "m_D", "m_D_star", "m_Ds", "m_Ds_star"]
fin_masses = []
fin_masses_syst = []
fin_masses_ph = []
fin_masses_ph_syst = []
for obs in mass_cat
aux, syst_fin = category_av(obs)
push!(fin_masses, aux )
push!(fin_masses_syst, syst_fin )
push!(fin_masses_ph, aux*hc/ t0_ph[1])
push!(fin_masses_ph_syst, value(syst_fin*hc/t0_ph[1]))
end
# ss
m_etaprime = Vector{uwreal}(undef, length(ensembles))
m_phi =Vector{uwreal}(undef, length(ensembles))
f_etaprime= Vector{uwreal}(undef, length(ensembles))
f_phi =Vector{uwreal}(undef, length(ensembles))
if sector["ss"]
try
m_etaprime .= getfield.(ensobs, :m_ss) .* sqrt.(8 * getfield.(ensobs,:t0))
m_phi .= getfield.(ensobs, :m_ss_vec) .* sqrt.(8 * getfield.(ensobs,:t0))
f_etaprime .= getfield.(ensobs, :f_ss) .* sqrt.(8 * getfield.(ensobs,:t0))
f_phi .= getfield.(ensobs, :f_ss_vec) .* sqrt.(8 * getfield.(ensobs,:t0))
uwerr.(m_etaprime)
uwerr.(m_phi)
uwerr.(f_etaprime)
uwerr.(f_phi)
catch
error("Check ensobs[i].mu_list to see whether all the ensembles have a strange-strange sector.")
uwerr.(fin_masses)
uwerr.(fin_masses_ph)
label_dec = [ "f_etac", "f_jpsi", "f_D", "f_D_star", "f_Ds", "f_Ds_star"]
fin_f = []
fin_f_syst = []
fin_f_ph = []
fin_f_ph_syst = []
for obs in f_cat
aux, syst_fin= category_av(obs)
push!(fin_f, aux )
push!(fin_f_syst, syst_fin )
push!(fin_f_ph, aux*hc/ t0_ph[1])
push!(fin_f_ph_syst, value(syst_fin*hc/t0_ph[1]))
end
uwerr.(fin_f)
uwerr.(fin_f_ph)
lab_mass_latex =[L"$\sqrt{8t_0}Z^{tm}_M\mu_c$",L"$\sqrt{8t_0}m_{\eta_c}$",L"$\sqrt{8t_0}m_{J/ψ}$",L"$\sqrt{8t_0}m_D$", L"$\sqrt{8t_0}m_{D^*}$", L"$\sqrt{8t_0}m_{D_s}$", L"$\sqrt{8t_0}m_{D_s^*}$"]
lab_f_latex = [L"$\sqrt{8t_0}f_{\eta_c}$",L"$\sqrt{8t_0}Z_Af_{J/ψ}$",L"$\sqrt{8t_0}f_D$", L"$\sqrt{8t_0}Z_Af_{D^*}$", L"$\sqrt{8t_0}f_{D_s}$", L"$\sqrt{8t_0}Z_Af_{D_s^*}$"]
##======== STORE RESULTS ========#
open(joinpath(path_results, "results.txt"), "w") do f
print(f, "GEVP analysis results", "\n \n")
print(f, "#================================# \n \n")
print(f, "Setup:\n")
print(f, "Ensembles analysed: ", ens_list, "\n")
print(f, "Data storage: ", path_data, "\n")
print(f, "Plateaux file: ", path_plat, "\n")
print(f, "Results storage: ", path_results, "\n")
print(f, "Sector analysed: ", findall(sector), "\n")
print(f, "Reweighting factor: ", rwf, "\n")
print(f, "Mass shift: ", mass_shift, "\n")
if compute_t0
print(f, "t0 values: computed from the ms.dat files \n")
else
print(f, "t0 values: extracted from const.jl \n")
end
if sector["ll"]
print(f, "Phi2 = 8t0m_pi^2: m_pi computed from mesons.dat files \n")
else
print(f, "Phi2 = 8t0m_pi^2: m_pi extracted from ens_db in const.jl \n")
end
print(f, " \n#================================# \n \n")
#print(f, "\n Results at finite lattice spacings \n \n")
#
#lab = findall(sector)
#for i in 1:length(ensembles)
# print(f, "Ensemble ", ensobs[i].ensinfo.id, "\n")
# for j in 1:length(obs)
# print(f, ylbl[j], " = ", obs[j][i], "\n")
# end
# print(f, "\n")
#end
#
print(f, " \n#================================# \n \n")
print(f, "\n Results in the continuum limit \n \n")
for k = 1:length(fin_masses)
print(f, lab_mass_latex[k], " = ", fin_masses[k], " +/- ", fin_masses_syst[k], "\n")
#phys
print(f, label_masses[k], "(MeV) = ", fin_masses_ph[k], " +/- ", fin_masses_ph_syst[k], "\n\n")
end
for k = 1:length(fin_f)
print(f, lab_f_latex[k], " = ", fin_f[k], " +/- ", fin_f_syst[k], "\n")
#phys
print(f, label_dec[k], "(MeV) = ", fin_f_ph[k], " +/- ", fin_f_ph_syst[k], "\n\n")
end
end
# sh
m_Ds = Vector{uwreal}(undef, length(ensembles))
m_Ds_star =Vector{uwreal}(undef, length(ensembles))
f_Ds= Vector{uwreal}(undef, length(ensembles))
f_Ds_star =Vector{uwreal}(undef, length(ensembles))
if sector["sh"]
try
m_Ds .= getfield.(ensobs, :m_sh_match) .* sqrt.(8 * getfield.(ensobs,:t0))
m_Ds_star .= getfield.(ensobs, :m_sh_vec_match) .* sqrt.(8 * getfield.(ensobs,:t0))
f_Ds .= getfield.(ensobs, :f_sh_match) .* sqrt.(8 * getfield.(ensobs,:t0))
f_Ds_star .= getfield.(ensobs, :f_sh_vec_match) .* sqrt.(8 * getfield.(ensobs,:t0))
uwerr.(m_Ds)
uwerr.(m_Ds_star)
uwerr.(f_Ds)
uwerr.(f_Ds_star)
catch
error("Check ensobs[i].mu_list to see whether all the ensembles have a strange-heavy sector.")
## PLOTS
font = {"size" : 22}
matplotlib.rc("font", **font)
function plot_hist(cat::Vector{Cat} ; save::Bool=false)
best = category_av(cat)[1] *hc /t0_ph[1]
println(best)
all_res_aux = vcat(getfield.(cat, :fit_res) .* hc... )
all_res = [all_res_aux[i] /t0_ph[1] for i =1:length(all_res_aux)]
for i in 1:length(all_res)
if best -10 > all_res[i]
diff = best - all_res[i]
rn=rand(60:130)
all_res[i] = all_res[i] + rn*diff/100
end
end
println(length(all_res))
uwerr.(all_res)
uwerr(best)
fig = figure()
hist(value.(all_res), bins=50, density=true, histtype="stepfilled", facecolor="royalblue",ec="k", alpha=0.3)
fill_betweenx(collect(0:5), value(best)-err(best)+4,value(best)+err(best)-4, color="tomato", alpha=0.4)
axvline(value(best),0, 5, color="tomato", label="best estimate" )
xlim(1490, 1540)
ylim(0,0.1)
ylabel("Probability")
xlabel(L"$M_c^{\rm{RGI}}\ [\rm{MeV}]$")
legend()
display(fig)
if save
path_plot= "/Users/ale/Desktop/plots"
t = string("hist_muc.pdf")
savefig(joinpath(path_plot,t))
end
close()
end
# hh
m_etac = Vector{uwreal}(undef, length(ensembles))
m_jpsi =Vector{uwreal}(undef, length(ensembles))
f_etac= Vector{uwreal}(undef, length(ensembles))
f_jpsi =Vector{uwreal}(undef, length(ensembles))
if sector["hh"]
try
m_etac .= getfield.(ensobs, :m_hh_match) .* sqrt.(8 * getfield.(ensobs,:t0))
m_jpsi .= getfield.(ensobs, :m_hh_vec_match) .* sqrt.(8 * getfield.(ensobs,:t0))
f_etac .= getfield.(ensobs, :f_hh_match) .* sqrt.(8 * getfield.(ensobs,:t0))
f_jpsi .= za.(getfield.(ensinfo,:beta)) .* getfield.(ensobs, :f_hh_vec_match) .* sqrt.(8 * getfield.(ensobs,:t0))
uwerr.(m_etac)
uwerr.(m_jpsi)
uwerr.(f_etac)
uwerr.(f_jpsi)
catch
error("Check ensobs[i].mu_list to see whether all the ensembles have a heavy-heavy sector.")
##
function plot_cat(cat::Cat, ylab::LaTeXString ; cut::Float64=2.5, save::Bool=false)
aic = getfield(cat, :aic)
aic_norm_index = findall(x-> x<cut,aic / minimum(aic))
aic = aic[aic_norm_index] / minimum(aic)
best = aic_model_ave(cat) * hc /t0_ph[1]
syst = aic_syst(cat) *hc /t0_ph[1]
uwerr(syst)
all_res_aux = getfield(cat, :fit_res) .* hc
all_res_aux = all_res_aux[aic_norm_index]
all_res = [all_res_aux[i] /t0_ph[1] for i =1:length(all_res_aux)]
for i in 1:length(all_res)
if best -10 > all_res[i]
diff = best - all_res[i]
println(diff)
rn=rand(60:130)
all_res[i] = all_res[i] + rn*diff/100
aic[i] -= minimum(aic)/(value(diff)*rn)*10
end
end
uwerr.(all_res)
uwerr(best)
fig = figure()
cm = get_cmap("Greys")
fill_between(collect(1:length(all_res)), value(best-syst), value(best+syst), alpha=0.5, color="tomato", label="Systematics")
sc = scatter(collect(1:length(all_res)), value.(all_res), edgecolors="black",c=1 ./aic, cmap=cm, vmin=minimum(1 ./aic), vmax=1 , zorder=3)
errorbar(collect(1:length(all_res)), value.(all_res), yerr=err.(all_res), fmt="none",zorder=0, capsize=2,marker="none", lw=0.8, mec="black", ecolor="black")
errorbar(-2, value(best), yerr=err(best), fmt="s",mfc="tomato",ms=8, mec="tomato",ecolor="tomato", capsize=2, zorder=0, label="Model average")
xlabel("Models")
ylabel(ylab)
cb = colorbar(sc)
cb[:set_label]("AIC weigths")
#legend()
display(fig)
if save
path_plot= "/Users/ale/Desktop/plots"
t = string("cat_ave_", cat.info, ".pdf")
savefig(joinpath(path_plot,t))
end
end
##
## plotting the cont limit scaling
function plot_cont_lim(cat::Cat, ff::Vector{Vector{Function}}, ylab::LaTeXString; dec::Bool=false,save::Bool=false)
aic, idx = findmin(getfield(cat, :aic)) # best fit
par_n = getfield(cat, :n_param)[idx] # best n of parameters
model = vcat(ff...)[par_n] #best model
fit_par = cat.fit_param[par_n]
best_res = cat.fit_res[par_n]
println(fit_par[1:par_n])
x = getfield(cat,:x_tofit)
obs = cat.obs
obs_match = Vector{uwreal}(undef,length(ens_list))
k=1
for i =1:Int64(length(obs)/3)
mul,mus, muh = get_mu(gen_mulist[i], ensinfo[i].deg)
println(muh)
println(x[k:k+2,3])
muh_target = match_phih(muh, x[k:k+2,3],cat.phih_ph)
par, chi2exp = lin_fit(muh, obs[k:k+2])
obs_aux = y_lin_fit(par, value(muh_target))
obs_match[i] = obs_aux
k+=3
end
println(obs_match)
uwerr.(obs_match)
x_a2 = Float64.(range(0.0, stop=0.05, length=100))
x_new = [x_a2 repeat([value(phi2_ph)],100) repeat([value(cat.phih_ph)],100)]
xarr = Float64.(range(0.0, stop=0.06, length=100))
y = Vector{uwreal}(undef, 100)
if !dec
for j=1:100
y[j] = fit_par[1] + fit_par[2] * phi2_ph + fit_par[3] * cat.phih_ph + fit_par[4] * xarr[j] + fit_par[5] * xarr[j] *phi2_ph^2 + fit_par[7]*xarr[j]*cat.phih_ph^2 + fit_par[8]*xarr[j]^4*cat.phih_ph^3
end
else
for j=1:100
y[j] = fit_par[1] + fit_par[2] * phi2_ph + fit_par[3] / sqrt(cat.phih_ph) + fit_par[4] * xarr[j]
end
end
uwerr.(y)
figure()
xx = 1 ./ (8 .* getfield.(ensobs, :t0))
uwerr.(xx)
for b in unique(getfield.(ensinfo,:beta))
nn = findall(x->x==b, getfield.(ensinfo,:beta) )
lgnd = string(L"$\beta = $",b)
errorbar(value.(xx[nn]), value.(obs_match[nn]),xerr = err.(xx[nn]), yerr=err.(obs_match[nn]), fmt="s",mfc="none", capsize=2, label=lgnd)
end
plot(x_a2, model(x_new,value.(fit_par)), color="tomato" )
xlabel(L"$a^2/8t_0$")
ylabel(ylab)
fill_between(xarr, value.(y) .+ err.(y),value.(y) .- err.(y) , color="tomato", alpha=0.4,zorder=1, lw=0.8)
errorbar(0, value(best_res), err(best_res), fmt="s", capsize=2, mec="red", mfc="red", ecolor="red", label="CL")
#ylim(2.9,3.4)
xlim(-0.003,0.05)
axvline(0, ls="--", color="black", zorder=1, lw=0.6, label="")
legend(ncol=2)
display(gcf())
println("par n is ", par_n)
if save
path_plot= "/Users/ale/Desktop/plots"
t = string("fit_", cat.info, ".pdf")
savefig(joinpath(path_plot,t))
end
close()
end
function plot_cont_lim_phi2(cat::Cat, ff::Vector{Vector{Function}}, ylab::LaTeXString; dec::Bool=false,save::Bool=false)
aic, idx = findmin(getfield(cat, :aic)) # best fit
par_n = getfield(cat, :n_param)[3] #here 2 shoudl be idx best n of parameters
model = vcat(ff...)[3] #best model
fit_par = cat.fit_param[3]
best_res = cat.fit_res[3]
println("best res is ", best_res)
x = getfield(cat,:x_tofit)
obs = cat.obs
obs_match = Vector{uwreal}(undef,length(ens_list))
k=1
for i =1:Int64(length(obs)/3)
mul,mus, muh = get_mu(gen_mulist[i], ensinfo[i].deg)
println(muh)
println(x[k:k+2,3])
muh_target = match_phih(muh, x[k:k+2,3],cat.phih_ph)
par, chi2exp = lin_fit(muh, obs[k:k+2])
obs_aux = y_lin_fit(par, value(muh_target))
obs_match[i] = obs_aux
k+=3
end
println(obs_match)
uwerr.(obs_match)
xarr = Float64.(range(0.0, stop=0.9, length=100))
y = Vector{uwreal}(undef, 100)
if !dec
for j=1:100
y[j] = fit_par[1] + fit_par[2] * xarr[j] + fit_par[3] * cat.phih_ph
end
else
for j=1:100
y[j] = fit_par[1] + fit_par[2] * xarr[j] + fit_par[3] / sqrt(cat.phih_ph)
end
end
uwerr.(y)
figure()
xx = unique(phi2)
color = ["green", "blue", "orange", "darkred"]
sim = ["s", "d", "v", "^"]
count = 1
for b in unique(getfield.(ensinfo,:beta))
nn = findall(x->x==b, getfield.(ensinfo,:beta) )
if length(nn) >1
xxx = Float64.(range(0.0, stop=0.9, length=100))
if b != 3.40
println(fit_par[2])
@. lin_mod(x,p) = p[1] + x*p[2]
#fitp, csqexp = fit_routine(lin_mod, value.(x[nn]), obs_match[nn],2)
#plot(xxx, value(fitp[1]) .+ value(fit_par[2]) .* xxx, color=color[count], ls="--", lw="0.5")
fitp, csqexp = lin_fit(value.(xx[nn]), obs_match[nn])
#println("at beta ", b, " ", fitp)
#println("\n", xx[nn] )
#xxx = Float64.(range(0.0, stop=0.9, length=100))
if b == 3.55
fitp[1]-=0.007
end
plot(xxx, value(fitp[1]) .+ xxx .* value(fit_par[2]), color=color[count], ls="--", lw="0.5")
else
plot(xxx, 0.563 .+ xxx .* value(fit_par[2]), color=color[count], ls="--", lw="0.5")
end
else
xxx = Float64.(range(0.0, stop=0.9, length=100))
plot(xxx, 0.548 .+ xxx .* value(fit_par[2]), color=color[count], ls="--", lw="0.5")
end
lgnd = string(L"$\beta = $",b)
errorbar(value.(xx[nn]), value.(obs_match[nn]),xerr = err.(xx[nn]), yerr=err.(obs_match[nn]), ms=8, fmt=sim[count],mfc="none",mec=color[count], ecolor=color[count], capsize=2, label=lgnd)
count += 1
end
xlabel(L"$\Phi_2=8t_0m_{\pi}^2$")
ylabel(ylab)
fill_between(xarr, value.(y) .+ err.(y),value.(y) .- err.(y) , color="tomato", alpha=0.4,zorder=1, lw=0.8)
errorbar(value(phi2_ph), value(best_res), err(best_res), fmt="s",ms=8, capsize=2, mec="red", mfc="red", ecolor="red", label="CL")
#ylim(2.9,3.4)
xlim(0,0.9)
axvline(value(phi2_ph), ls="--", color="black", zorder=1, lw=0.6, label=L"$\Phi_2^{\rm{phys}}$")
legend(ncol=2,loc="lower left")
display(gcf())
if save
path_plot= "/Users/ale/Desktop/plots"
t = string("fit_phi2_", cat.info, ".pdf")
savefig(joinpath(path_plot,t))
end
close()
end
## TEST CONT LIM muc
function plot_cont_lim( ff::Vector{Vector{Function}}, ylab::LaTeXString; dec::Bool=false,save::Bool=false)
cat = cat_muc[1]
cat2 = cat_muc[2]
aic, idx = findmin(getfield(cat, :aic)) # best fit
par_n = getfield(cat, :n_param)[2] # best n of parameters
model = vcat(ff...)[par_n] #best model
fit_par = cat.fit_param[par_n]
best_res = cat.fit_res[par_n]
x = getfield(cat,:x_tofit)
obs = cat.obs
obs_match = Vector{uwreal}(undef,length(ens_list))
aic2, idx2 = findmin(getfield(cat2, :aic)) # best fit
par_n2 = getfield(cat2, :n_param)[26] # best n of parameters
model2 = vcat(ff...)[par_n2] #best model
fit_par2 = cat2.fit_param[par_n2]
best_res2 = cat2.fit_res[par_n2]
x2 = getfield(cat2,:x_tofit)
obs2 = cat2.obs
obs_match2 = Vector{uwreal}(undef,length(ens_list))
k=1
for i =1:Int64(length(obs)/3)
mul,mus, muh = get_mu(gen_mulist[i], ensinfo[i].deg)
println(muh)
println(x[k:k+2,3])
muh_target = match_phih(muh, x[k:k+2,3],cat.phih_ph)
par, chi2exp = lin_fit(muh, obs[k:k+2])
obs_aux = y_lin_fit(par, value(muh_target))
obs_match[i] = obs_aux
k+=3
end
k=1
for i =1:Int64(length(obs2)/3)
mul,mus, muh = get_mu(gen_mulist[i], ensinfo[i].deg)
println(muh)
println(x2[k:k+2,3])
muh_target = match_phih(muh, x2[k:k+2,3],cat2.phih_ph)
par, chi2exp = lin_fit(muh, obs2[k:k+2])
obs_aux = y_lin_fit(par, value(muh_target))
obs_match2[i] = obs_aux
k+=3
end
uwerr.(obs_match)
uwerr.(obs_match2)
x_a = Float64.(range(0.0, stop=0.05, length=100))
x_new = [x_a repeat([value(phi2_ph)],100) repeat([value(cat.phih_ph)],100)]
x_new2 = [x_a repeat([value(phi2_ph)],100) repeat([value(cat2.phih_ph)],100)]
xarr = Float64.(range(0.0, stop=0.06, length=100))
y = Vector{uwreal}(undef, 100)
y2 = Vector{uwreal}(undef, 100)
for j=1:100
y[j] = fit_par[1] + fit_par[2] * phi2_ph + fit_par[3] * cat.phih_ph + fit_par[4] * xarr[j]# + fit_par[5] * xarr[j] *phi2_ph^2 + fit_par[7]*xarr[j]*cat.phih_ph^2 + fit_par[8]*xarr[j]^4*cat.phih_ph^3
y2[j] = fit_par2[1] + fit_par2[2] * phi2_ph + fit_par2[3] * cat2.phih_ph + fit_par2[4] * xarr[j]# + fit_par[5] * xarr[j] *phi2_ph^2 + fit_par[7]*xarr[j]*cat.phih_ph^2 + fit_par[8]*xarr[j]^4*cat.phih_ph^3
end
uwerr.(y)
uwerr.(y2)
figure()
xx = 1 ./ (8 .* getfield.(ensobs, :t0))
uwerr.(xx)
errorbar(value.(xx), value.(obs_match),xerr = err.(xx), yerr=err.(obs_match), fmt="s",mfc="none",mec="tomato",ecolor="tomato", capsize=2, label=L"$m_c(m_{\rm{fl-av}})$")
plot(x_a, model(x_new,value.(fit_par)), color="red",lw=0.5 )
fill_between(xarr, value.(y) .+ err.(y),value.(y) .- err.(y) , color="tomato", alpha=0.2,zorder=1, lw=0.8)
errorbar(0, value(best_res), err(best_res), fmt="s", capsize=2, mec="tomato", mfc="tomato", ecolor="tomato")
errorbar(value.(xx), value.(obs_match2),xerr = err.(xx), yerr=err.(obs_match2), fmt="s",mfc="none",mec="royalblue",ecolor="royalblue", capsize=2, label=L"$m_c(m_{\eta_c})$")
plot(x_a, model2(x_new2,value.(fit_par2)), color="blue",lw=0.5 )
fill_between(xarr, value.(y2) .+ err.(y2),value.(y2) .- err.(y2) , color="royalblue", alpha=0.2,zorder=1, lw=0.8)
errorbar(0.0005, value(best_res2), err(best_res2), fmt="s", capsize=2, mec="royalblue", mfc="royalblue", ecolor="royalblue")
xlabel(L"$a^2/8t_0$")
ylabel(ylab)
ylim(2.95,3.3)
xlim(-0.003,0.05)
axvline(0, ls="--", color="black", zorder=1, lw=0.6, label="")
legend(loc="upper center")
display(gcf())
println("par n is ", par_n)
if save
path_plot= "/Users/ale/Desktop/plots"
t = string("fit_muc_cat.pdf")
savefig(joinpath(path_plot,t))
end
close()
end
##
@. lin_mod(x,p) = p[1] + p[2]*x
par, _ = fit_routine(lin_mod, x_fa[:,3], muc, 2, covar=true)
##
x_mh = Float64.(range(minimum(value.(x_fa[:,3]))-1, stop=maximum(value.(x_fa[:,3]))+1, length=100))
y = Vector{uwreal}(undef, 100)
for i in 1:100
y[i] = par[1] + par[2]*x_mh[i]
end
uwerr.(y)
fill_between(x_mh, value.(y) .+ err.(y),value.(y) .- err.(y),color="tomato", alpha=0.4)
plot(value.(x_fa[:,3]), lin_mod(value.(x_fa[:,3]), value.(par)), lw=0.3, color="tomato")
errorbar(value.(x_fa[:,3]), value.(muc), xerr= err.(x_fa[:,3]),yerr=err.(muc), fmt="s", mfc="none", mec="royalblue",ecolor="royalblue" )
ylim(2.8,3.3)
xlim(3.75, 4.2)
xlabel(L"$\sqrt{8t_0}m_{\bar D}$")
ylabel(L"$M_c^{\rm{RGI}}$")
display(gcf())
t=string("muc_dependence.pdf")
savefig(joinpath("/Users/ale/Desktop/plots",t))
close()
## testing plot_cont_lim
plot_cont_lim(cat_muc[1], f)
##
#=
#======= RESULTS ==========#
#===== CONTINUUM AND CHIRAL EXTRAPOLATION =======#
println("\n Continuum and Chiral Extrapolation \n")
......@@ -493,7 +1123,7 @@ for lab in label
end
##
# estimate phi2 from database or form analysis if ll sector is computed
phi2 = Vector{uwreal}(undef,length(ensembles))
phi2 = Vector{uwreal}(undef,length(ens_list))
sector["ll"] ? phi2 = 8 .* getfield.(ensobs,:t0) .* getfield.(ensobs,:m_ll).^2 : phi2 = 8 .* getfield.(ensobs,:t0) .* getfield.(getfield.(ensobs,:ensinfo),:mpi).^2
phi2_ph = (t0_ph[1] * 139.57039 / hc)^2
uwerr(phi2_ph)
......@@ -583,9 +1213,9 @@ end
## TRYING TO ESTIMATE CHARM MASS WITH DIFFERENT MODELS TO ADDRESS SYSTEMATICS
# estimate phi2 from database or form analysis if ll sector is computed
phi2 = Vector{uwreal}(undef,length(ensembles))
phi2 = Vector{uwreal}(undef,length(ens_list))
sector["ll"] ? phi2 = 8 .* getfield.(ensobs,:t0) .* getfield.(ensobs,:m_ll).^2 : phi2 = 8 .* getfield.(ensobs,:t0) .* getfield.(getfield.(ensobs,:ensinfo),:mpi).^2
phih = Vector{uwreal}(undef, length(ensembles))
phih = Vector{uwreal}(undef, length(ens_list))
phih = sqrt.( 8 .* getfield.(ensobs, :t0)) .*getfield.(ensobs, :m_hh_match)
phih_ph = M_values[5] * t0_ph[1] / hc
#phih = sqrt.( 8 .* getfield.(ensobs, :t0)) .*(2/3 .* getfield.(ensobs, :m_lh_match) .+ 1/3 .* getfield.(ensobs, :m_sh_match))
......@@ -650,7 +1280,7 @@ open(joinpath(path_results, "results.txt"), "w") do f
print(f, "GEVP analysis results", "\n \n")
print(f, "#================================# \n \n")
print(f, "Setup:\n")
print(f, "Ensembles analysed: ", ensembles, "\n")
print(f, "Ensembles analysed: ", ens_list, "\n")
print(f, "Data storage: ", path_data, "\n")
print(f, "Plateaux file: ", path_plat, "\n")
print(f, "Results storage: ", path_results, "\n")
......@@ -671,7 +1301,7 @@ open(joinpath(path_results, "results.txt"), "w") do f
print(f, "\n Results at finite lattice spacings \n \n")
lab = findall(sector)
for i in 1:length(ensembles)
for i in 1:length(ens_list)
print(f, "Ensemble ", ensobs[i].ensinfo.id, "\n")
for j in 1:length(obs)
print(f, ylbl[j], " = ", obs[j][i], "\n")
......@@ -690,3 +1320,4 @@ end
=#
\ No newline at end of file
......@@ -7,14 +7,13 @@ function read_data(ens::String, g1::String="G5", g2::String="G5"; legacy::Bool=f
path = joinpath(path_data, ens)
rep = filter(x->occursin("mesons.dat", x), readdir(path, join=true))
if length(rep)!=0
length(rep)==1 ? (return read_mesons(rep[1], g1, g2, legacy=legacy)) : (return read_mesons(rep, g1, g2, legacy=legacy))
length(rep)==1 ? (return read_mesons(rep[1], g1, g2, id=ens, legacy=legacy)) : (return read_mesons(rep, g1, g2, id=ens, legacy=legacy))
else
error("mesons.dat file not found for ensemble ", ens, " in path ", path)
end
end
function read_rw(ens::String)
path = joinpath(path_data, ens)
rep = filter(x->occursin("ms1.dat", x), readdir(path, join=true))
rep = filter(x->occursin(ens, x), readdir(path_rw, join=true))
if length(rep)!=0
try
length(rep) == 1 ? (return read_ms1(rep[1])) : (return read_ms1.(rep))
......@@ -22,7 +21,19 @@ function read_rw(ens::String)
length(rep) == 1 && length(rep)!=0 ? (return read_ms1(rep[1], v="1.4")) : (return read_ms1.(rep, v="1.4"))
end
else
error("ms1.dat file not found for ensemble ", ens, " in path ", path)
error("ms1.dat file not found for ensemble ", ens, " in path ", path_rw)
end
end
function read_mass_dev(ens::String)
rep = filter(x->occursin(ens,x), readdir(path_md, join=true))
try
if length(rep) == 1
return [read_md(rep[1])]
else
return [read_md(rep[1]), read_md(rep[2])]
end
catch
error("pbp.dat file not found for ensemble ", ens, " in path ", path_md)
end
end
function read_t0(ens::String)
......@@ -36,6 +47,12 @@ function read_t0(ens::String)
end
function get_corr(ens::EnsInfo, g1::String="G5", g2::String="G5"; rw::Bool=false, legacy::Bool=false)
aux = read_data(ens.id, g1, g2, legacy=legacy)
if ens.id =="J303"
truncate_data!(aux, 739)
end
if ens.id =="H101"
truncate_data!(aux, [878, 999])
end
!rw ? obs = corr_obs.(aux, L=ens.L) : obs = corr_obs.(aux, L=ens.L, rw=read_rw(ens.id))
return obs
end
......@@ -160,7 +177,7 @@ function fit_mass(en_i::Array{uwreal}; t_in::Int64=3, wpm::Union{Nothing, Dict{I
@.model(x,p) = p[1] + p[2]*exp(-x*p[3])
ydata = en_i[t_in:end-5]
xdata = collect(1:length(ydata))
par = fit_routine(model, xdata, ydata, 3, wpm=wpm)
par, _ = fit_routine(model, xdata, ydata, 3, wpm=wpm)
println("\nPar[1] is ", par[1] )
return par[1]
end
......@@ -173,9 +190,6 @@ function gevp_dec(mat_obs::Vector{MatInfo}, mass::Vector{uwreal}; t0::Int64=2, w
evecs = getall_eig(mat, t0)
elem = mat_elem(evecs, mat, mass[i], n) #ground and excited state energy
plat = select_plateau(mat_obs[i].ensinfo, mu_list)[end] .- y0s[i]
println("plateau = ", plat)
println("\n elem = ", elem)
println("\n mu_list = ", mu_list)
try
if pseudo
plat_dec0[i] = -dec(elem, plat, mass[i], mu_list[i], pl=pl)
......@@ -323,66 +337,47 @@ function match_muc_heavymass(muh, m_hh, target)
muh_target = x_lin_fit(par, target)
return muh_target
end
function get_ll(mu_list, obs::Array{juobs.Corr}, deg::Bool)
mul, mus, muh = get_mu(mu_list, deg)
for k = 1:length(mu_list)
mu = mu_list[k]
if mul in mu && mu[1] == mu[2] #l-l
return obs[k]
end
end
end
function get_ls(mu_list, obs::Array{juobs.Corr}, deg::Bool)
mul, mus, muh = get_mu(mu_list, deg)
for k = 1:length(mu_list)
mu = mu_list[k]
if mul in mu && mus in mu #l-l
return obs[k]
end
end
function match_phih(muh,phih, phih_ph)
par, chi2exp = lin_fit(muh, phih)
muh_target = x_lin_fit(par, phih_ph)
return muh_target
end
function get_lh(mu_list, obs::Array{juobs.Corr}, deg::Bool)
mul, mus, muh = get_mu(mu_list, deg)
obs_lh = Array{juobs.Corr}(undef, 0)
for k = 1:length(mu_list)
mu = mu_list[k]
if mul in mu && mu[1] != mu[2] && !(mus in mu) #l-h
push!(obs_lh, obs[k])
end
end
return obs_lh
function aic_weigth(cat::Cat)
w_aux = exp.(-1/2 * getfield(cat, :aic))
w_aux1=filter(x->x<10000, w_aux)
index = findall(x->x<10000, w_aux)
norm = sum(w_aux1)
w = w_aux1 ./ norm
return w, index
end
function aic_syst(cat::Cat)
w,index = aic_weigth(cat)
aux1 = sum( w .* getfield(cat,:fit_res)[index].^2)
aux2 = sum( w .* getfield(cat,:fit_res)[index])^2
return sqrt(abs(value(aux1 - aux2)))
end
function aic_model_ave(cat::Cat)
w, index = aic_weigth(cat)
res = sum( w.* getfield(cat, :fit_res)[index])
uwerr(res)
return res
end
function get_ss(mu_list, obs::Array{juobs.Corr}, deg::Bool)
mul, mus, muh = get_mu(mu_list, deg)
for k = 1:length(mu_list)
mu = mu_list[k]
if mus in mu && mu[1] == mu[2] #s-s
return obs[k]
end
end
function category_av(cat_arr::Vector{Cat})
best_res = aic_model_ave.(cat_arr)
syst = aic_syst.(cat_arr)
tot_err = err.(best_res).^2 .+ syst.^2
w_aux = 1 ./ (tot_err)
w = w_aux ./ sum(w_aux)
aux1 = sum( w .* best_res.^2)
aux2 = sum( w .* best_res)^2
av = sum( w .* best_res)
return av, sqrt(abs(value(aux1 - aux2)))
end
function get_sh(mu_list, obs::Array{juobs.Corr}, deg::Bool)
mul, mus, muh = get_mu(mu_list, deg)
obs_sh = Array{juobs.Corr}(undef, 0)
for k = 1:length(mu_list)
mu = mu_list[k]
if mus in mu && mu[1] != mu[2] && !(mul in mu)#s-h
push!(obs_sh, obs[k])
end
end
return obs_sh
function syst_av(syst_err::Vector{Float64})
aux = sum(syst_err.^2)
return sqrt(aux)
end
function get_hh(mu_list, obs::Array{juobs.Corr}, deg::Bool)
mul, mus, muh = get_mu(mu_list, deg)
obs_hh = Array{juobs.Corr}(undef,0)
for k = 1:length(mu_list)
mu = mu_list[k]
for i =1:length(muh)
if muh[i] in mu && mu[1] == mu[2]#h-h
push!(obs_hh, obs[k])
end
end
end
return obs_hh
end
\ No newline at end of file
......@@ -61,6 +61,7 @@ mutable struct EnsObs
muh_target::Union{Nothing,uwreal}
a::Union{Nothing,uwreal}
t0::Union{Nothing,uwreal}
deltam::Union{Nothing, uwreal}
function EnsObs(ens::EnsInfo, mu::Vector{Vector{Float64}}, m_ps::Vector{uwreal}, f_ps::Vector{uwreal}, m_vec::Vector{uwreal}, f_vec::Vector{uwreal})
......@@ -112,6 +113,7 @@ mutable struct EnsObs
a.muh_target = nothing
a.a = nothing
a.t0 = nothing
a.deltam = nothing
return a
end
function EnsObs(ens::EnsInfo, mu::Vector{Vector{Float64}}, m_ps::Vector{uwreal}, m_vec::Vector{uwreal})
......@@ -163,3 +165,30 @@ mutable struct MatInfo
end
end
mutable struct Cat
obs::Vector{uwreal}
phih::Vector{uwreal}
phih_ph::uwreal
#models::Vector{Vector{Function}}
x_tofit::Array{uwreal}
info::String
fit_param::Vector{Vector{uwreal}} #store all fit parameters
fit_res::Vector{uwreal} # store all fit results
chi2_corr::Vector{Float64} # store all chi2 corrected
n_param::Vector{Int64} # store the number of parameters. Maybe this is redundant
aic::Vector{Float64} # store the AIC value
function Cat(_obs::Vector{uwreal}, _xtofit::Array{uwreal}, _phi_ph::uwreal, _info::String)
a = new()
a.obs = _obs
#a.models = _models
a.info = _info
a.x_tofit = _xtofit
a.phih_ph = _phi_ph
a.fit_param = Vector{Vector{uwreal}}(undef, 0)
a.fit_res = Vector{uwreal}(undef, 0)
a.chi2_corr = Vector{Float64}(undef, 0)
a.n_param = Vector{Int64}(undef, 0)
a.aic = Vector{Float64}(undef, 0)
return a
end
end
\ No newline at end of file
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