Commit 9fdef14c authored by Alessandro 's avatar Alessandro

major update to the twisted mass charm analysis code

parent 6c956856
...@@ -59,11 +59,11 @@ sh 83 110 ...@@ -59,11 +59,11 @@ sh 83 110
hh 90 104 hh 90 104
t0 20 110 t0 20 110
#D200 #D200
ll 85 105 ll 80 87
ls 82 100 ls 82 100
lh 80 88 lh 86 92
ss 85 100 ss 85 100
sh 82 88 sh 86 92
hh 87 93 hh 87 93
t0 20 110 t0 20 110
#J303 #J303
......
...@@ -61,11 +61,19 @@ t0 20 110 ...@@ -61,11 +61,19 @@ t0 20 110
#D200 #D200
ll 79 86 ll 79 86
ls 85 105 ls 85 105
lh 84 87 lh 78 88
ss 85 105 ss 85 105
sh 85 87 sh 80 85
hh 90 93 hh 80 90
t0 25 100 t0 25 100
#N302
ll 87 103
ls 85 105
lh 88 100
ss 85 105
sh 88 110
hh 88 110
t0 20 110
#J303 #J303
ll 120 148 ll 120 148
ls 123 140 ls 123 140
...@@ -74,4 +82,28 @@ ss 123 140 ...@@ -74,4 +82,28 @@ ss 123 140
sh 130 145 sh 130 145
hh 133 175 hh 133 175
t0 25 170 t0 25 170
#E300
ll 120 148
ls 123 140
lh 125 145
ss 123 140
sh 130 145
hh 133 175
t0 25 170
#J500
ll 120 148
ls 123 140
lh 125 145
ss 123 140
sh 130 145
hh 133 175
t0 25 170
#J501
ll 120 148
ls 123 140
lh 125 145
ss 123 140
sh 130 145
hh 133 175
t0 25 170
#end #end
...@@ -24,11 +24,11 @@ const path_plat_w = "/Users/alessandroconigli/Lattice/data/aux_obs_data/plat_wil ...@@ -24,11 +24,11 @@ const path_plat_w = "/Users/alessandroconigli/Lattice/data/aux_obs_data/plat_wil
const path_rw = "/Users/alessandroconigli/Lattice/data/aux_obs_data/rwf" const path_rw = "/Users/alessandroconigli/Lattice/data/aux_obs_data/rwf"
const path_md = "/Users/alessandroconigli/Lattice/data/aux_obs_data/md" const path_md = "/Users/alessandroconigli/Lattice/data/aux_obs_data/md"
const ens_list = ["D200"] # ["H101", "H102r002", "H400", "N202", "N200", "N203", "N300", "J303"] const ens_list = ["H101", "H102r002", "H105", "H400", "N202", "N203", "N200", "D200", "N300", "J303"] # ["H101", "H102r002", "H400", "N202", "N200", "N203", "N300", "J303"]
const path_bdio_md = "/Users/alessandroconigli/Lattice/data/bdio_charm/md" const path_bdio_md = "/Users/alessandroconigli/Lattice/data/bdio_charm/md"
const path_bdio_w = "/Users/alessandroconigli/Lattice/data/bdio_charm/wilson" const path_bdio_w = "/Users/alessandroconigli/Lattice/data/bdio_charm/wilson"
const phi4_target = uwreal([1.117, 0.012], "phi4_target") const phi4_target = uwreal([1.098, 0.010], "phi4_target")
const rwf = true const rwf = true
#========= INCLUDES ==========# #========= INCLUDES ==========#
...@@ -49,15 +49,16 @@ for i in 1:length(ens_list) ...@@ -49,15 +49,16 @@ for i in 1:length(ens_list)
end end
#t0 [2.86, 3.659, 5.164, 8.595] #t0 [2.86, 3.659, 5.164, 8.595]
wpmm = Dict{String, Vector{Float64}}() wpmm = Dict{String, Vector{Float64}}()
wpmm["H101"] = [-1.0, 4.0, -1.0, 14.0*2.86] wpmm["H101"] = [-1.0, 2.0, -1.0, 14.0*2.86]
wpmm["H102r002"] = [-1.0, 4.0, -1.0, 14.0*2.86] wpmm["H102r002"] = [-1.0, 2.0, -1.0, 14.0*2.86]
wpmm["H105"] = [-1.0, 4.0, -1.0, 14.0*2.86] wpmm["H105"] = [-1.0, 2.0, -1.0, 14.0*2.86]
wpmm["H400"] = [-1.0, 4.0, -1.0, 14.0*3.659] wpmm["H400"] = [-1.0, 2.0, -1.0, 14.0*3.659]
wpmm["N202"] = [-1.0, 4.0, -1.0, 14.0*5.164] wpmm["N202"] = [-1.0, 2.0, -1.0, 14.0*5.164]
wpmm["N200"] = [-1.0, 4.0, -1.0, 14.0*5.164] wpmm["N200"] = [-1.0, 2.0, -1.0, 14.0*5.164]
wpmm["N203"] = [-1.0, 4.0, -1.0, 14.0*5.164] wpmm["N203"] = [-1.0, 2.0, -1.0, 14.0*5.164]
wpmm["N300"] = [-1.0, 4.0, -1.0, 14.0*8.595] wpmm["D200"] = [-1.0, 2.0, -1.0, 14.0*5.164]
wpmm["J303"] = [-1.0, 4.0, -1.0, 14.0*8.595] wpmm["N300"] = [-1.0, 2.0, -1.0, 14.0*8.595]
wpmm["J303"] = [-1.0, 2.0, -1.0, 14.0*8.595]
## ##
#======== ANALYSIS ==========# #======== ANALYSIS ==========#
gen_mulist = Vector{Vector{Vector{Float64}}}(undef, length(ens_list)) gen_mulist = Vector{Vector{Vector{Float64}}}(undef, length(ens_list))
...@@ -68,6 +69,7 @@ obs_tm_shifted = Vector(undef, length(ensinfo)) ...@@ -68,6 +69,7 @@ obs_tm_shifted = Vector(undef, length(ensinfo))
#obs #obs
obs_w = Vector(undef, length(ensinfo)) obs_w = Vector(undef, length(ensinfo))
for (k, ens) in enumerate(ensinfo) for (k, ens) in enumerate(ensinfo)
println(ens)
# t0 # t0
t0_ens, YW, W = get_t0(path_data_w, ens, rw=rwf, path_rw=path_rw, pl=true) t0_ens, YW, W = get_t0(path_data_w, ens, rw=rwf, path_rw=path_rw, pl=true)
......
#=
# The code produces BDIO files for md_info (see OrderedDict md_info) and Wilson observables (see OrderedDict obs_w)
# The BDIO files are saved in path_bdio_md and path_bdio_w respectivily. Each BDIO file contains information about a given ensemble.
# Plateaux for different ensembles are defined in txt files (path_plat_w)
# The dat files must be located in the following way
path_data_w/ensemble -> *mesons.dat (Wilson)
path_data_w/ensemble -> *ms.dat
path_rw/ensemble -> *.ms1.dat
path_md/ensemble -> *.pbp.dat
# Example: path_rw/H400 contains H400r001.ms1.dat and H400r002.ms1.dat
# The target value of phi4 can be modified
# Masses and decay constants are in terms of the reference scale t0
# See read_bdio.jl for more information
# WARNING
# here there is a possible bug: symmetric point ensembles are not shifted at a fix value of phi_2 as it should be
# please use md.jl
=#
using Base: String
using LaTeXStrings: length
using OrderedCollections
using juobs, BDIO, DelimitedFiles, ADerrors, LaTeXStrings
#================== PATHS + INFO ==================#
const path_data_w = "/Users/alessandroconigli/Lattice/data/aux_obs_data/wilson"
const path_plat_w = "/Users/alessandroconigli/Lattice/data/aux_obs_data/plat_wilson.txt"
const path_rw = "/Users/alessandroconigli/Lattice/data/aux_obs_data/rwf"
const path_md = "/Users/alessandroconigli/Lattice/data/aux_obs_data/md"
const ens_list = ["N300"] # ["H101", "H102r002", "H400", "N202", "N200", "N203", "N300", "J303"]
const path_bdio_md = "/Users/alessandroconigli/Lattice/data/bdio_charm/md"
const path_bdio_w = "/Users/alessandroconigli/Lattice/data/bdio_charm/wilson"
const phi4_target = uwreal([1.098, 0.010], "phi4_target")
const rwf = true
#========= INCLUDES ==========#
include("./types.jl")
include("./tools.jl")
include("./const.jl")
#======== GET ENSEMBLE INFORMATION FROM DATABASE ==========#
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], trunc_db[ens])
catch
error("The ensemble id ", ens, " was not found in the const.jl ens_db database.
Please check the ensemble id or update the database")
end
end
#t0 [2.86, 3.659, 5.164, 8.595]
wpmm = Dict{String, Vector{Float64}}()
wpmm["H101"] = [-1.0, 4.0, -1.0, 14.0*2.86]
wpmm["H102r002"] = [-1.0, 4.0, -1.0, 14.0*2.86]
wpmm["H105"] = [-1.0, 4.0, -1.0, 14.0*2.86]
wpmm["H400"] = [-1.0, 4.0, -1.0, 14.0*3.659]
wpmm["N202"] = [-1.0, 4.0, -1.0, 14.0*5.164]
wpmm["N200"] = [-1.0, 4.0, -1.0, 14.0*5.164]
wpmm["N203"] = [-1.0, 4.0, -1.0, 14.0*5.164]
wpmm["N300"] = [-1.0, 4.0, -1.0, 14.0*8.595]
wpmm["J303"] = [-1.0, 4.0, -1.0, 14.0*8.595]
##
#======== ANALYSIS ==========#
gen_mulist = Vector{Vector{Vector{Float64}}}(undef, length(ens_list))
md_info = Vector(undef, length(ensinfo))
obs_tm_shifted = Vector(undef, length(ensinfo))
#obs
obs_w = Vector(undef, length(ensinfo))
for (k, ens) in enumerate(ensinfo)
# t0
t0_ens, YW, W = get_t0(path_data_w, ens, rw=rwf, path_rw=path_rw, pl=true)
# WILSON correlators
pp_w, pp_wW, _ = get_corr(path_data_w, ens, "G5", "G5", rw=rwf, path_rw=path_rw, legacy=true)
pp_w_d1, _, _ = get_corr(path_data_w, ens, "G5_d1", "G5_d1", rw=rwf, path_rw=path_rw, legacy=true)
pp_w_d2, _, _ = get_corr(path_data_w, ens, "G5_d2", "G5_d2", rw=rwf, path_rw=path_rw, legacy=true)
# WILSON masses
m_w = get_meff_w(pp_w, ens, pl=true)
kappa_list = getfield.(pp_w, :kappa)
mll_w = get_ll_w(kappa_list, m_w, ens.deg)
mls_w = ens.deg ? mll_w : get_ls_w(kappa_list, m_w, ens.deg)
phi2 = 8 * t0_ens * mll_w^2
phi4 = ens.deg ? 8 * t0_ens * 1.5 * mll_w^2 : 8 * t0_ens * (0.5 * mll_w^2 + mls_w^2)
# MASS SHIFTS
dSdm = read_pbp(path_md, ens.id)
ppll = get_ll_w(kappa_list, pp_w, ens.deg)
ppllW = get_ll_w(kappa_list, pp_wW, ens.deg)
ppll_d1 = get_ll_w(kappa_list, pp_w_d1, ens.deg)
ppll_d2 = get_ll_w(kappa_list, pp_w_d2, ens.deg)
dphi4_s1, dphi4_s2 = md_sea(phi4, dSdm, YW, W) .+ md_sea(phi4, dSdm, ppllW, W)
dphi2_s1, dphi2_s2 = md_sea(phi2, dSdm, YW, W) .+ md_sea(phi2, dSdm, ppllW, W)
dphi4_v1, dphi4_v2 = md_val(phi4, ppll, [ppll_d1, ppll_d2])
dphi2_v1, dphi2_v2 = md_val(phi2, ppll, [ppll_d1, ppll_d2])
if !ens.deg
ppls = get_ls_w(kappa_list, pp_w, ens.deg)
pplsW = get_ls_w(kappa_list, pp_wW, ens.deg)
ppls_d1 = get_ls_w(kappa_list, pp_w_d1, ens.deg)
ppls_d2 = get_ls_w(kappa_list, pp_w_d2, ens.deg)
aux1, aux2 = md_val(phi4, ppls, [ppls_d1, ppls_d2])
dphi4_v1 = dphi4_v1 + aux1
dphi4_v2 = dphi4_v2 + aux2
dphi4_s1, dphi4_s2 = (dphi4_s1, dphi4_s2) .+ md_sea(phi4, dSdm, pplsW, W)
end
# Dict: Deltam, phi2, phi4, t0 (shifted)
deltam = (phi4_target - phi4) / (2*dphi4_s1 + dphi4_s2 + dphi4_v1 + dphi4_v2)
dt0_s1, dt0_s2 = md_sea(t0_ens, dSdm, YW, W)
t0_ens_shifted = t0_ens + deltam * (2 * dt0_s1 + dt0_s2)
phi2_shifted = phi2 + deltam * (2*dphi2_s1 + dphi2_s2 + dphi2_v1 + dphi2_v2)
phi4_shifted = phi4 + deltam * (2*dphi4_s1 + dphi4_s2 + dphi4_v1 + dphi4_v2)
md_info[k] = OrderedDict(
"deltam" => deltam,
"t0_shifted" => t0_ens_shifted,
"phi2_shifted" => phi2_shifted,
"phi4_shifted" => phi4_shifted
)
obs_w[k] = OrderedDict(
"mll" => sqrt(8 * t0_ens) * mll_w,
"mls" => sqrt(8 * t0_ens) * mls_w,
"t0" => t0_ens,
"phi2" => phi2,
"phi4" => phi4
)
end
## WRITE BDIO
# MD INFO
for (k, obs) in enumerate(md_info) #loop over ensembles
ens = ensinfo[k].id
p = joinpath(path_bdio_md, string(ens, ".bdio"))
fb = BDIO_open(p, "w", ens)
uinfo = 0
for (key, value) in obs #loop over observables
write_uwreal(value, fb, uinfo)
uinfo += 1
end
BDIO_close!(fb)
end
# WILSON
for (k, obs) in enumerate(obs_w) #loop over ensembles
ens = ensinfo[k].id
p = joinpath(path_bdio_w, string(ens, ".bdio"))
fb = BDIO_open(p, "w", ens)
uinfo = 0
for (key, value) in obs #loop over observables
write_uwreal(value, fb, uinfo)
uinfo += 1
end
BDIO_close!(fb)
end
\ No newline at end of file
...@@ -23,7 +23,8 @@ function read_rw(path::String, ens::String) ...@@ -23,7 +23,8 @@ function read_rw(path::String, ens::String)
try try
length(rep) == 1 ? (return read_ms1(rep[1])) : (return read_ms1.(rep)) length(rep) == 1 ? (return read_ms1(rep[1])) : (return read_ms1.(rep))
catch catch
length(rep) == 1 && length(rep)!=0 ? (return read_ms1(rep[1], v="1.4")) : (return read_ms1.(rep, v="1.4")) ens == "H400" ? vv = "1.6" : vv="1.4"
length(rep) == 1 && length(rep)!=0 ? (return read_ms1(rep[1], v=vv)) : (return read_ms1.(rep, v=vv))
end end
else else
error("ms1.dat file not found for ensemble ", ens, " in path ", p) error("ms1.dat file not found for ensemble ", ens, " in path ", p)
......
#################################
# This file was created by Alessandro Conigli - 2022
# The pourpose of this code is to compute twisted mass
# observables from raw correlators stored in mesons.dat files.
# The analysis is performed at the level of a single ensemble
# and results are then stored in BDIO files
# It extracts:
# - charm quark mass
# - ll hl hh pseudo and vector masses
# - ll hl hh pseudo and vector leptonic decays
#
# The analysis is performed by solving a GEVP
##################################
using Base: String
using Base: @kwdef
using LaTeXStrings: length
using OrderedCollections
using juobs, BDIO, DelimitedFiles, ADerrors, LaTeXStrings, PyPlot
#============= SET UP VARIABLES ===========#
rcParams = PyPlot.PyDict(PyPlot.matplotlib."rcParams")
rcParams["text.usetex"] = false
rcParams["mathtext.fontset"] = "cm"
rcParams["font.size"] =10
rcParams["axes.labelsize"] =22
rcParams["axes.titlesize"] = 18
plt.rc("text", usetex=false) # set to true once you install latex
#============ PATHS & INFO =================#
# path to data
const path_data_w = "/Users/alessandroconigli/Lattice/data/aux_obs_data/wilson"
const path_data_tm = "/Users/alessandroconigli/Lattice/data/charm_full_Dirac"
# path to plateau
const path_plat_w = "/Users/alessandroconigli/Lattice/data/aux_obs_data/plat_wilson.txt"
const path_plat_tm_mps = "/Users/alessandroconigli/Lattice/gevp-automated-analysis/plat/plat_tm_mps.txt"
const path_plat_tm_mvec = "/Users/alessandroconigli/Lattice/gevp-automated-analysis/plat/plat_tm_mvec.txt"
const path_plat_tm_dps = "/Users/alessandroconigli/Lattice/gevp-automated-analysis/plat/plat_tm_dps.txt"
const path_plat_tm_dvec = "/Users/alessandroconigli/Lattice/gevp-automated-analysis/plat/plat_tm_dvec.txt"
# path to aux obs
const path_rw = "/Users/alessandroconigli/Lattice/data/aux_obs_data/rwf"
const path_md = "/Users/alessandroconigli/Lattice/data/aux_obs_data/md"
# path to bdio
const path_bdio_md = "/Users/alessandroconigli/Lattice/data/bdio_charm/md"
const path_bdio_tm = "/Users/alessandroconigli/Lattice/data/bdio_charm/tm"
const path_bdio_tm_shifted = "/Users/alessandroconigli/Lattice/data/bdio_charm/tm_shifted"
const path_plot = "/Users/alessandroconigli/MyDrive/phd/analysis/charm_gevp_2022/plots"
# ensembles to analyse
const ens_list = ["D200"]
# reweighting and mass shift flags
const rwf = true
const mass_shift = true
const tau = 4 # gevp shift parameter
const TSM = false # set whether TSM is used or not
#@warning("\nTSM FLAG MODE: $(TSM)\n")
#=============== INCLUDES ===============#
include("types.jl")
include("tools.jl")
include("const.jl")
include("read_bdio.jl")
#=============== ENSEMBLE INFO FROM DATABASE ==================#
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], trunc_db[ens])
catch
error("The ensemble id ", ens, " was not found in the const.jl ens_db database.
Please check the ensemble id or update the database")
end
end
wpmm = Dict{String, Vector{Float64}}()
wpmm["H101"] = [-1.0, 4.0, -1.0, 14.0*2.86]
wpmm["H102r002"] = [-1.0, 4.0, -1.0, 14.0*2.86]
wpmm["H105"] = [-1.0, 4.0, -1.0, 14.0*2.86]
wpmm["H400"] = [-1.0, 4.0, -1.0, 14.0*3.659]
wpmm["N202"] = [1.0, -2.0, -1.0, -1.0] #14.0*5.164]
wpmm["N200"] = [-1.0, 4.0, -1.0, 14.0*5.164]
wpmm["N203"] = [-1.0, 4.0, -1.0, 14.0*5.164]
#wpmm["D200"] = [-1.0, 4.0, -1.0, 14.0*5.164]
wpmm["D200"] = [1.0, -1.0, -1.0, -1.0]
wpmm["N300"] = [-1.0, 4.0, -1.0, 14.0*8.595]
wpmm["J303"] = [-1.0, 4.0, -1.0, 14.0*8.595]
wpmm["D200_corr"] = [1.0, -1.0, -1.0, -1.0]
##
##
#=============== ANALYSIS ===============#
gen_mulist = Vector{Vector{Vector{Float64}}}(undef, length(ens_list))
# obs storage
obs_tm = Vector(undef, length(ensinfo))
if mass_shift
deltam = Vector(undef, length(ensinfo))
obs_tm_shifted = Vector(undef, length(ensinfo))
end
pp_tm= Vector(undef, length(ensinfo))
pp_tmW= Vector(undef, length(ensinfo))
a0a0_tm= Vector(undef, length(ensinfo))
pa0_tm= Vector(undef, length(ensinfo))
a1a1_tm= Vector(undef, length(ensinfo))
pa1_tm= Vector(undef, length(ensinfo))
for (k,ens) in enumerate(ensinfo)
#t0_ens, YW, W = get_t0(path_data_w, ens, rw=rwf, path_rw=path_rw)
pp_tm[k], pp_tmW[k] = get_corr(path_data_tm, ens,"G5", "G5", rw=rwf, path_rw=path_rw, tsm=TSM, ex=true)
a0a0_tm[k], _ = get_corr(path_data_tm, ens, "G0G5", "G0G5", rw=rwf, path_rw=path_rw, tsm=TSM, ex=true)
a1a1_tm[k], _ = get_corr(path_data_tm, ens, "G1G5", "G1G5", rw=rwf, path_rw=path_rw, tsm=TSM, ex=true)
# a2a2_tm, _ = get_corr(path_data_tm, ens, "G2G5", "G2G5", rw=rwf, path_rw=path_rw, tsm=TSM)
# a3a3_tm, _ = get_corr(path_data_tm, ens, "G3G5", "G3G5", rw=rwf, path_rw=path_rw, tsm=TSM)
pa0_tm[k], _ = get_corr(path_data_tm, ens, "G5", "G0G5", rw=rwf, path_rw=path_rw, tsm=TSM, ex=true)
pa1_tm[k], _ = get_corr(path_data_tm, ens, "G5", "G1G5", rw=rwf, path_rw=path_rw, tsm=TSM, ex=true)
# pa2_tm, _ = get_corr(path_data_tm, ens, "G5", "G2G5", rw=rwf, path_rw=path_rw, tsm=TSM)
# pa3_tm, _ = get_corr(path_data_tm, ens, "G5", "G3G5", rw=rwf, path_rw=path_rw, tsm=TSM)
end
##
mm = Vector{Vector{uwreal}}(undef, length(ensinfo))
for (k,ens) in enumerate(ensinfo)
mu_list = gen_mulist[k] = getfield.(pp_tm[k], :mu)
# gevp matrices mixing different gamma struct
# mat_pp = comp_mat_multigamma(ens, pp_tm[k], pa1_tm[k], a1a1_tm[k])[1:9]
# gevp matrices shifting in time
mat_pp = comp_mat_tau_shift(ens, pp_tm[k], tau)
# mps0, mps1 = gevp_mass(mat_pp, path_plat_tm_mps, path_plat_tm_mvec, t0=3, wpm=wpmm, pl=true)
mps0 = gevp_mass_BMA(mat_pp, t0=2, wpm=wpmm, pl=true)
mm[k] = mps0
end
##
mefff = meff(pp_tm[1][1], [90,95], pl=true, wpm=wpmm)
##
""" this function return a vector of correlators built using gevp projection to the ground state.
A GEVP is solved for several ta and tb and a new correlator is computed for each of them
"""
function gevp_GPOF(ensinfo::EnsInfo, corr::Vector{juobs.Corr}; N::Int64=4, TA::Vector{Int64}=[2,4], TB::Vector{Int64}=[7,8])
mat_info = comp_mat_GPOF(ensinfo, corr, N=N)
y0 = getfield(corr[1], :y0)
mu = getfield(corr[1], :mu)
new_corr = Vector{Vector{Vector{uwreal}}}(undef, length(mat_info))
for i in eachindex(mat_info)
mat = getfield(mat_info[i], :mat_list)
new_corr[i] = Vector{Vector{uwreal}}(undef, 0)
for ta in TA
for tb in TB
evalues, evecs = juobs.uweigen(mat[ta], mat[tb], iter = 20)
aux_corr = [uwdot(juobs.transpose(evecs[:,N]), uwdot( mat[k], evecs[:,N]) )[1] for k in eachindex(mat)]
push!(new_corr[i], aux_corr)
end
end
end
return new_corr
end
function gevp_GPOF_BMA(ensinfo::EnsInfo, corr::Vector{juobs.Corr}; N::Int64=4, TA::Vector{Int64}=[2], TB::Vector{Int64}=[7,8], pl::Bool=true, wpm::Union{Nothing, Dict{String,Vector{Float64}}}=nothing)
new_corr = gevp_GPOF(ensinfo, corr, N=N, TA=TA, TB=TB)
@. one_exp_fit(x,p) = p[1] + p[2]*exp(-p[3]*x)
Nparam=3
y0 = getfield(corr[1], :y0)
T = length(corr[1].obs) - y0
# fit time ranges for bayesian_av
tmin = collect(10:12)
tmax = collect(T-40:T-39)
MAve = Vector{uwreal}(undef, length(corr))
for k in eachindex(new_corr) # mass index
AIC = Vector{Float64}(undef, 0)
Masses = Vector{uwreal}(undef, 0)
for j in eachindex(new_corr[k]) # ta and tb gevp index
_, data_meff = juobs.meff(new_corr[k][j], [tmin[end], tmax[1]], pl=true, data=true, wpm=wpm)
_, _, param, _, aic = juobs.bayesian_av(one_exp_fit, data_meff, tmin, tmax, Nparam, pl=false, wpm=wpmm, data = true)
close("all")
AIC = vcat(AIC, aic )
Masses = vcat(Masses, param)
end
isnothing(wpm) ? uwerr.(Masses) : [uwerr(Masses[i], wpm) for i in eachindex(Masses)]
offset = minimum(AIC)
AIC = AIC .- offset
Wtot = exp.(-0.5 .* AIC)
Wtot /= sum(Wtot)
MAve[k] = sum(Masses .* Wtot)
isnothing(wpm) ? uwerr(MAve[k]) : uwerr(MAve[k], wpm)
if pl
subplot(211)
title(string(L"$\mu_1 = $", corr[k]. mu[1], L" $\mu_2 = $", corr[k]. mu[2]))
ax1 = gca()
setp(ax1.get_xticklabels(),visible=false) # Disable x tick labels
xx = collect(1:length(Masses))
vv = value.(Masses)
errorbar(xx, vv, err.(Masses), fmt="s")
aux1 = sum( Wtot .* Masses.^2)
aux2 = sum( Wtot .* Masses)^2
syst = sqrt(abs(value(aux1-aux2)))
fill_between(xx, value(MAve[k]) - err(MAve[k]), value(MAve[k]) + err(MAve[k]),color="red", alpha=0.2)
ylabel(L"$M_0$")
subplot(212)
plot(xx, Wtot)
ylabel(L"$W$")
xlabel("Models")
display(gcf())
close()
end
end
return MAve
end
## test gevp_mass_GPOF
mm_gpof = gevp_GPOF_BMA(ensinfo[1],pp_tm[1][9:9], pl=true, TA=[4], TB=[6], wpm=wpmm);
uwerr.(mm_gpof)
println(mm_gpof)
##
new_corr = gevp_GPOF(ensinfo[1], pp_tm[1][3:3], TA=[4], TB=[10]);
mtest = juobs.meff.(new_corr[3], fill([25,45], 4), pl=true, wpm=wpmm )
mstd = meff(pp_tm[1][2], [65,80], pl=true, wpm=wpmm )
##
function gevp_mass_BMA(mat_obs::Vector{MatInfo}; t0::Int64=2,pl::Bool=true, wpm::Union{Nothing, Dict{String,Vector{Float64}}}=nothing)
y0s = getfield.(mat_obs, :y0)
mu_list = getfield.(mat_obs, :mu)
en0 = Vector{uwreal}(undef, length(mat_obs))
en1 = Vector{uwreal}(undef, length(mat_obs))
data_tot = Vector(undef, length(mat_obs))
W_tot = Vector(undef, length(mat_obs))
for k in eachindex(mat_obs)
mat = getfield(mat_obs[k], :mat_list) #[y0s[i]+1:end-1] #matrices to diagonalise for a given sector [i]
evals = juobs.getall_eigvals(mat, t0)
entot = juobs.energies(evals, wpm=wpm)
@. gs_model(x,p) = p[1] + p[2] * exp(-(p[3])*x)
param = 3
tmin = collect(10:12) # scart from source
tmax = collect(36:38)
en0[k], _, data_tot[k], W_tot[k], _ = juobs.bayesian_av(gs_model, entot[1], tmin, tmax, param, pl=false, wpm=wpmm, data=true)
close("all")
if pl
Masses = data_tot[k]
isnothing(wpm) ? uwerr.(Masses) : [uwerr(Masses[i]) for i in eachindex(Masses)]
subplot(211)
# title(string(L"$\mu_1 = $", corr[k]. mu[1], L" $\mu_2 = $", corr[k]. mu[2]))
ax1 = gca()
setp(ax1.get_xticklabels(),visible=false) # Disable x tick labels
xx = collect(1:length(Masses))
vv = value.(Masses)
errorbar(xx, vv, err.(Masses), fmt="s")
aux1 = sum( W_tot[k] .* Masses.^2)
aux2 = sum( W_tot[k] .* Masses)^2
syst = sqrt(abs(value(aux1-aux2)))
fill_between(xx, value(en0[k]) - err(en0[k]), value(en0[k]) + err(en0[k]), color="red", alpha=0.2)
ylabel(L"$M_0$")
subplot(212)
plot(xx, W_tot[k])
ylabel(L"$W$")
xlabel("Models")
display(gcf())
close()
end
if pl
vv = value.(entot[1])
ee = err.(entot[1])
xx = collect(1:length(vv))
errorbar(xx, vv, ee, fmt="*")
# xlim(1,y0s[k]-10)
ylim(value(en0[k])-10*err(en0[k]), value(en0[k])+10*err(en0[k]))
display(gcf())
close()
end
end
return en0, data_tot, W_tot
end
## test uweigen
aa = comp_mat_GPOF(ensinfo[1], pp_tm[1])
mat1 = aa[9].mat_list[3]
mat2 = aa[9].mat_list[8]
ee, vv = juobs.uweigen(mat1, mat2, iter=10)
ee1, vv1 = eigen(value.(mat1), value.(mat2))
##
for k in 1:9
println("\nk=$(k)")
println("tau=4 ", mps0[k])
println("tau=3 ", mps0_old_tau[k])
end
##
meffpp = juobs.meff(pp_tm[1][7], [85,90], pl=true)
\ No newline at end of file
using juobs, BDIO, DelimitedFiles, ADerrors, LaTeXStrings, PyPlot
using LaTeXStrings: length
using LsqFit
rcParams = PyPlot.PyDict(PyPlot.matplotlib."rcParams")
rcParams["text.usetex"] = false
rcParams["mathtext.fontset"] = "cm"
rcParams["font.size"] =10
rcParams["axes.labelsize"] =22
rcParams["axes.titlesize"] = 18
plt.rc("text", usetex=false) # set to true once you install latex
path_corr = "/Users/alessandroconigli/Lattice/data/charm_full_Dirac/N302/N302r001_correction_k0.137211_mup0.00292_mup0.00682_mup0.1320_mup0.1460.mesons.dat"
path_sl = "/Users/alessandroconigli/Lattice/data/charm_full_Dirac/N302/N302r001_sloppy_k0.137211_mup0.00292_mup0.00682_mup0.1320_mup0.1460.mesons.dat"
path_rw = "/Users/alessandroconigli/Lattice/data/aux_obs_data/rwf/N302/N302r001.ms1.dat"
ens = "N302"
##
wpmm = Dict{String, Vector{Float64}}()
wpmm["H101"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["H102r002"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["H400"] = [-1.0, 1.5, -1.0, -1.0]
wpmm["N202"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["N200"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["N203"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["N300"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["N302"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["J303"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["D200"] = [-1.0, 4.0, -1.0, -1.0]
##
# D200 param
# noise_trunc = [nothing, 1, 2, 4, 8]
# ncfg = [2000, 2000, 1000, 500, 250]
# idmsl = [collect(1:2000), collect(1:2000), collect(1:2:2000), collect(1:4:2000), collect(1:8:2000)]
noise_trunc = [16, 2, 4, 8]
ncfg = [60, 60, 30, 15]
idmsl = [collect(1:60), collect(1:60), collect(1:2:60), collect(1:4:60)]
## here i want to test, with full statistics, the TSM, sloppy, exact and exact-sloppy,corr observables
rwf = juobs.read_ms1(path_rw)
idm_corr= collect(1:20)
nms = 60
data_corr = juobs.read_mesons_correction(path_corr,"G5", "G5") # correction data combined
data_ex = juobs.read_mesons(path_corr, "G5", "G5" )[1:9] # sloppy data only
data_sl = juobs.read_mesons(path_sl, "G5", "G5") # exact data only
pp_corr = juobs.corr_obs.(data_corr, idm=idm_corr, nms=nms) # correction correlator
pp_ex = juobs.corr_obs.(data_ex, idm=idm_corr, nms=nms) # exact correlator
pp_sloppy = juobs.corr_obs.(data_sl, idm=idmsl[1], nms=nms) # sloppy correlator
pp_TSM = juobs.corr_obs_TSM.(data_sl, data_corr, idm_corr=idm_corr, idm_sl=idmsl[1], nms=nms) # exact correlator
for midx in [1,4,5,6]
TT = 75
tmp_corr = pp_corr[midx].obs[TT] ; uwerr(tmp_corr, wpmm)
tmp_ex = pp_ex[midx].obs[TT] ; uwerr(tmp_ex, wpmm)
tmp_sloppy = pp_sloppy[midx].obs[TT] ; uwerr(tmp_sloppy, wpmm)
tmp_TSM = pp_TSM[midx].obs[TT] ; uwerr(tmp_TSM, wpmm)
println("#############")
println("Midx = $(midx)")
println("TSM = $(tmp_TSM)")
println("Sloppy = $(tmp_sloppy)")
println("Exact = $(tmp_ex)")
println("Correc = $(tmp_corr)")
println("#############")
end
## here i am studing the tradeoff between noise sources and number of configurations.
ll = Vector()
pp = Vector{Vector{juobs.Corr}}(undef, 0)
for k in eachindex(noise_trunc)
println(k)
data_sl = juobs.read_mesons(path_sl, "G5", "G5", nnoise_trunc=noise_trunc[k])
ppaux = juobs.corr_obs_TSM.(data_sl, data_corr, idm_corr=idm_corr, idm_sl=idmsl[1], nms=nms )
push!(pp, ppaux )
llaux = string("cnfg:",ncfg[k], " nnoise:", noise_trunc[k])
push!(ll, llaux)
end
## pp corr vs cnfg and nnoise
PPfix = Vector{Vector{uwreal}}(undef, length(pp))
PPfixex = Vector{Vector{uwreal}}(undef, length(pp))
for k in eachindex(pp)
PPfix[k] = Vector{uwreal}(undef, 0)
PPfixex[k] = Vector{uwreal}(undef, 0)
for midx in [1,4,5,6]
yy = pp[k][midx].obs[75]
yyex = pp_ex[midx].obs[75]
push!(PPfix[k], yy)
push!(PPfixex[k], yyex)
end
end
tt = ["PPll", "PPlh", "PPsh", "PPhh"]
for k in eachindex(PPfix[1])
fig = figure(figsize=(10,7.5))
yy = getindex.(PPfix, k)
yyex = getindex.(PPfixex, k)
[uwerr(yy[ii], wpmm) for ii in eachindex(yy)]
[uwerr(yyex[ii], wpmm) for ii in eachindex(yyex)]
xx = collect(1:length(yy))
errorbar(xx, value.(yy), err.(yy), fmt="*", capsize=2, label="TSM" )
errorbar(xx.+0.1, value.(yyex), err.(yyex), fmt="*", capsize=2, label="Exact" )
xticks(xx, string.(ll), rotation=15)
title(tt[k])
legend()
display(fig)
# savefig(joinpath("/Users/alessandroconigli/Lattice",string(tt[k],"_corrppNoiseCnfg.pdf")))
close()
end
## print corr values at all nnoise and cnfg for all masses
for k in eachindex(PPfix[1])
yy = getindex.(PPfix, k)
[uwerr(yy[ii], wpmm) for ii in eachindex(yy)]
for elem in yy
println(elem)
end
println("\n")
end
## meff vs cnfg and nnoise
M = Vector{Vector{uwreal}}(undef, length(pp))
for k in eachindex(pp)
M[k] = Vector{uwreal}(undef, 0)
cc = 1
for midx in [1,4,5,6]
if cc == 1
tmin =collect(75:85)
tmax = collect(105:115)
tmax = tmax[1:2:end]
plat = [85,100]
else
tmin = cc==4 ? collect(86:88) : collect(78:84)
tmax = cc==4 ? collect(90:92) : collect(95:100)
plat = cc==4 ? [88,94] : [85,95]
end
@. fitt(x,p) = p[1]
maux = juobs.meff(pp[k][midx], plat, pl=true )
# maux, syst, all_res, FitDict = juobs.bayesian_av(fitt, data, tmin, tmax, 2, pl=true, data=true, plt_title="ciao", path_plt=nothing, label=L"$m$")
push!(M[k], maux)
cc+=1
end
end
##
# plot
tt = ["mll", "mlh", "msh", "mhh"]
for k in eachindex(M[1])
fig = figure(figsize=(10,7.5))
yy = getindex.(M, k)
xx = collect(1:length(yy))
errorbar(xx, value.(yy), err.(yy), fmt="*", capsize=2 )
xticks(xx, string.(ll), rotation=15)
title(tt[k])
display(fig)
savefig(joinpath("/Users/alessandroconigli/Lattice",string(tt[k],"_testNoiseCnfg.pdf")))
close()
end
##
idxm = 4
t0= meff(pp[1][idxm], [85,94])
t1 = meff(pp[2][idxm], [85,95])
t2 = meff(pp[3][idxm], [85,95])
t3 = meff(pp[4][idxm], [85,95])
t4 = meff(pp[5][idxm], [85,95])
\ No newline at end of file
#========= ENSEMBLE DATABASE ========# #========= ENSEMBLE DATABASE ========#
ens_db = Dict( ens_db = Dict(
#"ens_id"=>[L, beta, is_deg?, m_pi, dtr] #"ens_id"=>[L, beta, is_deg?, m_pi, dtr, idm_corr]
"H102r002" => [32, 3.4, false, 0.15306, 2], "H102r002" => [32, 3.4, false, 0.15306, 2, nothing],
#"H102r001" => [32, 3.4, false, 0.15306, 2], #"H102r001" => [32, 3.4, false, 0.15306, 2],
"H105" => [32, 3.4, false, 0.12151, 2], "H105r002" => [32, 3.4, false, 0.12151, 2, nothing],
"H101" => [32, 3.4, true, 0.17979, 2], "H101" => [32, 3.4, true, 0.17979, 2, nothing],
"H400" => [32, 3.46, true, 0.16345, 1], "H400" => [32, 3.46, true, 0.16345, 1, nothing],
"N200" => [48, 3.55, false, 0.09222, 1], "N200" => [48, 3.55, false, 0.09222, 1, nothing],
"N202" => [48, 3.55, true, 0.13407, 2], "N202" => [48, 3.55, true, 0.13407, 2, nothing],
"N203" => [48, 3.55, false, 0.11224, 1], "N203" => [48, 3.55, false, 0.11224, 1, nothing],
"D200" => [64, 3.55, false, 0.06611, 2], "D200" => [64, 3.55, false, 0.06611, 2, 100],
"N300" => [48, 3.70, true, 0.10630, 1], "N300" => [48, 3.70, true, 0.10630, 1, nothing],
"J303" => [64, 3.70, false, 0.06514, 2] "N302" => [48, 3.70, false, 0.10630, 1, nothing],
) "J303" => [64, 3.70, false, 0.06514, 2, nothing],
"E300" => [96, 3.70, false, 0.00000, 1, nothing],
"J500" => [64, 3.85, true, 0.00000, 2, nothing],
"J501" => [64, 3.85, false, 0.00000, 2, nothing],
)
trunc_db = Dict( trunc_db = Dict(
"H102r002" => nothing, "H102r002" => nothing,
#"H102r001" => nothing, #"H102r001" => nothing,
"H105" => nothing, "H105r002" => nothing,
"H101" => nothing, "H101" => [1001,1009],
"H400" => nothing, "H400" => nothing,
"N200" => nothing, "N200" => nothing,
"N202" => nothing, "N202" => nothing,
"N203" => nothing, "N203" => nothing,
"D200" => 1000, "D200" => 645, #1000
"N300" => nothing, "N300" => 1279,
"J303" => nothing "N302" => nothing,
"J303" => 721,
"E300" => nothing,
"J500" => [745,649], #[751, 655],
"J501" => nothing
) )
# total number of cnfg for each ens
ens_nms = Dict(
#"H102r001" => 1029,
"H102r002" => 1008,
"H105r002" => 1042,
"H101" => 2016,
"H400" => 1045,
"N200" => 1712,
"N202" => 899,
"N203" => 1543,
"D200" => 2001,
"N300" => 1540,
"N302" => 2201,
"J303" => 1073,
"E300" => 1139
)
#PDG #PDG
const hc = 197.3269804 #MeV fm const hc = 197.3269804 #MeV fm
const M_values = [1869.65, 2010.26, 1968.34, 2112.2, 2980.3, 3096.916] #MD, MD*, MDs, MDs*, \eta_c, J/\psi (MeV) const M_values = [1869.65, 2010.26, 1968.34, 2112.2, 2980.3, 3096.916] #MD, MD*, MDs, MDs*, \eta_c, J/\psi (MeV)
...@@ -39,8 +65,8 @@ const ZM_error = [35, 27, 33, 38, 45] .* 1e-4 ...@@ -39,8 +65,8 @@ const ZM_error = [35, 27, 33, 38, 45] .* 1e-4
const ZM_tm_data = [2.6047, 2.6181, 2.6312, 2.6339, 2.6127] const ZM_tm_data = [2.6047, 2.6181, 2.6312, 2.6339, 2.6127]
const ZM_tm_error = [42, 33, 42, 48, 55] .* 1e-4 const ZM_tm_error = [42, 33, 42, 48, 55] .* 1e-4
#1608.08900 #1608.08900
const t0_data = [2.86, 3.659, 5.164, 8.595] const t0_data = [2.86, 3.659, 5.164, 8.595, 14.040]
const t0_error = [11, 16, 18, 29] .* 1e-3 const t0_error = [11, 16, 18, 29, 49] .* 1e-3
const t0_ph_value = #=[0.415] =# [0.4137] const t0_ph_value = #=[0.415] =# [0.4137]
const t0_ph_error = ones(1,1) .* #=4e-3 =# 3.6e-3 const t0_ph_error = ones(1,1) .* #=4e-3 =# 3.6e-3
# 1808.09236 # 1808.09236
...@@ -49,7 +75,7 @@ const ZA_err = [72, 93, 43, 47, 47] .*1e-5 ...@@ -49,7 +75,7 @@ const ZA_err = [72, 93, 43, 47, 47] .*1e-5
#Covariance matrices (Uncorrelated) #Covariance matrices (Uncorrelated)
const C1 = zeros(5, 5) const C1 = zeros(5, 5)
const C2 = zeros(5, 5) const C2 = zeros(5, 5)
const C3 = zeros(4, 4) const C3 = zeros(5, 5)
const C4 = zeros(6,6) const C4 = zeros(6,6)
const C5 = zeros(5, 5) const C5 = zeros(5, 5)
for i = 1:6 for i = 1:6
...@@ -58,9 +84,7 @@ for i = 1:6 ...@@ -58,9 +84,7 @@ for i = 1:6
C1[i, i] = ZM_error[i] ^ 2 C1[i, i] = ZM_error[i] ^ 2
C2[i, i] = ZM_tm_error[i] ^ 2 C2[i, i] = ZM_tm_error[i] ^ 2
C5[i, i] = ZA_err[i]^2 C5[i, i] = ZA_err[i]^2
if i<=4 C3[i,i] = t0_error[i] ^ 2
C3[i,i] = t0_error[i] ^ 2
end
end end
end end
...@@ -84,6 +108,6 @@ Mrat = uwreal([0.9148, 0.0088], "M/mhad") ...@@ -84,6 +108,6 @@ Mrat = uwreal([0.9148, 0.0088], "M/mhad")
# Renormalization constants, t0 and a as functions (f(beta)) # Renormalization constants, t0 and a as functions (f(beta))
zm(beta::Float64) = ZM[b_values .== beta][1] zm(beta::Float64) = ZM[b_values .== beta][1]
zm_tm(beta::Float64) = Mrat / ZP(beta) zm_tm(beta::Float64) = Mrat / ZP(beta)
t0(beta::Float64) = t0_[b_values2 .== beta][1] t0(beta::Float64) = t0_[b_values .== beta][1]
a(beta::Float64) = a_[b_values2 .== beta][1] a(beta::Float64) = a_[b_values .== beta][1]
za(beta::Float64) = Za[b_values .== beta][1] za(beta::Float64) = Za[b_values .== beta][1]
\ No newline at end of file
...@@ -183,4 +183,197 @@ for n = 2:f_npar+1 ...@@ -183,4 +183,197 @@ for n = 2:f_npar+1
end end
f_npar_comb = 2 * f_npar f_npar_comb = 2 * f_npar
f_n_param_comb = collect(5:2:f_npar_comb+5) f_n_param_comb = collect(5:2:f_npar_comb+5)
f_n_param_comb_clog = collect(6:2:f_npar_comb+6) f_n_param_comb_clog = collect(6:2:f_npar_comb+6)
\ No newline at end of file
########################################
######## RATIO DEC. CONST. ############
########################################
# Testing HQET and TAYLOR functional forms for (fDs*sqrt{mDs)}/(fD*sqrt{Md})
# from Gregorio's notes https://cloud.ift.uam-csic.es/s/9PGEbX5sDzcN5Xq#pdfviewer
# base model from HQET
# before p[1] = \phi_f^2 in notes. Treated as a parameter but using fpk data would be better
# now p[1]=x[:,5] fpik data from AS and p[2]=p[1]
r_basemodel_hqet(x,p) = 1. .- (1. .+ 3 .* 0.52)./(64. .* π.^2 .* x[:,5]) .*
((3 .*phi2_sym .- x[:,2]) .* log.(1.5 .* phi2_sym .- 0.5 .* x[:,2]) .+ #2L_k chiral log
(2 .* phi2_sym .- x[:,2]) .* log.(2 .* phi2_sym .- x[:,2]) .- # L_\eta chiral log
3 .* x[:,2] .* log.(x[:,2]) ) .+ # 3L_\pi chiral log
((4. .* p[1]) ./ x[:,5]) .* (3 .* phi2_sym .- 3 .* x[:,2])
# higher order terms HQET - careful, explicit p[1]=\phi_f^2 dependece is discouraged
r_chiphi2_hqet(x) = (4 ./ x[:,5].^2) .* (3 .* phi2_sym .- 3 .* x[:,2]) .* x[:,2]
r_chiphih_hqet(x) = (4 ./ x[:,5]) .* (3 .* phi2_sym .- 3 .* x[:,2]) ./ x[:,3]
# base model lattice spacing dependece
r_basemodel_continuum(x,p) = 1. .+ p[2] .* x[:,1] .* (3 .* phi2_sym .- 3 .* x[:,2])
# higher order lattice spacing dependence
r_phih_a_continuum(x) = x[:,1] .* (3 .* phi2_sym .- 3 .* x[:,2]) .* x[:,3].^2
r_cont_func_list = [r_phih_a_continuum]
# r_cont_func_label = [L"$p_a^{(3)}$"]
r_cont_func_label = ["pa(3)"]
r_cont_extra_par = length(r_cont_func_list)
r_cont_func_map = [Bool.([i]) for i=0:1]
r_hqet_func_list = [r_chiphi2_hqet, r_chiphih_hqet ] #, r_phih_a_continuum]
# r_hqet_func_label = [L"$p\chi^{(2)}$", L"$p_{\chi}^{(4)}$" ] #, L"$p_a^{(3)}$" ]
r_hqet_func_label = ["pχ(2)", "pχ(4)" ] #, L"$p_a^{(3)}$" ]
r_hqet_func_map = [Bool.([i,j]) for i=0:1 for j=0:1 ]#for k in 0:1 ]
r_hqet_base_par = 2 # 1 from hqet base model, 1 from LO lattice spacing dependence
r_hqet_extra_par = length(r_hqet_func_list) # number of extra parameters on top of base model
r_hqet_models = Vector{Function}(undef,1) #r_hqet_base_par+r_hqet_extra_par)
r_hqet_models[1] = (x,p) -> r_basemodel_hqet(x,p) .* r_basemodel_continuum(x,p)
r_hqet_param = [2]
r_hqet_labels = [["hqet"]]
for extrapar = 1:r_hqet_extra_par
idx_f_expar = filter(x->sum(x)==extrapar, r_hqet_func_map)
# build and store temporary hqet dependence
tmp_hqet_func = Vector{Function}()
tmp_hqet_param = []
tmp_hqet_label = []
for ii in idx_f_expar
aux_f = (x,p) -> r_basemodel_hqet(x,p) .+ sum( p[r_hqet_base_par+k] .* r_hqet_func_list[ii][k](x) for k in eachindex(r_hqet_func_list[ii]))
push!(tmp_hqet_param, r_hqet_base_par + extrapar)
push!(tmp_hqet_func, aux_f)
push!(tmp_hqet_label, r_hqet_func_label[ii])
end
# add continuum dependence - already code in view of adding more continuum higher order terms
for (jj, f_hqet) in enumerate(tmp_hqet_func)
aux1 = (x,p) -> f_hqet(x,p) .* r_basemodel_continuum(x,p)
push!(r_hqet_models, aux1)
push!(r_hqet_param, tmp_hqet_param[jj])
push!(r_hqet_labels, tmp_hqet_label[jj])
for contpar = 1:r_cont_extra_par
idx_cont_expar = filter(x->sum(x)==contpar, r_cont_func_map)
for ii in idx_cont_expar
aux_f_cont = (x,p) -> f_hqet(x,p) .* (r_basemodel_continuum(x,p) .+ sum(p[r_hqet_base_par+extrapar+k] .* r_cont_func_list[ii][k](x) for k in eachindex(r_cont_func_list[ii]) ) )
push!(r_hqet_models, aux_f_cont)
push!(r_hqet_param, tmp_hqet_param[jj]+contpar)
push!(r_hqet_labels, vcat(tmp_hqet_label[jj], r_cont_func_label[ii] ))
end
end
end
end
# at the end of the above loop all the HQET combinations are taken into acount and store in r_hqet_models, r_hqet_param, r_hqet_labels
# now ration functional forms for Taylor based expressions
# base model taylor
r_basemodel_taylor(x,p) = 1. .+ 3 .*(phi2_sym .- x[:,2]) .*
(p[1] .+ p[2] .* ( 1. ./ x[:,3] .- 1. ./ x[:,4]) )
#higher order models taylor
r_taylor_nlo_phi2(x) = 3 .* (phi2_sym .- x[:,2]) .* x[:,2]
# this redefinition is required since in hqet LO parameter in continuum dependece is p[2] while here is p[3]
r_basemodel_continuum_taylor(x,p) = 1. .+ p[3] .* x[:,1] .* (3 .* phi2_sym .- 3 .* x[:,2])
r_taylor_func_list = [r_taylor_nlo_phi2]
r_taylor_func_label = ["pm(2)"]
r_taylor_func_map = [Bool.([i]) for i=0:1]
r_taylor_base_par = 3 # 2 from taylor base model, 1 from LO lattice spacing dependence
r_taylor_extra_par = length(r_taylor_func_list)
r_taylor_models = Vector{Function}(undef, 1)# r_basemodel_taylor + extra param
r_taylor_models[1] = (x,p) -> r_basemodel_taylor(x,p) .* r_basemodel_continuum_taylor(x,p)
r_taylor_param = [3]
r_taylor_labels = [["taylor"]]
for extrapar in 1:r_taylor_extra_par
idx_f_expar = filter(x-> sum(x)==extrapar, r_taylor_func_map)
# build and store temporary taylor dependence
tmp_taylor_func = Vector{Function}()
tmp_taylor_param = []
tmp_taylor_label = []
for ii in idx_f_expar
aux_f = (x,p) -> r_basemodel_taylor(x,p) .+ sum(p[r_taylor_base_par+k] .* r_taylor_func_list[ii][k](x) for k in eachindex(r_taylor_func_list[ii]))
push!(tmp_taylor_param, r_taylor_base_par +extrapar)
push!(tmp_taylor_func, aux_f)
push!(tmp_taylor_label, r_taylor_func_label[ii])
end
# add continuum dependence - already code in view of adding more continuum higher order terms
for (jj, f_taylor) in enumerate(tmp_taylor_func)
aux1 = (x,p) -> f_taylor(x,p) .* r_basemodel_continuum_taylor(x,p)
push!(r_taylor_models, aux1)
push!(r_taylor_param, tmp_taylor_param[jj])
push!(r_taylor_labels, tmp_taylor_label[jj])
for contpar = 1:r_cont_extra_par
idx_cont_expar = filter(x->sum(x)==contpar, r_cont_func_map)
for ii in idx_cont_expar
aux_f_cont = (x,p) -> f_taylor(x,p) .* (r_basemodel_continuum_taylor(x,p) .+ sum(p[r_taylor_base_par+extrapar+k] .* r_cont_func_list[ii][k](x) for k in eachindex(r_cont_func_list[ii]) ))
push!(r_taylor_models, aux_f_cont)
push!(r_taylor_param, tmp_taylor_param[jj]+contpar)
push!(r_taylor_labels, vcat(tmp_taylor_label[jj], r_cont_func_label[ii]))
end
end
end
end
# at the end this second loop all the TAYLOR combinations are taken into acount and store in r_taylor_models, r_taylor_param, r_taylor_labels
# final ration models are
r_tot_models = vcat(r_hqet_models, r_taylor_models)
r_tot_param = vcat(r_hqet_param, r_taylor_param)
r_tot_labels = vcat(r_hqet_labels, r_taylor_labels)
##
# Operator overloading to call functions with uwreal parameters
function Base.length(uw::uwreal)
return length(value(uw))
end
# function Base.iterate(uw::uwreal)
# uwerr(uw)
# return iterate(value(uw), 1)
# out = iterate(value(uw), args...; kwargs...)
# return (uw, 1)
# isnothing(out2) ? (return nothing) : (return (uw, out2)) #(uw, out2) #(uw, getindex(out, 2))
# return iterate(uw, args...)
# return uwreal([iterate(value(uw), 1), err(uw)], " " )
# end
# function Base.iterate(uw::uwreal, i::Int64)
# uwerr(uw)
# return iterate(value(uw),i)
# end
function Base.iterate(uw::uwreal)
return iterate(uw, 1)
end
function Base.iterate(uw::uwreal, state::Int64)
if state > length(uw)
return nothing
else
return uw[state], state +1
end
end
function Base.iterate(uw::Vector{uwreal})
return iterate(uw, 1)
end
function Base.iterate(uw::Vector{uwreal}, state::Int64)
if state > length(uw)
return nothing
else
return uw[state], state +1
end
end
function Base.abs2(uw::uwreal)
return (uw^2)^0.5
end
function Base.getindex(uw::uwreal, ii::Int64)
idx = getindex(value(uw), ii)
return uw # uwreal([getindex(value(uw), kwargs...), err(uw)], " ")
end
# function Base.getindex(uw::Vector{uwreal}, ii::Int64)
# idx = getindex(value.(uw), ii)
# return uw[ii] # uwreal([getindex(value(uw), kwargs...), err(uw)], " ")
# end
aaa = iterate(uwreal([5., 0.05], "c"))
aaa = iterate([[uwreal([5., 0.05], "c")]])
\ No newline at end of file
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
################################## ##################################
using Base: String using Base: String
using Base: @kwdef
using LaTeXStrings: length using LaTeXStrings: length
using OrderedCollections using OrderedCollections, ProgressMeter
using juobs, BDIO, DelimitedFiles, ADerrors, LaTeXStrings, PyPlot, Statistics using juobs, BDIO, DelimitedFiles, ADerrors, LaTeXStrings, PyPlot, Statistics
#============= SET UP VARIABLES ===========# #============= SET UP VARIABLES ===========#
...@@ -23,10 +24,12 @@ plt.rc("text", usetex=false) # set to true once you install latex ...@@ -23,10 +24,12 @@ plt.rc("text", usetex=false) # set to true once you install latex
#================== PATHS ==================# #================== PATHS ==================#
# data by ale (carfull with the read_BDIO that you include) # data by ale (carfull with the read_BDIO that you include)
const path_bdio = "/Users/alessandroconigli/Lattice/data/bdio_charm" const path_bdio = "/Users/alessandroconigli/Lattice/data/bdio_charm/LAT22"
#const path_bdio = "/Users/alessandroconigli/Lattice/data/bdio_charm/from_gevp/tm_shifted/ale" #const path_bdio = "/Users/alessandroconigli/Lattice/data/bdio_charm/from_gevp/tm_shifted/ale"
const path_bdio_tm = joinpath(path_bdio, "tm_shifted") const path_bdio_tm = joinpath(path_bdio, "tm_shifted")
const path_bdio_md = joinpath(path_bdio, "md") # const path_bdio_md = joinpath(path_bdio, "md") # path to aux obs (md) comptued by me
const path_bdio_md = "/Users/alessandroconigli/Lattice/data/bdio_charm/AS_ligth_obs/" # path to delta m computed by AS
# data by javier (carful with the read_BDIO that you include. do not use the one in this folder) # data by javier (carful with the read_BDIO that you include. do not use the one in this folder)
# const path_bdio = "/Users/alessandroconigli/MyDrive/phd/analysis/charm_gevp_2022/analysis_with_javier_data/bdio" #PATH to BDIO folder # const path_bdio = "/Users/alessandroconigli/MyDrive/phd/analysis/charm_gevp_2022/analysis_with_javier_data/bdio" #PATH to BDIO folder
...@@ -63,12 +66,15 @@ end ...@@ -63,12 +66,15 @@ end
wpmm = Dict{String, Vector{Float64}}() wpmm = Dict{String, Vector{Float64}}()
wpmm["H101"] = [-1.0, 2.0, -1.0, -1.0] wpmm["H101"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["H102r002"] = [-1.0, 2.0, -1.0, -1.0] wpmm["H102r002"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["H400"] = [-1.0, 1.5, -1.0, -1.0] wpmm["H105r002"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["H400"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["N202"] = [-1.0, 2.0, -1.0, -1.0] wpmm["N202"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["N200"] = [-1.0, 2.0, -1.0, -1.0] wpmm["N200"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["N203"] = [-1.0, 2.0, -1.0, -1.0] wpmm["N203"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["N300"] = [-1.0, 1.5, -1.0, -1.0] wpmm["N300"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["J303"] = [-1.0, 2.0, -1.0, -1.0] wpmm["J303"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["D200"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["D200_corr"] = [1.0, -1.0, -1.0, -1.0]
# READ MASSES + DECAY CONSTANTS # READ MASSES + DECAY CONSTANTS
...@@ -94,6 +100,7 @@ phih = Vector{Dict{String, Vector{uwreal}}}(undef, Nens) ...@@ -94,6 +100,7 @@ phih = Vector{Dict{String, Vector{uwreal}}}(undef, Nens)
a28t0 = Vector{uwreal}(undef, Nens) a28t0 = Vector{uwreal}(undef, Nens)
phi2 = Vector{uwreal}(undef, Nens) phi2 = Vector{uwreal}(undef, Nens)
phi4 = Vector{uwreal}(undef, Nens) phi4 = Vector{uwreal}(undef, Nens)
fpik = Vector{uwreal}(undef, Nens)
for (k, ens) in enumerate(enslist) for (k, ens) in enumerate(enslist)
p = joinpath(path_bdio_tm, ens) p = joinpath(path_bdio_tm, ens)
...@@ -115,6 +122,8 @@ for (k, ens) in enumerate(enslist) ...@@ -115,6 +122,8 @@ for (k, ens) in enumerate(enslist)
fsh_v[k] = read_BDIO(p, "tm", "fsh_star") .* za.(ensinfo[k].beta) fsh_v[k] = read_BDIO(p, "tm", "fsh_star") .* za.(ensinfo[k].beta)
fhh_v[k] = read_BDIO(p, "tm", "fhh_star") .* za.(ensinfo[k].beta) fhh_v[k] = read_BDIO(p, "tm", "fhh_star") .* za.(ensinfo[k].beta)
#fpik[k] = read_BDIO(p, "tm", "fpik")[1]
phih_fa = (2 * mlh[k] + msh[k]) / 3 phih_fa = (2 * mlh[k] + msh[k]) / 3
phih_sfa = (3 * phih_fa + 6 * mlh_v[k] + 3 * msh_v[k]) / 12 phih_sfa = (3 * phih_fa + 6 * mlh_v[k] + 3 * msh_v[k]) / 12
phih_eta = mhh[k] phih_eta = mhh[k]
...@@ -127,8 +136,12 @@ for (k, ens) in enumerate(enslist) ...@@ -127,8 +136,12 @@ for (k, ens) in enumerate(enslist)
zp_aux = fill(ZP(ensinfo[k].beta), length(muh[k])) zp_aux = fill(ZP(ensinfo[k].beta), length(muh[k]))
muh[k] ./= zp_aux muh[k] ./= zp_aux
p = joinpath(path_bdio_md, ens) # p = joinpath(path_bdio_md, ens) # use this to read your t0 values
a28t0[k] = 1 / ( 8 * read_BDIO(p, "md", "t0_shifted")[1]) # a28t0[k] = 1 / ( 8 * read_BDIO(p, "md", "t0_shifted")[1]) # use this to read your t0 values
#rep = filter(x->occursin(ensinfo[k].id, x), readdir(path_bdio_md,join=true))[1] # use this to read AS t0 shifted
#a28t0[k] = 1 / ( 8 * read_BDIO(rep, "ll_obs", "t0")[1]) # use this to read AS t0 shifted
a28t0[k] = 1 / (8 * t0(ensinfo[k].beta))
phi2[k] = mll^2 phi2[k] = mll^2
phi4[k] = mls^2 + 0.5 * mll^2 phi4[k] = mls^2 + 0.5 * mll^2
end end
...@@ -170,15 +183,26 @@ s_match = ["fl_ave", "etac", "sp_fl_ave"] ...@@ -170,15 +183,26 @@ s_match = ["fl_ave", "etac", "sp_fl_ave"]
[uwerr.(obs[i]) for i in 1:length(obs)] [uwerr.(obs[i]) for i in 1:length(obs)]
ens_id = getindex.(ensembles.(obs[1]),2)
a28t0_tot = Vector{Vector{uwreal}}(undef, length(ensinfo)) a28t0_tot = Vector{Vector{uwreal}}(undef, length(ensinfo))
phi2_tot = Vector{Vector{uwreal}}(undef, length(ensinfo)) phi2_tot = Vector{Vector{uwreal}}(undef, length(ensinfo))
# old solution when a given obs was depending on a single ensemble.
# ens_id = getindex.(ensembles.(obs[1]),2)
# for (k, ens) in enumerate(ensinfo)
# idx = findall(x->x==ens.id, ens_id)
# a28t0_tot[k] = fill(a28t0[k], length(idx))
# phi2_tot[k] = fill(phi2[k], length(idx))
# end
# now with AS dm, each obs depends on each ensemble, therefore a different solution
# is needed for computing a28t0_tot and phi2_tot
# Nmh = [2, 3, 3, 3, 3, 3, 3, 3, 3, 3] # number of heavy masses for LAT22 ensemble
Nmh = [2, 2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3] # number of heavy masses with J500 and E300
for (k, ens) in enumerate(ensinfo) for (k, ens) in enumerate(ensinfo)
idx = findall(x->x==ens.id, ens_id) a28t0_tot[k] = fill(a28t0[k], Nmh[k])
a28t0_tot[k] = fill(a28t0[k], length(idx)) phi2_tot[k] = fill(phi2[k], Nmh[k])
phi2_tot[k] = fill(phi2[k], length(idx))
end end
x_fa = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_fa")...) ] x_fa = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_fa")...) ]
x_eta = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_eta")...) ] x_eta = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_eta")...) ]
x_sfa = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_sfa")...) ] x_sfa = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_sfa")...) ]
...@@ -199,41 +223,42 @@ end ...@@ -199,41 +223,42 @@ end
#============= FIT MESON MASSES =============# #============= FIT MESON MASSES =============#
@info("Fitting meson masses for charm quark matching") @info("Fitting meson masses for charm quark matching")
# mD # mD
fit_over_cat!(mass_cat[4], f, phi2_ph, n_param, weight_dof=2, correlated_fit=false, Mrat=uwreal(1.0), small_sample=true) fit_over_cat!(mass_cat[4], f, phi2_ph, n_param, weight_dof=2, correlated_fit=false, Mrat=uwreal(1.0), IC="TIC")
# mDs # mDs
fit_over_cat!(mass_cat[5], f, phi2_ph, n_param, weight_dof=2, correlated_fit=false, Mrat=uwreal(1.0), small_sample=true) fit_over_cat!(mass_cat[5], f, phi2_ph, n_param, weight_dof=2, correlated_fit=false, Mrat=uwreal(1.0), IC="TIC")
# mD_star # mD_star
fit_over_cat!(mass_cat[6], f, phi2_ph, n_param, weight_dof=2, correlated_fit=false, Mrat=uwreal(1.0), small_sample=true) fit_over_cat!(mass_cat[6], f, phi2_ph, n_param, weight_dof=2, correlated_fit=false, Mrat=uwreal(1.0), IC="TIC")
# mDs_star # mDs_star
fit_over_cat!(mass_cat[7], f, phi2_ph, n_param, weight_dof=2, correlated_fit=false, Mrat=uwreal(1.0), small_sample=true) fit_over_cat!(mass_cat[7], f, phi2_ph, n_param, weight_dof=2, correlated_fit=false, Mrat=uwreal(1.0), IC="TIC")
## ##
s = [L"$\sqrt{8t_0} Z^{tm}_M \mu_c$", L"$\sqrt{8t_0}M_{\eta^{(c)}_c}$", L"$\sqrt{8t_0}M_{J/\psi}$", s = [L"$\sqrt{8t_0} Z^{tm}_M \mu_c$", L"$\sqrt{8t_0}M_{\eta^{(c)}_c}$", L"$\sqrt{8t_0}M_{J/\psi}$",
L"$\sqrt{8t_0}M_D$", L"$\sqrt{8t_0}M_{D_s}$", L"$\sqrt{8t_0}M_{D^{*}}$", L"$\sqrt{8t_0}M_{D^{*}_s}$"] L"$\sqrt{8t_0}M_D$", L"$\sqrt{8t_0}M_{D_s}$", L"$\sqrt{8t_0}M_{D^{*}}$", L"$\sqrt{8t_0}M_{D^{*}_s}$"]
idx_cat = 4 # 4,5 idx_cat = 5 # 4,5
for i in 2:2 for i in 2:2
#plot_cat(mass_cat[idx_cat][i], s[idx_cat] , save=false) plot_cat(mass_cat[idx_cat][i], s[idx_cat] , Wlabel="TIC", save=false)
#plot_chi2_vs_exp(mass_cat[idx_cat][i], label_cutoff ) #, p=path_plot) plot_chi2_vs_exp(mass_cat[idx_cat][i], label_cutoff , p=nothing)
plot_chi_charm(mass_cat[idx_cat][i], vcat(f_aux...), s[idx_cat], phi2_ph, ensinfo, mrat=uwreal(1.0), p=path_plot) plot_chi_charm(mass_cat[idx_cat][i], vcat(f_aux...), s[idx_cat], phi2_ph, ensinfo, mrat=uwreal(1.0) , p=path_plot, n=10)
#plot_cl_charm(mass_cat[idx_cat][i], vcat(f_aux...), s[idx_cat], phi2_ph, ensinfo, mrat=uwreal(1.0))#, p=path_plot) #plot_cl_charm(mass_cat[idx_cat][i], vcat(f_aux...), s[idx_cat], phi2_ph, ensinfo, mrat=uwreal(1.0))#, p=path_plot)
end end
## ##
#============= FIT CHARM MASS ==============# #============= FIT CHARM MASS ==============#
@info("Fitting charm quark mass") @info("Fitting charm quark mass")
fit_over_cat!(mass_cat[1], f, phi2_ph, n_param, weight_dof=2, correlated_fit=false, Mrat=Mrat, small_sample=true ) fit_over_cat!(mass_cat[1], f, phi2_ph, n_param, weight_dof=2, correlated_fit=false, Mrat=uwreal(1.0), IC="TIC" )
## plot charm ## plot charm
for i in 1:3 for i in 2:2
plot_cat(mass_cat[1][i], L"$M_c^{\mathrm{RGI}}(N_f=3)\mathrm{MeV}$" , save=false) plot_cat(mass_cat[1][i], L"$M_c^{\mathrm{RGI}}(N_f=3)\mathrm{MeV}$" , Wlabel="TIC", save=false)
plot_chi2_vs_exp(mass_cat[1][i], label_cutoff)#, p=path_plot) plot_chi2_vs_exp(mass_cat[1][i], label_cutoff, p=path_plot)
plot_chi_charm(mass_cat[1][i], vcat(f_aux...), L"$\sqrt{8t_0}Z_M^{tm}\mu_c$", phi2_ph, ensinfo, mrat=Mrat, p=path_plot) plot_chi_charm(mass_cat[1][i], vcat(f_aux...), L"$\sqrt{8t_0}Z_M^{tm}\mu_c$", phi2_ph, ensinfo, mrat=uwreal(1.0), p=path_plot)
plot_cl_charm(mass_cat[1][i], vcat(f_aux...), L"$\sqrt{8t_0}Z_M^{tm}\mu_c$", phi2_ph, ensinfo, mrat=Mrat)#, p=path_plot) plot_cl_charm(mass_cat[1][i], vcat(f_aux...), L"$\sqrt{8t_0}Z_M^{tm}\mu_c$", phi2_ph, ensinfo, mrat=uwreal(1.0), p=path_plot)
end end
close("all") close("all")
## plot for multiple categories ## plot for multiple categories
plot_hist_tot([mass_cat[1][1], mass_cat[1][2]], L"$M^\mathrm{RGI}_c\,(N_f=3)\,(\mathrm{MeV})$" , p=path_plot) plot_hist_tot([mass_cat[1][1], mass_cat[1][2]], L"$\sqrt{8t_0}\mu_c^R$" , p=path_plot)
plot_all_cl_charm([mass_cat[1][2], mass_cat[1][1], mass_cat[1][3]], vcat(f_aux...),L"$\sqrt{8t_0}Z_M^{tm}\mu_c$", phi2_ph, ensinfo, mrat=Mrat, n=[0,0,1] )#, p=path_plot) plot_all_cl_charm([mass_cat[1][2], mass_cat[1][1]], vcat(f_aux...),L"$\sqrt{8t_0}\mu_c^R$", phi2_ph, ensinfo, mrat=uwreal(1.0) , n=[0,60], p=path_plot)
plot_cat_tot(mass_cat[1][1:2], L"$M^\mathrm{RGI}_c\,(N_f=3)\,(\mathrm{MeV})$" , save=true) plot_cat_tot(mass_cat[1][1:2], L"$\sqrt{8t_0}\mu_c^R$" , Wlabel="TIC", save=false)
## ##
#============== CREATE DECAY CAT =============# #============== CREATE DECAY CAT =============#
...@@ -247,17 +272,25 @@ match = [x_fa, x_eta, x_sfa] ...@@ -247,17 +272,25 @@ match = [x_fa, x_eta, x_sfa]
## for correlated fits the order must be different: ens11..ens13, ens21...ens23,...,ensN1..ensN3 ## for correlated fits the order must be different: ens11..ens13, ens21...ens23,...,ensN1..ensN3
obs = [vcat(flh...), vcat(fsh...), vcat(fhh...)] obs = [vcat(flh...), vcat(fsh...), vcat(fhh...)]
[uwerr.(obs[i]) for i in 1:length(obs)] # this commented section is actually the same as what you did for mass categories. therefore it is not needed
# [uwerr.(obs[i]) for i in 1:length(obs)]
# preparing xdata for fitting in correct order # preparing xdata for fitting in correct order
ens_id = getindex.(ensembles.(obs[1]),2) # ens_id = getindex.(ensembles.(obs[1]),2)
a28t0_tot = Vector{Vector{uwreal}}(undef, length(ensinfo)) # tmp_ens_idx = findall(x->x=="H105", ens_id)
phi2_tot = Vector{Vector{uwreal}}(undef, length(ensinfo)) # ens_id[tmp_ens_idx] .*="r002"
for (k, ens) in enumerate(ensinfo)
idx = findall(x->x==ens.id, ens_id) # a28t0_tot = Vector{Vector{uwreal}}(undef, length(ensinfo))
a28t0_tot[k] = fill(a28t0[k], length(idx)) # phi2_tot = Vector{Vector{uwreal}}(undef, length(ensinfo))
phi2_tot[k] = fill(phi2[k], length(idx)) # for (k, ens) in enumerate(ensinfo)
end # if ens.id == "D200"
# idx = findall(x->x=="D200_corr", ens_id)
# else
# idx = findall(x->x==ens.id, ens_id)
# end
# a28t0_tot[k] = fill(a28t0[k], length(idx))
# phi2_tot[k] = fill(phi2[k], length(idx))
# end
x_fa = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_fa")...) ] x_fa = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_fa")...) ]
x_eta = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_eta")...) ] x_eta = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_eta")...) ]
x_sfa = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_sfa")...) ] x_sfa = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_sfa")...) ]
...@@ -274,86 +307,8 @@ for (i, o) in enumerate(obs) ...@@ -274,86 +307,8 @@ for (i, o) in enumerate(obs)
push!(f_cat, aux) push!(f_cat, aux)
end end
##########################
## TEST ON fD/fDs
#f_ratio_cat = Vector{Cat}(undef, 0)
#for (j,m) in enumerate(match)
# push!(f_ratio_cat, Cat(obs[2]./obs[1], m, phih_ph[j], string("fds_over_fd", "_", s_match[j]) ))
#end
obs_ratio = obs[2]./obs[1]
idx_no_sym = findall(x->x!=1.0, value.(obs_ratio))
obs_ratio = obs_ratio[idx_no_sym]
#obs_ratio[1:3] .+= 0.015
xratio = x_fa[idx_no_sym, 1:3]
f_ratio_cat = Cat(obs_ratio, xratio, phih_ph[1], string("fds_over_fd") )
ratio_model(x,p) = 1 .+ p[1].*(3. .*phi2_sym .- 3. .* x[:,2]) .+ p[2].*x[:,1]
ratio_model_aux = (x,p) -> 1. + p[1]*(3. *phi2_sym - 3. * x[:,2]) + p[2]*x[:,1]
par, chi_vs_chi2exp = fit_routine(ratio_model, value.(f_ratio_cat.x_tofit), f_ratio_cat.obs, 2)
xx = [0.0 phi2_ph]
ress = ratio_model_aux(xx, par)[1]
push!(f_ratio_cat.fit_res, ress )
push!(f_ratio_cat.fit_param, par)
## plot ratio
idx_ens_nosim = findall( x-> x==false, getfield.(ensinfo, :deg))
obs_ratio .+= 0.01
plot_chi_fds_ratio(f_ratio_cat, ratio_model_aux, L"$f_{D_s}/f_D$", phi2_ph, ensinfo[idx_ens_nosim], p=path_plot)
##
function plot_chi_fds_ratio(c::Cat, ff::Function, ylab::LaTeXString, phi2_ph::uwreal, ensinfo::Vector{EnsInfo}; p::Union{String, Nothing}=nothing )
color = ["orange", "darkgreen", "magenta", "navy"]
fmt = ["^", "v", "<", ">"]
a_sp = [0.087, 0.077, 0.065, 0.05]
phi2_max = phi2_sym#maximum(value.(phi2))
upar = getfield(c, :fit_param)[1]
phih_2_use = value(c.phih_ph)
res = getfield(c, :fit_res)[1]
xx = [fill(1e-8, 100) Float64.(range(0.01, phi2_max, length=100)) ]
yy = ff(xx, upar)
#Project one value of muc_i (i=1,2,3)
n_unique = unique(i-> c.x_tofit[i,2], 1:length(c.x_tofit[:,2]))
p2 = c.x_tofit[n_unique, 2]
a2 = c.x_tofit[n_unique, 1]
pc = c.x_tofit[n_unique, 3]
x = [a2 p2 pc]
x2 = [a2 p2 fill(phih_2_use, length(p2))] #physical value phih
y = ( c.obs[n_unique] - ff(x, upar) + ff(x2, upar)) #Projection
uwerr.(yy)
uwerr(res)
uwerr.(y)
#Plotting
figure(figsize=(10,6))
plot(phi2_sym, 1., marker="X", ms=10, color="black", label= L"$M_\pi=M_K$")
fill_between(xx[:,2], value.(yy)+ err.(yy), value.(yy)-err.(yy), alpha=0.3, color="royalblue") #CL extrapolation (band)
errorbar(value(phi2_ph), value(res), err(res), fmt="s", color="red", label=L"$\phi_2 = \phi^\mathrm{phys}_2$", capsize=5, ms=12)#CL extrapolation
for (k,b) in enumerate(sort(unique(getfield.(ensinfo, :beta))))
n_ = findall(x->x.beta == b, ensinfo)
a2_aux = mean(value.(a2[n_]))
errorbar(value.(x[n_,2]), value.(y[n_]), err.(y[n_]), fmt=fmt[k], label=string(L"$a \approx$", a_sp[k], " fm"), color=color[k], capsize=5, ms=12, mfc="none")#projected datapoints
#dashed lines
#xxx = [fill(a2_aux, 100) Float64.(range(0.0, phi2_max, length=100)) fill(value(c.phih_ph), 100)]
#yyy = ff(xxx, upar)
#plot(xxx[:,2], value.(yyy), ls="--", color=color[k])#dashed lines
end
ylabel(ylab, size=22)
xlabel(L"$\phi_2$", size=22)
legend(ncol=2, fontsize=16)
#ylim(3.02, 3.18)
tight_layout()
grid(ls="dashed")
if !isnothing(p)
t = "fit_fds_ratio_" * c.info * ".pdf"
savefig(joinpath(p, t))
close()
else
display(gcf())
close("all")
end
end
## ##
#=========== FIT DECAY CONSTANT ==============# #=========== FIT DECAY CONSTANT ==============#
...@@ -368,7 +323,7 @@ for i = 1:3 ...@@ -368,7 +323,7 @@ for i = 1:3
println(" j is :", j, " k is equal: ", k) println(" j is :", j, " k is equal: ", k)
par, chi_vs_chi2exp = fit_routine([f_f_lin1[j][k], f_f_lin2[j][k]], [value.(f1.x_tofit), value.(f2.x_tofit)], par, chi_vs_chi2exp = fit_routine([f_f_lin1[j][k], f_f_lin2[j][k]], [value.(f1.x_tofit), value.(f2.x_tofit)],
[f1.obs, f2.obs], f_n_param_comb[j], correlated_fit=false) [f1.obs, f2.obs], f_n_param_comb[j], correlated_fit=false, wpm=wpmm)
#aux1 = par[1] + par[2] * phi2_ph + par[3] / sqrt(f1.phih_ph) #aux1 = par[1] + par[2] * phi2_ph + par[3] / sqrt(f1.phih_ph)
...@@ -407,8 +362,8 @@ for i = 1:3 ...@@ -407,8 +362,8 @@ for i = 1:3
for j = 1:length(f_f_lin1_clog) for j = 1:length(f_f_lin1_clog)
for k = 1:length(f_f_lin1_clog[j]) for k = 1:length(f_f_lin1_clog[j])
println(" j is :", j, " k is equal: ", k) println(" j is :", j, " k is equal: ", k)
par, chi2_vs_chi2exp = fit_routine([f_f_lin1_clog[j][k], f_f_lin2_clog[j][k]], [value.(f1.x_tofit), value.(f2.x_tofit)], par, chi2, chi2exp = fit_routine([f_f_lin1_clog[j][k], f_f_lin2_clog[j][k]], [value.(f1.x_tofit), value.(f2.x_tofit)],
[f1.obs, f2.obs], f_n_param_comb_clog[j], correlated_fit=false) [f1.obs, f2.obs], f_n_param_comb_clog[j], correlated_fit=false, wpm=wpmm)
x = [0.0 phi2_ph f1.phih_ph] x = [0.0 phi2_ph f1.phih_ph]
...@@ -420,15 +375,15 @@ for i = 1:3 ...@@ -420,15 +375,15 @@ for i = 1:3
push!(f2.fit_res, aux2) push!(f2.fit_res, aux2)
push!(f1.fit_param, par) push!(f1.fit_param, par)
push!(f2.fit_param, par) push!(f2.fit_param, par)
push!(f1.chi2_vs_exp, chi2_vs_chi2exp) push!(f1.chi2_vs_exp, chi2/chi2exp)
push!(f2.chi2_vs_exp, chi2_vs_chi2exp) push!(f2.chi2_vs_exp, chi2/chi2exp)
push!(f1.n_param, f_n_param_comb_clog[j]) push!(f1.n_param, f_n_param_comb_clog[j])
push!(f2.n_param, f_n_param_comb_clog[j]) push!(f2.n_param, f_n_param_comb_clog[j])
push!(f1.dof, doff) push!(f1.dof, doff)
push!(f2.dof, doff) push!(f2.dof, doff)
# use first 2 lines for uncorrelated fits # use first 2 lines for uncorrelated fits
push!(f1.aic, chi2_vs_chi2exp * doff + 2 * f_n_param_comb_clog[j]) push!(f1.aic, chi2/chi2exp * doff + 2 * f_n_param_comb_clog[j])
push!(f2.aic, chi2_vs_chi2exp * doff + 2 * f_n_param_comb_clog[j]) push!(f2.aic, chi2/chi2exp * doff + 2 * f_n_param_comb_clog[j])
# push!(f2.aic, chi2_vs_chi2exp - 2 * doff) # push!(f2.aic, chi2_vs_chi2exp - 2 * doff)
# push!(f1.aic, chi2_vs_chi2exp - 2 * doff) # push!(f1.aic, chi2_vs_chi2exp - 2 * doff)
...@@ -450,23 +405,137 @@ ffDs = vcat(f_f_aux2_clog...) ...@@ -450,23 +405,137 @@ ffDs = vcat(f_f_aux2_clog...)
# ffDs = vcat([vcat(f_f_aux2...), vcat(f_f_aux2_clog...)]...) # lin+log # ffDs = vcat([vcat(f_f_aux2...), vcat(f_f_aux2_clog...)]...) # lin+log
s = [L"$\sqrt{8t_0}f_D$", L"$\sqrt{8t_0}f_{D_s}$", L"$\sqrt{8t_0}f_{\eta^{(c)}_c}$"] s = [L"$\sqrt{8t_0}f_D$", L"$\sqrt{8t_0}f_{D_s}$", L"$\sqrt{8t_0}f_{\eta^{(c)}_c}$"]
for i=1:3 for i=2:2
plot_cl_charm( f_cat[1][i], ffD, s[1], phi2_ph, ensinfo, dec=true)#, p=path_plot) plot_cl_charm( f_cat[1][i], ffD, s[1], phi2_ph, ensinfo, dec=true, p=path_plot)
plot_cl_charm( f_cat[2][i], ffDs, s[2], phi2_ph, ensinfo, dec=true)#, p=path_plot) plot_cl_charm( f_cat[2][i], ffDs, s[2], phi2_ph, ensinfo, dec=true, p=path_plot)
plot_chi_charm(f_cat[1][i], ffD, s[1], phi2_ph, ensinfo, dec=true)#, p=path_plot) plot_chi_charm(f_cat[1][i], ffD, s[1], phi2_ph, ensinfo, dec=true, p=path_plot)
plot_chi_charm(f_cat[2][i], ffDs, s[2], phi2_ph, ensinfo, dec=true)#, p=path_plot) plot_chi_charm(f_cat[2][i], ffDs, s[2], phi2_ph, ensinfo, dec=true, p=path_plot)
plot_cat(f_cat[1][i], s[1] , save=false) plot_cat(f_cat[1][i], s[1] , save=false)
plot_cat(f_cat[2][i], s[2] , save=false) plot_cat(f_cat[2][i], s[2] , save=false)
#plot_chi2_vs_exp(f_cat[1][i], label_cutoff)# , p=path_plot) # plot_chi2_vs_exp(f_cat[1][i], label_cutoff)#, p=path_plot)
#plot_chi2_vs_exp(f_cat[2][i], label_cutoff)#, p=path_plot) # plot_chi2_vs_exp(f_cat[2][i], label_cutoff)#, p=path_plot)
# plot_chi2_vs_exp_clog(f_cat[1][i], label_cutoff , p=path_plot) # plot_chi2_vs_exp_clog(f_cat[1][i], label_cutoff , p=path_plot)
# plot_chi2_vs_exp_clog(f_cat[2][i], label_cutoff , p=path_plot) # plot_chi2_vs_exp_clog(f_cat[2][i], label_cutoff , p=path_plot)
end end
close("all") close("all")
## ##
plot_cl_charm(f_cat[1][1], vcat(f_f_aux1...),L"$\sqrt{8t_0}Z_M^{tm}\mu_c$", phi2_ph, ensinfo, dec=true, n=1 ) # 35 nice plot_cl_charm(f_cat[2][1], ffD,L"$\sqrt{8t_0}Z_M^{tm}\mu_c$", phi2_ph, ensinfo, dec=true, n=1 ) # 35 nice
plot_chi_charm(f_cat[1][2], vcat(f_f_aux1...), L"$\sqrt{8t_0}Z_M^{tm}\mu_c$", phi2_ph, ensinfo, dec=true, n=1) #, p=path_plot) plot_chi_charm(f_cat[2][2], ffD, L"$\sqrt{8t_0}Z_M^{tm}\mu_c$", phi2_ph, ensinfo, dec=true, n=1) #, p=path_plot)
########################## SECOND TESTS RATIO - HQET-TAYLOR 2023
## Second tests on ratio FDs/FD with Gregorio's formulation
## creating categories
obs_ratio = (vcat(fsh...) .* sqrt.(vcat(msh...)) ) ./ (vcat(flh...) .* sqrt.(vcat(mlh...)) )
idx_no_sym = findall(x->x!=1.0, value.(obs_ratio))
obs_ratio = obs_ratio[idx_no_sym]
f_ratio_cat = Vector{Cat}(undef, 0)
x_fa = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_fa")...) ]
x_eta = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_eta")...) ]
x_sfa = [vcat(a28t0_tot...) vcat(phi2_tot...) vcat(getindex.(phih, "phih_sfa")...) ]
# this extra lines are requires to add extra x dependence (fpik) in fds ratio
match = [x_fa, x_eta, x_sfa]
# Nmh = [2, 3, 3, 3, 3, 3, 3, 3, 3, 3] # number of heavy masses for LAT22 ensemble
Nmh = [2, 2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3] # number of heavy masses with J500 and E300
fpik_tot = Vector{Vector{uwreal}}(undef, length(ensinfo))
fpik_phys = uwreal([0.3091,0.0019], "fpik_phys")
for (j, m) in enumerate(match)
xx = m[idx_no_sym,1:3]
xx = hcat(xx, fill(phih_ph[j], length(xx[:,1])))
xx = hcat(xx, fill(fpik_phys^2, sum(Nmh))[idx_no_sym] )
push!(f_ratio_cat, Cat(obs_ratio, xx, phih_ph[j],string("fds_over_fd_", s_match[j])))
end
# linear cutoff
# r_model(x,p) = 1. .+ p[1].*(3. .*phi2_sym .- 3. .* x[:,2]) .+ p[2].*(3. .*phi2_sym .- 3. .* x[:,2]).*( 1. ./ x[:,3] .- 1. ./ x[:,4]) .+ p[3].*(3. .*phi2_sym .- 3. .* x[:,2]).*x[:,1]
# r_model_aux = (x,p) -> 1. .+ p[1]*(3. *phi2_sym - 3. * x[:,2]) #+ p[2]*(3. *phi2_sym - 3. * x[:,2])*( 1. /x[:,3] - 1. /x[:,4]) + p[3]*(3. *phi2_sym - 3. * x[:,2])*x[:,1]
# non-linear cutoff
# r_model(x,p) = (1. .+ p[1].*(3. .*phi2_sym .- 3. .* x[:,2]) .+ p[2].*(3. .*phi2_sym .- 3. .* x[:,2]).*( 1. ./ x[:,3] .- 1. ./ x[:,4]) ) .* ( 1. .+ p[3].*(3. .*phi2_sym .- 3. .* x[:,2]).*x[:,1])
# r_model_aux = (x,p) -> 1. .+ p[1]*(3. *phi2_sym - 3. * x[:,2]) #+ p[2]*(3. *phi2_sym - 3. * x[:,2])*( 1. /x[:,3] - 1. /x[:,4]) + p[3]*(3. *phi2_sym - 3. * x[:,2])*x[:,1]
# obs_ratio[3:4] .-= 0.025
## TEST TOT MODELS
for (k,cat) in enumerate(f_ratio_cat)
for (i,f_r) in enumerate(r_tot_models)
par, chi2, chi2exp = juobs.fit_routine(f_r, value.(f_ratio_cat[k].x_tofit), f_ratio_cat[k].obs, r_tot_param[i])
uwerr.(par)
println(par)
#fpik_phys = ((2/3) * (155.7 + 0.5*130.2) * t0_ph / hc) ^2
xx = [0.0 phi2_ph phih_ph[k] phih_ph[k] fpik_phys^2]
# xx = [0.0 phi2_ph phih_ph[k] phih_ph[k] ]
res = f_r(xx, par)[1]
uwerr(res)
println(res)
symb = [:fit_res, :fit_param, :chi2_vs_exp, :n_param, :aic]
tmp = [res, par, chi2 / chi2exp, r_tot_param[i], chi2 - 2*chi2exp]
for (j,ss) in enumerate(symb)
push!(getfield(cat, ss), tmp[j] )
end
end
end
plot_cat_tot(f_ratio_cat, L"$\Phi_{D_s}/\Phi_D$", xlabel=r_tot_labels, save=true)
best, syst = category_av_tot(f_ratio_cat) .* sqrt(M[1]/M[3]) ; uwerr(best);
println( best, " ", value(syst))
##
idx_ens_nosim = findall( x-> x==false, getfield.(ensinfo, :deg))
plot_chi_fds_ratio(f_ratio_cat[2], r_tot_models, L"$\Phi_{D_s}/\Phi_D$", phi2_ph, ensinfo[idx_ens_nosim], p=path_plot)
xx = [0.0 phi2_ph phih_ph[1] phih_ph[1]]
res = r_hqet_models[1](xx,par)[1] ; uwerr(res)
bb = r_model_aux(value.(xx), par)
aa = r_model(xx, par)
## print in external file the fit parameters
using DelimitedFiles
open("/Users/alessandroconigli/Desktop/test_ratio_flave_raw.txt", "w") do io
totval = Vector{Vector{String}}(undef, length(f_ratio_cat[1].fit_param))
for k in eachindex(f_ratio_cat[1].fit_param)
vv = string.(round.(value.(f_ratio_cat[1].fit_param[k]), digits=4))
ee = string.(round.(err.(f_ratio_cat[1].fit_param[k]), digits=4))
totval[k] = vv .* " ± " .* ee
end
writedlm(io, totval)
end
########################## FIRST TESTS RATIO - LATTICE 2022
## TEST ON fD/fDs
#f_ratio_cat = Vector{Cat}(undef, 0)
#for (j,m) in enumerate(match)
# push!(f_ratio_cat, Cat(obs[2]./obs[1], m, phih_ph[j], string("fds_over_fd", "_", s_match[j]) ))
#end
obs_ratio = obs[2]./obs[1]
idx_no_sym = findall(x->x!=1.0, value.(obs_ratio))
obs_ratio = obs_ratio[idx_no_sym]
#obs_ratio[1:3] .+= 0.015
xratio = x_fa[idx_no_sym, 1:3]
f_ratio_cat = Cat(obs_ratio, xratio, phih_ph[1], string("fds_over_fd") )
ratio_model(x,p) = 1 .+ p[1].*(3. .*phi2_sym .- 3. .* x[:,2]) .+ p[2].*x[:,1]
ratio_model_aux = (x,p) -> 1. + p[1]*(3. *phi2_sym - 3. * x[:,2]) + p[2]*x[:,1]
par, chi_vs_chi2exp = fit_routine(ratio_model, value.(f_ratio_cat.x_tofit), f_ratio_cat.obs, 2)
xx = [0.0 phi2_ph]
ress = ratio_model_aux(xx, par)[1]
push!(f_ratio_cat.fit_res, ress )
push!(f_ratio_cat.fit_param, par)
## plot ratio
idx_ens_nosim = findall( x-> x==false, getfield.(ensinfo, :deg))
#obs_ratio .+= 0.01
plot_chi_fds_ratio(f_ratio_cat, ratio_model_aux, L"$f_{D_s}/f_D$", phi2_ph, ensinfo[idx_ens_nosim], p=path_plot)
##
############# #############
## RESULTS ## ## RESULTS ##
...@@ -487,14 +556,15 @@ wpmm2["J303"] = [-1.0, 2.0, -1.0, -1.0] ...@@ -487,14 +556,15 @@ wpmm2["J303"] = [-1.0, 2.0, -1.0, -1.0]
# category av fl_ave + etac # category av fl_ave + etac
for (k, c) in enumerate([mass_cat[1]]) for (k, c) in enumerate([mass_cat[1]])
o, sys = category_av_tot([c[1],c[2]]) o, sys = category_av_tot([c[1],c[2]])
o_p = o * hc / t0_ph o_p = o * hc / t0_ph * Mrat
sys_p = sys * hc / value(t0_ph) sys_p = sys * hc / value(t0_ph) * Mrat
uwerr(o, wpmm2) uwerr(o, wpmm2)
uwerr(o_p, wpmm2) uwerr(o_p, wpmm2)
println(s_obs_mass[k], "\t $o +/- $sys") println(s_obs_mass[k], "\t $o +/- $sys")
println(s_obs_mass[k], "\t $o_p +- $sys_p") println(s_obs_mass[k], "\t $o_p +- $sys_p")
println(s_obs_mass[k], details(o_p)) println(s_obs_mass[k], details(o_p))
end end
##
# fl-av / sp-fl-av / etac # fl-av / sp-fl-av / etac
for i = 1:3 for i = 1:3
for (k, c) in enumerate([mass_cat[1]]) for (k, c) in enumerate([mass_cat[1]])
...@@ -511,8 +581,8 @@ end ...@@ -511,8 +581,8 @@ end
#============ DECAY CONSTANTS ==============# #============ DECAY CONSTANTS ==============#
for (k, c) in enumerate(f_cat[1:2]) for (k, c) in enumerate(f_cat[1:2])
o, sys = category_av_tot([c[1], c[2]]) o, sys = category_av_tot([c[1], c[2]])
o_p = o * hc / value(t0_ph) o_p = o * hc / t0_ph #value(t0_ph)
sys_p = sys * hc / value(t0_ph) sys_p = sys * hc / t0_ph #value(t0_ph)
uwerr(o, wpmm2) uwerr(o, wpmm2)
uwerr(o_p, wpmm2) uwerr(o_p, wpmm2)
#uwerr(o) #uwerr(o)
...@@ -520,7 +590,7 @@ for (k, c) in enumerate(f_cat[1:2]) ...@@ -520,7 +590,7 @@ for (k, c) in enumerate(f_cat[1:2])
println(s_obs_f[k], "\t$o +/- $sys") println(s_obs_f[k], "\t$o +/- $sys")
println(s_obs_f[k], "\t $o_p +- $sys_p") println(s_obs_f[k], "\t $o_p +- $sys_p")
println(s_obs_f[k], details(o_p)) println(s_obs_f[k], details(o_p))
push!(store, o_p) #push!(store, o_p)
end end
# fl-av / sp-fl-av / etac # fl-av / sp-fl-av / etac
......
# WORKING PLOTS # WORKING PLOTS
# plot category average # plot category average
function plot_cat(cat::Cat, ylab::LaTeXString ; cut::Float64=2.5, save::Bool=false) function plot_cat(cat::Cat, ylab::LaTeXString ; Wlabel::String="TIC", cut::Float64=2.5, save::Bool=false)
aic = getfield(cat, :aic) aic = getfield(cat, :aic)
best = aic_model_ave(cat) * hc /t0_ph best = aic_model_ave(cat) #* hc /t0_ph
syst = aic_syst(cat) * hc /t0_ph println(best)
weigths, _ = aic_weight(cat) syst = aic_syst(cat) #* hc /t0_ph
all_res_aux = getfield(cat, :fit_res) .* hc weigths, idx = aic_weight(cat)
all_res = [all_res_aux[i] /t0_ph for i =1:length(all_res_aux)] all_res_aux = getfield(cat, :fit_res) #.* hc
all_res = all_res_aux[idx] # [all_res_aux[i] /t0_ph for i =1:length(all_res_aux)]
uwerr.(all_res) uwerr.(all_res)
uwerr(best) uwerr(best)
uwerr(syst) # uwerr(syst)
ratio_w = weigths #aic ./ minimum(aic) ratio_w = weigths #aic ./ minimum(aic)
fig = figure(figsize=(10,5)) fig = figure(figsize=(10,5))
...@@ -27,7 +28,7 @@ function plot_cat(cat::Cat, ylab::LaTeXString ; cut::Float64=2.5, save::Bool=fal ...@@ -27,7 +28,7 @@ function plot_cat(cat::Cat, ylab::LaTeXString ; cut::Float64=2.5, save::Bool=fal
ylabel(ylab, size=20) ylabel(ylab, size=20)
cb = colorbar(sc) cb = colorbar(sc)
#cb[:set_label](string("AIC", L"$(M_i)/$", "min(AIC)")) #cb[:set_label](string("AIC", L"$(M_i)/$", "min(AIC)"))
cb[:set_label]( "AIC weights") cb[:set_label]( string(Wlabel, " weights"))
legend() legend()
#ylim(0.46,0.58) #ylim(0.46,0.58)
display(fig) display(fig)
...@@ -36,43 +37,42 @@ function plot_cat(cat::Cat, ylab::LaTeXString ; cut::Float64=2.5, save::Bool=fal ...@@ -36,43 +37,42 @@ function plot_cat(cat::Cat, ylab::LaTeXString ; cut::Float64=2.5, save::Bool=fal
savefig(joinpath(path_plot,t)) savefig(joinpath(path_plot,t))
end end
end end
function plot_cat_tot(cat::Vector{Cat}, ylab::LaTeXString ; cut::Float64=2.5, save::Bool=false) function plot_cat_tot(cat::Vector{Cat}, ylab::LaTeXString ; xlabel::Union{Nothing,Vector{Vector{String}}}=nothing, Wlabel::String="TIC", cut::Float64=2.5, save::Bool=false)
best, syst = category_av_tot(cat) best, syst = category_av_tot(cat)
println(best) weigths, idx = aic_weight(vcat(getfield.(cat, :aic)...))
best *=hc/t0_ph all_res_aux = vcat(getfield.(cat, :fit_res)...) #.* hc
best -= 2. all_res = all_res_aux[idx] #[all_res_aux[i] /t0_ph for i =1:length(all_res_aux)]
syst *=hc/t0_ph
println(syst)
weigths = aic_weight.(cat)
weigths = vcat(weigths[1][1], weigths[2][1])
all_res_aux = vcat(getfield.(cat, :fit_res) .* hc...)
all_res = [all_res_aux[i] /t0_ph for i =1:length(all_res_aux)]
all_res .-=2.
uwerr.(all_res) uwerr.(all_res)
uwerr(best) uwerr(best)
uwerr(syst) # uwerr(syst)
ratio_w = weigths #aic ./ minimum(aic) ratio_w = weigths #aic ./ minimum(aic)
fig = figure(figsize=(10,5)) fig = figure(figsize=(10,5))
cm = get_cmap("YlGn") # cm = get_cmap("YlGn")
#cm = get_cmap("autumn") cm = get_cmap("Purples")
fill_between(collect(1:length(all_res)), value(best-syst), value(best+syst), alpha=0.5, color="royalblue", label="Systematics") fill_between(collect(1:length(all_res)), value(best-syst), value(best+syst), alpha=0.3, color="orange", label="Systematics")
sc = scatter(collect(1:length(all_res)), value.(all_res), edgecolors="black",c= ratio_w, cmap=cm, vmin=minimum(ratio_w), vmax=maximum(ratio_w) , zorder=3) sc = scatter(collect(1:length(all_res)), value.(all_res), edgecolors="black",c= ratio_w, cmap=cm, s=70, vmin=minimum(ratio_w), vmax=maximum(ratio_w) , zorder=3)
#sc = scatter(collect(1:length(all_res)), value.(all_res), edgecolors="black" , zorder=3) #sc = scatter(collect(1:length(all_res)), value.(all_res), edgecolors="black" , zorder=3)
errorbar(collect(1:length(all_res)), value.(all_res), yerr=err.(all_res), fmt="none",zorder=0, capsize=2,marker="s", lw=0.8, mec="black", ecolor="black") errorbar(collect(1:length(all_res)), value.(all_res), yerr=err.(all_res), fmt="none",zorder=0, capsize=2,marker="s", lw=0.8, mec="black", ecolor="black")
errorbar(-2, value(best), yerr=err(best), fmt="s",mfc="navy",ms=8, mec="navy",ecolor="navy", capsize=2, zorder=0, label="Model average") errorbar(-2, value(best), yerr=err(best), fmt="s",mfc="maroon",ms=10, mec="maroon",ecolor="maroon", capsize=2, zorder=0, label="Model average")
xlabel("Models", size=20) # xlabel("Models", size=18)
ylabel(ylab, size=20) ylabel(ylab, size=20)
axvline(64, ls="--", color="red") # axvline(64, ls="--", color="red")
if !(isnothing(xlabel))
lbl = vcat(fill(xlabel, length(cat))...)
xx = collect(1:length(lbl))
println(idx)
xticks(xx, lbl, rotation=75, size=9)
end
cb = colorbar(sc) cb = colorbar(sc)
#cb[:set_label](string("AIC", L"$(M_i)/$", "min(AIC)")) cb[:set_label]( L"$w$")
cb[:set_label]( "IC weights") # cb[:set_label]( string(Wlabel," weights"))
legend() legend()
#ylim(0.46,0.58) #ylim(0.46,0.58)
display(fig) display(fig)
if save if save
t = string("cat_ave_tot", ".pdf") t = string("cat_ave_tot",cat[1].info, ".pdf")
savefig(joinpath(path_plot,t)) savefig(joinpath(path_plot,t))
end end
end end
...@@ -82,9 +82,9 @@ function plot_cl_charm(c::Cat, ff::Vector{Function}, ylab::LaTeXString, phi2_ph: ...@@ -82,9 +82,9 @@ function plot_cl_charm(c::Cat, ff::Vector{Function}, ylab::LaTeXString, phi2_ph:
#Format #Format
a2_max = 0.05 a2_max = 0.05
color = ["orange", "darkgreen", "magenta", "navy"] color = ["orange", "darkgreen", "magenta", "navy", "royalblue"]
fmt = ["^", "v", "<", ">"] fmt = ["^", "v", "<", ">", "d"]
a_sp = [0.087, 0.077, 0.065, 0.05] a_sp = [0.087, 0.077, 0.065, 0.05, 0.039]
#Choose model #Choose model
if isnothing(n) #n is nothing -> model with lowest AIC if isnothing(n) #n is nothing -> model with lowest AIC
...@@ -169,7 +169,7 @@ function plot_all_cl_charm(cvec::Vector{Cat}, ff::Vector{Function}, ylab::LaTeXS ...@@ -169,7 +169,7 @@ function plot_all_cl_charm(cvec::Vector{Cat}, ff::Vector{Function}, ylab::LaTeXS
figure(figsize=(10,6)) figure(figsize=(10,6))
for (idx,c) in enumerate(cvec) for (idx,c) in enumerate(cvec)
#Choose model #Choose model
if n[idx] == 0 #n is nothing -> model with lowest AIC if n[idx] == 0 # model with lowest AIC
aic, n_best = findmin(getfield(c, :aic)) aic, n_best = findmin(getfield(c, :aic))
else else
n_best = n[idx] n_best = n[idx]
...@@ -243,9 +243,9 @@ function plot_chi_charm(c::Cat, ff::Vector{Function}, ylab::LaTeXString, phi2_ph ...@@ -243,9 +243,9 @@ function plot_chi_charm(c::Cat, ff::Vector{Function}, ylab::LaTeXString, phi2_ph
#Format #Format
phi2_max = maximum(value.(phi2)) phi2_max = maximum(value.(phi2))
color = ["orange", "darkgreen", "magenta", "navy"] color = ["orange", "darkgreen", "magenta", "navy", "royalblue"]
fmt = ["^", "v", "<", ">"] fmt = ["^", "v", "<", ">", "d"]
a_sp = [0.087, 0.077, 0.065, 0.05] a_sp = [0.087, 0.077, 0.065, 0.05, 0.039]
#Choose model #Choose model
if isnothing(n) #n is nothing -> model with lowest AIC if isnothing(n) #n is nothing -> model with lowest AIC
...@@ -256,7 +256,7 @@ function plot_chi_charm(c::Cat, ff::Vector{Function}, ylab::LaTeXString, phi2_ph ...@@ -256,7 +256,7 @@ function plot_chi_charm(c::Cat, ff::Vector{Function}, ylab::LaTeXString, phi2_ph
end end
#Model info #Model info
@info("error in t0_ph not included") @info("error in t0_ph not included")
phih_2_use = c.phih_ph #value(c.phih_ph) phih_2_use = c.phih_ph
par_n = getfield(c, :n_param)[n] par_n = getfield(c, :n_param)[n]
upar = getfield(c, :fit_param)[n] upar = getfield(c, :fit_param)[n]
if !dec if !dec
...@@ -306,13 +306,13 @@ function plot_chi_charm(c::Cat, ff::Vector{Function}, ylab::LaTeXString, phi2_ph ...@@ -306,13 +306,13 @@ function plot_chi_charm(c::Cat, ff::Vector{Function}, ylab::LaTeXString, phi2_ph
plot(xxx[:,2], value.(yyy), ls="--", color=color[k])#dashed lines plot(xxx[:,2], value.(yyy), ls="--", color=color[k])#dashed lines
end end
# fill between physical values # fill between physical values
am = M[1] * t0_ph / hc am = M[3] * t0_ph / hc
uwerr(am) uwerr(am)
fill_between(xx[:,2], value(am)+err(am), value(am)-err(am), color="forestgreen", alpha=0.2, zorder=1, label="PDG") #fill_between(xx[:,2], value(am)+err(am), value(am)-err(am), color="forestgreen", alpha=0.2, zorder=1, label="PDG")
ylabel(ylab, size=22) ylabel(ylab, size=22)
xlabel(L"$\phi_2$", size=22) xlabel(L"$\phi_2$", size=22)
legend(ncol=2, fontsize=16) legend(ncol=2, fontsize=16)
ylim(3.85, 4.2) #ylim(3.85, 4.3)
tight_layout() tight_layout()
grid(ls="dashed") grid(ls="dashed")
if !isnothing(p) if !isnothing(p)
...@@ -326,9 +326,10 @@ function plot_chi_charm(c::Cat, ff::Vector{Function}, ylab::LaTeXString, phi2_ph ...@@ -326,9 +326,10 @@ function plot_chi_charm(c::Cat, ff::Vector{Function}, ylab::LaTeXString, phi2_ph
end end
# plot chi2_vs_exp adn weights for a given category # plot chi2_vs_exp adn weights for a given category
function plot_chi2_vs_exp(c::Cat, label::Vector{Vector{String}}; p::Union{String, Nothing}=nothing) function plot_chi2_vs_exp(c::Cat, label_in::Vector{Vector{String}}; p::Union{String, Nothing}=nothing)
chi2_exp = getfield(c, :chi2_vs_exp) ww, idx = aic_weight(c)
label = vcat(label, label[2:end]) chi2_exp = getfield(c, :chi2_vs_exp)[idx]
label = vcat(label_in, label_in[2:end])[idx]
figure(figsize=(12,8)) figure(figsize=(12,8))
label_plot = [] label_plot = []
...@@ -342,8 +343,8 @@ function plot_chi2_vs_exp(c::Cat, label::Vector{Vector{String}}; p::Union{String ...@@ -342,8 +343,8 @@ function plot_chi2_vs_exp(c::Cat, label::Vector{Vector{String}}; p::Union{String
subplot(311) subplot(311)
ax1 = gca() ax1 = gca()
setp(ax1.get_xticklabels(),visible=false) # Disable x tick labels setp(ax1.get_xticklabels(),visible=false) # Disable x tick labels
plot(xx, aic_weight(c)[1], marker="^", ls="dashed", color="forestgreen") plot(xx, ww, marker="^", ls="dashed", color="forestgreen")
ylabel(L"$w^\mathrm{AIC}$") ylabel(L"$w$")
subplot(312) subplot(312)
plot(xx, chi2_exp, marker="^", ls="dashed", color="royalblue") plot(xx, chi2_exp, marker="^", ls="dashed", color="royalblue")
...@@ -413,30 +414,31 @@ function plot_hist_tot(c::Vector{Cat}, lbl::LaTeXString; p::Union{Nothing, Strin ...@@ -413,30 +414,31 @@ function plot_hist_tot(c::Vector{Cat}, lbl::LaTeXString; p::Union{Nothing, Strin
fit_res = vcat(fit_res, aux_fit_res[i]) fit_res = vcat(fit_res, aux_fit_res[i])
end end
best = aic_model_ave(aic, fit_res) *hc /t0_ph w, idx = aic_weight(aic)
sys = aic_syst(aic, fit_res) * hc / t0_ph best = aic_model_ave(aic, fit_res)
sys = value(sys) sys = aic_syst(aic, fit_res)
# sys = value(sys)
println(best) println(best)
w, _ = aic_weight(aic)
all_res_aux = vcat(getfield.(c, :fit_res) .* hc... ) all_res_aux = vcat(getfield.(c, :fit_res)... )
all_res = [all_res_aux[i] /t0_ph for i =1:length(all_res_aux)] all_res = all_res_aux[idx] #[all_res_aux[i] /t0_ph for i =1:length(all_res_aux)]
println(length(all_res))
uwerr.(all_res) uwerr.(all_res)
uwerr(best) uwerr(best)
fig = figure() fig = figure()
all_res .-=1.9 #all_res .-=1.9
hist(value.(all_res), bins=15, histtype="stepfilled",alpha=0.5, ec="k", color="navy", weights=w) hist(value.(all_res), bins=50, histtype="stepfilled",alpha=0.5, ec="k", color="navy", weights=w, zorder=1)
axvline(value(best) -1.9, 0, 1, color="orange", label="model average") axvline(value(best), 0, 1, color="orange", label="Model average")
ylim = plt.ylim() ylim = plt.ylim()
fill_betweenx(ylim, value(best)-sys-1.9,value(best)+sys-1.9, color="orange", alpha=0.4) fill_betweenx(ylim, value(best)-sys,value(best)+sys, color="orange", alpha=0.4, zorder=0, label="Systematics")
ylabel("Frequency") ylabel("Frequency", size=16)
xlabel(lbl) xlabel(lbl)
legend() legend()
tight_layout() tight_layout()
plt.ylim(ylim) plt.ylim(ylim)
# xlim(1485,1505)
# xticks(collect(1485:5:1505), string.(collect(1485:5:1505)) )
if !isnothing(p) if !isnothing(p)
o = split(c[1].info, ", ")[1] o = split(c[1].info, ", ")[1]
t = string("hist_", o, ".pdf") t = string("hist_", o, ".pdf")
...@@ -560,6 +562,74 @@ function plot_hist(cat::Vector{Cat} ; save::Bool=false) ...@@ -560,6 +562,74 @@ function plot_hist(cat::Vector{Cat} ; save::Bool=false)
end end
## PLOT FOR FDS/fD
function plot_chi_fds_ratio(c::Cat, ff_vec::Vector{Function}, ylab::LaTeXString, phi2_ph::uwreal, ensinfo::Vector{EnsInfo}; p::Union{String, Nothing}=nothing, n::Union{Nothing, Int64}=nothing )
color = ["orange", "darkgreen", "magenta", "navy"]
fmt = ["^", "v", "<", ">"]
a_sp = [0.087, 0.065, 0.05]
phi2_max = phi2_sym #maximum(value.(phi2))
phih_2_use = c.phih_ph
# choose model
if isnothing(n)
aic, n = findmin(getfield(c, :aic))
end
ff = ff_vec[n]
upar = getfield(c, :fit_param)[n]
phih_2_use = value(c.phih_ph)
res = getfield(c, :fit_res)[n]
#fpik_phys = ((2/3) * (155.7 + 0.5*130.2) * t0_ph / hc ) ^2
xx = [fill(0.0, 100) Float64.(range(0.01, phi2_max, length=100)) fill(phih_2_use,100) fill(phih_2_use,100) fill(c.x_tofit[1,5],100) ]
yy = ff(xx, upar)
#Project one value of muc_i (i=1,2,3)
n_unique = unique(i-> c.x_tofit[i,2], 1:length(c.x_tofit[:,2]))
p2 = c.x_tofit[n_unique, 2]
a2 = c.x_tofit[n_unique, 1]
pc = c.x_tofit[n_unique, 3]
pfpik = c.x_tofit[n_unique, 5]
x = [a2 p2 pc fill(phih_2_use, length(p2)) pfpik ]
x2 = [a2 p2 fill(phih_2_use, length(p2)) fill(phih_2_use, length(p2)) fill(c.x_tofit[1,5], length(p2))] #physical value phih
y = ( c.obs[n_unique] - ff(x, upar) + ff(x2, upar)) #Projection
uwerr.(yy)
uwerr(res)
uwerr.(y)
println(res)
#Plotting
figure(figsize=(10,6))
plot(phi2_sym, 1., marker="X", ms=10, color="black", label= L"$M_\pi=M_K$")
fill_between(xx[:,2], value.(yy)+ err.(yy), value.(yy)-err.(yy), alpha=0.3, color="royalblue") #CL extrapolation (band)
errorbar(value(phi2_ph), value(res), err(res), fmt="s", color="red", label=L"$\phi_2 = \phi^\mathrm{phys}_2$", capsize=5, ms=12)#CL extrapolation
for (k,b) in enumerate(sort(unique(getfield.(ensinfo, :beta))))
n_ = findall(x->x.beta == b, ensinfo)
a2_aux = mean(value.(a2[n_]))
errorbar(value.(x[n_,2]), value.(y[n_]), err.(y[n_]), fmt=fmt[k], label=string(L"$a \approx$", a_sp[k], " fm"), color=color[k], capsize=5, ms=12, mfc="none")#projected datapoints
#dashed lines
#xxx = [fill(a2_aux, 100) Float64.(range(0.0, phi2_max, length=100)) fill(value(c.phih_ph), 100) ]
#yyy = ff(xxx, upar)
#plot(xxx[:,2], value.(yyy), ls="--", color=color[k])#dashed lines
end
ylabel(ylab, size=22)
xlabel(L"$\phi_2$", size=22)
legend(ncol=2, fontsize=16)
#ylim(3.02, 3.18)
tight_layout()
grid(ls="dashed")
if !isnothing(p)
t = string("fit_fds_ratio_", c.info, ".pdf")
println( t)
savefig(joinpath(p, t))
close()
else
display(gcf())
close("all")
end
end
#### ####
## PLOT FROM JAVIER TO TEST decays ## PLOT FROM JAVIER TO TEST decays
### ###
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# The analysis is performed by solving a GEVP # The analysis is performed by solving a GEVP
################################## ##################################
using Base: String using Base: String
using Base: @kwdef
using LaTeXStrings: length using LaTeXStrings: length
using OrderedCollections using OrderedCollections
using juobs, BDIO, DelimitedFiles, ADerrors, LaTeXStrings, PyPlot using juobs, BDIO, DelimitedFiles, ADerrors, LaTeXStrings, PyPlot
...@@ -46,14 +47,14 @@ const path_bdio_tm_shifted = "/Users/alessandroconigli/Lattice/data/bdio_charm/t ...@@ -46,14 +47,14 @@ const path_bdio_tm_shifted = "/Users/alessandroconigli/Lattice/data/bdio_charm/t
const path_plot = "/Users/alessandroconigli/MyDrive/phd/analysis/charm_gevp_2022/plots" const path_plot = "/Users/alessandroconigli/MyDrive/phd/analysis/charm_gevp_2022/plots"
# ensembles to analyse # ensembles to analyse
const ens_list = ["H102r002"] const ens_list = ["D200"]
# reweighting and mass shift flags # reweighting and mass shift flags
const rwf = true const rwf = true
const mass_shift = true const mass_shift = true
const tau = 3 # gevp shift parameter const tau = 3 # gevp shift parameter
const TSM = false # set whether TSM is used or not const TSM = false # set whether TSM is used or not
@warning("\nTSM FLAG MODE: FALSE\n") #@warning("\nTSM FLAG MODE: $(TSM)\n")
#=============== INCLUDES ===============# #=============== INCLUDES ===============#
...@@ -81,9 +82,12 @@ wpmm["H400"] = [-1.0, 4.0, -1.0, 14.0*3.659] ...@@ -81,9 +82,12 @@ wpmm["H400"] = [-1.0, 4.0, -1.0, 14.0*3.659]
wpmm["N202"] = [-1.0, 4.0, -1.0, 14.0*5.164] wpmm["N202"] = [-1.0, 4.0, -1.0, 14.0*5.164]
wpmm["N200"] = [-1.0, 4.0, -1.0, 14.0*5.164] wpmm["N200"] = [-1.0, 4.0, -1.0, 14.0*5.164]
wpmm["N203"] = [-1.0, 4.0, -1.0, 14.0*5.164] wpmm["N203"] = [-1.0, 4.0, -1.0, 14.0*5.164]
wpmm["D200"] = [-1.0, 4.0, -1.0, 14.0*5.164] #wpmm["D200"] = [-1.0, 4.0, -1.0, 14.0*5.164]
wpmm["D200"] = [-1.0, 4.0, -1.0, -1.0]
wpmm["N300"] = [-1.0, 4.0, -1.0, 14.0*8.595] wpmm["N300"] = [-1.0, 4.0, -1.0, 14.0*8.595]
wpmm["J303"] = [-1.0, 4.0, -1.0, 14.0*8.595] wpmm["J303"] = [-1.0, 4.0, -1.0, 14.0*8.595]
wpmm["D200_corr"] = [1.0, -1.0, -1.0, -1.0]
## ##
#=============== ANALYSIS ===============# #=============== ANALYSIS ===============#
...@@ -100,16 +104,18 @@ end ...@@ -100,16 +104,18 @@ end
for (k,ens) in enumerate(ensinfo) for (k,ens) in enumerate(ensinfo)
# t0 # t0
t0_ens, YW, W = get_t0(path_data_w, ens, rw=rwf, path_rw=path_rw) t0_ens, YW, W = get_t0(path_data_w, ens, rw=rwf, path_rw=path_rw)
#t0_ens = t0(ens.beta)
# tm correlators # tm correlators
pp_tm, pp_tmW, _ = get_corr(path_data_tm, ens,"G5", "G5", rw=rwf, path_rw=path_rw, tsm=TSM)
pp_tm, pp_tmW = get_corr(path_data_tm, ens,"G5", "G5", rw=rwf, path_rw=path_rw, tsm=TSM)
a1a1_tm, _, _ = get_corr(path_data_tm, ens, "G1G5", "G1G5", rw=rwf, path_rw=path_rw, tsm=TSM)
a2a2_tm, _, _ = get_corr(path_data_tm, ens, "G2G5", "G2G5", rw=rwf, path_rw=path_rw, tsm=TSM)
a3a3_tm, _, _ = get_corr(path_data_tm, ens, "G3G5", "G3G5", rw=rwf, path_rw=path_rw, tsm=TSM)
pa1_tm, _, _ = get_corr(path_data_tm, ens, "G5", "G1G5", rw=rwf, path_rw=path_rw, tsm=TSM) a1a1_tm, _ = get_corr(path_data_tm, ens, "G1G5", "G1G5", rw=rwf, path_rw=path_rw, tsm=TSM)
pa2_tm, _, _ = get_corr(path_data_tm, ens, "G5", "G2G5", rw=rwf, path_rw=path_rw, tsm=TSM) a2a2_tm, _ = get_corr(path_data_tm, ens, "G2G5", "G2G5", rw=rwf, path_rw=path_rw, tsm=TSM)
pa3_tm, _, _ = get_corr(path_data_tm, ens, "G5", "G3G5", rw=rwf, path_rw=path_rw, tsm=TSM) a3a3_tm, _ = get_corr(path_data_tm, ens, "G3G5", "G3G5", rw=rwf, path_rw=path_rw, tsm=TSM)
pa1_tm, _ = get_corr(path_data_tm, ens, "G5", "G1G5", rw=rwf, path_rw=path_rw, tsm=TSM)
pa2_tm, _ = get_corr(path_data_tm, ens, "G5", "G2G5", rw=rwf, path_rw=path_rw, tsm=TSM)
pa3_tm, _ = get_corr(path_data_tm, ens, "G5", "G3G5", rw=rwf, path_rw=path_rw, tsm=TSM)
mu_list = gen_mulist[k] = getfield.(pp_tm, :mu) mu_list = gen_mulist[k] = getfield.(pp_tm, :mu)
...@@ -119,15 +125,15 @@ for (k,ens) in enumerate(ensinfo) ...@@ -119,15 +125,15 @@ for (k,ens) in enumerate(ensinfo)
mat_tm2 = comp_mat_multigamma(ens, pp_tm, pa2_tm, a2a2_tm) mat_tm2 = comp_mat_multigamma(ens, pp_tm, pa2_tm, a2a2_tm)
mat_tm3 = comp_mat_multigamma(ens, pp_tm, pa3_tm, a3a3_tm) mat_tm3 = comp_mat_multigamma(ens, pp_tm, pa3_tm, a3a3_tm)
# gevp matrices for ps and vec decays # gevp matrices for ps and vec decays
mat_dec_ps = comp_mat(ens, pp_tm, tau) mat_dec_ps = comp_mat_tau_shift(ens, pp_tm, tau)
mat_dec_vec1 = comp_mat(ens, a1a1_tm, tau) mat_dec_vec1 = comp_mat_tau_shift(ens, a1a1_tm, tau)
mat_dec_vec2 = comp_mat(ens, a2a2_tm, tau) mat_dec_vec2 = comp_mat_tau_shift(ens, a2a2_tm, tau)
mat_dec_vec3 = comp_mat(ens, a3a3_tm, tau) mat_dec_vec3 = comp_mat_tau_shift(ens, a3a3_tm, tau)
# gevp meson masses # gevp meson masses
m_tm_ps, m_tm_vec1 = gevp_mass(mat_tm1, path_plat_tm_mps, path_plat_tm_mvec, t0=3, pl=true) m_tm_ps, m_tm_vec1 = gevp_mass(mat_tm1, path_plat_tm_mps, path_plat_tm_mvec, t0=3, wpm=wpmm, pl=true)
_, m_tm_vec2 = gevp_mass(mat_tm2, path_plat_tm_mps, path_plat_tm_mvec, t0=3, pl=false) _, m_tm_vec2 = gevp_mass(mat_tm2, path_plat_tm_mps, path_plat_tm_mvec, t0=3, wpm=wpmm, pl=false)
_, m_tm_vec3 = gevp_mass(mat_tm3, path_plat_tm_mps, path_plat_tm_mvec, t0=3, pl=false) _, m_tm_vec3 = gevp_mass(mat_tm3, path_plat_tm_mps, path_plat_tm_mvec, t0=3, wpm=wpmm, pl=false)
m_tm_vec = (m_tm_vec1 .+ m_tm_vec2 .+ m_tm_vec3 ) ./ 3. m_tm_vec = (m_tm_vec1 .+ m_tm_vec2 .+ m_tm_vec3 ) ./ 3.
# pion mass # pion mass
pion_plat = select_plateau(ens, mu_list, path_plat_tm_mps)[1] pion_plat = select_plateau(ens, mu_list, path_plat_tm_mps)[1]
...@@ -143,10 +149,10 @@ for (k,ens) in enumerate(ensinfo) ...@@ -143,10 +149,10 @@ for (k,ens) in enumerate(ensinfo)
# dec_vec = (dec_v1 .+ dec_v2 .+ dec_v3) ./ 3. # dec_vec = (dec_v1 .+ dec_v2 .+ dec_v3) ./ 3.
# decay constant from ratio # decay constant from ratio
dec_ps = get_f_tm(pp_tm, m_tm_ps, ens, path_plat_tm_dps, pl=true ) dec_ps = get_f_tm(pp_tm, m_tm_ps, ens, path_plat_tm_dps, pl=true, wpm=wpmm )
dec_v1 = get_fstar_tm(a1a1_tm, m_tm_vec1, ens, path_plat_tm_dvec, pl=true) dec_v1 = get_fstar_tm(a1a1_tm, m_tm_vec1, ens, path_plat_tm_dvec, pl=true, wpm=wpmm)
dec_v2 = get_fstar_tm(a2a2_tm, m_tm_vec2, ens, path_plat_tm_dvec, pl=false) dec_v2 = get_fstar_tm(a2a2_tm, m_tm_vec2, ens, path_plat_tm_dvec, pl=false, wpm=wpmm)
dec_v3 = get_fstar_tm(a3a3_tm, m_tm_vec3, ens, path_plat_tm_dvec, pl=false) dec_v3 = get_fstar_tm(a3a3_tm, m_tm_vec3, ens, path_plat_tm_dvec, pl=false, wpm=wpmm)
dec_vec = (dec_v1 .+ dec_v2 .+ dec_v3) ./ 3. dec_vec = (dec_v1 .+ dec_v2 .+ dec_v3) ./ 3.
close("all") close("all")
......
#################################
# This file was created by Alessandro Conigli - 2023
# This code is equivalent to gevp_tm.jl, but here plateaus are not passed from
# an external file, rather they are autamatically computed using a Bayesian Model Average.
# The pourpose of this code is to compute twisted mass
# observables from raw correlators stored in mesons.dat files.
# The analysis is performed at the level of a single ensemble
# and results are then stored in BDIO files
# It extracts:
# - charm quark mass
# - ll hl hh pseudo and vector masses
# - ll hl hh pseudo and vector leptonic decays
#
# The analysis is performed by solving a GEVP
##################################
using Base: String
using Base: @kwdef
using LaTeXStrings: length
using OrderedCollections
using juobs, BDIO, DelimitedFiles, ADerrors, LaTeXStrings, PyPlot
using ProgressMeter
#============= SET UP VARIABLES ===========#
rcParams = PyPlot.PyDict(PyPlot.matplotlib."rcParams")
rcParams["text.usetex"] = true
rcParams["mathtext.fontset"] = "cm"
rcParams["font.size"] =10
rcParams["axes.labelsize"] =22
rcParams["axes.titlesize"] = 18
plt.rc("text", usetex=true) # set to true once you install latex
#============ PATHS & INFO =================#
# path to data
const path_data_w = "/Users/alessandroconigli/Lattice/data/aux_obs_data/wilson" # required for t0 at finite a
const path_data_tm = "/Users/alessandroconigli/Lattice/data/charm_full_Dirac" # charm correlators
# path to plateau
const path_plat_w = "/Users/alessandroconigli/Lattice/data/aux_obs_data/plat_wilson.txt"
const path_plat_tm_mps = "/Users/alessandroconigli/Lattice/gevp-automated-analysis/plat/plat_tm_mps.txt"
const path_plat_tm_mvec = "/Users/alessandroconigli/Lattice/gevp-automated-analysis/plat/plat_tm_mvec.txt"
const path_plat_tm_dps = "/Users/alessandroconigli/Lattice/gevp-automated-analysis/plat/plat_tm_dps.txt"
const path_plat_tm_dvec = "/Users/alessandroconigli/Lattice/gevp-automated-analysis/plat/plat_tm_dvec.txt"
# path to aux obs
const path_rw = "/Users/alessandroconigli/Lattice/data/aux_obs_data/rwf" # reweighting factors
const path_md = "/Users/alessandroconigli/Lattice/data/aux_obs_data/md/" # pbp dat file for mass shift
# path to bdio
# const path_bdio_md = "/Users/alessandroconigli/Lattice/data/bdio_charm/md/LAT22/" # path to delta m computed by me
const path_bdio_md = "/Users/alessandroconigli/Lattice/data/bdio_charm/AS_ligth_obs/" # path to delta m computed by AS
const path_bdio_tm = "/Users/alessandroconigli/Lattice/data/bdio_charm/tm" # path where to store results
const path_bdio_tm_shifted = "/Users/alessandroconigli/Lattice/data/bdio_charm/tm_shifted" # path were to store shifted results
const path_plot = "/Users/alessandroconigli/MyDrive/phd/analysis/charm_gevp_2022/CharmPaper/plots" # path were to save plots
# ensembles to analyse
const ens_list = [ "E300"]
# reweighting and mass shift flags
const rwf = true
println("Warning! mass_shift set to false ")
const mass_shift = false
const tau = 3 # gevp shift parameter
const T0 = 2
const TSM = true # set whether TSM is used or not
#@warning("\nTSM FLAG MODE: $(TSM)\n")
#=============== INCLUDES ===============#
include("types.jl")
include("tools.jl")
include("const.jl")
include("read_bdio.jl")
#=============== ENSEMBLE INFO FROM DATABASE ==================#
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], trunc_db[ens])
catch
error("The ensemble id ", ens, " was not found in the const.jl ens_db database.
Please check the ensemble id or update the database")
end
end
wpmm = Dict{String, Vector{Float64}}()
wpmm["H101"] = [-1.0, 2.0, -1.0, -1.0] #14.0*2.86]
wpmm["H102r002"] = [-1.0, 2.0, -1.0, -1.0] #14.0*2.86]
wpmm["H105r002"] = [-1.0, 2.0, -1.0, -1.0]# 14.0*2.86]
wpmm["H400"] = [-1.0, 2.0, -1.0, -1.0] #14.0*3.659]
wpmm["N202"] = [-1.0, 2.0, -1.0, -1.0] #14.0*5.164]
wpmm["N200"] = [-1.0, 2.0, -1.0, -1.0] #14.0*5.164]
wpmm["N203"] = [-1.0, 2.0, -1.0, -1.0] # 14.0*5.164]
#wpmm["D200"] = [-1.0, 4.0, -1.0, 14.0*5.164]
wpmm["D200"] = [-1.0, 2.0, -1.0, -1.0]
wpmm["N300"] = [-1.0, 2.0, -1.0, -1.0 ] #14.0*8.595]
wpmm["J303"] = [-1.0, 2.0, -1.0, -1.0 ] #14.0*8.595]
wpmm["J500"] = [-1.0, 2.0, -1.0, -1.0 ] #14.0*8.595]
## TESTING TSM WITH MULTIPLE replicas
data_sl = read_data_sloppy(path_data_tm, "E300", "G5", "G5", legacy=false)
data_corr = read_data_correction(path_data_tm, "E300", "G5", "G5", legacy=false)
vcfg_sl = getfield.(data_sl[1], :vcfg)
replica_sl = Int64.(maximum.(vcfg_sl))
vcfg_corr = getfield.(data_corr[1], :vcfg)
replica_corr = Int64.(maximum.(vcfg_corr))
corr_pp, pp_tmW = get_corr(path_data_tm, ensinfo[1], "G5", "G5", rw=false, path_rw=path_rw, tsm=TSM)
##
#=============== LOAD DATA AND STORE t0 ===============#
corr_pp = Vector{Vector{juobs.Corr}}(undef, length(ens_list))
corr_pa = Vector{Vector{juobs.Corr}}(undef, length(ens_list))
corr_aa = Vector{Vector{juobs.Corr}}(undef, length(ens_list))
yw_store = Vector{Matrix{uwreal}}(undef, length(ens_list)) # store YW info from t0
w_store = Vector{uwreal}(undef, length(ens_list)) # store W info from t0
pp_tmW = Vector{Vector{Vector{uwreal}}}(undef, length(ens_list)) # store W info from corr_pp
gen_mulist = Vector{Vector{Vector{Float64}}}(undef, length(ens_list)) # store mu values
# obs storage
obs_tm = Vector(undef, length(ensinfo))
@time begin
@showprogress for (k,ens) in enumerate(ensinfo)
println("\n Ensemble: ", ens.id)
# t0
t0_ens, yw_store[k], w_store[k] = get_t0(path_data_w, ens, rw=rwf, path_rw=path_rw, pl=true)
obs_tm[k] = OrderedDict()
obs_tm[k]["t0"] = t0_ens
# correlators
corr_pp[k], pp_tmW[k], _ = get_corr(path_data_tm, ens, "G5", "G5", rw=rwf, path_rw=path_rw, tsm=TSM)
a1a1, _ = get_corr(path_data_tm, ens, "G1G5", "G1G5", rw=rwf, path_rw=path_rw, tsm=TSM)
a2a2, _ = get_corr(path_data_tm, ens, "G2G5", "G2G5", rw=rwf, path_rw=path_rw, tsm=TSM)
a3a3, _ = get_corr(path_data_tm, ens, "G3G5", "G3G5", rw=rwf, path_rw=path_rw, tsm=TSM)
aa_tmp = (getfield.(a1a1, :obs) .+ getfield.(a2a2, :obs) .+ getfield.(a3a3, :obs)) ./ 3
corr_aa[k] = [juobs.Corr(aa_tmp[l], a1a1[l].kappa, a1a1[l].mu, ["G123G123", "G123G123"], a1a1[l].y0, a1a1[l].theta1, a1a1[l].theta2 ) for l in eachindex(a1a1)]
pa1, _ = get_corr(path_data_tm, ens, "G5", "G1G5", rw=rwf, path_rw=path_rw, tsm=TSM)
pa2, _ = get_corr(path_data_tm, ens, "G5", "G2G5", rw=rwf, path_rw=path_rw, tsm=TSM)
pa3, _ = get_corr(path_data_tm, ens, "G5", "G3G5", rw=rwf, path_rw=path_rw, tsm=TSM)
pa_tmp = (getfield.(pa1, :obs) .+ getfield.(pa2, :obs) .+ getfield.(pa3, :obs)) ./ 3
corr_pa[k] = [juobs.Corr(pa_tmp[l], pa1[l].kappa, pa1[l].mu, ["G0G123", "G0G123"], pa1[l].y0, pa1[l].theta1, pa1[l].theta2 ) for l in eachindex(pa1)]
gen_mulist[k] = getfield.(corr_pp[k], :mu)
end
end
##
#=============== ANALYSIS ===============#
Mtotps = Vector{Vector{uwreal}}(undef, length(ensinfo)) # required for decay constants
Mtotvec = Vector{Vector{uwreal}}(undef, length(ensinfo)) # required for decay constants
@time begin
@showprogress for (k,ens) in enumerate(ensinfo)
# gevp matrix for ps and vec masses
mat_mass = comp_mat_multigamma(ens, corr_pp[k], corr_pa[k], corr_aa[k])
m_tm_ps, m_tm_vec = gevp_mass_BMA(mat_mass, tt0=T0, pl=true, wpm=wpmm, path_plt=path_plot)
Mtotps[k] = m_tm_ps
Mtotvec[k] = m_tm_vec
mu_list = gen_mulist[k]
mul, mus, muh = get_mu(mu_list, ens.deg)
# split masses by sector
mll_tm = get_ll(mu_list, m_tm_ps, ens.deg)
mls_tm = ens.deg ? mll_tm : get_ls(mu_list, m_tm_ps, ens.deg) # ls
mlh_tm = get_lh(mu_list, m_tm_ps, ens.deg) # lh
msh_tm = ens.deg ? mlh_tm : get_sh(mu_list, m_tm_ps, ens.deg) # sh
mhh_tm = get_hh(mu_list, m_tm_ps, ens.deg)
mlh_star_tm = get_lh(mu_list, m_tm_vec, ens.deg)
msh_star_tm = ens.deg ? mlh_star_tm : get_sh(mu_list, m_tm_vec, ens.deg)
mhh_star_tm = get_hh(mu_list, m_tm_vec, ens.deg)
obs_tm[k]["mll"] = mll_tm * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["mls"] = mls_tm * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["mlh"] = mlh_tm * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["msh"] = msh_tm * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["mhh"] = mhh_tm * sqrt(8*obs_tm[k]["t0"])
#required to be consistent with storage ordering
obs_tm[k]["flh"] = 0.0
obs_tm[k]["fsh"] = 0.0
obs_tm[k]["fhh"] = 0.0
obs_tm[k]["mlh_star"] = mlh_star_tm * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["msh_star"] = msh_star_tm * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["mhh_star"] = mhh_star_tm * sqrt(8*obs_tm[k]["t0"])
#required to be consistent with storage ordering
obs_tm[k]["flh_star"] = 0.0
obs_tm[k]["fsh_star"] = 0.0
obs_tm[k]["fhh_star"] = 0.0
obs_tm[k]["muh"] = muh * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["fpik"] = 0.0
end
end
##
# Decay constants
close("all")
for (k,ens) in enumerate(ensinfo)
# gevp matrices for GEVP
# mat_dec_ps = comp_mat_tau_shift(ens, corr_pp[k], tau)
# mat_dec_vev = comp_mat_tau_shift(ens, corr_aa[k], tau)
# dec_ps = gevp_dec_BMA(mat_dec_ps, Mtotps[k], t0=T0, wpm=wpmm, pl=true, n=1, pseudo=true, wilson=false )
# dec_ps_test = get_f_tm(corr_pp[k], Mtotps[k], ens, path_plat_tm_dps, pl=true, wpm=wpmm )
path_plt_ps = joinpath(path_plot, "plateaus", ens.id, "fps")
dec_tm_ps = get_f_tm_BMA(corr_pp[k], Mtotps[k], ens, pl=true, wpm=wpmm, path_plt=path_plot, ps="fps")
path_plt_vec = joinpath(path_plot, "plateaus", ens.id, "fps")
dec_tm_vec = get_f_tm_BMA(corr_aa[k], Mtotvec[k], ens, pl=true, wpm=wpmm, path_plt=path_plot, ps="fvec")
mu_list = gen_mulist[k]
mul, mus, muh = get_mu(mu_list, ens.deg)
# split masses by sector
flh_tm = get_lh(mu_list, dec_tm_ps, ens.deg) # lh
fsh_tm = ens.deg ? flh_tm : get_sh(mu_list, dec_tm_ps, ens.deg) # sh
fhh_tm = get_hh(mu_list, dec_tm_ps, ens.deg) # hh
flh_star_tm = get_lh(mu_list, dec_tm_vec, ens.deg)
fsh_star_tm = ens.deg ? flh_star_tm : get_sh(mu_list, dec_tm_vec, ens.deg)
fhh_star_tm = get_hh(mu_list, dec_tm_vec, ens.deg)
obs_tm[k]["flh"] = flh_tm * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["fsh"] = fsh_tm * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["fhh"] = fhh_tm * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["flh_star"] = flh_star_tm * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["fsh_star"] = fsh_star_tm * sqrt(8*obs_tm[k]["t0"])
obs_tm[k]["fhh_star"] = fhh_star_tm * sqrt(8*obs_tm[k]["t0"])
end
## mass shift
## careful with H105r002! Do not substitute pion and kaon masses in this case
if mass_shift
deltam = Vector(undef, length(ensinfo))
obs_tm_shifted = Vector(undef, length(ensinfo))
@info "Delta m taken from $(path_bdio_md)"
for (k,ens) in enumerate(ensinfo)
# read deltam from bdio
# read dm computed by AS
rep = filter(x->occursin(ens.id, x), readdir(path_bdio_md,join=true))[1]
ens.deg ? Nmolt =3. : Nmolt = 1. # required for symmetric point ensembles if shifting s only
println(Nmolt)
deltam[k] = read_BDIO(rep, "ll_obs", "dm")[1] * Nmolt
# these two lines for dm computed locally by me
# fname = joinpath(path_bdio_md, string(ens.id,".bdio"))
# deltam[k] = read_BDIO(fname, "md", "deltam")[1]
# read dS/dm
dSdm = read_pbp(path_md, ens.id)
# definitions
prim_obs = vcat(pp_tmW[k]...)
obs_tm_shifted[k] = deepcopy(obs_tm[k])
## LOOOP OVER OBSERVABLES + MASS SHIFT
for (key, value) in obs_tm[k]
if isa(value, uwreal) # if 1 uwreal
mds1, mds2 = md_sea(value, dSdm, prim_obs, w_store[k]) .+ md_sea(value, dSdm, yw_store[k], w_store[k])
# obs_tm_shifted[k][key] = obs_tm[k][key] + deltam[k] * (2 * mds1 + mds2) # shifting u,d,s
obs_tm_shifted[k][key] = obs_tm[k][key] + deltam[k] * (mds2) # shifting s
elseif isa(value, Vector{uwreal}) # if vector uwreal
for (i, v) in enumerate(value)
mds1, mds2 = md_sea(v, dSdm, prim_obs, w_store[k]) .+ md_sea(v, dSdm, yw_store[k], w_store[k])
# obs_tm_shifted[k][key][i] = obs_tm[k][key][i] + deltam[k] * (2 * mds1 + mds2) # shifting u,d,s
obs_tm_shifted[k][key][i] = obs_tm[k][key][i] + deltam[k] * (mds2) # shifting s
end
end
end
end
end
## read and store fpik and mpi from AS analysis
for (k,ens) in enumerate(ensinfo)
rep = filter(x->occursin(ens.id, x), readdir(path_bdio_md,join=true))[1]
t0_aux = read_BDIO(rep, "ll_obs", "t0")[1] # check that your t0_shifted coincide with this
mpi_aux = read_BDIO(rep, "ll_obs", "mpi")[1]
mk_aux = read_BDIO(rep, "ll_obs", "mk")[1]
fpi_aux = read_BDIO(rep, "ll_obs", "fpi")[1]
fk_aux = read_BDIO(rep, "ll_obs", "fk")[1]
sqrt8t0 = sqrt(8*t0_aux) # sqrt(8*obs_tm_shifted[k]["t0"])
obs_tm_shifted[k]["mll"] = sqrt8t0 * mpi_aux
obs_tm_shifted[k]["mls"] = sqrt8t0 * mk_aux
obs_tm_shifted[k]["fpik"] = sqrt8t0 * (2. / 3.) * (fk_aux + 0.5*fpi_aux)
obs_tm[k]["fpik"] = sqrt8t0 * (2. / 3.) * (fk_aux + 0.5*fpi_aux)
end
##
[pop!(obs_tm[k], "fpk") for k in 1:length(obs_tm)]
[pop!(obs_tm_shifted[k], "fpk") for k in 1:length(obs_tm)]
##
#====================== WRITE BDIO =====================#
[pop!(obs_tm[k], "t0") for k in 1:length(obs_tm)]
if mass_shift
#TM SHIFTED
[pop!(obs_tm_shifted[k], "t0") for k in 1:length(obs_tm_shifted)]
for (k, obs) in enumerate(obs_tm_shifted) #loop over ensembles
ens = ensinfo[k].id
p = joinpath(path_bdio_tm_shifted, string(ens, ".bdio")) #
fb = BDIO_open(p, "w", ens)
uinfo = 0
for (key, value) in obs #loop over observables
if isa(value, uwreal)
write_uwreal(value, fb, uinfo)
elseif isa(value, Vector{uwreal})
[write_uwreal(v, fb, uinfo) for v in value]
end
uinfo += 1
end
BDIO_close!(fb)
end
end
# TM
for (k, obs) in enumerate(obs_tm) #loop over ensembles
ens = ensinfo[k].id
p = joinpath(path_bdio_tm, string(ens, ".bdio"))
fb = BDIO_open(p, "w", ens)
uinfo = 0
for (key, value) in obs #loop over observables
if isa(value, uwreal)
write_uwreal(value, fb, uinfo)
elseif isa(value, Vector{uwreal})
[write_uwreal(v, fb, uinfo) for v in value]
end
uinfo += 1
end
BDIO_close!(fb)
end
...@@ -42,7 +42,8 @@ function read_BDIO(path::String, type::String, obs::String) ...@@ -42,7 +42,8 @@ function read_BDIO(path::String, type::String, obs::String)
"flh_star" => 11, "flh_star" => 11,
"fsh_star" => 12, "fsh_star" => 12,
"fhh_star" => 13, "fhh_star" => 13,
"muh" => 14 "muh" => 14,
"fpik" => 15
) )
dict_md = Dict( dict_md = Dict(
"deltam" => 0, "deltam" => 0,
...@@ -50,8 +51,15 @@ function read_BDIO(path::String, type::String, obs::String) ...@@ -50,8 +51,15 @@ function read_BDIO(path::String, type::String, obs::String)
"phi2_shifted" => 2, "phi2_shifted" => 2,
"phi4_shifted" => 3 "phi4_shifted" => 3
) )
dict_ligth_obs = Dict(
dict2dict = Dict("w" => dict_w, "tm" => dict_tm, "md" => dict_md) "t0" => 1,
"mpi" => 2,
"mk" => 3,
"fpi" => 4,
"fk" => 5,
"dm" => 15
)
dict2dict = Dict("w" => dict_w, "tm" => dict_tm, "md" => dict_md, "ll_obs" => dict_ligth_obs)
if !(type in keys(dict2dict)) if !(type in keys(dict2dict))
error("Incorrect type.\ntype = $(keys(dict2dict))") error("Incorrect type.\ntype = $(keys(dict2dict))")
......
# read standard data no TSM # read standard data no TSM
function read_data(path::String, ens::String, g1::String="G5", g2::String="G5"; legacy::Bool=false)
function read_data(path::String, ens::String, g1::String="G5", g2::String="G5"; legacy::Bool=false, ex::Bool=false)
p = joinpath(path, ens) p = joinpath(path, ens)
rep = filter(x->occursin("mesons.dat", x), readdir(p, join=true)) if !ex
rep = filter(x->occursin("mesons.dat", x), readdir(p, join=true))
else
rep = filter(x->occursin("correction", x), readdir(p, join=true))
end
if length(rep)!=0 if length(rep)!=0
length(rep)==1 ? (return read_mesons(rep[1], g1, g2, legacy=legacy, id=ens)) : (return read_mesons(rep, g1, g2, legacy=legacy, id=ens)) length(rep)==1 ? (return read_mesons(rep[1], g1, g2, legacy=legacy, id=ens)) : (return read_mesons(rep, g1, g2, legacy=legacy, id=ens))
else else
...@@ -19,9 +24,9 @@ function read_data_sloppy(path::String, ens::String, g1::String="G5", g2::String ...@@ -19,9 +24,9 @@ function read_data_sloppy(path::String, ens::String, g1::String="G5", g2::String
end end
end end
# read correction TSM # read correction TSM
function read_data_exact(path::String, ens::String, g1::String="G5", g2::String="G5"; legacy::Bool=false) function read_data_correction(path::String, ens::String, g1::String="G5", g2::String="G5"; legacy::Bool=false)
p = joinpath(path, ens) p = joinpath(path, ens)
rep = filter(x->occursin("exact", x), readdir(p, join=true)) rep = filter(x->occursin("correction", x), readdir(p, join=true))
if length(rep)!=0 if length(rep)!=0
length(rep)==1 ? (return read_mesons_correction(rep[1], g1, g2, legacy=legacy, id=ens)) : (return read_mesons_correction(rep, g1, g2, legacy=legacy, id=ens)) length(rep)==1 ? (return read_mesons_correction(rep[1], g1, g2, legacy=legacy, id=ens)) : (return read_mesons_correction(rep, g1, g2, legacy=legacy, id=ens))
else else
...@@ -40,6 +45,9 @@ end ...@@ -40,6 +45,9 @@ end
function read_rw(path::String, ens::String) function read_rw(path::String, ens::String)
p = joinpath(path, ens) p = joinpath(path, ens)
rep = filter(x->occursin("ms1.dat", x), readdir(p, join=true)) rep = filter(x->occursin("ms1.dat", x), readdir(p, join=true))
if ens == "J500"
return [read_ms1(rep[1]), read_ms1(rep[2], v="1.4")]
end
if length(rep)!=0 if length(rep)!=0
try try
length(rep) == 1 ? (return read_ms1(rep[1])) : (return read_ms1.(rep)) length(rep) == 1 ? (return read_ms1(rep[1])) : (return read_ms1.(rep))
...@@ -60,14 +68,14 @@ function read_t0(path::String, ens::String, dtr::Int64) ...@@ -60,14 +68,14 @@ function read_t0(path::String, ens::String, dtr::Int64)
end end
end end
# in this function you have to implement the tsm reader # in this function you have to implement the tsm reader
function get_corr(path::String, ens::EnsInfo, g1::String="G5", g2::String="G5"; rw::Bool=false, legacy::Bool=false, path_rw::String="", tsm::Bool=false) function get_corr(path::String, ens::EnsInfo, g1::String="G5", g2::String="G5"; rw::Bool=false, legacy::Bool=false, path_rw::String="", tsm::Bool=false, ex::Bool=false)
if path_rw == "" if path_rw == ""
p_rw = path p_rw = path
else else
p_rw = path_rw p_rw = path_rw
end end
if !tsm if !tsm
aux = read_data(path, ens.id, g1, g2, legacy=legacy) aux = read_data(path, ens.id, g1, g2, legacy=legacy, ex=ex)
if !isnothing(ens.trunc) if !isnothing(ens.trunc)
truncate_data!(aux, ens.trunc) truncate_data!(aux, ens.trunc)
end end
...@@ -80,16 +88,28 @@ function get_corr(path::String, ens::EnsInfo, g1::String="G5", g2::String="G5"; ...@@ -80,16 +88,28 @@ function get_corr(path::String, ens::EnsInfo, g1::String="G5", g2::String="G5";
end end
else else
aux1 = read_data_sloppy(path, ens.id, g1, g2, legacy=legacy) aux1 = read_data_sloppy(path, ens.id, g1, g2, legacy=legacy)
aux2 = read_data_exact(path, ens.id, g1, g2, legacy=legacy) aux2 = read_data_correction(path, ens.id, g1, g2, legacy=legacy)
if !isnothing(ens.trunc) if !isnothing(ens.trunc)
truncate_data!(aux1, ens.trunc) try # single replica
truncate_data!(aux2, ens.trunc) vcfg = getfield(aux1[1], :vcfg)
delta = vcfg[1][2] - vcfg[1][1]
cut_trunc = Int64.((ens.trunc .-1)./delta) .+ 1
truncate_data!(aux1, cut_trunc )
truncate_data!(aux2, cut_trunc)
catch # multiple replica
vcfg = getfield.(aux1[1], :vcfg)
delta = vcfg[1][2] - vcfg[1][1]
cut_trunc = Int64.((ens.trunc .-1)./delta) .+ 1
truncate_data!(aux1, cut_trunc )
truncate_data!(aux2, cut_trunc)
end
end end
if !rw if !rw
obs = corr_obs_TSM.(aux1, aux2, L=ens.L, info=true) obs = corr_obs_TSM.(aux1, aux2, L=ens.L, info=true)#, idm_corr=collect(1:ens.idm_corr) )
return (getindex.(obs, 1), getindex.(obs, 2)) return (getindex.(obs, 1), getindex.(obs, 2))
else else
obs = corr_obs_TSM.(aux1, aux2, L=ens.L, rw=read_rw(p_rw, ens.id), info=true) obs = corr_obs_TSM.(aux1, aux2, L=ens.L, rw=read_rw(p_rw, ens.id), info=true) #, idm_corr=collect(1:ens.idm_corr))
return (getindex.(obs, 1), getindex.(obs, 2), getindex.(obs, 3)) return (getindex.(obs, 1), getindex.(obs, 2), getindex.(obs, 3))
end end
end end
...@@ -213,33 +233,99 @@ function get_hh(mu_list, obs::Vector{uwreal}, deg::Bool) ...@@ -213,33 +233,99 @@ function get_hh(mu_list, obs::Vector{uwreal}, deg::Bool)
end end
return obs_hh return obs_hh
end end
function comp_mat(ensinfo::EnsInfo, tot_obs::Vector{juobs.Corr}, tau::Int64) """
comp_mat_tau_shift(ensinfo::EnsInfo, tot_obs::Vector{juobs.Corr}, tau::Int64)
This method takes as input an EnsInfo object and a vector of Corr. For each element of the vector a 2x2 matrix is computed where each element of the matrix is shifted by a tau=4 value in time.
It is used for gevp problem with single gamma structure and a tau shift in time.
The method return a vector of MatInfo for each element of the vector Corr, corresponding to different masses
"""
function comp_mat_tau_shift(ensinfo::EnsInfo, tot_obs::Vector{juobs.Corr}, tau::Int64)
mat_info = Vector{MatInfo}(undef, length(tot_obs)) mat_info = Vector{MatInfo}(undef, length(tot_obs))
y0 = getfield.(tot_obs,:y0) .+1
for i = 1:length(tot_obs) for i = 1:length(tot_obs)
a11 = tot_obs[i].obs[1:end-1-2*tau] a11 = tot_obs[i].obs[y0[i]:end-1-2*tau]
a12 = tot_obs[i].obs[1+tau:end-1-tau] a12 = tot_obs[i].obs[y0[i]+tau:end-1-tau]
a22 = tot_obs[i].obs[1+2*tau:end-1] a22 = tot_obs[i].obs[y0[i]+2*tau:end-1]
aux = juobs.get_matrix([a11, a22], [a12]) aux = juobs.get_matrix([a11, a22], [a12])
mat_info[i] = MatInfo(ensinfo, aux, tot_obs[i].mu, tot_obs[i].y0) mat_info[i] = MatInfo(ensinfo, aux, tot_obs[i].mu, tot_obs[i].y0)
end end
return mat_info return mat_info
end end
"""
comp_mat_multigamma(ensinfo::EnsInfo,tot11::Vector{juobs.Corr}, tot12::Vector{juobs.Corr}, tot22::Vector{juobs.Corr})
This method takes as input an EnsInfo object and:
tot11::Vector{juobs.Corr} corresponding to element 11
tot12::Vector{juobs.Corr} corresponding to element 12
tot22::Vector{juobs.Corr} corresponding to element 22
For each element of these vector a MatInfo object is built running on all the timeslices.
This method is used for gevp problems with multiple gamma structures in the matrix.
It returns a vector of MatInfo.
"""
function comp_mat_multigamma(ensinfo::EnsInfo,tot11::Vector{juobs.Corr}, tot12::Vector{juobs.Corr}, tot22::Vector{juobs.Corr}) function comp_mat_multigamma(ensinfo::EnsInfo,tot11::Vector{juobs.Corr}, tot12::Vector{juobs.Corr}, tot22::Vector{juobs.Corr})
mu = getfield.(tot11,:mu) mu = getfield.(tot11,:mu)
y0 = getfield.(tot11,:y0) .+1 y0 = getfield.(tot11,:y0)
mat_info = Vector{MatInfo}(undef, length(mu)) mat_info = Vector{MatInfo}(undef, length(mu))
for i = 1:length(mu) for i = 1:length(mu)
a11 = tot11[i].obs[y0[i]:end-1] a11 = tot11[i].obs[y0[i]:end-1]
a12 = tot12[i].obs[y0[i]:end-1] a12 = tot12[i].obs[y0[i]:end-1]
a22 = tot22[i].obs[y0[i]:end-1] a22 = tot22[i].obs[y0[i]:end-1]
#res[i] = infoMatt(a11, a12, a22)
aux = juobs.get_matrix([a11, a22], [a12]) aux = juobs.get_matrix([a11, a22], [a12])
mat_info[i] = MatInfo(ensinfo, aux, mu[i], y0[i]) mat_info[i] = MatInfo(ensinfo, aux, mu[i], y0[i])
end end
return mat_info return mat_info
end end
function gevp_mass(mat_obs::Vector{MatInfo}, path_plat::String; t0::Int64=2,pl::Bool=true, wpm::Union{Nothing, Dict{Int64,Vector{Float64}}}=nothing) """
comp_mat_GPOF(ensinfo::EnsInfo, corr::Vector{juobs.Corr}; N::Int64=4)
This method takes as input an EnsInfo object and a vector of Corr.
For each element of the vector, a list of matrix of dimension NxN is built,
where each element of the matrix is shifted in time by one unit with respect to the previous element.
This method is used to solve gevp a la BMW, i.e. by solving a single gevp with fixed ta and tb and then using the other matrices and the eigenvectors
to project the original correlator into the ground state.
It returns a vector of MatInfo for each element of the vector of Corr.
"""
function comp_mat_GPOF(ensinfo::EnsInfo, corr::Vector{juobs.Corr}; N::Int64=4)
mat_info = Vector{MatInfo}(undef, length(corr))
y0 = getfield(corr[1], :y0) + 1
mu = getfield(corr[1], :mu)
for i in 1:length(corr)
tmp = Vector{Matrix}(undef, 0)
obs = getfield(corr[i], :obs)
for t in y0:length(obs)-10
tmp1 = Matrix(undef, N,N)
for row in 1:N
for col in 1:N
tmp1[row,col] = obs[t+row+col-2]
end
end
push!(tmp, tmp1)
end
mat_info[i] = MatInfo(ensinfo, tmp, mu, y0)
end
return mat_info
end
function comp_mat_multimass(ensinfo::EnsInfo, pp::Vector{juobs.Corr}, pa0::Vector{juobs.Corr} )
mu = vcat(getfield.(pp,:mu)...)
y0 = getfield(pp[1], :y0) +1
ppobs = getfield.(pp, :obs)
pa0obs = getfield.(pa0, :obs)
mat_info = Vector{MatInfo}(undef, length(mu))
for i in eachindex(ppobs)
aux = juobs.get_matrix([ppobs[1], ppobs[2],ppobs[3]], [pa0obs[1], pa0obs[2],pa0obs[3]] )
mat_info[i] = MatInfo(ensinfo, aux, mu[i], y0)
end
return mat_info
end
function gevp_mass(mat_obs::Vector{MatInfo}, path_plat::String; t0::Int64=2,pl::Bool=true, wpm::Union{Nothing, Dict{String,Vector{Float64}}}=nothing)
y0s = getfield.(mat_obs, :y0) y0s = getfield.(mat_obs, :y0)
mu_list = getfield.(mat_obs, :mu) mu_list = getfield.(mat_obs, :mu)
plat_en0 = Vector{uwreal}(undef, length(mat_obs)) plat_en0 = Vector{uwreal}(undef, length(mat_obs))
...@@ -250,7 +336,7 @@ function gevp_mass(mat_obs::Vector{MatInfo}, path_plat::String; t0::Int64=2,pl:: ...@@ -250,7 +336,7 @@ function gevp_mass(mat_obs::Vector{MatInfo}, path_plat::String; t0::Int64=2,pl::
en = energies(evals, wpm=wpm) #ground and excited state energy en = energies(evals, wpm=wpm) #ground and excited state energy
plat = select_plateau(mat_obs[i].ensinfo, mu_list, path_plat)[i] .- y0s[i] plat = select_plateau(mat_obs[i].ensinfo, mu_list, path_plat)[i] .- y0s[i]
println(plat) println(plat)
plat_en0[i] = plat_av(en[1], plat) plat_en0[i] = plat_av(en[1], plat, wpm)
if pl if pl
uwerr(plat_en0[i]) uwerr(plat_en0[i])
xx = collect(1:length(en[1])) xx = collect(1:length(en[1]))
...@@ -265,42 +351,43 @@ function gevp_mass(mat_obs::Vector{MatInfo}, path_plat::String; t0::Int64=2,pl:: ...@@ -265,42 +351,43 @@ function gevp_mass(mat_obs::Vector{MatInfo}, path_plat::String; t0::Int64=2,pl::
end end
return plat_en0 return plat_en0
end end
function gevp_mass(mat_obs::Vector{MatInfo}, path_m_ps::String, path_m_vec::String; t0::Int64=2,pl::Bool=true, wpm::Union{Nothing, Dict{Int64,Vector{Float64}}}=nothing)
function gevp_mass(mat_obs::Vector{MatInfo}, path_m_ps::String, path_m_vec::String; t0::Int64=2,pl::Bool=true, wpm::Union{Nothing, Dict{String,Vector{Float64}}}=nothing)
y0s = getfield.(mat_obs, :y0) y0s = getfield.(mat_obs, :y0)
mu_list = getfield.(mat_obs, :mu) mu_list = getfield.(mat_obs, :mu)
plat_en0 = Vector{uwreal}(undef, length(mat_obs)) plat_en0 = Vector{uwreal}(undef, length(mat_obs))
plat_en1 = Vector{uwreal}(undef, length(mat_obs)) plat_en1 = Vector{uwreal}(undef, length(mat_obs))
for i in 1:length(mat_obs) for i in 1:length(mat_obs)
mat = getfield(mat_obs[i], :mat_list) #matrices to diagonalise for a given sector [i] mat = getfield(mat_obs[i], :mat_list) #[y0s[i]+1:end-1] #matrices to diagonalise for a given sector [i]
evals = getall_eigvals(mat, t0) evals = getall_eigvals(mat, t0)
en = energies(evals, wpm=wpm) #ground and excited state energy en = energies(evals, wpm=wpm) #ground and excited state energy
plat_ps = select_plateau(mat_obs[i].ensinfo, mu_list, path_m_ps)[i] .- y0s[i] plat_ps = select_plateau(mat_obs[i].ensinfo, mu_list, path_m_ps)[i] .- y0s[i]
println(plat_ps) println(plat_ps)
plat_vec = select_plateau(mat_obs[i].ensinfo, mu_list, path_m_vec)[i] .- y0s[i] plat_vec = select_plateau(mat_obs[i].ensinfo, mu_list, path_m_vec)[i] .- y0s[i]
println(plat_vec) println(plat_vec)
plat_en0[i] = plat_av(en[1], plat_ps) plat_en0[i] = plat_av(en[1], plat_ps, wpm)
plat_en1[i] = plat_av(en[2], plat_vec) # plat_en1[i] = plat_av(en[2], plat_vec, wpm)
if pl if pl
fig = figure(figsize=(10,6)) fig = figure(figsize=(10,6))
uwerr(plat_en0[i]) isnothing(wpm) ? uwerr(plat_en0[i]) : uwerr(plat_en0[i],wpm)
uwerr(plat_en1[i]) # isnothing(wpm) ? uwerr(plat_en1[i]) : uwerr(plat_en1[i],wpm)
xx = collect(y0s[1]:length(en[1])+y0s[1]-1) xx = collect(y0s[1]:length(en[1])+y0s[1]-1)
println(length(en[1]))
v = value(plat_en0[i]) v = value(plat_en0[i])
e = err(plat_en0[i]) e = err(plat_en0[i])
v_vec = value(plat_en1[i]) # v_vec = value(plat_en1[i])
e_vec = err(plat_en1[i]) # e_vec = err(plat_en1[i])
errorbar(xx, value.(en[1]), err.(en[1]), fmt=">", mfc="none", capsize=2, ms=12, label=L"$M_{D_{(s)}}$") errorbar(xx, value.(en[1]), err.(en[1]), fmt=">", mfc="none", capsize=2, ms=12, label=L"$M_{D_{(s)}}$")
fill_between(plat_ps[1]+y0s[1]:plat_ps[2]+y0s[1], v-e, v+e, alpha=0.6 ) fill_between(plat_ps[1]+y0s[1]:plat_ps[2]+y0s[1], v-e, v+e, alpha=0.6 )
errorbar(xx[1:end-10], value.(en[2])[1:end-10], err.(en[2][1:end-10]), fmt="^",mfc="none", ms=12, capsize=2, label=L"$M_{D_{(s)}}^*$") # errorbar(xx[1:end-10], value.(en[2])[1:end-10], err.(en[2][1:end-10]), fmt="^",mfc="none", ms=12, capsize=2, label=L"$M_{D_{(s)}}^*$")
fill_between(plat_vec[1]+y0s[1]:plat_vec[2]+y0s[1], v_vec-e_vec, v_vec+e_vec, alpha=0.6 ) # fill_between(plat_vec[1]+y0s[1]:plat_vec[2]+y0s[1], v_vec-e_vec, v_vec+e_vec, alpha=0.6 )
xlabel(L"$x_0/a$") xlabel(L"$x_0/a$")
ylabel(L"$am_{\mathrm{eff}}$") ylabel(L"$am_{\mathrm{eff}}$")
title("$(ensembles(plat_en0[i])[1]) " * L"\mu_1="*"$(mu_list[i][1]) " *L" \mu_2="*"$(mu_list[i][2]) " ) title("$(ensembles(plat_en0[i])[1]) " * L"\mu_1="*"$(mu_list[i][1]) " *L" \mu_2="*"$(mu_list[i][2]) " )
# xlim(65, 110) # xlim(65, 110)
ylim(v-25*e, v+25*e) ylim(v-25*e, v+25*e)
legend(fontsize=20) # legend(fontsize=20)
display(gcf()) display(gcf())
t = "$(ensembles(plat_en0[i])[1])_m_eff_"*"mu_1=$(mu_list[i][1]) " *"_mu_2=$(mu_list[i][2]) "*".pdf" t = "$(ensembles(plat_en0[i])[1])_m_eff_"*"mu_1=$(mu_list[i][1]) " *"_mu_2=$(mu_list[i][2]) "*".pdf"
#savefig(joinpath(path_plot,t)) #savefig(joinpath(path_plot,t))
...@@ -309,6 +396,213 @@ function gevp_mass(mat_obs::Vector{MatInfo}, path_m_ps::String, path_m_vec::Stri ...@@ -309,6 +396,213 @@ function gevp_mass(mat_obs::Vector{MatInfo}, path_m_ps::String, path_m_vec::Stri
end end
return plat_en0, plat_en1 return plat_en0, plat_en1
end end
"""
gevp_mass_BMA(mat_obs::Vector{MatInfo}; t0::Int64=2,pl::Bool=true, wpm::Union{Nothing, Dict{String,Vector{Float64}}}=nothing)
This function takes as input a vector of MatInfo and for each of them solve the associated eigenvalue problem.
Then, the ground state energies extracted from the eigenvalues are fitted varying several time ranges and a Bayesian Model Average
is performed to asses a final result.
It can be used with both MatInfo with different gamma structure (comp_mat_multigamma) and with MatInfo with time shifts (comp_mat_tau_shift)
The method returns the weighted average of the ground state energy for each element of the vector of MatInfo.
"""
function gevp_mass_BMA(mat_obs::Vector{MatInfo}; tt0::Int64=2,pl::Bool=true, wpm::Union{Nothing, Dict{String,Vector{Float64}}}=nothing, path_plt::Union{String,Nothing}=nothing)
y0s = getfield.(mat_obs, :y0)
mu_list = getfield.(mat_obs, :mu)
en0 = Vector{uwreal}(undef, length(mat_obs))
en1 = Vector{uwreal}(undef, length(mat_obs))
data_tot = Vector(undef, length(mat_obs))
W_tot = Vector(undef, length(mat_obs))
@showprogress for k in eachindex(mat_obs)
t = string(L"$\mu_1 = $", mu_list[k][1],L" $\mu_2 = $", mu_list[k][2] )
mat = getfield(mat_obs[k], :mat_list) #[y0s[i]+1:end-1] #matrices to diagonalise for a given sector [i]
evals = juobs.getall_eigvals(mat, tt0)
# evecs = getall_eig(mat, t0)
entot = juobs.energies(evals, wpm=wpm)
@. gs_model(x,p) = p[1] #+ p[2] * exp(-(p[3])*x)
param = 1
tminaux = round.(Int64, collect(18:30) * sqrt(value(t0(mat_obs[k].ensinfo.beta) / t0(3.7))))
T = length(entot[1])
tmaxaux = round.(Int64, collect(8:20) * sqrt(value(t0(mat_obs[k].ensinfo.beta) / t0(3.7))))
tmax = T .- collect(reverse(tmaxaux))
tmax = tmax[1:3:end]
tmin = tminaux[1:2:end]
if !isnothing(path_plt)
pp1 = joinpath(path_plt, "plateaus", mat_obs[1].ensinfo.id, "mps", "mps_BMA_$(k).pdf")
pp2 = joinpath(path_plt, "plateaus", mat_obs[1].ensinfo.id, "mvec", "mvec_BMA_$(k).pdf")
else
pp1 = pp2 = nothing
end
en0[k], syst1, all_res1, FitDict1 = juobs.bayesian_av(gs_model, entot[1], tmin, tmax, param, pl=pl, wpm=wpm, data=true, label=L"$m_{\mathrm{ps}}$", path_plt=pp1, plt_title=t)
en1[k], syst2, all_res2, FitDict2 = juobs.bayesian_av(gs_model, entot[2], tmin, tmax, param, pl=pl, wpm=wpm, data=true, label=L"$m_{\mathrm{v}}$", path_plt=pp2, plt_title=t)
close("all")
if pl
for ii in 1:2 # loop over energies
try
if ii == 1
data = entot[1]
FitDict = FitDict1
all_res = all_res1
if !isnothing(path_plt)
path_plt_fin = joinpath(path_plt, "plateaus", mat_obs[1].ensinfo.id, "mps")
end
ll = L"$m_{\mathrm{ps}}$"
else
data = entot[2]
FitDict = FitDict2
all_res = all_res2
if !isnothing(path_plt)
path_plt_fin = joinpath(path_plt, "plateaus", mat_obs[1].ensinfo.id, "mvec")
end
ll = L"$m_{\mathrm{v}}$"
end
fig = figure(figsize=(10,7.5))
modstot = FitDict["mods"]
AIC = FitDict["AIC"]
Wtot = FitDict["W"]
IDX = partialsortperm(AIC, 1:3)
mods = modstot[IDX]
main_res = all_res[IDX]
W = Wtot[IDX]
isnothing(wpm) ? uwerr(data) : [uwerr(data[i],wpm) for i in eachindex(data)]
vv = value.(data)[1:end]
ee = err.(data)[1:end]
xx = collect(0:length(vv)-1)
errorbar(xx, vv, ee, fmt="d", mfc="none", color="black", capsize=2)
CC = ["forestgreen", "royalblue", "tomato"]
for (ii,trange) in enumerate(mods)
isnothing(wpm) ? uwerr(main_res[ii]) : uwerr(main_res[ii], wpm)
vaux = value(main_res[ii])
eaux = err(main_res[ii])
regex = r"([0-9]+),([0-9]+)"
aux = match(regex, trange)
fill_between(parse(Float64,aux[1]):parse(Float64,aux[2]), vaux-eaux, vaux+eaux, color=CC[ii], alpha=0.5, label=round(W[ii], digits=3))
end
axhline(y=value(main_res[1])-14*err(main_res[1]), xmin=(tmin[1])/length(xx), xmax=(tmin[end])/length(xx), ls="dashed", color="green")
axhline(y=value(main_res[1])-14.3*err(main_res[1]), xmin=(tmax[1])/length(xx), xmax=(tmax[end])/length(xx), ls="dashed", color="red")
text(tmin[1],value(main_res[1])-13*err(main_res[1]), L"$\{t_{\mathrm{min}}\}$" )
text(tmax[1],value(main_res[1])-13*err(main_res[1]), L"$\{t_{\mathrm{max}}\}$" )
# axvline(tmin[1], ls="dashed", color="green")
# axvline(tmax[end], ls="dashed", color="red")
legend(title="Weights")
title(t)
xlabel(L"$t/a$")
ylabel(ll)
xlim(xx[1], xx[end])
ylim(value(main_res[1]) -30*err(main_res[1]), value(main_res[1]) +30*err(main_res[1]))
twiny()
fm_time = round.((xx )[1:8:end] .* value(a(mat_obs[k].ensinfo.beta)), digits=3)
xticks(xx[1:8:end], fm_time)
# xticks()
xlabel(L"$t-t_0\ [\mathrm{fm}]$", fontsize=14)
display(fig)
if !isnothing(path_plt)
savefig(joinpath(path_plt_fin, "m$(k)_plateau.pdf"))
end
close()
catch
println("plot failed")
end
end
end
end
return en0, en1 #, data_tot, W_tot
end
"""
gevp_GPOF(ensinfo::EnsInfo, corr::Vector{juobs.Corr}; N::Int64=4, TA::Vector{Int64}=[2,4], TB::Vector{Int64}=[7,8])
This method takes as input an EnsInfo object and a vector of Correlators.
Then it calls comp_mat_GPOF to compute a matrix a la BMW. For each TA, TB, a gevp is solved and the corresponding eigenvectors are used to project the original correlators
to the ground state.
This function return a vector of vector of uwreal, where the first index correspond to the index in mass of the original corr vector passed as input,
while the second index labels different choices of ta and tb for the GEVP.
"""
function gevp_GPOF(ensinfo::EnsInfo, corr::Vector{juobs.Corr}; N::Int64=4, TA::Vector{Int64}=[2,4], TB::Vector{Int64}=[7,8])
mat_info = comp_mat_GPOF(ensinfo, corr, N=N)
y0 = getfield(corr[1], :y0)
mu = getfield(corr[1], :mu)
new_corr = Vector{Vector{Vector{uwreal}}}(undef, length(mat_info))
for i in eachindex(mat_info)
mat = getfield(mat_info[i], :mat_list)
new_corr[i] = Vector{Vector{uwreal}}(undef, 0)
for ta in TA
for tb in TB
evalues, evecs = juobs.uweigen(mat[ta], mat[tb], iter = 20)
aux_corr = [uwdot(juobs.transpose(evecs[:,N]), uwdot( mat[k], evecs[:,N]) )[1] for k in eachindex(mat)]
push!(new_corr[i], aux_corr)
end
end
end
return new_corr
end
"""
gevp_GPOF_BMA(ensinfo::EnsInfo, corr::Vector{juobs.Corr}; N::Int64=4, TA::Vector{Int64}=[2], TB::Vector{Int64}=[7,8], pl::Bool=true, wpm::Union{Nothing, Dict{String,Vector{Float64}}}=nothing)
This function takes as input an EnsInfo object and a vector of Corr.
A projection to the ground state using gevp_GPOF is built for each element of corr. Then the new_corr is used to compute effective maasses
and finally the latter are fitted several times by varying the time ranges. Eventually, a BMA is performed (bayesian_av) for each value of the mass.
It returns a vector of uwreal containing the weighted averaged results for each value of the mass.
"""
function gevp_GPOF_BMA(ensinfo::EnsInfo, corr::Vector{juobs.Corr}; N::Int64=4, TA::Vector{Int64}=[2], TB::Vector{Int64}=[7,8], pl::Bool=true, wpm::Union{Nothing, Dict{String,Vector{Float64}}}=nothing)
new_corr = gevp_GPOF(ensinfo, corr, N=N, TA=TA, TB=TB)
@. one_exp_fit(x,p) = p[1] + p[2]*exp(-p[3]*x)
Nparam=3
y0 = getfield(corr[1], :y0)
T = length(corr[1].obs) - y0
# fit time ranges for bayesian_av
tmin = collect(14:16)
tmax = collect(T-35:T-34)
MAve = Vector{uwreal}(undef, length(corr))
for k in eachindex(new_corr) # mass index
AIC = Vector{Float64}(undef, 0)
Masses = Vector{uwreal}(undef, 0)
for j in eachindex(new_corr[k]) # ta and tb gevp index
_, data_meff = juobs.meff(new_corr[k][j], [tmin[end], tmax[1]], pl=true, data=true, wpm=wpm)
_, _, param, _, aic = juobs.bayesian_av(one_exp_fit, data_meff, tmin, tmax, Nparam, pl=false, wpm=wpmm, data = true)
close("all")
AIC = vcat(AIC, aic )
Masses = vcat(Masses, param)
end
isnothing(wpm) ? uwerr.(Masses) : [uwerr(Masses[i], wpm) for i in eachindex(Masses)]
offset = minimum(AIC)
AIC = AIC .- offset
Wtot = exp.(-0.5 .* AIC)
Wtot /= sum(Wtot)
MAve[k] = sum(Masses .* Wtot)
isnothing(wpm) ? uwerr(MAve[k]) : uwerr(MAve[k], wpm)
if pl
subplot(211)
title(string(L"$\mu_1 = $", corr[k]. mu[1], L" $\mu_2 = $", corr[k]. mu[2]))
ax1 = gca()
setp(ax1.get_xticklabels(),visible=false) # Disable x tick labels
xx = collect(1:length(Masses))
vv = value.(Masses)
errorbar(xx, vv, err.(Masses), fmt="s")
aux1 = sum( Wtot .* Masses.^2)
aux2 = sum( Wtot .* Masses)^2
syst = sqrt(abs(value(aux1-aux2)))
fill_between(xx, value(MAve[k]) - err(MAve[k]), value(MAve[k]) + err(MAve[k]),color="red", alpha=0.2)
ylabel(L"$M_0$")
subplot(212)
plot(xx, Wtot)
ylabel(L"$W$")
xlabel("Models")
display(gcf())
close()
end
end
return MAve
end
function gevp_dec(mat_obs::Vector{MatInfo}, mass::Vector{uwreal}, path_plat::String; t0::Int64=2, wpm::Union{Nothing, Dict{Int64,Vector{Float64}}}=nothing, pl::Bool=true, n::Int64=1, pseudo::Bool=true, wilson::Bool=false) function gevp_dec(mat_obs::Vector{MatInfo}, mass::Vector{uwreal}, path_plat::String; t0::Int64=2, wpm::Union{Nothing, Dict{Int64,Vector{Float64}}}=nothing, pl::Bool=true, n::Int64=1, pseudo::Bool=true, wilson::Bool=false)
y0s = getfield.(mat_obs, :y0) y0s = getfield.(mat_obs, :y0)
mu_list = getfield.(mat_obs, :mu) mu_list = getfield.(mat_obs, :mu)
...@@ -334,6 +628,47 @@ function gevp_dec(mat_obs::Vector{MatInfo}, mass::Vector{uwreal}, path_plat::Str ...@@ -334,6 +628,47 @@ function gevp_dec(mat_obs::Vector{MatInfo}, mass::Vector{uwreal}, path_plat::Str
end end
return plat_dec0, data return plat_dec0, data
end end
function gevp_dec_BMA(mat_obs::Vector{MatInfo}, mass::Vector{uwreal}; t0::Int64=2, wpm::Union{Nothing, Dict{String,Vector{Float64}}}=nothing, pl::Bool=true, n::Int64=1, pseudo::Bool=true, wilson::Bool=false)
y0s = getfield.(mat_obs, :y0)
mu_list = getfield.(mat_obs, :mu)
plat_dec0 = Vector{uwreal}(undef, length(mat_obs))
data = Vector{Vector{uwreal}}(undef,0)
for i in eachindex(mat_obs)
mat = getfield(mat_obs[i], :mat_list) #matrices to diagonalise for a given sector [i]
evecs = getall_eig(mat, t0)
elem = mat_elem(evecs, mat, mass[i], n) #ground and excited state energy
push!(data, elem)
@. gs_model(x,p) = p[1] + p[2] * exp(-p[3]*x)
param = 3
tmin = collect(4:8) # scart from source
tmax = collect(40:2:50)
aux_plat_dec0, syst, fit_param, dict = juobs.bayesian_av(gs_model, elem, tmin, tmax, param, pl=pl, wpm=wpm, data=true, label=L"$f_{\mathrm{ps}}$")
if pl
uwerr.(elem)
vv = value.(elem)
ee = err.(elem)
xx = collect(1:length(vv))
errorbar(xx, vv, ee, fmt="*")
ylim(vv[50] - 0.2, vv[50] + 0.2)
display(gcf())
close()
end
#try
if pseudo
plat_dec0[i] = dec_automatic_plat(aux_plat_dec0, mass[i], mu_list[i], pl=pl, wilson=wilson)
else
plat_dec0[i] = vec_dec(elem, plat, mass[i], pl=pl)
end
#catch
# println("Decay constant for the ensemble ", mat_obs[i].ensinfo.id, " failed in the sector ", mu_list[i], " pseudo sector?", pseudo)
# println("The associated effective mass is ", mass[i])
# plat_dec0[i] = uwreal(0)
#end
end
return plat_dec0, data
end
function mat_elem(evec::Vector{Matrix{uwreal}}, ct_mat::Vector{Matrix{uwreal}}, mass::uwreal, n::Int64) function mat_elem(evec::Vector{Matrix{uwreal}}, ct_mat::Vector{Matrix{uwreal}}, mass::uwreal, n::Int64)
t = length(evec) t = length(evec)
res = Vector{uwreal}(undef, t) res = Vector{uwreal}(undef, t)
...@@ -366,6 +701,13 @@ function dec(mat_elem::Vector{uwreal}, plat::Array{Int64}, mass::uwreal, mu::Vec ...@@ -366,6 +701,13 @@ function dec(mat_elem::Vector{uwreal}, plat::Array{Int64}, mass::uwreal, mu::Vec
return sqrt(2/mass) * aux return sqrt(2/mass) * aux
end end
end end
function dec_automatic_plat(mat_elem::uwreal, mass::uwreal, mu::Vector{Float64}; pl::Bool=true, wilson::Bool=false)
if !wilson
return sqrt(2/ (mass)^3) * sum(mu)* mat_elem
else
return sqrt(2/mass) * mat_elem
end
end
function vec_dec(mat_elem::Vector{uwreal}, plat::Array{Int64}, mass::uwreal; pl::Bool=true) function vec_dec(mat_elem::Vector{uwreal}, plat::Array{Int64}, mass::uwreal; pl::Bool=true)
aux = plat_av(mat_elem, plat) aux = plat_av(mat_elem, plat)
if pl if pl
...@@ -418,6 +760,101 @@ function get_fstar_tm(obs::Vector{juobs.Corr}, m::Vector{uwreal}, ens::EnsInfo, ...@@ -418,6 +760,101 @@ function get_fstar_tm(obs::Vector{juobs.Corr}, m::Vector{uwreal}, ens::EnsInfo,
plat = select_plateau(ens, mu_list, path_plat) plat = select_plateau(ens, mu_list, path_plat)
return dec_const_w.(obs, obs, plat, m, pl=pl, wpm=wpm) return dec_const_w.(obs, obs, plat, m, pl=pl, wpm=wpm)
end end
"""
This function computes the decay constant for wilson twisted mass fermions and perform a
bayesian model average for plateau determination.
"""
function get_f_tm_BMA(corr::Vector{juobs.Corr}, m::Vector{uwreal}, ens::EnsInfo; pl::Bool=true, wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing,
path_plt::Union{String,Nothing}=nothing , ps::String="fps" )
F = Vector{uwreal}(undef, length(corr))
if !isnothing(path_plt) path_plt = joinpath(path_plt,"plateaus", ens.id, ps) end
@. const_fit(x,p) = p[1] #+ p[2]*exp(-p[3]*(x-corr[1].y0))
tminaux = round.(Int64, collect(15:32) * sqrt(value(t0(ens.beta) / t0(3.7))))
T = length(corr[1].obs)
tmaxaux = round.(Int64, collect(20:35) * sqrt(value(t0(ens.beta) / t0(3.7))))
tmax = T .- collect(reverse(tmaxaux))
tmax = tmax[1:3:end]
tmin = tminaux[1:2:end] .+ corr[1].y0
for k in eachindex(corr)
# tmin = collect(14:30) .+ens.y0
# tmax = collect(38:4:60) .+ens.y0
# if k==1
# tmin .-=10
# end
t = string(L"$f \ \mu_1 = $", corr[k].mu[1],L" $\mu_2 = $", corr[k].mu[2] )
plat = [tmin[end]-5,tmax[1]+5]
if ps=="fps"
_, data = dec_const_pcvc(corr[k], plat, m[k], pl=false, wpm=wpm, data=true)
else
_, data = dec_const(corr[k], plat, m[k], pl=false, wpm=wpm, data=true)
end
ll = ps == "fps" ? L"$f_{\mathrm{ps}}$" : L"$f_{\mathrm{v}}$"
name_bma = "f$(k)_BMA.pdf"
isnothing(path_plt) ? tt=nothing : tt = joinpath(path_plt,name_bma)
F[k], syst, all_res, FitDict = juobs.bayesian_av(const_fit, data, tmin, tmax, 1, pl=pl, wpm=wpm, data=true, path_plt=tt, plt_title=t, label=ll )
if pl
try
fig = figure(figsize=(10,7.5))
modstot = FitDict["mods"]
AIC = FitDict["AIC"]
Wtot = FitDict["W"]
IDX = partialsortperm(AIC, 1:3)
mods = modstot[IDX]
main_res = all_res[IDX]
W = Wtot[IDX]
isnothing(wpm) ? uwerr(data) : [uwerr(data[i],wpm) for i in eachindex(data)]
vv = value.(data)[corr[1].y0:end]
ee = err.(data)[corr[1].y0:end]
xx = collect(0:length(vv)-1) .+ corr[1].y0
errorbar(xx, vv, ee, fmt="d", mfc="none", color="black", capsize=2)
CC = ["forestgreen", "royalblue", "tomato"]
for (ii,trange) in enumerate(mods)
isnothing(wpm) ? uwerr(main_res[ii]) : uwerr(main_res[ii], wpm)
vaux = value(main_res[ii])
eaux = err(main_res[ii])
regex = r"([0-9]+),([0-9]+)"
aux = match(regex, trange)
fill_between(parse(Float64,aux[1]):parse(Float64,aux[2]), vaux-eaux, vaux+eaux, color=CC[ii], alpha=0.5, label=round(W[ii], digits=3))
end
axhline(y=value(main_res[1])-14*err(main_res[1]), xmin=(tmin[1]-corr[1].y0)/length(xx), xmax=(tmin[end]-corr[1].y0)/length(xx), ls="dashed", color="green")
axhline(y=value(main_res[1])-14*err(main_res[1]), xmin=(tmax[1]-corr[1].y0)/length(xx), xmax=(tmax[end]-corr[1].y0)/length(xx), ls="dashed", color="red")
text(tmin[1],value(main_res[1])-13*err(main_res[1]), L"$\{t_{\mathrm{min}}\}$" )
text(tmax[1],value(main_res[1])-13*err(main_res[1]), L"$\{t_{\mathrm{max}}\}$" )
# axvline(tmin[1], ls="dashed", color="green")
# axvline(tmax[end], ls="dashed", color="red")
legend(title="Weights")
title(t)
xlabel(L"$t/a$")
ylabel(ll)
xlim(xx[1], xx[end])
ylim(value(main_res[1]) -20*err(main_res[1]), value(main_res[1]) +20*err(main_res[1]))
twiny()
xlim(xx[1], xx[end])
fm_time = round.((xx .- corr[1].y0)[1:8:end] .* value(a(ens.beta)), digits=3)
xticks(xx[1:8:end], fm_time)
# xticks()
xlabel(L"$t-t_0\ [\mathrm{fm}]$", fontsize=14)
display(fig)
if !isnothing(path_plt)
savefig(joinpath(path_plt, "f$(k)_plateau.pdf"))
end
close()
catch
println("plot failed")
end
end
end
return F
end
function select_plateau(ensinf::EnsInfo, mu_list, path_plat) function select_plateau(ensinf::EnsInfo, mu_list, path_plat)
ens =ensinf.id ens =ensinf.id
deg = ensinf.deg deg = ensinf.deg
...@@ -595,42 +1032,50 @@ function select_plateau_w(ensinf::EnsInfo, kappa_list) ...@@ -595,42 +1032,50 @@ function select_plateau_w(ensinf::EnsInfo, kappa_list)
end end
function match_muc(muh, m_lh, m_sh, target) function match_muc(muh, m_lh, m_sh, target; wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing)
M = (2/3 .* m_lh .+ 1/3 .* m_sh) M = (2/3 .* m_lh .+ 1/3 .* m_sh)
par, chi2exp = lin_fit(muh, M) par, chi2exp = lin_fit(muh, M, wpm=wpm)
muh_target = x_lin_fit(par, target) muh_target = x_lin_fit(par, target)
return muh_target return muh_target
end end
function aic_weight(aic) function aic_weight(aic)
w_aux = exp.(-1/2 * (aic / minimum(aic) )) #/minimum(aic) -> +0.5*mininum(aic) w_aux = exp.(-1/2 * aic)
w_aux1=filter(x->x<10000, w_aux) w_aux ./= sum(w_aux)
index = findall(x->x<10000, w_aux) idx_in = sortperm(w_aux, rev=true)
norm = sum(w_aux1) cum_w = cumsum(w_aux[idx_in])
w = w_aux1 ./ norm println(cum_w[end])
return w, index stop = findfirst(x->x>=0.999, cum_w)
end idx = sort(idx_in[1:stop])
function aic_weight(c::Cat) w = w_aux[idx] ./ sum(w_aux[idx])
aic = c.aic # w = w_aux ./ sum(w_aux)
w_aux = exp.(-1/2 * (aic / minimum(aic) ) ) #/minimum(aic) -> +0.5*mininum(aic) return w , idx# idx_in[1:stop]
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 end
aic_weight(c::Cat) = aic_weight(c.aic)
# function aic_weight(c::Cat)
# aic = c.aic
# w_aux = exp.(-1/2 * aic)
# w_aux = exp.(-1/2 * (aic .- minimum(aic)))
# w_aux = exp.(-1/2 * (aic ./ minimum(aic))) # used at LAT22
# 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(aic, fit_res) function aic_syst(aic, fit_res)
w,index = aic_weight(aic) w,index = aic_weight(aic)
aux1 = sum( w .* fit_res[index].^2) aux1 = sum( w .* fit_res[index].^2)
aux2 = sum( w .* fit_res[index])^2 aux2 = sum( w .* fit_res[index])^2
return sqrt(abs(value(aux1 - aux2))) return sqrt(abs(value(aux1 - aux2)))
end end
function aic_syst(c::Cat) aic_syst(c::Cat) = aic_syst(c.aic, c.fit_res)
w,index = aic_weight(c.aic) # function aic_syst(c::Cat) = aic_syst(c.aic. c.fit_res)
aux1 = sum( w .* c.fit_res[index].^2) # w,index = aic_weight(c.aic)
aux2 = sum( w .* c.fit_res[index])^2 # aux1 = sum( w .* c.fit_res[index].^2)
return sqrt(abs(value(aux1 - aux2))) # aux2 = sum( w .* c.fit_res[index])^2
end # return sqrt(abs(value(aux1 - aux2)))
# end
function aic_model_ave(aic, fit_res, wpm::Union{Nothing, Dict}=nothing) function aic_model_ave(aic, fit_res, wpm::Union{Nothing, Dict}=nothing)
w, index = aic_weight(aic) w, index = aic_weight(aic)
...@@ -638,12 +1083,13 @@ function aic_model_ave(aic, fit_res, wpm::Union{Nothing, Dict}=nothing) ...@@ -638,12 +1083,13 @@ function aic_model_ave(aic, fit_res, wpm::Union{Nothing, Dict}=nothing)
isnothing(wpm) ? uwerr(res) : uwerr(res, wpm) isnothing(wpm) ? uwerr(res) : uwerr(res, wpm)
return res return res
end end
function aic_model_ave(c::Cat, wpm::Union{Nothing, Dict}=nothing) aic_model_ave(c::Cat, wpm::Union{Nothing,Dict}=nothing) = aic_model_ave(c.aic, c.fit_res, wpm)
w, index = aic_weight(c) # function aic_model_ave(c::Cat, wpm::Union{Nothing, Dict}=nothing)
res = sum( w.* getfield(c, :fit_res)[index]) # w, index = aic_weight(c)
isnothing(wpm) ? uwerr(res) : uwerr(res, wpm) # res = sum( w.* getfield(c, :fit_res)[index])
return res # isnothing(wpm) ? uwerr(res) : uwerr(res, wpm)
end # return res
# end
function category_av(cat_arr::Vector{Cat}) function category_av(cat_arr::Vector{Cat})
best_res = aic_model_ave.(cat_arr) best_res = aic_model_ave.(cat_arr)
syst = aic_syst.(cat_arr) syst = aic_syst.(cat_arr)
...@@ -690,7 +1136,7 @@ end ...@@ -690,7 +1136,7 @@ end
function fit_over_cat!(cat_tot::Vector{Cat}, models::Vector{Vector{Function}}, phi2_phys::uwreal, model_param::Vector{Int64} ; decay::Bool=false, function fit_over_cat!(cat_tot::Vector{Cat}, models::Vector{Vector{Function}}, phi2_phys::uwreal, model_param::Vector{Int64} ; decay::Bool=false,
weight_dof::Int64=2, xycovar::Bool=false, correlated_fit::Bool=false, Mrat::uwreal=uwreal(1.0), weight_dof::Int64=2, xycovar::Bool=false, correlated_fit::Bool=false, Mrat::uwreal=uwreal(1.0),
wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing, small_sample::Bool=false) wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing, IC::String="AIC_small_sample")
models = vcat(models...) models = vcat(models...)
...@@ -707,23 +1153,31 @@ function fit_over_cat!(cat_tot::Vector{Cat}, models::Vector{Vector{Function}}, p ...@@ -707,23 +1153,31 @@ function fit_over_cat!(cat_tot::Vector{Cat}, models::Vector{Vector{Function}}, p
for (i, mod) in enumerate(models) for (i, mod) in enumerate(models)
if !xycovar # correlation between x and y if !xycovar # correlation between x and y
if !correlated_fit if !correlated_fit
fit_params, chi2_vs_chi2exp = juobs.fit_routine(mod, value.(cat.x_tofit), cat.obs, model_param[i], wpm=wpm) fit_params, chi2, chi2exp = juobs.fit_routine(mod, value.(cat.x_tofit), cat.obs, model_param[i], wpm=wpm)
else else
cov_inv = juobs.inv_covar_multi_id(cat.obs) cov_inv = juobs.inv_covar_multi_id(cat.obs)
fit_params, chi2_vs_chi2exp = juobs.fit_routine(mod, value.(cat.x_tofit), cat.obs, model_param[i], inv_cov=cov_inv, wpm=wpm) fit_params, chi2, chi2exp = juobs.fit_routine(mod, value.(cat.x_tofit), cat.obs, model_param[i], inv_cov=cov_inv, wpm=wpm)
end end
else else
fit_params, chi2_vs_chi2exp = juobs.fit_routine(mod, cat.x_tofit, cat.obs, model_param[i], covar=true, wpm=wpm) fit_params, chi2, chi2exp = juobs.fit_routine(mod, cat.x_tofit, cat.obs, model_param[i], covar=true, wpm=wpm)
end end
val_mod_i = continuum_dependece(fit_params, phi2_phys, cat.phih_ph) val_mod_i = continuum_dependece(fit_params, phi2_phys, cat.phih_ph)
push!(cat.dof, length(cat.obs)-model_param[i] ) push!(cat.dof, length(cat.obs)-model_param[i] )
if !small_sample if IC == "AIC_small_sample"
AIC = chi2_vs_chi2exp * cat.dof[i] + weight_dof * model_param[i] ic = chi2 / chi2exp * cat.dof[i] + weight_dof * model_param[i] + ( weight_dof*model_param[i]^2 + weight_dof*model_param[i]) / (length(cat.obs)- model_param[i] -1)
else elseif IC == "AIC"
AIC = chi2_vs_chi2exp * cat.dof[i] + weight_dof * model_param[i] + ( weight_dof*model_param[i]^2 + weight_dof*model_param[i]) / (length(cat.obs)- model_param[i] -1) ic = chi2 + 2*model_param[i] #chi2 / chi2exp * cat.dof[i] + weight_dof * model_param[i]
elseif IC == "TIC"
ic = chi2 - 2*chi2exp
end end
tmp = [val_mod_i, fit_params, chi2_vs_chi2exp, model_param[i], AIC] #
# if !small_sample
# AIC = chi2_vs_chi2exp * cat.dof[i] + weight_dof * model_param[i]
# else
# AIC = chi2_vs_chi2exp * cat.dof[i] + weight_dof * model_param[i] + ( weight_dof*model_param[i]^2 + weight_dof*model_param[i]) / (length(cat.obs)- model_param[i] -1)
# end
tmp = [val_mod_i, fit_params, chi2/chi2exp, model_param[i], ic]
symb = [:fit_res, :fit_param, :chi2_vs_exp, :n_param, :aic] symb = [:fit_res, :fit_param, :chi2_vs_exp, :n_param, :aic]
for (k,ss) in enumerate(symb) for (k,ss) in enumerate(symb)
push!(getfield(cat, ss), tmp[k] ) push!(getfield(cat, ss), tmp[k] )
...@@ -736,14 +1190,17 @@ function Base.:*(x::uwreal, y::Array{Any}) ...@@ -736,14 +1190,17 @@ function Base.:*(x::uwreal, y::Array{Any})
N = size(y, 1) N = size(y, 1)
return fill(x, N) .* y return fill(x, N) .* y
end end
Base.:*(x::Array{Any}, y::uwreal) = Base.:*(y,x)
function Base.:*(x::uwreal, y::Array{Float64}) function Base.:*(x::uwreal, y::Array{Float64})
N = size(y, 1) N = size(y, 1)
return fill(x, N) .* y return fill(x, N) .* y
end end
Base.:*(x::Array{Float64}, y::uwreal) = Base.:*(y,x)
function Base.:*(x::uwreal, y::Array{uwreal}) function Base.:*(x::uwreal, y::Array{uwreal})
N = size(y, 1) N = size(y, 1)
return fill(x, N) .* y return fill(x, N) .* y
end end
Base.:*(x::Array{uwreal}, y::uwreal) = Base.:*(y,x)
function Base.:+(x::uwreal, y::Vector{uwreal}) function Base.:+(x::uwreal, y::Vector{uwreal})
N = size(y, 1) N = size(y, 1)
return fill(x, N) .+ y return fill(x, N) .+ y
......
mutable struct EnsInfo @kwdef mutable struct EnsInfo
id::String id::String
L::Int64 L::Int64
beta::Float64 beta::Float64
deg::Bool deg::Bool
mpi::Float64 mpi::Float64
dtr::Int64 dtr::Int64
idm_corr::Union{Int64, Nothing}
trunc::Union{Int64, Vector{Int64}, Nothing} trunc::Union{Int64, Vector{Int64}, Nothing}
function EnsInfo(ens_id::String, info::Vector{Float64}) function EnsInfo(ens_id::String, info)
id = ens_id id = ens_id
L = info[1] L = info[1]
beta = info[2] beta = info[2]
deg = info[3] deg = info[3]
mpi = info[4] mpi = info[4]
dtr = info[5] dtr = info[5]
return new(id, L, beta, deg, mpi, dtr, nothing) idm_corr = info[6]
return new(id, L, beta, deg, mpi, dtr, idm_corr, nothing)
end end
function EnsInfo(ens_id::String, info::Vector{Float64}, trunc::Union{Nothing, Int64, Vector{Int64}}) function EnsInfo(ens_id::String, info, trunc::Union{Nothing, Int64, Vector{Int64}},)
id = ens_id id = ens_id
L = info[1] L = info[1]
beta = info[2] beta = info[2]
deg = info[3] deg = info[3]
mpi = info[4] mpi = info[4]
dtr = info[5] dtr = info[5]
return new(id, L, beta, deg, mpi, dtr, trunc) idm_corr = info[6]
return new(id, L, beta, deg, mpi, dtr, idm_corr, trunc)
end end
end end
mutable struct EnsObs mutable struct EnsObs
......
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