Newer
Older
R_phipi / building_blocks / MC_fitter_unbinned.ipynb
@Davide Lancierini Davide Lancierini on 15 Nov 2018 17 KB big changes
{
 "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 architectures.data_processing import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "l_index=1\n",
    "l_flv=['e','mu']\n",
    "MC_Dplus_sig_dict, MC_Ds_sig_dict, _ = load_datasets(l_index)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "Dplus_M=np.array([MC_Dplus_sig_dict[\"Dplus_ConsD_M\"][i][0] for i in range(len(MC_Dplus_sig_dict[\"Dplus_ConsD_M\"]))])\n",
    "Ds_M=np.array([MC_Ds_sig_dict[\"Ds_ConsD_M\"][i][0] for i in range(len(MC_Ds_sig_dict[\"Ds_ConsD_M\"]))])\n",
    "\n",
    "data=np.concatenate((Dplus_M,Ds_M),axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#cut on mass\n",
    "cut_indices=[]\n",
    "\n",
    "lower_mass_cut=1930\n",
    "upper_mass_cut=2030\n",
    "\n",
    "for i in range(len(data)):\n",
    "    if lower_mass_cut<data[i]<upper_mass_cut:\n",
    "        cut_indices.append(i)\n",
    "        \n",
    "data_cut=data[cut_indices]/1000.  \n",
    "\n",
    "lower_mass_cut/=1000.\n",
    "upper_mass_cut/=1000."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA6gAAAJCCAYAAADN6ep4AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAHjJJREFUeJzt3X2sp3lZ3/HPVWYFQdoKO0sjs+1pSkOD62brDqi1RkkxbJ2mTboNW3U1KdgNRttqmpSBpEH+2GSaYDWkJLgWS2TJZlMebOzsFkiMoRtrN4Nu9oFFLGbKjhH2KJVQE7cre/WPc6OHdWfOmTkPv2t+5/VKJuf87odzrgk3c/Y93/t3T3V3AAAAYNX+wqoHAAAAgESgAgAAMIRABQAAYASBCgAAwAgCFQAAgBEEKgAAACMIVAAAAEYQqAAAAIwgUAEAABjh2KoHSJJrr722NzY2Vj0GAAAAB+CTn/zk73f38Z2OGxGoGxsbOXfu3KrHAAAA4ABU1f/ezXFu8QUAAGAEgQoAAMAIAhUAAIARBCoAAAAjCFQAAABGEKgAAACMIFABAAAYQaACAAAwgkAFAABgBIEKAADACAIVAACAEQQqAAAAIwhUAAAARhCoAAAAjCBQAQAAGEGgAgAAMIJABQAAYASBCgAAwAgCFQAAgBEEKgAAACMIVAAAAEYQqAAAAIwgUAEAABhBoAIAADDCsZ0OqKoXJHlgOfZFSc4m+ckkb0/yz5NsLoe+rbvvW855a5IfTvKVJP+6uz+6/6MDsCobp89ecv/5M6cOaRIAYJ3sGKhJnkry3d39R1V1TbZi9bXLvp/p7nduP7iqbk5ya5Ibk7wsyQNV9crufmof5wYAAGDN7HiLb2/5o+XlNUmel+TJS5xyKsm93f10d19I8liS1+x5UgAAANbart6DWlXPq6qHshWmv9rdjy67fqyqPl1VH6iqly7bTiR5YtvpF5Ztz/6ad1TVuao6t7m5+ezdAAAAHD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aqaiPJq5M88KxdJ5I8se31hWXbxbbDFbuC63A357KGBCqH4R1JXlZVn0ryliTnknRV/YMkT3b3J1c6HUfFc16H2fpz8NVJ3tnd35ytVax/u7IpOQou9mfi30jyk0n+epJvSvKiqrp9dWOyDqrqG5J8MMlPuDuEVdnLdegaPnoO7N9Bha9a/jD5ga++rqrfSfKZJP8oyT+squ9L8oIkf7Gq7u5u/0HGvrvEdfiiJL/b3f9z2fXBCFQO0CWuxdcn+bXu3ly2fzjJ301y9yrm5OpXVdck+VCSe7r7w89xyIUk1yf59eX1iWXbNcv2PGs7XLY9XIe7OZc1ZAWVA1dVf2l5P1WW1YDf7O4vdvdbu/tEd28k+adJfkWcclAucR0+keT3q+qVy6F/L8mnVzUn6+9i12KSzyb59qp6YVVVtq7Fz65wVK5iyzX03iSPd/dPX+Sw+5L84HL8tyZ5Zvkz8cEkN1TViSUQbkty/yGMzZrZy3W4y3NZQ1ZQ2bOquifJ9yS5tqouJHl7tv72Nd39nmw9le19VfXHSf5Xtp7QBvtqj9fhm5J8oKq++lCaHzzE0VkzV3otdveDVfXBbD0I5JkkDyV596H/BlgX35nkh5I8UlUPLdveluUZEMu1+KEkr11uN/9/Sf7Zsu+Pq+pHk3w0W4sZd3f3uUOen/Vwxdfhxc7t7vsOa3hWo7p71TMAAACAW3wBAACYQaACAAAwgkAFAABgBIEKAADACAIVAACAEQQqAAAAIwhUAAAARhCoAAAAjPD/AVft5Iud5AWUAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 1152x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data_array=np.array([data_cut[i] for i in range(len(data_cut))], dtype=[('D_sel_M', np.float32)])\n",
    "\n",
    "plt.hist(data_cut,range=(lower_mass_cut,upper_mass_cut),bins=100);\n",
    "fig=plt.gcf();\n",
    "\n",
    "fig.set_size_inches(16,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "rn.array2root(data_array,\n",
    "              filename='/disk/lhcb_data/davide/Rphipi/selected_data/'+l_flv[l_index]+l_flv[l_index]+'/sel_data_NN_'+l_flv[l_index]+l_flv[l_index]+'.root',\n",
    "              treename='D_M',\n",
    "              mode='recreate',\n",
    "             )\n",
    "f=r.TFile('/disk/lhcb_data/davide/Rphipi/selected_data/'+l_flv[l_index]+l_flv[l_index]+'/sel_data_NN_'+l_flv[l_index]+l_flv[l_index]+'.root')\n",
    "tree=f.Get(\"D_M\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "mass = np.array([0],dtype=np.float32)\n",
    "branch = tree.GetBranch(\"D_sel_M\")\n",
    "branch.SetAddress(mass)\n",
    "\n",
    "num_entries=tree.GetEntries()\n",
    "m = r.RooRealVar(\"m\",\"m\",lower_mass_cut,upper_mass_cut)\n",
    "l = r.RooArgSet(m)\n",
    "data_hist = r.RooDataSet(\"data histogram\", \"data\", l)\n",
    "\n",
    "\n",
    "for i in range(num_entries):\n",
    "    tree.GetEvent(i)\n",
    "    r.RooAbsRealLValue.__assign__(m, mass[0])\n",
    "    data_hist.add(l, 1.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Creating the signal PDF\n",
    "\n",
    "\n",
    "mean_dplus= r.RooRealVar(\"mean_D+\",\"mean_D+\",1.87,1.77,1.97)\n",
    "sigma_dplus = r.RooRealVar(\"sigma_D+\",\"sigma_D+\",0.020,0.,0.2)\n",
    "alpha_dplus = r.RooRealVar(\"alpha_D+\",\"alpha_D+\",0.020,-10.,10.)\n",
    "n_dplus = r.RooRealVar(\"n_D+\",\"n_D+\",0.020,-50.,50.)\n",
    "sig_dplus = r.RooCBShape(\"signal_D+\",\"signal_D+\", m, mean_dplus, sigma_dplus, alpha_dplus, n_dplus)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Creating the signal PDF\n",
    "\n",
    "mean_ds= r.RooRealVar(\"mean_Ds\",\"mean_Ds\",1.97,1.87,2.07)\n",
    "sigma_ds = r.RooRealVar(\"sigma_Ds\",\"sigma_Ds\",0.020,0.,0.2)\n",
    "alpha_ds = r.RooRealVar(\"alpha_Ds\",\"alpha_Ds\",0.020,-10.,10.)\n",
    "n_ds = r.RooRealVar(\"n_Ds\",\"n_Ds\",0.020,-50.,50.)\n",
    "sig_ds = r.RooCBShape(\"signal_Ds\",\"signal_Ds\", m, mean_ds, sigma_ds, alpha_ds, n_ds)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "#coef0 = r.RooRealVar(\"c0\",\"coefficient #0\",1.0,-1.,1)\n",
    "#coef1 = r.RooRealVar(\"c1\",\"coefficient #1\",0.1,-1.,1)\n",
    "#coef2 = r.RooRealVar(\"c2\",\"coefficient #2\",-0.1,-1.,1)\n",
    "#bkg = r.RooChebychev(\"bkg\",\"background p.d.f.\",m,r.RooArgList(coef0,coef1,coef2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Add 2 sources of signal\n",
    "\n",
    "# first add the sig and the peak together with fraction fpeak\n",
    "ns = r.RooRealVar(\"# of Ds sig events\",\"# of Ds sig events\",100.,0.,40000.)\n",
    "#nplus = r.RooRealVar(\"# of Dplus sig events\",\"# of Dplus sig events\",100.,0.,40000.)\n",
    "#nbkg = r.RooRealVar(\"# of bkg events\",\"# of bkg events\",100.,0.,40000.)\n",
    "# sigpeak(x) = fpeak*sig(x) + (1-fpeak)*bkg(x)\n",
    "model = r.RooAddPdf(\"model\",\"two mass peaks\",r.RooArgList(sig_ds),r.RooArgList(ns))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.fitTo(data_hist,r.RooFit.Extended())\n",
    "\n",
    "\n",
    "\n",
    "xframe = m.frame(r.RooFit.Title(\"Fit to \"+l_flv[l_index]+\" data\"))\n",
    "\n",
    "#bkg_component = r.RooArgSet(bkg)\n",
    "data_hist.plotOn(xframe)\n",
    "#model.plotOn(xframe,r.RooFit.Components(bkg_component),r.RooFit.LineStyle(2))\n",
    "model.plotOn(xframe)\n",
    "#sigpeaks.plotOn(xframe)\n",
    "xframe.Draw()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "#NB=nbkg.getVal()\n",
    "NS=ns.getVal()\n",
    "Nplus=nplus.getVal()\n",
    "\n",
    "if l_index==0:\n",
    "    Nsig_from_MC=1466+1974\n",
    "if l_index==1:\n",
    "    Nsig_from_MC=5881+9639\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15520.023435679977"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "NS+Nplus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15520"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Nsig_from_MC"
   ]
  },
  {
   "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
}