{ "cells": [ { "cell_type": "code", "execution_count": 173, "metadata": {}, "outputs": [], "source": [ "import uproot\t\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from mpl_toolkits import mplot3d\n", "import awkward as ak\n", "from scipy.optimize import curve_fit\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 174, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10923 2390\n", "13313\n" ] } ], "source": [ "file = uproot.open(\"tracking_losses_ntuple_Bd2KstEE.root:PrDebugTrackingLosses.PrDebugTrackingTool/Tuple;1\")\n", "#file = uproot.open(\n", "# \"tracking_losses_ntuple_B_default.root:PrDebugTrackingLosses.PrDebugTrackingTool/Tuple;1\"\n", "#)\n", "\n", "# selektiere nur elektronen von B->K*ee\n", "allcolumns = file.arrays()\n", "found = allcolumns[\n", " (allcolumns.isElectron) & (~allcolumns.lost) & (allcolumns.fromB)\n", "] # B: 9056\n", "lost = allcolumns[\n", " (allcolumns.isElectron) & (allcolumns.lost) & (allcolumns.fromB)\n", "] # B: 1466\n", "\n", "electrons = allcolumns[(allcolumns.isElectron) & (allcolumns.fromB)]\n", "\n", "print(ak.num(found, axis=0), ak.num(lost, axis=0))\n", "print(ak.num(electrons,axis=0))\n", "# ak.count(found, axis=None)" ] }, { "cell_type": "code", "execution_count": 175, "metadata": {}, "outputs": [], "source": [ "#electrons[0]" ] }, { "cell_type": "code", "execution_count": 176, "metadata": {}, "outputs": [], "source": [ "lost_e = electrons[\"lost\"]\n", "e = electrons[\"energy\"]\n", "brem_pe = electrons[\"brem_photons_pe\"]\n", "brem_z = electrons[\"brem_vtx_z\"]\n", "brem_x = electrons[\"brem_vtx_x\"]\n", "length = electrons[\"brem_vtx_z_length\"]\n", "\n", "\n", "\n", "brem = ak.ArrayBuilder()\n", "\n", "for itr in range(ak.num(electrons, axis=0)):\n", " brem.begin_record()\n", " brem.field(\"lost\").boolean(lost_e[itr])\n", " # [:,\"energy\"] energy\n", " brem.field(\"energy\").append(e[itr])\n", " # [:,\"photon_length\"] number of vertices\n", " brem.field(\"photon_length\").integer(length[itr])\n", " # [:,\"brem_photons_pe\",:] photon energy\n", " brem.field(\"brem_photons_pe\").append(brem_pe[itr])\n", " # [:,\"brem_vtx_z\",:] brem vtx z\n", " brem.field(\"brem_vtx_x\").append(brem_x[itr])\n", " brem.field(\"brem_vtx_z\").append(brem_z[itr])\n", " brem.end_record()\n", "\n", "brem = ak.Array(brem)" ] }, { "cell_type": "code", "execution_count": 177, "metadata": {}, "outputs": [], "source": [ "photon_cut = 0\n", "photon_cut_ratio = 0.2\n", "\n", "cut_brem = ak.ArrayBuilder()\n", "\n", "for itr in range(ak.num(brem, axis=0)):\n", " cut_brem.begin_record()\n", " cut_brem.field(\"lost\").boolean(brem[itr, \"lost\"])\n", " cut_brem.field(\"energy\").real(brem[itr, \"energy\"])\n", "\n", " ph_length = brem[itr, \"photon_length\"]\n", " \n", " tmp_energy = brem[itr, \"energy\"]\n", "\n", " cut_brem.field(\"brem_photons_pe\")\n", " cut_brem.begin_list()\n", " for jentry in range(brem[itr, \"photon_length\"]):\n", " if (\n", " brem[itr, \"brem_vtx_z\", jentry] > 3000\n", " or brem[itr, \"brem_photons_pe\", jentry] < photon_cut\n", " or brem[itr, \"brem_photons_pe\", jentry] < photon_cut_ratio * tmp_energy\n", " ):\n", " ph_length -= 1\n", " continue\n", " else:\n", " cut_brem.real(brem[itr, \"brem_photons_pe\", jentry])\n", " tmp_energy -= brem[itr, \"brem_photons_pe\", jentry]\n", " cut_brem.end_list()\n", "\n", " tmp_energy = brem[itr, \"energy\"]\n", "\n", " cut_brem.field(\"brem_vtx_x\")\n", " cut_brem.begin_list()\n", " for jentry in range(brem[itr, \"photon_length\"]):\n", " if (\n", " brem[itr, \"brem_vtx_z\", jentry] > 3000\n", " or brem[itr, \"brem_photons_pe\", jentry] < photon_cut\n", " or brem[itr, \"brem_photons_pe\", jentry] < photon_cut_ratio * tmp_energy\n", " ):\n", " continue\n", " else:\n", " cut_brem.real(brem[itr, \"brem_vtx_x\", jentry])\n", " tmp_energy -= brem[itr, \"brem_photons_pe\", jentry]\n", " cut_brem.end_list()\n", "\n", " tmp_energy = brem[itr, \"energy\"]\n", "\n", " cut_brem.field(\"brem_vtx_z\")\n", " cut_brem.begin_list()\n", " for jentry in range(brem[itr, \"photon_length\"]):\n", " if (\n", " brem[itr, \"brem_vtx_z\", jentry] > 3000\n", " or brem[itr, \"brem_photons_pe\", jentry] < photon_cut\n", " or brem[itr, \"brem_photons_pe\", jentry] < photon_cut_ratio * tmp_energy\n", " ):\n", " continue\n", " else:\n", " cut_brem.real(brem[itr, \"brem_vtx_z\", jentry])\n", " tmp_energy -= brem[itr, \"brem_photons_pe\", jentry]\n", " cut_brem.end_list()\n", " \n", " cut_brem.field(\"photon_length\").integer(ph_length)\n", "\n", " cut_brem.end_record()\n", "\n", "ntuple = ak.Array(cut_brem)\n", "\n" ] }, { "cell_type": "code", "execution_count": 178, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "13313\n" ] }, { "data": { "text/html": [ "
{lost: False,\n", " energy: 3.63e+03,\n", " brem_photons_pe: [],\n", " brem_vtx_x: [],\n", " brem_vtx_z: [],\n", " photon_length: 0}\n", "-----------------------------------\n", "type: {\n", " lost: bool,\n", " energy: float64,\n", " brem_photons_pe: var * float64,\n", " brem_vtx_x: var * float64,\n", " brem_vtx_z: var * float64,\n", " photon_length: int64\n", "}" ], "text/plain": [ "