Newer
Older
Rphipi_new / 4b_fit_MC.ipynb
@Davide Lancierini Davide Lancierini on 28 May 2019 4 KB first commit
{
 "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
}