diff --git a/rdstar/offline_analysis/tagging_calibration/comparison_speedup.ipynb b/rdstar/offline_analysis/tagging_calibration/comparison_speedup.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..5dacc5ea354e0e0462f41341888025738fc8ebfb --- /dev/null +++ b/rdstar/offline_analysis/tagging_calibration/comparison_speedup.ipynb @@ -0,0 +1,196 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "import rdstar.offline_analysis.vcb_legacy_tools as vlt\n", + "import pandas as pd\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Existing base paths:\n", + "/group/belle2/users/kilian/Data/vcb_legacy/target\n" + ] + } + ], + "source": [ + "fm = vlt.FileManager()\n", + "fm.append_basepath(\"/group/belle2/users/kilian/Data/vcb_legacy/target/\")\n", + "fm.base_stats()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "a = fm.get(\"prod_191104_single_dispatch/Charged_0/default3/tempunchecked_default3_Y4S_ntuple.root\")" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": {}, + "outputs": [], + "source": [ + "b = fm.get(\"prod_191104_single_dispatch/Charged_0/fast4/tempunchecked_fast4_Y4S_ntuple.root\")" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [], + "source": [ + "df_a = vlt.load_root_file(a, processing=lambda df: vlt.standard_processing(df, \"Charged\", columns=None))" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [], + "source": [ + "df_b = vlt.load_root_file(b, processing=lambda df: vlt.standard_processing(df, \"Charged\", columns=None))" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [], + "source": [ + "#df_b[diff != 0]" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [], + "source": [ + "def get_difference_series(df_a, df_b, var):\n", + " assert (df_a.index == df_b.index).all()\n", + " diff = df_a[var] - df_b[var]\n", + " return df_a[diff != 0][var], df_b[diff != 0][var]" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": {}, + "outputs": [], + "source": [ + "def get_difference_columns(df_a, df_b):\n", + " set(df_a.columns) - set(df_b.columns)\n", + " res = []\n", + " for col in df_a.columns:\n", + " try:\n", + " diff = np.flatnonzero((df_a[col] - df_b[col]))\n", + " except TypeError:\n", + " pass\n", + " if len(diff) >= 1:\n", + " res.append(col)\n", + " return res" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [], + "source": [ + "def plot_differences(df_a, df_b, var, axs=None):\n", + " a, b = get_difference_series(df_a, df_b, var)\n", + " if axs is None:\n", + " _, axs = plt.subplots(1, 2, figsize=(10, 5))\n", + " axs[0].scatter(a, b)\n", + " x_min, x_max = axs[0].get_xlim()\n", + " x = np.linspace(x_min, x_max, 100)\n", + " axs[0].plot(x, x, \"k:\")\n", + " axs[0].set_xlabel(\"a\")\n", + " axs[0].set_ylabel(\"b\")\n", + " axs[0].get_figure().suptitle(var)\n", + " axs[1].hist(a, label=\"a\", histtype=\"step\", lw=2)\n", + " axs[1].hist(b, label=\"b\", histtype=\"step\", lw=2)\n", + " axs[1].legend(frameon=False)\n", + " return ax" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [], + "source": [ + "def plot_all_differences(df_a, df_b):\n", + " cols = get_difference_columns(df_a, df_b)\n", + " print(cols)\n", + " for col in cols:\n", + " plot_differences(df_a, df_b, col)\n", + " plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[]\n" + ] + } + ], + "source": [ + "plot_all_differences(df_a, df_b)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (Belle2)", + "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.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}