diff --git a/0_create_dirs.ipynb b/0_create_dirs.ipynb new file mode 100644 index 0000000..87bae12 --- /dev/null +++ b/0_create_dirs.ipynb @@ -0,0 +1,170 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "import os" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "l_index = 0\n", + "mother_index = None\n", + "data_type = ['MC','data']\n", + "mother_ID=['Dplus','Ds']\n", + "l_flv = ['e','mu']\n", + "PATH='/disk/lhcb_data/davide/Rphipi_new/'\n", + "n_cats = 6" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# MC dirs" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "if not os.path.exists(PATH+data_type[0]):\n", + " os.makedirs(PATH+data_type[0])\n", + " \n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples')\n", + " \n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/presel/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/presel/')\n", + " \n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/truthed/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/truthed/')\n", + "\n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/ghosts/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/ghosts/')\n", + " \n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/')\n", + " \n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/for_BDT/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/for_BDT/')\n", + "\n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/presel/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/presel/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/')\n", + "\n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/presel/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/presel/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/')\n", + "\n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/truthed/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/truthed/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/')\n", + " \n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/truthed/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/truthed/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/')\n", + "\n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/ghosts/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/ghosts/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/')\n", + " \n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/ghosts/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/ghosts/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/')\n", + "\n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/')\n", + " \n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/')\n", + "\n", + "for i in range(n_cats):\n", + "\n", + " if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/trigCats/'+str(i)):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/trigCats/'+str(i))\n", + " \n", + " if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/trigCats/'+str(i)):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/trigCats/'+str(i))\n", + " \n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/for_BDT/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/for_BDT/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index])\n", + "\n", + "if not os.path.exists(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/for_BDT/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]):\n", + " os.makedirs(PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/for_BDT/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index])\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Data dirs" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "if not os.path.exists(PATH+data_type[1]):\n", + " os.makedirs(PATH+data_type[1])\n", + " \n", + "if not os.path.exists(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples'):\n", + " os.makedirs(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples')\n", + " \n", + "if not os.path.exists(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/presel/'):\n", + " os.makedirs(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/presel/')\n", + " \n", + "if not os.path.exists(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/trigged/'):\n", + " os.makedirs(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/trigged/')\n", + "\n", + "if not os.path.exists(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/trigged/trigCats/'):\n", + " os.makedirs(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/trigged/trigCats/')\n", + "\n", + "if not os.path.exists(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/for_BDT/'):\n", + " os.makedirs(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/for_BDT/')\n", + "\n", + "for i in range(n_cats):\n", + "\n", + " if not os.path.exists(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/trigged/trigCats/'+str(i)):\n", + " os.makedirs(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/trigged/trigCats/'+str(i))\n", + " \n", + " if not os.path.exists(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/trigged/trigCats/'+str(i)):\n", + " os.makedirs(PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/trigged/trigCats/'+str(i))\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1_MC_preselection.ipynb b/1_MC_preselection.ipynb new file mode 100644 index 0000000..6c5c75c --- /dev/null +++ b/1_MC_preselection.ipynb @@ -0,0 +1,606 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/hep/davide/miniconda3/envs/root_env/lib/ROOT.py:301: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility\n", + " return _orig_ihook( name, *args, **kwds )\n" + ] + } + ], + "source": [ + "import ROOT as r\n", + "import root_numpy as rn\n", + "import numpy as np\n", + "import root_numpy as rn\n", + "import matplotlib.pyplot as plt\n", + "import os\n", + "\n", + "from tools.data_processing import *\n", + "from tools.kinematics_fix import *\n", + "from tools.preselector import *\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "l_index = 0\n", + "mother_index = None\n", + "data_index = 0\n", + "n_cats=6\n", + "apply_phi_mass_cut = True\n", + "data_type = ['MC','data']\n", + "mother_ID=['Dplus','Ds']\n", + "l_flv = ['e','mu']\n", + "PATH='/disk/lhcb_data/davide/Rphipi_new/'\n", + "\n", + "save_path_presel_Dplus= PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/presel/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'\n", + "save_path_presel_Ds= PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/presel/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'\n", + "\n", + "save_path_truthed_Dplus= PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/truthed/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'\n", + "save_path_ghosts_Dplus= PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/ghosts/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'\n", + "save_path_truthed_Ds= PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/truthed/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'\n", + "save_path_ghosts_Ds= PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/truthed/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'\n", + "\n", + "save_path_trigged_Dplus = PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'\n", + "save_path_trigged_Ds= PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'\n", + "\n", + "save_path_trigCats_Dplus= save_path_trigged_Dplus+'trigCats/'\n", + "save_path_trigCats_Ds= save_path_trigged_Ds+'trigCats/'\n", + "\n", + "save_path_BDT_for_Dplus= PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/for_BDT_training/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'\n", + "save_path_BDT_for_Ds= PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/for_BDT_training/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "#retrieve files\n", + "\n", + "def find_file_path(l_index=l_index, mother_index=mother_index): \n", + " return \"/disk/lhcb_data/davide/Rphipi/MC/\"+mother_ID[mother_index]+\"_phipi_\"+l_flv[l_index]+l_flv[l_index]+\"/\"+mother_ID[mother_index]+\"_phipi_\"+l_flv[l_index]+l_flv[l_index]+\".root\"\n", + "\n", + "MC_Dplus = r.TFile(find_file_path(l_index=l_index, mother_index=0))\n", + "MC_Ds = r.TFile(find_file_path(l_index=l_index, mother_index=1))\n", + "\n", + "tree_name_Dplus = mother_ID[0]+'_OfflineTree/DecayTree'\n", + "tree_name_Ds = mother_ID[1]+'_OfflineTree/DecayTree'\n", + "\n", + "t_MC_Dplus = MC_Dplus.Get(tree_name_Dplus)\n", + "t_MC_Ds = MC_Ds.Get(tree_name_Ds)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Converting tuples to dictionary" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "#Switch on only the branches that you need\n", + "t_MC_Dplus.SetBranchStatus(\"*\",0)\n", + "\n", + "for branch in return_branches(data_index=data_index, mother_index=0, l_index=l_index):\n", + " if branch!='cos_thetal':\n", + " t_MC_Dplus.SetBranchStatus(branch, 1)\n", + " \n", + "MC_Dplus_tuple_dict_presel = {}\n", + "branches_needed=return_branches(data_index=data_index, mother_index=0, l_index=l_index)\n", + "\n", + "for branch in branches_needed:\n", + " if branch!='cos_thetal':\n", + " MC_Dplus_tuple_dict_presel[branch] = rn.root2array(\n", + " \n", + " filenames= find_file_path(l_index=l_index, mother_index=0),\n", + " treename = tree_name_Dplus,\n", + " branches = branch,\n", + " start=0,\n", + " stop=t_MC_Dplus.GetEntries(),\n", + " )\n", + " \n", + "t_MC_Ds.SetBranchStatus(\"*\",0)\n", + " \n", + "for branch in return_branches(data_index=data_index, mother_index=1, l_index=l_index):\n", + " if branch!='cos_thetal':\n", + " t_MC_Ds.SetBranchStatus(branch, 1)\n", + "\n", + "MC_Ds_tuple_dict_presel = {}\n", + "branches_needed=return_branches(data_index=data_index, mother_index=1, l_index=l_index)\n", + "for branch in branches_needed:\n", + " if branch!='cos_thetal':\n", + " MC_Ds_tuple_dict_presel[branch] = rn.root2array(\n", + " \n", + " filenames=find_file_path(l_index=l_index, mother_index=1),\n", + " treename = tree_name_Ds,\n", + " branches = branch,\n", + " start=0,\n", + " stop=t_MC_Ds.GetEntries(),\n", + " ) \n", + "\n", + "\n", + "MC_Dplus_tuple_dict_presel= fix_mass_vector(MC_Dplus_tuple_dict_presel, 'Dplus_ConsD_M')\n", + "MC_Ds_tuple_dict_presel = fix_mass_vector(MC_Ds_tuple_dict_presel, 'Ds_ConsD_M')\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Add Cos_thetal branch" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "costheta_Dplus=get_costheta_list(MC_Dplus_tuple_dict_presel, l_index=l_index, mother_index=0)\n", + "costheta_Ds=get_costheta_list(MC_Ds_tuple_dict_presel, l_index=l_index, mother_index=1)\n", + "\n", + "MC_Dplus_tuple_dict_presel[\"cos_thetal\"]=costheta_Dplus\n", + "MC_Ds_tuple_dict_presel[\"cos_thetal\"]=costheta_Ds\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Save the tuples" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "presel\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/presel/Dplus_phipi_ee/Dplus_phipi_ee_presel.pickle\n", + "presel\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/presel/Ds_phipi_ee/Dplus_phipi_ee_presel.root\n", + "presel\n", + "Saving pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/presel/Dplus_phipi_ee/Ds_phipi_ee_presel.pickle\n", + "presel\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/presel/Ds_phipi_ee/Ds_phipi_ee_presel.root\n" + ] + } + ], + "source": [ + "save_tuples(locals(), MC_Dplus_tuple_dict_presel, l_index, save_path_presel_Dplus, file_format='pickle')\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_presel, l_index, save_path_presel_Ds, file_format='root')\n", + "\n", + "save_tuples(locals(), MC_Ds_tuple_dict_presel, l_index, save_path_presel_Dplus, file_format='pickle')\n", + "save_tuples(locals(), MC_Ds_tuple_dict_presel, l_index, save_path_presel_Ds, file_format='root')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Truthmatching and saving the tuples" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "truthed\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/truthed/Dplus_phipi_ee/Dplus_phipi_ee_truthed.pickle\n", + "truthed\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/truthed/Dplus_phipi_ee/Dplus_phipi_ee_truthed.root\n", + "ghosts\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/ghosts/Dplus_phipi_ee/Dplus_phipi_ee_ghosts.pickle\n", + "ghosts\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/ghosts/Dplus_phipi_ee/Dplus_phipi_ee_ghosts.root\n", + "truthed\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/truthed/Ds_phipi_ee/Ds_phipi_ee_truthed.pickle\n", + "truthed\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/truthed/Ds_phipi_ee/Ds_phipi_ee_truthed.root\n", + "ghosts\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/truthed/Ds_phipi_ee/Ds_phipi_ee_ghosts.pickle\n", + "ghosts\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/truthed/Ds_phipi_ee/Ds_phipi_ee_ghosts.root\n" + ] + } + ], + "source": [ + "\n", + "MC_Dplus_tuple_dict_truthed = filter_tuple_cond(locals(), MC_Dplus_tuple_dict_presel, l_index, 'Dplus_BKGCAT', cmp_eq, 0)\n", + "MC_Dplus_tuple_dict_ghosts =filter_tuple_cond(locals(), MC_Dplus_tuple_dict_presel, l_index, 'Dplus_BKGCAT', cmp_eq, 60)\n", + "\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_truthed, l_index, save_path_truthed_Dplus, file_format='pickle')\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_truthed, l_index, save_path_truthed_Dplus, file_format='root')\n", + "\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_ghosts, l_index, save_path_ghosts_Dplus, file_format='pickle')\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_ghosts, l_index, save_path_ghosts_Dplus, file_format='root')\n", + "\n", + "\n", + "MC_Ds_tuple_dict_truthed = filter_tuple_cond(locals(), MC_Ds_tuple_dict_presel, l_index, 'Ds_BKGCAT', cmp_eq, 0)\n", + "MC_Ds_tuple_dict_ghosts = filter_tuple_cond(locals(), MC_Ds_tuple_dict_presel, l_index, 'Ds_BKGCAT', cmp_eq, 60)\n", + "\n", + "\n", + "save_tuples(locals(), MC_Ds_tuple_dict_truthed, l_index, save_path_truthed_Ds, file_format='pickle')\n", + "save_tuples(locals(), MC_Ds_tuple_dict_truthed, l_index, save_path_truthed_Ds, file_format='root')\n", + "\n", + "save_tuples(locals(), MC_Ds_tuple_dict_ghosts, l_index, save_path_ghosts_Ds, file_format='pickle')\n", + "save_tuples(locals(), MC_Ds_tuple_dict_ghosts, l_index, save_path_ghosts_Ds, file_format='root')\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Phi Mass Cut " + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "if apply_phi_mass_cut:\n", + " \n", + " if l_flv[l_index]=='mu':\n", + " lower_phi_mass = 990\n", + " upper_phi_mass = 1050\n", + " \n", + " if l_flv[l_index]=='e':\n", + " lower_phi_mass = 870\n", + " upper_phi_mass = 1110\n", + " \n", + " MC_Dplus_tuple_dict_truthed =filter_tuple_mass_cut(locals(), MC_Dplus_tuple_dict_truthed, l_index, 'phi_M', lower_bound=lower_phi_mass, upper_bound=upper_phi_mass, cut_kind='inside')\n", + " MC_Ds_tuple_dict_truthed =filter_tuple_mass_cut(locals(), MC_Ds_tuple_dict_truthed, l_index, 'phi_M', lower_bound=lower_phi_mass, upper_bound=upper_phi_mass, cut_kind='inside')\n", + " \n", + "#for i in range(20):\n", + "# \n", + "# upper_cut=np.arange(800+5*i,1100-5*i).max()\n", + "# lower_cut=np.arange(800+5*i,1100-5*i).min()\n", + "# plt.clf()\n", + "# MC_Dplus_tuple_dict_truthed_phi_cut=filter_tuple_mass_cut(globals(), MC_Dplus_tuple_dict_truthed, l_index, 'phi_M', lower_bound=lower_cut, upper_bound=upper_cut)\n", + "# plt.hist(MC_Dplus_tuple_dict_truthed_phi_cut['Dplus_ConsD_M'],bins=40);\n", + "# plt.savefig('plot_{0}.png'.format(i))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Get Hlt cuts " + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hlt1\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/Dplus_phipi_ee_Hlt1.pickle\n", + "Hlt1\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/Dplus_phipi_ee_Hlt1.root\n", + "Hlt1\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/Ds_phipi_ee_Hlt1.pickle\n", + "Hlt1\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/Ds_phipi_ee_Hlt1.root\n", + "Hlt2\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/Dplus_phipi_ee_Hlt2.pickle\n", + "Hlt2\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/Dplus_phipi_ee_Hlt2.root\n", + "Hlt2\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/Ds_phipi_ee_Hlt2.pickle\n", + "Hlt2\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/Ds_phipi_ee_Hlt2.root\n", + "FullHlt\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/Dplus_phipi_ee_FullHlt.pickle\n", + "FullHlt\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/Dplus_phipi_ee_FullHlt.root\n", + "FullHlt\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/Ds_phipi_ee_FullHlt.pickle\n", + "FullHlt\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/Ds_phipi_ee_FullHlt.root\n" + ] + } + ], + "source": [ + "#Hlt1\n", + "MC_Dplus_tuple_dict_Hlt1 = filter_tuple_cond(locals(), MC_Dplus_tuple_dict_truthed, l_index, 'Dplus_Hlt1TrackMVADecision_TOS', cmp_eq, True)\n", + "\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_Hlt1, l_index, save_path_trigged_Dplus, file_format='pickle')\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_Hlt1, l_index, save_path_trigged_Dplus, file_format='root')\n", + "\n", + "MC_Ds_tuple_dict_Hlt1 = filter_tuple_cond(locals(), MC_Ds_tuple_dict_truthed, l_index, 'Ds_Hlt1TrackMVADecision_TOS', cmp_eq, True)\n", + "\n", + "save_tuples(locals(), MC_Ds_tuple_dict_Hlt1, l_index, save_path_trigged_Ds, file_format='pickle')\n", + "save_tuples(locals(), MC_Ds_tuple_dict_Hlt1, l_index, save_path_trigged_Ds, file_format='root')\n", + "\n", + "#Hlt2\n", + "MC_Dplus_tuple_dict_Hlt2 = filter_tuple_cond(locals(), MC_Dplus_tuple_dict_truthed, l_index, \"Dplus_Hlt2RareCharmD2Pi\"+l_flv[l_index].capitalize()+l_flv[l_index].capitalize()+\"OSDecision_TOS\",cmp_eq, True)\n", + "\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_Hlt2, l_index, save_path_trigged_Dplus, file_format='pickle')\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_Hlt2, l_index, save_path_trigged_Dplus, file_format='root')\n", + "\n", + "MC_Ds_tuple_dict_Hlt2 = filter_tuple_cond(locals(), MC_Ds_tuple_dict_truthed, l_index, \"Ds_Hlt2RareCharmD2Pi\"+l_flv[l_index].capitalize()+l_flv[l_index].capitalize()+\"OSDecision_TOS\",cmp_eq, True)\n", + "\n", + "save_tuples(locals(), MC_Ds_tuple_dict_Hlt2, l_index, save_path_trigged_Ds, file_format='pickle')\n", + "save_tuples(locals(), MC_Ds_tuple_dict_Hlt2, l_index, save_path_trigged_Ds, file_format='root')\n", + "\n", + "#FullHlt\n", + "MC_Dplus_tuple_dict_FullHlt = filter_tuple_cond(locals(), MC_Dplus_tuple_dict_Hlt1, l_index, \"Dplus_Hlt2RareCharmD2Pi\"+l_flv[l_index].capitalize()+l_flv[l_index].capitalize()+\"OSDecision_TOS\",cmp_eq, True)\n", + "\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_FullHlt, l_index, save_path_trigged_Dplus, file_format='pickle')\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_FullHlt, l_index, save_path_trigged_Dplus, file_format='root')\n", + "\n", + "MC_Ds_tuple_dict_FullHlt = filter_tuple_cond(locals(), MC_Ds_tuple_dict_Hlt1, l_index, \"Ds_Hlt2RareCharmD2Pi\"+l_flv[l_index].capitalize()+l_flv[l_index].capitalize()+\"OSDecision_TOS\",cmp_eq, True)\n", + "\n", + "save_tuples(locals(), MC_Ds_tuple_dict_FullHlt, l_index, save_path_trigged_Ds, file_format='pickle')\n", + "save_tuples(locals(), MC_Ds_tuple_dict_FullHlt, l_index, save_path_trigged_Ds, file_format='root')\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Split in trigger categories\n", + "\n", + " if trig_cat == 0:\n", + " #Exclusive L0_Lepton_TOS \n", + " \n", + " if trig_cat == 1:\n", + " #Exclusive L0_Global_TIS\n", + " \n", + " if trig_cat == 2:\n", + " #L0_Lepton_TOS and L0_Global_TIS\n", + " \n", + " if trig_cat == 3:\n", + " #Either L0_Lepton_TOS or L0_Global_TIS\n", + " \n", + " if trig_cat == 4:\n", + " #TOS and TOSandTIS\n", + "\n", + " if trig_cat == 5:\n", + " #TIS and TOSandTIS\n", + "\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The counts come back\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/0/Dplus_phipi_ee_trigCat0.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/1/Dplus_phipi_ee_trigCat1.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/2/Dplus_phipi_ee_trigCat2.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/3/Dplus_phipi_ee_trigCat3.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/4/Dplus_phipi_ee_trigCat4.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/5/Dplus_phipi_ee_trigCat5.pickle\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/0/Dplus_phipi_ee_trigCat0.root\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/1/Dplus_phipi_ee_trigCat1.root\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/2/Dplus_phipi_ee_trigCat2.root\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/3/Dplus_phipi_ee_trigCat3.root\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/4/Dplus_phipi_ee_trigCat4.root\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Dplus_phipi_ee/trigCats/5/Dplus_phipi_ee_trigCat5.root\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/0/Ds_phipi_ee_trigCat0.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/1/Ds_phipi_ee_trigCat1.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/2/Ds_phipi_ee_trigCat2.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/3/Ds_phipi_ee_trigCat3.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/4/Ds_phipi_ee_trigCat4.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/5/Ds_phipi_ee_trigCat5.pickle\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/0/Ds_phipi_ee_trigCat0.root\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/1/Ds_phipi_ee_trigCat1.root\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/2/Ds_phipi_ee_trigCat2.root\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/3/Ds_phipi_ee_trigCat3.root\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/4/Ds_phipi_ee_trigCat4.root\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/trigged/Ds_phipi_ee/trigCats/5/Ds_phipi_ee_trigCat5.root\n" + ] + } + ], + "source": [ + "MC_Dplus_tuple_dict_trigCats = {}\n", + "MC_Ds_tuple_dict_trigCats = {}\n", + "\n", + "for i in range(n_cats):\n", + " \n", + " MC_Dplus_tuple_dict_trigCats[i] = filter_tuple_L0TrigCat(locals(), MC_Dplus_tuple_dict_FullHlt, l_index, i)\n", + " MC_Ds_tuple_dict_trigCats[i] = filter_tuple_L0TrigCat(locals(), MC_Ds_tuple_dict_FullHlt, l_index, i)\n", + " \n", + "n_0=MC_Dplus_tuple_dict_trigCats[0]['Dplus_ConsD_M'].shape[0]\n", + "n_1=MC_Dplus_tuple_dict_trigCats[1]['Dplus_ConsD_M'].shape[0]\n", + "n_2=MC_Dplus_tuple_dict_trigCats[2]['Dplus_ConsD_M'].shape[0]\n", + "n_3=MC_Dplus_tuple_dict_trigCats[3]['Dplus_ConsD_M'].shape[0]\n", + "n_4=MC_Dplus_tuple_dict_trigCats[4]['Dplus_ConsD_M'].shape[0]\n", + "n_5=MC_Dplus_tuple_dict_trigCats[5]['Dplus_ConsD_M'].shape[0]\n", + "\n", + "sanity_1=np.array_equal([n_0+n_2+n_1==n_3,n_0+n_5==n_3,n_4+n_1==n_3],[True,True,True])\n", + "\n", + "n_0=MC_Ds_tuple_dict_trigCats[0]['Ds_ConsD_M'].shape[0]\n", + "n_1=MC_Ds_tuple_dict_trigCats[1]['Ds_ConsD_M'].shape[0]\n", + "n_2=MC_Ds_tuple_dict_trigCats[2]['Ds_ConsD_M'].shape[0]\n", + "n_3=MC_Ds_tuple_dict_trigCats[3]['Ds_ConsD_M'].shape[0]\n", + "n_4=MC_Ds_tuple_dict_trigCats[4]['Ds_ConsD_M'].shape[0]\n", + "n_5=MC_Ds_tuple_dict_trigCats[5]['Ds_ConsD_M'].shape[0]\n", + "\n", + "sanity_2=np.array_equal([n_0+n_2+n_1==n_3,n_0+n_5==n_3,n_4+n_1==n_3],[True,True,True])\n", + "if sanity_1 and sanity_2:\n", + " print('The counts come back')\n", + " \n", + " save_tuples(locals(), MC_Dplus_tuple_dict_trigCats, l_index, save_path_trigCats_Dplus, file_format='pickle')\n", + " save_tuples(locals(), MC_Dplus_tuple_dict_trigCats, l_index, save_path_trigCats_Dplus, file_format='root')\n", + " \n", + " save_tuples(locals(), MC_Ds_tuple_dict_trigCats, l_index, save_path_trigCats_Ds, file_format='pickle')\n", + " save_tuples(locals(), MC_Ds_tuple_dict_trigCats, l_index, save_path_trigCats_Ds, file_format='root')\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Prepare Sig Sets for BDT" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "for_BDT\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/for_BDT/Dplus_phipi_ee/Dplus_phipi_ee_for_BDT.pickle\n", + "for_BDT\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/for_BDT/Dplus_phipi_ee/Dplus_phipi_ee_for_BDT.root\n", + "for_BDT\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/for_BDT/Ds_phipi_ee/Ds_phipi_ee_for_BDT.pickle\n", + "for_BDT\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/MC/e_tuples/for_BDT/Ds_phipi_ee/Ds_phipi_ee_for_BDT.root\n" + ] + } + ], + "source": [ + "if l_flv[l_index]=='mu':\n", + " \n", + " lower_Dplus_mass_mc=1830\n", + " upper_Dplus_mass_mc=1910\n", + " \n", + " lower_Ds_mass_mc=1930\n", + " upper_Ds_mass_mc=2010\n", + " \n", + " \n", + "if l_flv[l_index]=='e':\n", + " \n", + " lower_Dplus_mass_mc=1790\n", + " upper_Dplus_mass_mc=1950\n", + "\n", + " lower_Ds_mass_mc=1890\n", + " upper_Ds_mass_mc=2050\n", + " \n", + "\n", + "MC_Dplus_tuple_dict_sig_for_BDT = filter_tuple_mass_cut(locals(), MC_Dplus_tuple_dict_FullHlt, l_index, 'Dplus_ConsD_M', lower_bound=lower_Dplus_mass_mc, upper_bound=upper_Dplus_mass_mc, cut_kind='inside') \n", + "save_tuples(locals(), MC_Dplus_tuple_dict_sig_for_BDT, l_index, save_path_BDT_for_Dplus, file_format='pickle')\n", + "save_tuples(locals(), MC_Dplus_tuple_dict_sig_for_BDT, l_index, save_path_BDT_for_Dplus, file_format='root')\n", + "\n", + "\n", + "MC_Ds_tuple_dict_sig_for_BDT = filter_tuple_mass_cut(locals(), MC_Ds_tuple_dict_FullHlt, l_index, 'Ds_ConsD_M', lower_bound=lower_Ds_mass_mc, upper_bound=upper_Ds_mass_mc, cut_kind='inside') \n", + "save_tuples(locals(), MC_Ds_tuple_dict_sig_for_BDT, l_index, save_path_BDT_for_Ds, file_format='pickle')\n", + "save_tuples(locals(), MC_Ds_tuple_dict_sig_for_BDT, l_index, save_path_BDT_for_Ds, file_format='root')\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYEAAAD8CAYAAACRkhiPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAADkxJREFUeJzt3V+s5OVdx/H3p+1KUqsG2EOb9Ox6Lpo0Goqke0AbtKWKAdlEE7EQdPWCmhVT/1BvKPUCuSDhQjTBmtBNwCoYspGWNqa7Cr1CkibkgHT/sFj/hMIxhT0V03ChBMvXi/Ngx+Uczp+ZOWdmnvcrmcxvnvnNzPPdJzufeX7/TqoKSVKf3rHbHZAk7R5DQJI6ZghIUscMAUnqmCEgSR0zBCSpY4aAJHXMEJCkjhkCktSxd+12BwD27t1bCwsLu90NSZoqTz311Heqam6Y95iIEFhYWGBpaWm3uyFJUyXJt4Z9DzcHSVLHDAFJ6pghIEkdMwQkqWOGgCR1zBCQpI4ZApLUMUNAkjpmCEhSxybijGFNroXPfPX/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1r3yMd8t/eMb2EP+kOsToNeZzXdPglcAXwDeBZ4BvipgfX/kNXtqKdpR9G09sW27rPA52gnzE3ybSu1A7/Saj4JnAI+Ma21r1P3LcBzrba7BmuYlTHfSt0zNt4/DRSrO0afabdrgQuBr7UavwZcMEtjvtW6Rz3mnjEsSR2b9s1BkqQhGAKS1DFDQJI6ZghIUscMAUnqmCEgSR0zBCSpY4aAJHXsfwE7/xiPvXWzDQAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.hist(np.concatenate([MC_Dplus_tuple_dict_sig_for_BDT['Dplus_ConsD_M'],MC_Ds_tuple_dict_sig_for_BDT['Ds_ConsD_M']]), bins=70);\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAESNJREFUeJzt3X2MZXddx/H3h1LAloLd9q4NtMuGxDTGtllhGiSolFBi2wUSgrYQlsQsZsEotTUoVKOl0T8wkYegJmR5iHGX1I0FQWEHuoQ0tRox27J0tw+UYIqFtLvTUgtCRB6+/jFnZdjO7D33zr13Zn77fiWT83DPOfc7Z+5+9nd/95zfTVUhSdr4nrLWBUiSJsNAl6RGGOiS1AgDXZIaYaBLUiMMdElqhIEuSY0w0CWpEQa6JDXiqbN8snPPPbe2bt06y6eUpA3vzjvvfLSqBsO2m2mgb926lYMHD87yKSVpw0vytT7b2eUiSY0w0CWpEQa6JDXCQJekRhjoktSIoYGe5MIkh5b8fCvJdUk2JTmQ5HCSW5OcPYuCJUnLGxroVfXlqtpWVduAFwL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PwMPB9FjPtTbN+rXmnqCQ1YqN0uUiShjDQJakRBrokNcJAl6RGGOiS1AgDXZIaYaBLUiMMdElqxP8BfwCDi9wrm3IAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.hist(np.concatenate([MC_Dplus_tuple_dict_sig_for_BDT['cos_thetal'],MC_Ds_tuple_dict_sig_for_BDT['cos_thetal']]), bins=70);" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/2_data_preselection.ipynb b/2_data_preselection.ipynb new file mode 100644 index 0000000..779ba03 --- /dev/null +++ b/2_data_preselection.ipynb @@ -0,0 +1,440 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/hep/davide/miniconda3/envs/root_env/lib/ROOT.py:301: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility\n", + " return _orig_ihook( name, *args, **kwds )\n" + ] + } + ], + "source": [ + "import ROOT as r\n", + "import numpy as np\n", + "from array import array\n", + "import root_numpy as rn\n", + "import matplotlib.pyplot as plt\n", + "import pickle\n", + "import math\n", + "import os\n", + "\n", + "from tools.data_processing import *\n", + "from tools.kinematics_fix import *\n", + "from tools.preselector import *\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "l_index = 1\n", + "mother_index = 1\n", + "data_index = 1\n", + "apply_phi_mass_cut = True\n", + "n_cats=6\n", + "data_type = ['MC','data']\n", + "mother_ID=['Dplus','Ds']\n", + "l_flv = ['e','mu']\n", + "PATH='/disk/lhcb_data/davide/Rphipi_new/'\n", + "\n", + "save_path_presel_data=PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/presel/'\n", + "save_path_trigged_data=PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/trigged/'\n", + "save_path_trigCats_data=save_path_trigged_data+'trigCats/'\n", + "save_path_BDT_for_data=PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/for_BDT_training/'" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "#retrieve files\n", + "\n", + "def find_file_path(l_index=l_index, mother_index=mother_index): \n", + " return \"/disk/lhcb_data/davide/Rphipi/data/\"+mother_ID[mother_index]+\"_phipi_\"+l_flv[l_index]+l_flv[l_index]+\"/\"+mother_ID[mother_index]+\"_phipi_\"+l_flv[l_index]+l_flv[l_index]+\".root\"\n", + "\n", + "data = r.TFile(find_file_path(l_index=l_index, mother_index=mother_index))\n", + "tree_name_Ds = mother_ID[mother_index]+'_OfflineTree/DecayTree'\n", + "t_data = data.Get(tree_name_Ds)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Converting tuples to dictionary" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "#Switch on only the branches that you need\n", + "data_tuple_dict = {}\n", + "\n", + "t_data.SetBranchStatus(\"*\",0)\n", + "\n", + "for branch in return_branches(data_index=data_index, mother_index=mother_index, l_index=l_index):\n", + " if branch!='cos_thetal':\n", + " t_data.SetBranchStatus(branch, 1)\n", + "\n", + "branches_needed=return_branches(data_index=data_index, mother_index=mother_index, l_index=l_index)\n", + "for branch in branches_needed:\n", + " if branch!='cos_thetal':\n", + " data_tuple_dict[branch] = rn.root2array(\n", + " \n", + " filenames=find_file_path(l_index, mother_index=mother_index),\n", + " treename = tree_name_Ds,\n", + " branches = branch,\n", + " start=0,\n", + " stop=t_data.GetEntries(),\n", + " )\n", + " \n", + "data_tuple_dict = fix_mass_vector(data_tuple_dict, 'Ds_ConsD_M')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Phi Mass Cut " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "#for plot purposes\n", + "#data_tuple_dict_phi_cut=data_tuple_dict\n", + "\n", + "if apply_phi_mass_cut:\n", + " \n", + " if l_flv[l_index]=='mu':\n", + " lower_phi_mass = 990\n", + " upper_phi_mass = 1050\n", + " \n", + " if l_flv[l_index]=='e':\n", + " lower_phi_mass = 870\n", + " upper_phi_mass = 1110\n", + " \n", + " data_tuple_dict =filter_tuple_mass_cut(locals(), data_tuple_dict, l_index, \n", + " 'phi_M', lower_bound=lower_phi_mass, upper_bound=upper_phi_mass, \n", + " cut_kind='inside', include_costhetal = False)\n", + " \n", + "##nice plot\n", + "#for i in range(20):\n", + "# \n", + "# upper_cut=np.arange(800+5*i,1100-5*i).max()\n", + "# lower_cut=np.arange(800+5*i,1100-5*i).min()\n", + "# plt.clf()\n", + "# data_tuple_dict_phi_cut=filter_tuple_mass_cut(globals(), data_tuple_dict_phi_cut, l_index, 'phi_M', lower_bound=lower_cut, upper_bound=upper_cut)\n", + "# plt.hist(data_tuple_dict_phi_cut['Ds_ConsD_M'],bins=40);\n", + "# plt.savefig('plot_{0}.png'.format(i))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# PID Cut " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "if l_flv[l_index]=='mu':\n", + " lPID_cut = 0.4\n", + " piPID_cut = 0.6\n", + " \n", + " \n", + "if l_flv[l_index]=='e':\n", + " lPID_cut = 0.2\n", + " piPID_cut = 0.6\n", + " \n", + "data_tuple_dict_eplusPID =filter_tuple_cond(locals(), data_tuple_dict, l_index, l_flv[l_index]+\"_plus_MC15TuneV1_ProbNN\"+l_flv[l_index], cmp_gte, lPID_cut, include_costhetal=False)\n", + "data_tuple_dict_eminusPID =filter_tuple_cond(locals(), data_tuple_dict_eplusPID, l_index, l_flv[l_index]+\"_minus_MC15TuneV1_ProbNN\"+l_flv[l_index], cmp_gte, lPID_cut, include_costhetal=False)\n", + "data_tuple_dict_presel =filter_tuple_cond(locals(), data_tuple_dict_eminusPID, l_index, 'pi_MC15TuneV1_ProbNNpi', cmp_gte, piPID_cut, include_costhetal=False)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Add cos_thetal branch & save preselection" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "costheta_Ds=get_costheta_list(data_tuple_dict_presel, l_index=l_index, mother_index=mother_index)\n", + "data_tuple_dict_presel[\"cos_thetal\"]=costheta_Ds\n", + "\n", + "save_tuples(locals(), data_tuple_dict_presel, l_index, save_path_presel_data, file_format='pickle')\n", + "save_tuples(locals(), data_tuple_dict_presel, l_index, save_path_presel_data, file_format='root')\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Get Hlt cuts " + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hlt1\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/Ds_phipi_mumu_Hlt1.pickle\n", + "Hlt1\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/Ds_phipi_mumu_Hlt1.root\n", + "Hlt2\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/Ds_phipi_mumu_Hlt2.pickle\n", + "Hlt2\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/Ds_phipi_mumu_Hlt2.root\n", + "FullHlt\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/Ds_phipi_mumu_FullHlt.pickle\n", + "FullHlt\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/Ds_phipi_mumu_FullHlt.root\n" + ] + } + ], + "source": [ + "data_tuple_dict_presel_Hlt1 = filter_tuple_cond(locals(), data_tuple_dict_presel, l_index, 'Ds_Hlt1TrackMVADecision_TOS', cmp_eq, True)\n", + "\n", + "data_tuple_dict_presel_Hlt2 = filter_tuple_cond(locals(), data_tuple_dict_presel, l_index, \"Ds_Hlt2RareCharmD2Pi\"+l_flv[l_index].capitalize()+l_flv[l_index].capitalize()+\"OSDecision_TOS\",cmp_eq, True)\n", + "\n", + "data_tuple_dict_presel_FullHlt = filter_tuple_cond(locals(), data_tuple_dict_presel_Hlt1, l_index, \"Ds_Hlt2RareCharmD2Pi\"+l_flv[l_index].capitalize()+l_flv[l_index].capitalize()+\"OSDecision_TOS\",cmp_eq, True)\n", + "\n", + "save_tuples(locals(), data_tuple_dict_presel_Hlt1, l_index, save_path_trigged_data, file_format='pickle')\n", + "save_tuples(locals(), data_tuple_dict_presel_Hlt1, l_index, save_path_trigged_data, file_format='root')\n", + "\n", + "save_tuples(locals(), data_tuple_dict_presel_Hlt2, l_index, save_path_trigged_data, file_format='pickle')\n", + "save_tuples(locals(), data_tuple_dict_presel_Hlt2, l_index, save_path_trigged_data, file_format='root')\n", + "\n", + "save_tuples(locals(), data_tuple_dict_presel_FullHlt, l_index, save_path_trigged_data, file_format='pickle')\n", + "save_tuples(locals(), data_tuple_dict_presel_FullHlt, l_index, save_path_trigged_data, file_format='root')\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Split in trigger categories\n", + "\n", + " if trig_cat == 0:\n", + " #Exclusive L0_Lepton_TOS \n", + " \n", + " if trig_cat == 1:\n", + " #Exclusive L0_Global_TIS\n", + " \n", + " if trig_cat == 2:\n", + " #L0_Lepton_TOS and L0_Global_TIS\n", + " \n", + " if trig_cat == 3:\n", + " #Either L0_Lepton_TOS or L0_Global_TIS\n", + " \n", + " if trig_cat == 4:\n", + " #TOS and TOSandTIS\n", + "\n", + " if trig_cat == 5:\n", + " #TIS and TOSandTIS\n", + "\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The counts are coming back\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/0/Ds_phipi_mumu_trigCat0.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/1/Ds_phipi_mumu_trigCat1.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/2/Ds_phipi_mumu_trigCat2.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/3/Ds_phipi_mumu_trigCat3.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/4/Ds_phipi_mumu_trigCat4.pickle\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/5/Ds_phipi_mumu_trigCat5.pickle\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/0/Ds_phipi_mumu_trigCat0.root\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/1/Ds_phipi_mumu_trigCat1.root\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/2/Ds_phipi_mumu_trigCat2.root\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/3/Ds_phipi_mumu_trigCat3.root\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/4/Ds_phipi_mumu_trigCat4.root\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/trigged/trigCats/5/Ds_phipi_mumu_trigCat5.root\n" + ] + } + ], + "source": [ + "data_tuple_dict_presel_trigCats = {}\n", + "\n", + "for i in range(n_cats):\n", + " \n", + " data_tuple_dict_presel_trigCats[i] = filter_tuple_L0TrigCat(locals(), data_tuple_dict_presel_FullHlt, l_index, trig_cat=i)\n", + " \n", + "n_0=data_tuple_dict_presel_trigCats[0]['Ds_ConsD_M'].shape[0]\n", + "n_1=data_tuple_dict_presel_trigCats[1]['Ds_ConsD_M'].shape[0]\n", + "n_2=data_tuple_dict_presel_trigCats[2]['Ds_ConsD_M'].shape[0]\n", + "n_3=data_tuple_dict_presel_trigCats[3]['Ds_ConsD_M'].shape[0]\n", + "n_4=data_tuple_dict_presel_trigCats[4]['Ds_ConsD_M'].shape[0]\n", + "n_5=data_tuple_dict_presel_trigCats[5]['Ds_ConsD_M'].shape[0]\n", + "\n", + "sanity=np.array_equal([n_0+n_2+n_1==n_3,n_0+n_5==n_3,n_4+n_1==n_3],[True,True,True])\n", + "\n", + "if sanity:\n", + " print('The counts are coming back')\n", + " \n", + " save_tuples(locals(), data_tuple_dict_presel_trigCats, l_index, save_path_trigCats_data, file_format='pickle')\n", + " save_tuples(locals(), data_tuple_dict_presel_trigCats, l_index, save_path_trigCats_data, file_format='root')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Prepare Bkg Sets for BDT" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "for_BDT\n", + "Saving pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/for_BDT/Ds_phipi_mumu_for_BDT.pickle\n", + "for_BDT\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/for_BDT/Ds_phipi_mumu_for_BDT.root\n" + ] + } + ], + "source": [ + "if l_flv[l_index]=='mu':\n", + " \n", + " lower_Dplus_mass_data=1830\n", + " upper_Dplus_mass_data=1910\n", + " \n", + " lower_Ds_mass_data=1930\n", + " upper_Ds_mass_data=2010\n", + " \n", + " \n", + "if l_flv[l_index]=='e':\n", + " \n", + " lower_Dplus_mass_data=1810\n", + " upper_Dplus_mass_data=1920\n", + "\n", + " lower_Ds_mass_data=1920\n", + " upper_Ds_mass_data=2020\n", + " \n", + "data_Ds_tuple_dict_bkg_1 = filter_tuple_mass_cut(locals(), data_tuple_dict_presel_FullHlt, l_index, 'Ds_ConsD_M', lower_bound=lower_Dplus_mass_data, upper_bound=upper_Dplus_mass_data, cut_kind='outside')\n", + "data_Ds_tuple_dict_bkg_for_BDT = filter_tuple_mass_cut(locals(), data_Ds_tuple_dict_bkg_1, l_index, 'Ds_ConsD_M', lower_bound=lower_Ds_mass_data, upper_bound=upper_Ds_mass_data, cut_kind='outside')\n", + " \n", + "save_tuples(locals(), data_Ds_tuple_dict_bkg_for_BDT, l_index, save_path_BDT_for_data, file_format='pickle')\n", + "save_tuples(locals(), data_Ds_tuple_dict_bkg_for_BDT, l_index, save_path_BDT_for_data, file_format='root') \n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAEEVJREFUeJzt3W2MpWddx/Hvj7IpImhadiqRWdwXJAazrQ07FEhFHixpYQ1GCl2JKy+qaWp8oGoiLiaSvtikJjYh6Au6EUTbpG4EKkF2pSXElEZNM4WyDyyCMYVOQrsHUIJGNyv9+2KuldNlzs6ZhzPn7DXfTzI5932d+z73f6+d/c211/0wqSokSf16zrQLkCRNlkEvSZ0z6CWpcwa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"
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.hist(data_Ds_tuple_dict_bkg_for_BDT['Ds_ConsD_M'], bins=70);" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAEJ1JREFUeJzt3X2IZXd9x/H3pzUGTESMmY3U3biIECrrEswkIpY20oBJVgtlW1PbRIqx2xQfSGuLxkKNtAstKEpaIS6NSJOSLuRBS7trjASJKbRhkq6bTTZNsUSz4mbHKGlKabpNvv1jzup1Mw/3zr1n7sxv3i8Y7rm/ex6+c+7dz/zu7zxsqgpJUrt+ZtoFSJL6ZdBLUuMMeklqnEEvSY0z6CWpcQa9JDXOoJekxhn0ktQ4g16SGveyaRcAcO6559b27dunXYYkbSgPPfTQD6pqZqX51kXQb9++nbm5uWmXIUkbSpLvDDOfQzeS1DiDXpIaZ9BLUuMMeklqnEEvSY0z6CWpcQa9JDVuxaBPsi3J/UmOJHkiyce69huTfC/Joe7nyoFlbkhytFvmnX3+ApKk5Q1zwdRJ4ENVdTjJK4GHk9zTvfbZqvr04MxJLgJ2AzuB84AHklxQVc9PsnBJ0nBWDPqqOg4c76afS3IYeN0yi+wC9lfVSeBYkkeBS4BvTqBeSdrQtn/8H3/q+ZN/vqv3bY40Rp9kO3Ax8EDX9MEkjyf52ySv6dq2Ak8NLHasazt9XXuSzCWZm5+fH7lwSdJwhg76JGcDdwDXV9WzwOeBNwJvAr4N3DTKhqtqX1XNVtXszMyK9+SRJK3SUEGf5AzgTuD2qroLoKrmq+qFqnoRuJmFnj4s9OC3DSy+tWuTJE3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U9zf62ZdRP0VXXZmKtY7rYL80lmqmo+yQxwYhJ1JRllvVcAD1fV0wPrnh9Y180sHINYs7qq6nj3eCLJHSz0nu9lyvsrC1dT3wncXlV3Dax71ftrESvepmNgnn8+bZ4zhli2z7pIshO4Bbiiqp451b7Me9p7Xd1Q26npe5L8Lwt/9If6nfqqa8BLvlH3uL+GsWafr5aGbpa77cIB4Opu+momdzuGUdb7krHBrhdxym7gsbWqK8lZ3VdZkpzFwlfax4Zdvse6wkKAHa2qz5z22iT31zC36ThA942hOyPixap6ashle6sryfnAXcA1VfXEQPty7+la1DUzMH0RcDYLf8ynur+6el4F/BILBz9PtfW5v4axdp+vPo42T/oH+FUW/qI9DzwN3NO1/xxwYGC+K4FHgaMsDPmcan8N8HXgke7xnAnVteh6F6nrLOAZujMlBtpvY+Fg4+PA11j42rsmdQFv6Lb9LRbObPkzfnIB3dT2FwvDENXVdqj7ubKP/bXY5wW4Driumw4Lw0WPdXXMLrfsBD/vK9X118CPBvbP3Erv6RrV9RHgSPfzMHDpethf3fPfBv7utOX63l+3A98HTrKQX9dO6/PllbGS1LiWhm4kSYsw6CWpcQa9JDXOoJekxhn0ktQ4g16SGmfQS1LjDHpJatz/AxxCfsoU0GOOAAAAAElFTkSuQmCC\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.hist(data_Ds_tuple_dict_bkg_for_BDT['cos_thetal'], bins=70);" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/3_BDT_train.ipynb b/3_BDT_train.ipynb new file mode 100644 index 0000000..e762c18 --- /dev/null +++ b/3_BDT_train.ipynb @@ -0,0 +1,297 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/hep/davide/miniconda3/envs/root_env/lib/python2.7/site-packages/root_numpy/_tree.py:5: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility\n", + " from . import _librootnumpy\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import os\n", + "import pickle\n", + "import math\n", + "\n", + "from sklearn.metrics import accuracy_score, roc_auc_score\n", + "\n", + "from xgboost import XGBClassifier\n", + "from tools.data_processing import *" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# IMPORTING THE DATASET" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "l_index = 1\n", + "mother_ID=['Dplus','Ds']\n", + "l_flv = ['e','mu']\n", + "PATH='/disk/lhcb_data/davide/Rphipi_new/'\n", + "n_cats = 6" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Bkg data amounts to 9660 while signal MC amounts to 5521 Ds and 9109 Dplus samples\n" + ] + } + ], + "source": [ + "MC_Dplus_sig_dict, MC_Ds_sig_dict, data_bkg_dict = load_datasets(l_index, PATH)\n", + "MC_Dplus_sig_dict, MC_Ds_sig_dict, data_bkg_dict = norm_chi2(MC_Dplus_sig_dict, MC_Ds_sig_dict, data_bkg_dict)\n", + "\n", + "m_plus=MC_Dplus_sig_dict[\"Dplus_ConsD_M\"].shape[0]\n", + "m_s=MC_Ds_sig_dict[\"Ds_ConsD_M\"].shape[0]\n", + "n=data_bkg_dict[\"Ds_ConsD_M\"].shape[0]\n", + "\n", + "#Number of input features\n", + "\n", + "print('Bkg data amounts to {0} while signal MC amounts to {1} Ds and {2} Dplus samples'.format(n,m_s,m_plus))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAFNhJREFUeJzt3X+s3fV93/Hnq3ZxtB9xAjhbZyDXESSaWdr88Mg6JW00lNSka5wssJhNmrcgoWxFaxtVm1FVRFgrhXQbWxekDg00QtdBRrbpbjjy2GhSbSKOLwkJcZibi8OGC0pNjNzRlhAn7/1xvi6Hw72+33vvuefc68/zIR35+/18P9973ufcr1/f7/18v+d7UlVIktrwQ9MuQJI0OYa+JDXE0Jekhhj6ktQQQ1+SGmLoS1JDDH1JaoihL0kNMfQlqSGbp13AqAsvvLBmZmamXYYkbSiPPPLIs1W1bal+6y70Z2ZmmJubm3YZkrShJPk/ffo5vCNJDTH0Jakhhr4kNcTQl6SGGPqS1BBDX5IaYuhLUkMMfUlqiKEvSQ0x9LUuzOx/YNolSE0w9CWpIYa+JDXE0Jekhhj6ktQQQ1+SGmLoS1JDDH1JaoihL0kNMfQlqSGGvrSR3bx12hVogzH0NXXegkGanF6hn2R3kqNJ5pPsX2D5liT3dcsPJZkZWvajSR5OciTJY0leNb7yJUnLsWToJ9kE3A5cBewErk2yc6TbdcBzVXUpcBtwa7fuZuA3gY9W1eXAu4Hvja16nVNm9j/gUb+0xvoc6V8BzFfVsap6EbgX2DPSZw9wdzd9P3BlkgDvBb5WVV8FqKrvVNX3x1O6JGm5+oT+duCpofnjXduCfarqNHAKuAB4I1BJDib5cpJ/tNATJLk+yVySuRMnTiz3NUiSeuoT+lmgrXr22Qy8E/jb3b8fTHLlKzpW3VFVu6pq17Zt23qUJElaiT6hfxy4eGj+IuD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W1bWfwgbMz1vK2Ej8P/FqSp4B/Ctw4VMPobTG2n6V9krUB/HiSryb5XJLLl6h5LXwdeH83fQ0vfThw2u/bYnXBlLa1JDPAW4FDwJ+rqmdgEHLA64bqmOj71rMumMK2NlLbYqa9rZ2VoT9wLS8/yn8GuKSq3gp8DPitbgy2120lxuTvA79QVRcDv8DgsxCcpYb1UNuXgddX1Y8B/wr4z137JGv7CPCzSR5h8Kf4i0vUMKnaFqtrKttakj8DfBb4+ar6g7N1XaSONalvGXVNfFtbr+/ZcjUf+hncNuJvAPedaev+LPtON/0Ig3G4NzLYM180tPqCt5UYk33Af+ym/wODPw1h8Vtb9LrlxVrWVlV/UFXPd9MHgB9OcuEka6uq/11V762qtzPYkT/RLZrq+7ZYXdPY1pL8MIPw+ndVdeb3+O1u2ObM0NLvd+0Te9+WU9ekt7VFalvMevg/urhJn0SY5oMFTpoxGIf8wkjbNmBTN/0G4PeA87v5wwxOaJ05ufa+taiNwbjhu7vpK4FHuumf5uUn1r7UtZ8PfIvBSbXXdtPnT7i2P89Ln/24Avi/XZ2bGZzo28FLJ7AuX6PaXtf9+0MMxsE/0s1fzstPrh1jcGJtTWpbRl0T3da6n/Vp4F+MtP8aLz9h+slJbm8rqGti29pitQ0t/zwvP5E70W1t2a9n0k84rQeDo6tngO8x2ONe17X/W+CjI30/BBzpfilfBn5maNkuBuOzTwCfOrPhjbs24J3AI10Nh4C3D22At3fP/9jIxvYRBieN5oG/t1bv21lqu2Hoffsi8FeHfs77GFz18ATwS2tY2891z/O7wCeGfz/AL3XPf5ShK2HGXdty6prCtvZOBkMKXwMe7R7vY3Ar9P8BfLP798yOZyLb2wrqmti2dpbaPtj9fr8LfBs4OOltbSUPP5ErSQ1pfkxfklpi6EtSQwx9SWqIoS9JDTH0Jakhhr4kNcTQl6SGGPqS1JD/DyPCog5LHFvWAAAAAElFTkSuQmCC\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "\n", + "plt.hist(MC_Dplus_sig_dict[\"Dplus_ConsD_M\"],bins=50, density=True);\n", + "plt.hist(MC_Ds_sig_dict[\"Ds_ConsD_M\"],bins=50, density=True);\n", + "plt.hist(data_bkg_dict[\"Ds_ConsD_M\"],bins=50, density=True);" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "#Convert data dictionaries to arrays for XG_BOOST\n", + "features=return_branches_BDT(mother_index=0, l_index=l_index)\n", + "MC_Dplus_sig = extract_array_for_BDT(MC_Dplus_sig_dict, features, m_plus)\n", + "\n", + "features=return_branches_BDT(mother_index=1, l_index=l_index)\n", + "MC_Ds_sig = extract_array_for_BDT(MC_Ds_sig_dict, features, m_s)\n", + "\n", + "features=return_branches_BDT(mother_index=1, l_index=l_index)\n", + "data_bkg = extract_array_for_BDT(data_bkg_dict, features, n)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "dim=len(features)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "#Add 0/1 label for bkg/sig\n", + "\n", + "MC_Dplus_sig_labelled=add_labels(MC_Dplus_sig,signal=True)\n", + "MC_Ds_sig_labelled=add_labels(MC_Ds_sig,signal=True)\n", + "data_bkg_labelled=add_labels(data_bkg,signal=False)\n", + "\n", + "#Merge MC sig and data bkg, shuffle it\n", + "\n", + "data=np.concatenate((data_bkg_labelled,MC_Dplus_sig_labelled), axis =0)\n", + "data=np.concatenate((data,MC_Ds_sig_labelled), axis =0)\n", + "np.random.seed(1)\n", + "np.random.shuffle(data)\n", + "\n", + "#get train size\n", + "train_size=data.shape[0]\n", + "\n", + "#Strip away the label column and convert it to a one-hot encoding\n", + "\n", + "X=data[:,0:dim]\n", + "Y_labels=data[:,dim].astype(int)\n", + "Y_labels=Y_labels.reshape(train_size,1)\n", + "Y_labels_hot = to_one_hot(Y_labels)\n", + "Y_labels=Y_labels_hot" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Training XGBOOST with K-folding" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "pAUC from XG Boost 0.89248732815\n", + "pAUC from XG Boost 0.8981822648\n", + "pAUC from XG Boost 0.891673744237\n", + "pAUC from XG Boost 0.901611464589\n", + "pAUC from XG Boost 0.907353115727\n", + "pAUC from XG Boost 0.895278819119\n", + "pAUC from XG Boost 0.894574348419\n", + "pAUC from XG Boost 0.897631671969\n", + "pAUC from XG Boost 0.891227438988\n", + "pAUC from XG Boost 0.875042311412\n" + ] + }, + { + "data": { + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#Divide the dataset k \"equi populated\" sets\n", + "test=1\n", + "k=10 #number of subsets\n", + "plot=True\n", + "for i in range(k): \n", + " X_train, Y_train, X_test, Y_test, X_dict, Y_dict = k_subsets(i, k, X, Y_labels)\n", + " \n", + " PATH_BDTs=PATH+'BDT/'+l_flv[l_index]+'/test_'+str(test)\n", + " \n", + " if not os.path.exists(PATH_BDTs):\n", + " os.mkdir(PATH_BDTs)\n", + " \n", + " if not os.path.exists(PATH_BDTs+'/variables_used.pickle'):\n", + " with open(PATH_BDTs+'/variables_used.pickle', 'wb') as handle: \n", + " pickle.dump(features, handle, protocol=2)\n", + " \n", + " PATH_current_BDT=PATH_BDTs+'/XG_'+str(i)\n", + " \n", + " if not os.path.exists(PATH_current_BDT):\n", + " os.mkdir(PATH_current_BDT)\n", + " \n", + " model = XGBClassifier()\n", + " model.fit(X_train, Y_train[:,1])\n", + " \n", + " output_XG = model.predict_proba(X_test)\n", + " \n", + " if plot:\n", + " \n", + " plt.clf();\n", + " true_positives_XG=output_XG[:,1][np.where(Y_test[:,1]==1)]\n", + " false_positives_XG=output_XG[:,1][np.where(Y_test[:,0]==1)]\n", + " plt.hist(true_positives_XG,alpha=0.5,bins=80,density=True,label=\"True positives\");\n", + " plt.hist(false_positives_XG,alpha=0.5,bins=80,density=True, label=\"False positives\");\n", + " plt.legend()\n", + " plt.xlabel(\"XGBoost BDT output\", fontsize='15')\n", + " plt.ylabel(\"Events (a.u.)\", fontsize='15')\n", + " fig=plt.gcf()\n", + " fig.set_size_inches(16,8)\n", + " plt.savefig(PATH_current_BDT+'/tp_vs_fp_XG.png', format='png', dpi=100)\n", + " plt.clf();\n", + " \n", + " threshold_range=np.linspace(0.0,1.,num=30)\n", + " sig_eps_vals_XG=[sel_eff(true_positives_XG,threshold_range[k]) for k in range(len(threshold_range))]\n", + " bkg_eps_vals_XG=[sel_eff(false_positives_XG,threshold_range[k]) for k in range(len(threshold_range))]\n", + " \n", + " \n", + " plt.plot(threshold_range,threshold_range, 'black', linestyle='dashed')\n", + " plt.plot(bkg_eps_vals_XG,sig_eps_vals_XG,'b',label=\"XG Boost ROC Curve\")\n", + " plt.xlabel(\"Background selection efficiency\", fontsize='15')\n", + " plt.ylabel(\"Signal selection efficiency\", fontsize='15')\n", + " pAUC_XG=roc_auc_score(Y_test,output_XG)\n", + " plt.text(0.69,0.1,\"\\n XGBoost AUC {0:.4g}\\n\".format(pAUC_XG), bbox=dict(boxstyle=\"round\", facecolor='blue', alpha=0.10), horizontalalignment='center', verticalalignment='center',fontsize='15')\n", + " plt.legend()\n", + " fig=plt.gcf()\n", + " fig.set_size_inches(8,8)\n", + " \n", + " print(\"pAUC from XG Boost {0}\".format(pAUC_XG))\n", + " plt.savefig(PATH_current_BDT+'/roc_comparison_'+str(i)+'.png', format='png', dpi=100)\n", + " plt.clf();\n", + " \n", + " plt.bar(np.arange(dim),model.feature_importances_)\n", + " plt.xticks(np.arange(dim), features[:-1], rotation=90, fontsize=12);\n", + " fig=plt.gcf()\n", + " fig.set_size_inches(12,6)\n", + " plt.savefig(PATH_current_BDT+'/significant_features_'+str(i)+'.png', format='png', dpi=100)\n", + " plt.clf();\n", + " \n", + " # save XGBOOST model to file\n", + " pickle.dump(model, open(PATH_current_BDT+\"/XG_\"+str(i)+\".pickle.dat\", \"wb\"), protocol=2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/4a_prepare_MC_workspace.ipynb b/4a_prepare_MC_workspace.ipynb new file mode 100644 index 0000000..b5b3eff --- /dev/null +++ b/4a_prepare_MC_workspace.ipynb @@ -0,0 +1,311 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/hep/davide/miniconda3/envs/root_env/lib/ROOT.py:301: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility\n", + " return _orig_ihook( name, *args, **kwds )\n" + ] + } + ], + "source": [ + "import ROOT as r\n", + "import root_numpy as rn\n", + "import pickle\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import array as array\n", + "from xgboost import XGBClassifier\n", + "from tools.data_processing import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "l_flv=['e','mu']\n", + "mother_ID=[\"Dplus\",\"Ds\",\"both\"]\n", + "PATH='/disk/lhcb_data/davide/Rphipi_new/'\n", + "data_type=['MC','data']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# PATHs" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "data_index=0\n", + "test=1\n", + "l_index=0\n", + "trigCat=0\n", + "\n", + "mother_index=0\n", + "mis_id_bkg=False\n", + "\n", + "PATH_BDTs=PATH+'BDT/'+l_flv[l_index]+'/test_'+str(test)+'/'\n", + "FIT_PATH=l_flv[l_index]+'_fits/'\n", + "MC_PATH = PATH+'MC/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[mother_index]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/trigCats/'+str(trigCat)+'/'\n", + "\n", + "workspace_filename='fitAndsPlot_D_phipi_'+l_flv[l_index]+l_flv[l_index]+'_2016_trigCat'+str(trigCat)+'.root'\n", + "workspace_path='/home/hep/davide/Rphipi_new/workspaces/'\n", + "\n", + "mpi = 140\n", + "if l_flv[l_index]=='mu':\n", + " ml = 105 \n", + " \n", + " if mis_id_bkg==False:\n", + " \n", + " if mother_ID[mother_index]=='Dplus':\n", + " \n", + " mean_d_down=1830\n", + " mean_d_startval=1850\n", + " mean_d_up=1910\n", + "\n", + " if mother_ID[mother_index]=='Ds':\n", + " \n", + " mean_d_down=1925\n", + " mean_d_startval=1950\n", + " mean_d_up=2010\n", + " \n", + " \n", + " if mis_id_bkg==True:\n", + " \n", + " if mother_ID[mother_index]=='Dplus':\n", + " \n", + " mean_d_down=1780\n", + " mean_d_startval=1840\n", + " mean_d_up=1910\n", + " \n", + " if mother_ID[mother_index]=='Ds':\n", + " \n", + " mean_d_down=1880\n", + " mean_d_startval=1950\n", + " mean_d_up=2010\n", + " \n", + " \n", + "if l_flv[l_index]=='e':\n", + " ml=0.5\n", + " if mis_id_bkg==False:\n", + " if mother_ID[mother_index]=='Dplus':\n", + " \n", + " mean_d_down=1780\n", + " mean_d_startval=1850\n", + " mean_d_up=1970\n", + "\n", + " if mother_ID[mother_index]=='Ds':\n", + " \n", + " mean_d_down=1850\n", + " mean_d_startval=1950\n", + " mean_d_up=2090\n", + " \n", + " if mis_id_bkg==True:\n", + " if mother_ID[mother_index]=='Dplus':\n", + " \n", + " mean_d_down=1650\n", + " mean_d_startval=1840\n", + " mean_d_up=1950\n", + " \n", + " if mother_ID[mother_index]=='Ds':\n", + " mean_d_down=1750\n", + " mean_d_startval=1900\n", + " mean_d_up=2080\n", + "\n", + "names={}\n", + "names['m_name']=data_type[data_index]+\"_\"+mother_ID[mother_index]+\"_m\"\n", + "\n", + "names['mean_D_name']=data_type[data_index]+\"_mean_\"+mother_ID[mother_index]\n", + "names['sigma_D_name']=data_type[data_index]+\"_sigma_\"+mother_ID[mother_index]\n", + "\n", + "names['alpha_left_name']=data_type[data_index]+\"_alpha_\"+mother_ID[mother_index]+\"_left\"\n", + "names['n_left_name' ]=data_type[data_index]+\"_n_\"+mother_ID[mother_index]+\"_left\"\n", + "names['sig_pdf_left_name' ]=data_type[data_index]+\"_pdf_\"+mother_ID[mother_index]+\"_left\"\n", + "\n", + "names['alpha_right_name']=data_type[data_index]+\"_alpha_\"+mother_ID[mother_index]+\"_right\"\n", + "names['n_right_name'] =data_type[data_index]+\"_n_\"+mother_ID[mother_index]+\"_right\"\n", + "names['sig_pdf_right_name'] =data_type[data_index]+\"_pdf_\"+mother_ID[mother_index]+\"_right\"\n", + "\n", + "names['frac_lr_name']=data_type[data_index]+'_'+mother_ID[mother_index]+\"_lr_fraction\"\n", + "names['model_name']=data_type[data_index]+'_'+mother_ID[mother_index]+\"_model\"\n", + "names['data_set_name']=data_type[data_index]+'_'+mother_ID[mother_index]+'_ConsD_M'\n", + " \n", + "if mis_id_bkg:\n", + " for key in names:\n", + " names[key]=names[key]+'_misID'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "if mis_id_bkg==True:\n", + " with open(MC_PATH+mother_ID[mother_index]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_trigCat'+str(trigCat)+'.pickle', 'rb') as f:\n", + " MC_sig_dict=pickle.load(f)\n", + " \n", + " data = MC_sig_dict[mother_ID[mother_index]+'_ConsD_M']\n", + " \n", + " deltam2 = (mpi*mpi)-(ml*ml)\n", + " \n", + " Epi=MC_sig_dict['pi_PE']\n", + " El1=MC_sig_dict[l_flv[l_index]+'_minus_PE']\n", + " El2=MC_sig_dict[l_flv[l_index]+'_plus_PE']\n", + " \n", + " \n", + " data_shift = np.sqrt(data**2-deltam2*(2+Epi*((El1+El2)/((El1*El2)))+(((El1**2+El2**2))/((El1*El2)))))\n", + " data_array=np.array([data_shift[i] for i in range(len(data))], dtype=[(mother_ID[mother_index]+'_ConsD_M', np.float32)])\n", + " \n", + " \n", + " rn.array2root(data_array,\n", + " filename=MC_PATH+mother_ID[mother_index]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_trigCat'+str(trigCat)+'_for_misID_FIT.root',\n", + " treename='DecayTree',\n", + " mode='recreate',\n", + " )\n", + " f=r.TFile(MC_PATH+mother_ID[mother_index]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_trigCat'+str(trigCat)+'_for_misID_FIT.root')\n", + " tree=f.Get(\"DecayTree\")\n", + "\n", + "else:\n", + "\n", + " f=r.TFile(MC_PATH+mother_ID[mother_index]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_trigCat'+str(trigCat)+'.root')\n", + " tree=f.Get(\"DecayTree\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "mass = np.array([0],dtype=np.float32)\n", + "branch = tree.GetBranch(mother_ID[mother_index]+\"_ConsD_M\")\n", + "branch.SetAddress(mass)\n", + "\n", + "num_entries=tree.GetEntries()\n", + " \n", + "m = r.RooRealVar(names['m_name'],names['m_name'],mean_d_down,mean_d_up)\n", + "l = r.RooArgSet(m)\n", + "\n", + "\n", + "data_set = r.RooDataSet(names['data_set_name'], names['data_set_name'], l)\n", + "\n", + "for i in range(num_entries):\n", + " tree.GetEvent(i)\n", + " r.RooAbsRealLValue.__assign__(m, mass[0])\n", + " data_set.add(l, 1.0)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "mean_D= r.RooRealVar(names['mean_D_name'],names['mean_D_name'],mean_d_startval,mean_d_down,mean_d_up)\n", + "sigma_D = r.RooRealVar(names['sigma_D_name'],names['sigma_D_name'],20,0.,200)\n", + "\n", + "alpha_D_l = r.RooRealVar(names['alpha_left_name'],names['alpha_left_name'],-0.020,-10.,10.)\n", + "n_D_l = r.RooRealVar(names['n_left_name'],names['n_left_name'],0.020,-50.,50.)\n", + "sig_D_l = r.RooCBShape(names['sig_pdf_left_name'], names['sig_pdf_left_name'], m, mean_D, sigma_D, alpha_D_l, n_D_l)\n", + "\n", + "alpha_D_r = r.RooRealVar(names['alpha_right_name'],names['alpha_right_name'],+0.020,-10.,10.)\n", + "n_D_r = r.RooRealVar(names['n_right_name'],names['n_right_name'],0.020,-50.,50.)\n", + "sig_D_r = r.RooCBShape(names['sig_pdf_right_name'],names['sig_pdf_right_name'], m, mean_D, sigma_D, alpha_D_r, n_D_r)\n", + "\n", + "frac_D = r.RooRealVar(names['frac_lr_name'],names['frac_lr_name'],0.5,0.,1.)\n", + "\n", + "model = r.RooAddPdf(names['model_name'],names['model_name'],r.RooArgList(sig_D_l,sig_D_r),r.RooArgList(frac_D))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "if not os.path.exists(workspace_path+workspace_filename): \n", + " \n", + " w = r.RooWorkspace(workspace_filename)\n", + " \n", + "elif os.path.exists(workspace_path+workspace_filename):\n", + " \n", + " f = r.TFile(workspace_path+workspace_filename)\n", + " w = (f.Get(workspace_filename))\n", + " \n", + "getattr(w,'import')(data_set)\n", + "getattr(w,'import')(mean_D)\n", + "getattr(w,'import')(sigma_D)\n", + "\n", + "getattr(w,'import')(alpha_D_r)\n", + "getattr(w,'import')(n_D_r)\n", + "#getattr(w,'import')(sig_D_r)\n", + "\n", + "getattr(w,'import')(alpha_D_l)\n", + "getattr(w,'import')(n_D_l)\n", + "#getattr(w,'import')(sig_D_l)\n", + "\n", + "\n", + "getattr(w,'import')(frac_D)\n", + "getattr(w,'import')(model)\n", + "\n", + "w.Print()\n", + "\n", + "w.writeToFile(workspace_path+workspace_filename, r.kTRUE)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/4b_fit_MC.ipynb b/4b_fit_MC.ipynb new file mode 100644 index 0000000..e36971e --- /dev/null +++ b/4b_fit_MC.ipynb @@ -0,0 +1,154 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/hep/davide/miniconda3/envs/root_env/lib/ROOT.py:301: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility\n", + " return _orig_ihook( name, *args, **kwds )\n" + ] + } + ], + "source": [ + "import ROOT as r\n", + "import root_numpy as rn\n", + "import pickle\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import array as array\n", + "from xgboost import XGBClassifier\n", + "from tools.data_processing import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "l_flv=['e','mu']\n", + "mother_ID=[\"Dplus\",\"Ds\",\"both\"]\n", + "PATH='/disk/lhcb_data/davide/Rphipi_new/'\n", + "data_type=['MC','data']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# PATHs" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "test=1\n", + "l_index=0\n", + "trigCat=0\n", + "data_index=0\n", + "\n", + "mother_index=0\n", + "mis_id_bkg=False\n", + "\n", + "PATH_BDTs=PATH+'BDT/'+l_flv[l_index]+'/test_'+str(test)+'/'\n", + "FIT_PATH=l_flv[l_index]+'_fits/'\n", + "MC_PATH = PATH+'MC/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[mother_index]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/trigCats/'+str(trigCat)+'/'\n", + "\n", + "workspace_filename='fitAndsPlot_D_phipi_'+l_flv[l_index]+l_flv[l_index]+'_2016_trigCat'+str(trigCat)+'.root'\n", + "workspace_path='/home/hep/davide/Rphipi_new/workspaces/'\n", + "\n", + "names={}\n", + "names['m_name']=data_type[data_index]+\"_\"+mother_ID[mother_index]+\"_m\"\n", + "\n", + "names['mean_D_name']=data_type[data_index]+\"_mean_\"+mother_ID[mother_index]\n", + "names['sigma_D_name']=data_type[data_index]+\"_sigma_\"+mother_ID[mother_index]\n", + "\n", + "names['alpha_left_name']=data_type[data_index]+\"_alpha_\"+mother_ID[mother_index]+\"_left\"\n", + "names['n_left_name' ]=data_type[data_index]+\"_n_\"+mother_ID[mother_index]+\"_left\"\n", + "names['sig_pdf_left_name' ]=data_type[data_index]+\"_pdf_\"+mother_ID[mother_index]+\"_left\"\n", + "\n", + "names['alpha_right_name']=data_type[data_index]+\"_alpha_\"+mother_ID[mother_index]+\"_right\"\n", + "names['n_right_name'] =data_type[data_index]+\"_n_\"+mother_ID[mother_index]+\"_right\"\n", + "names['sig_pdf_right_name'] =data_type[data_index]+\"_pdf_\"+mother_ID[mother_index]+\"_right\"\n", + "\n", + "names['frac_lr_name']=data_type[data_index]+'_'+mother_ID[mother_index]+\"_lr_fraction\"\n", + "names['model_name']=data_type[data_index]+'_'+mother_ID[mother_index]+\"_model\"\n", + "names['data_set_name']=data_type[data_index]+'_'+mother_ID[mother_index]+'_ConsD_M'\n", + " \n", + "if mis_id_bkg:\n", + " for key in names:\n", + " names[key]=names[key]+'_misID'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f = r.TFile(workspace_path+workspace_filename)\n", + "w = f.Get(workspace_filename)\n", + "\n", + "w.Print()\n", + "\n", + "model = w.pdf(names['model_name'])\n", + "data_set = w.data(names['data_set_name'])\n", + "\n", + "\n", + "model.fitTo(data_set,r.RooFit.Save())\n", + "\n", + "model_vars = w.allVars()\n", + "getattr(w,'import')(model_vars)\n", + "\n", + "w.writeToFile(workspace_path+workspace_filename, r.kTRUE)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/4c_plot_MC.ipynb b/4c_plot_MC.ipynb new file mode 100644 index 0000000..fb68a31 --- /dev/null +++ b/4c_plot_MC.ipynb @@ -0,0 +1,151 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/hep/davide/miniconda3/envs/root_env/lib/ROOT.py:301: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility\n", + " return _orig_ihook( name, *args, **kwds )\n" + ] + } + ], + "source": [ + "import ROOT as r\n", + "import root_numpy as rn\n", + "import pickle\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import array as array\n", + "from xgboost import XGBClassifier\n", + "from tools.data_processing import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "l_flv=['e','mu']\n", + "mother_ID=[\"Dplus\",\"Ds\",\"both\"]\n", + "PATH='/disk/lhcb_data/davide/Rphipi_new/'\n", + "data_type=['MC','data']" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "test=1\n", + "l_index=1\n", + "trigCat=0\n", + "data_index=0\n", + "\n", + "mother_index=0\n", + "mis_id_bkg=False\n", + "\n", + "PATH_BDTs=PATH+'BDT/'+l_flv[l_index]+'/test_'+str(test)+'/'\n", + "FIT_PATH=l_flv[l_index]+'_fits/'\n", + "MC_PATH = PATH+'MC/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[mother_index]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/trigCats/'+str(trigCat)+'/'\n", + "\n", + "workspace_filename='fitAndsPlot_D_phipi_'+l_flv[l_index]+l_flv[l_index]+'_2016_trigCat'+str(trigCat)+'.root'\n", + "workspace_path='/home/hep/davide/Rphipi_new/workspaces/'\n", + "\n", + "names={}\n", + "names['m_name']=data_type[data_index]+\"_\"+mother_ID[mother_index]+\"_m\"\n", + "\n", + "names['mean_D_name']=data_type[data_index]+\"_mean_\"+mother_ID[mother_index]\n", + "names['sigma_D_name']=data_type[data_index]+\"_sigma_\"+mother_ID[mother_index]\n", + "\n", + "names['alpha_left_name']=data_type[data_index]+\"_alpha_\"+mother_ID[mother_index]+\"_left\"\n", + "names['n_left_name' ]=data_type[data_index]+\"_n_\"+mother_ID[mother_index]+\"_left\"\n", + "names['sig_pdf_left_name' ]=data_type[data_index]+\"_pdf_\"+mother_ID[mother_index]+\"_left\"\n", + "\n", + "names['alpha_right_name']=data_type[data_index]+\"_alpha_\"+mother_ID[mother_index]+\"_right\"\n", + "names['n_right_name'] =data_type[data_index]+\"_n_\"+mother_ID[mother_index]+\"_right\"\n", + "names['sig_pdf_right_name'] =data_type[data_index]+\"_pdf_\"+mother_ID[mother_index]+\"_right\"\n", + "\n", + "names['frac_lr_name']=data_type[data_index]+'_'+mother_ID[mother_index]+\"_lr_fraction\"\n", + "names['model_name']=data_type[data_index]+'_'+mother_ID[mother_index]+\"_model\"\n", + "names['data_set_name']=data_type[data_index]+'_'+mother_ID[mother_index]+'_ConsD_M'\n", + " \n", + "if mis_id_bkg:\n", + " for key in names:\n", + " names[key]=names[key]+'_misID'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "f = r.TFile(workspace_path+workspace_filename)\n", + "w2 = (f.Get(workspace_filename))\n", + "\n", + "model=w2.pdf(names['model_name'])\n", + "data_set=w2.data(names['data_set_name'])\n", + "alpha_D_l=w2.var(names['alpha_left_name'])\n", + "alpha_D_r=w2.var(names['alpha_right_name'])\n", + "n_D_l=w2.var(names['n_left_name'])\n", + "n_D_r=w2.var(names['n_right_name'])\n", + "frac_D=w2.var(names['frac_lr_name'])\n", + "m = w2.var(names['m_name'])\n", + "\n", + "frame_title=\"Fit to \"+mother_ID[mother_index]+\"_phipi_\"+l_flv[l_index]+l_flv[l_index]+\" MC trigCat\"+str(trigCat)\n", + "\n", + "if mis_id_bkg: frame_title=frame_title+\" misID\"\n", + "xframe = m.frame(r.RooFit.Title(frame_title))" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "data_set.plotOn(xframe)\n", + "argset=r.RooArgSet(alpha_D_l, alpha_D_r, n_D_l, n_D_r)\n", + "model.plotOn(xframe)\n", + "model.paramOn(xframe, r.RooFit.Layout(0.6,0.99,0.92), r.RooFit.Parameters(argset),r.RooFit.Format(\"NEU\", r.RooFit.AutoPrecision(1)))\n", + "xframe.getAttText().SetTextSize(0.03)\n", + "xframe.Draw()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/5_Apply_BDT.ipynb b/5_Apply_BDT.ipynb new file mode 100644 index 0000000..c10197d --- /dev/null +++ b/5_Apply_BDT.ipynb @@ -0,0 +1,196 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/hep/davide/miniconda3/envs/root_env/lib/ROOT.py:301: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility\n", + " return _orig_ihook( name, *args, **kwds )\n" + ] + } + ], + "source": [ + "import ROOT as r\n", + "import root_numpy as rn\n", + "import pickle\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import array as array\n", + "from xgboost import XGBClassifier\n", + "from tools.data_processing import *\n", + "from tools.preselector import *" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "l_flv=['e','mu']\n", + "mother_ID=[\"Dplus\",\"Ds\",\"both\"]\n", + "PATH='/disk/lhcb_data/davide/Rphipi_new/'\n", + "data_type=['MC','data']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# PATHs" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "test=1\n", + "l_index=1\n", + "trigCat=0\n", + "#mother_index=1\n", + "data_index=0\n", + "\n", + "BDTs_PATH=PATH+'BDT/'+l_flv[l_index]+'/test_'+str(test)+'/'\n", + "FIT_PATH=l_flv[l_index]+'_fits/'\n", + "\n", + "DATA_PATH = PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/trigged/trigCats/'+str(trigCat)+'/'\n", + "MC_Dplus_PATH = PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/trigCats/'+str(trigCat)+'/'\n", + "MC_Ds_PATH = PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/trigged/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/trigCats/'+str(trigCat)+'/'\n", + "\n", + "SAVE_BDT_SELECTED_PATH=PATH+data_type[1]+'/'+l_flv[l_index]+'_tuples/BDT_selected/trigCats/'+str(trigCat)+'/'\n", + "SAVE_BDT_SELECTED_MC_Dplus_PATH=PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/BDT_selected/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/trigCats/'+str(trigCat)+'/'\n", + "SAVE_BDT_SELECTED_MC_Ds_PATH=PATH+data_type[0]+'/'+l_flv[l_index]+'_tuples/BDT_selected/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/trigCats/'+str(trigCat)+'/'\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Apply BDT" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "with open(DATA_PATH+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_trigCat'+str(trigCat)+'.pickle') as f:\n", + "\n", + " data_to_select = pickle.load(f)\n", + "\n", + "with open(MC_Dplus_PATH+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_trigCat'+str(trigCat)+'.pickle') as f:\n", + "\n", + " MC_Dplus_to_select = pickle.load(f)\n", + " \n", + "with open(MC_Ds_PATH+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_trigCat'+str(trigCat)+'.pickle') as f:\n", + "\n", + " MC_Ds_to_select = pickle.load(f)\n", + "\n", + "if l_flv[l_index]=='e':\n", + " BDT_cut=0.01\n", + " \n", + "if l_flv[l_index]=='mu':\n", + " BDT_cut=0.2\n", + " \n", + "data_BDT_selected = get_BDT_weights(locals(), data_to_select, BDTs_PATH)\n", + "MC_Dplus_BDT_selected = get_BDT_weights(locals(), MC_Dplus_to_select, BDTs_PATH)\n", + "MC_Ds_BDT_selected = get_BDT_weights(locals(), MC_Ds_to_select, BDTs_PATH)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAFGpJREFUeJzt3X+MXeWd3/H3Z7HDVkpahTBo1YzBK0VdNTgkIUPZFaWJu6xqsNQfhARFeFcCby0jr7ZO/4k3rZZEVVUqhSTrbaSRJUJ2cYSshVTVCiNgq0YIiQgNxgv+kU26Kss4Cng220ZpVcCNv/3jPpYuw52Zc4c7947H75c08jnPeZ57v/fxzP3M+XHPpKqQJOkXJl2AJGl9MBAkSYCBIElqDARJEmAgSJIaA0GSBBgIkqTGQJAkAQaCJKnZNOkChnHllVfW1q1bJ12GJF1UXnjhhb+uqqmV+l1UgbB161bm5uYmXYYkXVSS/FWXfp0OGSXZkeREktNJDgzYniQHk5xK8mKS61v7LyaZS3I8yQ+TfD1J2rYrkjyd5OUkTyV5/zAvUJI0WisGQpLLgVngVuA64I4Lb/h9bgeuAa4FdgMPtfY3gU9W1ceADwO/Bmxv274MPFFVHwGeaOuSpAnpsodwI3Cyquar6hxwBNi5qM9O4HD1HAM2JdnS1v9P67MZuAw42zfm4bZ8eMBjSpLGqEsgTAPzfetnWlunPkkuS3KcXhB8t6pOtD5TVbUA0P69avjyJUmjsuaXnVbVz9sho2ng5iTbVxrTL8medh5ibmFhYW2KlCR1CoQzwJa+9enWNlSfqvpfwOPAr7amhSRTAO3fswxQVYeqaqaqZqamVrxqSpK0Sl0C4XlgW5LpJJuBO+mdBO53FLgLoJ1wPl9V80muTPK+1v63gN8ATvSN2dWWdw14TEnSGK34OYSqeiPJvcCT9ALkcFXNJd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3iroGWqOfg4G1VdXpqhr0Adqxfr+txiUfCCu4GXi9qn7Y17a1HRp5Lsmvt7albt2xFr4APJBknt5dZC98Tn6Y24esRW1L1QWTn7PTwD9ry58Brl6hhvVQG0xo3pJsBW6gt9f3tlvMABduMTP2uetYF0xg3hbVtpT18P22LANheZ/j7XsHPwamq+qj9C6zfbj/mOqYPAj8q6raQm9X+cExP/9SlqprPczZbwH727H7K+ndon29WKq2icxbkvcCjwL7q+qna/18XQ1R19jnbb3O2Wqs+3sZTUqSTcDt9I77AVBVb9J+YKt3C+8T9I4Xdrm9x6j8GvAbbflPgIfa8lI1jKu2gXWthzmrqhO0myq23+Rua5smPWdL1jaJeUvvbgKPAY9U1Xda81K3mBnb3A1T17jnbYnaljLx77eVuIewtFuA77djfQAk+UCSX2jLW4FtwH+vqleB8+ndtgN6t/FYq1tx/BXwybb8j+mdmILeh//uTLI5yXSr7fkx1jawrvUwZ0mubP+G3p3HLuy9THrOlqxt3PPWnv9B4HRVPdC3aalbzIxl7oata5zztkxtS5n499uKJnEmez190Tsk9GPgHL1U3t3avwXsXdT3Dnongl4GTgCf6ds2AxwHTgH/ifahv1HXBtwE/Hl7nuPAr/b1/zf0jkmfpF3xsxa1DVPXOpmz/cD32/Pf3/8845qzYWubwLz9Q6DonRg93r5uAz4A/Fmr48+AK8Y5d8PWNc55W6a2f9H+f9+kd1ueJyfx/baaLz+pLEkCPGQkSWoMBEkSYCBIkhoDQZIEGAiSpMZAkCQBBoIkqTEQJEkA/H9968L+2dXqbQAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.hist(data_BDT_selected['Ds_ConsD_M'], bins=70, weights=data_BDT_selected['BDT_selection'], density=True);\n", + "plt.hist(data_BDT_selected['Ds_ConsD_M'], bins=70, alpha=0.5, density=True);" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Adding branch BDT_selection\n", + "Saving pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/BDT_selected/trigCats/0/Ds_phipi_mumu_BDT_selection.pickle\n", + "Adding branch BDT_selection\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/BDT_selected/trigCats/0/Ds_phipi_mumu_BDT_selection.root\n", + "Adding branch BDT_selection\n", + "Saving pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/mu_tuples/BDT_selected/Dplus_phipi_mumu/trigCats/0/Dplus_phipi_mumu_BDT_selection.pickle\n", + "Adding branch BDT_selection\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/MC/mu_tuples/BDT_selected/Dplus_phipi_mumu/trigCats/0/Dplus_phipi_mumu_BDT_selection.root\n", + "Adding branch BDT_selection\n", + "Saving pickle file at/disk/lhcb_data/davide/Rphipi_new/MC/mu_tuples/BDT_selected/Ds_phipi_mumu/trigCats/0/Ds_phipi_mumu_BDT_selection.pickle\n", + "Adding branch BDT_selection\n", + "Saving root file at/disk/lhcb_data/davide/Rphipi_new/MC/mu_tuples/BDT_selected/Ds_phipi_mumu/trigCats/0/Ds_phipi_mumu_BDT_selection.root\n" + ] + } + ], + "source": [ + "add_branch_and_save_tuples(locals(), data_BDT_selected, l_index, 'BDT_selection', SAVE_BDT_SELECTED_PATH, 'pickle' )\n", + "add_branch_and_save_tuples(locals(), data_BDT_selected, l_index, 'BDT_selection', SAVE_BDT_SELECTED_PATH, 'root' )\n", + "\n", + "add_branch_and_save_tuples(locals(), MC_Dplus_BDT_selected, l_index, 'BDT_selection', SAVE_BDT_SELECTED_MC_Dplus_PATH, 'pickle' )\n", + "add_branch_and_save_tuples(locals(), MC_Dplus_BDT_selected, l_index, 'BDT_selection', SAVE_BDT_SELECTED_MC_Dplus_PATH, 'root' )\n", + "\n", + "add_branch_and_save_tuples(locals(), MC_Ds_BDT_selected, l_index, 'BDT_selection', SAVE_BDT_SELECTED_MC_Ds_PATH, 'pickle' )\n", + "add_branch_and_save_tuples(locals(), MC_Ds_BDT_selected, l_index, 'BDT_selection', SAVE_BDT_SELECTED_MC_Ds_PATH, 'root' )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/fitAndSplotPhipiee.ipynb b/fitAndSplotPhipiee.ipynb new file mode 100644 index 0000000..1a678bd --- /dev/null +++ b/fitAndSplotPhipiee.ipynb @@ -0,0 +1,181 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/hep/davide/miniconda3/envs/root_env/lib/ROOT.py:301: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility\n", + " return _orig_ihook( name, *args, **kwds )\n" + ] + } + ], + "source": [ + "from tools.fitAndSplotPhipill import *" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "fit= fitAndSplotphipill(trigCat=1, l_index=0)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "fit.set_paths()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Preparing MC Dplus_phipi_e workspace\n", + "Done!\n", + "Preparing MC Ds_phipi_e workspace\n", + "Done!\n", + "Fitting MC Dplus_phipi_e\n", + "Done!\n", + "Fitting MC Ds_phipi_e\n", + "Done!\n", + "Preparing data workspace\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/e_tuples/BDT_selected/trigCats/1/Ds_phipi_ee_BDT_selection_temp.pickle\n", + "Done!\n" + ] + } + ], + "source": [ + "fit.prepare_MC_workspaces(mother_index=0, mis_id_bkg=False)\n", + "fit.prepare_MC_workspaces(mother_index=1, mis_id_bkg=False)\n", + "\n", + "fit.fit_MC(mother_index=0, mis_id_bkg=False)\n", + "fit.fit_MC(mother_index=1, mis_id_bkg=False)\n", + "\n", + "fit.prepare_data_workspace(BDT_CUT=0.1)\n", + "#" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Plotting MC Dplus_phipi_e\n", + "Done!\n", + "Plotting MC Ds_phipi_e\n", + "Done!\n" + ] + } + ], + "source": [ + "fit.plot_MC(mother_index=0, mis_id_bkg=False)\n", + "fit.plot_MC(mother_index=1, mis_id_bkg=False)\n", + "#" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Fitting data D(s)_phipi_ee\n", + "(, , )\n", + "Done!\n" + ] + } + ], + "source": [ + "fit.fit_data()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "TCanvas::Constructor:0: RuntimeWarning: Deleting canvas with same name: Fit\n" + ] + } + ], + "source": [ + "fit.plot_data(wantThesisStyle=True)\n", + "fit.plot_data(wantThesisStyle=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Done!\n", + "1791\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/e_tuples/BDT_selected/trigCats/1/Ds_phipi_ee_2016_sWeighted.pickle\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/data/e_tuples/BDT_selected/trigCats/1/Ds_phipi_ee_2016_sWeighted.root\n" + ] + } + ], + "source": [ + "fit.splot(plot=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/fitAndSplotPhipimumu.ipynb b/fitAndSplotPhipimumu.ipynb new file mode 100644 index 0000000..ebb575a --- /dev/null +++ b/fitAndSplotPhipimumu.ipynb @@ -0,0 +1,181 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/hep/davide/miniconda3/envs/root_env/lib/ROOT.py:301: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility\n", + " return _orig_ihook( name, *args, **kwds )\n" + ] + } + ], + "source": [ + "from tools.fitAndSplotPhipill import *" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "fit= fitAndSplotphipill(trigCat=1, l_index=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "fit.set_paths()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Preparing MC Dplus_phipi_mu workspace\n", + "Done!\n", + "Preparing MC Ds_phipi_mu workspace\n", + "Done!\n", + "Fitting MC Dplus_phipi_mu\n", + "Done!\n", + "Fitting MC Ds_phipi_mu\n", + "Done!\n", + "Preparing data workspace\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/BDT_selected/trigCats/1/Ds_phipi_mumu_BDT_selection_temp.pickle\n", + "Done!\n" + ] + } + ], + "source": [ + "fit.prepare_MC_workspaces(mother_index=0, mis_id_bkg=False)\n", + "fit.prepare_MC_workspaces(mother_index=1, mis_id_bkg=False)\n", + "\n", + "fit.fit_MC(mother_index=0, mis_id_bkg=False)\n", + "fit.fit_MC(mother_index=1, mis_id_bkg=False)\n", + "\n", + "fit.prepare_data_workspace(BDT_CUT=0.4)\n", + "#" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Plotting MC Dplus_phipi_mu\n", + "Done!\n", + "Plotting MC Ds_phipi_mu\n", + "Done!\n" + ] + } + ], + "source": [ + "fit.plot_MC(mother_index=0, mis_id_bkg=False)\n", + "fit.plot_MC(mother_index=1, mis_id_bkg=False)\n", + "#" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Fitting data D(s)_phipi_mumu\n", + "(, , )\n", + "Done!\n" + ] + } + ], + "source": [ + "fit.fit_data()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "TCanvas::Constructor:0: RuntimeWarning: Deleting canvas with same name: Fit\n" + ] + } + ], + "source": [ + "fit.plot_data(wantThesisStyle=True)\n", + "fit.plot_data(wantThesisStyle=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Done!\n", + "1854\n", + "Overwriting pickle file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/BDT_selected/trigCats/1/Ds_phipi_mumu_2016_sWeighted.pickle\n", + "Overwriting root file at/disk/lhcb_data/davide/Rphipi_new/data/mu_tuples/BDT_selected/trigCats/1/Ds_phipi_mumu_2016_sWeighted.root\n" + ] + } + ], + "source": [ + "fit.splot(plot=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/tools/__init__.py b/tools/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tools/__init__.py diff --git a/tools/data_processing.py b/tools/data_processing.py new file mode 100644 index 0000000..8ab2057 --- /dev/null +++ b/tools/data_processing.py @@ -0,0 +1,1655 @@ +import os +import pickle +import numpy as np +import sys +import root_numpy as rn + +mother_ID=['Dplus','Ds','both'] +l_flv = ['e','mu'] +data_type = ['MC','data'] +mag_status =['Up','Down'] +tree_name = 'Ds_OfflineTree/DecayTree' + +def namestr(obj, namespace): + return [name for name in namespace if namespace[name] is obj] + +def sel_eff(tp,threshold): + + sig_eps = np.float(np.where(tp>threshold)[0].shape[0])/np.float(tp.shape[0]) + return sig_eps + +def load_datasets(l_index, PATH): + + if sys.version_info[0]>2: + data_index=0 + with open(PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/for_BDT_training/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_for_BDT.pickle', 'rb') as f: + MC_Ds_sig_dict=pickle.load(f, encoding='latin1') + + data_index=0 + with open(PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/for_BDT_training/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_for_BDT.pickle', 'rb') as f: + MC_Dplus_sig_dict=pickle.load(f, encoding='latin1') + + data_index=1 + with open(PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/for_BDT_training/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_for_BDT.pickle', 'rb') as f: + data_bkg_dict=pickle.load(f, encoding='latin1') + else: + + data_index=0 + with open(PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/for_BDT_training/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_for_BDT.pickle', 'rb') as f: + MC_Ds_sig_dict=pickle.load(f)#, encoding='latin1') + + data_index=0 + with open(PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/for_BDT_training/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'/'+mother_ID[0]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_for_BDT.pickle', 'rb') as f: + MC_Dplus_sig_dict=pickle.load(f)#, encoding='latin1') + + data_index=1 + with open(PATH+data_type[data_index]+'/'+l_flv[l_index]+'_tuples/for_BDT_training/'+mother_ID[1]+'_phipi_'+l_flv[l_index]+l_flv[l_index]+'_for_BDT.pickle', 'rb') as f: + data_bkg_dict=pickle.load(f)#, encoding='latin1') + + return MC_Dplus_sig_dict, MC_Ds_sig_dict, data_bkg_dict + +def extract_array_for_BDT(event_dict, branches_needed, examples): + + features = len(branches_needed) + extracted = np.array( + [np.zeros(shape=features) for i in range(examples)] + ) + + for event in range(examples): + for i, key in enumerate(branches_needed): + extracted[event][i]=event_dict[key][event] + + return extracted + +def add_labels(ndarray, signal=True): + if signal==True: + labeled_ndarray=np.concatenate((ndarray, np.ones(shape=(ndarray.shape[0],1))), axis =1) + elif signal==False: + labeled_ndarray=np.concatenate((ndarray, np.zeros(shape=(ndarray.shape[0],1))), axis =1) + + return labeled_ndarray + +def to_one_hot(labels): + + temp = np.zeros(shape=(labels.shape[0],2)) + + for i in range(labels.shape[0]): + if labels[i]==0: + temp[i][0]=1 + else: + temp[i][1]=1 + + return temp + +def k_subsets(i, k, X, Y_labels): + + train_size, dim=X.shape + #divide in k subsets + k_batch_size = train_size//k + + X_dict={} + Y_dict={} + + for b in range(k): + X_dict[b]=X[k_batch_size*b:k_batch_size*(b+1)] + Y_dict[b]=Y_labels[k_batch_size*b:k_batch_size*(b+1)] + + k_range=np.arange(k) + + X_test = X_dict[i][:,0:dim] + Y_test = Y_dict[i][:,0:dim] + + + k_subset=np.delete(k_range, i) + + + X_train = np.concatenate([X_dict[j][:,0:dim] for j in k_subset],axis=0) + Y_train = np.concatenate([Y_dict[j][:,0:dim] for j in k_subset],axis=0) + + return X_train, Y_train, X_test, Y_test, X_dict, Y_dict + +def return_branches(data_index=None, mother_index=None, l_index=None): + #data_index =0 -> MC + if data_index==0: + if l_index==1: + branches_needed = [ + #________________________________________ + #D MC true info + + + mother_ID[mother_index]+'_MC_MOTHER_ID', + mother_ID[mother_index]+'_BKGCAT', + mother_ID[mother_index]+'_TRUEID', + #________________________________________ + #D Geometric variables, pT and FD + + mother_ID[mother_index]+"_ENDVERTEX_CHI2", + mother_ID[mother_index]+"_ENDVERTEX_NDOF", + mother_ID[mother_index]+"_IPCHI2_OWNPV", + + mother_ID[mother_index]+"_OWNPV_CHI2", + mother_ID[mother_index]+"_OWNPV_NDOF", + mother_ID[mother_index]+"_IP_OWNPV", + mother_ID[mother_index]+"_DIRA_OWNPV", + + mother_ID[mother_index]+"_PX", + mother_ID[mother_index]+"_PY", + mother_ID[mother_index]+"_PZ", + mother_ID[mother_index]+"_PT", + mother_ID[mother_index]+"_P", + mother_ID[mother_index]+"_PE", + mother_ID[mother_index]+"_FD_OWNPV", + mother_ID[mother_index]+"_FDCHI2_OWNPV", + + #D Reconstructed mass + mother_ID[mother_index]+"_ConsD_M", + mother_ID[mother_index]+"_M", + + #D Trigger variables + mother_ID[mother_index]+"_L0Global_TIS", + mother_ID[mother_index]+"_L0Global_TOS", + + mother_ID[mother_index]+"_L0MuonDecision_TIS", + mother_ID[mother_index]+"_L0MuonDecision_TOS", + + mother_ID[mother_index]+"_L0ElectronDecision_TIS", + mother_ID[mother_index]+"_L0ElectronDecision_TOS", + + mother_ID[mother_index]+"_L0HadronDecision_TIS", + mother_ID[mother_index]+"_L0HadronDecision_TOS", + + mother_ID[mother_index]+"_Hlt1TrackMVADecision_TOS", + mother_ID[mother_index]+"_Hlt2RareCharmD2Pi"+l_flv[l_index].capitalize()+l_flv[l_index].capitalize()+"OSDecision_TOS", + mother_ID[mother_index]+"_Hlt2Phys_TOS", + + #________________________________________ + #PHI MC TRUE INFO + + 'phi_MC_MOTHER_ID', + 'phi_BKGCAT', + 'phi_TRUEID', + #________________________________________ + #phi geometric variables, pT and FD + + "phi_ENDVERTEX_CHI2", + "phi_ENDVERTEX_NDOF", + "phi_IPCHI2_OWNPV", + + #"phi_OWNPV_CHI2", + #"phi_OWNPV_NDOF", + #"phi_IP_OWNPV", + #"phi_DIRA_OWNPV", + + "phi_PT", + "phi_P", + + #phi Reconstructed mass + + "phi_M", + + #________________________________________ + #PION + #Pion mother ID and bkg cat + + 'pi_MC_MOTHER_ID', + 'pi_TRUEID', + + #_____________________________________ + #pi Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + "pi_PX", + "pi_PY", + "pi_PZ", + + 'pi_PT', + 'pi_P', + 'pi_PE', + + #pi PID variables + + "pi_MC15TuneV1_ProbNNpi", + + #________________________________________ + #LEPTONS + l_flv[l_index]+'_plus_MC_MOTHER_ID', + l_flv[l_index]+'_plus_TRUEID', + + l_flv[l_index]+'_minus_MC_MOTHER_ID', + l_flv[l_index]+'_minus_TRUEID', + #________________________________________ + #leptons Geometric variables and pT + + l_flv[l_index]+"_plus_OWNPV_CHI2", + #l_flv[l_index]+"_plus_OWNPV_NDOF", + l_flv[l_index]+"_minus_OWNPV_CHI2", + #l_flv[l_index]+"_minus_OWNPV_NDOF", + # + #l_flv[l_index]+"_plus_IP_OWNPV", + #l_flv[l_index]+"_minus_IP_OWNPV", + + l_flv[l_index]+"_plus_PX", + l_flv[l_index]+"_plus_PY", + l_flv[l_index]+"_plus_PZ", + l_flv[l_index]+"_plus_PE", + + l_flv[l_index]+"_minus_PX", + l_flv[l_index]+"_minus_PY", + l_flv[l_index]+"_minus_PZ", + l_flv[l_index]+"_minus_PE", + + l_flv[l_index]+"_plus_PT", + l_flv[l_index]+"_minus_PT", + l_flv[l_index]+"_plus_P", + l_flv[l_index]+"_minus_P", + 'cos_thetal', + + + #leptons PID variables + + l_flv[l_index]+"_plus_MC15TuneV1_ProbNN"+l_flv[l_index], + l_flv[l_index]+"_minus_MC15TuneV1_ProbNN"+l_flv[l_index], + + l_flv[l_index]+"_plus_MC15TuneV1_ProbNNpi", + l_flv[l_index]+"_minus_MC15TuneV1_ProbNNpi", + ] + if l_index==0: + branches_needed = [ + #________________________________________ + #D MC true info + + + mother_ID[mother_index]+'_MC_MOTHER_ID', + mother_ID[mother_index]+'_BKGCAT', + mother_ID[mother_index]+'_TRUEID', + #________________________________________ + #D Geometric variables, pT and FD + + mother_ID[mother_index]+"_ENDVERTEX_CHI2", + mother_ID[mother_index]+"_ENDVERTEX_NDOF", + mother_ID[mother_index]+"_IPCHI2_OWNPV", + + mother_ID[mother_index]+"_OWNPV_CHI2", + mother_ID[mother_index]+"_OWNPV_NDOF", + mother_ID[mother_index]+"_IP_OWNPV", + mother_ID[mother_index]+"_DIRA_OWNPV", + + mother_ID[mother_index]+"_PX", + mother_ID[mother_index]+"_PY", + mother_ID[mother_index]+"_PZ", + mother_ID[mother_index]+"_PT", + mother_ID[mother_index]+"_P", + mother_ID[mother_index]+"_PE", + mother_ID[mother_index]+"_FD_OWNPV", + mother_ID[mother_index]+"_FDCHI2_OWNPV", + + #D Reconstructed mass + mother_ID[mother_index]+"_ConsD_M", + mother_ID[mother_index]+"_M", + + #D Trigger variables + mother_ID[mother_index]+"_L0Global_TIS", + mother_ID[mother_index]+"_L0Global_TOS", + + mother_ID[mother_index]+"_L0MuonDecision_TIS", + mother_ID[mother_index]+"_L0MuonDecision_TOS", + + mother_ID[mother_index]+"_L0ElectronDecision_TIS", + mother_ID[mother_index]+"_L0ElectronDecision_TOS", + + mother_ID[mother_index]+"_L0HadronDecision_TIS", + mother_ID[mother_index]+"_L0HadronDecision_TOS", + + mother_ID[mother_index]+"_Hlt1TrackMVADecision_TOS", + mother_ID[mother_index]+"_Hlt2RareCharmD2Pi"+l_flv[l_index].capitalize()+l_flv[l_index].capitalize()+"OSDecision_TOS", + mother_ID[mother_index]+"_Hlt2Phys_TOS", + + #________________________________________ + #PHI MC TRUE INFO + + 'phi_MC_MOTHER_ID', + 'phi_BKGCAT', + 'phi_TRUEID', + #________________________________________ + #phi geometric variables, pT and FD + + "phi_ENDVERTEX_CHI2", + "phi_ENDVERTEX_NDOF", + "phi_IPCHI2_OWNPV", + + #"phi_OWNPV_CHI2", + #"phi_OWNPV_NDOF", + #"phi_IP_OWNPV", + #"phi_DIRA_OWNPV", + + "phi_PT", + "phi_P", + + #phi Reconstructed mass + + "phi_M", + + #________________________________________ + #PION + #Pion mother ID and bkg cat + + 'pi_MC_MOTHER_ID', + 'pi_TRUEID', + + #_____________________________________ + #pi Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + + "pi_PX", + "pi_PY", + "pi_PZ", + + 'pi_PT', + 'pi_P', + 'pi_PE', + + #pi PID variables + + "pi_MC15TuneV1_ProbNNpi", + + #________________________________________ + #LEPTONS + l_flv[l_index]+'_plus_MC_MOTHER_ID', + l_flv[l_index]+'_plus_TRUEID', + + l_flv[l_index]+'_minus_MC_MOTHER_ID', + l_flv[l_index]+'_minus_TRUEID', + #________________________________________ + #leptons Geometric variables and pT + + l_flv[l_index]+"_plus_OWNPV_CHI2", + #l_flv[l_index]+"_plus_OWNPV_NDOF", + l_flv[l_index]+"_minus_OWNPV_CHI2", + #l_flv[l_index]+"_minus_OWNPV_NDOF", + # + #l_flv[l_index]+"_plus_IP_OWNPV", + #l_flv[l_index]+"_minus_IP_OWNPV", + + l_flv[l_index]+"_plus_PX", + l_flv[l_index]+"_plus_PY", + l_flv[l_index]+"_plus_PZ", + l_flv[l_index]+"_plus_PE", + + l_flv[l_index]+"_minus_PX", + l_flv[l_index]+"_minus_PY", + l_flv[l_index]+"_minus_PZ", + l_flv[l_index]+"_minus_PE", + + l_flv[l_index]+"_plus_PT", + l_flv[l_index]+"_plus_P", + + l_flv[l_index]+"_minus_PT", + l_flv[l_index]+"_minus_P", + 'cos_thetal', + + #leptons PID variables + + l_flv[l_index]+"_plus_MC15TuneV1_ProbNN"+l_flv[l_index], + l_flv[l_index]+"_minus_MC15TuneV1_ProbNN"+l_flv[l_index], + + l_flv[l_index]+"_plus_MC15TuneV1_ProbNNpi", + l_flv[l_index]+"_minus_MC15TuneV1_ProbNNpi", + + ] + #data_index =1 -> data + if data_index==1: + branches_needed = [ + #________________________________ + #D Geometric variables, pT and FD + + mother_ID[mother_index]+"_ENDVERTEX_CHI2", + mother_ID[mother_index]+"_ENDVERTEX_NDOF", + mother_ID[mother_index]+"_IPCHI2_OWNPV", + + mother_ID[mother_index]+"_OWNPV_CHI2", + mother_ID[mother_index]+"_OWNPV_NDOF", + mother_ID[mother_index]+"_IP_OWNPV", + mother_ID[mother_index]+"_DIRA_OWNPV", + + mother_ID[mother_index]+"_PX", + mother_ID[mother_index]+"_PY", + mother_ID[mother_index]+"_PZ", + mother_ID[mother_index]+"_PT", + mother_ID[mother_index]+"_P", + mother_ID[mother_index]+"_PE", + mother_ID[mother_index]+"_FD_OWNPV", + mother_ID[mother_index]+"_FDCHI2_OWNPV", + + #D Reconstructed mass + mother_ID[mother_index]+"_ConsD_M", + mother_ID[mother_index]+"_M", + + #D Trigger variables + mother_ID[mother_index]+"_L0Global_TIS", + mother_ID[mother_index]+"_L0Global_TOS", + + mother_ID[mother_index]+"_L0MuonDecision_TIS", + mother_ID[mother_index]+"_L0MuonDecision_TOS", + + mother_ID[mother_index]+"_L0ElectronDecision_TIS", + mother_ID[mother_index]+"_L0ElectronDecision_TOS", + + mother_ID[mother_index]+"_L0HadronDecision_TIS", + mother_ID[mother_index]+"_L0HadronDecision_TOS", + + + mother_ID[mother_index]+"_Hlt1TrackMVADecision_TOS", + mother_ID[mother_index]+"_Hlt2RareCharmD2Pi"+l_flv[l_index].capitalize()+l_flv[l_index].capitalize()+"OSDecision_TOS", + mother_ID[mother_index]+"_Hlt2Phys_TOS", + + + #________________________________________ + #phi geometric variables, pT and FD + + "phi_ENDVERTEX_CHI2", + "phi_ENDVERTEX_NDOF", + "phi_IPCHI2_OWNPV", + + #"phi_OWNPV_CHI2", + #"phi_OWNPV_NDOF", + #"phi_IP_OWNPV", + #"phi_DIRA_OWNPV", + + "phi_PT", + "phi_P", + + #phi Reconstructed mass + + "phi_M", + + #________________________________________ + #PION + + #_____________________________________ + #pi Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + + "pi_PX", + "pi_PY", + "pi_PZ", + + 'pi_PT', + 'pi_P', + 'pi_PE', + + #pi PID variables + + "pi_MC15TuneV1_ProbNNpi", + + #________________________________________ + #LEPTONS + #________________________________________ + #leptons Geometric variables and pT + + l_flv[l_index]+"_plus_OWNPV_CHI2", + #l_flv[l_index]+"_plus_OWNPV_NDOF", + l_flv[l_index]+"_minus_OWNPV_CHI2", + #l_flv[l_index]+"_minus_OWNPV_NDOF", + # + #l_flv[l_index]+"_plus_IP_OWNPV", + #l_flv[l_index]+"_minus_IP_OWNPV", + + l_flv[l_index]+"_plus_PX", + l_flv[l_index]+"_plus_PY", + l_flv[l_index]+"_plus_PZ", + l_flv[l_index]+"_plus_PE", + + + + l_flv[l_index]+"_minus_PX", + l_flv[l_index]+"_minus_PY", + l_flv[l_index]+"_minus_PZ", + l_flv[l_index]+"_minus_PE", + + l_flv[l_index]+"_plus_PT", + l_flv[l_index]+"_plus_P", + l_flv[l_index]+"_minus_PT", + l_flv[l_index]+"_minus_P", + 'cos_thetal', + + #leptons PID variables + + l_flv[l_index]+"_plus_MC15TuneV1_ProbNN"+l_flv[l_index], + l_flv[l_index]+"_minus_MC15TuneV1_ProbNN"+l_flv[l_index], + + l_flv[l_index]+"_plus_MC15TuneV1_ProbNNpi", + l_flv[l_index]+"_minus_MC15TuneV1_ProbNNpi", + + ] + return branches_needed + +def return_branches_BDT(mother_index=None, l_index=None): + if l_index==1: + branches_needed = [ + #________________________________ + #D Geometric variables, pT and FD + # mother_ID[mother_index]+"_OWNPV_CHI2", + mother_ID[mother_index]+"_ENDVERTEX_CHI2", + mother_ID[mother_index]+"_PT", + mother_ID[mother_index]+"_FD_OWNPV", + mother_ID[mother_index]+"_IPCHI2_OWNPV", + + mother_ID[mother_index]+"_DIRA_OWNPV", + #mother_ID[mother_index]+"_FDCHI2_OWNPV", + + #________________________________________ + #phi geometric variables, pT and FD + + #"phi_ENDVERTEX_CHI2", + "phi_IPCHI2_OWNPV", + + #"phi_OWNPV_CHI2", + #"phi_OWNPV_NDOF", + #"phi_IP_OWNPV", + #"phi_DIRA_OWNPV", + + #"phi_PT", + + #________________________________________ + #PION + + #_____________________________________ + #pi Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + + 'pi_PT', + 'pi_P', + + + #________________________________________ + #LEPTONS + #________________________________________ + #leptons Geometric variables and pT + + #l_flv[l_index]+"_plus_OWNPV_CHI2", + #l_flv[l_index]+"_plus_OWNPV_NDOF", + #l_flv[l_index]+"_minus_OWNPV_CHI2", + #l_flv[l_index]+"_minus_OWNPV_NDOF", + # + #l_flv[l_index]+"_plus_IP_OWNPV", + #l_flv[l_index]+"_minus_IP_OWNPV", + + l_flv[l_index]+"_plus_PT", + l_flv[l_index]+"_minus_PT", + + l_flv[l_index]+"_plus_P", + l_flv[l_index]+"_minus_P", + "cos_thetal", + + #D Reconstructed mass + # mother_ID[mother_index]+"_ConsD_M", + ] + if l_index==0: + branches_needed = [ + #________________________________ + #D Geometric variables, pT and FD + # mother_ID[mother_index]+"_OWNPV_CHI2", + mother_ID[mother_index]+"_ENDVERTEX_CHI2", + mother_ID[mother_index]+"_PT", + mother_ID[mother_index]+"_FD_OWNPV", + mother_ID[mother_index]+"_IPCHI2_OWNPV", + + mother_ID[mother_index]+"_DIRA_OWNPV", + #mother_ID[mother_index]+"_FDCHI2_OWNPV", + + #________________________________________ + #phi geometric variables, pT and FD + + #"phi_ENDVERTEX_CHI2", + "phi_IPCHI2_OWNPV", + + #"phi_OWNPV_CHI2", + #"phi_OWNPV_NDOF", + #"phi_IP_OWNPV", + #"phi_DIRA_OWNPV", + + #"phi_PT", + + #________________________________________ + #PION + + #_____________________________________ + #pi Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + + 'pi_PT', + 'pi_P', + + + #________________________________________ + #LEPTONS + #________________________________________ + #leptons Geometric variables and pT + + #l_flv[l_index]+"_plus_OWNPV_CHI2", + #l_flv[l_index]+"_plus_OWNPV_NDOF", + #l_flv[l_index]+"_minus_OWNPV_CHI2", + #l_flv[l_index]+"_minus_OWNPV_NDOF", + # + #l_flv[l_index]+"_plus_IP_OWNPV", + #l_flv[l_index]+"_minus_IP_OWNPV", + + l_flv[l_index]+"_plus_PT", + l_flv[l_index]+"_minus_PT", + + l_flv[l_index]+"_plus_P", + l_flv[l_index]+"_minus_P", + "cos_thetal", + #D Reconstructed mass + #mother_ID[mother_index]+"_ConsD_M", + ] + return branches_needed + +def return_branches_TISTOS(data_index=None, l_index=None): + if l_flv[l_index]=='e': + #data_index =0 -> MC + if data_index==0: + branches_needed = [ + #________________________________________ + #D MC true info + + + 'B_MC_MOTHER_ID', + 'B_BKGCAT', + 'B_TRUEID', + #________________________________________ + #B Geometric variables, pT and FD + + "B_ENDVERTEX_CHI2", + "B_ENDVERTEX_NDOF", + "B_IPCHI2_OWNPV", + + "B_OWNPV_CHI2", + "B_OWNPV_NDOF", + "B_IP_OWNPV", + "B_DIRA_OWNPV", + + "B_PX", + "B_PY", + "B_PZ", + "B_PT", + "B_P", + "B_PE", + "B_FD_OWNPV", + "B_FDCHI2_OWNPV", + "B_PVandJpsiDTF_B_M", + + #D Reconstructed mass + #mother_ID[mother_index]+"_ConsD_M", + + #D Trigger variables + "B_L0Global_TIS", + + "B_L0MuonDecision_TIS", + "B_L0MuonDecision_TOS", + + "B_L0ElectronDecision_TIS", + "B_L0ElectronDecision_TOS", + + "B_L0HadronDecision_TIS", + "B_L0HadronDecision_TOS", + + "B_Hlt1TrackMVADecision_TOS", + "B_Hlt1TrackMVADecision_TIS", + #"B_Hlt2RareCharmD2Pi"+l_flv[l_index].capitalize()+l_flv[l_index].capitalize()+"OSDecision_TOS", + #"B_Hlt2Phys_TOS", + + #________________________________________ + #PHI MC TRUE INFO + + 'Jpsi_MC_MOTHER_ID', + 'Jpsi_BKGCAT', + 'Jpsi_TRUEID', + #________________________________________ + #phi geometric variables, pT and FD + + "Jpsi_ENDVERTEX_CHI2", + "Jpsi_ENDVERTEX_NDOF", + "Jpsi_IPCHI2_OWNPV", + + #"phi_OWNPV_CHI2", + #"phi_OWNPV_NDOF", + #"phi_IP_OWNPV", + #"phi_DIRA_OWNPV", + + "Jpsi_PT", + + #phi Reconstructed mass + + "Jpsi_M", + #________________________________________ + #K* + #K* mother ID and bkg cat + + 'Kstar_MC_MOTHER_ID', + 'Kstar_TRUEID', + + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + "Kstar_PX", + "Kstar_PY", + "Kstar_PZ", + + "Kstar_PT", + "Kstar_P", + "Kstar_PE", + + #________________________________________ + #________________________________________ + #Kaon + #Kaon mother ID and bkg cat + + 'K_MC_MOTHER_ID', + 'K_TRUEID', + + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + "K_PX", + "K_PY", + "K_PZ", + + "K_PT", + "K_P", + "K_PE", + + #Kaon PID variables + + "K_MC15TuneV1_ProbNNpi", + #________________________________________ + #Pion + #Pion mother ID and bkg cat + + 'Pi_MC_MOTHER_ID', + 'Pi_TRUEID', + + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + "Pi_PX", + "Pi_PY", + "Pi_PZ", + + "Pi_PT", + "Pi_P", + "Pi_PE", + + #Kaon PID variables + + "Pi_MC15TuneV1_ProbNNpi", + + #________________________________________ + #LEPTONS + 'L1_MC_MOTHER_ID', + 'L1_TRUEID', + + 'L2_MC_MOTHER_ID', + 'L2_TRUEID', + + #________________________________________ + #leptons Geometric variables and pT + + 'L1_OWNPV_CHI2', + #l_flv[l_index]+"_plus_OWNPV_NDOF", + 'L2_OWNPV_CHI2', + #l_flv[l_index]+"_minus_OWNPV_NDOF", + # + #l_flv[l_index]+"_plus_IP_OWNPV", + #l_flv[l_index]+"_minus_IP_OWNPV", + + "L1_PX", + "L1_PY", + "L1_PZ", + "L1_PT", + "L1_P", + "L1_PE", + 'L1_CosTheta', + + "L2_PX", + "L2_PY", + "L2_PZ", + "L2_PT", + "L2_P", + "L2_PE", + 'L2_CosTheta', + + #leptons PID variables + + # "L1_MC15TuneV1_ProbNN", + # "L2_MC15TuneV1_ProbNN", + ] + #data_index =1 -> data + if data_index==1: + branches_needed = [ + + #________________________________________ + #B Geometric variables, pT and FD + + "B_ENDVERTEX_CHI2", + "B_ENDVERTEX_NDOF", + "B_IPCHI2_OWNPV", + + "B_OWNPV_CHI2", + "B_OWNPV_NDOF", + "B_IP_OWNPV", + "B_DIRA_OWNPV", + + "B_PX", + "B_PY", + "B_PZ", + "B_PT", + "B_P", + "B_FD_OWNPV", + "B_FDCHI2_OWNPV", + "B_PVandJpsiDTF_B_M", + + #B Reconstructed mass + #mother_ID[mother_index]+"_ConsD_M", + + #D Trigger variables + "B_L0Global_TIS", + + "B_L0MuonDecision_TIS", + "B_L0MuonDecision_TOS", + + "B_L0ElectronDecision_TIS", + "B_L0ElectronDecision_TOS", + + "B_L0HadronDecision_TIS", + "B_L0HadronDecision_TOS", + + "B_Hlt1TrackMVADecision_TOS", + "B_Hlt1TrackMVADecision_TIS", + #"B_Hlt2RareCharmD2Pi"+l_flv[l_index].capitalize()+l_flv[l_index].capitalize()+"OSDecision_TOS", + #"B_Hlt2Phys_TOS", + + + #___________________________________ + #Jpsi + + #___________________________________ + #Jpsi geometric variables, pT and FD + + "Jpsi_ENDVERTEX_CHI2", + "Jpsi_ENDVERTEX_NDOF", + "Jpsi_IPCHI2_OWNPV", + + #"phi_OWNPV_CHI2", + #"phi_OWNPV_NDOF", + #"phi_IP_OWNPV", + #"phi_DIRA_OWNPV", + + "Jpsi_PT", + + #phi Reconstructed mass + + "Jpsi_M", + + #________________________________________ + #Kstar + + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + "Kstar_PX", + "Kstar_PY", + "Kstar_PZ", + + "Kstar_PT", + "Kstar_P", + "Kstar_PE", + + + #________________________________________ + #Kaon + + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + "K_PX", + "K_PY", + "K_PZ", + + "K_PT", + "K_P", + "K_PE", + #Kaon PID variables + + "K_MC15TuneV1_ProbNNpi", + #________________________________________ + #Pion + + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + "Pi_PX", + "Pi_PY", + "Pi_PZ", + + "Pi_PT", + "Pi_P", + "Pi_PE", + + #Kaon PID variables + + "Pi_MC15TuneV1_ProbNNpi", + + #________________________________________ + #LEPTONS + + #________________________________________ + #leptons Geometric variables and pT + + 'L1_OWNPV_CHI2', + #l_flv[l_index]+"_plus_OWNPV_NDOF", + 'L2_OWNPV_CHI2', + #l_flv[l_index]+"_minus_OWNPV_NDOF", + # + #l_flv[l_index]+"_plus_IP_OWNPV", + #l_flv[l_index]+"_minus_IP_OWNPV", + + "L1_PX", + "L1_PY", + "L1_PZ", + "L1_PT", + "L1_P", + "L1_PE", + 'L1_CosTheta', + + "L2_PX", + "L2_PY", + "L2_PZ", + "L2_PT", + "L2_P", + "L2_PE", + 'L2_CosTheta', + + #leptons PID variables + + # "L1_MC15TuneV1_ProbNN", + # "L2_MC15TuneV1_ProbNN", + ] + #data_index =1 -> data + if l_flv[l_index]=='mu': + #data_index =0 -> MC + if data_index==0: + branches_needed = [ + + #________________________________________ + #B Geometric variables, pT and FD + "B0_BKGCAT", + "B0_TRUEID", + "B0_ENDVERTEX_CHI2", + "B0_ENDVERTEX_NDOF", + "B0_IPCHI2_OWNPV", + + "B0_OWNPV_CHI2", + "B0_OWNPV_NDOF", + "B0_IP_OWNPV", + "B0_DIRA_OWNPV", + + "B0_PX", + "B0_PY", + "B0_PZ", + "B0_PT", + "B0_P", + "B0_PE", + "B0_FD_OWNPV", + "B0_FDCHI2_OWNPV", + "B0_M", + + "B0_TRUEP_X", + "B0_TRUEP_Y", + "B0_TRUEP_Z", + "B0_TRUEP_E", + + "B0_FD_OWNPV", + "B0_FDCHI2_OWNPV", + "B0_M", + #"B0_PVandJpsiDTF_B_M", + + #B Reconstructed mass + #mother_ID[mother_index]+"_ConsD_M", + + #D Trigger variables + "B0_L0Global_TIS", + "B0_L0MuonDecision_TIS", + "B0_L0MuonDecision_TOS", + "B0_L0ElectronDecision_TIS", + "B0_L0ElectronDecision_TOS", + "B0_L0HadronDecision_TIS", + "B0_L0HadronDecision_TOS", + "B0_Hlt1TrackMVADecision_TOS", + "B0_Hlt1TrackMVADecision_TIS", + #"B_Hlt2Phys_TOS", + + + #___________________________________ + #Jpsi + + "J_psi_BKGCAT", + "J_psi_TRUEID", + + #___________________________________ + #Jpsi geometric variables, pT and FD + + "J_psi_ENDVERTEX_CHI2", + "J_psi_ENDVERTEX_NDOF", + "J_psi_IPCHI2_OWNPV", + + #"phi_OWNPV_CHI2", + #"phi_OWNPV_NDOF", + #"phi_IP_OWNPV", + #"phi_DIRA_OWNPV", + + "J_psi_PT", + + #phi Reconstructed mass + + "J_psi_M", + #________________________________________ + #Kaon + + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + "Kstar_TRUEID", + "Kstar_PX", + "Kstar_PY", + "Kstar_PZ", + + "Kstar_TRUEP_X", + "Kstar_TRUEP_Y", + "Kstar_TRUEP_Z", + + "Kstar_PT", + "Kstar_P", + "Kstar_PE", + "Kstar_TRUEP_E", + + + #________________________________________ + #Kaon + + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + "K_TRUEID", + "K_PX", + "K_PY", + "K_PZ", + "K_TRUEP_X", + "K_TRUEP_Y", + "K_TRUEP_Z", + + + "K_PT", + "K_P", + "K_PE", + "K_TRUEP_E", + #Kaon PID variables + + "K_MC15TuneV1_ProbNNk", + #________________________________________ + #Pion + "Pi_TRUEID", + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + "Pi_PX", + "Pi_PY", + "Pi_PZ", + + "Pi_TRUEP_X", + "Pi_TRUEP_Y", + "Pi_TRUEP_Z", + + "Pi_PT", + "Pi_P", + "Pi_PE", + "Pi_TRUEP_E", + + #Kaon PID variables + + "Pi_MC15TuneV1_ProbNNpi", + + #________________________________________ + #LEPTONS + + 'mu_plus_TRUEID', + 'mu_minus_TRUEID', + + #________________________________________ + #leptons Geometric variables and pT + + 'mu_minus_OWNPV_CHI2', + #l_flv[l_index]+"_plus_OWNPV_NDOF", + 'mu_plus_OWNPV_CHI2', + #l_flv[l_index]+"_minus_OWNPV_NDOF", + # + #l_flv[l_index]+"_plus_IP_OWNPV", + #l_flv[l_index]+"_minus_IP_OWNPV", + + + + "mu_plus_PX", + "mu_plus_PY", + "mu_plus_PZ", + "mu_plus_TRUEP_X", + "mu_plus_TRUEP_Y", + "mu_plus_TRUEP_Z", + "mu_plus_TRUEP_E", + + "mu_plus_PY", + "mu_plus_PZ", + "mu_plus_PT", + "mu_plus_P", + "mu_plus_PE", + "mu_plus_CosTheta", + + "mu_minus_PX", + "mu_minus_PY", + "mu_minus_PZ", + "mu_minus_TRUEP_X", + "mu_minus_TRUEP_Y", + "mu_minus_TRUEP_Z", + "mu_minus_TRUEP_E", + "mu_minus_PT", + "mu_minus_P", + "mu_minus_PE", + "mu_minus_CosTheta", + + #leptons PID variables + + # "L1_MC15TuneV1_ProbNN", + # "L2_MC15TuneV1_ProbNN", + ] + #data_index =1 -> data + if data_index==1: + branches_needed = [ + + #________________________________________ + #B Geometric variables, pT and FD + + "B0_ENDVERTEX_CHI2", + "B0_ENDVERTEX_NDOF", + "B0_IPCHI2_OWNPV", + + "B0_OWNPV_CHI2", + "B0_OWNPV_NDOF", + "B0_IP_OWNPV", + "B0_DIRA_OWNPV", + + "B0_PX", + "B0_PY", + "B0_PZ", + "B0_PT", + "B0_P", + "B0_PE", + "B0_FD_OWNPV", + "B0_FDCHI2_OWNPV", + "B0_M", + + #B Reconstructed mass + #mother_ID[mother_index]+"_ConsD_M", + + #D Trigger variables + "B0_L0Global_TIS", + "B0_L0MuonDecision_TIS", + "B0_L0MuonDecision_TOS", + "B0_L0ElectronDecision_TIS", + "B0_L0ElectronDecision_TOS", + "B0_L0HadronDecision_TIS", + "B0_L0HadronDecision_TOS", + "B0_Hlt1TrackMVADecision_TOS", + "B0_Hlt1TrackMVADecision_TIS", + #"B_Hlt2Phys_TOS", + + + #___________________________________ + #Jpsi + + #___________________________________ + #Jpsi geometric variables, pT and FD + + "J_psi_ENDVERTEX_CHI2", + "J_psi_ENDVERTEX_NDOF", + "J_psi_IPCHI2_OWNPV", + + #"phi_OWNPV_CHI2", + #"phi_OWNPV_NDOF", + #"phi_IP_OWNPV", + #"phi_DIRA_OWNPV", + + "J_psi_PT", + + #phi Reconstructed mass + + "J_psi_M", + #________________________________________ + #Kstar + + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + "Kstar_PX", + "Kstar_PY", + "Kstar_PZ", + + "Kstar_PT", + "Kstar_P", + "Kstar_PE", + + #________________________________________ + #Kaon + + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + "K_PX", + "K_PY", + "K_PZ", + + "K_PT", + "K_P", + "K_PE", + #Kaon PID variables + + "K_MC15TuneV1_ProbNNk", + #________________________________________ + #Pion + + #_____________________________________ + #Kaon Geometric variables and pT + #"pi_OWNPV_CHI2", + #"pi_OWNPV_NDOF", + #'pi_IP_OWNPV', + + "Pi_PX", + "Pi_PY", + "Pi_PZ", + + "Pi_PT", + "Pi_P", + "Pi_PE", + + #Kaon PID variables + + "Pi_MC15TuneV1_ProbNNpi", + + #________________________________________ + #LEPTONS + + #________________________________________ + #leptons Geometric variables and pT + + 'mu_plus_OWNPV_CHI2', + #l_flv[l_index]+"_plus_OWNPV_NDOF", + 'mu_minus_OWNPV_CHI2', + #l_flv[l_index]+"_minus_OWNPV_NDOF", + # + #l_flv[l_index]+"_plus_IP_OWNPV", + #l_flv[l_index]+"_minus_IP_OWNPV", + + "mu_plus_PX", + "mu_plus_PY", + "mu_plus_PZ", + "mu_plus_PT", + "mu_plus_P", + "mu_plus_PE", + "mu_plus_CosTheta", + + + "mu_minus_PX", + "mu_minus_PY", + "mu_minus_PZ", + "mu_minus_PT", + "mu_minus_P", + "mu_minus_PE", + "mu_minus_CosTheta", + + + #leptons PID variables + + # "L1_MC15TuneV1_ProbNN", + # "L2_MC15TuneV1_ProbNN", + ] + #data_index =1 -> data + return branches_needed + +def norm_chi2(MC_Dplus_sig_dict, MC_Ds_sig_dict, data_dict): + MC_Ds_sig_dict["Ds_ENDVERTEX_CHI2"]=MC_Ds_sig_dict["Ds_ENDVERTEX_CHI2"]/MC_Ds_sig_dict["Ds_ENDVERTEX_NDOF"] + MC_Ds_sig_dict["Ds_IPCHI2_OWNPV"]=MC_Ds_sig_dict["Ds_IPCHI2_OWNPV"]/MC_Ds_sig_dict["Ds_ENDVERTEX_NDOF"] + + MC_Ds_sig_dict["Ds_FDCHI2_OWNPV"]=MC_Ds_sig_dict["Ds_FDCHI2_OWNPV"]/MC_Ds_sig_dict["Ds_OWNPV_NDOF"] + MC_Ds_sig_dict["Ds_OWNPV_CHI2"]=MC_Ds_sig_dict["Ds_OWNPV_CHI2"]/MC_Ds_sig_dict["Ds_OWNPV_NDOF"] + + del MC_Ds_sig_dict["Ds_OWNPV_NDOF"] + del MC_Ds_sig_dict["Ds_ENDVERTEX_NDOF"] + + MC_Dplus_sig_dict["Dplus_ENDVERTEX_CHI2"]=MC_Dplus_sig_dict["Dplus_ENDVERTEX_CHI2"]/MC_Dplus_sig_dict["Dplus_ENDVERTEX_NDOF"] + MC_Dplus_sig_dict["Dplus_IPCHI2_OWNPV"]=MC_Dplus_sig_dict["Dplus_IPCHI2_OWNPV"]/MC_Dplus_sig_dict["Dplus_ENDVERTEX_NDOF"] + + MC_Dplus_sig_dict["Dplus_FDCHI2_OWNPV"]=MC_Dplus_sig_dict["Dplus_FDCHI2_OWNPV"]/MC_Dplus_sig_dict["Dplus_OWNPV_NDOF"] + MC_Dplus_sig_dict["Dplus_OWNPV_CHI2"]=MC_Dplus_sig_dict["Dplus_OWNPV_CHI2"]/MC_Dplus_sig_dict["Dplus_OWNPV_NDOF"] + + del MC_Dplus_sig_dict["Dplus_OWNPV_NDOF"] + del MC_Dplus_sig_dict["Dplus_ENDVERTEX_NDOF"] + + data_dict["Ds_ENDVERTEX_CHI2"]=data_dict["Ds_ENDVERTEX_CHI2"]/data_dict["Ds_ENDVERTEX_NDOF"] + data_dict["Ds_IPCHI2_OWNPV"]=data_dict["Ds_IPCHI2_OWNPV"]/data_dict["Ds_ENDVERTEX_NDOF"] + + data_dict["Ds_FDCHI2_OWNPV"]=data_dict["Ds_FDCHI2_OWNPV"]/data_dict["Ds_OWNPV_NDOF"] + data_dict["Ds_OWNPV_CHI2"]=data_dict["Ds_OWNPV_CHI2"]/data_dict["Ds_OWNPV_NDOF"] + + del data_dict["Ds_OWNPV_NDOF"] + del data_dict["Ds_ENDVERTEX_NDOF"] + + return MC_Dplus_sig_dict, MC_Ds_sig_dict, data_dict + +# def mass_cut_for_fit(lower_cut, upper_cut, mother_index_fit=None, l_index=None, +# branches_needed=None, data_dict=None, +# MC_Dplus_dict=None, MC_Ds_dict=None): +# #Applies needed mass cuts on data and +# #returns arrays of mass distr for MC and data +# data_indices=[] + +# for i in range(len(data_dict["Ds_ConsD_M"])): + +# D_m = data_dict["Ds_ConsD_M"][i] +# #fixing a window on the phi mass +# if lower_cut2: + # with open(self.SAVE_BDT_SELECTED_PATH+mother_ID[1]+'_phipi_'+l_flv[self.l_index]+l_flv[self.l_index]+'_BDT_selection.pickle', 'rb') as f: + # data_dict=pickle.load(f, encoding='latin1') + + # else: + # with open(self.SAVE_BDT_SELECTED_PATH+mother_ID[1]+'_phipi_'+l_flv[self.l_index]+l_flv[self.l_index]+'_BDT_selection.pickle', 'rb') as f: + # data_dict=pickle.load(f) + + """" + + Create RooDataSet + + """ + + ##VERSION 1 VANILLA DATASET + #mass = np.array([0],dtype=np.float32) + #branch = tree.GetBranch(mother_ID[mother_index]+"_ConsD_M") + #branch.SetAddress(mass) + # + #num_entries=tree.GetEntries() + # + #m = r.RooRealVar(names['m_name'],names['m_name'],mean_d_down,mean_d_up) + #l = r.RooArgSet(m) + # + #data_set = r.RooDataSet(names['data_set_name'], names['data_set_name'], l) + # + #for i in range(num_entries): + # tree.GetEvent(i) + # if mean_d_down < mass[0] < mean_d_up: + # r.RooAbsRealLValue.__assign__(m, mass[0]) + # data_set.add(l, 1.0) + + #VERSION 2 HARD CUT ON BDT_VALUE + + mass = np.array([0],dtype=np.float32) + branch = tree.GetBranch(mother_ID[mother_index]+"_ConsD_M") + branch.SetAddress(mass) + + bdt_weight = np.array([0],dtype=np.float32) + weight_branch = tree.GetBranch("BDT_selection") + weight_branch.SetAddress(bdt_weight) + + num_entries=tree.GetEntries() + + m = r.RooRealVar(names['m_name'],names['m_name'],mean_d_down,mean_d_up) + bdt_weights = r.RooRealVar('bdt_weights', 'bdt_weights', 0., 1.) + l = r.RooArgSet(m) + + data_set = r.RooDataSet(names['data_set_name'], names['data_set_name'], l) + selected = [] + for i in range(num_entries): + tree.GetEvent(i) + if bdt_weight[0]>BDT_CUT: + if mean_d_down < mass[0] < mean_d_up: + selected.append(i) + r.RooAbsRealLValue.__assign__(m, mass[0]) + data_set.add(l, 1.0) + + selected_np = np.array(selected) + + with open(self.SAVE_BDT_SELECTED_PATH+mother_ID[1]+'_phipi_'+l_flv[self.l_index]+l_flv[self.l_index]+'_BDT_selection.pickle') as f: + data_dict=pickle.load(f) + + branches=data_dict.keys() + data_BDT_selected={} + + for label in branches: + data_BDT_selected[label]=data_dict[label][selected_np] + + FILE_PATH = self.SAVE_BDT_SELECTED_PATH+mother_ID[1]+'_phipi_'+l_flv[self.l_index]+l_flv[self.l_index]+'_BDT_selection_temp.pickle' + if os.path.exists(FILE_PATH): + + print('Overwriting pickle file at'+FILE_PATH) + + else: + print('Saving pickle file at'+FILE_PATH) + + + with open(FILE_PATH, 'wb') as handle: + pickle.dump(data_BDT_selected, handle, protocol=pickle.HIGHEST_PROTOCOL) + + #VERSION 3 WEIGHTED DATASET + + # mass = np.array([0],dtype=np.float32) + # branch = tree.GetBranch(mother_ID[mother_index]+"_ConsD_M") + # branch.SetAddress(mass) + + # bdt_weight = np.array([0],dtype=np.float32) + # weight_branch = tree.GetBranch("BDT_selection") + # weight_branch.SetAddress(bdt_weight) + + # num_entries=tree.GetEntries() + + # m = r.RooRealVar(names['m_name'],names['m_name'],mean_d_down,mean_d_up) + # bdt_weights = r.RooRealVar('bdt_weights', 'bdt_weights', 0., 1.) + # obs = r.RooArgSet(m, bdt_weights) + + # data_set = r.RooDataSet(names['data_set_name'], names['data_set_name'], obs, r.RooFit.WeightVar(bdt_weights)) + + # for i in range(num_entries): + # tree.GetEvent(i) + # if mean_d_down < mass[0] < mean_d_up: + # r.RooAbsRealLValue.__assign__(m, mass[0]) + # data_set.add(obs, bdt_weight[0]) + + """" + + Load and update dataset + + """ + + f = r.TFile(self.workspace_path+self.workspace_filename) + w = f.Get(self.workspace_filename) + + + getattr(w, 'import')(m) + #getattr(w, 'import')(bdt_weights) + getattr(w, 'import')(data_set) + + """" + + Prepare fit model + + """ + ################## + # + # Dplus SIGNAL PDF + # + ################## + + mean_Dplus_MC=w.var("MC_mean_Dplus") + sigma_Dplus_MC=w.var("MC_sigma_Dplus") + + mean_Dplus_MC.setConstant(True) + sigma_Dplus_MC.setConstant(True) + + meanShift_Dplus=r.RooRealVar("mean_shift_Dplus","mean_shift_Dplus",1.5,-5,5) + scaleSigma_Dplus=r.RooRealVar("scale_factor_Dplus","scale_factor_Dplus",1.12,1,5) + + mean_Dplus_shifted=r.RooFormulaVar("shifted_mean_Dplus","shifted_mean_Dplus","@0+@1",r.RooArgList(mean_Dplus_MC,meanShift_Dplus)) + sigma_Dplus_scaled=r.RooFormulaVar("scaled_sigma_Dplus","scaled_sigma_Dplus","@0*@1",r.RooArgList(sigma_Dplus_MC,scaleSigma_Dplus)) + + frc_lr_Dplus_MC=w.var("MC_Dplus_lr_fraction") + + al_Dplus_left = w.var("MC_alpha_Dplus_left") + n_Dplus_left = w.var("MC_n_Dplus_left") + pdf_Dplus_left = r.RooCBShape("data_pdf_Dplus_left","data_pdf_Dplus_left", m, mean_Dplus_shifted, sigma_Dplus_scaled, al_Dplus_left, n_Dplus_left) + + al_Dplus_right = w.var("MC_alpha_Dplus_right") + n_Dplus_right = w.var("MC_n_Dplus_right") + pdf_Dplus_right = r.RooCBShape("data_pdf_Dplus_right","data_pdf_Dplus_right", m, mean_Dplus_shifted, sigma_Dplus_scaled, al_Dplus_right, n_Dplus_right) + + sig_Dplus = r.RooAddPdf("data_pdf_Dplus","data_pdf_Dplus",r.RooArgList(pdf_Dplus_left, pdf_Dplus_right),r.RooArgList(frc_lr_Dplus_MC)) + + ################## + # + # Dplus ->PiPiPi MisID PDF + # + ################## + + # mean_Dplus_misID=w.var("MC_mean_Dplus_misID") + # sigma_Dplus_misID=w.var("MC_sigma_Dplus_misID") + + # frc_lr_Dplus_misID=w.var("MC_Dplus_lr_fraction_misID") + + # al_Dplus_left_misID = w.var("MC_alpha_Dplus_left_misID") + # n_Dplus_left_misID = w.var("MC_n_Dplus_left_misID") + # pdf_Dplus_left_misID = r.RooCBShape("data_pdf_Dplus_left_misID","data_pdf_Dplus_left_misID", m, mean_Dplus_misID, sigma_Dplus_misID, al_Dplus_left_misID, n_Dplus_left_misID) + + # al_Dplus_right_misID = w.var("MC_alpha_Dplus_right_misID") + # n_Dplus_right_misID = w.var("MC_n_Dplus_right_misID") + # pdf_Dplus_right_misID = r.RooCBShape("data_pdf_Dplus_right_misID","data_pdf_Dplus_right_misID", m, mean_Dplus_misID, sigma_Dplus_misID, al_Dplus_right_misID, n_Dplus_right_misID) + + # bkg_Dplus_misID = r.RooAddPdf("data_pdf_Dplus_misID","data_pdf_Dplus_misID",r.RooArgList(pdf_Dplus_left_misID, pdf_Dplus_right_misID),r.RooArgList(frc_lr_Dplus_misID)) + + ################## + # + # Ds SIGNAL PDF + # + ################## + + mean_Ds_MC=w.var("MC_mean_Ds") + sigma_Ds_MC=w.var("MC_sigma_Ds") + + mean_Ds_MC.setConstant(True) + sigma_Ds_MC.setConstant(True) + + meanShift_Ds=r.RooRealVar("mean_shift_Ds","mean_shift_Ds",1.5,-5,5) + scaleSigma_Ds=r.RooRealVar("scale_factor_Ds","scale_factor_Ds",1.12,1,1.5) + + mean_Ds_shifted=r.RooFormulaVar("shifted_mean_Ds","shifted_mean_Ds","@0+@1",r.RooArgList(mean_Ds_MC,meanShift_Ds)) + sigma_Ds_scaled=r.RooFormulaVar("scaled_sigma_Ds","scaled_sigma_Ds","@0*@1",r.RooArgList(sigma_Ds_MC,scaleSigma_Ds)) + + + frc_lr_Ds_MC=w.var("MC_Ds_lr_fraction") + + al_Ds_left = w.var("MC_alpha_Ds_left") + n_Ds_left = w.var("MC_n_Ds_left") + pdf_Ds_left = r.RooCBShape("data_pdf_Ds_left","data_pdf_Ds_left", m, mean_Ds_shifted, sigma_Ds_scaled, al_Ds_left, n_Ds_left) + + al_Ds_right = w.var("MC_alpha_Ds_right") + n_Ds_right = w.var("MC_n_Ds_right") + pdf_Ds_right = r.RooCBShape("data_pdf_Ds_right","data_pdf_Ds_right", m, mean_Ds_shifted, sigma_Ds_scaled, al_Ds_right, n_Ds_right) + + sig_Ds = r.RooAddPdf("data_pdf_Ds","data_pdf_Ds",r.RooArgList(pdf_Ds_left, pdf_Ds_right),r.RooArgList(frc_lr_Ds_MC)) + + ################## + # + # Ds ->PiPiPi MisID PD + # + ################## + + # mean_Ds_misID=w.var("MC_mean_Ds_misID") + # sigma_Ds_misID=w.var("MC_sigma_Ds_misID") + + # frc_lr_Ds_misID=w.var("MC_Ds_lr_fraction_misID") + + # al_Ds_left_misID = w.var("MC_alpha_Ds_left_misID") + # n_Ds_left_misID = w.var("MC_n_Ds_left_misID") + # pdf_Ds_left_misID = r.RooCBShape("data_pdf_Ds_left_misID","data_pdf_Ds_left_misID", m, mean_Ds_misID, sigma_Ds_misID, al_Ds_left_misID, n_Ds_left_misID) + + # al_Ds_right_misID = w.var("MC_alpha_Ds_right_misID") + # n_Ds_right_misID = w.var("MC_n_Ds_right_misID") + # pdf_Ds_right_misID = r.RooCBShape("data_pdf_Ds_right_misID","data_pdf_Ds_right_misID", m, mean_Ds_misID, sigma_Ds_misID, al_Ds_right_misID, n_Ds_right_misID) + + # bkg_Ds_misID = r.RooAddPdf("data_pdf_Ds_misID","data_pdf_Ds_misID",r.RooArgList(pdf_Ds_left_misID, pdf_Ds_right_misID),r.RooArgList(frc_lr_Ds_misID)) + + ################# + # + # + # Bkg PDF + # + ############# + + lambd = r.RooRealVar("lambda","lambda",-5e-4,-0.1,0.1) + bkg = r.RooExponential("pdf_comb_bkg","pdf_comb_bkg",m,lambd) + + ################# + # + # + # Yields and total model + # + ############# + + yield_Ds=r.RooRealVar("yield_Ds","yield_Ds",100.,0.,40000.) + yield_Dplus=r.RooRealVar("yield_Dplus","yield_Dplus",100.,0.,40000.) + + yield_Ds_misID=r.RooRealVar("yield_Ds_misID","yield_Ds_misID",100.,0.,200.) + yield_Dplus_misID=r.RooRealVar("yield_Dplus_misID","yield_Dplus_misID",100.,0.,200.) + + yield_comb_bkg=r.RooRealVar("yeld_comb_bkg","yeld_comb_bkg",100.,0.,1000.) + + #model = r.RooAddPdf("fit_model","fit_model",r.RooArgList(sig_Dplus, sig_Ds, bkg_Dplus_misID, bkg_Ds_misID, bkg),r.RooArgList(yield_Dplus, yield_Ds, yield_Dplus_misID, yield_Ds_misID, yield_comb_bkg)) + # model = r.RooAddPdf("fit_model","fit_model",r.RooArgList(sig_Dplus, sig_Ds, bkg_Dplus_misID, bkg_Ds_misID, bkg),r.RooArgList(yield_Dplus, yield_Ds, yield_Dplus_misID, yield_Ds_misID, yield_comb_bkg)) + # model = r.RooAddPdf("fit_model","fit_model",r.RooArgList(sig_Dplus, sig_Ds, bkg_Dplus_misID, bkg_Ds_misID, bkg),r.RooArgList(yield_Dplus, yield_Ds, yield_Dplus_misID, yield_Ds_misID, yield_comb_bkg)) + model = r.RooAddPdf("fit_model","fit_model",r.RooArgList(sig_Dplus, sig_Ds, bkg),r.RooArgList(yield_Dplus, yield_Ds, yield_comb_bkg)) + + bdt_cut = r.RooRealVar("bdt_cut","BDT Working Point", 0.,1.) + bdt_cut.setVal(BDT_CUT) + bdt_cut.setConstant(True) + + low_mass_cut = r.RooRealVar("low_mass_cut","Lower mass cut for fit", 1000.,2000.) + low_mass_cut.setVal(mean_d_down) + low_mass_cut.setConstant(True) + + up_mass_cut = r.RooRealVar("up_mass_cut","Upper mass cut for fit", 1000.,2000.) + up_mass_cut.setVal(mean_d_up) + up_mass_cut.setConstant(True) + + getattr(w, 'import')(bdt_cut) + getattr(w, 'import')(low_mass_cut) + getattr(w, 'import')(up_mass_cut) + getattr(w, 'import')(lambd) + getattr(w, 'import')(yield_Dplus) + getattr(w, 'import')(yield_Ds) + + getattr(w, 'import')(yield_Dplus_misID) + getattr(w, 'import')(yield_Ds_misID) + getattr(w, 'import')(yield_comb_bkg) + getattr(w, 'import')(model) + + w.Print() + w.writeToFile(self.workspace_path+self.workspace_filename, r.kTRUE) + + + print('Done!') + return + + def fit_data(self, mother_index=1): + + data_index=1 + + print("Fitting data D(s)_phipi_"+l_flv[self.l_index]+l_flv[self.l_index]) + + names = return_names(data_index, mother_index) + + """ + Get workspace from file + + """ + + f = r.TFile(self.workspace_path+self.workspace_filename) + w = f.Get(self.workspace_filename) + + w.Print() + + model = w.pdf(names['model_name']) + data_set = w.data(names['data_set_name']) + + m = w.var(names['m_name']) + + print(model, data_set, m) + """ + Fit step and save + + """ + + fitr = model.fitTo(data_set,r.RooFit.Extended(),r.RooFit.Save()) + + xframe = m.frame() + data_set.plotOn(xframe) + model.plotOn(xframe, r.RooFit.LineColor(r.kBlack), r.RooFit.LineStyle(2)) + hpull=xframe.pullHist() + + chisq = r.RooRealVar("reduced_chisq","#Chi^2 / n.d.o.f.", 0., 10.) + n_param = fitr.floatParsFinal().getSize() + reduced_chi_square = xframe.chiSquare(n_param) + chisq.setVal(reduced_chi_square) + + model_vars = w.allVars() + model_pdfs = w.allPdfs() + getattr(w,'import')(model_vars) + getattr(w,'import')(chisq) + getattr(w,'import')(model_pdfs) + + w.Print() + w.writeToFile(self.workspace_path+self.workspace_filename, r.kTRUE) + + print('Done!') + return + + def plot_data(self, mother_index=1, wantThesisStyle=None): + + mother_index=1 + data_index=1 + + names = return_names(data_index, mother_index) + f = r.TFile(self.workspace_path+self.workspace_filename) + w = f.Get(self.workspace_filename) + w.Print() + + model = w.pdf(names['model_name']) + data_set = w.data(names['data_set_name']) + m = w.var(names['m_name']) + bkg = w.pdf("pdf_comb_bkg") + sig_Dplus = w.pdf("data_pdf_Dplus") + sig_Ds = w.pdf("data_pdf_Ds") + bkg_Dplus_misID=w.pdf("data_pdf_Dplus_misID") + bkg_Ds_misID=w.pdf("data_pdf_Ds_misID") + lambd = w.var("lambda") + mean_Dplus = w.var("MC_mean_Dplus") + mean_Ds = w.var("MC_mean_Ds") + sigma_Dplus = w.var("MC_sigma_Dplus") + sigma_Ds = w.var("MC_sigma_Ds") + meanShift_Dplus = w.var("mean_shift_Dplus") + scaleSigma_Dplus = w.var("scale_factor_Dplus") + meanShift_Ds = w.var("mean_shift_Ds") + scaleSigma_Ds = w.var("scale_factor_Ds") + chisq=w.var("reduced_chisq") + + mean_Ds.setConstant(False) + mean_Dplus.setConstant(False) + + sigma_Dplus.setConstant(False) + sigma_Ds.setConstant(False) + chisq.setConstant(False) + + xframe = m.frame(r.RooFit.Title("Fit to "+l_flv[self.l_index]+" data trigCat"+str(self.trigCat))) + + if wantThesisStyle==False: + + argset=r.RooArgSet(chisq, mean_Dplus, mean_Ds, sigma_Dplus, sigma_Ds, meanShift_Dplus, scaleSigma_Dplus, meanShift_Ds, scaleSigma_Ds) + model.paramOn(xframe, r.RooFit.Layout(0.63,0.95,0.90), r.RooFit.Parameters(argset),r.RooFit.Format("NEU", r.RooFit.AutoPrecision(2))) + xframe.getAttText().SetTextSize(0.038) + #xframe.getAttFill(names["model_name"]+"_paramBox").SetFillStyle(0) + xframe.getAttFill(names["model_name"]+"_paramBox").SetFillColor(r.kWhite) + xframe.getAttFill(names["model_name"]+"_paramBox").SetLineWidth(0) + + third_set = r.RooArgSet(bkg,sig_Dplus,sig_Ds) + fourth_set = r.RooArgSet(bkg,sig_Dplus) + fifth_set = r.RooArgSet(bkg) + data_set.plotOn(xframe) + model.plotOn(xframe, r.RooFit.LineColor(r.kBlack), + r.RooFit.LineStyle(2)) + col1 = r.gROOT.GetColor(92); + col1.SetRGB(0.992, 0.6823, 0.3804); #orange for comb + col2 = r.gROOT.GetColor(93); + col2.SetRGB(0.6706, 0.8510, 0.9137); #light blue for Ds + col3 = r.gROOT.GetColor(94); + col3.SetRGB(0.8431, 0.098, 0.1098); #red for charm prc + col4 = r.gROOT.GetColor(95); #dark blue for Dplus + col4.SetRGB(0.1725, 0.4824, 0.7137); + + model.plotOn(xframe,r.RooFit.Name("Ds_component"), r.RooFit.Components(third_set),r.RooFit.FillColor(93), + r.RooFit.DrawOption("f"), r.RooFit.LineColor(93),) + model.plotOn(xframe,r.RooFit.Name("Dplus_component"), r.RooFit.Components(fourth_set),r.RooFit.FillColor(95), + r.RooFit.DrawOption("f"), r.RooFit.LineColor(95),) + model.plotOn(xframe,r.RooFit.Name("Combinatorial"), r.RooFit.Components(fifth_set),r.RooFit.FillColor(92), + r.RooFit.DrawOption("f"), r.RooFit.LineColor(92),) + model.plotOn(xframe , r.RooFit.Name("tot"), r.RooFit.LineColor(r.kBlack), r.RooFit.LineStyle(2)) + data_set.plotOn(xframe, r.RooFit.Name("data")) + hpull=xframe.pullHist() + + xframe2 = m.frame(r.RooFit.Title("Pulls")) + xframe2.addPlotable(hpull,"P") + + + canvTot = r.TCanvas("Fit","Fit",900,600) + pad1 = r.TPad("pad1", "pad1", 0, 0.35, 1, 1.0) + pad1.SetBottomMargin(0) + pad1.Draw() + canvTot.cd() + pad2 = r.TPad("pad2", "pad2", 0, 0.05, 1, 0.35) + pad2.SetTopMargin(0) + pad2.SetBottomMargin(0.2) + pad2.SetGridx() + pad2.SetGridy() + pad2.Draw() + + pad1.cd() + xframe.Draw() + + + text=r.TPaveText(-0.5, 1.25, 0.92, 0.45, "NDC"); + text.AddText( "#Chi^{2}/NDOF = %.4f" % chisq.getVal()) + text.SetTextSize(0.035); + text.SetFillColor(0); + text.SetFillStyle(0); + text.SetLineColor(0); + text.SetLineWidth(0); + text.SetBorderSize(1); + text.Draw("same") + + leg = r.TLegend(0.78,0.68,0.9,0.9) + leg.AddEntry("data", "Data", "lep") + leg.AddEntry("tot", "Total Fit", "l") + leg.AddEntry("Ds_component", "D_{s}^{#plus} #rightarrow #phi(e^{#plus} e^{#minus}) #pi^{#plus}", "f") + leg.AddEntry("Dplus_component", "D^{#plus} #rightarrow #phi(e^{#plus} e^{#minus}) #pi^{#plus}", "f") + leg.AddEntry("Combinatorial", "Comb bkg", "f") + leg.SetTextSize(xframe.GetYaxis().GetTitleSize()); + leg.SetLineColor(0); + leg.SetFillColor(0); + + pad2.cd() + xframe2.Draw() + xframe2.GetXaxis().SetTitleSize(0.09) + xframe2.GetXaxis().SetLabelSize(0.1) + xframe2.GetYaxis().SetLabelSize(0.05) + + if wantThesisStyle==False: + + + filename = "Fit_D(s)_phipi_"+l_flv[self.l_index]+l_flv[self.l_index]+".png" + canvTot.SaveAs(self.PLOT_DIR+filename) + + pad1.DrawClone() + pad1.SetLogy() + + filename = "Fit_D(s)_phipi_"+l_flv[self.l_index]+l_flv[self.l_index]+"_logy.png" + canvTot.SaveAs(self.PLOT_DIR+filename) + + + elif wantThesisStyle==True: + + pad1.cd() + leg.Draw("same") + filename = "Fit_D(s)_phipi_"+l_flv[self.l_index]+l_flv[self.l_index]+"_thesisStyle.png" + canvTot.SaveAs(self.PLOT_DIR+filename) + + pad1.DrawClone() + pad1.SetLogy() + + filename = "Fit_D(s)_phipi_"+l_flv[self.l_index]+l_flv[self.l_index]+"_logy_thesisStyle.png" + canvTot.SaveAs(self.PLOT_DIR+filename) + + def splot(self, mother_index=1, plot=True): + + data_index=1 + names = return_names(data_index, mother_index) + f = r.TFile(self.workspace_path+self.workspace_filename) + w = f.Get(self.workspace_filename) + + w.Print() + + model = w.pdf(names['model_name']) + data_set = w.data(names['data_set_name']) + m = w.var(names['m_name']) + bkg = w.pdf("pdf_comb_bkg") + sig_Dplus = w.pdf("data_pdf_Dplus") + sig_Ds = w.pdf("data_pdf_Ds") + bdt_cut = w.var("bdt_cut") + low_mass_cut = w.var("low_mass_cut") + up_mass_cut = w.var("up_mass_cut") + yield_Dplus=w.var("yield_Dplus") + yield_Ds=w.var("yield_Ds") + yield_comb_bkg=w.var("yeld_comb_bkg") + + + splot = r.RooStats.SPlot('sData','sData', data_set, model, r.RooArgList(yield_Dplus, yield_Ds, yield_comb_bkg) + ) + + yeld_comb_bkg_sw = splot.GetYieldFromSWeight("yeld_comb_bkg_sw") + yield_Dplus_sw= splot.GetYieldFromSWeight("yield_Dplus_sw") + yield_Ds_sw = splot.GetYieldFromSWeight("yield_Ds_sw") + + yeld_comb_bkg_sw_var = r.RooRealVar("sweighted_comb_bkg_yield","sweighted_comb_bkg_yield", 0., 10000.) + yield_Dplus_sw_var = r.RooRealVar("sweighted_Dplus_sw_yield","sweighted_Dplus_sw_yield", 0., 10000.) + yield_Ds_sw_var = r.RooRealVar("sweighted_Ds_sw_yield","sweighted_Ds_sw_yield", 0., 10000.) + + + getattr(w, 'import')(yeld_comb_bkg_sw_var) + getattr(w, 'import')(yield_Dplus_sw_var) + getattr(w, 'import')(yield_Ds_sw_var) + + w.Print() + w.writeToFile(self.workspace_path+self.workspace_filename, r.kTRUE) + + print('Done!') + + nentries=int(data_set.sumEntries()) + Dplus_sWeights=np.array([splot.GetSWeight(i, "yield_Dplus_sw") for i in range(nentries)]) + Ds_sWeights=np.array([splot.GetSWeight(i, "yield_Ds_sw") for i in range(nentries)]) + comb_bkg_sWeights=np.array([splot.GetSWeight(i, "yeld_comb_bkg_sw") for i in range(nentries)]) + + with open(self.SAVE_BDT_SELECTED_PATH+mother_ID[1]+'_phipi_'+l_flv[self.l_index]+l_flv[self.l_index]+'_BDT_selection_temp.pickle') as f: + data_dict=pickle.load(f) + + branches=data_dict.keys() + branches_updated = branches + ["Dplus_sWeights","Ds_sWeights","Comb_bkg_sWeights"] + + data_dict["Dplus_sWeights"]=Dplus_sWeights + data_dict["Ds_sWeights"]=Ds_sWeights + data_dict["Comb_bkg_sWeights"]=comb_bkg_sWeights + + assert nentries == data_dict["Ds_ConsD_M"].shape[0], "Mismatching number of events in two load methods" + + print(data_dict["Ds_ConsD_M"].shape[0]) + + FILE_PATH = self.SAVE_BDT_SELECTED_PATH+mother_ID[1]+'_phipi_'+l_flv[self.l_index]+l_flv[self.l_index]+'_'+self.year+'_sWeighted.pickle' + + if os.path.exists(FILE_PATH): + + print('Overwriting pickle file at'+FILE_PATH) + + else: + print('Saving pickle file at'+FILE_PATH) + + + with open(FILE_PATH, 'wb') as handle: + pickle.dump(data_dict, handle, protocol=pickle.HIGHEST_PROTOCOL) + + FILE_PATH = self.SAVE_BDT_SELECTED_PATH+mother_ID[1]+'_phipi_'+l_flv[self.l_index]+l_flv[self.l_index]+'_'+self.year+'_sWeighted.root' + + if os.path.exists(FILE_PATH): + print('Overwriting root file at'+FILE_PATH) + mode = 'recreate' + else: + print('Saving root file at'+FILE_PATH) + mode = 'create' + + + tuple_array= np.array( + [ + tuple(data_dict[label][k] for label in branches_updated ) + for k in range(nentries) + ], + dtype=[(label, np.float32) for label in branches_updated] + ) + + rn.array2root(tuple_array, + filename=FILE_PATH, + treename='DecayTree', + mode=mode, + ) + + Dplus_sw=splot.GetSWeightVars()[0] + Ds_sw=splot.GetSWeightVars()[1] + comb_bkg_sw=splot.GetSWeightVars()[2] + + if plot: + + Ds_sw.setRange(-0.5,1.5) + + frame_Ds_sw = Ds_sw.frame(r.RooFit.Title("signal Ds sWeights")) + data_set.plotOn(frame_Ds_sw, r.RooFit.MarkerSize(0.05)) + Dplus_sw.setRange(-1.,1.5) + + frame_Dplus_sw = Dplus_sw.frame(r.RooFit.Title("signal Dplus sWeights")) + data_set.plotOn(frame_Dplus_sw, r.RooFit.MarkerSize(0.05)) + + comb_bkg_sw.setRange(-.6,1.2) + frame_bkg_sw = comb_bkg_sw.frame(r.RooFit.Title("background sWeights")) + data_set.plotOn(frame_bkg_sw, r.RooFit.MarkerSize(0.05)) + + sframe = m.frame(r.RooFit.Title("sWeights vs D mass")) + data_set.plotOnXY(sframe, r.RooFit.YVar(Ds_sw), + r.RooFit.MarkerColor(r.kGreen), r.RooFit.Name("Ds_sig")) + data_set.plotOnXY(sframe, r.RooFit.YVar(Dplus_sw), + r.RooFit.MarkerColor(r.kBlue), r.RooFit.Name("Dplus_sig")) + data_set.plotOnXY(sframe, r.RooFit.YVar(comb_bkg_sw), + r.RooFit.MarkerColor(r.kRed), r.RooFit.Name("bkg")) + + legend = r.TLegend(0.89, 0.89, 0.5, 0.7) + legend.AddEntry(sframe.findObject('Ds_sig'), 'Signal Ds sWeights', 'p') + legend.AddEntry(sframe.findObject('Dplus_sig'), 'Signal Dplus sWeights', 'p') + legend.AddEntry(sframe.findObject('bkg'), 'Background sWeights', 'p') + + c = r.TCanvas("sWeights {0}".format(0),"sWeights {0}".format(0),900,900) + c.Divide(2,2) + c.cd(1) + frame_Ds_sw.Draw() + c.cd(2) + frame_Dplus_sw.Draw() + c.cd(3) + frame_bkg_sw.Draw() + c.cd(4) + sframe.Draw() + legend.Draw() + + filename = "D(s)_phipi_"+l_flv[self.l_index]+l_flv[self.l_index]+"_sWeights.png" + c.SaveAs(self.PLOT_DIR+filename) + + + + +def return_names(data_index , mother_index, mis_id_bkg=False): + + if data_index==0: + names={} + names['m_name']=data_type[data_index]+"_"+mother_ID[mother_index]+"_m" + + names['mean_D_name']=data_type[data_index]+"_mean_"+mother_ID[mother_index] + names['sigma_D_name']=data_type[data_index]+"_sigma_"+mother_ID[mother_index] + + names['alpha_left_name']=data_type[data_index]+"_alpha_"+mother_ID[mother_index]+"_left" + names['n_left_name' ]=data_type[data_index]+"_n_"+mother_ID[mother_index]+"_left" + names['sig_pdf_left_name' ]=data_type[data_index]+"_pdf_"+mother_ID[mother_index]+"_left" + + names['alpha_right_name']=data_type[data_index]+"_alpha_"+mother_ID[mother_index]+"_right" + names['n_right_name'] =data_type[data_index]+"_n_"+mother_ID[mother_index]+"_right" + names['sig_pdf_right_name'] =data_type[data_index]+"_pdf_"+mother_ID[mother_index]+"_right" + + names['frac_lr_name']=data_type[data_index]+'_'+mother_ID[mother_index]+"_lr_fraction" + names['model_name']=data_type[data_index]+'_'+mother_ID[mother_index]+"_model" + names['data_set_name']=data_type[data_index]+'_'+mother_ID[mother_index]+'_ConsD_M' + + if mis_id_bkg==True: + + for key in names: + names[key]=names[key]+'_misID' + + if data_index==1: + names={} + names['m_name']=data_type[data_index]+"_"+mother_ID[mother_index]+"_m" + names['data_set_name']=data_type[data_index]+'_'+mother_ID[mother_index]+'_ConsD_M' + names['model_name']='fit_model' + + return names diff --git a/tools/kinematics_fix.py b/tools/kinematics_fix.py new file mode 100644 index 0000000..f1478ca --- /dev/null +++ b/tools/kinematics_fix.py @@ -0,0 +1,97 @@ +import os +import pickle +import numpy as np +import sys +import ROOT as r + +mother_ID=['Dplus','Ds'] +meson_ID =['pi','X'] +l_flv = ['e','mu'] +data_type = ['MC','data'] +mag_status =['Up','Down'] + +masses = { + 'Ds': 1.968, + 'Dplus':1.869, + 'pi':0.140, + 'mu_plus': 0.105, + 'mu_minus': 0.105, + 'e_plus': 0.0005, + 'e_minus': 0.0005, +} + +mother_index=None +l_index=None + + +def get_4_momenta(data, particle): + + p_x = np.array(data[particle+"_PX"])/1000 + p_y = np.array(data[particle+"_PY"])/1000 + p_z = np.array(data[particle+"_PZ"])/1000 + p_E = np.array(data[particle+"_PE"])/1000 + p_spatial = np.array([ p_x, p_y, p_z ]) + + p_E = p_E.reshape(1,p_x.shape[0]) + + p = np.concatenate((p_E, p_spatial),axis=0) + + return p, p_spatial + + +def get_TLorentzVector(p, i): + + p_r = r.TLorentzVector(p[:,i][1], p[:,i][2], p[:,i][3], p[:,i][0]) + return p_r + + +def get_costheta_list(data, l_index, mother_index): + + cos_theta_list=[] + + p_D_lab, _, = get_4_momenta(data, mother_ID[mother_index]) + p_l_plus_lab, _, = get_4_momenta(data, l_flv[l_index]+'_plus') + p_l_minus_lab, _, = get_4_momenta(data, l_flv[l_index]+'_minus') + p_pi_lab, _, = get_4_momenta(data, 'pi') + + for j in range(len(data[mother_ID[mother_index]+"_ConsD_M"])): + + p_D_lab_r = get_TLorentzVector(p_D_lab, j) + #p_pi_lab_r = get_TLorentzVector(p_pi_lab, j) + p_l_plus_lab_r = get_TLorentzVector(p_l_plus_lab, j) + p_l_minus_lab_r = get_TLorentzVector(p_l_minus_lab, j) + p_pi_lab_r = get_TLorentzVector(p_pi_lab, j) + q_lab_r = p_l_plus_lab_r+p_l_minus_lab_r + + + #Determine boost from lab to D + lab_to_D_boost_vector = -1.*p_D_lab_r.BoostVector() + + #Boosting everything from lab to B + p_D_lab_r.Boost(lab_to_D_boost_vector) + p_pi_lab_r.Boost(lab_to_D_boost_vector) + p_l_minus_lab_r.Boost(lab_to_D_boost_vector) + p_l_plus_lab_r.Boost(lab_to_D_boost_vector) + + q_lab_r.Boost(lab_to_D_boost_vector) + + #Determine boost from B to q + D_to_q_boost_vector = -1.*q_lab_r.BoostVector() + + #Boosting everything from D to q + p_D_lab_r.Boost(D_to_q_boost_vector) + p_pi_lab_r.Boost(D_to_q_boost_vector) + + p_l_minus_lab_r.Boost(D_to_q_boost_vector) + p_l_plus_lab_r.Boost(D_to_q_boost_vector) + + + vpi=p_pi_lab_r.Vect().Unit() + vlplus=p_l_plus_lab_r.Vect().Unit() + + cos_theta_pi = vpi.Dot(vlplus) + cos_theta_list.append(cos_theta_pi) + + cos_theta_list=np.array(cos_theta_list) + + return cos_theta_list diff --git a/tools/preselector.py b/tools/preselector.py new file mode 100644 index 0000000..9a4c1a5 --- /dev/null +++ b/tools/preselector.py @@ -0,0 +1,388 @@ +import os +import pickle +import numpy as np +import sys +from tools.data_processing import * + +mother_ID=['Dplus','Ds','both'] +l_flv = ['e','mu'] +data_type = ['MC','data'] +mag_status =['Up','Down'] +tree_name = 'Ds_OfflineTree/DecayTree' + +cmp_lt = lambda x,y: x < y +cmp_gt = lambda x,y: x > y +cmp_eq = lambda x,y: x == y +cmp_lte = lambda x,y: x <= y +cmp_gte = lambda x,y: x >= y +cmp_neq = lambda x,y: x != y + +log_or = lambda x,y: np.logical_or(x,y) +log_and = lambda x,y: np.logical_and(x,y) +log_and_not = lambda x,y: np.logical_and(x,np.invert(y)) + + +def namestr(obj, namespace): + return [name for name in namespace if namespace[name] is obj] + + +def filter_tuple_cond(namespace, tuple_full, l_index, + cat_name, comparator, threshold, wantEff=False, + include_costhetal=True): + + if "Ds" in namestr(tuple_full, namespace)[0]: + + mother_index=1 + + elif "Dplus" in namestr(tuple_full, namespace)[0]: + + mother_index=0 + + elif "data" in namestr(tuple_full, namespace)[0]: + + mother_index=1 + + if "MC" in namestr(tuple_full, namespace)[0]: + data_index=0 + else: + data_index=1 + + indices=np.where(comparator(tuple_full[cat_name],threshold))[0] + + tuple_filtered={} + + branches=return_branches(data_index=data_index, mother_index=mother_index, l_index=l_index) + if include_costhetal: + for label in branches: + tuple_filtered[label]=tuple_full[label][indices] + + else: + for label in branches: + if label!='cos_thetal': + tuple_filtered[label]=tuple_full[label][indices] + + bf_cut=np.float32(len(tuple_full[cat_name])) + af_cut=np.float32(len(tuple_filtered[cat_name])) + + eff = af_cut/bf_cut*100 + + if wantEff: + print('************************') + print(' \n Applying mass cut on '+cat_name+' on '+ namestr(tuple_full, namespace)[0] +'\n') + if data_index==0: print('{0:.4g}% of signal passed this cut'.format(eff)) + print('************************') + return tuple_filtered, eff + else: + return tuple_filtered + + + +def filter_tuple_mass_cut(namespace, tuple_full, l_index, + cat_name, lower_bound=None, upper_bound=None, + cut_kind=None, equal=False, wantEff=False, + include_costhetal=True): + + if "Ds" in namestr(tuple_full, namespace)[0]: + + mother_index=1 + + elif "Dplus" in namestr(tuple_full, namespace)[0]: + + mother_index=0 + + elif "data" in namestr(tuple_full, namespace)[0]: + + mother_index=1 + + if "MC" in namestr(tuple_full, namespace)[0]: + data_index=0 + else: + data_index=1 + + if lower_bound == None or upper_bound==None: + + if lower_bound == None or upper_bound!=None: + threshold=upper_bound + if equal: comparator = cmp_lte + else: comparator = cmp_lt + + elif upper_bound==None and lower_bound != None: + threshold=lower_bound + if equal: comparator = cmp_gte + else: comparator = cmp_gt + + indices=np.where(comparator(tuple_full[cat_name],threshold))[0] + + elif upper_bound!=None and lower_bound != None: + + assert cut_kind!=None, '\n Specify cut_kind, either inside or outside bounds' + + if cut_kind == 'inside': + if equal: + indices_1 = np.where(tuple_full[cat_name]<=upper_bound)[0] + indices_2 = np.where(tuple_full[cat_name]>=lower_bound)[0] + else: + indices_1 = np.where(tuple_full[cat_name]lower_bound)[0] + + indices = np.intersect1d(indices_1,indices_2) + + elif cut_kind == 'outside': + if equal: + indices_1 = np.where(tuple_full[cat_name]>=0)[0] + indices_2 = np.where(tuple_full[cat_name]<=lower_bound)[0] + indices_3 = np.where(tuple_full[cat_name]>=upper_bound)[0] + + indices_temp = np.intersect1d(indices_1,indices_2) + else: + indices_1 = np.where(tuple_full[cat_name]>0)[0] + indices_2 = np.where(tuple_full[cat_name]upper_bound)[0] + + indices_temp = np.intersect1d(indices_1,indices_2) + + indices = np.concatenate([indices_temp,indices_3]) + + tuple_filtered={} + + branches=return_branches(data_index=data_index, mother_index=mother_index, l_index=l_index) + if include_costhetal: + for label in branches: + tuple_filtered[label]=tuple_full[label][indices] + + else: + for label in branches: + if label!='cos_thetal': + tuple_filtered[label]=tuple_full[label][indices] + + bf_cut=np.float32(len(tuple_full[cat_name])) + af_cut=np.float32(len(tuple_filtered[cat_name])) + + eff = af_cut/bf_cut*100 + + if wantEff: + print('************************') + print(' \n Applying mass cut on '+cat_name+' on '+ namestr(tuple_full, namespace)[0] +'\n') + if data_index==0: print('{0:.4g}% of signal passed this cut'.format(eff)) + print('************************') + return tuple_filtered, eff + else: + return tuple_filtered + +def filter_tuple_L0TrigCat(namespace, tuple_full, l_index, + trig_cat, wantEff=False, + include_costhetal=True): + + if "Ds" in namestr(tuple_full, namespace)[0]: + + mother_index=1 + + elif "Dplus" in namestr(tuple_full, namespace)[0]: + + mother_index=0 + + elif "data" in namestr(tuple_full, namespace)[0]: + + mother_index=1 + + if "MC" in namestr(tuple_full, namespace)[0]: + data_index=0 + else: + data_index=1 + + if l_index ==0: + cat_name_TOS = mother_ID[mother_index]+'_L0ElectronDecision_TOS' + else: + cat_name_TOS = mother_ID[mother_index]+'_L0MuonDecision_TOS' + + cat_name_TIS = mother_ID[mother_index]+'_L0Global_TIS' + + indices_TOS=tuple_full[cat_name_TOS] + indices_TIS=tuple_full[cat_name_TIS] + + + if trig_cat == 0: + #Exclusive L0_Lepton_TOS + indices=log_and_not(indices_TOS,indices_TIS) + + if trig_cat == 1: + #Exclusive L0_Global_TIS + indices=log_and_not(indices_TIS,indices_TOS) + + if trig_cat == 2: + #L0_Lepton_TOS and L0_Global_TIS + indices=log_and(indices_TIS,indices_TOS) + + if trig_cat == 3: + #Either L0_Lepton_Tos or L0_Global_TIS + indices=log_or(indices_TIS,indices_TOS) + + if trig_cat == 4: + #TOS and TOSandTIS + indices_and=log_and(indices_TIS,indices_TOS) + indices=log_or(indices_TOS,indices_and) + + if trig_cat == 5: + #TIS and TOSandTIS + indices_and=log_and(indices_TIS,indices_TOS) + indices=log_or(indices_TIS,indices_and) + + tuple_filtered={} + + branches=return_branches(data_index=data_index, mother_index=mother_index, l_index=l_index) + if include_costhetal: + for label in branches: + tuple_filtered[label]=tuple_full[label][indices] + + else: + for label in branches: + if label!='cos_thetal': + tuple_filtered[label]=tuple_full[label][indices] + + bf_cut=np.float32(len(tuple_full[cat_name_TOS])) + af_cut=np.float32(len(tuple_filtered[cat_name_TOS])) + + eff = af_cut/bf_cut*100 + + if wantEff: + print('************************') + print(' \n Applying L0TrigCat '+str(trig_cat)+' cut on '+ namestr(tuple_full, namespace)[0] +'\n') + if data_index==0: print('{0:.4g}% of signal passed this cut'.format(eff)) + print('************************') + return tuple_filtered, eff + else: + return tuple_filtered + + +# def apply_BDT_selection(namespace, data_to_select, cut_threshold, BDTs_PATH): + +# if "Ds" in namestr(data_to_select, namespace)[0]: + +# mother_index=1 + +# elif "Dplus" in namestr(data_to_select, namespace)[0]: + +# mother_index=0 + +# elif "data" in namestr(data_to_select, namespace)[0]: + +# mother_index=1 + +# if "MC" in namestr(data_to_select, namespace)[0]: +# data_index=0 +# else: +# data_index=1 + + +# branches = data_to_select.keys() +# n_evts = data_to_select[data_to_select.keys()[0]].shape[0] + +# with open(BDTs_PATH+'variables_used.pickle') as f: + +# branches_BDT_Ds = pickle.load(f) + +# branches_BDT_Dplus=[] + +# for label in branches_BDT_Ds: +# if 'Ds' in label: +# branches_BDT_Dplus.append(label.replace("Ds", "Dplus")) +# else: +# branches_BDT_Dplus.append(label) + +# if mother_index == 0: branches_BDT = branches_BDT_Dplus +# elif mother_index == 1: branches_BDT = branches_BDT_Ds + +# data_BDT_input={} +# for label in branches_BDT: + +# data_BDT_input[label]=data_to_select[label] + +# fold = 0 + +# while os.path.exists(BDTs_PATH+'/XG_'+str(fold)): +# fold+=1 + +# k = np.random.randint(fold) + +# MODEL_PATH=BDTs_PATH+'/XG_'+str(k) +# loaded_model = pickle.load(open(MODEL_PATH+"/XG_"+str(k)+".pickle.dat", "rb")) + +# data_BDT_input_array=extract_array_for_BDT(data_BDT_input, branches_BDT, n_evts) + +# output_XG=loaded_model.predict_proba(data_BDT_input_array) +# bdt_selection_data= np.where(output_XG[:,1]>cut_threshold) + +# data_BDT_output={} + + +# for label in branches: +# data_BDT_output[label] = data_to_select[label][bdt_selection_data] + +# n_before= data_BDT_input[data_BDT_input.keys()[0]].shape[0] +# n_after= data_BDT_output[data_BDT_output.keys()[0]].shape[0] +# eff = np.float32(n_after)/np.float32(n_before) + +# return data_BDT_output, eff + + +def get_BDT_weights(namespace, data_to_select, BDTs_PATH): + + if "Ds" in namestr(data_to_select, namespace)[0]: + + mother_index=1 + + elif "Dplus" in namestr(data_to_select, namespace)[0]: + + mother_index=0 + + elif "data" in namestr(data_to_select, namespace)[0]: + + mother_index=1 + + if "MC" in namestr(data_to_select, namespace)[0]: + data_index=0 + else: + data_index=1 + + + branches = data_to_select.keys() + n_evts = data_to_select[data_to_select.keys()[0]].shape[0] + + with open(BDTs_PATH+'variables_used.pickle') as f: + + branches_BDT_Ds = pickle.load(f) + + branches_BDT_Dplus=[] + + for label in branches_BDT_Ds: + if 'Ds' in label: + branches_BDT_Dplus.append(label.replace("Ds", "Dplus")) + else: + branches_BDT_Dplus.append(label) + + if mother_index == 0: branches_BDT = branches_BDT_Dplus + elif mother_index == 1: branches_BDT = branches_BDT_Ds + + data_BDT_input={} + for label in branches_BDT: + + data_BDT_input[label]=data_to_select[label] + + fold = 0 + + while os.path.exists(BDTs_PATH+'/XG_'+str(fold)): + fold+=1 + + k = np.random.randint(fold) + + MODEL_PATH=BDTs_PATH+'/XG_'+str(k) + loaded_model = pickle.load(open(MODEL_PATH+"/XG_"+str(k)+".pickle.dat", "rb")) + + data_BDT_input_array=extract_array_for_BDT(data_BDT_input, branches_BDT, n_evts) + + output_XG=loaded_model.predict_proba(data_BDT_input_array) + + data_to_select['BDT_selection']=output_XG[:,1] + + + return data_to_select