{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Welcome to JupyROOT 6.10/02\n" ] } ], "source": [ "import ROOT\n", "\n", "in_file = ROOT.TFile(\"~/work/sti-profiling/inputs_joinTwo.root\")\n", "#in_file = ROOT.TFile(\"/home/smirnovd/my-tests-data/inputs_joinTwo.root\")\n", "\n", "t = in_file.Get(\"t\")\n", "\n", "ROOT.enableJSVis()\n", "ROOT.gStyle.SetPadRightMargin(0.3)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import plotly\n", "import plotly.figure_factory as ff\n", "import plotly.graph_objs as go\n", "\n", "plotly.offline.init_notebook_mode(connected=True)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Define some functions\n", "\n", "g_h_counter = 1\n", "\n", "# Fill 1D histogram from the tree\n", "def project1D(expression, x_bins, x_first, x_last, h_title = \"\", selection = \"\"):\n", "\n", " global g_h_counter\n", "\n", " h_name = 'h_{:03d}'.format(g_h_counter)\n", " g_h_counter += 1\n", "\n", " if h_title == \"\":\n", " h_title = expression\n", "\n", " h1D = ROOT.TH1D(h_name, h_title, x_bins, x_first, x_last)\n", "\n", " t.Project(h_name, expression, selection)\n", "\n", " return h1D\n", "\n", "\n", "\n", "# Fill 2D histogram from the tree\n", "def project2D(expression, x_bins, x_first, x_last, y_bins, y_first, y_last,\n", " h_title = \"\", selection = \"\", draw_options = \"\"):\n", "\n", " global g_h_counter\n", "\n", " h_name = 'h_{:03d}'.format(g_h_counter)\n", " g_h_counter += 1\n", "\n", " if h_title == \"\":\n", " h_title = expression\n", "\n", " h2D = ROOT.TH2D(h_name, h_title, x_bins, x_first, x_last, y_bins, y_first, y_last)\n", " h2D.SetOption(draw_options)\n", "\n", " t.Project(h_name, expression, selection, draw_options)\n", "\n", " return h2D\n", "\n", "\n", "\n", "def drawOnCanvases(hists, width = 800, height = 600):\n", "\n", " canvases = []\n", "\n", " for hist in hists:\n", " canvas = ROOT.TCanvas(\"canvas_\" + hist.GetName(), \"ROOT Canvas\", width, height)\n", " hist.Draw( hist.GetOption() )\n", " canvas.Draw()\n", " canvases.append(canvas)\n", "\n", " return canvases\n", "\n", "\n", "\n", "def getCumulative(hists):\n", "\n", " hists_cumul = []\n", "\n", " for hist in hists:\n", " hist_cumul = hist\n", " hist_cumul.Scale( 1./hist_cumul.Integral() )\n", " hist_cumul = hist_cumul.GetCumulative()\n", " hists_cumul.append(hist_cumul)\n", "\n", " return hists_cumul\n", "\n", "\n", "\n", "def plotly1D(h1D):\n", "\n", " y_values_ptr = h1D.GetArray()\n", " y_values = []\n", " x_values = []\n", "\n", " for i_bin in range( 1, h1D.GetNbinsX() + 1 ):\n", " y_values.append( y_values_ptr[i_bin] )\n", " x_values.append( h1D.GetBinCenter(i_bin) )\n", "\n", " #return [ go.Bar(y = y_values) ]\n", " plotly.offline.iplot( [ go.Bar(y = y_values) ] )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Distributions for each component of the input vectors" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "hists = []\n", "\n", "# Create and plot input distributions\n", "hists.append( project1D(\"P1[0]\", 100, -20, 200, \"; x; events\", \"nP1 == 6\") )\n", "hists.append( project1D(\"P1[1]\", 100, -60, 60, \"; y; events\", \"nP1 == 6\") )\n", "hists.append( project1D(\"P1[2]\", 100, -250, 250, \"; z; events\", \"nP1 == 6\") )\n", "hists.append( project1D(\"P1[3]\", 100, -1.5, 1.5, \"; #phi; events\", \"nP1 == 6\") )\n", "hists.append( project1D(\"P1[4]\", 100, -100, 100, \"; q/Pt; events\", \"nP1 == 6\") )\n", "hists.append( project1D(\"P1[5]\", 100, -5, 5, \"; tan(#Lambda); events\", \"nP1 == 6\") )\n", "\n", "canvases = drawOnCanvases(hists)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Correlation between the corresponding components of the input vectors" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "hists = []\n", "\n", "# Create and plot input distributions\n", "hists.append( project2D(\"P1[0]:P2[0]\", 200, -20, 200, 200, -20, 200, \"; P2[x]; P1[x];\", \"nP1 == 6\", \"colz logz\") )\n", "hists.append( project2D(\"P1[1]:P2[1]\", 200, -60, 60, 200, -60, 60, \"; P2[y]; P1[y];\", \"nP1 == 6\", \"colz logz\") )\n", "hists.append( project2D(\"P1[2]:P2[2]\", 200, -250, 250, 200, -250, 250, \"; P2[z]; P1[z];\", \"nP1 == 6\", \"colz logz\") )\n", "hists.append( project2D(\"P1[3]:P2[3]\", 200, -1.5, 1.5, 200, -1.5, 1.5, \"; P2[#phi]; P1[#phi];\", \"nP1 == 6\", \"colz logz\") )\n", "hists.append( project2D(\"P1[4]:P2[4]\", 200, -100, 100, 200, -100, 100, \"; P2[q/Pt]; P1[q/Pt];\", \"nP1 == 6\", \"colz logz\") )\n", "hists.append( project2D(\"P1[5]:P2[5]\", 200, -5, 5, 200, -5, 5, \"; P2[tan(#Lambda)]; P1[tan(#Lambda)];\", \"nP1 == 6\", \"colz logz\") )\n", "\n", "canvases = drawOnCanvases(hists)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Correlation between the corresponding components of the input and output vectors" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "hists = []\n", "\n", "# Create and plot input distributions\n", "hists.append( project2D(\"P1[0]:PJ[0]\", 200, -20, 200, 200, -20, 200, \"; PJ[x]; P1[x];\", \"nP1 == 6\", \"colz logz\") )\n", "hists.append( project2D(\"P1[1]:PJ[1]\", 200, -60, 60, 200, -60, 60, \"; PJ[y]; P1[y];\", \"nP1 == 6\", \"colz logz\") )\n", "hists.append( project2D(\"P1[2]:PJ[2]\", 200, -250, 250, 200, -250, 250, \"; PJ[z]; P1[z];\", \"nP1 == 6\", \"colz logz\") )\n", "hists.append( project2D(\"P1[3]:PJ[3]\", 200, -1.5, 1.5, 200, -1.5, 1.5, \"; PJ[#phi]; P1[#phi];\", \"nP1 == 6\", \"colz logz\") )\n", "hists.append( project2D(\"P1[4]:PJ[4]\", 200, -100, 100, 200, -100, 100, \"; PJ[q/Pt]; P1[q/Pt];\", \"nP1 == 6\", \"colz logz\") )\n", "hists.append( project2D(\"P1[5]:PJ[5]\", 200, -5, 5, 200, -5, 5, \"; PJ[tan(#Lambda)]; P1[tan(#Lambda)];\", \"nP1 == 6\", \"colz logz\") )\n", "\n", "canvases = drawOnCanvases(hists)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Difference between individual components in input and output vectors" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "hists = []\n", "\n", "hists.append( project1D(\"fabs(P2[0] - PJ[0]) / sqrt(E2[1])\", 50, 0, 10, \"; #chi[x]; prob.\" , \"nP2 == 6\") )\n", "hists.append( project1D(\"fabs(P2[1] - PJ[1]) / sqrt(E2[2])\", 50, 0, 10, \"; #chi[y]; prob.\" , \"nP2 == 6\") )\n", "hists.append( project1D(\"fabs(P2[2] - PJ[2]) / sqrt(E2[5])\", 50, 0, 10, \"; #chi[z]; prob.\" , \"nP2 == 6\") )\n", "hists.append( project1D(\"fabs(P2[3] - PJ[3]) / sqrt(E2[9])\", 50, 0, 10, \"; #chi[#phi]; prob.\" , \"nP2 == 6\") )\n", "hists.append( project1D(\"fabs(P2[4] - PJ[4]) / sqrt(E2[14])\", 50, 0, 10, \"; #chi[q/Pt]; prob.\" , \"nP2 == 6\") )\n", "hists.append( project1D(\"fabs(P2[5] - PJ[5]) / sqrt(E2[20])\", 50, 0, 10, \"; #chi[tan(#Lambda)]; prob.\", \"nP2 == 6\") )\n", "\n", "#canvases = drawOnCanvases(hists)\n", "hists_cumul = getCumulative(hists)\n", "canvases = drawOnCanvases(hists_cumul)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Difference between input and output vectors for all/inner/outer nodes" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "diff_P2_PJ_chi2 = (\n", " \" (P2[1] - PJ[1]) * (P2[1] - PJ[1]) / E2[2] + \"\n", " \" (P2[2] - PJ[2]) * (P2[2] - PJ[2]) / E2[5] + \"\n", " \" (P2[3] - PJ[3]) * (P2[3] - PJ[3]) / E2[9] + \"\n", " \" (P2[4] - PJ[4]) * (P2[4] - PJ[4]) / E2[14] + \"\n", " \" (P2[5] - PJ[5]) * (P2[5] - PJ[5]) / E2[20] \"\n", ")\n", "\n", "hists = []\n", "\n", "hists.append( project1D(diff_P2_PJ_chi2, 50, 0, 50, \"; #chi^2; \", \"nP1 == 6\") )\n", "hists.append( project1D(diff_P2_PJ_chi2, 50, 0, 50, \"; #chi^2; \", \"nP1 == 6 && ino == 1\") )\n", "hists.append( project1D(diff_P2_PJ_chi2, 50, 0, 50, \"; #chi^2; \", \"nP1 == 6 && ino == -1\") )\n", "\n", "hists_cumul = getCumulative(hists)\n", "canvases = drawOnCanvases(hists_cumul)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Auxilary plots\n", "\n", "1 nP2 vs nP1\n", "2 inner/middle/outer = -1/0/1. More outer nodes than inner ones?\n", "3 Direction of the fit. The fit is done only in one direction (0 = outside in)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "
\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "hists = []\n", "\n", "hists.append( project2D(\"nP2:nP1\", 10, 0, 10, 10, 0, 10, \"; nP1; nP2\", \"\", \"colz\") )\n", "hists.append( project1D(\"ino\", 5, -2, 3, \"; inner/middle/outer; \", \"nP1 == 6\") )\n", "hists.append( project1D(\"dir\", 4, -2, 2, \"; fit direction; \", \"\") )\n", "hists.append( project1D(\"dir\", 4, -2, 2, \"; fit direction; \", \"nP1 == 6\") )\n", "\n", "canvases = drawOnCanvases(hists)" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The raw code for this IPython notebook is by default hidden for easier reading.\n", "To toggle on/off the raw code, click here." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.1" }, "toc": { "nav_menu": {}, "number_sections": true, "sideBar": false, "skip_h1_title": false, "toc_cell": false, "toc_position": {}, "toc_section_display": "block", "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }