{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Histograms" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook shows how to generate histograms with various settings." ] }, { "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", "example_style()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load or generate toy dataset." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = toydata.get()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define processes to plot as deparate colors." ] }, { "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": "markdown", "metadata": {}, "source": [ "Define colors and how to stack the processes. Data should not be stacked on top of the MC prediction." ] }, { "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": "markdown", "metadata": {}, "source": [ "Define the variable to use on the x-axis." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "v_higgs_m = Variable(r\"$m^H$\", \"higgs_m\", \"GeV\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Examples" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hist(df, v_higgs_m, 20, [s_bkg, s_data], range=(0, 200), selection=None,\n", " weight=\"weight\", ratio_label=\"Data / SM\")\n", "None" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hist(df, v_higgs_m, 22, [s_bkg, s_data], range=(75, 130), selection=None,\n", " weight=\"weight\", ratio_label=\"Data / SM\", include_outside=True)\n", "None" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hist(df, v_higgs_m, 20, [s_bkg, s_data], range=(0, 200), selection=None,\n", " weight=\"weight\", ratio_label=\"Data / SM\", y_log=True, numerator=None)\n", "None" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hist(df, v_higgs_m, 20, [s_bkg, s_data], range=(0, 200), selection=None,\n", " weight=\"weight\", ratio_label=\"MC / Data\", y_log=True, y_min=1e-1,\n", " vlines=[80, {'x': 100, 'color': 'b'}])\n", "None" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s_sig = McStack(p_sig, color=palette[1], histtype='step')\n", "s_ztt = McStack(p_ztt, color=palette[0], histtype='step')\n", "\n", "hist(df, v_higgs_m, 20, [s_bkg, s_data], range=(40, 120), selection=None,\n", " weight=\"weight\", ratio_label=\"Signal / Bkg\", y_log=True, y_min=1e-1,\n", " vlines=[80, {'x': 100, 'color': 'b'}], numerator=s_sig, denominator=s_ztt)\n", "None" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hist(df, v_higgs_m, 20, [s_bkg, s_data], range=(0, 200), selection=None,\n", " weight=\"weight\", ratio_label=\"Data - Bkg\", y_log=True, y_min=1e-1, diff=True,\n", " enlarge=1.5,\n", " vlines=[80, {'x': 100, 'color': 'b'}], numerator=s_data, denominator=s_ztt)\n", "None" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import freeforestml.plot as nnp\n", "nnp.INFO = \"$\\sqrt{s} = 13\\,\\mathrm{TeV}$, $140\\,\\mathrm{fb}^{-1}$\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hist(df, v_higgs_m, 20, [s_bkg, s_data], range=(0, 200), selection=None,\n", " weight=\"weight\", ratio_label=\"Data / SM\")\n", "None" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s_sig = McStack(p_sig, color=palette[1], histtype='step')\n", "s_ztt = McStack(p_ztt, color=palette[0], histtype='step')\n", "\n", "hist(df, v_higgs_m, 20, [s_sig, s_ztt], range=(0, 200), selection=None,\n", " weight=\"weight\", numerator=None, density=True)\n", "None" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hist(df, v_higgs_m, 30, [s_bkg, s_data], range=(25, 175),\n", " selection=None, numerator=[s_ztt, s_sig], denominator=s_data,\n", " weight=\"weight\", ratio_label=\"Process / Asimov\")\n", "None" ] } ], "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 }