{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# UHepp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook illustrates how FreeForestML integrates with uhepp." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import seaborn as sns\n", "\n", "from freeforestml import Variable, Process, Cut, hist, McStack, DataStack, Stack\n", "from freeforestml import toydata, example_style\n", "from freeforestml.plot import hist\n", "example_style()\n", "\n", "import uhepp" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = toydata.get()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df.compute()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p_ztt = Process(r\"$Z\\rightarrow\\tau\\tau$\", range=(0, 0))\n", "p_sig = Process(r\"Signal\", range=(1, 1))\n", "\n", "p_asimov = Process(r\"Asimov\", selection=lambda d: d.fpid >= 0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "colors = [\"windows blue\", \"amber\", \"greyish\", \"faded green\", \"dusty purple\"]\n", "palette = sns.xkcd_palette(colors)\n", "\n", "s_bkg = McStack(p_ztt, p_sig, palette=palette)\n", "s_data = DataStack(p_asimov)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "v_higgs_m = Variable(r\"$m^H$\", \"higgs_m\", \"GeV\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pass the `return_uhepp=True` argument to `hist()`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "h = hist(df, v_higgs_m, 20, [s_bkg, s_data], range=(0, 200), selection=None,\n", " weight=\"weight\", ratio_label=\"Data / SM\", return_uhepp=True)\n", "h.render()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "json_string = h.to_jsons()\n", "print(json_string)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You could now save the `json_string` as a file or push it to uhepp.org via `h.push(collection_id)`. Here will will simply restore the plot from the string." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "h = uhepp.from_jsons(json_string)\n", "h.render()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "h.rebin_edges = [0, 70, 80, 90, 100, 110, 120, 130, 140, 150, 200]\n", "h.subtext = \"Hello\"\n", "h.brand = None\n", "h.render()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.2" } }, "nbformat": 4, "nbformat_minor": 2 }