{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Histogram processing in Coffea\n", "\n", "While `coffea` provides its own [`coffea.hist`][coffeahist] package, to better\n", "interface with the python ecosystem in general, I recommend users to start\n", "their analysis using the [`scikit hist`][scikithist] package, as it is more\n", "general purpose, and coffea histogram will be depreciated in newer version of\n", "`coffea`. All the core functionalities would be the same, but `sckikit hist`\n", "(which we will refer to as just `hist` for the remainder of this tutorial) has\n", "more bells and whistles out of the box. A very good documentation on using\n", "`hist` is already provided by the developers [here][scikithist], so this\n", "documentation would mainly focus on going over the fundamental concepts of\n", "using histogram for physics analysis. \n", "\n", "One thing that will not be included in this documentation would be the plotting\n", "of histogram, as there are much too many customization options to go over. Here\n", "we will be using the in-built `Hist.plot1d` and `Hist.plot2d` with minimal\n", "styling settings, just to illustrate how the data in the histogram are being\n", "stored. \n", "\n", "Let us start by importing the basic libraries that we will be using: `hist` and\n", "`numpy` (`numpy` would mainly be used for pseudo-data generation and nothing\n", "else.)\n", "\n", "\n", "[coffeahist]: https://coffeateam.github.io/coffea/api/coffea.hist.Hist.html\n", "[scikithist]: https://hist.readthedocs.io/en/latest/?badge=latest" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "import hist \n", "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Histogram construction in computation\n", "\n", "Histograms in the context of an analysis is typically used to tally the number\n", "of entities that fall under some \"discrete\" criteria. These criteria can either\n", "be some true discrete variable (like data sets/particle flavor), or some\n", "continuous variable that we explicitly discrete-ize (like for particle kinematic\n", "variables). Let use make a very simple histogram that represents the 3 particle\n", "kinematic variables used in HEP: $p_{T}$, $\\eta$ and $\\phi$:\n", "\n", "The filling of the histogram can be done in parallel, supposing that you have\n", "arrays of identical dimensions. \n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "