Execute 2D model construction Literate tutorial with plots#42
Execute 2D model construction Literate tutorial with plots#42mmikhasenko wants to merge 4 commits into
Conversation
Enable Literate execution so the tutorial renders cell outputs and a saved figure asset, fix constructor argument order after #40, import extended NLL for method extension, and pin DistributionsHEP to a revision that exports ExtendedMixtureModel. Co-authored-by: Cursor <cursoragent@cursor.com>
Replace the manual figure save/asset workaround with a plain Plots layout picked up by Literate, and relax Documenter's HTML size threshold so the generated tutorial page can embed the plot output. Co-authored-by: Cursor <cursoragent@cursor.com>
Use a side-by-side model heatmap and data histogram2d with themed 1D projection panels, without overlaying scatter on the density map. Co-authored-by: Cursor <cursoragent@cursor.com>
Explain how two_dimensional_model.jl defines the 1D shapes, extended 2D assembly, and NLL wrapper before the tutorial builds constructor instances. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Code Review
This pull request replaces the plotting backend in the documentation from CairoMakie to Plots.jl, updates the project and manifest files accordingly, and enables execution of the literate tutorial. It also significantly expands the tutorial documentation explaining the 2D model construction. The feedback suggests minor code improvements: removing an unnecessary collect call on a range to avoid redundant memory allocation, and adding explicit labels to the 1D projection plots to prevent unprofessional default legends.
| hm = heatmap!(ax, mass_grid, mass_grid, density_grid) | ||
| scatter!(ax, fit_df.mKK1, fit_df.mKK2; markersize = 2, color = (:white, 0.35)) | ||
| Colorbar(fig[1, 2], hm, label = "extended density") | ||
| mass_grid = collect(range(KK_LIMITS[1], KK_LIMITS[2]; length = 160)) |
There was a problem hiding this comment.
Unnecessary collect call on the range. In Julia, range returns a lazy StepRangeLen which is an AbstractVector. Most operations (such as comprehensions, broadcasting, and plotting in Plots.jl) work perfectly fine with ranges directly without allocating an array. Removing collect avoids unnecessary memory allocation.
mass_grid = range(KK_LIMITS[1], KK_LIMITS[2]; length = 160)| p_m1 = histogram( | ||
| fit_df.mKK1; | ||
| bins = 60, | ||
| fillcolor = :steelblue, | ||
| fillalpha = 0.45, | ||
| linecolor = :steelblue, | ||
| linewidth = 0.5, | ||
| xlabel = "m(K⁺K⁻)₁ [GeV]", | ||
| ylabel = "events / bin", | ||
| title = "m(K⁺K⁻)₁ projection", | ||
| ) | ||
| plot!(p_m1, mass_grid, projection_1 .* bin_scale; color = :black) |
There was a problem hiding this comment.
The 1D projection plots do not specify labels for the histogram and the model curve. By default, Plots.jl will generate legends with default names like y1, which looks unprofessional in the documentation. Specifying explicit labels (e.g., label = "Data" and label = "Model") will make the plots much clearer and more professional.
p_m1 = histogram(
fit_df.mKK1;
bins = 60,
fillcolor = :steelblue,
fillalpha = 0.45,
linecolor = :steelblue,
linewidth = 0.5,
xlabel = "m(K⁺K⁻)₁ [GeV]",
ylabel = "events / bin",
title = "m(K⁺K⁻)₁ projection",
label = "Data",
)
plot!(p_m1, mass_grid, projection_1 .* bin_scale; color = :black, label = "Model")| p_m2 = histogram( | ||
| fit_df.mKK2; | ||
| bins = 60, | ||
| fillcolor = :darkorange, | ||
| fillalpha = 0.45, | ||
| linecolor = :darkorange, | ||
| linewidth = 0.5, | ||
| xlabel = "m(K⁺K⁻)₂ [GeV]", | ||
| ylabel = "events / bin", | ||
| title = "m(K⁺K⁻)₂ projection", | ||
| ) | ||
| plot!(p_m2, mass_grid, projection_2 .* bin_scale; color = :black) |
There was a problem hiding this comment.
The 1D projection plots do not specify labels for the histogram and the model curve. By default, Plots.jl will generate legends with default names like y1, which looks unprofessional in the documentation. Specifying explicit labels (e.g., label = "Data" and label = "Model") will make the plots much clearer and more professional.
p_m2 = histogram(
fit_df.mKK2;
bins = 60,
fillcolor = :darkorange,
fillalpha = 0.45,
linecolor = :darkorange,
linewidth = 0.5,
xlabel = "m(K⁺K⁻)₂ [GeV]",
ylabel = "events / bin",
title = "m(K⁺K⁻)₂ projection",
label = "Data",
)
plot!(p_m2, mass_grid, projection_2 .* bin_scale; color = :black, label = "Model")
Related issues
There is no related issue.
Checklist
I am following the contributing guidelines
Tests are passing
Lint workflow is passing
Docs were updated and workflow is passing
Summary
examples/2d_distribution_fit/src/two_dimensional_model.jldefines the model with@with_parameters, including the 1D shapes, extended 2D yield components, and NLL wrapper.ConstructorOfFit2DExtendedKKComponentsargument order andextended_negative_log_likelihoodimport so executed Literate blocks succeed.theme(:boxed), a model heatmap plus datahistogram2d, and 1D projection panels.docs/Manifest.tomlto aDistributionsHEPrevision exportingExtendedMixtureModel, and relax Documentersize_thresholdfor the generated tutorial page.Test plan
julia --project=docs docs/generate_literate.jljulia --project=docs docs/make.jlMade with Cursor