{ "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": [ "10522" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "file = uproot.open(\"tracking_losses_ntuple_Bd2KstEE.root:PrDebugTrackingLosses.PrDebugTrackingTool/Tuple;1\")\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) & (~allcolumns.lost) & (allcolumns.fromSignal) & (allcolumns.p > 5e3)] #B: 9056\n", "lost = allcolumns[(allcolumns.isElectron) & (allcolumns.lost) & (allcolumns.fromSignal) & (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.8606728758791105 +/- 0.003375885792719708\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", "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", "\n", " \n", " cut_brem_found.end_record()\n", "\n", "cut_brem_found = ak.Array(cut_brem_found)\n", "\n", "\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", " \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)\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
{energy: 9.36e+03,\n", " brem_photons_pe: [2.47e+03, 170, 224, 388, 3.23e+03, 809, 172, 224],\n", " brem_vtx_z: [400, 501, 638, 667, 677, 709, 8.58e+03, 9.28e+03]}\n", "---------------------------------------------------------------------\n", "type: {\n", " energy: float64,\n", " brem_photons_pe: var * float64,\n", " brem_vtx_z: var * float64\n", "}" ], "text/plain": [ "
{energy: 4.62e+04,\n", " brem_photons_pe: [3.26e+03, 4.45e+03, 178, 1.45e+04, 1.1e+03, 3.79e+03],\n", " brem_vtx_z: [162, 187, 387, 487, 1.34e+03, 2.32e+03]}\n", "-------------------------------------------------------------------------\n", "type: {\n", " energy: float64,\n", " brem_photons_pe: var * float64,\n", " brem_vtx_z: var * float64\n", "}" ], "text/plain": [ "