Skip to content

Execute 2D model construction Literate tutorial with plots#42

Closed
mmikhasenko wants to merge 4 commits into
mainfrom
fix/2d-model-construction-literate-execute
Closed

Execute 2D model construction Literate tutorial with plots#42
mmikhasenko wants to merge 4 commits into
mainfrom
fix/2d-model-construction-literate-execute

Conversation

@mmikhasenko

Copy link
Copy Markdown
Collaborator

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

  • Enable Literate execution for the 2D Model Construction tutorial so code cells render outputs and plots.
  • Document how examples/2d_distribution_fit/src/two_dimensional_model.jl defines the model with @with_parameters, including the 1D shapes, extended 2D yield components, and NLL wrapper.
  • Fix ConstructorOfFit2DExtendedKKComponents argument order and extended_negative_log_likelihood import so executed Literate blocks succeed.
  • Switch tutorial plotting to Plots.jl with theme(:boxed), a model heatmap plus data histogram2d, and 1D projection panels.
  • Update docs/Manifest.toml to a DistributionsHEP revision exporting ExtendedMixtureModel, and relax Documenter size_threshold for the generated tutorial page.

Test plan

  • julia --project=docs docs/generate_literate.jl
  • julia --project=docs docs/make.jl
  • CI Docs workflow passes on this PR

Made with Cursor

mmikhasenko and others added 4 commits May 25, 2026 21:15
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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)

Comment on lines +283 to +294
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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")

Comment on lines +296 to +307
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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")

@mmikhasenko mmikhasenko deleted the fix/2d-model-construction-literate-execute branch May 25, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant