Newer
Older
Master_thesis / raremodel-nb.ipynb
@Sascha Liechti Sascha Liechti on 9 Jul 2019 111 KB ...
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Import"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\util\\execution.py:57: UserWarning: Not running on Linux. Determining available cpus for thread can failand be overestimated. Workaround (only if too many cpus are used):`zfit.run.set_n_cpu(your_cpu_number)`\n",
      "  warnings.warn(\"Not running on Linux. Determining available cpus for thread can fail\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.\n",
      "For more information, please see:\n",
      "  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md\n",
      "  * https://github.com/tensorflow/addons\n",
      "If you depend on functionality not listed there, please file an issue.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "# os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"-1\"\n",
    "\n",
    "import numpy as np\n",
    "from pdg_const import pdg\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "import pickle as pkl\n",
    "import sys\n",
    "import time\n",
    "from helperfunctions import display_time, prepare_plot\n",
    "import cmath as c\n",
    "import scipy.integrate as integrate\n",
    "from scipy.optimize import fminbound\n",
    "from array import array as arr\n",
    "import collections\n",
    "from itertools import compress\n",
    "import tensorflow as tf\n",
    "import zfit\n",
    "from zfit import ztf\n",
    "# from IPython.display import clear_output\n",
    "import os\n",
    "import tensorflow_probability as tfp\n",
    "tfd = tfp.distributions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# chunksize = 10000\n",
    "# zfit.run.chunking.active = True\n",
    "# zfit.run.chunking.max_n_points = chunksize"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Build model and graphs\n",
    "## Create graphs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def formfactor( q2, subscript): #returns real value\n",
    "    #check if subscript is viable\n",
    "\n",
    "    if subscript != \"0\" and subscript != \"+\" and subscript != \"T\":\n",
    "        raise ValueError('Wrong subscript entered, choose either 0, + or T')\n",
    "\n",
    "    #get constants\n",
    "\n",
    "    mK = ztf.constant(pdg['Ks_M'])\n",
    "    mbstar0 = ztf.constant(pdg[\"mbstar0\"])\n",
    "    mbstar = ztf.constant(pdg[\"mbstar\"])\n",
    "    b0 = ztf.constant(pdg[\"b0\"])\n",
    "    bplus = ztf.constant(pdg[\"bplus\"])\n",
    "    bT = ztf.constant(pdg[\"bT\"])\n",
    "\n",
    "    mmu = ztf.constant(pdg['muon_M'])\n",
    "    mb = ztf.constant(pdg['bquark_M'])\n",
    "    ms = ztf.constant(pdg['squark_M'])\n",
    "    mB = ztf.constant(pdg['Bplus_M'])\n",
    "\n",
    "    #N comes from derivation in paper\n",
    "\n",
    "    N = 3\n",
    "\n",
    "    #some helperfunctions\n",
    "\n",
    "    tpos = (mB - mK)**2\n",
    "    tzero = (mB + mK)*(ztf.sqrt(mB)-ztf.sqrt(mK))**2\n",
    "\n",
    "    z_oben = ztf.sqrt(tpos - q2) - ztf.sqrt(tpos - tzero)\n",
    "    z_unten = ztf.sqrt(tpos - q2) + ztf.sqrt(tpos - tzero)\n",
    "    z = tf.divide(z_oben, z_unten)\n",
    "\n",
    "    #calculate f0\n",
    "\n",
    "    if subscript == \"0\":\n",
    "        prefactor = 1/(1 - q2/(mbstar0**2))\n",
    "        _sum = 0\n",
    "\n",
    "        for i in range(N):\n",
    "            _sum += b0[i]*(tf.pow(z,i))\n",
    "\n",
    "        return tf.complex(prefactor * _sum, ztf.constant(0.0))\n",
    "\n",
    "    #calculate f+ or fT\n",
    "\n",
    "    else:\n",
    "        prefactor = 1/(1 - q2/(mbstar**2))\n",
    "        _sum = 0\n",
    "\n",
    "        if subscript == \"T\":\n",
    "            b = bT\n",
    "        else:\n",
    "            b = bplus\n",
    "\n",
    "        for i in range(N):\n",
    "            _sum += b[i] * (tf.pow(z, i) - ((-1)**(i-N)) * (i/N) * tf.pow(z, N))\n",
    "\n",
    "        return tf.complex(prefactor * _sum, ztf.constant(0.0))\n",
    "\n",
    "def resonance(q, _mass, width, phase, scale):\n",
    "\n",
    "    q2 = tf.pow(q, 2)\n",
    "\n",
    "    mmu = ztf.constant(pdg['muon_M'])\n",
    "\n",
    "    p = 0.5 * ztf.sqrt(q2 - 4*(mmu**2))\n",
    "\n",
    "    p0 =  0.5 * ztf.sqrt(_mass**2 - 4*mmu**2)\n",
    "\n",
    "    gamma_j = tf.divide(p, q) * _mass * width / p0\n",
    "\n",
    "    #Calculate the resonance\n",
    "\n",
    "    _top = tf.complex(_mass * width, ztf.constant(0.0))\n",
    "\n",
    "    _bottom = tf.complex(_mass**2 - q2, -_mass*gamma_j)\n",
    "\n",
    "    com = _top/_bottom\n",
    "\n",
    "    #Rotate by the phase\n",
    "\n",
    "    r = ztf.to_complex(scale*tf.abs(com))\n",
    "\n",
    "    _phase = tf.angle(com)\n",
    "\n",
    "    _phase += phase\n",
    "\n",
    "    com = r * tf.exp(tf.complex(ztf.constant(0.0), _phase))\n",
    "\n",
    "    return com\n",
    "\n",
    "def bifur_gauss(q, mean, sigma_L, sigma_R, scale):\n",
    "\n",
    "    _exp = tf.where(q < mean, ztf.exp(- tf.pow((q-mean),2) / (2 * sigma_L**2)), ztf.exp(- tf.pow((q-mean),2) / (2 * sigma_R**2)))\n",
    "\n",
    "    #Scale so the total area under curve is 1 and the top of the cusp is continuous\n",
    "\n",
    "    dgamma = scale*_exp/(ztf.sqrt(2*np.pi))*2*(sigma_L*sigma_R)/(sigma_L+sigma_R)\n",
    "\n",
    "    com = ztf.complex(dgamma, ztf.constant(0.0))\n",
    "\n",
    "    return com\n",
    "\n",
    "def axiv_nonres(q):\n",
    "\n",
    "    GF = ztf.constant(pdg['GF'])\n",
    "    alpha_ew = ztf.constant(pdg['alpha_ew'])\n",
    "    Vtb = ztf.constant(pdg['Vtb'])\n",
    "    Vts = ztf.constant(pdg['Vts'])\n",
    "    C10eff = ztf.constant(pdg['C10eff'])\n",
    "\n",
    "    mmu = ztf.constant(pdg['muon_M'])\n",
    "    mb = ztf.constant(pdg['bquark_M'])\n",
    "    ms = ztf.constant(pdg['squark_M'])\n",
    "    mK = ztf.constant(pdg['Ks_M'])\n",
    "    mB = ztf.constant(pdg['Bplus_M'])\n",
    "\n",
    "    q2 = tf.pow(q, 2)\n",
    "\n",
    "    #Some helperfunctions\n",
    "\n",
    "    beta = ztf.sqrt(tf.abs(1. - 4. * mmu**2. / q2))\n",
    "\n",
    "    kabs = ztf.sqrt(mB**2. +tf.pow(q2, 2)/mB**2. + mK**4./mB**2. - 2. * (mB**2. * mK**2. + mK**2. * q2 + mB**2. * q2) / mB**2.)\n",
    "\n",
    "    #prefactor in front of whole bracket\n",
    "\n",
    "    prefactor1 = GF**2. *alpha_ew**2. * (tf.abs(Vtb*Vts))**2. * kabs * beta / (128. * np.pi**5.)\n",
    "\n",
    "    #left term in bracket\n",
    "\n",
    "    bracket_left = 2./3. * kabs**2. * beta**2. *tf.abs(tf.complex(C10eff, ztf.constant(0.0))*formfactor(q2, \"+\"))**2.\n",
    "\n",
    "    #middle term in bracket\n",
    "\n",
    "    _top = 4. * mmu**2. * (mB**2. - mK**2.) * (mB**2. - mK**2.)\n",
    "\n",
    "    _under = q2 * mB**2.\n",
    "\n",
    "    bracket_middle = _top/_under *tf.pow(tf.abs(tf.complex(C10eff, ztf.constant(0.0)) * formfactor(q2, \"0\")), 2)\n",
    "\n",
    "    #Note sqrt(q2) comes from derivation as we use q2 and plot q\n",
    "\n",
    "    return prefactor1 * (bracket_left + bracket_middle) * 2 *ztf.sqrt(q2)\n",
    "\n",
    "def vec(q, funcs):\n",
    "    \n",
    "    q2 = tf.pow(q, 2)\n",
    "\n",
    "    GF = ztf.constant(pdg['GF'])\n",
    "    alpha_ew = ztf.constant(pdg['alpha_ew'])\n",
    "    Vtb = ztf.constant(pdg['Vtb'])\n",
    "    Vts = ztf.constant(pdg['Vts'])\n",
    "    C7eff = ztf.constant(pdg['C7eff'])\n",
    "\n",
    "    mmu = ztf.constant(pdg['muon_M'])\n",
    "    mb = ztf.constant(pdg['bquark_M'])\n",
    "    ms = ztf.constant(pdg['squark_M'])\n",
    "    mK = ztf.constant(pdg['Ks_M'])\n",
    "    mB = ztf.constant(pdg['Bplus_M'])\n",
    "\n",
    "    #Some helperfunctions\n",
    "\n",
    "    beta = ztf.sqrt(tf.abs(1. - 4. * mmu**2. / q2))\n",
    "\n",
    "    kabs = ztf.sqrt(mB**2. + tf.pow(q2, 2)/mB**2. + mK**4./mB**2. - 2 * (mB**2 * mK**2 + mK**2 * q2 + mB**2 * q2) / mB**2)\n",
    "\n",
    "    #prefactor in front of whole bracket\n",
    "\n",
    "    prefactor1 = GF**2. *alpha_ew**2. * (tf.abs(Vtb*Vts))**2 * kabs * beta / (128. * np.pi**5.)\n",
    "\n",
    "    #right term in bracket\n",
    "\n",
    "    prefactor2 = kabs**2 * (1. - 1./3. * beta**2)\n",
    "\n",
    "    abs_bracket = tf.abs(c9eff(q, funcs) * formfactor(q2, \"+\") + tf.complex(2.0 * C7eff * (mb + ms)/(mB + mK), ztf.constant(0.0)) * formfactor(q2, \"T\"))**2\n",
    "\n",
    "    bracket_right = prefactor2 * abs_bracket\n",
    "\n",
    "    #Note sqrt(q2) comes from derivation as we use q2 and plot q\n",
    "\n",
    "    return prefactor1 * bracket_right * 2 * ztf.sqrt(q2)\n",
    "\n",
    "def c9eff(q, funcs):\n",
    "\n",
    "    C9eff_nr = tf.complex(ztf.constant(pdg['C9eff']), ztf.constant(0.0))\n",
    "\n",
    "    c9 = C9eff_nr\n",
    "\n",
    "    c9 = c9 + funcs\n",
    "\n",
    "    return c9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def G(y):\n",
    "    \n",
    "    def inner_rect_bracket(q):\n",
    "        return tf.log(ztf.to_complex((1+tf.sqrt(q))/(1-tf.sqrt(q)))-tf.complex(ztf.constant(0), -1*ztf.constant(np.pi)))    \n",
    "    \n",
    "    def inner_right(q):\n",
    "        return ztf.to_complex(2 * tf.atan(1/tf.sqrt(tf.math.real(-q))))\n",
    "    \n",
    "    big_bracket = tf.where(tf.math.real(y) > ztf.constant(0.0), inner_rect_bracket(y), inner_right(y))\n",
    "    \n",
    "    return ztf.to_complex(tf.sqrt(tf.abs(y))) * big_bracket\n",
    "\n",
    "def h_S(m, q):\n",
    "    \n",
    "    return ztf.to_complex(2) - G(ztf.to_complex(1) - ztf.to_complex(4*tf.pow(m, 2)) / ztf.to_complex(tf.pow(q, 2)))\n",
    "\n",
    "def h_P(m, q):\n",
    "    \n",
    "    return ztf.to_complex(2/3) + (ztf.to_complex(1) - ztf.to_complex(4*tf.pow(m, 2)) / ztf.to_complex(tf.pow(q, 2))) * h_S(m,q)\n",
    "\n",
    "def two_p_ccbar(mD, m_D_bar, m_D_star, q):\n",
    "    \n",
    "    \n",
    "    #Load constants\n",
    "    nu_D_bar = ztf.to_complex(pdg[\"nu_D_bar\"])\n",
    "    nu_D = ztf.to_complex(pdg[\"nu_D\"])\n",
    "    nu_D_star = ztf.to_complex(pdg[\"nu_D_star\"])\n",
    "    \n",
    "    phase_D_bar = ztf.to_complex(pdg[\"phase_D_bar\"])\n",
    "    phase_D = ztf.to_complex(pdg[\"phase_D\"])\n",
    "    phase_D_star = ztf.to_complex(pdg[\"phase_D_star\"])\n",
    "    \n",
    "    #Calculation\n",
    "    left_part =  nu_D_bar * tf.exp(tf.complex(ztf.constant(0.0), phase_D_bar)) * h_S(m_D_bar, q) \n",
    "    \n",
    "    right_part_D = nu_D * tf.exp(tf.complex(ztf.constant(0.0), phase_D)) * h_P(m_D, q) \n",
    "    \n",
    "    right_part_D_star = nu_D_star * tf.exp(tf.complex(ztf.constant(0.0), phase_D_star)) * h_P(m_D_star, q) \n",
    "\n",
    "    return left_part + right_part_D + right_part_D_star"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## C_q,qbar constraint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# r = rho_scale * rho_width/rho_mass * np.cos(rho_phase)*(1-np.tan(rho_phase)*rho_width/rho_mass)\n",
    "# o = omega_scale*np.cos(omega_phase)*omega_width/omega_mass\n",
    "# p = phi_scale*np.cos(phi_phase)*phi_width/phi_mass\n",
    "\n",
    "# # phi_s = np.linspace(-500, 5000, 100000)\n",
    "\n",
    "# # p_ = phi_s*np.cos(phi_phase)*phi_width/phi_mass\n",
    "\n",
    "# # p_y = r+o+p_\n",
    "\n",
    "# # plt.plot(phi_s, p_y)\n",
    "\n",
    "# print(r + o + p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Build pdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "class total_pdf(zfit.pdf.ZPDF):\n",
    "    _N_OBS = 1  # dimension, can be omitted\n",
    "    _PARAMS = ['rho_mass', 'rho_scale', 'rho_phase', 'rho_width',\n",
    "               'jpsi_mass', 'jpsi_scale', 'jpsi_phase', 'jpsi_width',\n",
    "               'psi2s_mass', 'psi2s_scale', 'psi2s_phase', 'psi2s_width',\n",
    "               'p3770_mass', 'p3770_scale', 'p3770_phase', 'p3770_width',\n",
    "               'p4040_mass', 'p4040_scale', 'p4040_phase', 'p4040_width',\n",
    "               'p4160_mass', 'p4160_scale', 'p4160_phase', 'p4160_width',\n",
    "               'p4415_mass', 'p4415_scale', 'p4415_phase', 'p4415_width',\n",
    "               'omega_mass', 'omega_scale', 'omega_phase', 'omega_width',\n",
    "               'phi_mass', 'phi_scale', 'phi_phase', 'phi_width',\n",
    "               'Dbar_mass', 'Dbar_scale', 'Dbar_phase',\n",
    "               'DDstar_mass', 'DDstar_scale', 'DDstar_phase',\n",
    "               'tau_mass', 'C_tt']\n",
    "# the name of the parameters\n",
    "\n",
    "    def _unnormalized_pdf(self, x):\n",
    "        \n",
    "        x = x.unstack_x()\n",
    "        \n",
    "        def rho_res(q):\n",
    "            return resonance(q, _mass = self.params['rho_mass'], scale = self.params['rho_scale'],\n",
    "                             phase = self.params['rho_phase'], width = self.params['rho_width'])\n",
    "    \n",
    "        def omega_res(q):\n",
    "            return resonance(q, _mass = self.params['omega_mass'], scale = self.params['omega_scale'],\n",
    "                             phase = self.params['omega_phase'], width = self.params['omega_width'])\n",
    "        \n",
    "        def phi_res(q):\n",
    "            return resonance(q, _mass = self.params['phi_mass'], scale = self.params['phi_scale'],\n",
    "                             phase = self.params['phi_phase'], width = self.params['phi_width'])\n",
    "\n",
    "        def jpsi_res(q):\n",
    "            return resonance(q, _mass = self.params['jpsi_mass'], scale = self.params['jpsi_scale'],\n",
    "                             phase = self.params['jpsi_phase'], width = self.params['jpsi_width'])\n",
    "\n",
    "        def psi2s_res(q):\n",
    "            return resonance(q, _mass = self.params['psi2s_mass'], scale = self.params['psi2s_scale'],\n",
    "                             phase = self.params['psi2s_phase'], width = self.params['psi2s_width'])\n",
    "        \n",
    "        def p3770_res(q):\n",
    "            return resonance(q, _mass = self.params['p3770_mass'], scale = self.params['p3770_scale'],\n",
    "                             phase = self.params['p3770_phase'], width = self.params['p3770_width'])\n",
    "        \n",
    "        def p4040_res(q):\n",
    "            return resonance(q, _mass = self.params['p4040_mass'], scale = self.params['p4040_scale'],\n",
    "                             phase = self.params['p4040_phase'], width = self.params['p4040_width'])\n",
    "        \n",
    "        def p4160_res(q):\n",
    "            return resonance(q, _mass = self.params['p4160_mass'], scale = self.params['p4160_scale'],\n",
    "                             phase = self.params['p4160_phase'], width = self.params['p4160_width'])\n",
    "        \n",
    "        def p4415_res(q):\n",
    "            return resonance(q, _mass = self.params['p4415_mass'], scale = self.params['p4415_scale'],\n",
    "                             phase = self.params['p4415_phase'], width = self.params['p4415_width'])\n",
    "        \n",
    "        def P2_D(q):\n",
    "            Dbar_contrib = ztf.to_complex(self.params['Dbar_scale'])*tf.exp(tf.complex(ztf.constant(0.0), self.params['Dbar_phase']))*ztf.to_complex(h_S(self.params['Dbar_mass'], q))\n",
    "            DDstar_contrib = ztf.to_complex(self.params['DDstar_scale'])*tf.exp(tf.complex(ztf.constant(0.0), self.params['DDstar_phase']))*ztf.to_complex(h_P(self.params['DDstar_mass'], q))\n",
    "            return Dbar_contrib + DDstar_contrib\n",
    "        \n",
    "        def ttau_cusp(q):\n",
    "            return ztf.to_complex(self.params['C_tt'])*(ztf.to_complex((h_S(self.params['tau_mass'], q))) - ztf.to_complex(h_P(self.params['tau_mass'], q)))\n",
    "        \n",
    "\n",
    "        funcs = rho_res(x) + omega_res(x) + phi_res(x) + jpsi_res(x) + psi2s_res(x) + p3770_res(x) + p4040_res(x)+ p4160_res(x) + p4415_res(x) + P2_D(x) + ttau_cusp(x)\n",
    "\n",
    "        vec_f = vec(x, funcs)\n",
    "\n",
    "        axiv_nr = axiv_nonres(x)\n",
    "\n",
    "        tot = vec_f + axiv_nr\n",
    "\n",
    "        return tot"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_min = 2*pdg['muon_M']\n",
    "x_max = (pdg[\"Bplus_M\"]-pdg[\"Ks_M\"]-0.1)\n",
    "\n",
    "obs = zfit.Space('q', limits = (x_min, x_max))\n",
    "\n",
    "# with open(r\"./data/slim_points/slim_points_toy_0_range({0}-{1}).pkl\".format(int(x_min), int(x_max)), \"rb\") as input_file:\n",
    "#     part_set = pkl.load(input_file)\n",
    "\n",
    "# x_part = part_set['x_part']\n",
    "\n",
    "# x_part = x_part.astype('float64')\n",
    "\n",
    "# data = zfit.data.Data.from_numpy(array=x_part, obs=obs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setup parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\ops\\resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n"
     ]
    }
   ],
   "source": [
    "#rho\n",
    "\n",
    "rho_mass, rho_width, rho_phase, rho_scale = pdg[\"rho\"]\n",
    "\n",
    "rho_m = zfit.Parameter(\"rho_m\", ztf.constant(rho_mass), floating = False) #lower_limit = rho_mass - rho_width,\n",
    "#                        upper_limit = rho_mass + rho_width)\n",
    "rho_w = zfit.Parameter(\"rho_w\", ztf.constant(rho_width), floating = False)\n",
    "rho_p = zfit.Parameter(\"rho_p\", ztf.constant(rho_phase), floating = False) #, lower_limit=-2*np.pi, upper_limit=2*np.pi)\n",
    "rho_s = zfit.Parameter(\"rho_s\", ztf.constant(rho_scale), floating = False) #, lower_limit=rho_scale-np.sqrt(rho_scale), upper_limit=rho_scale+np.sqrt(rho_scale))\n",
    "\n",
    "#omega\n",
    "\n",
    "omega_mass, omega_width, omega_phase, omega_scale = pdg[\"omega\"]\n",
    "\n",
    "omega_m = zfit.Parameter(\"omega_m\", ztf.constant(omega_mass), floating = False)\n",
    "omega_w = zfit.Parameter(\"omega_w\", ztf.constant(omega_width), floating = False)\n",
    "omega_p = zfit.Parameter(\"omega_p\", ztf.constant(omega_phase), floating = False) #, lower_limit=-2*np.pi, upper_limit=2*np.pi)\n",
    "omega_s = zfit.Parameter(\"omega_s\", ztf.constant(omega_scale), floating = False) #, lower_limit=omega_scale-np.sqrt(omega_scale), upper_limit=omega_scale+np.sqrt(omega_scale))\n",
    "\n",
    "\n",
    "#phi\n",
    "\n",
    "phi_mass, phi_width, phi_phase, phi_scale = pdg[\"phi\"]\n",
    "\n",
    "phi_m = zfit.Parameter(\"phi_m\", ztf.constant(phi_mass), floating = False)\n",
    "phi_w = zfit.Parameter(\"phi_w\", ztf.constant(phi_width), floating = False)\n",
    "phi_p = zfit.Parameter(\"phi_p\", ztf.constant(phi_phase), floating = False) #, lower_limit=-2*np.pi, upper_limit=2*np.pi)\n",
    "phi_s = zfit.Parameter(\"phi_s\", ztf.constant(phi_scale), floating = False) #, lower_limit=phi_scale-np.sqrt(phi_scale), upper_limit=phi_scale+np.sqrt(phi_scale))\n",
    "\n",
    "#jpsi\n",
    "\n",
    "jpsi_mass, jpsi_width, jpsi_phase, jpsi_scale = pdg[\"jpsi\"]\n",
    "# jpsi_scale *= pdg[\"factor_jpsi\"]\n",
    "\n",
    "jpsi_m = zfit.Parameter(\"jpsi_m\", ztf.constant(jpsi_mass), floating = False)\n",
    "jpsi_w = zfit.Parameter(\"jpsi_w\", ztf.constant(jpsi_width), floating = False)\n",
    "jpsi_p = zfit.Parameter(\"jpsi_p\", ztf.constant(jpsi_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi)\n",
    "jpsi_s = zfit.Parameter(\"jpsi_s\", ztf.constant(jpsi_scale), lower_limit=jpsi_scale-np.sqrt(jpsi_scale), upper_limit=jpsi_scale+np.sqrt(jpsi_scale))\n",
    "\n",
    "#psi2s\n",
    "\n",
    "psi2s_mass, psi2s_width, psi2s_phase, psi2s_scale = pdg[\"psi2s\"]\n",
    "\n",
    "psi2s_m = zfit.Parameter(\"psi2s_m\", ztf.constant(psi2s_mass), floating = False)\n",
    "psi2s_w = zfit.Parameter(\"psi2s_w\", ztf.constant(psi2s_width), floating = False)\n",
    "psi2s_p = zfit.Parameter(\"psi2s_p\", ztf.constant(psi2s_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi)\n",
    "psi2s_s = zfit.Parameter(\"psi2s_s\", ztf.constant(psi2s_scale), lower_limit=psi2s_scale-np.sqrt(psi2s_scale), upper_limit=psi2s_scale+np.sqrt(psi2s_scale))\n",
    "\n",
    "#psi(3770)\n",
    "\n",
    "p3770_mass, p3770_width, p3770_phase, p3770_scale = pdg[\"p3770\"]\n",
    "\n",
    "p3770_m = zfit.Parameter(\"p3770_m\", ztf.constant(p3770_mass), floating = False)\n",
    "p3770_w = zfit.Parameter(\"p3770_w\", ztf.constant(p3770_width), floating = False)\n",
    "p3770_p = zfit.Parameter(\"p3770_p\", ztf.constant(p3770_phase), floating = False) #, lower_limit=-2*np.pi, upper_limit=2*np.pi)\n",
    "p3770_s = zfit.Parameter(\"p3770_s\", ztf.constant(p3770_scale), floating = False) #, lower_limit=p3770_scale-np.sqrt(p3770_scale), upper_limit=p3770_scale+np.sqrt(p3770_scale))\n",
    "\n",
    "#psi(4040)\n",
    "\n",
    "p4040_mass, p4040_width, p4040_phase, p4040_scale = pdg[\"p4040\"]\n",
    "\n",
    "p4040_m = zfit.Parameter(\"p4040_m\", ztf.constant(p4040_mass), floating = False)\n",
    "p4040_w = zfit.Parameter(\"p4040_w\", ztf.constant(p4040_width), floating = False)\n",
    "p4040_p = zfit.Parameter(\"p4040_p\", ztf.constant(p4040_phase), floating = False) #, lower_limit=-2*np.pi, upper_limit=2*np.pi)\n",
    "p4040_s = zfit.Parameter(\"p4040_s\", ztf.constant(p4040_scale), floating = False) #, lower_limit=p4040_scale-np.sqrt(p4040_scale), upper_limit=p4040_scale+np.sqrt(p4040_scale))\n",
    "\n",
    "#psi(4160)\n",
    "\n",
    "p4160_mass, p4160_width, p4160_phase, p4160_scale = pdg[\"p4160\"]\n",
    "\n",
    "p4160_m = zfit.Parameter(\"p4160_m\", ztf.constant(p4160_mass), floating = False)\n",
    "p4160_w = zfit.Parameter(\"p4160_w\", ztf.constant(p4160_width), floating = False)\n",
    "p4160_p = zfit.Parameter(\"p4160_p\", ztf.constant(p4160_phase), floating = False) #, lower_limit=-2*np.pi, upper_limit=2*np.pi)\n",
    "p4160_s = zfit.Parameter(\"p4160_s\", ztf.constant(p4160_scale), floating = False) #, lower_limit=p4160_scale-np.sqrt(p4160_scale), upper_limit=p4160_scale+np.sqrt(p4160_scale))\n",
    "\n",
    "#psi(4415)\n",
    "\n",
    "p4415_mass, p4415_width, p4415_phase, p4415_scale = pdg[\"p4415\"]\n",
    "\n",
    "p4415_m = zfit.Parameter(\"p4415_m\", ztf.constant(p4415_mass), floating = False)\n",
    "p4415_w = zfit.Parameter(\"p4415_w\", ztf.constant(p4415_width), floating = False)\n",
    "p4415_p = zfit.Parameter(\"p4415_p\", ztf.constant(p4415_phase), floating = False) #, lower_limit=-2*np.pi, upper_limit=2*np.pi)\n",
    "p4415_s = zfit.Parameter(\"p4415_s\", ztf.constant(p4415_scale), floating = False) #, lower_limit=p4415_scale-np.sqrt(p4415_scale), upper_limit=p4415_scale+np.sqrt(p4415_scale))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Dynamic generation of 2 particle contribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<zfit.util.temporary.TemporarilySet at 0x1795ef3a2e8>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "_0 = jpsi_scale*np.cos(jpsi_phase)*jpsi_width/jpsi_mass**3 + psi2s_scale*np.cos(psi2s_phase)*psi2s_width/psi2s_mass**3\n",
    "_1 = p3770_scale*np.cos(p3770_phase)*p3770_width/p3770_mass**3 + p4040_scale*np.cos(p4040_phase)*p4040_width/p4040_mass**3\n",
    "_2 = p4160_scale*np.cos(p4160_phase)*p4160_width/p4160_mass**3 + p4415_scale*np.cos(p4415_phase)*p4415_width/p4415_mass**3\n",
    "\n",
    "C_pert = np.random.uniform(0.03, 0.1)\n",
    "# c_pert = 0.1\n",
    "m_c = 1300\n",
    "\n",
    "cDDstar_phase = 10\n",
    "\n",
    "\n",
    "DDstar_eta = 0\n",
    "Dbar_phase = np.random.uniform(0.0, 2*np.pi)\n",
    "DDstar_phase = np.random.uniform(0.0, 2*np.pi)\n",
    "DDstar_mass = pdg['D0_M']\n",
    "\n",
    "if Dbar_phase < np.pi:\n",
    "    Dbar_phase = 0.0\n",
    "else:\n",
    "    Dbar_phase = np.pi\n",
    "\n",
    "R = (C_pert/(m_c**2) - ((_0 + _1 + _2)))\n",
    "\n",
    "Dbar_mass = (pdg['D0_M']+pdg['Dst_M'])/2\n",
    "\n",
    "Dbar_eta = R/np.cos(Dbar_phase)*(6*Dbar_mass**2)\n",
    "\n",
    "# print(np.cos(Dbar_phase))\n",
    "\n",
    "# cDDstar_phase = R_*10*DDstar_mass**2/DDstar_eta\n",
    "\n",
    "\n",
    "# print(Dbar_eta)\n",
    "\n",
    "\n",
    "Dbar_s = zfit.Parameter(\"Dbar_s\", ztf.constant(Dbar_eta), lower_limit=-1.464, upper_limit=1.464)\n",
    "Dbar_m = zfit.Parameter(\"Dbar_m\", ztf.constant(Dbar_mass), floating = False)\n",
    "Dbar_p = zfit.Parameter(\"Dbar_p\", ztf.constant(Dbar_phase), floating = False)\n",
    "DDstar_s = zfit.Parameter(\"DDstar_s\", ztf.constant(DDstar_eta), floating = False)\n",
    "DDstar_m = zfit.Parameter(\"DDstar_m\", ztf.constant(DDstar_mass), floating = False)\n",
    "DDstar_p = zfit.Parameter(\"DDstar_p\", ztf.constant(DDstar_phase), floating = False)\n",
    "\n",
    "Dbar_s.set_value(0.0)\n",
    "DDstar_s.set_value(0.0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Tau parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "tau_m = zfit.Parameter(\"tau_m\", ztf.constant(pdg['tau_M']), floating = False)\n",
    "Ctt = zfit.Parameter(\"Ctt\", ztf.constant(0.0), lower_limit=-0.5, upper_limit=0.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setup pdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "total_f = total_pdf(obs=obs, jpsi_mass = jpsi_m, jpsi_scale = jpsi_s, jpsi_phase = jpsi_p, jpsi_width = jpsi_w,\n",
    "                    psi2s_mass = psi2s_m, psi2s_scale = psi2s_s, psi2s_phase = psi2s_p, psi2s_width = psi2s_w,\n",
    "                    p3770_mass = p3770_m, p3770_scale = p3770_s, p3770_phase = p3770_p, p3770_width = p3770_w,\n",
    "                    p4040_mass = p4040_m, p4040_scale = p4040_s, p4040_phase = p4040_p, p4040_width = p4040_w,\n",
    "                    p4160_mass = p4160_m, p4160_scale = p4160_s, p4160_phase = p4160_p, p4160_width = p4160_w,\n",
    "                    p4415_mass = p4415_m, p4415_scale = p4415_s, p4415_phase = p4415_p, p4415_width = p4415_w,\n",
    "                    rho_mass = rho_m, rho_scale = rho_s, rho_phase = rho_p, rho_width = rho_w,\n",
    "                    omega_mass = omega_m, omega_scale = omega_s, omega_phase = omega_p, omega_width = omega_w,\n",
    "                    phi_mass = phi_m, phi_scale = phi_s, phi_phase = phi_p, phi_width = phi_w,\n",
    "                    DDstar_mass = DDstar_m, DDstar_scale = DDstar_s, DDstar_phase = DDstar_p,\n",
    "                    Dbar_mass = Dbar_m, Dbar_scale = Dbar_s, Dbar_phase = Dbar_p,\n",
    "                    tau_mass = tau_m, C_tt = Ctt)\n",
    "                    \n",
    "                   \n",
    "# print(total_pdf.obs)\n",
    "\n",
    "# print(calcs_test)\n",
    "\n",
    "# for param in total_f.get_dependents():\n",
    "#     print(zfit.run(param))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test if graphs actually work and compute values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# def total_test_tf(xq):\n",
    "\n",
    "#     def jpsi_res(q):\n",
    "#         return resonance(q, jpsi_m, jpsi_s, jpsi_p, jpsi_w)\n",
    "\n",
    "#     def psi2s_res(q):\n",
    "#         return resonance(q, psi2s_m, psi2s_s, psi2s_p, psi2s_w)\n",
    "\n",
    "#     def cusp(q):\n",
    "#         return bifur_gauss(q, cusp_m, sig_L, sig_R, cusp_s)\n",
    "\n",
    "#     funcs = jpsi_res(xq) + psi2s_res(xq) + cusp(xq)\n",
    "\n",
    "#     vec_f = vec(xq, funcs)\n",
    "\n",
    "#     axiv_nr = axiv_nonres(xq)\n",
    "\n",
    "#     tot = vec_f + axiv_nr\n",
    "    \n",
    "#     return tot\n",
    "\n",
    "def jpsi_res(q):\n",
    "    return resonance(q, jpsi_m, jpsi_s, jpsi_p, jpsi_w)\n",
    "\n",
    "# calcs = zfit.run(total_test_tf(x_part))\n",
    "\n",
    "test_q = np.linspace(x_min, x_max, 200000)\n",
    "\n",
    "probs = total_f.pdf(test_q)\n",
    "\n",
    "calcs_test = zfit.run(probs)\n",
    "res_y = zfit.run(jpsi_res(test_q))\n",
    "f0_y = zfit.run(formfactor(test_q,\"0\"))\n",
    "fplus_y = zfit.run(formfactor(test_q,\"+\"))\n",
    "fT_y = zfit.run(formfactor(test_q,\"T\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZ8AAAD8CAYAAACo9anUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO29eXhd1Xnv/3nPOTqaJ0uyjSTbsrGMJ4wxxkAgQAxhCAkmBG5MQsMvkEvTkjZtevsD2iT3hoQmtGnobRNKaCAho6FAgkMgQAKBEMB4Nh4w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Rqcu+rGxeBtrrdUZwNXAy8aYdmNMB/AyVv68jMEYc9QYs8U+7gb2YGXAmFLPwr6fQFKvHPvHkMbprBKJiNQC1wE/sD+ndWqvFJDw+PvPqAAAAjNJREFUv4+pKD7h0gWNSceTpcwwxhwF66UMTLfLIz2TrHpWtrvkXKxv/VPuWdhupm3ACayXw37iTGcFhKazyujnYPNvwP8P+O3Pcaf2IvuehQFeEpHNYqUhgyT8fUzFbbTjSsczxTit1EWZgIgUAU8Df2OM6ZLIezFl7bMw1vq35SJSBvwSWBSumv1v1j4HEfkocMIYs1lELg8Uh6ma9c/C5mJjTIuITAdeFpH3otSdtGcxFS2fqZyO57htImP/e8IuH28apIxCRHKwhOdnxphn7OIp+SwAjDGngD9g+eynYjqri4HrReQgltt9NZYlNBWfBcaYFvvfE1hfSlaRhL+PqSg+8aQLylZCUxSNTl30GTuS5UKg0za1XwSuEpFyO9rlKrssY7B9848Ce4wx3wk5NaWehYhU2RYPIpIPXIk1/zXl0lkZY+41xtQaK0nmWqx7+zRT8FmISKGIFAeOsX6vd5KMv49UR1qk4gcrYuN9LJ/3P6Z6PAm6x18ARwEP1reSO7D81L8H9tn/TrPrCtbmfvuBd4GVIe3cjjWR2gB8NtX3NYHncAmW+b8D2Gb/fGSqPQtgGVa6qh32y+Wrdvk8rBdmA/DfQK5dnmd/brDPzwtp6x/t57MXuDbV93aaz+VyhqPdptyzsO95u/2zK/A+TMbfh6bXURRFUZLOVHS7KYqiKClGxUdRFEVJOio+iqIoStJR8VEURVGSjoqPoiiKknRUfBRFUZSko+KjKIqiJJ3/B8fWcVIpEC9fAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.clf()\n",
    "# plt.plot(x_part, calcs, '.')\n",
    "plt.plot(test_q, calcs_test, label = 'pdf')\n",
    "# plt.plot(test_q, f0_y, label = '0')\n",
    "# plt.plot(test_q, fT_y, label = 'T')\n",
    "# plt.plot(test_q, fplus_y, label = '+')\n",
    "# plt.plot(test_q, res_y, label = 'res')\n",
    "plt.legend()\n",
    "plt.ylim(0.0, 6e-6)\n",
    "# plt.yscale('log')\n",
    "# plt.xlim(770, 785)\n",
    "plt.savefig('test.png')\n",
    "# print(jpsi_width)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "# probs = mixture.prob(test_q)\n",
    "# probs_np = zfit.run(probs)\n",
    "# probs_np *= np.max(calcs_test) / np.max(probs_np)\n",
    "# plt.figure()\n",
    "# plt.semilogy(test_q, probs_np,label=\"importance sampling\")\n",
    "# plt.semilogy(test_q, calcs_test, label = 'pdf')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 0.213/(0.00133+0.213+0.015)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Adjust scaling of different parts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "total_f.update_integration_options(draws_per_dim=200000, mc_sampler=None)\n",
    "# inte = total_f.integrate(limits = (2000, x_max), norm_range=False)\n",
    "# inte_fl = zfit.run(inte)\n",
    "# print(inte_fl)\n",
    "# print(pdg[\"jpsi_BR\"]/pdg[\"NR_BR\"], inte_fl*pdg[\"psi2s_auc\"]/pdg[\"NR_auc\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # print(\"jpsi:\", inte_fl)\n",
    "# # print(\"Increase am by factor:\", np.sqrt(pdg[\"jpsi_BR\"]/pdg[\"NR_BR\"]*pdg[\"NR_auc\"]/inte_fl))\n",
    "# # print(\"New amp:\", pdg[\"jpsi\"][3]*np.sqrt(pdg[\"jpsi_BR\"]/pdg[\"NR_BR\"]*pdg[\"NR_auc\"]/inte_fl))\n",
    "\n",
    "# # print(\"psi2s:\", inte_fl)\n",
    "# # print(\"Increase am by factor:\", np.sqrt(pdg[\"psi2s_BR\"]/pdg[\"NR_BR\"]*pdg[\"NR_auc\"]/inte_fl))\n",
    "# # print(\"New amp:\", pdg[\"psi2s\"][3]*np.sqrt(pdg[\"psi2s_BR\"]/pdg[\"NR_BR\"]*pdg[\"NR_auc\"]/inte_fl))\n",
    "\n",
    "# name = \"phi\"\n",
    "\n",
    "# print(name+\":\", inte_fl)\n",
    "# print(\"Increase am by factor:\", np.sqrt(pdg[name+\"_BR\"]/pdg[\"NR_BR\"]*pdg[\"NR_auc\"]/inte_fl))\n",
    "# print(\"New amp:\", pdg[name][3]*np.sqrt(pdg[name+\"_BR\"]/pdg[\"NR_BR\"]*pdg[\"NR_auc\"]/inte_fl))\n",
    "\n",
    "\n",
    "# # print(x_min)\n",
    "# # print(x_max)\n",
    "# # # total_f.update_integration_options(draws_per_dim=2000000, mc_sampler=None)\n",
    "# # total_f.update_integration_options(mc_sampler=lambda dim, num_results,\n",
    "# #                                     dtype: tf.random_uniform(maxval=1., shape=(num_results, dim), dtype=dtype),\n",
    "# #                                    draws_per_dim=1000000)\n",
    "# # # _ = []\n",
    "\n",
    "# # # for i in range(10):\n",
    "\n",
    "# # #     inte = total_f.integrate(limits = (x_min, x_max))\n",
    "# # #     inte_fl = zfit.run(inte)\n",
    "# # #     print(inte_fl)\n",
    "# # #     _.append(inte_fl)\n",
    "\n",
    "# # # print(\"mean:\", np.mean(_))\n",
    "\n",
    "# # _ = time.time()\n",
    "\n",
    "# # inte = total_f.integrate(limits = (x_min, x_max))\n",
    "# # inte_fl = zfit.run(inte)\n",
    "# # print(inte_fl)\n",
    "# # print(\"Time taken: {}\".format(display_time(int(time.time() - _))))\n",
    "\n",
    "# print(pdg['NR_BR']/pdg['NR_auc']*inte_fl)\n",
    "# print(0.25**2*4.2/1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Sampling\n",
    "## Toys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "    \n",
    "# print(list_of_borders[:9])\n",
    "# print(list_of_borders[-9:])\n",
    "\n",
    "\n",
    "class UniformSampleAndWeights(zfit.util.execution.SessionHolderMixin):\n",
    "    def __call__(self, limits, dtype, n_to_produce):\n",
    "        # n_to_produce = tf.cast(n_to_produce, dtype=tf.int32)\n",
    "        low, high = limits.limit1d\n",
    "        low = tf.cast(low, dtype=dtype)\n",
    "        high = tf.cast(high, dtype=dtype)\n",
    "#         uniform = tfd.Uniform(low=low, high=high)\n",
    "#         uniformjpsi = tfd.Uniform(low=tf.constant(3080, dtype=dtype), high=tf.constant(3112, dtype=dtype))\n",
    "#         uniformpsi2s = tfd.Uniform(low=tf.constant(3670, dtype=dtype), high=tf.constant(3702, dtype=dtype))\n",
    "\n",
    "#         list_of_borders = []\n",
    "#         _p = []\n",
    "#         splits = 10\n",
    "\n",
    "#         _ = np.linspace(x_min, x_max, splits)\n",
    "\n",
    "#         for i in range(splits):\n",
    "#             list_of_borders.append(tf.constant(_[i], dtype=dtype))\n",
    "#             _p.append(tf.constant(1/splits, dtype=dtype))\n",
    "    \n",
    "#         mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=_p[:(splits-1)]),\n",
    "#                                         components_distribution=tfd.Uniform(low=list_of_borders[:(splits-1)], \n",
    "#                                                                             high=list_of_borders[-(splits-1):]))\n",
    "        mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.05, dtype=dtype),\n",
    "                                                                                    tf.constant(0.93, dtype=dtype),\n",
    "                                                                                    tf.constant(0.05, dtype=dtype),\n",
    "                                                                                    tf.constant(0.065, dtype=dtype),\n",
    "                                                                                    tf.constant(0.04, dtype=dtype),\n",
    "                                                                                    tf.constant(0.05, dtype=dtype)]),\n",
    "                                        components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), \n",
    "                                                                                 tf.constant(3090, dtype=dtype),\n",
    "                                                                                 tf.constant(3681, dtype=dtype), \n",
    "                                                                                 tf.constant(3070, dtype=dtype),\n",
    "                                                                                 tf.constant(1000, dtype=dtype),\n",
    "                                                                                 tf.constant(3660, dtype=dtype)], \n",
    "                                                                            high=[tf.constant(x_max, dtype=dtype),\n",
    "                                                                                  tf.constant(3102, dtype=dtype), \n",
    "                                                                                  tf.constant(3691, dtype=dtype),\n",
    "                                                                                  tf.constant(3110, dtype=dtype),\n",
    "                                                                                  tf.constant(1040, dtype=dtype),\n",
    "                                                                                  tf.constant(3710, dtype=dtype)]))\n",
    "#         dtype = tf.float64\n",
    "#         mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.04, dtype=dtype),\n",
    "#                                                                                     tf.constant(0.90, dtype=dtype),\n",
    "#                                                                                     tf.constant(0.02, dtype=dtype),\n",
    "#                                                                                     tf.constant(0.07, dtype=dtype),\n",
    "#                                                                                     tf.constant(0.02, dtype=dtype)]),\n",
    "#                                         components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), \n",
    "#                                                                                  tf.constant(3089, dtype=dtype),\n",
    "#                                                                                  tf.constant(3103, dtype=dtype), \n",
    "#                                                                                  tf.constant(3681, dtype=dtype),\n",
    "#                                                                                  tf.constant(3691, dtype=dtype)], \n",
    "#                                                                             high=[tf.constant(3089, dtype=dtype),\n",
    "#                                                                                   tf.constant(3103, dtype=dtype), \n",
    "#                                                                                   tf.constant(3681, dtype=dtype),\n",
    "#                                                                                   tf.constant(3691, dtype=dtype), \n",
    "#                                                                                   tf.constant(x_max, dtype=dtype)]))\n",
    "#         mixture = tfd.Uniform(tf.constant(x_min, dtype=dtype), tf.constant(x_max, dtype=dtype))\n",
    "#         sample = tf.random.uniform((n_to_produce, 1), dtype=dtype)\n",
    "        sample = mixture.sample((n_to_produce, 1))\n",
    "#         sample = tf.random.uniform((n_to_produce, 1), dtype=dtype)\n",
    "        weights = mixture.prob(sample)[:,0]\n",
    "#         weights = tf.broadcast_to(tf.constant(1., dtype=dtype), shape=(n_to_produce,))\n",
    "        # sample = tf.expand_dims(sample, axis=-1)\n",
    "#         print(sample, weights)\n",
    "        \n",
    "#         weights = tf.ones(shape=(n_to_produce,), dtype=dtype)\n",
    "        weights_max = None\n",
    "        thresholds = tf.random_uniform(shape=(n_to_produce,), dtype=dtype)\n",
    "        return sample, thresholds, weights, weights_max, n_to_produce"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "total_f._sample_and_weights = UniformSampleAndWeights"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 0.00133/(0.00133+0.213+0.015)*(x_max-3750)/(x_max-x_min)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# zfit.settings.set_verbosity(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# # zfit.run.numeric_checks = False   \n",
    "\n",
    "# nr_of_toys = 1\n",
    "# nevents = int(pdg[\"number_of_decays\"])\n",
    "# nevents = pdg[\"number_of_decays\"]\n",
    "# event_stack = 1000000\n",
    "# # zfit.settings.set_verbosity(10)\n",
    "# calls = int(nevents/event_stack + 1)\n",
    "\n",
    "# total_samp = []\n",
    "\n",
    "# start = time.time()\n",
    "\n",
    "# sampler = total_f.create_sampler(n=event_stack)\n",
    "\n",
    "# for toy in range(nr_of_toys):\n",
    "    \n",
    "#     dirName = 'data/zfit_toys/toy_{0}'.format(toy)\n",
    "    \n",
    "#     if not os.path.exists(dirName):\n",
    "#         os.mkdir(dirName)\n",
    "#         print(\"Directory \" , dirName ,  \" Created \")\n",
    "\n",
    "#     for call in range(calls):\n",
    "\n",
    "#         sampler.resample(n=event_stack)\n",
    "#         s = sampler.unstack_x()\n",
    "#         sam = zfit.run(s)\n",
    "# #         clear_output(wait=True)\n",
    "\n",
    "#         c = call + 1\n",
    "        \n",
    "#         print(\"{0}/{1} of Toy {2}/{3}\".format(c, calls, toy+1, nr_of_toys))\n",
    "#         print(\"Time taken: {}\".format(display_time(int(time.time() - start))))\n",
    "#         print(\"Projected time left: {}\".format(display_time(int((time.time() - start)/(c+calls*(toy))*((nr_of_toys-toy)*calls-c)))))\n",
    "\n",
    "#         with open(\"data/zfit_toys/toy_{0}/{1}.pkl\".format(toy, call), \"wb\") as f:\n",
    "#             pkl.dump(sam, f, pkl.HIGHEST_PROTOCOL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# with open(r\"data/zfit_toys/toy_0/0.pkl\", \"rb\") as input_file:\n",
    "#     sam = pkl.load(input_file)\n",
    "# print(sam[:10])\n",
    "\n",
    "# with open(r\"data/zfit_toys/toy_0/1.pkl\", \"rb\") as input_file:\n",
    "#     sam2 = pkl.load(input_file)\n",
    "# print(sam2[:10])\n",
    "\n",
    "# print(np.sum(sam-sam2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print(\"Time to generate full toy: {} s\".format(int(time.time()-start)))\n",
    "\n",
    "# total_samp = []\n",
    "\n",
    "# for call in range(calls):\n",
    "#     with open(r\"data/zfit_toys/toy_0/{}.pkl\".format(call), \"rb\") as input_file:\n",
    "#         sam = pkl.load(input_file)\n",
    "#         total_samp = np.append(total_samp, sam)\n",
    "\n",
    "# total_samp = total_samp.astype('float64')\n",
    "\n",
    "# data2 = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs)\n",
    "\n",
    "# data3 = zfit.data.Data.from_numpy(array=total_samp, obs=obs)\n",
    "\n",
    "# print(total_samp[:nevents].shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# plt.clf()\n",
    "\n",
    "# bins = int((x_max-x_min)/7)\n",
    "\n",
    "# # calcs = zfit.run(total_test_tf(samp))\n",
    "# print(total_samp[:nevents].shape)\n",
    "\n",
    "# plt.hist(total_samp[:nevents], bins = bins, range = (x_min,x_max), label = 'data')\n",
    "# # plt.plot(test_q, calcs_test*nevents , label = 'pdf')\n",
    "\n",
    "# # plt.plot(sam, calcs, '.')\n",
    "# # plt.plot(test_q, calcs_test)\n",
    "# # plt.yscale('log')\n",
    "# plt.ylim(0, 200)\n",
    "# # plt.xlim(3080, 3110)\n",
    "\n",
    "# plt.legend()\n",
    "\n",
    "# plt.savefig('test2.png')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# sampler = total_f.create_sampler(n=nevents)\n",
    "# nll = zfit.loss.UnbinnedNLL(model=total_f, data=sampler, fit_range = (x_min, x_max))\n",
    "\n",
    "# # for param in pdf.get_dependents():\n",
    "# #     param.set_value(initial_value)\n",
    "\n",
    "# sampler.resample(n=nevents)\n",
    "\n",
    "# # Randomise initial values\n",
    "# # for param in pdf.get_dependents():\n",
    "# #     param.set_value(random value here)\n",
    "\n",
    "# # Minimise the NLL\n",
    "# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 10)\n",
    "# minimum = minimizer.minimize(nll)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# jpsi_width"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# plt.hist(sample, weights=1 / prob(sample))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Fitting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "# start = time.time()\n",
    "\n",
    "# for param in total_f.get_dependents():\n",
    "#     param.randomize()\n",
    "    \n",
    "# # for param in total_f.get_dependents():\n",
    "# #     print(zfit.run(param))\n",
    "    \n",
    "# nll = zfit.loss.UnbinnedNLL(model=total_f, data=data2, fit_range = (x_min, x_max))\n",
    "\n",
    "# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5)\n",
    "# # minimizer._use_tfgrad = False\n",
    "# result = minimizer.minimize(nll)\n",
    "\n",
    "# # param_errors = result.error()\n",
    "\n",
    "# # for var, errors in param_errors.items():\n",
    "# #     print('{}: ^{{+{}}}_{{{}}}'.format(var.name, errors['upper'], errors['lower']))\n",
    "\n",
    "# print(\"Function minimum:\", result.fmin)\n",
    "# # print(\"Results:\", result.params)\n",
    "# print(\"Hesse errors:\", result.hesse())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print(\"Time taken for fitting: {}\".format(display_time(int(time.time()-start))))\n",
    "\n",
    "# # probs = total_f.pdf(test_q)\n",
    "\n",
    "# calcs_test = zfit.run(probs)\n",
    "# res_y = zfit.run(jpsi_res(test_q))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# plt.clf()\n",
    "# # plt.plot(x_part, calcs, '.')\n",
    "# plt.plot(test_q, calcs_test, label = 'pdf')\n",
    "# # plt.plot(test_q, res_y, label = 'res')\n",
    "# plt.legend()\n",
    "# plt.ylim(0.0, 10e-6)\n",
    "# # plt.yscale('log')\n",
    "# # plt.xlim(3080, 3110)\n",
    "# plt.savefig('test3.png')\n",
    "# # print(jpsi_width)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "# _tot = 4.37e-7+6.02e-5+4.97e-6\n",
    "# _probs = []\n",
    "# _probs.append(6.02e-5/_tot)\n",
    "# _probs.append(4.97e-6/_tot)\n",
    "# _probs.append(4.37e-7/_tot)\n",
    "# print(_probs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "# dtype = 'float64'\n",
    "# # mixture = tfd.Uniform(tf.constant(x_min, dtype=dtype), tf.constant(x_max, dtype=dtype))\n",
    "# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.007, dtype=dtype),\n",
    "#                                                                             tf.constant(0.917, dtype=dtype),\n",
    "#                                                                             tf.constant(0.076, dtype=dtype)]),\n",
    "#                                 components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), \n",
    "#                                                                          tf.constant(3080, dtype=dtype),\n",
    "#                                                                          tf.constant(3670, dtype=dtype)], \n",
    "#                                                                     high=[tf.constant(x_max, dtype=dtype),\n",
    "#                                                                           tf.constant(3112, dtype=dtype), \n",
    "#                                                                           tf.constant(3702, dtype=dtype)]))\n",
    "# # for i in range(10):\n",
    "# #     print(zfit.run(mixture.prob(mixture.sample((10, 1)))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print((zfit.run(jpsi_p)%(2*np.pi))/np.pi)\n",
    "# print((zfit.run(psi2s_p)%(2*np.pi))/np.pi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "#         def jpsi_res(q):\n",
    "#             return resonance(q, _mass = jpsi_mass, scale = jpsi_scale,\n",
    "#                              phase = jpsi_phase, width = jpsi_width)\n",
    "\n",
    "#         def psi2s_res(q):\n",
    "#             return resonance(q, _mass = psi2s_mass, scale = psi2s_scale,\n",
    "#                              phase = psi2s_phase, width = psi2s_width)\n",
    "        \n",
    "#         def p3770_res(q):\n",
    "#             return resonance(q, _mass = p3770_mass, scale = p3770_scale,\n",
    "#                              phase = p3770_phase, width = p3770_width)\n",
    "        \n",
    "#         def p4040_res(q):\n",
    "#             return resonance(q, _mass = p4040_mass, scale = p4040_scale,\n",
    "#                              phase = p4040_phase, width = p4040_width)\n",
    "        \n",
    "#         def p4160_res(q):\n",
    "#             return resonance(q, _mass = p4160_mass, scale = p4160_scale,\n",
    "#                              phase = p4160_phase, width = p4160_width)\n",
    "        \n",
    "#         def p4415_res(q):\n",
    "#             return resonance(q, _mass = p4415_mass, scale = p4415_scale,\n",
    "#                              phase = p4415_phase, width = p4415_width)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 0.15**2*4.2/1000\n",
    "# result.hesse()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Toy 0: Generating data...\n",
      "Toy 0: Data generation finished\n",
      "Toy 0: Loading data...\n",
      "Toy 0: Loading data finished\n",
      "Toy 0: Fitting pdf...\n",
      "------------------------------------------------------------------\n",
      "| FCN = 4.145E+04               |     Ncalls=189 (189 total)     |\n",
      "| EDM = 0.000434 (Goal: 5E-06)  |            up = 0.5            |\n",
      "------------------------------------------------------------------\n",
      "|  Valid Min.   | Valid Param.  | Above EDM | Reached call limit |\n",
      "------------------------------------------------------------------\n",
      "|     True      |     True      |   False   |       False        |\n",
      "------------------------------------------------------------------\n",
      "| Hesse failed  |   Has cov.    | Accurate  | Pos. def. | Forced |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   True    |   True    | False  |\n",
      "------------------------------------------------------------------\n",
      "Toy 0: Fitting finished\n",
      "Function minimum: 41446.17176214419\n",
      "---------------------------------------------------------------------------------------------\n",
      "|   | Name    |   Value   | Hesse Err | Minos Err- | Minos Err+ | Limit-  | Limit+  | Fixed |\n",
      "---------------------------------------------------------------------------------------------\n",
      "| 0 | psi2s_p |   -4.4    |    0.4    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 1 | Dbar_s  |   -0.7    |    1.8    |            |            | -1.464  |  1.464  |       |\n",
      "| 2 | Ctt     |   -0.5    |    1.0    |            |            |  -0.5   |   0.5   |       |\n",
      "| 3 | jpsi_p  |   -1.9    |    0.7    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 4 | jpsi_s  |  0.980E4  |  0.011E4  |            |            | 9797.52 | 9996.48 |       |\n",
      "| 5 | psi2s_s |   1430    |    50     |            |            | 1358.64 | 1433.36 |       |\n",
      "---------------------------------------------------------------------------------------------\n",
      "-------------------------------------------------------------\n",
      "|         | psi2s_p  Dbar_s     Ctt  jpsi_p  jpsi_s psi2s_s |\n",
      "-------------------------------------------------------------\n",
      "| psi2s_p |   1.000   0.896   0.021   0.977  -0.145  -0.023 |\n",
      "|  Dbar_s |   0.896   1.000   0.236   0.941  -0.223   0.004 |\n",
      "|     Ctt |   0.021   0.236   1.000   0.013  -0.053  -0.007 |\n",
      "|  jpsi_p |   0.977   0.941   0.013   1.000  -0.133  -0.004 |\n",
      "|  jpsi_s |  -0.145  -0.223  -0.053  -0.133   1.000  -0.001 |\n",
      "| psi2s_s |  -0.023   0.004  -0.007  -0.004  -0.001   1.000 |\n",
      "-------------------------------------------------------------\n",
      "Hesse errors: OrderedDict([(<zfit.Parameter 'psi2s_p' floating=True>, {'error': 0.41840024605493187}), (<zfit.Parameter 'Dbar_s' floating=True>, {'error': 1.8317143176053508}), (<zfit.Parameter 'Ctt' floating=True>, {'error': 0.996289918615876}), (<zfit.Parameter 'jpsi_p' floating=True>, {'error': 0.7473453412456892}), (<zfit.Parameter 'jpsi_s' floating=True>, {'error': 113.9126570143626}), (<zfit.Parameter 'psi2s_s' floating=True>, {'error': 47.11513567257623})])\n",
      "Toy 1/10\n",
      "Time taken: 2 min, 32 s\n",
      "Projected time left: 22 min, 50 s\n",
      "Toy 1: Generating data...\n",
      "Toy 1: Data generation finished\n",
      "Toy 1: Loading data...\n",
      "Toy 1: Loading data finished\n",
      "Toy 1: Fitting pdf...\n",
      "------------------------------------------------------------------\n",
      "| FCN = 4.145E+04               |     Ncalls=174 (174 total)     |\n",
      "| EDM = 0.000246 (Goal: 5E-06)  |            up = 0.5            |\n",
      "------------------------------------------------------------------\n",
      "|  Valid Min.   | Valid Param.  | Above EDM | Reached call limit |\n",
      "------------------------------------------------------------------\n",
      "|     True      |     True      |   False   |       False        |\n",
      "------------------------------------------------------------------\n",
      "| Hesse failed  |   Has cov.    | Accurate  | Pos. def. | Forced |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   True    |   True    | False  |\n",
      "------------------------------------------------------------------\n",
      "Toy 1: Fitting finished\n",
      "Function minimum: 41446.21391501494\n",
      "---------------------------------------------------------------------------------------------\n",
      "|   | Name    |   Value   | Hesse Err | Minos Err- | Minos Err+ | Limit-  | Limit+  | Fixed |\n",
      "---------------------------------------------------------------------------------------------\n",
      "| 0 | psi2s_p |   1.51    |   0.17    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 1 | Dbar_s  |   -0.7    |    1.8    |            |            | -1.464  |  1.464  |       |\n",
      "| 2 | Ctt     |   -0.5    |    0.8    |            |            |  -0.5   |   0.5   |       |\n",
      "| 3 | jpsi_p  |    2.0    |    0.5    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 4 | jpsi_s  |  0.980E4  |  0.013E4  |            |            | 9797.52 | 9996.48 |       |\n",
      "| 5 | psi2s_s |   1430    |    50     |            |            | 1358.64 | 1433.36 |       |\n",
      "---------------------------------------------------------------------------------------------\n",
      "-------------------------------------------------------------\n",
      "|         | psi2s_p  Dbar_s     Ctt  jpsi_p  jpsi_s psi2s_s |\n",
      "-------------------------------------------------------------\n",
      "| psi2s_p |    1.00    0.80    0.84    0.72    0.16   -0.27 |\n",
      "|  Dbar_s |    0.80    1.00    0.98    0.88    0.17   -0.22 |\n",
      "|     Ctt |    0.84    0.98    1.00    0.94    0.21   -0.23 |\n",
      "|  jpsi_p |    0.72    0.88    0.94    1.00    0.17   -0.22 |\n",
      "|  jpsi_s |    0.16    0.17    0.21    0.17    1.00   -0.05 |\n",
      "| psi2s_s |   -0.27   -0.22   -0.23   -0.22   -0.05    1.00 |\n",
      "-------------------------------------------------------------\n",
      "Hesse errors: OrderedDict([(<zfit.Parameter 'psi2s_p' floating=True>, {'error': 0.17027941762338372}), (<zfit.Parameter 'Dbar_s' floating=True>, {'error': 1.7969490420133767}), (<zfit.Parameter 'Ctt' floating=True>, {'error': 0.8149920548026126}), (<zfit.Parameter 'jpsi_p' floating=True>, {'error': 0.4859306435087767}), (<zfit.Parameter 'jpsi_s' floating=True>, {'error': 129.95009225722333}), (<zfit.Parameter 'psi2s_s' floating=True>, {'error': 47.350217126767575})])\n",
      "Toy 2/10\n",
      "Time taken: 5 min, 16 s\n",
      "Projected time left: 21 min, 7 s\n",
      "Toy 2: Generating data...\n",
      "Toy 2: Data generation finished\n",
      "Toy 2: Loading data...\n",
      "Toy 2: Loading data finished\n",
      "Toy 2: Fitting pdf...\n",
      "------------------------------------------------------------------\n",
      "| FCN = 4.145E+04               |     Ncalls=204 (204 total)     |\n",
      "| EDM = 0.00128 (Goal: 5E-06)   |            up = 0.5            |\n",
      "------------------------------------------------------------------\n",
      "|  Valid Min.   | Valid Param.  | Above EDM | Reached call limit |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   True    |       False        |\n",
      "------------------------------------------------------------------\n",
      "| Hesse failed  |   Has cov.    | Accurate  | Pos. def. | Forced |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   True    |   True    | False  |\n",
      "------------------------------------------------------------------\n",
      "Toy 2: Fitting finished\n",
      "Function minimum: 41446.21446623224\n",
      "---------------------------------------------------------------------------------------------\n",
      "|   | Name    |   Value   | Hesse Err | Minos Err- | Minos Err+ | Limit-  | Limit+  | Fixed |\n",
      "---------------------------------------------------------------------------------------------\n",
      "| 0 | psi2s_p |   -4.78   |    0.18   |            |            |-6.28319 | 6.28319 |       |\n",
      "| 1 | Dbar_s  |   -0.7    |    1.8    |            |            | -1.464  |  1.464  |       |\n",
      "| 2 | Ctt     |   -0.5    |    0.7    |            |            |  -0.5   |   0.5   |       |\n",
      "| 3 | jpsi_p  |   -4.3    |    0.5    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 4 | jpsi_s  |  0.980E4  |  0.013E4  |            |            | 9797.52 | 9996.48 |       |\n",
      "| 5 | psi2s_s |   1430    |    40     |            |            | 1358.64 | 1433.36 |       |\n",
      "---------------------------------------------------------------------------------------------\n",
      "-------------------------------------------------------------\n",
      "|         | psi2s_p  Dbar_s     Ctt  jpsi_p  jpsi_s psi2s_s |\n",
      "-------------------------------------------------------------\n",
      "| psi2s_p |    1.00    0.82    0.86    0.76    0.20    0.32 |\n",
      "|  Dbar_s |    0.82    1.00    0.98    0.89    0.21    0.26 |\n",
      "|     Ctt |    0.86    0.98    1.00    0.95    0.24    0.27 |\n",
      "|  jpsi_p |    0.76    0.89    0.95    1.00    0.21    0.26 |\n",
      "|  jpsi_s |    0.20    0.21    0.24    0.21    1.00    0.07 |\n",
      "| psi2s_s |    0.32    0.26    0.27    0.26    0.07    1.00 |\n",
      "-------------------------------------------------------------\n",
      "Hesse errors: OrderedDict([(<zfit.Parameter 'psi2s_p' floating=True>, {'error': 0.17884003769401335}), (<zfit.Parameter 'Dbar_s' floating=True>, {'error': 1.7953075848497315}), (<zfit.Parameter 'Ctt' floating=True>, {'error': 0.6507663138579277}), (<zfit.Parameter 'jpsi_p' floating=True>, {'error': 0.49871222470060794}), (<zfit.Parameter 'jpsi_s' floating=True>, {'error': 127.32075889710268}), (<zfit.Parameter 'psi2s_s' floating=True>, {'error': 38.958773985027506})])\n",
      "Toy 3/10\n",
      "Time taken: 7 min, 58 s\n",
      "Projected time left: 18 min, 37 s\n",
      "Toy 3: Generating data...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Toy 3: Data generation finished\n",
      "Toy 3: Loading data...\n",
      "Toy 3: Loading data finished\n",
      "Toy 3: Fitting pdf...\n",
      "------------------------------------------------------------------\n",
      "| FCN = 4.145E+04               |     Ncalls=233 (233 total)     |\n",
      "| EDM = 0.000301 (Goal: 5E-06)  |            up = 0.5            |\n",
      "------------------------------------------------------------------\n",
      "|  Valid Min.   | Valid Param.  | Above EDM | Reached call limit |\n",
      "------------------------------------------------------------------\n",
      "|     True      |     True      |   False   |       False        |\n",
      "------------------------------------------------------------------\n",
      "| Hesse failed  |   Has cov.    | Accurate  | Pos. def. | Forced |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   False   |   False   |  True  |\n",
      "------------------------------------------------------------------\n",
      "Toy 3: Fitting finished\n",
      "Function minimum: 41446.213143894536\n",
      "---------------------------------------------------------------------------------------------\n",
      "|   | Name    |   Value   | Hesse Err | Minos Err- | Minos Err+ | Limit-  | Limit+  | Fixed |\n",
      "---------------------------------------------------------------------------------------------\n",
      "| 0 | psi2s_p |   -4.77   |    0.20   |            |            |-6.28319 | 6.28319 |       |\n",
      "| 1 | Dbar_s  |   -0.7    |    1.8    |            |            | -1.464  |  1.464  |       |\n",
      "| 2 | Ctt     |   -0.5    |    1.0    |            |            |  -0.5   |   0.5   |       |\n",
      "| 3 | jpsi_p  |   -4.3    |    0.5    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 4 | jpsi_s  |  0.980E4  |  0.012E4  |            |            | 9797.52 | 9996.48 |       |\n",
      "| 5 | psi2s_s |   1430    |    50     |            |            | 1358.64 | 1433.36 |       |\n",
      "---------------------------------------------------------------------------------------------\n",
      "-------------------------------------------------------------\n",
      "|         | psi2s_p  Dbar_s     Ctt  jpsi_p  jpsi_s psi2s_s |\n",
      "-------------------------------------------------------------\n",
      "| psi2s_p |    1.00    0.89    0.92    0.85    0.41   -0.32 |\n",
      "|  Dbar_s |    0.89    1.00    0.98    0.93    0.43   -0.26 |\n",
      "|     Ctt |    0.92    0.98    1.00    0.97    0.46   -0.27 |\n",
      "|  jpsi_p |    0.85    0.93    0.97    1.00    0.43   -0.26 |\n",
      "|  jpsi_s |    0.41    0.43    0.46    0.43    1.00   -0.12 |\n",
      "| psi2s_s |   -0.32   -0.26   -0.27   -0.26   -0.12    1.00 |\n",
      "-------------------------------------------------------------\n",
      "Hesse errors: OrderedDict([(<zfit.Parameter 'psi2s_p' floating=True>, {'error': 0.2028644492314955}), (<zfit.Parameter 'Dbar_s' floating=True>, {'error': 1.8154514362409575}), (<zfit.Parameter 'Ctt' floating=True>, {'error': 0.9807202234423524}), (<zfit.Parameter 'jpsi_p' floating=True>, {'error': 0.5159537418531039}), (<zfit.Parameter 'jpsi_s' floating=True>, {'error': 117.77974601317328}), (<zfit.Parameter 'psi2s_s' floating=True>, {'error': 45.73863717851896})])\n",
      "Toy 4/10\n",
      "Time taken: 10 min, 46 s\n",
      "Projected time left: 16 min, 9 s\n",
      "Toy 4: Generating data...\n",
      "Toy 4: Data generation finished\n",
      "Toy 4: Loading data...\n",
      "Toy 4: Loading data finished\n",
      "Toy 4: Fitting pdf...\n",
      "------------------------------------------------------------------\n",
      "| FCN = 4.145E+04               |     Ncalls=180 (180 total)     |\n",
      "| EDM = 0.000259 (Goal: 5E-06)  |            up = 0.5            |\n",
      "------------------------------------------------------------------\n",
      "|  Valid Min.   | Valid Param.  | Above EDM | Reached call limit |\n",
      "------------------------------------------------------------------\n",
      "|     True      |     True      |   False   |       False        |\n",
      "------------------------------------------------------------------\n",
      "| Hesse failed  |   Has cov.    | Accurate  | Pos. def. | Forced |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   True    |   True    | False  |\n",
      "------------------------------------------------------------------\n",
      "Toy 4: Fitting finished\n",
      "Function minimum: 41446.213230540496\n",
      "---------------------------------------------------------------------------------------------\n",
      "|   | Name    |   Value   | Hesse Err | Minos Err- | Minos Err+ | Limit-  | Limit+  | Fixed |\n",
      "---------------------------------------------------------------------------------------------\n",
      "| 0 | psi2s_p |   -4.77   |    0.21   |            |            |-6.28319 | 6.28319 |       |\n",
      "| 1 | Dbar_s  |   -0.7    |    1.8    |            |            | -1.464  |  1.464  |       |\n",
      "| 2 | Ctt     |   -0.5    |    0.7    |            |            |  -0.5   |   0.5   |       |\n",
      "| 3 | jpsi_p  |   -4.3    |    0.5    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 4 | jpsi_s  |  0.980E4  |  0.012E4  |            |            | 9797.52 | 9996.48 |       |\n",
      "| 5 | psi2s_s |   1430    |    60     |            |            | 1358.64 | 1433.36 |       |\n",
      "---------------------------------------------------------------------------------------------\n",
      "-------------------------------------------------------------\n",
      "|         | psi2s_p  Dbar_s     Ctt  jpsi_p  jpsi_s psi2s_s |\n",
      "-------------------------------------------------------------\n",
      "| psi2s_p |    1.00    0.89    0.92    0.87    0.45   -0.45 |\n",
      "|  Dbar_s |    0.89    1.00    0.98    0.93    0.47   -0.37 |\n",
      "|     Ctt |    0.92    0.98    1.00    0.97    0.50   -0.38 |\n",
      "|  jpsi_p |    0.87    0.93    0.97    1.00    0.47   -0.38 |\n",
      "|  jpsi_s |    0.45    0.47    0.50    0.47    1.00   -0.19 |\n",
      "| psi2s_s |   -0.45   -0.37   -0.38   -0.38   -0.19    1.00 |\n",
      "-------------------------------------------------------------\n",
      "Hesse errors: OrderedDict([(<zfit.Parameter 'psi2s_p' floating=True>, {'error': 0.21090063108815427}), (<zfit.Parameter 'Dbar_s' floating=True>, {'error': 1.8277281246469832}), (<zfit.Parameter 'Ctt' floating=True>, {'error': 0.7144740345016457}), (<zfit.Parameter 'jpsi_p' floating=True>, {'error': 0.5130723061292268}), (<zfit.Parameter 'jpsi_s' floating=True>, {'error': 120.0500270283901}), (<zfit.Parameter 'psi2s_s' floating=True>, {'error': 59.20149657515435})])\n",
      "Toy 5/10\n",
      "Time taken: 13 min, 31 s\n",
      "Projected time left: 13 min, 31 s\n",
      "Toy 5: Generating data...\n",
      "Toy 5: Data generation finished\n",
      "Toy 5: Loading data...\n",
      "Toy 5: Loading data finished\n",
      "Toy 5: Fitting pdf...\n",
      "------------------------------------------------------------------\n",
      "| FCN = 4.145E+04               |     Ncalls=304 (304 total)     |\n",
      "| EDM = 0.00152 (Goal: 5E-06)   |            up = 0.5            |\n",
      "------------------------------------------------------------------\n",
      "|  Valid Min.   | Valid Param.  | Above EDM | Reached call limit |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   True    |       False        |\n",
      "------------------------------------------------------------------\n",
      "| Hesse failed  |   Has cov.    | Accurate  | Pos. def. | Forced |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   False   |   False   |  True  |\n",
      "------------------------------------------------------------------\n",
      "Toy 5: Fitting finished\n",
      "Function minimum: 41446.26376718663\n",
      "---------------------------------------------------------------------------------------------\n",
      "|   | Name    |   Value   | Hesse Err | Minos Err- | Minos Err+ | Limit-  | Limit+  | Fixed |\n",
      "---------------------------------------------------------------------------------------------\n",
      "| 0 | psi2s_p |   4.67    |   0.32    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 1 | Dbar_s  |   -0.8    |    1.8    |            |            | -1.464  |  1.464  |       |\n",
      "| 2 | Ctt     |   -0.5    |    0.5    |            |            |  -0.5   |   0.5   |       |\n",
      "| 3 | jpsi_p  |   -2.1    |    0.5    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 4 | jpsi_s  |  0.980E4  |  0.015E4  |            |            | 9797.52 | 9996.48 |       |\n",
      "| 5 | psi2s_s |   1430    |    50     |            |            | 1358.64 | 1433.36 |       |\n",
      "---------------------------------------------------------------------------------------------\n",
      "-------------------------------------------------------------\n",
      "|         | psi2s_p  Dbar_s     Ctt  jpsi_p  jpsi_s psi2s_s |\n",
      "-------------------------------------------------------------\n",
      "| psi2s_p |   1.000  -0.915  -0.954   0.850  -0.143   0.107 |\n",
      "|  Dbar_s |  -0.915   1.000   0.967  -0.848   0.117  -0.004 |\n",
      "|     Ctt |  -0.954   0.967   1.000  -0.937   0.157  -0.019 |\n",
      "|  jpsi_p |   0.850  -0.848  -0.937   1.000  -0.126   0.030 |\n",
      "|  jpsi_s |  -0.143   0.117   0.157  -0.126   1.000  -0.005 |\n",
      "| psi2s_s |   0.107  -0.004  -0.019   0.030  -0.005   1.000 |\n",
      "-------------------------------------------------------------\n",
      "Hesse errors: OrderedDict([(<zfit.Parameter 'psi2s_p' floating=True>, {'error': 0.31586736018571226}), (<zfit.Parameter 'Dbar_s' floating=True>, {'error': 1.7931181136417407}), (<zfit.Parameter 'Ctt' floating=True>, {'error': 0.505275767707557}), (<zfit.Parameter 'jpsi_p' floating=True>, {'error': 0.5046726165950495}), (<zfit.Parameter 'jpsi_s' floating=True>, {'error': 147.58315697207308}), (<zfit.Parameter 'psi2s_s' floating=True>, {'error': 45.95130250092461})])\n",
      "Toy 6/10\n",
      "Time taken: 16 min, 29 s\n",
      "Projected time left: 10 min, 59 s\n",
      "Toy 6: Generating data...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Toy 6: Data generation finished\n",
      "Toy 6: Loading data...\n",
      "Toy 6: Loading data finished\n",
      "Toy 6: Fitting pdf...\n",
      "------------------------------------------------------------------\n",
      "| FCN = 4.145E+04               |     Ncalls=216 (216 total)     |\n",
      "| EDM = 0.000883 (Goal: 5E-06)  |            up = 0.5            |\n",
      "------------------------------------------------------------------\n",
      "|  Valid Min.   | Valid Param.  | Above EDM | Reached call limit |\n",
      "------------------------------------------------------------------\n",
      "|     True      |     True      |   False   |       False        |\n",
      "------------------------------------------------------------------\n",
      "| Hesse failed  |   Has cov.    | Accurate  | Pos. def. | Forced |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   True    |   True    | False  |\n",
      "------------------------------------------------------------------\n",
      "Toy 6: Fitting finished\n",
      "Function minimum: 41446.21393607266\n",
      "---------------------------------------------------------------------------------------------\n",
      "|   | Name    |   Value   | Hesse Err | Minos Err- | Minos Err+ | Limit-  | Limit+  | Fixed |\n",
      "---------------------------------------------------------------------------------------------\n",
      "| 0 | psi2s_p |   -4.77   |    0.19   |            |            |-6.28319 | 6.28319 |       |\n",
      "| 1 | Dbar_s  |   -0.7    |    1.8    |            |            | -1.464  |  1.464  |       |\n",
      "| 2 | Ctt     |   -0.5    |    0.5    |            |            |  -0.5   |   0.5   |       |\n",
      "| 3 | jpsi_p  |    2.0    |    0.5    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 4 | jpsi_s  |  0.980E4  |  0.010E4  |            |            | 9797.52 | 9996.48 |       |\n",
      "| 5 | psi2s_s |   1430    |    40     |            |            | 1358.64 | 1433.36 |       |\n",
      "---------------------------------------------------------------------------------------------\n",
      "-------------------------------------------------------------\n",
      "|         | psi2s_p  Dbar_s     Ctt  jpsi_p  jpsi_s psi2s_s |\n",
      "-------------------------------------------------------------\n",
      "| psi2s_p |    1.00    0.87    0.90    0.83    0.49    0.16 |\n",
      "|  Dbar_s |    0.87    1.00    0.98    0.92    0.51    0.13 |\n",
      "|     Ctt |    0.90    0.98    1.00    0.96    0.56    0.13 |\n",
      "|  jpsi_p |    0.83    0.92    0.96    1.00    0.51    0.13 |\n",
      "|  jpsi_s |    0.49    0.51    0.56    0.51    1.00    0.07 |\n",
      "| psi2s_s |    0.16    0.13    0.13    0.13    0.07    1.00 |\n",
      "-------------------------------------------------------------\n",
      "Hesse errors: OrderedDict([(<zfit.Parameter 'psi2s_p' floating=True>, {'error': 0.1917856359807728}), (<zfit.Parameter 'Dbar_s' floating=True>, {'error': 1.8156013659952255}), (<zfit.Parameter 'Ctt' floating=True>, {'error': 0.5117900295417959}), (<zfit.Parameter 'jpsi_p' floating=True>, {'error': 0.49818141138885563}), (<zfit.Parameter 'jpsi_s' floating=True>, {'error': 100.16204116151494}), (<zfit.Parameter 'psi2s_s' floating=True>, {'error': 38.14017204277275})])\n",
      "Toy 7/10\n",
      "Time taken: 19 min, 23 s\n",
      "Projected time left: 8 min, 18 s\n",
      "Toy 7: Generating data...\n",
      "Toy 7: Data generation finished\n",
      "Toy 7: Loading data...\n",
      "Toy 7: Loading data finished\n",
      "Toy 7: Fitting pdf...\n",
      "------------------------------------------------------------------\n",
      "| FCN = 4.145E+04               |     Ncalls=202 (202 total)     |\n",
      "| EDM = 0.000126 (Goal: 5E-06)  |            up = 0.5            |\n",
      "------------------------------------------------------------------\n",
      "|  Valid Min.   | Valid Param.  | Above EDM | Reached call limit |\n",
      "------------------------------------------------------------------\n",
      "|     True      |     True      |   False   |       False        |\n",
      "------------------------------------------------------------------\n",
      "| Hesse failed  |   Has cov.    | Accurate  | Pos. def. | Forced |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   True    |   True    | False  |\n",
      "------------------------------------------------------------------\n",
      "Toy 7: Fitting finished\n",
      "Function minimum: 41446.171485007675\n",
      "---------------------------------------------------------------------------------------------\n",
      "|   | Name    |   Value   | Hesse Err | Minos Err- | Minos Err+ | Limit-  | Limit+  | Fixed |\n",
      "---------------------------------------------------------------------------------------------\n",
      "| 0 | psi2s_p |    1.9    |    0.4    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 1 | Dbar_s  |   -0.7    |    1.8    |            |            | -1.464  |  1.464  |       |\n",
      "| 2 | Ctt     |   -0.5    |    1.0    |            |            |  -0.5   |   0.5   |       |\n",
      "| 3 | jpsi_p  |   -1.9    |    0.7    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 4 | jpsi_s  |  0.980E4  |  0.012E4  |            |            | 9797.52 | 9996.48 |       |\n",
      "| 5 | psi2s_s |   1430    |    60     |            |            | 1358.64 | 1433.36 |       |\n",
      "---------------------------------------------------------------------------------------------\n",
      "-------------------------------------------------------------\n",
      "|         | psi2s_p  Dbar_s     Ctt  jpsi_p  jpsi_s psi2s_s |\n",
      "-------------------------------------------------------------\n",
      "| psi2s_p |   1.000   0.861   0.035   0.970  -0.112  -0.115 |\n",
      "|  Dbar_s |   0.861   1.000   0.322   0.916  -0.184   0.022 |\n",
      "|     Ctt |   0.035   0.322   1.000   0.018  -0.058  -0.048 |\n",
      "|  jpsi_p |   0.970   0.916   0.018   1.000  -0.102  -0.013 |\n",
      "|  jpsi_s |  -0.112  -0.184  -0.058  -0.102   1.000  -0.004 |\n",
      "| psi2s_s |  -0.115   0.022  -0.048  -0.013  -0.004   1.000 |\n",
      "-------------------------------------------------------------\n",
      "Hesse errors: OrderedDict([(<zfit.Parameter 'psi2s_p' floating=True>, {'error': 0.39988882358765476}), (<zfit.Parameter 'Dbar_s' floating=True>, {'error': 1.8338950485749796}), (<zfit.Parameter 'Ctt' floating=True>, {'error': 0.9813742089966919}), (<zfit.Parameter 'jpsi_p' floating=True>, {'error': 0.709065375300536}), (<zfit.Parameter 'jpsi_s' floating=True>, {'error': 116.26239022795016}), (<zfit.Parameter 'psi2s_s' floating=True>, {'error': 64.86664680863748})])\n",
      "Toy 8/10\n",
      "Time taken: 22 min, 12 s\n",
      "Projected time left: 5 min, 33 s\n",
      "Toy 8: Generating data...\n",
      "Toy 8: Data generation finished\n",
      "Toy 8: Loading data...\n",
      "Toy 8: Loading data finished\n",
      "Toy 8: Fitting pdf...\n",
      "------------------------------------------------------------------\n",
      "| FCN = 4.145E+04               |     Ncalls=185 (185 total)     |\n",
      "| EDM = 7.47E-05 (Goal: 5E-06)  |            up = 0.5            |\n",
      "------------------------------------------------------------------\n",
      "|  Valid Min.   | Valid Param.  | Above EDM | Reached call limit |\n",
      "------------------------------------------------------------------\n",
      "|     True      |     True      |   False   |       False        |\n",
      "------------------------------------------------------------------\n",
      "| Hesse failed  |   Has cov.    | Accurate  | Pos. def. | Forced |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   True    |   True    | False  |\n",
      "------------------------------------------------------------------\n",
      "Toy 8: Fitting finished\n",
      "Function minimum: 41446.171426607005\n",
      "---------------------------------------------------------------------------------------------\n",
      "|   | Name    |   Value   | Hesse Err | Minos Err- | Minos Err+ | Limit-  | Limit+  | Fixed |\n",
      "---------------------------------------------------------------------------------------------\n",
      "| 0 | psi2s_p |   -4.4    |    0.4    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 1 | Dbar_s  |   -0.7    |    1.8    |            |            | -1.464  |  1.464  |       |\n",
      "| 2 | Ctt     |   -0.5    |    1.0    |            |            |  -0.5   |   0.5   |       |\n",
      "| 3 | jpsi_p  |    4.4    |    0.7    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 4 | jpsi_s  |  0.980E4  |  0.012E4  |            |            | 9797.52 | 9996.48 |       |\n",
      "| 5 | psi2s_s |   1430    |    60     |            |            | 1358.64 | 1433.36 |       |\n",
      "---------------------------------------------------------------------------------------------\n",
      "-------------------------------------------------------------\n",
      "|         | psi2s_p  Dbar_s     Ctt  jpsi_p  jpsi_s psi2s_s |\n",
      "-------------------------------------------------------------\n",
      "| psi2s_p |   1.000   0.850   0.027   0.966  -0.108  -0.122 |\n",
      "|  Dbar_s |   0.850   1.000   0.309   0.913  -0.184   0.021 |\n",
      "|     Ctt |   0.027   0.309   1.000   0.012  -0.053  -0.042 |\n",
      "|  jpsi_p |   0.966   0.913   0.012   1.000  -0.097  -0.019 |\n",
      "|  jpsi_s |  -0.108  -0.184  -0.053  -0.097   1.000  -0.004 |\n",
      "| psi2s_s |  -0.122   0.021  -0.042  -0.019  -0.004   1.000 |\n",
      "-------------------------------------------------------------\n",
      "Hesse errors: OrderedDict([(<zfit.Parameter 'psi2s_p' floating=True>, {'error': 0.37581893654929166}), (<zfit.Parameter 'Dbar_s' floating=True>, {'error': 1.8374920961421453}), (<zfit.Parameter 'Ctt' floating=True>, {'error': 0.995543793163386}), (<zfit.Parameter 'jpsi_p' floating=True>, {'error': 0.6592821643495412}), (<zfit.Parameter 'jpsi_s' floating=True>, {'error': 118.1086035526505}), (<zfit.Parameter 'psi2s_s' floating=True>, {'error': 62.73818368176751})])\n",
      "Toy 9/10\n",
      "Time taken: 25 min, 2 s\n",
      "Projected time left: 2 min, 46 s\n",
      "Toy 9: Generating data...\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Toy 9: Data generation finished\n",
      "Toy 9: Loading data...\n",
      "Toy 9: Loading data finished\n",
      "Toy 9: Fitting pdf...\n",
      "------------------------------------------------------------------\n",
      "| FCN = 4.145E+04               |     Ncalls=181 (181 total)     |\n",
      "| EDM = 0.000129 (Goal: 5E-06)  |            up = 0.5            |\n",
      "------------------------------------------------------------------\n",
      "|  Valid Min.   | Valid Param.  | Above EDM | Reached call limit |\n",
      "------------------------------------------------------------------\n",
      "|     True      |     True      |   False   |       False        |\n",
      "------------------------------------------------------------------\n",
      "| Hesse failed  |   Has cov.    | Accurate  | Pos. def. | Forced |\n",
      "------------------------------------------------------------------\n",
      "|     False     |     True      |   True    |   True    | False  |\n",
      "------------------------------------------------------------------\n",
      "Toy 9: Fitting finished\n",
      "Function minimum: 41446.27791906745\n",
      "---------------------------------------------------------------------------------------------\n",
      "|   | Name    |   Value   | Hesse Err | Minos Err- | Minos Err+ | Limit-  | Limit+  | Fixed |\n",
      "---------------------------------------------------------------------------------------------\n",
      "| 0 | psi2s_p |   -1.94   |    0.26   |            |            |-6.28319 | 6.28319 |       |\n",
      "| 1 | Dbar_s  |   -0.7    |    0.8    |            |            | -1.464  |  1.464  |       |\n",
      "| 2 | Ctt     |   -0.5    |    0.8    |            |            |  -0.5   |   0.5   |       |\n",
      "| 3 | jpsi_p  |    1.8    |    0.4    |            |            |-6.28319 | 6.28319 |       |\n",
      "| 4 | jpsi_s  |  0.980E4  |  0.014E4  |            |            | 9797.52 | 9996.48 |       |\n",
      "| 5 | psi2s_s |   1430    |    40     |            |            | 1358.64 | 1433.36 |       |\n",
      "---------------------------------------------------------------------------------------------\n",
      "-------------------------------------------------------------\n",
      "|         | psi2s_p  Dbar_s     Ctt  jpsi_p  jpsi_s psi2s_s |\n",
      "-------------------------------------------------------------\n",
      "| psi2s_p |   1.000  -0.766  -0.254   0.902   0.074   0.130 |\n",
      "|  Dbar_s |  -0.766   1.000   0.391  -0.817  -0.169   0.028 |\n",
      "|     Ctt |  -0.254   0.391   1.000  -0.005  -0.040  -0.028 |\n",
      "|  jpsi_p |   0.902  -0.817  -0.005   1.000   0.041   0.019 |\n",
      "|  jpsi_s |   0.074  -0.169  -0.040   0.041   1.000  -0.004 |\n",
      "| psi2s_s |   0.130   0.028  -0.028   0.019  -0.004   1.000 |\n",
      "-------------------------------------------------------------\n",
      "Hesse errors: OrderedDict([(<zfit.Parameter 'psi2s_p' floating=True>, {'error': 0.2574778505665698}), (<zfit.Parameter 'Dbar_s' floating=True>, {'error': 0.8041361051173593}), (<zfit.Parameter 'Ctt' floating=True>, {'error': 0.800071724878314}), (<zfit.Parameter 'jpsi_p' floating=True>, {'error': 0.40940340284378474}), (<zfit.Parameter 'jpsi_s' floating=True>, {'error': 136.70046081025066}), (<zfit.Parameter 'psi2s_s' floating=True>, {'error': 41.38771918974419})])\n",
      "Toy 10/10\n",
      "Time taken: 27 min, 51 s\n",
      "Projected time left: \n"
     ]
    }
   ],
   "source": [
    "# zfit.run.numeric_checks = False   \n",
    "\n",
    "Ctt_list = []\n",
    "Ctt_error_list = []\n",
    "\n",
    "nr_of_toys = 10\n",
    "nevents = int(pdg[\"number_of_decays\"])\n",
    "nevents = pdg[\"number_of_decays\"]\n",
    "event_stack = 1000000\n",
    "# zfit.settings.set_verbosity(10)\n",
    "calls = int(nevents/event_stack + 1)\n",
    "\n",
    "total_samp = []\n",
    "\n",
    "start = time.time()\n",
    "\n",
    "sampler = total_f.create_sampler(n=event_stack)\n",
    "\n",
    "for toy in range(nr_of_toys):\n",
    "    \n",
    "    ### Generate data\n",
    "    \n",
    "    print(\"Toy {}: Generating data...\".format(toy))\n",
    "    \n",
    "    dirName = 'data/zfit_toys/toy_{0}'.format(toy)\n",
    "    \n",
    "    if not os.path.exists(dirName):\n",
    "        os.mkdir(dirName)\n",
    "        print(\"Directory \" , dirName ,  \" Created \")\n",
    "\n",
    "    for call in range(calls):\n",
    "\n",
    "        sampler.resample(n=event_stack)\n",
    "        s = sampler.unstack_x()\n",
    "        sam = zfit.run(s)\n",
    "#         clear_output(wait=True)\n",
    "\n",
    "        c = call + 1\n",
    "        \n",
    "        with open(\"data/zfit_toys/toy_{0}/{1}.pkl\".format(toy, call), \"wb\") as f:\n",
    "            pkl.dump(sam, f, pkl.HIGHEST_PROTOCOL)\n",
    "            \n",
    "    print(\"Toy {}: Data generation finished\".format(toy))\n",
    "        \n",
    "    ### Load data\n",
    "    \n",
    "    print(\"Toy {}: Loading data...\".format(toy))\n",
    "\n",
    "    for call in range(calls):\n",
    "        with open(r\"data/zfit_toys/toy_0/{}.pkl\".format(call), \"rb\") as input_file:\n",
    "            sam = pkl.load(input_file)\n",
    "        total_samp = np.append(total_samp, sam)\n",
    "\n",
    "    total_samp = total_samp.astype('float64')\n",
    "\n",
    "    data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs)\n",
    "    \n",
    "    print(\"Toy {}: Loading data finished\".format(toy))\n",
    "\n",
    "    ### Fit data\n",
    "    \n",
    "    print(\"Toy {}: Fitting pdf...\".format(toy))\n",
    "\n",
    "    for param in total_f.get_dependents():\n",
    "        param.randomize()\n",
    "\n",
    "    nll = zfit.loss.UnbinnedNLL(model=total_f, data=data, fit_range = (jpsi_mass+50.0, psi2s_mass-50.0))\n",
    "\n",
    "    minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5)\n",
    "    # minimizer._use_tfgrad = False\n",
    "    result = minimizer.minimize(nll)\n",
    "    \n",
    "    print(\"Toy {}: Fitting finished\".format(toy))\n",
    "\n",
    "    print(\"Function minimum:\", result.fmin)\n",
    "    print(\"Hesse errors:\", result.hesse())\n",
    "    \n",
    "    params = result.params\n",
    "    Ctt_list.append(params[Ctt]['value'])\n",
    "    Ctt_error_list.append(params[Ctt]['minuit_hesse']['error'])\n",
    "\n",
    "    print(\"Toy {0}/{1}\".format(toy+1, nr_of_toys))\n",
    "    print(\"Time taken: {}\".format(display_time(int(time.time() - start))))\n",
    "    print(\"Projected time left: {}\".format(display_time(int((time.time() - start)/(c+calls*(toy))*((nr_of_toys-toy)*calls-c)))))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mean Ctt value = -0.4955320725102208\n",
      "Mean Ctt error = 0.7951298069508159\n"
     ]
    }
   ],
   "source": [
    "print('Mean Ctt value = {}'.format(np.mean(Ctt_list)))\n",
    "print('Mean Ctt error = {}'.format(np.mean(Ctt_error_list)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}