Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot unfolded data and model #111

Merged
merged 7 commits into from
Jun 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: unfolded spectrum (wip with Fergus's edits)
phajy committed Jun 15, 2024
commit b0fa1e28ea0bbb702106b429d766b922b3544569
27 changes: 14 additions & 13 deletions src/plots-recipes.jl
Original file line number Diff line number Diff line change
@@ -224,11 +224,20 @@ end

result = r.args[1] isa FittingResult ? r.args[1][1] : r.args[1]
data = get_dataset(result)
x = plotting_domain(data)
model = get_model(result)

x_plot = plotting_domain(data)
y = invoke_result(result, result.u)
x_domain = make_output_domain(ContiguouslyBinned(), data)
# TODO: pass the result.u to invokemodel (currently not possible without knowing frozen paramters)
update_model!(model, result)
y_unfolded = invokemodel(x_domain, model)[data.data.data_mask]

unfolded_spectrum = @. x_plot^0 * result.objective * (y_unfolded / y)
unfolded_std = @. sqrt(result.variance) * x_plot^0 * result.objective * (y_unfolded / y)

y_unfolded = @. x^2 * result.objective / y # <-- allow power of x to be a parameter
# TODO: multiply this by the unfolded model
unfolded_spectrum = @. y_unfolded
unfolded_std = @. unfolded_spectrum / 100

ylabel --> "Unfolded spectrum [E F_E]" # <-- check units
xlabel --> "Energy (keV)"
@@ -238,23 +247,15 @@ end
label = make_label(data)
end

@series begin
linestyle --> :dash
seriestype --> :hline
label --> false
color --> modelcolor
[1.0]
end

@series begin
markerstrokecolor --> datacolor
label --> label
seriestype --> :scatter
markershape --> :none
markersize --> 0.5
yerror --> @. sqrt(result.variance) * x^2 * result.objective / y
yerror --> unfolded_std
xerror --> SpectralFitting.bin_widths(data) ./ 2
x, y_unfolded
x_plot, unfolded_spectrum
end
end