From 2df1468e58ca09286672ed45159b98d360962d5a Mon Sep 17 00:00:00 2001 From: cetin Date: Tue, 26 Sep 2023 15:12:03 +0200 Subject: [PATCH] finding shared tracks in all found events --- D_tasks.ipynb | 332 ++++++++++++++++++++++++++++---------------------- 1 file changed, 189 insertions(+), 143 deletions(-) diff --git a/D_tasks.ipynb b/D_tasks.ipynb index c02bcb0..cd918a0 100644 --- a/D_tasks.ipynb +++ b/D_tasks.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [ @@ -21,9 +21,20 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 61, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "51" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "file = uproot.open(\"tracking_losses_ntuple_Dst0ToD0EE.root:PrDebugTrackingLosses.PrDebugTrackingTool/Tuple;1\")\n", "\n", @@ -33,12 +44,13 @@ "found = allcolumns[(allcolumns.isElectron) & (~allcolumns.lost) & (allcolumns.fromSignal) & (allcolumns.p < 5e3)] #D: 2591\n", "lost = allcolumns[(allcolumns.isElectron) & (allcolumns.lost) & (allcolumns.fromSignal) & (allcolumns.p < 5e3)] #D: 1908\n", "\n", - "#ak.num(lost, axis=0)" + "#ak.num(lost, axis=0)\n", + "ak.num(allcolumns[(allcolumns.fromPairProd) & (allcolumns.isElectron) & (~allcolumns.lost) & (allcolumns.fromSignal)],axis=0)" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 62, "metadata": {}, "outputs": [ { @@ -47,7 +59,7 @@ "0.5759057568348522" ] }, - "execution_count": 4, + "execution_count": 62, "metadata": {}, "output_type": "execute_result" } @@ -63,7 +75,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 63, "metadata": {}, "outputs": [ { @@ -72,7 +84,7 @@ "0.7960893854748603" ] }, - "execution_count": 5, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } @@ -94,7 +106,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 64, "metadata": {}, "outputs": [ { @@ -103,7 +115,7 @@ "0.5568703211784594" ] }, - "execution_count": 6, + "execution_count": 64, "metadata": {}, "output_type": "execute_result" } @@ -126,7 +138,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 65, "metadata": {}, "outputs": [ { @@ -147,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 66, "metadata": {}, "outputs": [ { @@ -184,7 +196,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 67, "metadata": {}, "outputs": [], "source": [ @@ -213,7 +225,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 68, "metadata": {}, "outputs": [], "source": [ @@ -244,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 69, "metadata": {}, "outputs": [], "source": [ @@ -282,7 +294,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 70, "metadata": {}, "outputs": [ { @@ -340,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 71, "metadata": {}, "outputs": [ { @@ -376,7 +388,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 72, "metadata": {}, "outputs": [ { @@ -385,7 +397,7 @@ "-1.5438992626615335e-08" ] }, - "execution_count": 14, + "execution_count": 72, "metadata": {}, "output_type": "execute_result" } @@ -396,7 +408,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 73, "metadata": {}, "outputs": [ { @@ -444,7 +456,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 74, "metadata": {}, "outputs": [ { @@ -471,7 +483,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 75, "metadata": {}, "outputs": [ { @@ -505,7 +517,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 76, "metadata": {}, "outputs": [ { @@ -519,9 +531,6 @@ } ], "source": [ - "shared = np.array([0,1,0,1,1,2])\n", - "len(shared)\n", - "\n", "both = ak.concatenate([found,lost],axis=0)\n", "print(ak.num(found,axis=0))\n", "print(ak.num(lost,axis=0))\n", @@ -530,42 +539,33 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 81, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "#events w/ shared track electrons from found and lost: 1\n", + "event_count: [2822, 2822]\n", + "velo idx: [146, 146]\n", + "mcp_index: [5806, 5829]\n", + "\n", + "velo x: [-75.1, -75.1]\n", + "velo y: [5.88, 5.88]\n", + "\n", + "velo tx: [-0.0908, -0.0908]\n", + "velo ty: [0.00703, 0.00703]\n" + ] + } + ], "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" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#psb = ak.Array([])\n", - "global psb\n", + "f_itr = np.unique(a_f_itr)\n", + "\n", + "shared = ak.ArrayBuilder()\n", "count = 0\n", "\n", "for itr in f_itr:\n", @@ -579,36 +579,51 @@ " 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=0)\n", + " shared.append(jtem)\n", " else:\n", " continue\n", " else:\n", " continue\n", - " \n", - "ak.num(psb, axis=0)" + "shared = ak.Array(shared)\n", + "\n", + "idx=0\n", + "print(\"#events w/ shared track electrons from found and lost: \",ak.num(shared, axis=0))\n", + "\n", + "print(\"event_count: \", shared[idx,:,\"event_count\"])\n", + "print(\"velo idx: \" ,shared[idx,:,\"velo_track_idx\"])\n", + "print(\"mcp_index: \", shared[idx,:,\"mcp_idx\"])\n", + "\n", + "print(\"\\nvelo x: \" ,shared[idx,:,\"velo_track_x\"])\n", + "print(\"velo y: \" ,shared[idx,:,\"velo_track_y\"])\n", + "\n", + "print(\"\\nvelo tx: \" ,shared[idx,:,\"velo_track_tx\"])\n", + "print(\"velo ty: \" ,shared[idx,:,\"velo_track_ty\"])" ] }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 82, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "217" - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "#velo_track_idx in all events: 217\n", + "velo idx: [0, 0, 0]\n", + "mcp_index: [1066, 1251, 666]\n", + "event_count: [5735, 7049, 7378]\n", + "\n", + "velo x: [-2.21, 9.45, -18.5]\n", + "velo y: [-21.6, -33.4, 17.4]\n", + "\n", + "velo tx: [-0.0022, 0.0153, -0.0224]\n", + "velo ty: [-0.0263, -0.0469, 0.0212]\n" + ] } ], "source": [ + "#electrons with same velo_track_idx from all events\n", "temp_ = found[\"velo_track_idx\"].to_numpy()\n", "temp = np.unique(temp_)\n", "count=0\n", @@ -622,32 +637,10 @@ "\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(\"#velo_track_idx in all events: \",ak.num(psb,axis=0))\n", + "idx = 0\n", + "print(\"velo idx: \" ,psb[idx,:,\"velo_track_idx\"])\n", + "print(\"mcp_index: \", psb[idx,:,\"mcp_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", @@ -656,17 +649,6 @@ "print(\"velo ty: \" ,psb[idx,:,\"velo_track_ty\"])" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "for epair in range(10):\n", - " print(\"possibles[\", str(epair), \"]= \", psb[epair].tolist())" - ] - }, { "cell_type": "code", "execution_count": null, @@ -676,48 +658,112 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, + "execution_count": 83, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "[-0.03604912757873535,\n", - " 0.01677863299846649,\n", - " 0.03238071873784065,\n", - " -0.009163273498415947,\n", - " -0.022408662363886833,\n", - " -0.004034307319670916,\n", - " -0.01760791800916195,\n", - " 0.049464158713817596,\n", - " -0.01695789396762848]" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "#events w/ shared track electrons from Photon Conversions: 951\n", + "shared_idx: 0\n", + "event_count: [11, 11]\n", + "velo idx: [27, 27]\n", + "mcp_index: [1211, 1215]\n", + "\n", + "velo x: [-20.4, -20.4]\n", + "velo y: [-24.4, -24.4]\n", + "\n", + "velo tx: [-0.0234, -0.0234]\n", + "velo ty: [-0.028, -0.028]\n" + ] } ], "source": [ - "mo=found[(found[\"mother_key\"]==3) & (found[\"mother_id\"]==423)]\n", - "mo\n", + "#generell: wie viele elektronen von photon conversions teilen sich einen track?\n", + "conv = allcolumns[(allcolumns.fromPairProd) & (allcolumns.isElectron) & (~allcolumns.lost)]\n", "\n", - "\"\"\"\n", - "mother_key : event number\n", - "mother_id : specific event type\n", - "\"\"\"\n", - "ak.num(mo[\"energy\"], axis=0)\n", - "#mother_key=3 : 9 particles\n", - "mo[\"velo_track_ty\"].tolist()" + "conv_it = conv[\"event_count\"].to_numpy()\n", + "conv_itr = np.unique(conv_it)\n", + "\n", + "cshared = ak.ArrayBuilder()\n", + "count = 0\n", + "\n", + "for itr in conv_itr:\n", + " temp = conv[conv[\"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", + " #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", + " jtem = temp[temp[\"velo_track_idx\"]==jentry]\n", + " if ak.num(jtem,axis=0)>1:\n", + " cshared.append(jtem)\n", + " else:\n", + " continue\n", + " else:\n", + " continue\n", + "cshared = ak.Array(cshared)\n", + "\n", + "\n", + "print(\"#events w/ shared track electrons from Photon Conversions: \",ak.num(cshared, axis=0))\n", + "idx = 0\n", + "print(\"shared_idx: \", idx)\n", + "print(\"event_count: \", cshared[idx,:,\"event_count\"])\n", + "print(\"velo idx: \" ,cshared[idx,:,\"velo_track_idx\"])\n", + "print(\"mcp_index: \", cshared[idx,:,\"mcp_idx\"])\n", + "\n", + "print(\"\\nvelo x: \" ,cshared[idx,:,\"velo_track_x\"])\n", + "print(\"velo y: \" ,cshared[idx,:,\"velo_track_y\"])\n", + "\n", + "print(\"\\nvelo tx: \" ,cshared[idx,:,\"velo_track_tx\"])\n", + "print(\"velo ty: \" ,cshared[idx,:,\"velo_track_ty\"])" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null,