From 55a64adf94dfd017fab132fe7091785d9d26a42b Mon Sep 17 00:00:00 2001 From: Vitor Shen <17490173+shenvitor@users.noreply.github.com> Date: Mon, 26 Aug 2024 16:10:25 +0200 Subject: [PATCH] Add 1d projection with slider --- docs/eta-pi-p/manual.ipynb | 100 ++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 8 deletions(-) diff --git a/docs/eta-pi-p/manual.ipynb b/docs/eta-pi-p/manual.ipynb index 7a78367..82a1bec 100644 --- a/docs/eta-pi-p/manual.ipynb +++ b/docs/eta-pi-p/manual.ipynb @@ -78,7 +78,7 @@ ")\n", "from ampform.sympy import unevaluated\n", "from ampform.sympy._array_expressions import ArraySum\n", - "from IPython.display import Image, Latex, display\n", + "from IPython.display import SVG, Image, Latex, display\n", "from tensorwaves.data import (\n", " SympyDataTransformer,\n", " TFPhaseSpaceGenerator,\n", @@ -755,7 +755,7 @@ " raise NotImplementedError(symbol.name)\n", "\n", "tab_contents = []\n", - "resonances_name = [\"N*\", \"Δ*\", \"a₂*\"]\n", + "resonances_name = [\"N*\", \"Δ⁺\", \"a₂\"]\n", "for i in range(len(resonances_name)):\n", " tab_content = w.VBox([\n", " w.HBox(categorized_sliders_m[i] + categorized_sliders_gamma[i]),\n", @@ -886,9 +886,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "jupyter": { - "source_hidden": true - }, "tags": [ "full-width", "hide-input" @@ -935,13 +932,100 @@ "phi_ax[0].hist(phsp[\"phi_1\"], **plot_style)\n", "phi_ax[1].hist(phsp[\"phi_2\"], **plot_style)\n", "phi_ax[2].hist(phsp[\"phi_3\"], **plot_style)\n", - "mass_ax[0].hist(np.sqrt(phsp[\"s_{12}\"]), **plot_style)\n", - "mass_ax[1].hist(np.sqrt(phsp[\"s_{23}\"]), **plot_style)\n", - "mass_ax[2].hist(np.sqrt(phsp[\"s_{31}\"]), **plot_style)\n", + "mass_ax[0].hist(np.sqrt(phsp[\"s_{12}\"]), histtype=\"step\", color=\"r\", **plot_style)\n", + "mass_ax[1].hist(np.sqrt(phsp[\"s_{23}\"]), histtype=\"step\", color=\"g\", **plot_style)\n", + "mass_ax[2].hist(np.sqrt(phsp[\"s_{31}\"]), histtype=\"step\", color=\"b\", **plot_style)\n", + "\n", + "line_labels = [R\"$m_{a_2}$\", R\"$m_{\\Delta}$\", R\"$m_{N^*}$\"]\n", + "line_colors = [\"r\", \"g\", \"b\"]\n", + "mass_values = [\n", + " parameters_default[m_a2],\n", + " parameters_default[m_delta],\n", + " parameters_default[m_nstar],\n", + "]\n", + "\n", + "for i, ax in enumerate(mass_ax):\n", + " ax.axvline(\n", + " mass_values[i], color=line_colors[i], linestyle=\"--\", label=line_labels[i]\n", + " )\n", + " ax.legend()\n", "\n", "fig.tight_layout()\n", "plt.show()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib widget\n", + "%config InlineBackend.figure_formats = ['svg']\n", + "\n", + "fig, axes = plt.subplots(figsize=(11, 3.5), ncols=3, sharey=True)\n", + "fig.canvas.toolbar_visible = False\n", + "fig.canvas.header_visible = False\n", + "fig.canvas.footer_visible = False\n", + "ax1, ax2, ax3 = axes\n", + "\n", + "for i, ax in enumerate(axes):\n", + " ax.set_title(mass_subtitles[i])\n", + " ax.set_xlabel(\"Mass [GeV]\")\n", + "\n", + "LINES = 3 * [None]\n", + "RESONANCE_LINES = defaultdict(dict)\n", + "RESONANCES_MASS_NAME = [m_a2, m_delta, m_nstar]\n", + "\n", + "\n", + "def update_plot(**parameters):\n", + " # global LINES, RESONANCE_LINES\n", + " parameters = insert_phi(parameters)\n", + " intensity_func.update_parameters(parameters)\n", + " intensities = intensity_func(phsp)\n", + " max_value = 0\n", + " keys = [\"s_{12}\", \"s_{23}\", \"s_{31}\"]\n", + "\n", + " for i, ax in enumerate(axes):\n", + " key = keys[i]\n", + " bin_values, bin_edges = jnp.histogram(\n", + " np.sqrt(phsp[key]),\n", + " bins=120,\n", + " density=True,\n", + " weights=intensities,\n", + " )\n", + " max_value = max(max_value, bin_values.max())\n", + "\n", + " if LINES[i] is None:\n", + " LINES[i] = ax.step(bin_edges[:-1], bin_values, alpha=0.5)[0]\n", + " else:\n", + " LINES[i].set_ydata(bin_values)\n", + "\n", + " symbol_key = sp.latex([m_a2, m_delta, m_nstar][i])\n", + " val = parameters[symbol_key]\n", + " resonance_line = RESONANCE_LINES[i].get(symbol_key)\n", + " if resonance_line is None:\n", + " RESONANCE_LINES[i][symbol_key] = ax.axvline(\n", + " val, color=line_colors[i], linestyle=\"--\", label=line_labels[i]\n", + " )\n", + " else:\n", + " resonance_line.set_xdata([val, val])\n", + " for ax in axes:\n", + " ax.set_ylim(0, max_value * 1.1)\n", + " ax.legend()\n", + "\n", + "\n", + "interactive_plot = w.interactive_output(update_plot, sliders)\n", + "fig.tight_layout()\n", + "\n", + "if STATIC_PAGE:\n", + " filename = \"1d-histograms.svg\"\n", + " fig.savefig(filename)\n", + " plt.close(fig)\n", + " display(UI, SVG(filename))\n", + "else:\n", + " display(UI, interactive_plot)" + ] } ], "metadata": {