{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "import uproot\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib tk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<JaggedArray [[[0.012796929 -0.11647928 0.2177003 0.24723443] [-0.017542213 0.028378893 -0.12481077 0.948406] [0.032704882 0.19125353 0.08606246 0.9619816] ... [-4.9014157e-06 -0.00010105599 2.3466084e-05 0.0005214469] [-5.7461108e-05 -0.00010927784 -2.7991215e-05 0.0005264474] [0.00018131887 0.00014272933 -9.9944635e-05 0.0005695235]] [[0.4975031 0.3674033 0.91684073 1.1059347] [-0.5418325 -0.40721324 0.2992822 1.1955457] [-0.0006843601 -3.7102844e-05 0.000118733675 0.00086310075] ... [1.39064605e-05 -0.00010033507 7.3229836e-05 0.00052606367] [-0.0001342159 8.020731e-05 -5.2570922e-05 0.00053696433] [-0.000106765714 -0.0002584995 4.7580932e-05 0.00058446964]] [[0.26233676 0.42063588 0.1908641 0.5312104] [0.3367425 -0.06367448 0.46888483 1.1034751] [-0.119176455 -0.11087002 -0.040765774 0.9531587] ... [-0.00012120628 6.2429346e-05 -3.4657547e-05 0.00053000887] [0.00013135326 0.00016839185 0.0001434931 0.00057211856] [0.00015451711 -2.8992914e-05 -5.4456126e-07 0.0005346366]] ... [[-0.39426106 -0.37707 0.25185505 0.60087836] [0.21237822 0.58317786 0.09207223 1.1298059] [-0.025693536 -0.17396025 0.34086162 1.0136386] ... [-0.00017441744 -4.58666e-05 2.8165328e-05 0.00054262177] [0.0001541273 7.384292e-06 -6.0301154e-05 0.00053718325] [4.3270297e-06 -0.00015567934 0.00026628497 0.00059689395]] [[-0.40571418 0.12750585 0.7170512 0.8336812] [-0.06925168 0.028778879 0.19443081 0.9611356] [0.054794014 0.102245055 0.12852181 0.95411146] ... [-5.5740507e-05 0.0001419536 -0.00011682083 0.0005459165] [4.2116448e-05 -0.00010851189 -6.537875e-06 0.000524129] [5.6034245e-05 0.00012720686 -0.0002380775 0.00058062223]] [[-0.2817698 0.09529843 1.789157 1.8137143] [0.13794336 -0.08567715 -0.18258414 0.24434793] [0.30092528 -0.2314571 0.0017307396 1.0133679] ... [2.7687149e-05 -0.00020852858 5.0563733e-05 0.000554912] [5.6125336e-05 0.00013545544 -1.4012998e-05 0.00053180306] [-9.7244636e-05 -0.00016220225 0.00018762102 0.00057627045]]] at 0x7fe354832a20>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "root_file = uproot.open('reco2_checkout_hist.root')\n",
    "wcpselection = root_file['wcpselection']\n",
    "T_MCEval = wcpselection['T_MCEval']\n",
    "branches = T_MCEval.arrays(namedecode='utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<JaggedArray [[0 0 0] [0 0] [0 0 0 0 0 0] ... [0 0 0] [0 0 0 ... 0 0 0] [0 0 0 0]] at 0x7fe320f5ff60>"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mask = (branches['truth_mother']==0)\n",
    "branches['truth_mother'][mask]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.hist(branches['truth_startMomentum'][:,:,3].flatten(), bins=100, range=(0, 4))\n",
    "plt.xlabel('Muon $p_{\\mathrm{T}}$ [GeV]')\n",
    "plt.ylabel('Number of single muons / 1 GeV')\n",
    "# plt.yscale('log')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5548070"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(branches['truth_startMomentum'][:,:,3].flatten())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
