{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import uproot\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",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "file = uproot.open(\"tracking_losses_ntuple_Bd2KstEE.root:PrDebugTrackingLosses.PrDebugTrackingTool/Tuple;1\")\n",
    "#file = uproot.open(\"tracking_losses_ntuple_Dst0ToD0EE.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) & (~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)\n",
    "#ak.count(found, axis=None)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8606728758791105"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def t_eff(found, lost):\n",
    "    sel = found[\"energy\"]\n",
    "    des = lost[\"energy\"]\n",
    "    return ak.count(sel,axis=None)/(ak.count(sel,axis=None)+ak.count(des,axis=None))\n",
    "\n",
    "t_eff(found, lost)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.96875"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#finden wir die elektronen die keine bremsstrahlung gemacht haben mit hoher effizienz?\n",
    "nobrem_found = found[found[\"brem_photons_pe_length\"]==0]\n",
    "nobrem_lost = lost[lost[\"brem_photons_pe_length\"]==0]\n",
    "\n",
    "\"\"\"\n",
    "die effizienz mit der wir elektronen finden, die keine bremsstrahlung gemacht haben, ist gut mit 0.9688.\n",
    "allerdings haben wir hier nur sehr wenige teilchen (<100)\n",
    "\"\"\"\n",
    "\n",
    "t_eff(nobrem_found, nobrem_lost)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8603431839847474"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#wie viel energie relativ zur anfangsenergie verlieren die elektronen durch bremstrahlung und hat das einen einfluss darauf ob wir sie finden oder nicht?\n",
    "brem_found = found[found[\"brem_photons_pe_length\"]!=0]\n",
    "energy_found = ak.to_numpy(brem_found[\"energy\"])\n",
    "eph_found = ak.to_numpy(ak.sum(brem_found[\"brem_photons_pe\"], axis=-1, keepdims=False))\n",
    "energyloss_found = eph_found/energy_found\n",
    "\n",
    "\n",
    "brem_lost = lost[lost[\"brem_photons_pe_length\"]!=0]\n",
    "energy_lost = ak.to_numpy(brem_lost[\"energy\"])\n",
    "eph_lost = ak.to_numpy(ak.sum(brem_lost[\"brem_photons_pe\"], axis=-1, keepdims=False))\n",
    "energyloss_lost = eph_lost/energy_lost\n",
    "\n",
    "t_eff(brem_found,brem_lost)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mean energyloss relative to initial energy (found):  0.6475128752780828\n",
      "mean energyloss relative to initial energy (lost):  0.8241268441538472\n"
     ]
    }
   ],
   "source": [
    "mean_energyloss_found = ak.mean(energyloss_found)\n",
    "mean_energyloss_lost = ak.mean(energyloss_lost)\n",
    "print(\"mean energyloss relative to initial energy (found): \", mean_energyloss_found)\n",
    "print(\"mean energyloss relative to initial energy (lost): \", mean_energyloss_lost)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 19840 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.hist(energyloss_lost, bins=200, density=True, alpha=0.5, histtype='bar', color=\"darkorange\", label=\"lost\")\n",
    "plt.hist(energyloss_found, bins=100, density=True, alpha=0.5, histtype='bar', color=\"blue\", label=\"found\")\n",
    "plt.xticks(np.arange(0,1.1,0.1), minor=True,)\n",
    "plt.yticks(np.arange(0,10,1), minor=True)\n",
    "plt.xlabel(r\"$E_\\gamma/E_0$\")\n",
    "plt.ylabel(\"counts (normed)\")\n",
    "plt.title(r'$E_{ph}/E_0$')\n",
    "plt.legend()\n",
    "plt.grid()\n",
    "\n",
    "\"\"\"\n",
    "found: elektronen verlieren durchschnittlich 0.65 ihrer anfangsenergie durch bremsstrahlung\n",
    "lost: elektronen verlieren durchschnittlich 0.82 ihrer anfangsenergie durch bremsstrahlung\n",
    "\n",
    "-> wir können sofort erkennen, dass verlorene elektronen im schnitt mehr energie durch bremsstrahlung verlieren als gefundene, \n",
    "aber auch die rate der gefundenen elektronen steigt für raten nahe 1, wenn auch wesentlich schwächer als für verlorene elektronen.\n",
    "die meisten verlorenen elektronen verlieren >0.8 ihrer anfangsenergie.\n",
    "\"\"\"\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#ist die shape der teilspur im scifi anders? (koenntest du zum beispiel durch vergleich der verteilungen der fit parameter studieren,\n",
    "#in meiner thesis findest du das fitmodell -- ist einfach ein polynom dritten grades)\n",
    "z_ref=8520 #mm\n",
    "\n",
    "def scifi_track(z, a, b, c, d):\n",
    "    return a + b*(z-z_ref) + c*(z-z_ref)**2 + d*(z-z_ref)**3\n",
    "\n",
    "def z_mag(xv, zv, tx, a, b):\n",
    "    \"\"\" optical centre of the magnet is defined as the intersection between the trajectory tangents before and after the magnet\n",
    "\n",
    "    Args:\n",
    "        xv (double): velo x track\n",
    "        zv (double): velo z track\n",
    "        tx (double): velo x slope\n",
    "        a (double): ax parameter of track fit\n",
    "        b (double): bx parameter of track fit\n",
    "\n",
    "    Returns:\n",
    "        double: z_mag\n",
    "    \"\"\"\n",
    "    return (xv-tx*zv-a+b*z_ref)/(b-tx)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "scifi_found = found[found[\"scifi_hit_pos_x_length\"]>3]\n",
    "scifi_lost = lost[lost[\"scifi_hit_pos_x_length\"]>3]\n",
    "\n",
    "scifi_x_found = scifi_found[\"scifi_hit_pos_x\"]\n",
    "scifi_z_found = scifi_found[\"scifi_hit_pos_z\"]\n",
    "\n",
    "tx_found = scifi_found[\"velo_track_tx\"]\n",
    "\n",
    "scifi_x_lost = scifi_lost[\"scifi_hit_pos_x\"]\n",
    "scifi_z_lost = scifi_lost[\"scifi_hit_pos_z\"]\n",
    "\n",
    "tx_lost = scifi_lost[\"velo_track_tx\"]\n",
    "\n",
    "xv_found = scifi_found[\"velo_track_x\"]\n",
    "zv_found = scifi_found[\"velo_track_z\"]\n",
    "\n",
    "xv_lost = scifi_lost[\"velo_track_x\"]\n",
    "zv_lost = scifi_lost[\"velo_track_z\"]\n",
    "\n",
    "\n",
    "\n",
    "#ak.num(scifi_found[\"energy\"], axis=0)\n",
    "#scifi_found.snapshot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "#tx_lost.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "scifi_fitpars_found = ak.ArrayBuilder()\n",
    "\n",
    "for i in range(0,ak.num(scifi_found[\"energy\"], axis=0)):\n",
    "    popt, pcov = curve_fit(scifi_track,ak.to_numpy(scifi_z_found[i,:]),ak.to_numpy(scifi_x_found[i,:]))\n",
    "    scifi_fitpars_found.begin_list()\n",
    "    scifi_fitpars_found.real(popt[0])\n",
    "    scifi_fitpars_found.real(popt[1])\n",
    "    scifi_fitpars_found.real(popt[2])\n",
    "    scifi_fitpars_found.real(popt[3])\n",
    "    scifi_fitpars_found.end_list()\n",
    "\n",
    "scifi_fitpars_lost = ak.ArrayBuilder()\n",
    "\n",
    "for i in range(0,ak.num(scifi_lost[\"energy\"], axis=0)):\n",
    "    popt, pcov = curve_fit(scifi_track,ak.to_numpy(scifi_z_lost[i,:]),ak.to_numpy(scifi_x_lost[i,:]))\n",
    "    scifi_fitpars_lost.begin_list()\n",
    "    scifi_fitpars_lost.real(popt[0])\n",
    "    scifi_fitpars_lost.real(popt[1])\n",
    "    scifi_fitpars_lost.real(popt[2])\n",
    "    scifi_fitpars_lost.real(popt[3])\n",
    "    scifi_fitpars_lost.end_list()\n",
    "\n",
    "\n",
    "scifi_fitpars_lost = scifi_fitpars_lost.to_numpy()\n",
    "scifi_fitpars_found = scifi_fitpars_found.to_numpy()\n",
    "\n",
    "\n",
    "\n",
    "dtx_found = scifi_fitpars_found[:,1] - tx_found\n",
    "dtx_lost = scifi_fitpars_lost[:,1] - tx_lost\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 83876 characters]",
      "text/plain": [
       "<Figure size 1500x1000 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2, figsize=(15,10))\n",
    "\n",
    "ax0.hist(scifi_fitpars_found[:,0], bins=100, density=True, alpha=0.5, histtype='bar', color=\"blue\", label=r\"$a_x$ found\")\n",
    "ax0.hist(scifi_fitpars_lost[:,0], bins=100, density=True, alpha=0.5, histtype='bar', color=\"darkorange\", label=r\"$a_x$ lost\")\n",
    "ax0.set_xlabel(\"a\")\n",
    "ax0.set_ylabel(\"normed\")\n",
    "ax0.set_title(\"fitparameter a der scifi track\")\n",
    "ax0.legend()\n",
    "\n",
    "ax1.hist(scifi_fitpars_found[:,1], bins=100, density=True, alpha=0.5, histtype='bar', color=\"blue\", label=r\"$b_x$ found\")\n",
    "ax1.hist(scifi_fitpars_lost[:,1], bins=100, density=True, alpha=0.5, histtype='bar', color=\"darkorange\", label=r\"$b_x$ lost\")\n",
    "ax1.set_xlabel(\"b\")\n",
    "ax1.set_ylabel(\"normed\")\n",
    "ax1.set_title(\"fitparameter b der scifi track\")\n",
    "ax1.legend()\n",
    "\n",
    "ax2.hist(scifi_fitpars_found[:,2], bins=500, density=True, alpha=0.5, histtype='bar', color=\"blue\", label=r\"$c_x$ found\")\n",
    "ax2.hist(scifi_fitpars_lost[:,2], bins=500, density=True, alpha=0.5, histtype='bar', color=\"darkorange\", label=r\"$c_x$ lost\")\n",
    "ax2.set_xlim([-3e-5,3e-5])\n",
    "ax2.set_xticks(np.arange(-3e-5,3.5e-5,1e-5),minor=False)\n",
    "ax2.set_xlabel(\"c\")\n",
    "ax2.set_ylabel(\"normed\")\n",
    "ax2.set_title(\"fitparameter c der scifi track\")\n",
    "ax2.legend()\n",
    "\n",
    "ax3.hist(scifi_fitpars_found[:,3], bins=500, density=True, alpha=0.5, histtype='bar', color=\"blue\", label=r\"$d_x$ found\")\n",
    "ax3.hist(scifi_fitpars_lost[:,3], bins=500, density=True, alpha=0.5, histtype='bar', color=\"darkorange\", label=r\"$d_x$ lost\")\n",
    "ax3.set(xlim=(-5e-8,5e-8))\n",
    "ax3.text(-4e-8,3e8,\"d negligible <1e-7\")\n",
    "ax3.set_xlabel(\"d\")\n",
    "ax3.set_ylabel(\"normed\")\n",
    "ax3.set_title(\"fitparameter d der scifi track\")\n",
    "ax3.legend()\n",
    "\n",
    "\"\"\"\n",
    "a_x: virtual hit on the reference plane\n",
    "\"\"\"\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "found\n",
      "a =  -0.6718207391527037\n",
      "b =  0.0013778237292529144\n",
      "c =  3.3126998287416195e-08\n",
      "d =  -1.0330674442255529e-10\n",
      "lost\n",
      "a =  -36.98764338200992\n",
      "b =  -0.015685137956233643\n",
      "c =  -8.265859479503501e-07\n",
      "d =  -1.541510766903436e-11\n"
     ]
    }
   ],
   "source": [
    "print(\"found\")\n",
    "print(\"a = \", str(np.mean(scifi_fitpars_found[:,0])))\n",
    "print(\"b = \", str(np.mean(scifi_fitpars_found[:,1])))\n",
    "print(\"c = \", str(np.mean(scifi_fitpars_found[:,2])))\n",
    "print(\"d = \", str(np.mean(scifi_fitpars_found[:,3])))\n",
    "\n",
    "print(\"lost\")\n",
    "print(\"a = \", str(np.mean(scifi_fitpars_lost[:,0])))\n",
    "print(\"b = \", str(np.mean(scifi_fitpars_lost[:,1])))\n",
    "print(\"c = \", str(np.mean(scifi_fitpars_lost[:,2])))\n",
    "print(\"d = \", str(np.mean(scifi_fitpars_lost[:,3])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-4.6785491318157854e-07"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.min(scifi_fitpars_found[:,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 1272860 characters]",
      "text/plain": [
       "<Figure size 1500x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ((ax0, ax1)) = plt.subplots(nrows=1, ncols=2, figsize=(15,6))\n",
    "\n",
    "for i in range(0,ak.num(scifi_found[\"energy\"], axis=0)):\n",
    "    z_coord = np.linspace(scifi_z_found[i,0],12000,300)\n",
    "    fit = scifi_track(z_coord, *scifi_fitpars_found[i])\n",
    "    ax0.plot(z_coord, fit, \"-\", lw=0.5)\n",
    "    ax0.errorbar(ak.to_numpy(scifi_z_found[i,:]),ak.to_numpy(scifi_x_found[i,:]),fmt=\".\",ms=2)\n",
    "\n",
    "#ax0.legend()\n",
    "ax0.set_xlabel(\"z [mm]\")\n",
    "ax0.set_ylabel(\"x [mm]\")\n",
    "ax0.set_title(\"found tracks of scifi hits\")\n",
    "ax0.set(xlim=(7e3,12000), ylim=(-4000,4000))\n",
    "ax0.grid()\n",
    "\n",
    "for i in range(0,ak.num(scifi_lost[\"energy\"], axis=0)):\n",
    "    z_coord = np.linspace(scifi_z_lost[i,0],12000,300)\n",
    "    fit = scifi_track(z_coord, *scifi_fitpars_lost[i])\n",
    "    ax1.plot(z_coord, fit, \"-\", lw=0.5)\n",
    "    ax1.errorbar(ak.to_numpy(scifi_z_lost[i,:]),ak.to_numpy(scifi_x_lost[i,:]),fmt=\".\",ms=2)\n",
    "\n",
    "#ax1.legend()\n",
    "ax1.set_xlabel(\"z [mm]\")\n",
    "ax1.set_ylabel(\"x [mm]\")\n",
    "ax1.set_title(\"lost tracks of scifi hits\")\n",
    "ax1.set(xlim=(7e3,12000), ylim=(-4000,4000))\n",
    "ax1.grid()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "found \n",
      "zmag =  5215.5640412342\n",
      "lost \n",
      "zmag =  5450.484726770035\n"
     ]
    }
   ],
   "source": [
    "#vergleich der zmag werte\n",
    "zmag_found = z_mag(xv_found, zv_found, tx_found, scifi_fitpars_found[:,0], scifi_fitpars_found[:,1])\n",
    "zmag_lost = z_mag(xv_lost, zv_lost, tx_lost, scifi_fitpars_lost[:,0], scifi_fitpars_lost[:,1])\n",
    "zmag_lost = zmag_lost[~np.isnan(zmag_lost)]\n",
    "zmag_found = zmag_found[~np.isnan(zmag_found)]\n",
    "\n",
    "print(\"found \\nzmag = \", str(np.mean(zmag_found)))\n",
    "print(\"lost \\nzmag = \", str(np.mean(zmag_lost)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 28968 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.hist(zmag_found, bins=5000, density=True, alpha=0.5, histtype='bar', color=\"blue\", label=\"found\")\n",
    "plt.hist(zmag_lost, bins=300, density=True, alpha=0.5, histtype=\"bar\",color=\"darkorange\", label=\"lost\")\n",
    "plt.xlabel(\"$z_{mag}$ [mm]\")\n",
    "plt.ylabel(\"normed\")\n",
    "plt.title(\"magnet kick position $z_{mag}$ calculated w fitparameters\")\n",
    "plt.legend()\n",
    "plt.xticks(np.arange(5100,5800,5), minor=True)\n",
    "plt.yticks(np.arange(0,0.015,0.001), minor=True)\n",
    "plt.xlim(5100,5800)\n",
    "\n",
    "\"\"\"\n",
    "wir können einen radikalen unterschied für den z_mag wert erkennen, zwischen den found and lost elektronen.\n",
    "\"\"\"\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'all_endvtx_types_length': 9,\n",
       " 'all_endvtx_types': [101.0,\n",
       "  101.0,\n",
       "  101.0,\n",
       "  101.0,\n",
       "  101.0,\n",
       "  101.0,\n",
       "  101.0,\n",
       "  101.0,\n",
       "  0.0],\n",
       " 'all_endvtx_x_length': 9,\n",
       " 'all_endvtx_x': [4.337699890136719,\n",
       "  14.665200233459473,\n",
       "  76.01349639892578,\n",
       "  407.2786865234375,\n",
       "  407.5032958984375,\n",
       "  410.0320129394531,\n",
       "  415.61248779296875,\n",
       "  416.95660400390625,\n",
       "  434.4844970703125],\n",
       " 'all_endvtx_y_length': 9,\n",
       " 'all_endvtx_y': [11.121000289916992,\n",
       "  44.36029815673828,\n",
       "  229.05709838867188,\n",
       "  701.25048828125,\n",
       "  701.5361938476562,\n",
       "  704.75341796875,\n",
       "  711.8519287109375,\n",
       "  713.556396484375,\n",
       "  735.4926147460938],\n",
       " 'all_endvtx_z_length': 9,\n",
       " 'all_endvtx_z': [225.14419555664062,\n",
       "  794.5338134765625,\n",
       "  3962.47607421875,\n",
       "  12063.0546875,\n",
       "  12067.9521484375,\n",
       "  12123.0634765625,\n",
       "  12244.5712890625,\n",
       "  12273.71875,\n",
       "  12650.5009765625],\n",
       " 'brem_photons_pe_length': 8,\n",
       " 'brem_photons_pe': [8379.3701171875,\n",
       "  1664.8931884765625,\n",
       "  1533.9306640625,\n",
       "  636.8262939453125,\n",
       "  1398.7904052734375,\n",
       "  190.91404724121094,\n",
       "  12675.98828125,\n",
       "  17840.21875],\n",
       " 'brem_photons_px_length': 8,\n",
       " 'brem_photons_px': [151.9600067138672,\n",
       "  30.200000762939453,\n",
       "  36.0,\n",
       "  29.139999389648438,\n",
       "  63.97999954223633,\n",
       "  8.739999771118164,\n",
       "  582.6599731445312,\n",
       "  821.239990234375],\n",
       " 'brem_photons_py_length': 8,\n",
       " 'brem_photons_py': [488.9800109863281,\n",
       "  96.83999633789062,\n",
       "  89.2300033569336,\n",
       "  37.040000915527344,\n",
       "  81.45999908447266,\n",
       "  11.109999656677246,\n",
       "  739.2999877929688,\n",
       "  1038.8900146484375],\n",
       " 'brem_photons_pz_length': 8,\n",
       " 'brem_photons_pz': [8363.7099609375,\n",
       "  1661.800048828125,\n",
       "  1530.9100341796875,\n",
       "  635.0800170898438,\n",
       "  1394.949951171875,\n",
       "  190.38999938964844,\n",
       "  12640.990234375,\n",
       "  17791.0],\n",
       " 'brem_vtx_x_length': 8,\n",
       " 'brem_vtx_x': [4.337699890136719,\n",
       "  14.665200233459473,\n",
       "  76.01349639892578,\n",
       "  407.2786865234375,\n",
       "  407.5032958984375,\n",
       "  410.0320129394531,\n",
       "  415.61248779296875,\n",
       "  416.95660400390625],\n",
       " 'brem_vtx_y_length': 8,\n",
       " 'brem_vtx_y': [11.121000289916992,\n",
       "  44.36029815673828,\n",
       "  229.05709838867188,\n",
       "  701.25048828125,\n",
       "  701.5361938476562,\n",
       "  704.75341796875,\n",
       "  711.8519287109375,\n",
       "  713.556396484375],\n",
       " 'brem_vtx_z_length': 8,\n",
       " 'brem_vtx_z': [225.14419555664062,\n",
       "  794.5338134765625,\n",
       "  3962.47607421875,\n",
       "  12063.0546875,\n",
       "  12067.9521484375,\n",
       "  12123.0634765625,\n",
       "  12244.5712890625,\n",
       "  12273.71875],\n",
       " 'endvtx_type': 0,\n",
       " 'endvtx_x': nan,\n",
       " 'endvtx_y': nan,\n",
       " 'endvtx_z': nan,\n",
       " 'energy': 56441.954665682184,\n",
       " 'eta': 3.488542459471178,\n",
       " 'event_count': 4,\n",
       " 'fromB': True,\n",
       " 'fromD': False,\n",
       " 'fromDecay': True,\n",
       " 'fromHadInt': False,\n",
       " 'fromPV': False,\n",
       " 'fromPairProd': False,\n",
       " 'fromSignal': True,\n",
       " 'fromStrange': False,\n",
       " 'isElectron': True,\n",
       " 'isKaon': False,\n",
       " 'isMuon': False,\n",
       " 'isPion': False,\n",
       " 'isProton': False,\n",
       " 'lost': False,\n",
       " 'lost_in_track_fit': False,\n",
       " 'match_fraction': 1.0,\n",
       " 'mcp_idx': 742,\n",
       " 'mother_id': -511,\n",
       " 'mother_key': 698,\n",
       " 'originvtx_type': 3,\n",
       " 'originvtx_x': 1.1207,\n",
       " 'originvtx_y': 0.8300000000000001,\n",
       " 'originvtx_z': 48.8842,\n",
       " 'p': 56441.95466336899,\n",
       " 'phi': 1.2677798486443645,\n",
       " 'pid': 11,\n",
       " 'pt': 3444.8656184095194,\n",
       " 'px': 1027.95,\n",
       " 'py': 3287.92,\n",
       " 'pz': 56336.73,\n",
       " 'scifi_hit_pos_x_length': 12,\n",
       " 'scifi_hit_pos_x': [213.45494079589844,\n",
       "  216.5443115234375,\n",
       "  219.6619110107422,\n",
       "  222.7693634033203,\n",
       "  243.98696899414062,\n",
       "  247.14352416992188,\n",
       "  250.3206329345703,\n",
       "  253.48336791992188,\n",
       "  275.1091003417969,\n",
       "  278.3012390136719,\n",
       "  281.5145568847656,\n",
       "  284.71240234375],\n",
       " 'scifi_hit_pos_y_length': 12,\n",
       " 'scifi_hit_pos_y': [454.385986328125,\n",
       "  458.4554138183594,\n",
       "  462.55010986328125,\n",
       "  466.6192932128906,\n",
       "  494.1504821777344,\n",
       "  498.219482421875,\n",
       "  502.31170654296875,\n",
       "  506.38079833984375,\n",
       "  534.1050415039062,\n",
       "  538.1732788085938,\n",
       "  542.2637939453125,\n",
       "  546.33056640625],\n",
       " 'scifi_hit_pos_z_length': 12,\n",
       " 'scifi_hit_pos_z': [7827.7353515625,\n",
       "  7897.55078125,\n",
       "  7967.765625,\n",
       "  8037.5810546875,\n",
       "  8509.87890625,\n",
       "  8579.693359375,\n",
       "  8649.9091796875,\n",
       "  8719.724609375,\n",
       "  9195.0224609375,\n",
       "  9264.837890625,\n",
       "  9335.052734375,\n",
       "  9404.8681640625],\n",
       " 'track_p': 45119.27933089411,\n",
       " 'track_pt': 2751.5483539471675,\n",
       " 'tx': 0.018246532945735403,\n",
       " 'ty': 0.05836192480465231,\n",
       " 'ut_hit_pos_x_length': 4,\n",
       " 'ut_hit_pos_x': [42.633201599121094,\n",
       "  43.659507751464844,\n",
       "  47.88643264770508,\n",
       "  48.9288444519043],\n",
       " 'ut_hit_pos_y_length': 4,\n",
       " 'ut_hit_pos_y': [133.4278106689453,\n",
       "  136.63731384277344,\n",
       "  149.7635040283203,\n",
       "  152.9698028564453],\n",
       " 'ut_hit_pos_z_length': 4,\n",
       " 'ut_hit_pos_z': [2321.846435546875,\n",
       "  2376.846435546875,\n",
       "  2601.846435546875,\n",
       "  2656.846435546875],\n",
       " 'velo_hit_pos_x_length': 11,\n",
       " 'velo_hit_pos_x': [2.4984264373779297,\n",
       "  2.954725503921509,\n",
       "  3.4115281105041504,\n",
       "  3.8682260513305664,\n",
       "  4.323416709899902,\n",
       "  4.777114391326904,\n",
       "  5.2308149337768555,\n",
       "  6.138315677642822,\n",
       "  7.523914337158203,\n",
       "  9.338811874389648,\n",
       "  11.151512145996094],\n",
       " 'velo_hit_pos_y_length': 11,\n",
       " 'velo_hit_pos_y': [5.234837055206299,\n",
       "  6.694038391113281,\n",
       "  8.154040336608887,\n",
       "  9.614141464233398,\n",
       "  11.075146675109863,\n",
       "  12.537148475646973,\n",
       "  13.99904727935791,\n",
       "  16.921545028686523,\n",
       "  21.37623405456543,\n",
       "  27.210132598876953,\n",
       "  33.04653549194336],\n",
       " 'velo_hit_pos_z_length': 11,\n",
       " 'velo_hit_pos_z': [124.35900115966797,\n",
       "  149.35899353027344,\n",
       "  174.35899353027344,\n",
       "  199.35899353027344,\n",
       "  224.35899353027344,\n",
       "  249.35899353027344,\n",
       "  274.3590087890625,\n",
       "  324.3590087890625,\n",
       "  400.6409912109375,\n",
       "  500.6409912109375,\n",
       "  600.6409912109375],\n",
       " 'velo_track_idx': 44,\n",
       " 'velo_track_tx': 0.018183697015047073,\n",
       " 'velo_track_ty': 0.05834294483065605,\n",
       " 'velo_track_x': 14.221809387207031,\n",
       " 'velo_track_y': 42.918701171875,\n",
       " 'velo_track_z': 770.0}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "same = found[found[\"event_count\"]==4]\n",
    "same[1].tolist()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "env1",
   "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.11.5"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
