From 7f537d7d3bf406fe786cce984d3d47910022af4f Mon Sep 17 00:00:00 2001 From: cetin Date: Tue, 26 Sep 2023 13:35:31 +0200 Subject: [PATCH] finding shared tracks in all found events --- D_tasks.ipynb | 152 +++++++++++++++++++++++++++++--------------------- 1 file changed, 88 insertions(+), 64 deletions(-) diff --git a/D_tasks.ipynb b/D_tasks.ipynb index e8369d3..c02bcb0 100644 --- a/D_tasks.ipynb +++ b/D_tasks.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 28, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -47,7 +47,7 @@ "0.5759057568348522" ] }, - "execution_count": 30, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -63,7 +63,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -72,7 +72,7 @@ "0.7960893854748603" ] }, - "execution_count": 31, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -94,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -103,7 +103,7 @@ "0.5568703211784594" ] }, - "execution_count": 32, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -126,7 +126,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -147,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -184,7 +184,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -213,7 +213,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -244,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -282,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -340,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -376,7 +376,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -385,7 +385,7 @@ "-1.5438992626615335e-08" ] }, - "execution_count": 40, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -396,7 +396,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -444,7 +444,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -471,7 +471,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -505,7 +505,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -522,7 +522,7 @@ "shared = np.array([0,1,0,1,1,2])\n", "len(shared)\n", "\n", - "both = ak.concatenate([found,lost])\n", + "both = ak.concatenate([found,lost],axis=0)\n", "print(ak.num(found,axis=0))\n", "print(ak.num(lost,axis=0))\n", "print(ak.num(both,axis=0))" @@ -530,35 +530,14 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 19, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'\\ndef shared_track(mc_arr, mc_itr):\\n for itr in mc_itr: #iterate over events\\n potential = mc_arr[mc_arr[\"event_count\"]==itr] #holds all pt of a single event\\n velo_idx = potential[\"velo_track_idx\"].to_numpy()\\n velo_idx_unis, mults = np.unique(velo_idx, return_counts=True)\\n print(velo_idx_unis, mults)\\n if any(x>1 for x in mults):\\n'" - ] - }, - "execution_count": 48, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#versuche teilchen von denselben events mit shared tracks zu finden. \n", "#idee: alle teilchen eines events sind durch event_count auffindbar. \n", "a_f_itr = found[\"event_count\"].to_numpy()\n", - "f_itr = np.unique(a_f_itr)\n", - "\n", - "\"\"\"\n", - "def shared_track(mc_arr, mc_itr):\n", - " for itr in mc_itr: #iterate over events\n", - " potential = mc_arr[mc_arr[\"event_count\"]==itr] #holds all pt of a single event\n", - " velo_idx = potential[\"velo_track_idx\"].to_numpy()\n", - " velo_idx_unis, mults = np.unique(velo_idx, return_counts=True)\n", - " print(velo_idx_unis, mults)\n", - " if any(x>1 for x in mults):\n", - "\"\"\" " + "f_itr = np.unique(a_f_itr)\n" ] }, { @@ -570,7 +549,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -579,7 +558,7 @@ "2" ] }, - "execution_count": 72, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -593,7 +572,8 @@ " temp = both[both[\"event_count\"]==itr]\n", " if ak.num(temp,axis=0)>1:\n", " #iterate over cols in temp and append all with duplicate velo_track_idx, such that possibles is array with possible shared tracks particles\n", - " #print(temp.tolist())\n", + " #idea: look at one event at a time and at one velo track at a time. if there are at least two e with the same velo_track_idx in the same event,\n", + " #concatenate to the array of other shared track particles\n", " _jitr = temp[\"velo_track_idx\"].to_numpy()\n", " jitr = np.unique(_jitr)\n", " for jentry in jitr:\n", @@ -603,7 +583,7 @@ " psb = jtem\n", " count=1\n", " else:\n", - " psb = ak.concatenate([psb,jtem],axis=1)\n", + " psb = ak.concatenate([psb,jtem],axis=0)\n", " else:\n", " continue\n", " else:\n", @@ -614,22 +594,66 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "217" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "_jitr = temp[\"velo_track_idx\"].to_numpy()\n", - " jitr = np.unique(_jitr)\n", - " for jentry in jitr:\n", - " jtem = temp[temp[\"velo_track_idx\"]==jentry]\n", - " if ak.num(jtem,axis=0)>1:\n", - " if count==0:\n", - " psb = jtem\n", - " count=1\n", - " else:\n", - " psb = ak.concatenate([psb,jtem],axis=1)\n", - " else:\n", - " continue" + "temp_ = found[\"velo_track_idx\"].to_numpy()\n", + "temp = np.unique(temp_)\n", + "count=0\n", + "psb=ak.ArrayBuilder()\n", + "for jentry in temp:\n", + " jtem = found[found[\"velo_track_idx\"]==jentry]\n", + " if ak.num(jtem,axis=0)>1:\n", + " psb.append(jtem)\n", + " else:\n", + " continue\n", + "\n", + "psb = ak.Array(psb)\n", + "\n", + "ak.num(psb,axis=0)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "velo idx: 1\n", + "event_count: [3692, 5481, 8364, 8596]\n", + "\n", + "velo x: [9.85, -11.9, 28.6, -5.75]\n", + "velo y: [1.43, 20.1, 8.4, -27.6]\n", + "\n", + "velo tx: [0.0146, -0.0161, 0.0404, -0.00595]\n", + "velo ty: [0.00154, 0.0273, 0.00778, -0.0497]\n" + ] + } + ], + "source": [ + "idx = 1\n", + "print(\"velo idx: \" ,idx)\n", + "print(\"event_count: \", psb[idx,:,\"event_count\"])\n", + "print(\"\\nvelo x: \" ,psb[idx,:,\"velo_track_x\"])\n", + "print(\"velo y: \" ,psb[idx,:,\"velo_track_y\"])\n", + "\n", + "print(\"\\nvelo tx: \" ,psb[idx,:,\"velo_track_tx\"])\n", + "print(\"velo ty: \" ,psb[idx,:,\"velo_track_ty\"])" ] }, {