Commit a8a14206 authored by Antonino D'Anna's avatar Antonino D'Anna

Updated meff to use plot_data and plot_func. Now the function output also...

Updated meff to use plot_data and plot_func. Now the function output also fig,ax if pl is true. Updated documentation
parent 0e6b14b7
@doc raw"""
meff(corr::Vector{uwreal}, plat::Vector{Int64}; pl::Bool=true, data::Bool=false, wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing)
@doc raw"""
meff(corr::Vector{uwreal}, plat::Vector{Int64}; pl::Bool=false, data::Bool=false,
mu::Union{Vector{Float64}, Nothing}=nothing, kappa::Union{Vector{Float64}, Nothing}=nothing,
wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing, savepl::Bool=false,
filename::String="",plot_kw...)
meff(corr::Corr, plat::Vector{Int64}; kwargs..)
meff(corr::Corr, plat::Vector{Int64}; pl::Bool=true, data::Bool=false, wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing)
meff(corr::Vector{Corr},plat::Vector{Vector{Int64}}; kwargs...)
Computes effective mass for a given correlator corr at a given plateau `plat`.
Computes the mass associated to given correlator `corr` at a given plateau `plat`.
Correlator can be passed as an `Corr` struct or `Vector{uwreal}`.
In case of Vector{Corr} it is better to not broadcast, especially in case of `data=true` or `pl=true`, since the the overloaded function for Vector{Corr} takes care of the extra outputs and organize them into a `Tuple` of Vector
# Arguments
- `pl::Bool=false` and `savepl::Bool=false`: show and save the plots. The plots are made through the functions `plot_data` and `plot_func`. It is possible to pass keyword arguments for these two functions.
When `savepl = true`, the plots are saved and closed. When `pl = true` the plot are generated, displayed and the last two returns are always `fig,ax` object to allow more costumability.
If both are `true`, `pl` is ignored.
The flags `pl` and `data` allow to show the plots and return data as an extra result.
See also: [`plot_data`](@ref), [`plot_funct`](@ref).
- `data::Bool=false`: if set to `true`, the second return is a vector with the effective mass.
- `filename::String=""`: if given, overrides the automatically generated filename. `mkpath(dirname(filename))` is called before saving. If not given, a folder "meff/" is made and the correlator `μ` or `κ` are used to name the figure
# Examples
- with one correlator
```@example
data = read_mesons(path, "G5", "G5")
corr_pp = corr_obs.(data)
m = meff(corr_pp[1], [50, 60], pl=false)
data = read_mesons(path, "G5", "G5")[1]
corr_pp = corr_obs(data)
m = meff(corr_pp, [50, 60]) # return only meff
```
- with more correlator, making plots and returning data vector too
```@example
data = read_mesons(path, "G5", "G5")
corr_pp = corr_obs.(data)
m,fig,ax = meff(corr_pp, [[50, 60] for eachindex(corr_pp), pl=true)
# return meff, a vector of fig obj and a vector of ax obj
m,data = meff(corr_pp[1], [50, 60], pl=true,data=true, savepl=true)
# since pl and savepl are both true, pl is ignored, the plot is generated and saved
# the second arguments is given by the data vector
```
- with more correlator, making plots and returning effective PCAC masses
```@example
data_pp = read_mesons(path, "G5", "G5")
corr_pp = corr_obs.(data_pp)
m, data,fig,ax = meff(corr_a0p, corr_pp, [[50, 60] for eachindex(corr_pp), pl=true,data=true)
#the return is a Vector{uwreal} with the pseudoscalar masses, a Vector{Vector{uwreal}} with the effective ,
#a Vector{Figure} with the figure objects and a Vector{PyPlot.PyCall.PyObject} with the axes objects
```
"""
function meff(corr::Vector{uwreal}, plat::Vector{Int64}; pl::Bool=true, data::Bool=false,
mu::Union{Vector{Float64}, Nothing}=nothing, kappa::Union{Vector{Float64}, Nothing}=nothing,
wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing, savepl::Bool=false,
label::Union{String, Nothing}=nothing,)
dim = length(corr)
aux = 0.5 .* log.((corr[2:dim-2] ./ corr[3:dim-1]).^2)
mass = plat_av(aux, plat, wpm)
if pl || savepl
isnothing(wpm) ? uwerr(mass) : uwerr(mass, wpm)
x = 1:length(aux)
y = abs.(value.(aux))
dy = err.(aux)
v = abs(value(mass))
e = err(mass)
filename = "meff/";
fig,ax = subplots(1)
ax.fill_between(plat[1]:plat[2], v-e, v+e, color="green", alpha=0.75)
l,=ax.errorbar(x, y, dy, fmt="x", color="black")
if !isnothing(label)
l.set_label(label)
ax.legend()
filename*=label*"_"
end
ax.set_ylabel(L"$m_\mathrm{eff}$")
ax.set_xlabel(L"$x_0$")
_, max_idx = findmax(value.(corr))
ax.set_ylim(v-20*e, v+20*e)
ax.set_xlim(left=max_idx)
function meff(corr::Vector{uwreal}, plat::Vector{Int64}; pl::Bool=false, data::Bool=false,
mu::Union{Vector{Float64}, Nothing}=nothing, kappa::Union{Vector{Float64}, Nothing}=nothing,
wpm::Union{Dict{Int64,Vector{Float64}},Dict{String,Vector{Float64}}, Nothing}=nothing, savepl::Bool=false,
filename::String="",plot_kw...)
dim = length(corr)
aux = 0.5 .* log.((corr[2:dim-2] ./ corr[3:dim-1]).^2)
mass = plat_av(aux, plat, wpm)
if pl || savepl
abs_mass = abs2(mass);
isnothing(wpm) ? uwerr(abs_mass) : uwerr(abs_mass, wpm)
v,e = value(abs_mass), err(abs_mass);
x = [_ for _ in eachindex(aux)]
fig,ax = plot_data(abs2.(aux),x;plot_kw...)
fig,ax = plot_func(x->abs_mass,x[plat[1]:plat[2]],figs=(fig,ax) ;plot_kw...)
if !isnothing(kappa)
title(string(L"$\kappa_1 = $", kappa[1], L" $\kappa_2 = $", kappa[2]))
filename*="kappa_1_$(kappa[1])_kappa_2_$(kappa[2]).png"
end
if !isnothing(mu)
title(string(L"$\mu_1 = $", mu[1], L" $\mu_2 = $", mu[2]))
filename*="mu_1_$(mu[1])_mu_2_$(mu[2]).png"
end
if savepl
fig.tight_layout()
fig.set_size_inches(10,5)
mkpath(dirname(filename));
fig.savefig(filename)
close(fig)
else
display(gcf())
end
# close("all")
end
if pl && !savepl
return data ? (mass,aux,fig,ax) : (mass,fig,ax)
else
return data ? (mass,aux) : mass
end
if !haskey(plot_kw,:title)
temp = isnothing(kappa) ? L"$\mu_1 = %$(mu[1])$ $\mu_2 = %$(mu[2])$" : L"$\kappa_1 = %$(kappa[1])$ $\kappa_2 = %$(kappa[2])$"
fig.suptitle(temp);
end
if !haskey(plot_kw,:ylabel)
ax.set_ylabel(L"$m_\mathrm{eff}$")
end
if !haskey(plot_kw,:xlabel)
ax.set_xlabel(L"$x_0$")
end
_, max_idx = findmax(value.(corr))
ax.set_xlim(left=max_idx)
ax.set_ylim(v-20*e,v+20*e)
if savepl
fig.tight_layout();
if filename ==""
filename = "meff/"
filename *= isnothing(kappa) ? "" : "kappa_1_$(kappa[1])_kappa_2_$(kappa[2]).png"
filename *= isnothing(mu) ? "" : "mu_1_$(mu[1])_mu_2_$(mu[2]).png"
end
mkpath(dirname(filename))
fig.savefig(filename)
close(fig)
elseif pl
display(fig);
end
end
if pl && !savepl
return data ? (mass,aux,fig,ax) : (mass,fig,ax)
else
return data ? (mass,aux) : mass
end
end
function meff(corr::Corr, plat::Vector{Int64}; kwargs...)
......@@ -79,8 +108,8 @@ function meff(corr::Corr, plat::Vector{Int64}; kwargs...)
end
end
function meff(pp::Vector{Corr},plat::Vector{Vector{Int64}}; kwargs...)
a = meff.(pp,plat; kwargs...)
function meff(corr::Vector{Corr},plat::Vector{Vector{Int64}}; kwargs...)
a = meff.(corr,plat; kwargs...)
if length(a[1])==1
return a
end
......@@ -114,7 +143,7 @@ end
Computes the bare PCAC mass for a given correlator `a0p` and `pp` at a given plateau `plat`.
Correlator can be passed as an `Corr` struct or `Vector{uwreal}`.
In case of Vector{Corr} it is better to not broadcast, espectially in case of `data=true` or `pl=true`, since the the overloaded function for Vector{Corr} takes care of the extra outputs and organize them into a `Tuple` of Vector
In case of Vector{Corr} it is better to not broadcast, especially in case of `data=true` or `pl=true`, since the the overloaded function for Vector{Corr} takes care of the extra outputs and organize them into a `Tuple` of Vector
The return structure is: mpcac[,data][,figs,axs]
......@@ -183,10 +212,11 @@ function mpcac(a0p::Vector{uwreal}, pp::Vector{uwreal}, plat::Vector{Int64}; ca:
aux = der_a0p ./ ( 2. .* corr_pp[3:end-2])
mass = plat_av(aux, plat, wpm)
if pl|| savepl
x = [_ for _ in eachindex(aux)]
fig,ax = plot_data(aux,x,wpm=wpm,ylabel =L"$m_\mathrm{PCAC}$",xlabel=L"$x_0$";plot_kw...)
isnothing(wpm) ? uwerr(mass) : uwerr(mass,wpm)
fig,ax = plot_func(x->mass,[plat[1]:plat[2]...],figs=(fig,ax);plot_kw...)
if !isnothing(kappa)
fig.suptitle(string(L"$\kappa_1 = $", kappa[1], L" $\kappa_2 = $", kappa[2]))
......@@ -195,9 +225,6 @@ function mpcac(a0p::Vector{uwreal}, pp::Vector{uwreal}, plat::Vector{Int64}; ca:
fig.suptitle(string(L"$\mu_1 = $", mu[1], L" $\mu_2 = $", mu[2]))
end
_, max_idx = findmax(value.(pp))
isnothing(wpm) ? uwerr(mass) : uwerr(mass,wpm)
v,e = value(mass), err(mass)
ax.set_ylim(v-20*e, v+20*e)
ax.set_xlim(left=max_idx)
if savepl
......
......@@ -32,7 +32,7 @@ It return a tuple `fig,ax` to easily allow any modification to the plot.
xdata2 = [uwreal([x,0.1], "xdata") for x in xdata];
fig,ax = data_plot(ydata2,xdata2,label=L"$\cos(\frac{x*\pi}{10}$",figs = (fig,ax))
```
See also [`plot_func`](@ref)
See also: [`plot_func`](@ref)
"""
function plot_data(data::Vector{uwreal},xdata::Vector{T} where T <: Real;
wpm::Union{Dict{String, Vector{Float64}},Nothing} = nothing,
......@@ -108,7 +108,7 @@ It returns a tuple with `fig,ax` to easiy edit the plot
f(x) = uwreal([sin(x*0.1*π),0.1],"sin")
fig,ax = plot_func(f,xdata,label=L"\sin(\frac{x*\pi}{10})")
```
See also [`plot_data`](@ref)
See also: [`plot_data`](@ref)
"""
function plot_func(f::Function, xdata::Vector{T} where T<:Real;
wpm::Union{Dict{String,Vector{Float64}},Nothing} = nothing,
......
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