{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import uproot\t\n", "import numpy as np\n", "import sys\n", "import os\n", "import matplotlib\n", "import matplotlib.pyplot as plt\n", "from mpl_toolkits import mplot3d\n", "import itertools\n", "import awkward as ak\n", "from scipy.optimize import curve_fit\n", "from mpl_toolkits.axes_grid1 import ImageGrid\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "44804" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# file = uproot.open(\"tracking_losses_ntuple_Bd2KstEE.root:PrDebugTrackingLosses.PrDebugTrackingTool/Tuple;1\")\n", "file = uproot.open(\n", " \"/work/cetin/Projektpraktikum/tracking_losses_ntuple_B_rad_length_beginVelo2endUT.root:PrDebugTrackingLosses.PrDebugTrackingTool/Tuple;1\"\n", ")\n", "\n", "# selektiere nur elektronen von B->K*ee und nur solche mit einem momentum von ueber 5 GeV\n", "allcolumns = file.arrays()\n", "found = allcolumns[(allcolumns.isElectron)\n", " & (~allcolumns.lost)\n", " & (allcolumns.fromB)\n", " & (allcolumns.p > 5e3)] # B: 9056\n", "lost = allcolumns[(allcolumns.isElectron)\n", " & (allcolumns.lost)\n", " & (allcolumns.fromB)\n", " & (allcolumns.p > 5e3)] # B: 1466\n", "\n", "ak.num(found, axis=0) + ak.num(lost, axis=0)\n", "# ak.count(found, axis=None)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "eff all = 0.8343228283189001 +/- 0.0017564670414882176\n" ] } ], "source": [ "def t_eff(found, lost, axis=0):\n", " sel = ak.num(found, axis=axis)\n", " des = ak.num(lost, axis=axis)\n", " return sel / (sel + des)\n", "\n", "\n", "def eff_err(found, lost):\n", " n_f = ak.num(found, axis=0)\n", " n_all = ak.num(found, axis=0) + ak.num(lost, axis=0)\n", " return 1 / n_all * np.sqrt(np.abs(n_f * (1 - n_f / n_all)))\n", "\n", "\n", "print(\"eff all = \", t_eff(found, lost), \"+/-\", eff_err(found, lost))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# try excluding all photons that originate from a vtx @ z>9500mm\n", "# ignore all brem vertices @ z>9500mm\n", "\n", "# found\n", "\n", "brem_e_f = found[\"brem_photons_pe\"]\n", "brem_z_f = found[\"brem_vtx_z\"]\n", "e_f = found[\"energy\"]\n", "length_f = found[\"brem_vtx_z_length\"]\n", "\n", "brem_f = ak.ArrayBuilder()\n", "\n", "for itr in range(ak.num(found, axis=0)):\n", " brem_f.begin_record()\n", " # [:,\"energy\"] energy\n", " brem_f.field(\"energy\").append(e_f[itr])\n", " # [:,\"photon_length\"] number of vertices\n", " brem_f.field(\"photon_length\").integer(length_f[itr])\n", " # [:,\"brem_photons_pe\",:] photon energy\n", " brem_f.field(\"brem_photons_pe\").append(brem_e_f[itr])\n", " # [:,\"brem_vtx_z\",:] brem vtx z\n", " brem_f.field(\"brem_vtx_z\").append(brem_z_f[itr])\n", " brem_f.end_record()\n", "\n", "brem_f = ak.Array(brem_f)\n", "\n", "# lost\n", "\n", "brem_e_l = lost[\"brem_photons_pe\"]\n", "brem_z_l = lost[\"brem_vtx_z\"]\n", "e_l = lost[\"energy\"]\n", "length_l = lost[\"brem_vtx_z_length\"]\n", "\n", "brem_l = ak.ArrayBuilder()\n", "\n", "for itr in range(ak.num(lost, axis=0)):\n", " brem_l.begin_record()\n", " # [:,\"energy\"] energy\n", " brem_l.field(\"energy\").append(e_l[itr])\n", " # [:,\"photon_length\"] number of vertices\n", " brem_l.field(\"photon_length\").integer(length_l[itr])\n", " # [:,\"brem_photons_pe\",:] photon energy\n", " brem_l.field(\"brem_photons_pe\").append(brem_e_l[itr])\n", " # [:,\"brem_vtx_z\",:] brem vtx z\n", " brem_l.field(\"brem_vtx_z\").append(brem_z_l[itr])\n", " brem_l.end_record()\n", "\n", "brem_l = ak.Array(brem_l)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "cut_brem_found = ak.ArrayBuilder()\n", "\n", "for itr in range(ak.num(brem_f, axis=0)):\n", " cut_brem_found.begin_record()\n", " cut_brem_found.field(\"energy\").real(brem_f[itr, \"energy\"])\n", "\n", " cut_brem_found.field(\"brem_photons_pe\")\n", " cut_brem_found.begin_list()\n", " for jentry in range(brem_f[itr, \"photon_length\"]):\n", " if brem_f[itr, \"brem_vtx_z\", jentry] > 9500:\n", " continue\n", " else:\n", " cut_brem_found.real(brem_f[itr, \"brem_photons_pe\", jentry])\n", "\n", " # cut_brem_found.field(\"brem_vtx_z\").real(brem_f[itr, \"brem_vtx_z\",jentry])\n", " cut_brem_found.end_list()\n", "\n", " cut_brem_found.field(\"brem_vtx_z\")\n", " cut_brem_found.begin_list()\n", " for jentry in range(brem_f[itr, \"photon_length\"]):\n", " if brem_f[itr, \"brem_vtx_z\", jentry] > 9500:\n", " continue\n", " else:\n", " cut_brem_found.real(brem_f[itr, \"brem_vtx_z\", jentry])\n", " cut_brem_found.end_list()\n", "\n", " cut_brem_found.end_record()\n", "\n", "cut_brem_found = ak.Array(cut_brem_found)\n", "\n", "cut_brem_lost = ak.ArrayBuilder()\n", "\n", "for itr in range(ak.num(brem_l, axis=0)):\n", " cut_brem_lost.begin_record()\n", " cut_brem_lost.field(\"energy\").real(brem_l[itr, \"energy\"])\n", "\n", " cut_brem_lost.field(\"brem_photons_pe\")\n", " cut_brem_lost.begin_list()\n", " for jentry in range(brem_l[itr, \"photon_length\"]):\n", " if brem_l[itr, \"brem_vtx_z\", jentry] > 9500:\n", " continue\n", " else:\n", " cut_brem_lost.real(brem_l[itr, \"brem_photons_pe\", jentry])\n", "\n", " # cut_brem_found.field(\"brem_vtx_z\").real(brem_f[itr, \"brem_vtx_z\",jentry])\n", " cut_brem_lost.end_list()\n", "\n", " cut_brem_lost.field(\"brem_vtx_z\")\n", " cut_brem_lost.begin_list()\n", " for jentry in range(brem_l[itr, \"photon_length\"]):\n", " if brem_l[itr, \"brem_vtx_z\", jentry] > 9500:\n", " continue\n", " else:\n", " cut_brem_lost.real(brem_l[itr, \"brem_vtx_z\", jentry])\n", " cut_brem_lost.end_list()\n", "\n", " cut_brem_lost.end_record()\n", "\n", "cut_brem_lost = ak.Array(cut_brem_lost)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
{energy: 3.26e+04,\n", " brem_photons_pe: [824, 287, 1.26e+04, 4.49e+03, 3.59e+03, 111],\n", " brem_vtx_z: [157, 158, 601, 2.33e+03, 8.65e+03, 8.67e+03]}\n", "----------------------------------------------------------------\n", "type: {\n", " energy: float64,\n", " brem_photons_pe: var * float64,\n", " brem_vtx_z: var * float64\n", "}" ], "text/plain": [ "