diff --git a/.ipynb_checkpoints/raremodel-nb-checkpoint.ipynb b/.ipynb_checkpoints/raremodel-nb-checkpoint.ipynb index a4e9462..b2495bc 100644 --- a/.ipynb_checkpoints/raremodel-nb-checkpoint.ipynb +++ b/.ipynb_checkpoints/raremodel-nb-checkpoint.ipynb @@ -1941,7 +1941,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 48, "metadata": { "scrolled": true }, @@ -1952,50 +1952,14 @@ "text": [ "WARNING:tensorflow:From C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\sample.py:163: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", - "Use tf.cast instead.\n", - "Step: 1/11\n", - "Current Ctt: 0.0\n", - "Ctt floating: True\n", - "Toy 0/1 - Fit 0/5\n", - "------------------------------------------------------------------\n", - "| FCN = 2.977E+05 | Ncalls=1285 (1285 total) |\n", - "| EDM = 0.000105 (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", - "Step: 1/11\n", - "Current Ctt: 0.0\n", - "Ctt floating: True\n", - "Toy 0/1 - Fit 1/5\n" - ] - }, - { - "ename": "RuntimeError", - "evalue": "exception was raised in user function\nUser function arguments:\n p4160_s = +2.119363\n rho_p = -0.447764\n p4160_p = -2.229073\n psi2s_p = +1.949040\n p4040_p = -3.142631\n bplus_2 = +0.271685\n jpsi_p = +1.695023\n Dbar_p = -4.211679\n p3770_s = +2.169347\n DDstar_p = -0.888402\n omega_s = +8.642103\n Dbar_s = +0.300000\n omega_p = -5.921044\n phi_p = +0.634553\n p3770_p = +3.029698\n DDstar_s = -0.300000\n p4415_s = +1.310081\n phi_s = +19.818317\n p4415_p = -2.586828\n bplus_0 = -0.489758\n bplus_1 = +0.923919\n Ctt = +0.196407\n rho_s = +1.120975\n p4040_s = +1.079351\nOriginal python exception in user function:\nKeyboardInterrupt: \n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\minimizer_minuit.py\", line 101, in func\n loss_evaluated = self.sess.run(loss_val)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 929, in run\n run_metadata_ptr)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1152, in _run\n feed_dict_tensor, options, run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1328, in _do_run\n run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1334, in _do_call\n return fn(*args)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1319, in _run_fn\n options, feed_dict, fetch_list, target_list, run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1407, in _call_tf_sessionrun\n run_metadata)\n", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mRuntimeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 94\u001b[0m \u001b[0mminimizer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mzfit\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mminimize\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mMinuitMinimizer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mverbosity\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 95\u001b[0m \u001b[1;31m# minimizer._use_tfgrad = False\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 96\u001b[1;33m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mminimizer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mminimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnll\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 97\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 98\u001b[0m \u001b[1;31m# print(\"Function minimum:\", result.fmin)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\baseminimizer.py\u001b[0m in \u001b[0;36mminimize\u001b[1;34m(self, loss, params)\u001b[0m\n\u001b[0;32m 205\u001b[0m \u001b[0mtuple\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstack\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0menter_context\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mparam\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mset_sess\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msess\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mparam\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 206\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 207\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_hook_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 208\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mFailMinimizeNaN\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merror\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# iminuit raises RuntimeError if user raises Error\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 209\u001b[0m \u001b[0mfail_result\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstrategy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit_result\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\baseminimizer.py\u001b[0m in \u001b[0;36m_hook_minimize\u001b[1;34m(self, loss, params)\u001b[0m\n\u001b[0;32m 214\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 215\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_hook_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 216\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 217\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 218\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_call_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\baseminimizer.py\u001b[0m in \u001b[0;36m_call_minimize\u001b[1;34m(self, loss, params)\u001b[0m\n\u001b[0;32m 218\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_call_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 219\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 220\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 221\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mNotImplementedError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merror\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 222\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\minimizer_minuit.py\u001b[0m in \u001b[0;36m_minimize\u001b[1;34m(self, loss, params)\u001b[0m\n\u001b[0;32m 136\u001b[0m minimizer_setter)\n\u001b[0;32m 137\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_minuit_minimizer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mminimizer\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 138\u001b[1;33m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mminimizer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmigrad\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m**\u001b[0m\u001b[0mminimize_options\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 139\u001b[0m \u001b[0mparams_result\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mp_dict\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mp_dict\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 140\u001b[0m \u001b[0mresult_vals\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mres\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"value\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mres\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mparams_result\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32miminuit\\_libiminuit.pyx\u001b[0m in \u001b[0;36miminuit._libiminuit.Minuit.migrad\u001b[1;34m()\u001b[0m\n", - "\u001b[1;31mRuntimeError\u001b[0m: exception was raised in user function\nUser function arguments:\n p4160_s = +2.119363\n rho_p = -0.447764\n p4160_p = -2.229073\n psi2s_p = +1.949040\n p4040_p = -3.142631\n bplus_2 = +0.271685\n jpsi_p = +1.695023\n Dbar_p = -4.211679\n p3770_s = +2.169347\n DDstar_p = -0.888402\n omega_s = +8.642103\n Dbar_s = +0.300000\n omega_p = -5.921044\n phi_p = +0.634553\n p3770_p = +3.029698\n DDstar_s = -0.300000\n p4415_s = +1.310081\n phi_s = +19.818317\n p4415_p = -2.586828\n bplus_0 = -0.489758\n bplus_1 = +0.923919\n Ctt = +0.196407\n rho_s = +1.120975\n p4040_s = +1.079351\nOriginal python exception in user function:\nKeyboardInterrupt: \n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\minimizer_minuit.py\", line 101, in func\n loss_evaluated = self.sess.run(loss_val)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 929, in run\n run_metadata_ptr)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1152, in _run\n feed_dict_tensor, options, run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1328, in _do_run\n run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1334, in _do_call\n return fn(*args)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1319, in _run_fn\n options, feed_dict, fetch_list, target_list, run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1407, in _call_tf_sessionrun\n run_metadata)\n" + "Use tf.cast instead.\n" ] } ], "source": [ "# zfit.run.numeric_checks = False \n", "\n", - "load = False\n", + "load = True\n", "\n", "bo5 = True\n", "\n", @@ -2033,7 +1997,6 @@ "\n", "__ = 0\n", "\n", - "\n", "#-----------------------------------------------------\n", "\n", "if not load:\n", @@ -2052,51 +2015,53 @@ " \n", " if bo5:\n", " \n", - " while len(Nll_list[-1])/bo5_set < nr_of_toys:\n", + " if __ < 6:\n", + " \n", + " while len(Nll_list[-1])/bo5_set < nr_of_toys:\n", "\n", - " print('Step: {0}/{1}'.format(__, ste))\n", + " print('Step: {0}/{1}'.format(__, ste))\n", "\n", - " print('Current Ctt: {0}'.format(Ctt_step))\n", - " print('Ctt floating: {0}'.format(floaty))\n", + " print('Current Ctt: {0}'.format(Ctt_step))\n", + " print('Ctt floating: {0}'.format(floaty))\n", "\n", - " print('Toy {0}/{1} - Fit {2}/{3}'.format(int(len(Nll_list[-1])/bo5_set), nr_of_toys, len(Nll_list[-1]), bo5_set))\n", + " print('Toy {0}/{1} - Fit {2}/{3}'.format(int(len(Nll_list[-1])/bo5_set), nr_of_toys, len(Nll_list[-1]), bo5_set))\n", "\n", - " reset_param_values()\n", + " reset_param_values()\n", "\n", - " if floaty:\n", - " Ctt.set_value(Ctt_step)\n", - " else:\n", - " Ctt.set_value(0.0)\n", + " if floaty:\n", + " Ctt.set_value(Ctt_step)\n", + " else:\n", + " Ctt.set_value(0.0)\n", "\n", - " if newset:\n", - " sampler.resample(n=nevents)\n", - " s = sampler.unstack_x()\n", - " total_samp = zfit.run(s)\n", - " calls = 0\n", - " c = 1\n", - " newset = False\n", + " if newset:\n", + " sampler.resample(n=nevents)\n", + " s = sampler.unstack_x()\n", + " total_samp = zfit.run(s)\n", + " calls = 0\n", + " c = 1\n", + " newset = False\n", "\n", "\n", - " data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit)\n", + " data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit)\n", "\n", - " ### Fit data\n", + " ### Fit data\n", "\n", - " for param in total_f_fit.get_dependents():\n", - " param.randomize()\n", + " for param in total_f_fit.get_dependents():\n", + " param.randomize()\n", "\n", - " nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints)\n", + " nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints)\n", "\n", - " minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5)\n", - " # minimizer._use_tfgrad = False\n", - " result = minimizer.minimize(nll)\n", + " minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5)\n", + " # minimizer._use_tfgrad = False\n", + " result = minimizer.minimize(nll)\n", "\n", - " # print(\"Function minimum:\", result.fmin)\n", - " # print(\"Hesse errors:\", result.hesse())\n", + " # print(\"Function minimum:\", result.fmin)\n", + " # print(\"Hesse errors:\", result.hesse())\n", "\n", - " params = result.params\n", + " params = result.params\n", "\n", - " if result.converged:\n", - " Nll_list[-1].append(result.fmin)\n", + " if result.converged:\n", + " Nll_list[-1].append(result.fmin)\n", "\n", " else:\n", "\n", @@ -2154,7 +2119,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 49, "metadata": {}, "outputs": [ { @@ -2164,43 +2129,8 @@ "(22, 1)\n", "(22, 2)\n", "(22, 3)\n", - "2254611\n", "(22, 4)\n", - "(22, 5)\n", - "(22, 6)\n", - "(22, 7)\n", - "(22, 8)\n", - "(22, 9)\n", - "2254618\n", - "(22, 10)\n", - "(22, 11)\n", - "2254621\n", - "(22, 12)\n", - "(22, 13)\n", - "(22, 14)\n", - "(22, 15)\n", - "(22, 16)\n", - "(22, 17)\n", - "slurm-2254608.out\n", - "slurm-2254609.out\n", - "slurm-2254610.out\n", - "slurm-2254611.out\n", - "slurm-2254612.out\n", - "slurm-2254613.out\n", - "slurm-2254614.out\n", - "slurm-2254615.out\n", - "slurm-2254616.out\n", - "slurm-2254617.out\n", - "slurm-2254618.out\n", - "slurm-2254619.out\n", - "slurm-2254620.out\n", - "slurm-2254621.out\n", - "slurm-2254622.out\n", - "slurm-2254623.out\n", - "slurm-2254624.out\n", - "slurm-2254625.out\n", - "slurm-2254626.out\n", - "slurm-2254627.out\n" + "bo1\n" ] } ], @@ -2264,20 +2194,20 @@ "\n", "\n", "if not load:\n", - " \n", - " CLs_values = []\n", - " \n", - " for i in range(int(len(Nll_list)/2)):\n", - " CLs_values.append([])\n", - " for j in range(nr_of_toys):\n", - " CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j])\n", - " \n", + " \n", " if not os.path.exists(dirName):\n", " os.mkdir(dirName)\n", " print(\"Directory \" , dirName , \" Created \")\n", "\n", " with open(\"{}/{}-{}_{}s--CLs_Nll_list.pkl\".format(dirName, mi,ma,ste), \"wb\") as f:\n", " pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL)\n", + " \n", + " CLs_values = []\n", + " \n", + " for i in range(int(len(Nll_list)/2)):\n", + " CLs_values.append([])\n", + " for j in range(nr_of_toys):\n", + " CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j])\n", "\n", " with open(\"{}/{}-{}_{}s--CLs_list.pkl\".format(dirName, mi,ma,ste), \"wb\") as f:\n", " pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL)" @@ -2287,18 +2217,10 @@ "cell_type": "code", "execution_count": 51, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[297763.5594876504], [297746.64841404365], [297789.27553325286], [298009.1505843799], [297607.1352560189], [297946.41725542664], [297743.2276395804], [297746.19702565676], [297661.1715722469], [297643.5799308492], [297659.81889337697], [297709.2817569911], [297762.47125993785], [297817.7748216014], [297549.04609343264], [297889.4714059658], [297755.38809197885], [297957.7457254501], [297726.10922358127], [297884.90020829753], [297620.82176273526], [297646.6438885114]]\n" - ] - } - ], + "outputs": [], "source": [ "# print(CLs_values)\n", - "print(Nll_list)" + "# print(Nll_list)" ] }, { @@ -2310,12 +2232,12 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 56, "metadata": {}, "outputs": [ { "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEICAYAAABPgw/pAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAcjUlEQVR4nO3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BBYJC7f5r+YYqIZLCXXw4SU+sdurvvNLMxwEtAI+ARdy81swlAsbvPITbFciAww8wA/ubugyIct9RDX375JeXl5VRVVdX1UARo1qwZOTk5NG7cuK6HIp06BYlJZcoFd58LzK22bXzC1/3TPC7JQOXl5bRo0YLc3Fzi/7BLHXF3KisrKS8vJy8vr66HIxs3BonRO0Ulbaqqqjj00ENV5vWAmXHooYfqp6X6Ytu2IDEqdEkrlXn9ob+LeuSoo4LEqNBFRKI2f36QmJTm0EX2Re7Y9H7s1uqJA2s9Zv369VxxxRUUFRXRtGlTcnNzufvuu2nSpAlvvfUW5513HgAlJSWsW7eOM844I+l5hg0bRmlpKRdeeCEbN26kT58+9O+/f78qev3117nzzjt57rnnvra9trHU5LbbbuPhhx+mUaNG3HvvvZx22mn7NT6J0LnnBolRoUvWcHfOOecchg8fTmFhIRAryw0bNvDVV1/x5JNPfq3Qi4uLk5bo+vXreeutt/j444+DjPubxlKTsrIyCgsLKS0tZd26dfTv35/ly5fTqFGjCEcq++z++4Os56IpF8kar732Go0bN+bSSy/dvS0/P5/evXszduxY5s+fT35+Prfffjvjx49n+vTp5OfnM3369K+d59RTT+XTTz8lPz+f+fPnM2LECGbOnMmmTZs45phjWLZsGRC7i//DH/4AwMsvv0yvXr047rjjGDJkCJs3bwbgxRdfpH379vzwhz/kmWee2WPMO3bs2GMsn3/+OWeffTZdunShZ8+eLF68eI/nzZ49m6FDh9K0aVPy8vL4wQ9+wF//+te0XUtJs3q0OJdIRliyZAndu3dPum/ixIn07t2bkpISrr32WiZMmMC5555LSUkJ51b7cXjOnDkcddRRlJSU0Lt3793bW7ZsyX333ceIESMoLCxk48aNjBw5ks8++4ybb76ZP/3pT7z77rsUFBRw1113UVVVxciRI3n22WeZP38+69ev32NcTZo02WMsN9xwA926dWPx4sXceuut/OxnP9vjeWvXrqVtwqfg5OTksHbt2n29dBK1QItzacpFZC+ccsopzJgxg9GjR7No0SIAFixYQFlZGSeeeCIQu+vu1asXH3zwAXl5ebR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2tt7MxgKVwDkZV8HmMi1Ch9XWPreiU+9zG5K8b23ZZGZfcfd3zewrwHtxB8o3M+tGqswfcffH04sTtd865JIDMxsO3AJc4u4fZ6yaD4xK3+CjBOgLvBxHxnaU5H3OZZqLpMqcvmMs0NpPaJ1SejrvB4A17n5nxqpE7beuFM1BekqDHsCW9KKl7n59et1tpI6r7yT1Y9xT2d+lczGzrwP/B+gF/BWoc/fz0+sSuc8AZnYhcDd/m+biBzFHyjszexSoIDV97CbgduC3wGPAUcB/ASPdPTET7JnZmcAS4DXgi/TifyV1HD0x+61CFxFJCB1yERFJCBW6iEhCqNBFRBJChS4ikhAqdBGRhFChi4gkhApdRCQh/j/paS3vCad70QAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] @@ -2329,12 +2251,16 @@ "source": [ "l = []\n", "\n", + "if not os.path.exists('data/CLs/plots'):\n", + " os.mkdir('data/CLs/plots')\n", + " print(\"Directory \" , 'data/CLs/plots' , \" Created \")\n", + "\n", "for i in range(len(CLs_values)):\n", " plt.clf()\n", " plt.title('Ctt value: {:.2f}'.format(Ctt_steps[i]))\n", - " plt.hist(CLs_values[0], bins = 100, label = 'Ctt fixed to 0')\n", - " plt.hist(CLs_values[i], bins = 100, label = 'Ctt floating')\n", - " plt.axvline(x=np.mean(CLs_values[0]),color='red', linewidth=0.7, linestyle = 'dotted')\n", + " plt.hist(CLs_values[0], bins = 100, range = (-25, 25), label = 'Ctt fixed to 0')\n", + " plt.hist(CLs_values[i], bins = 100, range = (-25, 25), label = 'Ctt floating')\n", + " plt.axvline(x=np.mean(CLs_values[0]),color='red', linewidth=1.0, linestyle = 'dotted')\n", " plt.legend()\n", " plt.savefig('data/CLs/plots/CLs-BR({:.1E}).png'.format(BR_steps[i]))\n", " \n", @@ -2343,59 +2269,59 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "BR: 0.0\n", - "0.0\n", + "BR: 0.0000\n", + "1.0\n", "\n", "BR: 0.0001\n", - "2.0\n", + "1.0\n", "\n", "BR: 0.0002\n", - "2.0\n", - "\n", - "BR: 0.00030000000000000003\n", - "2.0\n", - "\n", - "BR: 0.0004\n", "0.0\n", "\n", - "BR: 0.0005\n", - "2.0\n", + "BR: 0.0003\n", + "1.0\n", "\n", - "BR: 0.0006000000000000001\n", - "2.0\n", + "BR: 0.0004\n", + "1.0\n", + "\n", + "BR: 0.0005\n", + "1.5\n", + "\n", + "BR: 0.0006\n", + "0.5\n", "\n", "BR: 0.0007\n", - "2.0\n", + "0.0\n", "\n", "BR: 0.0008\n", - "2.0\n", + "0.5\n", "\n", - "BR: 0.0009000000000000001\n", - "2.0\n", + "BR: 0.0009\n", + "0.5\n", "\n", - "BR: 0.001\n", - "2.0\n", + "BR: 0.0010\n", + "0.5\n", "\n" ] } ], "source": [ "for s in range(len(l)):\n", - " print('BR: {}'.format(BR_steps[s]))\n", + " print('BR: {:.4f}'.format(BR_steps[s]))\n", " print(2*l[s]/len(CLs_values[0]))\n", " print()" ] }, { "cell_type": "code", - "execution_count": 54, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ diff --git a/data/CLs/finished/f1d1/2254881/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2254881/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..9311452 --- /dev/null +++ b/data/CLs/finished/f1d1/2254881/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2254881/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2254881/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..725153c --- /dev/null +++ b/data/CLs/finished/f1d1/2254881/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2254881/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2254881/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..69f9229 --- /dev/null +++ b/data/CLs/finished/f1d1/2254881/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2254881/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2254881/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..1e18f87 --- /dev/null +++ b/data/CLs/finished/f1d1/2254881/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2254881/helperfunctions.py b/data/CLs/finished/f1d1/2254881/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2254881/helperfunctions.py @@ -0,0 +1,33 @@ +# some helperfunctions + +import matplotlib +matplotlib.use("agg") +import matplotlib.pyplot as plt + +#Dislpay time (e.g. while generating points) + +display_intervals = ( + ('w', 604800), # 60 * 60 * 24 * 7 + ('d', 86400), # 60 * 60 * 24 + ('h', 3600), # 60 * 60 + ('min', 60), + ('s', 1), + ) + +def display_time(seconds, granularity=2): + result = [] + + for name, count in display_intervals: + value = seconds // count + if value: + seconds -= value * count + if value == 1: + name = name.rstrip('s') + result.append("{} {}".format(value, name)) + return ', '.join(result[:granularity]) + +def prepare_plot(title): + plt.title(title) + plt.grid() + plt.legend(loc = 'best') + plt.xlabel("q") diff --git a/data/CLs/finished/f1d1/2254881/pdg_const.py b/data/CLs/finished/f1d1/2254881/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2254881/pdg_const.py @@ -0,0 +1,226 @@ +pdg = { + + + ###Particle masses### + + "mbstar" : 5415.4, + "mbstar0" : 5711.0, + "B0_M" : 5279.5, + "Bs_M" : 5366.7, + "Bplus_M" : 5279.3, + "Lb_M" : 5619.4, + "D0_M" : 1864.8, + "Dst_M" : 2010, + "pi_M" : 139.6, + "Jpsi_M" : 3096.9, + "Psi2s_M" : 3685.6, + "kaon_M" : 493.7, + "Ks_M" : 497.6, + "phi_M" : 1019.5, + "rho_M" : 775.26, + "rho_width" : 149.1, + "omega_M" : 782.65, + "omega_width" : 8.49, + + "muon_M" : 105.7, + "tau_M": 1776.86, + + "squark_M" : 95.0, + "bquark_M" : 4180.0, + "cquark_M" : 1275.0, + + "Bplus_tau" : 1.638e-12, + + ###Wilson coefficients### + + "C1" : -0.257, + "C2" : 1.009, + "C3" : -0.005, + "C4" : -0.078, + + "C7eff" : -0.306, + "C9eff" : 4.211, + "C10eff" : -4.103, + +# "C7eff": 0.0, +# "C9eff": 0.0, +# "C10eff": 0.0, + + ###Other constants + + "GF" : 1.1663787e-5, + "alpha_ew" : 1.0/137.0, + "Vts" : 0.0394, + "Vtb" : 1.019, + "number_of_decays": 5404696, + + #Formfactor z coefficients + + #"b0" : [0.285, 0.19, -0.17], + #"bplus" : [0.437, -1.41, -2.5], + #"bT" : [0.440, -1.47, -2.7] + + "b0" : [0.292, 0.281, 0.150], + "bplus" : [0.466, -0.885, -0.213], + "bT" : [0.460, -1.089, -1.114], + + "NR_BR": 4.37e-7, + "NR_auc": 0.00133, + + #Resonances format(mass, width, phase, scale) + + # pre scaling + +# "rho": (775.26, 149.0, -0.35, 1.0), + +# "omega": (782.7, 8.5, 0.26, 1.0), + +# "phi": (1019.46, 4.25, 0.5, 1.0), + +# "jpsi": (3096.0, 0.09, -1.5, 2e-2), +# "jpsi_auc": 0.2126825758464027, + +# "psi2s": (3686.0, 0.3, -1.5, 3.14e-3), +# "psi2s_auc": 2.802257483178487e-10, + +# "p3770": (3773.0, 27.2, -2.13, 1.0e-3), + +# "p4040": (4039.0, 80.0, -2.52, 2.0), + +# "p4160": (4191.0, 70.0, -1.9, 2.2), + +# "p4415": (4421.0, 62.0, -2.52, 1.0), + + + # after scaling (Phase combination --) + + +# "rho": (743.2, 149.0, -0.22, 1.05), + +# "omega": (782.7, 8.5, 0.38, 6.8), + +# "phi": (1013.5, 4.25, 0.62, 19.2), + +# "jpsi": (3096.1, 0.09, 1.63, 9897.0), +# "jpsi_auc": 0.2126825758464027, +# "jpsi_phase_unc": 0.05, + +# "psi2s": (3686.0, 0.3, 1.8, 1396.0), +# "psi2s_auc": 0.0151332263, +# "psi2s_phase_unc": 0.1, + +# "p3770": (3773.0, 27.2, -2.95, 2.5), + +# "p4040": (4039.0, 80.0, -2.75, 1.01), + +# "p4160": (4191.0, 70.0, -2.28, 2.2), + +# "p4415": (4421.0, 62.0, -2.31, 1.24), + + # Phase combination of paper ++ + +# "rho": (743.2, 149.0, -0.35, 1.05), + +# "omega": (782.7, 8.5, 0.26, 6.8), + +# "phi": (1013.5, 4.25, 0.47, 19.2), + +# "jpsi": (3096.1, 0.09, -1.66, 9897.0), +# "jpsi_auc": 0.2126825758464027, +# "jpsi_phase_unc": 0.05, + +# "psi2s": (3686.0, 0.3, -1.93, 1396.0), +# "psi2s_auc": 0.0151332263, +# "psi2s_phase_unc": 0.1, + +# "p3770": (3773.0, 27.2, -2.13, 2.5), + +# "p4040": (4039.0, 80.0, -2.52, 1.01), + +# "p4160": (4191.0, 70.0, -1.90, 2.2), + +# "p4415": (4421.0, 62.0, -2.52, 1.24), + + # Phase combination of paper +- + + # "rho": (743.2, 149.0, -0.26, 1.05), + # + # "omega": (782.7, 8.5, 0.35, 6.8), + # + # "phi": (1013.5, 4.25, 0.58, 19.2), + # + # "jpsi": (3096.1, 0.09, 1.47, 9897.0), + # "jpsi_auc": 0.2126825758464027, + # "jpsi_phase_unc": 0.05, + # + # "psi2s": (3686.0, 0.3, -2.21, 1396.0), + # "psi2s_auc": 0.0151332263, + # "psi2s_phase_unc": 0.1, + # + # "p3770": (3773.0, 27.2, -2.140, 2.5), + # + # "p4040": (4039.0, 80.0, -2.64, 1.01), + # + # "p4160": (4191.0, 70.0, -2.11, 2.2), + # + # "p4415": (4421.0, 62.0, -2.42, 1.24), + + # Phase combination of paper -+ + + "rho": (743.2, 149.0, -0.30, 1.05), + + "omega": (782.7, 8.5, 0.30, 6.8), + + "phi": (1013.5, 4.25, 0.51, 19.2), + + "jpsi": (3096.1, 0.09, -1.5, 9897.0), + "jpsi_auc": 0.2126825758464027, + "jpsi_phase_unc": 0.05, + + "psi2s": (3686.0, 0.3, 2.08, 1396.0), + "psi2s_auc": 0.0151332263, + "psi2s_phase_unc": 0.1, + + "p3770": (3773.0, 27.2, -2.89, 2.5), + + "p4040": (4039.0, 80.0, -2.69, 1.01), + + "p4160": (4191.0, 70.0, -2.13, 2.2), + + "p4415": (4421.0, 62.0, -2.43, 1.24), + + + # zeroing resonances + +# "rho": (775.26, 149.0, -0.35, 0.0), +# "omega": (782.7, 8.5, 0.26, 0.0), +# "phi": (1019.46, 4.25, 0.5, 0.0), +# "jpsi": (3096.0, 0.09, -1.5, 0.0), +# "psi2s": (3686.0, 0.3, -1.5, 0.0), +# "p3770": (3773.0, 27.2, -2.13, 0.0), +# "p4040": (4039.0, 80.0, -2.52, 0.0), +# "p4160": (4147.0, 22.0, -1.9, 0.0), +# "p4415": (4421.0, 62.0, -2.52, 0.0), + + # 2P contributions format(mass, amp, phase) + +# "D_bar": ( + + #general + + "rho_BR": 1.7e-10, + "omega_BR": 4.9e-10, + "phi_BR": 2.5e-9, + "jpsi_BR": 6.02e-5, + "psi2s_BR": 4.97e-6, + "p3770_BR": 1.38e-9, + "p4040_BR": 4.2e-10, + "p4160_BR": 2.6e-9, + "p4415_BR": 6.1e-10, + +# Estimates + "Dbar_scale": 1.46, #with phase = pi + + "DDstar_scale": 2.41, #with phase = pi + + } diff --git a/data/CLs/finished/f1d1/2254881/raremodel-nb1.py b/data/CLs/finished/f1d1/2254881/raremodel-nb1.py new file mode 100644 index 0000000..1a5d9be --- /dev/null +++ b/data/CLs/finished/f1d1/2254881/raremodel-nb1.py @@ -0,0 +1,1939 @@ +#!/usr/bin/env python +# coding: utf-8 + +# # Import + +# In[1]: + + +import os + +# os.environ["CUDA_VISIBLE_DEVICES"] = "-1" + +import numpy as np +from pdg_const import pdg +import matplotlib +import matplotlib.pyplot as plt +import pickle as pkl +import sys +import time +from helperfunctions import display_time, prepare_plot +import cmath as c +import scipy.integrate as integrate +from scipy.optimize import fminbound +from array import array as arr +import collections +from itertools import compress +import tensorflow as tf +import zfit +from zfit import ztf +# from IPython.display import clear_output +import os +import tensorflow_probability as tfp +tfd = tfp.distributions + + +# In[2]: + + +# chunksize = 10000 +# zfit.run.chunking.active = True +# zfit.run.chunking.max_n_points = chunksize + + +# # Build model and graphs +# ## Create graphs + +# In[ ]: + + + + + +# In[3]: + + +def formfactor(q2, subscript, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): #returns real value + #check if subscript is viable + + if subscript != "0" and subscript != "+" and subscript != "T": + raise ValueError('Wrong subscript entered, choose either 0, + or T') + + #get constants + + mK = ztf.constant(pdg['Ks_M']) + mbstar0 = ztf.constant(pdg["mbstar0"]) + mbstar = ztf.constant(pdg["mbstar"]) + + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mB = ztf.constant(pdg['Bplus_M']) + + #N comes from derivation in paper + + N = 3 + + #some helperfunctions + + tpos = (mB - mK)**2 + tzero = (mB + mK)*(ztf.sqrt(mB)-ztf.sqrt(mK))**2 + + z_oben = ztf.sqrt(tpos - q2) - ztf.sqrt(tpos - tzero) + z_unten = ztf.sqrt(tpos - q2) + ztf.sqrt(tpos - tzero) + z = tf.divide(z_oben, z_unten) + + #calculate f0 + + if subscript == "0": + prefactor = 1/(1 - q2/(mbstar0**2)) + _sum = 0 + b0 = [b0_0, b0_1, b0_2] + + for i in range(N): + _sum += b0[i]*(tf.pow(z,i)) + + return ztf.to_complex(prefactor * _sum) + + #calculate f+ or fT + + else: + prefactor = 1/(1 - q2/(mbstar**2)) + _sum = 0 + + if subscript == "T": + bT = [bT_0, bT_1, bT_2] + for i in range(N): + _sum += bT[i] * (tf.pow(z, i) - ((-1)**(i-N)) * (i/N) * tf.pow(z, N)) + else: + bplus = [bplus_0, bplus_1, bplus_2] + for i in range(N): + _sum += bplus[i] * (tf.pow(z, i) - ((-1)**(i-N)) * (i/N) * tf.pow(z, N)) + + return ztf.to_complex(prefactor * _sum) + +def resonance(q, _mass, width, phase, scale): + + q2 = tf.pow(q, 2) + + mmu = ztf.constant(pdg['muon_M']) + + p = 0.5 * ztf.sqrt(q2 - 4*(mmu**2)) + + p0 = 0.5 * ztf.sqrt(_mass**2 - 4*mmu**2) + + gamma_j = tf.divide(p, q) * _mass * width / p0 + + #Calculate the resonance + + _top = tf.complex(_mass * width, ztf.constant(0.0)) + + _bottom = tf.complex(_mass**2 - q2, -_mass*gamma_j) + + com = _top/_bottom + + #Rotate by the phase + + r = ztf.to_complex(scale*tf.abs(com)) + + _phase = tf.angle(com) + + _phase += phase + + com = r * tf.exp(tf.complex(ztf.constant(0.0), _phase)) + + return com + + +def axiv_nonres(q, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): + + GF = ztf.constant(pdg['GF']) + alpha_ew = ztf.constant(pdg['alpha_ew']) + Vtb = ztf.constant(pdg['Vtb']) + Vts = ztf.constant(pdg['Vts']) + C10eff = ztf.constant(pdg['C10eff']) + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mK = ztf.constant(pdg['Ks_M']) + mB = ztf.constant(pdg['Bplus_M']) + + q2 = tf.pow(q, 2) + + #Some helperfunctions + + beta = 1. - 4. * mmu**2. / q2 + + 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.) + + #prefactor in front of whole bracket + + prefactor1 = GF**2. *alpha_ew**2. * (tf.abs(Vtb*Vts))**2. * kabs * beta / (128. * np.pi**5.) + + #left term in bracket + + bracket_left = 2./3. * tf.pow(kabs,2) * tf.pow(beta,2) * tf.pow(tf.abs(ztf.to_complex(C10eff)*formfactor(q2, "+", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)),2) + + #middle term in bracket + + _top = 4. * mmu**2. * (mB**2. - mK**2.) * (mB**2. - mK**2.) + + _under = q2 * mB**2. + + bracket_middle = _top/_under *tf.pow(tf.abs(ztf.to_complex(C10eff) * formfactor(q2, "0", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)), 2) + + #Note sqrt(q2) comes from derivation as we use q2 and plot q + + return prefactor1 * (bracket_left + bracket_middle) * 2 * q + +def vec(q, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): + + q2 = tf.pow(q, 2) + + GF = ztf.constant(pdg['GF']) + alpha_ew = ztf.constant(pdg['alpha_ew']) + Vtb = ztf.constant(pdg['Vtb']) + Vts = ztf.constant(pdg['Vts']) + C7eff = ztf.constant(pdg['C7eff']) + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mK = ztf.constant(pdg['Ks_M']) + mB = ztf.constant(pdg['Bplus_M']) + + #Some helperfunctions + + beta = 1. - 4. * mmu**2. / q2 + + 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) + + #prefactor in front of whole bracket + + prefactor1 = GF**2. *alpha_ew**2. * (tf.abs(Vtb*Vts))**2 * kabs * beta / (128. * np.pi**5.) + + #right term in bracket + + prefactor2 = tf.pow(kabs,2) * (1. - 1./3. * beta) + + abs_bracket = tf.pow(tf.abs(c9eff(q, funcs) * formfactor(q2, "+", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + ztf.to_complex(2.0 * C7eff * (mb + ms)/(mB + mK)) * formfactor(q2, "T", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)),2) + + bracket_right = prefactor2 * abs_bracket + + #Note sqrt(q2) comes from derivation as we use q2 and plot q + + return prefactor1 * bracket_right * 2 * q + +def c9eff(q, funcs): + + C9eff_nr = ztf.to_complex(ztf.constant(pdg['C9eff'])) + + c9 = C9eff_nr + funcs + + return c9 + + +# In[4]: + + +def G(y): + + def inner_rect_bracket(q): + return tf.log(ztf.to_complex((1+tf.sqrt(q))/(1-tf.sqrt(q)))-tf.complex(ztf.constant(0), -1*ztf.constant(np.pi))) + + def inner_right(q): + return ztf.to_complex(2 * tf.atan(1/tf.sqrt(tf.math.real(-q)))) + + big_bracket = tf.where(tf.math.real(y) > ztf.constant(0.0), inner_rect_bracket(y), inner_right(y)) + + return ztf.to_complex(tf.sqrt(tf.abs(y))) * big_bracket + +def h_S(m, q): + + 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))) + +def h_P(m, q): + + 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) + +def two_p_ccbar(mD, m_D_bar, m_D_star, q): + + + #Load constants + nu_D_bar = ztf.to_complex(pdg["nu_D_bar"]) + nu_D = ztf.to_complex(pdg["nu_D"]) + nu_D_star = ztf.to_complex(pdg["nu_D_star"]) + + phase_D_bar = ztf.to_complex(pdg["phase_D_bar"]) + phase_D = ztf.to_complex(pdg["phase_D"]) + phase_D_star = ztf.to_complex(pdg["phase_D_star"]) + + #Calculation + left_part = nu_D_bar * tf.exp(tf.complex(ztf.constant(0.0), phase_D_bar)) * h_S(m_D_bar, q) + + right_part_D = nu_D * tf.exp(tf.complex(ztf.constant(0.0), phase_D)) * h_P(m_D, q) + + right_part_D_star = nu_D_star * tf.exp(tf.complex(ztf.constant(0.0), phase_D_star)) * h_P(m_D_star, q) + + return left_part + right_part_D + right_part_D_star + + +# ## Build pdf + +# In[5]: + + +class total_pdf_cut(zfit.pdf.ZPDF): + _N_OBS = 1 # dimension, can be omitted + _PARAMS = ['b0_0', 'b0_1', 'b0_2', + 'bplus_0', 'bplus_1', 'bplus_2', + 'bT_0', 'bT_1', 'bT_2', + 'rho_mass', 'rho_scale', 'rho_phase', 'rho_width', + 'jpsi_mass', 'jpsi_scale', 'jpsi_phase', 'jpsi_width', + 'psi2s_mass', 'psi2s_scale', 'psi2s_phase', 'psi2s_width', + 'p3770_mass', 'p3770_scale', 'p3770_phase', 'p3770_width', + 'p4040_mass', 'p4040_scale', 'p4040_phase', 'p4040_width', + 'p4160_mass', 'p4160_scale', 'p4160_phase', 'p4160_width', + 'p4415_mass', 'p4415_scale', 'p4415_phase', 'p4415_width', + 'omega_mass', 'omega_scale', 'omega_phase', 'omega_width', + 'phi_mass', 'phi_scale', 'phi_phase', 'phi_width', + 'Dbar_mass', 'Dbar_scale', 'Dbar_phase', + 'Dstar_mass', 'DDstar_scale', 'DDstar_phase', 'D_mass', + 'tau_mass', 'C_tt'] +# the name of the parameters + + def _unnormalized_pdf(self, x): + + x = x.unstack_x() + + b0 = [self.params['b0_0'], self.params['b0_1'], self.params['b0_2']] + bplus = [self.params['bplus_0'], self.params['bplus_1'], self.params['bplus_2']] + bT = [self.params['bT_0'], self.params['bT_1'], self.params['bT_2']] + + def rho_res(q): + return resonance(q, _mass = self.params['rho_mass'], scale = self.params['rho_scale'], + phase = self.params['rho_phase'], width = self.params['rho_width']) + + def omega_res(q): + return resonance(q, _mass = self.params['omega_mass'], scale = self.params['omega_scale'], + phase = self.params['omega_phase'], width = self.params['omega_width']) + + def phi_res(q): + return resonance(q, _mass = self.params['phi_mass'], scale = self.params['phi_scale'], + phase = self.params['phi_phase'], width = self.params['phi_width']) + + def jpsi_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['jpsi_mass'], 2)) * resonance(q, _mass = self.params['jpsi_mass'], + scale = self.params['jpsi_scale'], + phase = self.params['jpsi_phase'], + width = self.params['jpsi_width']) + def psi2s_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['psi2s_mass'], 2)) * resonance(q, _mass = self.params['psi2s_mass'], + scale = self.params['psi2s_scale'], + phase = self.params['psi2s_phase'], + width = self.params['psi2s_width']) + def p3770_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p3770_mass'], 2)) * resonance(q, _mass = self.params['p3770_mass'], + scale = self.params['p3770_scale'], + phase = self.params['p3770_phase'], + width = self.params['p3770_width']) + + def p4040_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4040_mass'], 2)) * resonance(q, _mass = self.params['p4040_mass'], + scale = self.params['p4040_scale'], + phase = self.params['p4040_phase'], + width = self.params['p4040_width']) + + def p4160_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4160_mass'], 2)) * resonance(q, _mass = self.params['p4160_mass'], + scale = self.params['p4160_scale'], + phase = self.params['p4160_phase'], + width = self.params['p4160_width']) + + def p4415_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4415_mass'], 2)) * resonance(q, _mass = self.params['p4415_mass'], + scale = self.params['p4415_scale'], + phase = self.params['p4415_phase'], + width = self.params['p4415_width']) + + def P2_D(q): + 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)) + 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['Dstar_mass'], q)) + ztf.to_complex(h_P(self.params['D_mass'], q))) + return Dbar_contrib + DDstar_contrib + + def ttau_cusp(q): + 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))) + + + 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) + + vec_f = vec(x, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + axiv_nr = axiv_nonres(x, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + tot = vec_f + axiv_nr + + #Cut out jpsi and psi2s + + tot = tf.where(tf.math.logical_or(x < ztf.constant(jpsi_mass-60.), x > ztf.constant(jpsi_mass+70.)), tot, 0.0*tot) + + tot = tf.where(tf.math.logical_or(x < ztf.constant(psi2s_mass-50.), x > ztf.constant(psi2s_mass+50.)), tot, 0.0*tot) + + return tot + +class total_pdf_full(zfit.pdf.ZPDF): + _N_OBS = 1 # dimension, can be omitted + _PARAMS = ['b0_0', 'b0_1', 'b0_2', + 'bplus_0', 'bplus_1', 'bplus_2', + 'bT_0', 'bT_1', 'bT_2', + 'rho_mass', 'rho_scale', 'rho_phase', 'rho_width', + 'jpsi_mass', 'jpsi_scale', 'jpsi_phase', 'jpsi_width', + 'psi2s_mass', 'psi2s_scale', 'psi2s_phase', 'psi2s_width', + 'p3770_mass', 'p3770_scale', 'p3770_phase', 'p3770_width', + 'p4040_mass', 'p4040_scale', 'p4040_phase', 'p4040_width', + 'p4160_mass', 'p4160_scale', 'p4160_phase', 'p4160_width', + 'p4415_mass', 'p4415_scale', 'p4415_phase', 'p4415_width', + 'omega_mass', 'omega_scale', 'omega_phase', 'omega_width', + 'phi_mass', 'phi_scale', 'phi_phase', 'phi_width', + 'Dbar_mass', 'Dbar_scale', 'Dbar_phase', + 'Dstar_mass', 'DDstar_scale', 'DDstar_phase', 'D_mass', + 'tau_mass', 'C_tt'] +# the name of the parameters + + def _unnormalized_pdf(self, x): + + x = x.unstack_x() + + b0 = [self.params['b0_0'], self.params['b0_1'], self.params['b0_2']] + bplus = [self.params['bplus_0'], self.params['bplus_1'], self.params['bplus_2']] + bT = [self.params['bT_0'], self.params['bT_1'], self.params['bT_2']] + + def rho_res(q): + return resonance(q, _mass = self.params['rho_mass'], scale = self.params['rho_scale'], + phase = self.params['rho_phase'], width = self.params['rho_width']) + + def omega_res(q): + return resonance(q, _mass = self.params['omega_mass'], scale = self.params['omega_scale'], + phase = self.params['omega_phase'], width = self.params['omega_width']) + + def phi_res(q): + return resonance(q, _mass = self.params['phi_mass'], scale = self.params['phi_scale'], + phase = self.params['phi_phase'], width = self.params['phi_width']) + + def jpsi_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['jpsi_mass'], 2)) * resonance(q, _mass = self.params['jpsi_mass'], + scale = self.params['jpsi_scale'], + phase = self.params['jpsi_phase'], + width = self.params['jpsi_width']) + def psi2s_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['psi2s_mass'], 2)) * resonance(q, _mass = self.params['psi2s_mass'], + scale = self.params['psi2s_scale'], + phase = self.params['psi2s_phase'], + width = self.params['psi2s_width']) + def p3770_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p3770_mass'], 2)) * resonance(q, _mass = self.params['p3770_mass'], + scale = self.params['p3770_scale'], + phase = self.params['p3770_phase'], + width = self.params['p3770_width']) + + def p4040_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4040_mass'], 2)) * resonance(q, _mass = self.params['p4040_mass'], + scale = self.params['p4040_scale'], + phase = self.params['p4040_phase'], + width = self.params['p4040_width']) + + def p4160_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4160_mass'], 2)) * resonance(q, _mass = self.params['p4160_mass'], + scale = self.params['p4160_scale'], + phase = self.params['p4160_phase'], + width = self.params['p4160_width']) + + def p4415_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4415_mass'], 2)) * resonance(q, _mass = self.params['p4415_mass'], + scale = self.params['p4415_scale'], + phase = self.params['p4415_phase'], + width = self.params['p4415_width']) + + def P2_D(q): + 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)) + 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['Dstar_mass'], q)) + ztf.to_complex(h_P(self.params['D_mass'], q))) + return Dbar_contrib + DDstar_contrib + + def ttau_cusp(q): + 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))) + + + 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) + + vec_f = vec(x, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + axiv_nr = axiv_nonres(x, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + tot = vec_f + axiv_nr + + #Cut out jpsi and psi2s + +# tot = tf.where(tf.math.logical_or(x < ztf.constant(jpsi_mass-60.), x > ztf.constant(jpsi_mass+70.)), tot, 0.0*tot) + +# tot = tf.where(tf.math.logical_or(x < ztf.constant(psi2s_mass-50.), x > ztf.constant(psi2s_mass+50.)), tot, 0.0*tot) + + return tot + + +# ## Setup parameters + +# In[6]: + + +# formfactors + +b0_0 = zfit.Parameter("b0_0", ztf.constant(0.292), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +b0_1 = zfit.Parameter("b0_1", ztf.constant(0.281), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +b0_2 = zfit.Parameter("b0_2", ztf.constant(0.150), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) + +bplus_0 = zfit.Parameter("bplus_0", ztf.constant(0.466), lower_limit = -2.0, upper_limit= 2.0) +bplus_1 = zfit.Parameter("bplus_1", ztf.constant(-0.885), lower_limit = -2.0, upper_limit= 2.0) +bplus_2 = zfit.Parameter("bplus_2", ztf.constant(-0.213), lower_limit = -2.0, upper_limit= 2.0) + +bT_0 = zfit.Parameter("bT_0", ztf.constant(0.460), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +bT_1 = zfit.Parameter("bT_1", ztf.constant(-1.089), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +bT_2 = zfit.Parameter("bT_2", ztf.constant(-1.114), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) + + +#rho + +rho_mass, rho_width, rho_phase, rho_scale = pdg["rho"] + +rho_m = zfit.Parameter("rho_m", ztf.constant(rho_mass), floating = False) #lower_limit = rho_mass - rho_width, upper_limit = rho_mass + rho_width) +rho_w = zfit.Parameter("rho_w", ztf.constant(rho_width), floating = False) +rho_p = zfit.Parameter("rho_p", ztf.constant(rho_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +rho_s = zfit.Parameter("rho_s", ztf.constant(rho_scale), lower_limit=rho_scale-np.sqrt(rho_scale), upper_limit=rho_scale+np.sqrt(rho_scale)) + +#omega + +omega_mass, omega_width, omega_phase, omega_scale = pdg["omega"] + +omega_m = zfit.Parameter("omega_m", ztf.constant(omega_mass), floating = False) +omega_w = zfit.Parameter("omega_w", ztf.constant(omega_width), floating = False) +omega_p = zfit.Parameter("omega_p", ztf.constant(omega_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +omega_s = zfit.Parameter("omega_s", ztf.constant(omega_scale), lower_limit=omega_scale-np.sqrt(omega_scale), upper_limit=omega_scale+np.sqrt(omega_scale)) + + +#phi + +phi_mass, phi_width, phi_phase, phi_scale = pdg["phi"] + +phi_m = zfit.Parameter("phi_m", ztf.constant(phi_mass), floating = False) +phi_w = zfit.Parameter("phi_w", ztf.constant(phi_width), floating = False) +phi_p = zfit.Parameter("phi_p", ztf.constant(phi_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +phi_s = zfit.Parameter("phi_s", ztf.constant(phi_scale), lower_limit=phi_scale-np.sqrt(phi_scale), upper_limit=phi_scale+np.sqrt(phi_scale)) + +#jpsi + +jpsi_mass, jpsi_width, jpsi_phase, jpsi_scale = pdg["jpsi"] + +jpsi_m = zfit.Parameter("jpsi_m", ztf.constant(jpsi_mass), floating = False) +jpsi_w = zfit.Parameter("jpsi_w", ztf.constant(jpsi_width), floating = False) +jpsi_p = zfit.Parameter("jpsi_p", ztf.constant(jpsi_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +jpsi_s = zfit.Parameter("jpsi_s", ztf.constant(jpsi_scale), floating = False) #, lower_limit=jpsi_scale-np.sqrt(jpsi_scale), upper_limit=jpsi_scale+np.sqrt(jpsi_scale)) + +#psi2s + +psi2s_mass, psi2s_width, psi2s_phase, psi2s_scale = pdg["psi2s"] + +psi2s_m = zfit.Parameter("psi2s_m", ztf.constant(psi2s_mass), floating = False) +psi2s_w = zfit.Parameter("psi2s_w", ztf.constant(psi2s_width), floating = False) +psi2s_p = zfit.Parameter("psi2s_p", ztf.constant(psi2s_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +psi2s_s = zfit.Parameter("psi2s_s", ztf.constant(psi2s_scale), floating = False) #, lower_limit=psi2s_scale-np.sqrt(psi2s_scale), upper_limit=psi2s_scale+np.sqrt(psi2s_scale)) + +#psi(3770) + +p3770_mass, p3770_width, p3770_phase, p3770_scale = pdg["p3770"] + +p3770_m = zfit.Parameter("p3770_m", ztf.constant(p3770_mass), floating = False) +p3770_w = zfit.Parameter("p3770_w", ztf.constant(p3770_width), floating = False) +p3770_p = zfit.Parameter("p3770_p", ztf.constant(p3770_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p3770_s = zfit.Parameter("p3770_s", ztf.constant(p3770_scale), lower_limit=p3770_scale-np.sqrt(p3770_scale), upper_limit=p3770_scale+np.sqrt(p3770_scale)) + +#psi(4040) + +p4040_mass, p4040_width, p4040_phase, p4040_scale = pdg["p4040"] + +p4040_m = zfit.Parameter("p4040_m", ztf.constant(p4040_mass), floating = False) +p4040_w = zfit.Parameter("p4040_w", ztf.constant(p4040_width), floating = False) +p4040_p = zfit.Parameter("p4040_p", ztf.constant(p4040_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4040_s = zfit.Parameter("p4040_s", ztf.constant(p4040_scale), lower_limit=p4040_scale-np.sqrt(p4040_scale), upper_limit=p4040_scale+np.sqrt(p4040_scale)) + +#psi(4160) + +p4160_mass, p4160_width, p4160_phase, p4160_scale = pdg["p4160"] + +p4160_m = zfit.Parameter("p4160_m", ztf.constant(p4160_mass), floating = False) +p4160_w = zfit.Parameter("p4160_w", ztf.constant(p4160_width), floating = False) +p4160_p = zfit.Parameter("p4160_p", ztf.constant(p4160_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4160_s = zfit.Parameter("p4160_s", ztf.constant(p4160_scale), lower_limit=p4160_scale-np.sqrt(p4160_scale), upper_limit=p4160_scale+np.sqrt(p4160_scale)) + +#psi(4415) + +p4415_mass, p4415_width, p4415_phase, p4415_scale = pdg["p4415"] + +p4415_m = zfit.Parameter("p4415_m", ztf.constant(p4415_mass), floating = False) +p4415_w = zfit.Parameter("p4415_w", ztf.constant(p4415_width), floating = False) +p4415_p = zfit.Parameter("p4415_p", ztf.constant(p4415_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4415_s = zfit.Parameter("p4415_s", ztf.constant(p4415_scale), lower_limit=p4415_scale-np.sqrt(p4415_scale), upper_limit=p4415_scale+np.sqrt(p4415_scale)) + + +# ## Dynamic generation of 2 particle contribution + +# In[7]: + + +m_c = 1300 + +Dbar_phase = 0.0 +DDstar_phase = 0.0 +Dstar_mass = pdg['Dst_M'] +Dbar_mass = pdg['D0_M'] +D_mass = pdg['D0_M'] + +Dbar_s = zfit.Parameter("Dbar_s", ztf.constant(0.0), lower_limit=-0.3, upper_limit=0.3) +Dbar_m = zfit.Parameter("Dbar_m", ztf.constant(Dbar_mass), floating = False) +Dbar_p = zfit.Parameter("Dbar_p", ztf.constant(Dbar_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi)#, floating = False) +DDstar_s = zfit.Parameter("DDstar_s", ztf.constant(0.0), lower_limit=-0.3, upper_limit=0.3)#, floating = False) +Dstar_m = zfit.Parameter("Dstar_m", ztf.constant(Dstar_mass), floating = False) +D_m = zfit.Parameter("D_m", ztf.constant(D_mass), floating = False) +DDstar_p = zfit.Parameter("DDstar_p", ztf.constant(DDstar_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi)#, floating = False) + + +# ## Tau parameters + +# In[8]: + + +tau_m = zfit.Parameter("tau_m", ztf.constant(pdg['tau_M']), floating = False) +Ctt = zfit.Parameter("Ctt", ztf.constant(0.0), lower_limit=-1.5, upper_limit=1.5) + + +# ## Load data + +# In[9]: + + +x_min = 2*pdg['muon_M'] +x_max = (pdg["Bplus_M"]-pdg["Ks_M"]-0.1) + +# # Full spectrum + +obs_toy = zfit.Space('q', limits = (x_min, x_max)) + +# Jpsi and Psi2s cut out + +obs1 = zfit.Space('q', limits = (x_min, jpsi_mass - 60.)) +obs2 = zfit.Space('q', limits = (jpsi_mass + 70., psi2s_mass - 50.)) +obs3 = zfit.Space('q', limits = (psi2s_mass + 50., x_max)) + +obs_fit = obs1 + obs2 + obs3 + +# 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: +# part_set = pkl.load(input_file) + +# x_part = part_set['x_part'] + +# x_part = x_part.astype('float64') + +# data = zfit.data.Data.from_numpy(array=x_part, obs=obs) + + +# ## Setup pdf + +# In[10]: + + +total_f = total_pdf_cut(obs=obs_toy, jpsi_mass = jpsi_m, jpsi_scale = jpsi_s, jpsi_phase = jpsi_p, jpsi_width = jpsi_w, + psi2s_mass = psi2s_m, psi2s_scale = psi2s_s, psi2s_phase = psi2s_p, psi2s_width = psi2s_w, + p3770_mass = p3770_m, p3770_scale = p3770_s, p3770_phase = p3770_p, p3770_width = p3770_w, + p4040_mass = p4040_m, p4040_scale = p4040_s, p4040_phase = p4040_p, p4040_width = p4040_w, + p4160_mass = p4160_m, p4160_scale = p4160_s, p4160_phase = p4160_p, p4160_width = p4160_w, + p4415_mass = p4415_m, p4415_scale = p4415_s, p4415_phase = p4415_p, p4415_width = p4415_w, + rho_mass = rho_m, rho_scale = rho_s, rho_phase = rho_p, rho_width = rho_w, + omega_mass = omega_m, omega_scale = omega_s, omega_phase = omega_p, omega_width = omega_w, + phi_mass = phi_m, phi_scale = phi_s, phi_phase = phi_p, phi_width = phi_w, + Dstar_mass = Dstar_m, DDstar_scale = DDstar_s, DDstar_phase = DDstar_p, D_mass = D_m, + Dbar_mass = Dbar_m, Dbar_scale = Dbar_s, Dbar_phase = Dbar_p, + tau_mass = tau_m, C_tt = Ctt, b0_0 = b0_0, b0_1 = b0_1, b0_2 = b0_2, + bplus_0 = bplus_0, bplus_1 = bplus_1, bplus_2 = bplus_2, + bT_0 = bT_0, bT_1 = bT_1, bT_2 = bT_2) + +total_f_fit = total_pdf_full(obs=obs_fit, jpsi_mass = jpsi_m, jpsi_scale = jpsi_s, jpsi_phase = jpsi_p, jpsi_width = jpsi_w, + psi2s_mass = psi2s_m, psi2s_scale = psi2s_s, psi2s_phase = psi2s_p, psi2s_width = psi2s_w, + p3770_mass = p3770_m, p3770_scale = p3770_s, p3770_phase = p3770_p, p3770_width = p3770_w, + p4040_mass = p4040_m, p4040_scale = p4040_s, p4040_phase = p4040_p, p4040_width = p4040_w, + p4160_mass = p4160_m, p4160_scale = p4160_s, p4160_phase = p4160_p, p4160_width = p4160_w, + p4415_mass = p4415_m, p4415_scale = p4415_s, p4415_phase = p4415_p, p4415_width = p4415_w, + rho_mass = rho_m, rho_scale = rho_s, rho_phase = rho_p, rho_width = rho_w, + omega_mass = omega_m, omega_scale = omega_s, omega_phase = omega_p, omega_width = omega_w, + phi_mass = phi_m, phi_scale = phi_s, phi_phase = phi_p, phi_width = phi_w, + Dstar_mass = Dstar_m, DDstar_scale = DDstar_s, DDstar_phase = DDstar_p, D_mass = D_m, + Dbar_mass = Dbar_m, Dbar_scale = Dbar_s, Dbar_phase = Dbar_p, + tau_mass = tau_m, C_tt = Ctt, b0_0 = b0_0, b0_1 = b0_1, b0_2 = b0_2, + bplus_0 = bplus_0, bplus_1 = bplus_1, bplus_2 = bplus_2, + bT_0 = bT_0, bT_1 = bT_1, bT_2 = bT_2) + +# print(total_pdf.obs) + +# print(calcs_test) + +# for param in total_f.get_dependents(): +# print(zfit.run(param)) + + +# In[11]: + + +total_f_fit.normalization(obs_toy) + + +# ## Test if graphs actually work and compute values + +# In[12]: + + +# def total_test_tf(xq): + +# def jpsi_res(q): +# return resonance(q, jpsi_m, jpsi_s, jpsi_p, jpsi_w) + +# def psi2s_res(q): +# return resonance(q, psi2s_m, psi2s_s, psi2s_p, psi2s_w) + +# def cusp(q): +# return bifur_gauss(q, cusp_m, sig_L, sig_R, cusp_s) + +# funcs = jpsi_res(xq) + psi2s_res(xq) + cusp(xq) + +# vec_f = vec(xq, funcs) + +# axiv_nr = axiv_nonres(xq) + +# tot = vec_f + axiv_nr + +# return tot + +# def jpsi_res(q): +# return resonance(q, jpsi_m, jpsi_s, jpsi_p, jpsi_w) + +# calcs = zfit.run(total_test_tf(x_part)) + +test_q = np.linspace(x_min, x_max, int(2e6)) + +probs = total_f_fit.pdf(test_q, norm_range=False) + +calcs_test = zfit.run(probs) +# res_y = zfit.run(jpsi_res(test_q)) +# b0 = [b0_0, b0_1, b0_2] +# bplus = [bplus_0, bplus_1, bplus_2] +# bT = [bT_0, bT_1, bT_2] +# f0_y = zfit.run(tf.math.real(formfactor(test_q,"0", b0, bplus, bT))) +# fplus_y = zfit.run(tf.math.real(formfactor(test_q,"+", b0, bplus, bT))) +# fT_y = zfit.run(tf.math.real(formfactor(test_q,"T", b0, bplus, bT))) + + +# In[13]: + + +plt.clf() +# plt.plot(x_part, calcs, '.') +plt.plot(test_q, calcs_test, label = 'pdf') +# plt.plot(test_q, f0_y, label = '0') +# plt.plot(test_q, fT_y, label = 'T') +# plt.plot(test_q, fplus_y, label = '+') +# plt.plot(test_q, res_y, label = 'res') +plt.legend() +plt.ylim(0.0, 1.5e-6) +# plt.yscale('log') +# plt.xlim(770, 785) +plt.savefig('test.png') +# print(jpsi_width) + + +# In[14]: + + + + +# probs = mixture.prob(test_q) +# probs_np = zfit.run(probs) +# probs_np *= np.max(calcs_test) / np.max(probs_np) +# plt.figure() +# plt.semilogy(test_q, probs_np,label="importance sampling") +# plt.semilogy(test_q, calcs_test, label = 'pdf') + + +# In[15]: + + +# 0.213/(0.00133+0.213+0.015) + + +# ## Adjust scaling of different parts + +# In[16]: + + +total_f.update_integration_options(draws_per_dim=2000000, mc_sampler=None) +# inte = total_f.integrate(limits = (950., 1050.), norm_range=False) +# inte_fl = zfit.run(inte) +# print(inte_fl/4500) +# print(pdg["jpsi_BR"]/pdg["NR_BR"], inte_fl*pdg["psi2s_auc"]/pdg["NR_auc"]) + + +# In[17]: + + +# # print("jpsi:", inte_fl) +# # print("Increase am by factor:", np.sqrt(pdg["jpsi_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# # print("New amp:", pdg["jpsi"][3]*np.sqrt(pdg["jpsi_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + +# # print("psi2s:", inte_fl) +# # print("Increase am by factor:", np.sqrt(pdg["psi2s_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# # print("New amp:", pdg["psi2s"][3]*np.sqrt(pdg["psi2s_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + +# name = "phi" + +# print(name+":", inte_fl) +# print("Increase am by factor:", np.sqrt(pdg[name+"_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# print("New amp:", pdg[name][0]*np.sqrt(pdg[name+"_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + + +# print(x_min) +# print(x_max) +# # total_f.update_integration_options(draws_per_dim=2000000, mc_sampler=None) +# total_f.update_integration_options(mc_sampler=lambda dim, num_results, +# dtype: tf.random_uniform(maxval=1., shape=(num_results, dim), dtype=dtype), +# draws_per_dim=1000000) +# # _ = [] + +# # for i in range(10): + +# # inte = total_f.integrate(limits = (x_min, x_max)) +# # inte_fl = zfit.run(inte) +# # print(inte_fl) +# # _.append(inte_fl) + +# # print("mean:", np.mean(_)) + +# _ = time.time() + +# inte = total_f.integrate(limits = (x_min, x_max)) +# inte_fl = zfit.run(inte) +# print(inte_fl) +# print("Time taken: {}".format(display_time(int(time.time() - _)))) + +# print(pdg['NR_BR']/pdg['NR_auc']*inte_fl) +# print(0.25**2*4.2/1000) + + +# # Sampling +# ## Mixture distribution for sampling + +# In[18]: + + + + +# print(list_of_borders[:9]) +# print(list_of_borders[-9:]) + + +class UniformSampleAndWeights(zfit.util.execution.SessionHolderMixin): + def __call__(self, limits, dtype, n_to_produce): + # n_to_produce = tf.cast(n_to_produce, dtype=tf.int32) + low, high = limits.limit1d + low = tf.cast(low, dtype=dtype) + high = tf.cast(high, dtype=dtype) +# uniform = tfd.Uniform(low=low, high=high) +# uniformjpsi = tfd.Uniform(low=tf.constant(3080, dtype=dtype), high=tf.constant(3112, dtype=dtype)) +# uniformpsi2s = tfd.Uniform(low=tf.constant(3670, dtype=dtype), high=tf.constant(3702, dtype=dtype)) + +# list_of_borders = [] +# _p = [] +# splits = 10 + +# _ = np.linspace(x_min, x_max, splits) + +# for i in range(splits): +# list_of_borders.append(tf.constant(_[i], dtype=dtype)) +# _p.append(tf.constant(1/splits, dtype=dtype)) + +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=_p[:(splits-1)]), +# components_distribution=tfd.Uniform(low=list_of_borders[:(splits-1)], +# high=list_of_borders[-(splits-1):])) + mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.05, dtype=dtype), + tf.constant(0.93, dtype=dtype), + tf.constant(0.05, dtype=dtype), + tf.constant(0.065, dtype=dtype), + tf.constant(0.04, dtype=dtype), + tf.constant(0.05, dtype=dtype)]), + components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), + tf.constant(3090, dtype=dtype), + tf.constant(3681, dtype=dtype), + tf.constant(3070, dtype=dtype), + tf.constant(1000, dtype=dtype), + tf.constant(3660, dtype=dtype)], + high=[tf.constant(x_max, dtype=dtype), + tf.constant(3102, dtype=dtype), + tf.constant(3691, dtype=dtype), + tf.constant(3110, dtype=dtype), + tf.constant(1040, dtype=dtype), + tf.constant(3710, dtype=dtype)])) +# dtype = tf.float64 +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.04, dtype=dtype), +# tf.constant(0.90, dtype=dtype), +# tf.constant(0.02, dtype=dtype), +# tf.constant(0.07, dtype=dtype), +# tf.constant(0.02, dtype=dtype)]), +# components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), +# tf.constant(3089, dtype=dtype), +# tf.constant(3103, dtype=dtype), +# tf.constant(3681, dtype=dtype), +# tf.constant(3691, dtype=dtype)], +# high=[tf.constant(3089, dtype=dtype), +# tf.constant(3103, dtype=dtype), +# tf.constant(3681, dtype=dtype), +# tf.constant(3691, dtype=dtype), +# tf.constant(x_max, dtype=dtype)])) +# mixture = tfd.Uniform(tf.constant(x_min, dtype=dtype), tf.constant(x_max, dtype=dtype)) +# sample = tf.random.uniform((n_to_produce, 1), dtype=dtype) + sample = mixture.sample((n_to_produce, 1)) +# sample = tf.random.uniform((n_to_produce, 1), dtype=dtype) + weights = mixture.prob(sample)[:,0] +# weights = tf.broadcast_to(tf.constant(1., dtype=dtype), shape=(n_to_produce,)) + # sample = tf.expand_dims(sample, axis=-1) +# print(sample, weights) + +# weights = tf.ones(shape=(n_to_produce,), dtype=dtype) + weights_max = None + thresholds = tf.random_uniform(shape=(n_to_produce,), dtype=dtype) + return sample, thresholds, weights, weights_max, n_to_produce + + +# In[19]: + + +# total_f._sample_and_weights = UniformSampleAndWeights + + +# In[20]: + + +# 0.00133/(0.00133+0.213+0.015)*(x_max-3750)/(x_max-x_min) + + +# In[21]: + + +# zfit.settings.set_verbosity(10) + + +# In[22]: + + +# # zfit.run.numeric_checks = False + +# nr_of_toys = 1 +# nevents = int(pdg["number_of_decays"]) +# nevents = pdg["number_of_decays"] +# event_stack = 1000000 +# # zfit.settings.set_verbosity(10) +# calls = int(nevents/event_stack + 1) + +# total_samp = [] + +# start = time.time() + +# sampler = total_f.create_sampler(n=event_stack) + +# for toy in range(nr_of_toys): + +# dirName = 'data/zfit_toys/toy_{0}'.format(toy) + +# if not os.path.exists(dirName): +# os.mkdir(dirName) +# print("Directory " , dirName , " Created ") + +# for call in range(calls): + +# sampler.resample(n=event_stack) +# s = sampler.unstack_x() +# sam = zfit.run(s) +# # clear_output(wait=True) + +# c = call + 1 + +# print("{0}/{1} of Toy {2}/{3}".format(c, calls, toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(c+calls*(toy))*((nr_of_toys-toy)*calls-c))))) + +# with open("data/zfit_toys/toy_{0}/{1}.pkl".format(toy, call), "wb") as f: +# pkl.dump(sam, f, pkl.HIGHEST_PROTOCOL) + + +# In[23]: + + +# with open(r"data/zfit_toys/toy_0/0.pkl", "rb") as input_file: +# sam = pkl.load(input_file) +# print(sam[:10]) + +# with open(r"data/zfit_toys/toy_0/1.pkl", "rb") as input_file: +# sam2 = pkl.load(input_file) +# print(sam2[:10]) + +# print(np.sum(sam-sam2)) + + +# In[24]: + + +# print("Time to generate full toy: {} s".format(int(time.time()-start))) + +# total_samp = [] + +# for call in range(calls): +# with open(r"data/zfit_toys/toy_0/{}.pkl".format(call), "rb") as input_file: +# sam = pkl.load(input_file) +# total_samp = np.append(total_samp, sam) + +# total_samp = total_samp.astype('float64') + +# data2 = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs) + +# data3 = zfit.data.Data.from_numpy(array=total_samp, obs=obs) + +# print(total_samp[:nevents].shape) + + +# In[25]: + + +# plt.clf() + +# bins = int((x_max-x_min)/7) + +# # calcs = zfit.run(total_test_tf(samp)) +# print(total_samp[:nevents].shape) + +# plt.hist(total_samp[:nevents], bins = bins, range = (x_min,x_max), label = 'data') +# # plt.plot(test_q, calcs_test*nevents , label = 'pdf') + +# # plt.plot(sam, calcs, '.') +# # plt.plot(test_q, calcs_test) +# # plt.yscale('log') +# plt.ylim(0, 200) +# # plt.xlim(3080, 3110) + +# plt.legend() + +# plt.savefig('test2.png') + + +# In[26]: + + +# sampler = total_f.create_sampler(n=nevents) +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=sampler, fit_range = (x_min, x_max)) + +# # for param in pdf.get_dependents(): +# # param.set_value(initial_value) + +# sampler.resample(n=nevents) + +# # Randomise initial values +# # for param in pdf.get_dependents(): +# # param.set_value(random value here) + +# # Minimise the NLL +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 10) +# minimum = minimizer.minimize(nll) + + +# In[27]: + + +# jpsi_width + + +# In[28]: + + +# plt.hist(sample, weights=1 / prob(sample)) + + +# # Fitting + +# In[29]: + + +# start = time.time() + +# for param in total_f.get_dependents(): +# param.randomize() + +# # for param in total_f.get_dependents(): +# # print(zfit.run(param)) + +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=data2, fit_range = (x_min, x_max)) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# # param_errors = result.error() + +# # for var, errors in param_errors.items(): +# # print('{}: ^{{+{}}}_{{{}}}'.format(var.name, errors['upper'], errors['lower'])) + +# print("Function minimum:", result.fmin) +# # print("Results:", result.params) +# print("Hesse errors:", result.hesse()) + + +# In[30]: + + +# print("Time taken for fitting: {}".format(display_time(int(time.time()-start)))) + +# # probs = total_f.pdf(test_q) + +# calcs_test = zfit.run(probs) +# res_y = zfit.run(jpsi_res(test_q)) + + +# In[31]: + + +# plt.clf() +# # plt.plot(x_part, calcs, '.') +# plt.plot(test_q, calcs_test, label = 'pdf') +# # plt.plot(test_q, res_y, label = 'res') +# plt.legend() +# plt.ylim(0.0, 10e-6) +# # plt.yscale('log') +# # plt.xlim(3080, 3110) +# plt.savefig('test3.png') +# # print(jpsi_width) + + +# In[32]: + + +# _tot = 4.37e-7+6.02e-5+4.97e-6 +# _probs = [] +# _probs.append(6.02e-5/_tot) +# _probs.append(4.97e-6/_tot) +# _probs.append(4.37e-7/_tot) +# print(_probs) + + +# In[33]: + + +# dtype = 'float64' +# # mixture = tfd.Uniform(tf.constant(x_min, dtype=dtype), tf.constant(x_max, dtype=dtype)) +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.007, dtype=dtype), +# tf.constant(0.917, dtype=dtype), +# tf.constant(0.076, dtype=dtype)]), +# components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), +# tf.constant(3080, dtype=dtype), +# tf.constant(3670, dtype=dtype)], +# high=[tf.constant(x_max, dtype=dtype), +# tf.constant(3112, dtype=dtype), +# tf.constant(3702, dtype=dtype)])) +# # for i in range(10): +# # print(zfit.run(mixture.prob(mixture.sample((10, 1))))) + + +# In[34]: + + +# print((zfit.run(jpsi_p)%(2*np.pi))/np.pi) +# print((zfit.run(psi2s_p)%(2*np.pi))/np.pi) + + +# In[35]: + + +# def jpsi_res(q): +# return resonance(q, _mass = jpsi_mass, scale = jpsi_scale, +# phase = jpsi_phase, width = jpsi_width) + +# def psi2s_res(q): +# return resonance(q, _mass = psi2s_mass, scale = psi2s_scale, +# phase = psi2s_phase, width = psi2s_width) + +# def p3770_res(q): +# return resonance(q, _mass = p3770_mass, scale = p3770_scale, +# phase = p3770_phase, width = p3770_width) + +# def p4040_res(q): +# return resonance(q, _mass = p4040_mass, scale = p4040_scale, +# phase = p4040_phase, width = p4040_width) + +# def p4160_res(q): +# return resonance(q, _mass = p4160_mass, scale = p4160_scale, +# phase = p4160_phase, width = p4160_width) + +# def p4415_res(q): +# return resonance(q, _mass = p4415_mass, scale = p4415_scale, +# phase = p4415_phase, width = p4415_width) + + +# In[36]: + + +# 0.15**2*4.2/1000 +# result.hesse() + + +# ## Constraints + +# In[37]: + + +# 1. Constraint - Real part of sum of Psi contrib and D contribs + +sum_list = [] + +sum_list.append(ztf.to_complex(jpsi_s) * tf.exp(tf.complex(ztf.constant(0.0), jpsi_p)) * ztf.to_complex(jpsi_w / (tf.pow(jpsi_m,3)))) +sum_list.append(ztf.to_complex(psi2s_s) * tf.exp(tf.complex(ztf.constant(0.0), psi2s_p)) * ztf.to_complex(psi2s_w / (tf.pow(psi2s_m,3)))) +sum_list.append(ztf.to_complex(p3770_s) * tf.exp(tf.complex(ztf.constant(0.0), p3770_p)) * ztf.to_complex(p3770_w / (tf.pow(p3770_m,3)))) +sum_list.append(ztf.to_complex(p4040_s) * tf.exp(tf.complex(ztf.constant(0.0), p4040_p)) * ztf.to_complex(p4040_w / (tf.pow(p4040_m,3)))) +sum_list.append(ztf.to_complex(p4160_s) * tf.exp(tf.complex(ztf.constant(0.0), p4160_p)) * ztf.to_complex(p4160_w / (tf.pow(p4160_m,3)))) +sum_list.append(ztf.to_complex(p4415_s) * tf.exp(tf.complex(ztf.constant(0.0), p4415_p)) * ztf.to_complex(p4415_w / (tf.pow(p4415_m,3)))) +sum_list.append(ztf.to_complex(DDstar_s) * tf.exp(tf.complex(ztf.constant(0.0), DDstar_p)) * (ztf.to_complex(1.0 / (10.0*tf.pow(Dstar_m,2)) + 1.0 / (10.0*tf.pow(D_m,2))))) +sum_list.append(ztf.to_complex(Dbar_s) * tf.exp(tf.complex(ztf.constant(0.0), Dbar_p)) * ztf.to_complex(1.0 / (6.0*tf.pow(Dbar_m,2)))) + +sum_ru_1 = ztf.to_complex(ztf.constant(0.0)) + +for part in sum_list: + sum_ru_1 += part + +sum_1 = tf.math.real(sum_ru_1) +# constraint1 = zfit.constraint.GaussianConstraint(params = sum_1, mu = ztf.constant(1.7*10**-8), +# sigma = ztf.constant(2.2*10**-8)) + +constraint1 = tf.pow((sum_1-ztf.constant(1.7*10**-8))/ztf.constant(2.2*10**-8),2)/ztf.constant(2.) + +# 2. Constraint - Abs. of sum of Psi contribs and D contribs + +sum_2 = tf.abs(sum_ru_1) +constraint2 = tf.cond(tf.greater_equal(sum_2, 5.0e-8), lambda: 100000., lambda: 0.) + +# 3. Constraint - Maximum eta of D contribs + +constraint3_0 = tf.cond(tf.greater_equal(tf.abs(Dbar_s), 0.2), lambda: 100000., lambda: 0.) + +constraint3_1 = tf.cond(tf.greater_equal(tf.abs(DDstar_s), 0.2), lambda: 100000., lambda: 0.) + +# 4. Constraint - Formfactor multivariant gaussian covariance fplus + +Cov_matrix = [[ztf.constant( 1.), ztf.constant( 0.45), ztf.constant( 0.19), ztf.constant(0.857), ztf.constant(0.598), ztf.constant(0.531), ztf.constant(0.752), ztf.constant(0.229), ztf.constant(0,117)], + [ztf.constant( 0.45), ztf.constant( 1.), ztf.constant(0.677), ztf.constant(0.708), ztf.constant(0.958), ztf.constant(0.927), ztf.constant(0.227), ztf.constant(0.443), ztf.constant(0.287)], + [ztf.constant( 0.19), ztf.constant(0.677), ztf.constant( 1.), ztf.constant(0.595), ztf.constant(0.770), ztf.constant(0.819),ztf.constant(-0.023), ztf.constant( 0.07), ztf.constant(0.196)], + [ztf.constant(0.857), ztf.constant(0.708), ztf.constant(0.595), ztf.constant( 1.), ztf.constant( 0.83), ztf.constant(0.766), ztf.constant(0.582), ztf.constant(0.237), ztf.constant(0.192)], + [ztf.constant(0.598), ztf.constant(0.958), ztf.constant(0.770), ztf.constant( 0.83), ztf.constant( 1.), ztf.constant(0.973), ztf.constant(0.324), ztf.constant(0.372), ztf.constant(0.272)], + [ztf.constant(0.531), ztf.constant(0.927), ztf.constant(0.819), ztf.constant(0.766), ztf.constant(0.973), ztf.constant( 1.), ztf.constant(0.268), ztf.constant(0.332), ztf.constant(0.269)], + [ztf.constant(0.752), ztf.constant(0.227),ztf.constant(-0.023), ztf.constant(0.582), ztf.constant(0.324), ztf.constant(0.268), ztf.constant( 1.), ztf.constant( 0.59), ztf.constant(0.515)], + [ztf.constant(0.229), ztf.constant(0.443), ztf.constant( 0.07), ztf.constant(0.237), ztf.constant(0.372), ztf.constant(0.332), ztf.constant( 0.59), ztf.constant( 1.), ztf.constant(0.897)], + [ztf.constant(0.117), ztf.constant(0.287), ztf.constant(0.196), ztf.constant(0.192), ztf.constant(0.272), ztf.constant(0.269), ztf.constant(0.515), ztf.constant(0.897), ztf.constant( 1.)]] + +def triGauss(val1,val2,val3,m = Cov_matrix): + + mean1 = ztf.constant(0.466) + mean2 = ztf.constant(-0.885) + mean3 = ztf.constant(-0.213) + sigma1 = ztf.constant(0.014) + sigma2 = ztf.constant(0.128) + sigma3 = ztf.constant(0.548) + x1 = (val1-mean1)/sigma1 + x2 = (val2-mean2)/sigma2 + x3 = (val3-mean3)/sigma3 + rho12 = m[0][1] + rho13 = m[0][2] + rho23 = m[1][2] + w = x1*x1*(rho23*rho23-1) + x2*x2*(rho13*rho13-1)+x3*x3*(rho12*rho12-1)+2*(x1*x2*(rho12-rho13*rho23)+x1*x3*(rho13-rho12*rho23)+x2*x3*(rho23-rho12*rho13)) + d = 2*(rho12*rho12+rho13*rho13+rho23*rho23-2*rho12*rho13*rho23-1) + + fcn = -w/d + chisq = -2*fcn + return chisq + +constraint4 = triGauss(bplus_0, bplus_1, bplus_2) + +# mean1 = ztf.constant(0.466) +# mean2 = ztf.constant(-0.885) +# mean3 = ztf.constant(-0.213) +# sigma1 = ztf.constant(0.014) +# sigma2 = ztf.constant(0.128) +# sigma3 = ztf.constant(0.548) +# constraint4_0 = tf.pow((bplus_0-mean1)/sigma1,2)/ztf.constant(2.) +# constraint4_1 = tf.pow((bplus_1-mean2)/sigma2,2)/ztf.constant(2.) +# constraint4_2 = tf.pow((bplus_2-mean3)/sigma3,2)/ztf.constant(2.) + +# 5. Constraint - Abs. of sum of light contribs + +sum_list_5 = [] + +sum_list_5.append(rho_s*rho_w/rho_m) +sum_list_5.append(omega_s*omega_w/omega_m) +sum_list_5.append(phi_s*phi_w/phi_m) + + +sum_ru_5 = ztf.constant(0.0) + +for part in sum_list_5: + sum_ru_5 += part + +constraint5 = tf.cond(tf.greater_equal(tf.abs(sum_ru_5), ztf.constant(0.02)), lambda: 100000., lambda: 0.) + +# 6. Constraint on phases of Jpsi and Psi2s for cut out fit + + +# constraint6_0 = zfit.constraint.GaussianConstraint(params = jpsi_p, mu = ztf.constant(pdg["jpsi_phase_unc"]), +# sigma = ztf.constant(jpsi_phase)) +# constraint6_1 = zfit.constraint.GaussianConstraint(params = psi2s_p, mu = ztf.constant(pdg["psi2s_phase_unc"]), +# sigma = ztf.constant(psi2s_phase)) + +constraint6_0 = tf.pow((jpsi_p-ztf.constant(jpsi_phase))/ztf.constant(pdg["jpsi_phase_unc"]),2)/ztf.constant(2.) +constraint6_1 = tf.pow((psi2s_p-ztf.constant(psi2s_phase))/ztf.constant(pdg["psi2s_phase_unc"]),2)/ztf.constant(2.) + +# 7. Constraint on Ctt with higher limits + +constraint7 = tf.cond(tf.greater_equal(Ctt*Ctt, 0.25), lambda: 100000., lambda: 0.) + +constraint7dtype = tf.float64 + +# zfit.run(constraint6_0) + +# ztf.convert_to_tensor(constraint6_0) + +#List of all constraints + +constraints = [constraint1, constraint2, constraint3_0, constraint3_1,# constraint4, #constraint4_0, constraint4_1, constraint4_2, + constraint6_0, constraint6_1]#, constraint7] + + +# ## Reset params + +# In[38]: + + +def reset_param_values(): + jpsi_m.set_value(jpsi_mass) + jpsi_s.set_value(jpsi_scale) + jpsi_p.set_value(jpsi_phase) + jpsi_w.set_value(jpsi_width) + psi2s_m.set_value(psi2s_mass) + psi2s_s.set_value(psi2s_scale) + psi2s_p.set_value(psi2s_phase) + psi2s_w.set_value(psi2s_width) + p3770_m.set_value(p3770_mass) + p3770_s.set_value(p3770_scale) + p3770_p.set_value(p3770_phase) + p3770_w.set_value(p3770_width) + p4040_m.set_value(p4040_mass) + p4040_s.set_value(p4040_scale) + p4040_p.set_value(p4040_phase) + p4040_w.set_value(p4040_width) + p4160_m.set_value(p4160_mass) + p4160_s.set_value(p4160_scale) + p4160_p.set_value(p4160_phase) + p4160_w.set_value(p4160_width) + p4415_m.set_value(p4415_mass) + p4415_s.set_value(p4415_scale) + p4415_p.set_value(p4415_phase) + p4415_w.set_value(p4415_width) + rho_m.set_value(rho_mass) + rho_s.set_value(rho_scale) + rho_p.set_value(rho_phase) + rho_w.set_value(rho_width) + omega_m.set_value(omega_mass) + omega_s.set_value(omega_scale) + omega_p.set_value(omega_phase) + omega_w.set_value(omega_width) + phi_m.set_value(phi_mass) + phi_s.set_value(phi_scale) + phi_p.set_value(phi_phase) + phi_w.set_value(phi_width) + Dstar_m.set_value(Dstar_mass) + DDstar_s.set_value(0.0) + DDstar_p.set_value(0.0) + D_m.set_value(D_mass) + Dbar_m.set_value(Dbar_mass) + Dbar_s.set_value(0.0) + Dbar_p.set_value(0.0) + tau_m.set_value(pdg['tau_M']) + Ctt.set_value(0.0) + b0_0.set_value(0.292) + b0_1.set_value(0.281) + b0_2.set_value(0.150) + bplus_0.set_value(0.466) + bplus_1.set_value(-0.885) + bplus_2.set_value(-0.213) + bT_0.set_value(0.460) + bT_1.set_value(-1.089) + bT_2.set_value(-1.114) + + +# # Analysis + +# In[39]: + + +# # zfit.run.numeric_checks = False + +# fitting_range = 'cut' +# total_BR = 1.7e-10 + 4.9e-10 + 2.5e-9 + 6.02e-5 + 4.97e-6 + 1.38e-9 + 4.2e-10 + 2.6e-9 + 6.1e-10 + 4.37e-7 +# cut_BR = 1.0 - (6.02e-5 + 4.97e-6)/total_BR + +# Ctt_list = [] +# Ctt_error_list = [] + +# nr_of_toys = 1 +# if fitting_range == 'cut': +# nevents = int(pdg["number_of_decays"]*cut_BR) +# else: +# nevents = int(pdg["number_of_decays"]) +# # nevents = pdg["number_of_decays"] +# event_stack = 1000000 +# # nevents *= 41 +# # zfit.settings.set_verbosity(10) +# calls = int(nevents/event_stack + 1) + +# total_samp = [] + +# start = time.time() + +# sampler = total_f.create_sampler(n=event_stack) + +# for toy in range(nr_of_toys): + +# ### Generate data + +# # clear_output(wait=True) + +# print("Toy {}: Generating data...".format(toy)) + +# dirName = 'data/zfit_toys/toy_{0}'.format(toy) + +# if not os.path.exists(dirName): +# os.mkdir(dirName) +# print("Directory " , dirName , " Created ") + +# reset_param_values() + +# if fitting_range == 'cut': + +# sampler.resample(n=nevents) +# s = sampler.unstack_x() +# sam = zfit.run(s) +# calls = 0 +# c = 1 + +# else: +# for call in range(calls): + +# sampler.resample(n=event_stack) +# s = sampler.unstack_x() +# sam = zfit.run(s) + +# c = call + 1 + +# with open("data/zfit_toys/toy_{0}/{1}.pkl".format(toy, call), "wb") as f: +# pkl.dump(sam, f, pkl.HIGHEST_PROTOCOL) + +# print("Toy {}: Data generation finished".format(toy)) + +# ### Load data + +# print("Toy {}: Loading data...".format(toy)) + +# if fitting_range == 'cut': + +# total_samp = sam + +# else: + +# for call in range(calls): +# with open(r"data/zfit_toys/toy_0/{}.pkl".format(call), "rb") as input_file: +# sam = pkl.load(input_file) +# total_samp = np.append(total_samp, sam) + +# total_samp = total_samp.astype('float64') + +# if fitting_range == 'full': + +# data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs) + +# print("Toy {}: Loading data finished".format(toy)) + +# ### Fit data + +# print("Toy {}: Fitting pdf...".format(toy)) + +# for param in total_f.get_dependents(): +# param.randomize() + +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=data, fit_range = (x_min, x_max), constraints = constraints) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# print("Toy {}: Fitting finished".format(toy)) + +# print("Function minimum:", result.fmin) +# print("Hesse errors:", result.hesse()) + +# params = result.params +# Ctt_list.append(params[Ctt]['value']) +# Ctt_error_list.append(params[Ctt]['minuit_hesse']['error']) + +# #plotting the result + +# plotdirName = 'data/plots'.format(toy) + +# if not os.path.exists(plotdirName): +# os.mkdir(plotdirName) +# # print("Directory " , dirName , " Created ") + +# probs = total_f.pdf(test_q, norm_range=False) +# calcs_test = zfit.run(probs) +# plt.clf() +# plt.plot(test_q, calcs_test, label = 'pdf') +# plt.legend() +# plt.ylim(0.0, 6e-6) +# plt.savefig(plotdirName + '/toy_fit_full_range{}.png'.format(toy)) + +# print("Toy {0}/{1}".format(toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(c+calls*(toy))*((nr_of_toys-toy)*calls-c))))) + +# if fitting_range == 'cut': + +# _1 = np.where((total_samp >= x_min) & (total_samp <= (jpsi_mass - 60.))) + +# tot_sam_1 = total_samp[_1] + +# _2 = np.where((total_samp >= (jpsi_mass + 70.)) & (total_samp <= (psi2s_mass - 50.))) + +# tot_sam_2 = total_samp[_2] + +# _3 = np.where((total_samp >= (psi2s_mass + 50.)) & (total_samp <= x_max)) + +# tot_sam_3 = total_samp[_3] + +# tot_sam = np.append(tot_sam_1, tot_sam_2) +# tot_sam = np.append(tot_sam, tot_sam_3) + +# data = zfit.data.Data.from_numpy(array=tot_sam[:int(nevents)], obs=obs_fit) + +# print("Toy {}: Loading data finished".format(toy)) + +# ### Fit data + +# print("Toy {}: Fitting pdf...".format(toy)) + +# for param in total_f_fit.get_dependents(): +# param.randomize() + +# nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# print("Function minimum:", result.fmin) +# print("Hesse errors:", result.hesse()) + +# params = result.params + +# if result.converged: +# Ctt_list.append(params[Ctt]['value']) +# Ctt_error_list.append(params[Ctt]['minuit_hesse']['error']) + +# #plotting the result + +# plotdirName = 'data/plots'.format(toy) + +# if not os.path.exists(plotdirName): +# os.mkdir(plotdirName) +# # print("Directory " , dirName , " Created ") + +# plt.clf() +# plt.hist(tot_sam, bins = int((x_max-x_min)/7.), label = 'toy data') +# plt.savefig(plotdirName + '/toy_histo_cut_region{}.png'.format(toy)) + + +# probs = total_f_fit.pdf(test_q, norm_range=False) +# calcs_test = zfit.run(probs) +# plt.clf() +# plt.plot(test_q, calcs_test, label = 'pdf') +# plt.axvline(x=jpsi_mass-60.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=jpsi_mass+70.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=psi2s_mass-50.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=psi2s_mass+50.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.legend() +# plt.ylim(0.0, 1.5e-6) +# plt.savefig(plotdirName + '/toy_fit_cut_region{}.png'.format(toy)) + +# print("Toy {0}/{1}".format(toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(toy+1))*((nr_of_toys-toy-1))))) + + + +# In[40]: + + +# with open("data/results/Ctt_list.pkl", "wb") as f: +# pkl.dump(Ctt_list, f, pkl.HIGHEST_PROTOCOL) +# with open("data/results/Ctt_error_list.pkl", "wb") as f: +# pkl.dump(Ctt_error_list, f, pkl.HIGHEST_PROTOCOL) + + +# In[41]: + + +# print('{0}/{1} fits converged'.format(len(Ctt_list), nr_of_toys)) +# print('Mean Ctt value = {}'.format(np.mean(Ctt_list))) +# print('Mean Ctt error = {}'.format(np.mean(Ctt_error_list))) +# print('95 Sensitivy = {}'.format(((2*np.mean(Ctt_error_list))**2)*4.2/1000)) + + +# In[42]: + + +# plt.hist(tot_sam, bins = int((x_max-x_min)/7.)) + +# plt.show() + +# # _ = np.where((total_samp >= x_min) & (total_samp <= (jpsi_mass - 50.))) + +# tot_sam.shape + + +# In[43]: + + +# Ctt.floating = False + + +# In[44]: + + +# zfit.run(nll.value()) + + +# In[45]: + + +# result.fmin + + +# In[46]: + + +# BR_steps = np.linspace(0.0, 1e-3, 11) + + +# # CLS Code + +# In[47]: + + +# zfit.run.numeric_checks = False + +load = False + +bo5 = True + +bo5_set = 5 + +fitting_range = 'cut' +total_BR = 1.7e-10 + 4.9e-10 + 2.5e-9 + 6.02e-5 + 4.97e-6 + 1.38e-9 + 4.2e-10 + 2.6e-9 + 6.1e-10 + 4.37e-7 +cut_BR = 1.0 - (6.02e-5 + 4.97e-6)/total_BR + +Ctt_list = [] +Ctt_error_list = [] + +nr_of_toys = 1 +nevents = int(pdg["number_of_decays"]*cut_BR) +# nevents = pdg["number_of_decays"] +event_stack = 1000000 +# nevents *= 41 +# zfit.settings.set_verbosity(10) + +mi = 0.0 +ma = 1e-3 +ste = 11 + +BR_steps = np.linspace(mi, ma, ste) + +Ctt_steps = np.sqrt(BR_steps/4.2*1000) + +total_samp = [] + +start = time.time() + +Nll_list = [] + +sampler = total_f.create_sampler(n=nevents) + +__ = 0 + + +#----------------------------------------------------- + +if not load: + + for Ctt_step in Ctt_steps: + + __ += 1 + + newset = True + + for floaty in [True, False]: + + Ctt.floating = floaty + + Nll_list.append([]) + + if bo5: + + while len(Nll_list[-1])/bo5_set < nr_of_toys: + + print('Step: {0}/{1}'.format(__, ste)) + + print('Current Ctt: {0}'.format(Ctt_step)) + print('Ctt floating: {0}'.format(floaty)) + + print('Toy {0}/{1} - Fit {2}/{3}'.format(int(len(Nll_list[-1])/bo5_set), nr_of_toys, len(Nll_list[-1]), bo5_set)) + + reset_param_values() + + if floaty: + Ctt.set_value(Ctt_step) + else: + Ctt.set_value(0.0) + + if newset: + sampler.resample(n=nevents) + s = sampler.unstack_x() + total_samp = zfit.run(s) + calls = 0 + c = 1 + newset = False + + + data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit) + + ### Fit data + + for param in total_f_fit.get_dependents(): + param.randomize() + + nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + + minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) + # minimizer._use_tfgrad = False + result = minimizer.minimize(nll) + + # print("Function minimum:", result.fmin) + # print("Hesse errors:", result.hesse()) + + params = result.params + + if result.converged: + Nll_list[-1].append(result.fmin) + + else: + + while len(Nll_list[-1]) < nr_of_toys: + + print('Step: {0}/{1}'.format(__, ste)) + + print('Current Ctt: {0}'.format(Ctt_step)) + print('Ctt floating: {0}'.format(floaty)) + + print('Toy {0}/{1}'.format(len(Nll_list[-1]), nr_of_toys)) + + reset_param_values() + + if floaty: + Ctt.set_value(Ctt_step) + else: + Ctt.set_value(0.0) + + if floaty: + sampler.resample(n=nevents) + s = sampler.unstack_x() + total_samp = zfit.run(s) + calls = 0 + c = 1 + + + data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit) + + ### Fit data + + for param in total_f_fit.get_dependents(): + param.randomize() + + nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + + minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) + # minimizer._use_tfgrad = False + result = minimizer.minimize(nll) + + # print("Function minimum:", result.fmin) + # print("Hesse errors:", result.hesse()) + + params = result.params + + if result.converged: + Nll_list[-1].append(result.fmin) + + _t = int(time.time()-start) + + print('Time Taken: {}'.format(display_time(int(_t)))) + + print('Predicted time left: {}'.format(display_time(int((_t/(__+1)*(ste-__-1)))))) + + +# In[48]: + + +if load: + Nll_list = [] + CLs_values = [] + + _dir = 'data/CLs/finished/f1d1' + + jobs = os.listdir(_dir) + + for s in range(ste): + CLs_values.append([]) + + for s in range(2*ste): + Nll_list.append([]) + + for job in jobs: + if not os.path.exists("{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(_dir, job, mi,ma,ste)): + print(job) + continue + + with open(r"{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(_dir, job, mi,ma,ste), "rb") as input_file: + _Nll_list = pkl.load(input_file) + + if bo5: + for s in range(2*ste): + Nll_list[s].append(np.min(_Nll_list[s])) + else: + for s in range(2*ste): + Nll_list[s].extend(_Nll_list[s]) + + with open(r"{}/{}/data/CLs/{}-{}_{}s--CLs_list.pkl".format(_dir, job, mi,ma,ste), "rb") as input_file: + _CLs_values = pkl.load(input_file) + + for s in range(ste): + CLs_values[s].extend(_CLs_values[s]) + + print(np.shape(Nll_list)) + + +# In[50]: + + +dirName = 'data/CLs' + +# if bo5 and not load: +# for s in range(2*ste): +# Nll_list[s] = [np.min(Nll_list[s])] + +if bo5: + CLs_values= [] + for i in range(int(len(Nll_list)/2)): + CLs_values.append([]) + for j in range(len(Nll_list[0])): + CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j]) + + +if not load: + + CLs_values = [] + + for i in range(int(len(Nll_list)/2)): + CLs_values.append([]) + for j in range(nr_of_toys): + CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j]) + + if not os.path.exists(dirName): + os.mkdir(dirName) + print("Directory " , dirName , " Created ") + + with open("{}/{}-{}_{}s--CLs_Nll_list.pkl".format(dirName, mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + + with open("{}/{}-{}_{}s--CLs_list.pkl".format(dirName, mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +# print(CLs_values) +print(Nll_list) + + +# ## Plot + +# In[52]: + + +l = [] + +for i in range(len(CLs_values)): + plt.clf() + plt.title('Ctt value: {:.2f}'.format(Ctt_steps[i])) + plt.hist(CLs_values[0], bins = 100, label = 'Ctt fixed to 0') + plt.hist(CLs_values[i], bins = 100, label = 'Ctt floating') + plt.axvline(x=np.mean(CLs_values[0]),color='red', linewidth=0.7, linestyle = 'dotted') + plt.legend() + plt.savefig('data/CLs/plots/CLs-BR({:.1E}).png'.format(BR_steps[i])) + + l.append(len(np.where(np.array(CLs_values[i]) < np.mean(CLs_values[0]))[0])) + + +# In[53]: + + +for s in range(len(l)): + print('BR: {}'.format(BR_steps[s])) + print(2*l[s]/len(CLs_values[0])) + print() + + +# In[54]: + + +# print(np.array(Nll_list[0][:10])-np.array(Nll_list[1][:10])) + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2254881/test.png b/data/CLs/finished/f1d1/2254881/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2254881/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2254886/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2254886/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..00db4a8 --- /dev/null +++ b/data/CLs/finished/f1d1/2254886/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2254886/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2254886/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..d09bea0 --- /dev/null +++ b/data/CLs/finished/f1d1/2254886/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2254886/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2254886/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..3a2bb99 --- /dev/null +++ b/data/CLs/finished/f1d1/2254886/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2254886/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2254886/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..1414d37 --- /dev/null +++ b/data/CLs/finished/f1d1/2254886/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2254886/helperfunctions.py b/data/CLs/finished/f1d1/2254886/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2254886/helperfunctions.py @@ -0,0 +1,33 @@ +# some helperfunctions + +import matplotlib +matplotlib.use("agg") +import matplotlib.pyplot as plt + +#Dislpay time (e.g. while generating points) + +display_intervals = ( + ('w', 604800), # 60 * 60 * 24 * 7 + ('d', 86400), # 60 * 60 * 24 + ('h', 3600), # 60 * 60 + ('min', 60), + ('s', 1), + ) + +def display_time(seconds, granularity=2): + result = [] + + for name, count in display_intervals: + value = seconds // count + if value: + seconds -= value * count + if value == 1: + name = name.rstrip('s') + result.append("{} {}".format(value, name)) + return ', '.join(result[:granularity]) + +def prepare_plot(title): + plt.title(title) + plt.grid() + plt.legend(loc = 'best') + plt.xlabel("q") diff --git a/data/CLs/finished/f1d1/2254886/pdg_const.py b/data/CLs/finished/f1d1/2254886/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2254886/pdg_const.py @@ -0,0 +1,226 @@ +pdg = { + + + ###Particle masses### + + "mbstar" : 5415.4, + "mbstar0" : 5711.0, + "B0_M" : 5279.5, + "Bs_M" : 5366.7, + "Bplus_M" : 5279.3, + "Lb_M" : 5619.4, + "D0_M" : 1864.8, + "Dst_M" : 2010, + "pi_M" : 139.6, + "Jpsi_M" : 3096.9, + "Psi2s_M" : 3685.6, + "kaon_M" : 493.7, + "Ks_M" : 497.6, + "phi_M" : 1019.5, + "rho_M" : 775.26, + "rho_width" : 149.1, + "omega_M" : 782.65, + "omega_width" : 8.49, + + "muon_M" : 105.7, + "tau_M": 1776.86, + + "squark_M" : 95.0, + "bquark_M" : 4180.0, + "cquark_M" : 1275.0, + + "Bplus_tau" : 1.638e-12, + + ###Wilson coefficients### + + "C1" : -0.257, + "C2" : 1.009, + "C3" : -0.005, + "C4" : -0.078, + + "C7eff" : -0.306, + "C9eff" : 4.211, + "C10eff" : -4.103, + +# "C7eff": 0.0, +# "C9eff": 0.0, +# "C10eff": 0.0, + + ###Other constants + + "GF" : 1.1663787e-5, + "alpha_ew" : 1.0/137.0, + "Vts" : 0.0394, + "Vtb" : 1.019, + "number_of_decays": 5404696, + + #Formfactor z coefficients + + #"b0" : [0.285, 0.19, -0.17], + #"bplus" : [0.437, -1.41, -2.5], + #"bT" : [0.440, -1.47, -2.7] + + "b0" : [0.292, 0.281, 0.150], + "bplus" : [0.466, -0.885, -0.213], + "bT" : [0.460, -1.089, -1.114], + + "NR_BR": 4.37e-7, + "NR_auc": 0.00133, + + #Resonances format(mass, width, phase, scale) + + # pre scaling + +# "rho": (775.26, 149.0, -0.35, 1.0), + +# "omega": (782.7, 8.5, 0.26, 1.0), + +# "phi": (1019.46, 4.25, 0.5, 1.0), + +# "jpsi": (3096.0, 0.09, -1.5, 2e-2), +# "jpsi_auc": 0.2126825758464027, + +# "psi2s": (3686.0, 0.3, -1.5, 3.14e-3), +# "psi2s_auc": 2.802257483178487e-10, + +# "p3770": (3773.0, 27.2, -2.13, 1.0e-3), + +# "p4040": (4039.0, 80.0, -2.52, 2.0), + +# "p4160": (4191.0, 70.0, -1.9, 2.2), + +# "p4415": (4421.0, 62.0, -2.52, 1.0), + + + # after scaling (Phase combination --) + + +# "rho": (743.2, 149.0, -0.22, 1.05), + +# "omega": (782.7, 8.5, 0.38, 6.8), + +# "phi": (1013.5, 4.25, 0.62, 19.2), + +# "jpsi": (3096.1, 0.09, 1.63, 9897.0), +# "jpsi_auc": 0.2126825758464027, +# "jpsi_phase_unc": 0.05, + +# "psi2s": (3686.0, 0.3, 1.8, 1396.0), +# "psi2s_auc": 0.0151332263, +# "psi2s_phase_unc": 0.1, + +# "p3770": (3773.0, 27.2, -2.95, 2.5), + +# "p4040": (4039.0, 80.0, -2.75, 1.01), + +# "p4160": (4191.0, 70.0, -2.28, 2.2), + +# "p4415": (4421.0, 62.0, -2.31, 1.24), + + # Phase combination of paper ++ + +# "rho": (743.2, 149.0, -0.35, 1.05), + +# "omega": (782.7, 8.5, 0.26, 6.8), + +# "phi": (1013.5, 4.25, 0.47, 19.2), + +# "jpsi": (3096.1, 0.09, -1.66, 9897.0), +# "jpsi_auc": 0.2126825758464027, +# "jpsi_phase_unc": 0.05, + +# "psi2s": (3686.0, 0.3, -1.93, 1396.0), +# "psi2s_auc": 0.0151332263, +# "psi2s_phase_unc": 0.1, + +# "p3770": (3773.0, 27.2, -2.13, 2.5), + +# "p4040": (4039.0, 80.0, -2.52, 1.01), + +# "p4160": (4191.0, 70.0, -1.90, 2.2), + +# "p4415": (4421.0, 62.0, -2.52, 1.24), + + # Phase combination of paper +- + + # "rho": (743.2, 149.0, -0.26, 1.05), + # + # "omega": (782.7, 8.5, 0.35, 6.8), + # + # "phi": (1013.5, 4.25, 0.58, 19.2), + # + # "jpsi": (3096.1, 0.09, 1.47, 9897.0), + # "jpsi_auc": 0.2126825758464027, + # "jpsi_phase_unc": 0.05, + # + # "psi2s": (3686.0, 0.3, -2.21, 1396.0), + # "psi2s_auc": 0.0151332263, + # "psi2s_phase_unc": 0.1, + # + # "p3770": (3773.0, 27.2, -2.140, 2.5), + # + # "p4040": (4039.0, 80.0, -2.64, 1.01), + # + # "p4160": (4191.0, 70.0, -2.11, 2.2), + # + # "p4415": (4421.0, 62.0, -2.42, 1.24), + + # Phase combination of paper -+ + + "rho": (743.2, 149.0, -0.30, 1.05), + + "omega": (782.7, 8.5, 0.30, 6.8), + + "phi": (1013.5, 4.25, 0.51, 19.2), + + "jpsi": (3096.1, 0.09, -1.5, 9897.0), + "jpsi_auc": 0.2126825758464027, + "jpsi_phase_unc": 0.05, + + "psi2s": (3686.0, 0.3, 2.08, 1396.0), + "psi2s_auc": 0.0151332263, + "psi2s_phase_unc": 0.1, + + "p3770": (3773.0, 27.2, -2.89, 2.5), + + "p4040": (4039.0, 80.0, -2.69, 1.01), + + "p4160": (4191.0, 70.0, -2.13, 2.2), + + "p4415": (4421.0, 62.0, -2.43, 1.24), + + + # zeroing resonances + +# "rho": (775.26, 149.0, -0.35, 0.0), +# "omega": (782.7, 8.5, 0.26, 0.0), +# "phi": (1019.46, 4.25, 0.5, 0.0), +# "jpsi": (3096.0, 0.09, -1.5, 0.0), +# "psi2s": (3686.0, 0.3, -1.5, 0.0), +# "p3770": (3773.0, 27.2, -2.13, 0.0), +# "p4040": (4039.0, 80.0, -2.52, 0.0), +# "p4160": (4147.0, 22.0, -1.9, 0.0), +# "p4415": (4421.0, 62.0, -2.52, 0.0), + + # 2P contributions format(mass, amp, phase) + +# "D_bar": ( + + #general + + "rho_BR": 1.7e-10, + "omega_BR": 4.9e-10, + "phi_BR": 2.5e-9, + "jpsi_BR": 6.02e-5, + "psi2s_BR": 4.97e-6, + "p3770_BR": 1.38e-9, + "p4040_BR": 4.2e-10, + "p4160_BR": 2.6e-9, + "p4415_BR": 6.1e-10, + +# Estimates + "Dbar_scale": 1.46, #with phase = pi + + "DDstar_scale": 2.41, #with phase = pi + + } diff --git a/data/CLs/finished/f1d1/2254886/raremodel-nb1.py b/data/CLs/finished/f1d1/2254886/raremodel-nb1.py new file mode 100644 index 0000000..1a5d9be --- /dev/null +++ b/data/CLs/finished/f1d1/2254886/raremodel-nb1.py @@ -0,0 +1,1939 @@ +#!/usr/bin/env python +# coding: utf-8 + +# # Import + +# In[1]: + + +import os + +# os.environ["CUDA_VISIBLE_DEVICES"] = "-1" + +import numpy as np +from pdg_const import pdg +import matplotlib +import matplotlib.pyplot as plt +import pickle as pkl +import sys +import time +from helperfunctions import display_time, prepare_plot +import cmath as c +import scipy.integrate as integrate +from scipy.optimize import fminbound +from array import array as arr +import collections +from itertools import compress +import tensorflow as tf +import zfit +from zfit import ztf +# from IPython.display import clear_output +import os +import tensorflow_probability as tfp +tfd = tfp.distributions + + +# In[2]: + + +# chunksize = 10000 +# zfit.run.chunking.active = True +# zfit.run.chunking.max_n_points = chunksize + + +# # Build model and graphs +# ## Create graphs + +# In[ ]: + + + + + +# In[3]: + + +def formfactor(q2, subscript, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): #returns real value + #check if subscript is viable + + if subscript != "0" and subscript != "+" and subscript != "T": + raise ValueError('Wrong subscript entered, choose either 0, + or T') + + #get constants + + mK = ztf.constant(pdg['Ks_M']) + mbstar0 = ztf.constant(pdg["mbstar0"]) + mbstar = ztf.constant(pdg["mbstar"]) + + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mB = ztf.constant(pdg['Bplus_M']) + + #N comes from derivation in paper + + N = 3 + + #some helperfunctions + + tpos = (mB - mK)**2 + tzero = (mB + mK)*(ztf.sqrt(mB)-ztf.sqrt(mK))**2 + + z_oben = ztf.sqrt(tpos - q2) - ztf.sqrt(tpos - tzero) + z_unten = ztf.sqrt(tpos - q2) + ztf.sqrt(tpos - tzero) + z = tf.divide(z_oben, z_unten) + + #calculate f0 + + if subscript == "0": + prefactor = 1/(1 - q2/(mbstar0**2)) + _sum = 0 + b0 = [b0_0, b0_1, b0_2] + + for i in range(N): + _sum += b0[i]*(tf.pow(z,i)) + + return ztf.to_complex(prefactor * _sum) + + #calculate f+ or fT + + else: + prefactor = 1/(1 - q2/(mbstar**2)) + _sum = 0 + + if subscript == "T": + bT = [bT_0, bT_1, bT_2] + for i in range(N): + _sum += bT[i] * (tf.pow(z, i) - ((-1)**(i-N)) * (i/N) * tf.pow(z, N)) + else: + bplus = [bplus_0, bplus_1, bplus_2] + for i in range(N): + _sum += bplus[i] * (tf.pow(z, i) - ((-1)**(i-N)) * (i/N) * tf.pow(z, N)) + + return ztf.to_complex(prefactor * _sum) + +def resonance(q, _mass, width, phase, scale): + + q2 = tf.pow(q, 2) + + mmu = ztf.constant(pdg['muon_M']) + + p = 0.5 * ztf.sqrt(q2 - 4*(mmu**2)) + + p0 = 0.5 * ztf.sqrt(_mass**2 - 4*mmu**2) + + gamma_j = tf.divide(p, q) * _mass * width / p0 + + #Calculate the resonance + + _top = tf.complex(_mass * width, ztf.constant(0.0)) + + _bottom = tf.complex(_mass**2 - q2, -_mass*gamma_j) + + com = _top/_bottom + + #Rotate by the phase + + r = ztf.to_complex(scale*tf.abs(com)) + + _phase = tf.angle(com) + + _phase += phase + + com = r * tf.exp(tf.complex(ztf.constant(0.0), _phase)) + + return com + + +def axiv_nonres(q, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): + + GF = ztf.constant(pdg['GF']) + alpha_ew = ztf.constant(pdg['alpha_ew']) + Vtb = ztf.constant(pdg['Vtb']) + Vts = ztf.constant(pdg['Vts']) + C10eff = ztf.constant(pdg['C10eff']) + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mK = ztf.constant(pdg['Ks_M']) + mB = ztf.constant(pdg['Bplus_M']) + + q2 = tf.pow(q, 2) + + #Some helperfunctions + + beta = 1. - 4. * mmu**2. / q2 + + 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.) + + #prefactor in front of whole bracket + + prefactor1 = GF**2. *alpha_ew**2. * (tf.abs(Vtb*Vts))**2. * kabs * beta / (128. * np.pi**5.) + + #left term in bracket + + bracket_left = 2./3. * tf.pow(kabs,2) * tf.pow(beta,2) * tf.pow(tf.abs(ztf.to_complex(C10eff)*formfactor(q2, "+", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)),2) + + #middle term in bracket + + _top = 4. * mmu**2. * (mB**2. - mK**2.) * (mB**2. - mK**2.) + + _under = q2 * mB**2. + + bracket_middle = _top/_under *tf.pow(tf.abs(ztf.to_complex(C10eff) * formfactor(q2, "0", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)), 2) + + #Note sqrt(q2) comes from derivation as we use q2 and plot q + + return prefactor1 * (bracket_left + bracket_middle) * 2 * q + +def vec(q, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): + + q2 = tf.pow(q, 2) + + GF = ztf.constant(pdg['GF']) + alpha_ew = ztf.constant(pdg['alpha_ew']) + Vtb = ztf.constant(pdg['Vtb']) + Vts = ztf.constant(pdg['Vts']) + C7eff = ztf.constant(pdg['C7eff']) + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mK = ztf.constant(pdg['Ks_M']) + mB = ztf.constant(pdg['Bplus_M']) + + #Some helperfunctions + + beta = 1. - 4. * mmu**2. / q2 + + 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) + + #prefactor in front of whole bracket + + prefactor1 = GF**2. *alpha_ew**2. * (tf.abs(Vtb*Vts))**2 * kabs * beta / (128. * np.pi**5.) + + #right term in bracket + + prefactor2 = tf.pow(kabs,2) * (1. - 1./3. * beta) + + abs_bracket = tf.pow(tf.abs(c9eff(q, funcs) * formfactor(q2, "+", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + ztf.to_complex(2.0 * C7eff * (mb + ms)/(mB + mK)) * formfactor(q2, "T", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)),2) + + bracket_right = prefactor2 * abs_bracket + + #Note sqrt(q2) comes from derivation as we use q2 and plot q + + return prefactor1 * bracket_right * 2 * q + +def c9eff(q, funcs): + + C9eff_nr = ztf.to_complex(ztf.constant(pdg['C9eff'])) + + c9 = C9eff_nr + funcs + + return c9 + + +# In[4]: + + +def G(y): + + def inner_rect_bracket(q): + return tf.log(ztf.to_complex((1+tf.sqrt(q))/(1-tf.sqrt(q)))-tf.complex(ztf.constant(0), -1*ztf.constant(np.pi))) + + def inner_right(q): + return ztf.to_complex(2 * tf.atan(1/tf.sqrt(tf.math.real(-q)))) + + big_bracket = tf.where(tf.math.real(y) > ztf.constant(0.0), inner_rect_bracket(y), inner_right(y)) + + return ztf.to_complex(tf.sqrt(tf.abs(y))) * big_bracket + +def h_S(m, q): + + 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))) + +def h_P(m, q): + + 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) + +def two_p_ccbar(mD, m_D_bar, m_D_star, q): + + + #Load constants + nu_D_bar = ztf.to_complex(pdg["nu_D_bar"]) + nu_D = ztf.to_complex(pdg["nu_D"]) + nu_D_star = ztf.to_complex(pdg["nu_D_star"]) + + phase_D_bar = ztf.to_complex(pdg["phase_D_bar"]) + phase_D = ztf.to_complex(pdg["phase_D"]) + phase_D_star = ztf.to_complex(pdg["phase_D_star"]) + + #Calculation + left_part = nu_D_bar * tf.exp(tf.complex(ztf.constant(0.0), phase_D_bar)) * h_S(m_D_bar, q) + + right_part_D = nu_D * tf.exp(tf.complex(ztf.constant(0.0), phase_D)) * h_P(m_D, q) + + right_part_D_star = nu_D_star * tf.exp(tf.complex(ztf.constant(0.0), phase_D_star)) * h_P(m_D_star, q) + + return left_part + right_part_D + right_part_D_star + + +# ## Build pdf + +# In[5]: + + +class total_pdf_cut(zfit.pdf.ZPDF): + _N_OBS = 1 # dimension, can be omitted + _PARAMS = ['b0_0', 'b0_1', 'b0_2', + 'bplus_0', 'bplus_1', 'bplus_2', + 'bT_0', 'bT_1', 'bT_2', + 'rho_mass', 'rho_scale', 'rho_phase', 'rho_width', + 'jpsi_mass', 'jpsi_scale', 'jpsi_phase', 'jpsi_width', + 'psi2s_mass', 'psi2s_scale', 'psi2s_phase', 'psi2s_width', + 'p3770_mass', 'p3770_scale', 'p3770_phase', 'p3770_width', + 'p4040_mass', 'p4040_scale', 'p4040_phase', 'p4040_width', + 'p4160_mass', 'p4160_scale', 'p4160_phase', 'p4160_width', + 'p4415_mass', 'p4415_scale', 'p4415_phase', 'p4415_width', + 'omega_mass', 'omega_scale', 'omega_phase', 'omega_width', + 'phi_mass', 'phi_scale', 'phi_phase', 'phi_width', + 'Dbar_mass', 'Dbar_scale', 'Dbar_phase', + 'Dstar_mass', 'DDstar_scale', 'DDstar_phase', 'D_mass', + 'tau_mass', 'C_tt'] +# the name of the parameters + + def _unnormalized_pdf(self, x): + + x = x.unstack_x() + + b0 = [self.params['b0_0'], self.params['b0_1'], self.params['b0_2']] + bplus = [self.params['bplus_0'], self.params['bplus_1'], self.params['bplus_2']] + bT = [self.params['bT_0'], self.params['bT_1'], self.params['bT_2']] + + def rho_res(q): + return resonance(q, _mass = self.params['rho_mass'], scale = self.params['rho_scale'], + phase = self.params['rho_phase'], width = self.params['rho_width']) + + def omega_res(q): + return resonance(q, _mass = self.params['omega_mass'], scale = self.params['omega_scale'], + phase = self.params['omega_phase'], width = self.params['omega_width']) + + def phi_res(q): + return resonance(q, _mass = self.params['phi_mass'], scale = self.params['phi_scale'], + phase = self.params['phi_phase'], width = self.params['phi_width']) + + def jpsi_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['jpsi_mass'], 2)) * resonance(q, _mass = self.params['jpsi_mass'], + scale = self.params['jpsi_scale'], + phase = self.params['jpsi_phase'], + width = self.params['jpsi_width']) + def psi2s_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['psi2s_mass'], 2)) * resonance(q, _mass = self.params['psi2s_mass'], + scale = self.params['psi2s_scale'], + phase = self.params['psi2s_phase'], + width = self.params['psi2s_width']) + def p3770_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p3770_mass'], 2)) * resonance(q, _mass = self.params['p3770_mass'], + scale = self.params['p3770_scale'], + phase = self.params['p3770_phase'], + width = self.params['p3770_width']) + + def p4040_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4040_mass'], 2)) * resonance(q, _mass = self.params['p4040_mass'], + scale = self.params['p4040_scale'], + phase = self.params['p4040_phase'], + width = self.params['p4040_width']) + + def p4160_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4160_mass'], 2)) * resonance(q, _mass = self.params['p4160_mass'], + scale = self.params['p4160_scale'], + phase = self.params['p4160_phase'], + width = self.params['p4160_width']) + + def p4415_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4415_mass'], 2)) * resonance(q, _mass = self.params['p4415_mass'], + scale = self.params['p4415_scale'], + phase = self.params['p4415_phase'], + width = self.params['p4415_width']) + + def P2_D(q): + 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)) + 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['Dstar_mass'], q)) + ztf.to_complex(h_P(self.params['D_mass'], q))) + return Dbar_contrib + DDstar_contrib + + def ttau_cusp(q): + 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))) + + + 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) + + vec_f = vec(x, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + axiv_nr = axiv_nonres(x, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + tot = vec_f + axiv_nr + + #Cut out jpsi and psi2s + + tot = tf.where(tf.math.logical_or(x < ztf.constant(jpsi_mass-60.), x > ztf.constant(jpsi_mass+70.)), tot, 0.0*tot) + + tot = tf.where(tf.math.logical_or(x < ztf.constant(psi2s_mass-50.), x > ztf.constant(psi2s_mass+50.)), tot, 0.0*tot) + + return tot + +class total_pdf_full(zfit.pdf.ZPDF): + _N_OBS = 1 # dimension, can be omitted + _PARAMS = ['b0_0', 'b0_1', 'b0_2', + 'bplus_0', 'bplus_1', 'bplus_2', + 'bT_0', 'bT_1', 'bT_2', + 'rho_mass', 'rho_scale', 'rho_phase', 'rho_width', + 'jpsi_mass', 'jpsi_scale', 'jpsi_phase', 'jpsi_width', + 'psi2s_mass', 'psi2s_scale', 'psi2s_phase', 'psi2s_width', + 'p3770_mass', 'p3770_scale', 'p3770_phase', 'p3770_width', + 'p4040_mass', 'p4040_scale', 'p4040_phase', 'p4040_width', + 'p4160_mass', 'p4160_scale', 'p4160_phase', 'p4160_width', + 'p4415_mass', 'p4415_scale', 'p4415_phase', 'p4415_width', + 'omega_mass', 'omega_scale', 'omega_phase', 'omega_width', + 'phi_mass', 'phi_scale', 'phi_phase', 'phi_width', + 'Dbar_mass', 'Dbar_scale', 'Dbar_phase', + 'Dstar_mass', 'DDstar_scale', 'DDstar_phase', 'D_mass', + 'tau_mass', 'C_tt'] +# the name of the parameters + + def _unnormalized_pdf(self, x): + + x = x.unstack_x() + + b0 = [self.params['b0_0'], self.params['b0_1'], self.params['b0_2']] + bplus = [self.params['bplus_0'], self.params['bplus_1'], self.params['bplus_2']] + bT = [self.params['bT_0'], self.params['bT_1'], self.params['bT_2']] + + def rho_res(q): + return resonance(q, _mass = self.params['rho_mass'], scale = self.params['rho_scale'], + phase = self.params['rho_phase'], width = self.params['rho_width']) + + def omega_res(q): + return resonance(q, _mass = self.params['omega_mass'], scale = self.params['omega_scale'], + phase = self.params['omega_phase'], width = self.params['omega_width']) + + def phi_res(q): + return resonance(q, _mass = self.params['phi_mass'], scale = self.params['phi_scale'], + phase = self.params['phi_phase'], width = self.params['phi_width']) + + def jpsi_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['jpsi_mass'], 2)) * resonance(q, _mass = self.params['jpsi_mass'], + scale = self.params['jpsi_scale'], + phase = self.params['jpsi_phase'], + width = self.params['jpsi_width']) + def psi2s_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['psi2s_mass'], 2)) * resonance(q, _mass = self.params['psi2s_mass'], + scale = self.params['psi2s_scale'], + phase = self.params['psi2s_phase'], + width = self.params['psi2s_width']) + def p3770_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p3770_mass'], 2)) * resonance(q, _mass = self.params['p3770_mass'], + scale = self.params['p3770_scale'], + phase = self.params['p3770_phase'], + width = self.params['p3770_width']) + + def p4040_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4040_mass'], 2)) * resonance(q, _mass = self.params['p4040_mass'], + scale = self.params['p4040_scale'], + phase = self.params['p4040_phase'], + width = self.params['p4040_width']) + + def p4160_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4160_mass'], 2)) * resonance(q, _mass = self.params['p4160_mass'], + scale = self.params['p4160_scale'], + phase = self.params['p4160_phase'], + width = self.params['p4160_width']) + + def p4415_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4415_mass'], 2)) * resonance(q, _mass = self.params['p4415_mass'], + scale = self.params['p4415_scale'], + phase = self.params['p4415_phase'], + width = self.params['p4415_width']) + + def P2_D(q): + 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)) + 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['Dstar_mass'], q)) + ztf.to_complex(h_P(self.params['D_mass'], q))) + return Dbar_contrib + DDstar_contrib + + def ttau_cusp(q): + 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))) + + + 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) + + vec_f = vec(x, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + axiv_nr = axiv_nonres(x, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + tot = vec_f + axiv_nr + + #Cut out jpsi and psi2s + +# tot = tf.where(tf.math.logical_or(x < ztf.constant(jpsi_mass-60.), x > ztf.constant(jpsi_mass+70.)), tot, 0.0*tot) + +# tot = tf.where(tf.math.logical_or(x < ztf.constant(psi2s_mass-50.), x > ztf.constant(psi2s_mass+50.)), tot, 0.0*tot) + + return tot + + +# ## Setup parameters + +# In[6]: + + +# formfactors + +b0_0 = zfit.Parameter("b0_0", ztf.constant(0.292), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +b0_1 = zfit.Parameter("b0_1", ztf.constant(0.281), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +b0_2 = zfit.Parameter("b0_2", ztf.constant(0.150), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) + +bplus_0 = zfit.Parameter("bplus_0", ztf.constant(0.466), lower_limit = -2.0, upper_limit= 2.0) +bplus_1 = zfit.Parameter("bplus_1", ztf.constant(-0.885), lower_limit = -2.0, upper_limit= 2.0) +bplus_2 = zfit.Parameter("bplus_2", ztf.constant(-0.213), lower_limit = -2.0, upper_limit= 2.0) + +bT_0 = zfit.Parameter("bT_0", ztf.constant(0.460), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +bT_1 = zfit.Parameter("bT_1", ztf.constant(-1.089), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +bT_2 = zfit.Parameter("bT_2", ztf.constant(-1.114), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) + + +#rho + +rho_mass, rho_width, rho_phase, rho_scale = pdg["rho"] + +rho_m = zfit.Parameter("rho_m", ztf.constant(rho_mass), floating = False) #lower_limit = rho_mass - rho_width, upper_limit = rho_mass + rho_width) +rho_w = zfit.Parameter("rho_w", ztf.constant(rho_width), floating = False) +rho_p = zfit.Parameter("rho_p", ztf.constant(rho_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +rho_s = zfit.Parameter("rho_s", ztf.constant(rho_scale), lower_limit=rho_scale-np.sqrt(rho_scale), upper_limit=rho_scale+np.sqrt(rho_scale)) + +#omega + +omega_mass, omega_width, omega_phase, omega_scale = pdg["omega"] + +omega_m = zfit.Parameter("omega_m", ztf.constant(omega_mass), floating = False) +omega_w = zfit.Parameter("omega_w", ztf.constant(omega_width), floating = False) +omega_p = zfit.Parameter("omega_p", ztf.constant(omega_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +omega_s = zfit.Parameter("omega_s", ztf.constant(omega_scale), lower_limit=omega_scale-np.sqrt(omega_scale), upper_limit=omega_scale+np.sqrt(omega_scale)) + + +#phi + +phi_mass, phi_width, phi_phase, phi_scale = pdg["phi"] + +phi_m = zfit.Parameter("phi_m", ztf.constant(phi_mass), floating = False) +phi_w = zfit.Parameter("phi_w", ztf.constant(phi_width), floating = False) +phi_p = zfit.Parameter("phi_p", ztf.constant(phi_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +phi_s = zfit.Parameter("phi_s", ztf.constant(phi_scale), lower_limit=phi_scale-np.sqrt(phi_scale), upper_limit=phi_scale+np.sqrt(phi_scale)) + +#jpsi + +jpsi_mass, jpsi_width, jpsi_phase, jpsi_scale = pdg["jpsi"] + +jpsi_m = zfit.Parameter("jpsi_m", ztf.constant(jpsi_mass), floating = False) +jpsi_w = zfit.Parameter("jpsi_w", ztf.constant(jpsi_width), floating = False) +jpsi_p = zfit.Parameter("jpsi_p", ztf.constant(jpsi_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +jpsi_s = zfit.Parameter("jpsi_s", ztf.constant(jpsi_scale), floating = False) #, lower_limit=jpsi_scale-np.sqrt(jpsi_scale), upper_limit=jpsi_scale+np.sqrt(jpsi_scale)) + +#psi2s + +psi2s_mass, psi2s_width, psi2s_phase, psi2s_scale = pdg["psi2s"] + +psi2s_m = zfit.Parameter("psi2s_m", ztf.constant(psi2s_mass), floating = False) +psi2s_w = zfit.Parameter("psi2s_w", ztf.constant(psi2s_width), floating = False) +psi2s_p = zfit.Parameter("psi2s_p", ztf.constant(psi2s_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +psi2s_s = zfit.Parameter("psi2s_s", ztf.constant(psi2s_scale), floating = False) #, lower_limit=psi2s_scale-np.sqrt(psi2s_scale), upper_limit=psi2s_scale+np.sqrt(psi2s_scale)) + +#psi(3770) + +p3770_mass, p3770_width, p3770_phase, p3770_scale = pdg["p3770"] + +p3770_m = zfit.Parameter("p3770_m", ztf.constant(p3770_mass), floating = False) +p3770_w = zfit.Parameter("p3770_w", ztf.constant(p3770_width), floating = False) +p3770_p = zfit.Parameter("p3770_p", ztf.constant(p3770_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p3770_s = zfit.Parameter("p3770_s", ztf.constant(p3770_scale), lower_limit=p3770_scale-np.sqrt(p3770_scale), upper_limit=p3770_scale+np.sqrt(p3770_scale)) + +#psi(4040) + +p4040_mass, p4040_width, p4040_phase, p4040_scale = pdg["p4040"] + +p4040_m = zfit.Parameter("p4040_m", ztf.constant(p4040_mass), floating = False) +p4040_w = zfit.Parameter("p4040_w", ztf.constant(p4040_width), floating = False) +p4040_p = zfit.Parameter("p4040_p", ztf.constant(p4040_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4040_s = zfit.Parameter("p4040_s", ztf.constant(p4040_scale), lower_limit=p4040_scale-np.sqrt(p4040_scale), upper_limit=p4040_scale+np.sqrt(p4040_scale)) + +#psi(4160) + +p4160_mass, p4160_width, p4160_phase, p4160_scale = pdg["p4160"] + +p4160_m = zfit.Parameter("p4160_m", ztf.constant(p4160_mass), floating = False) +p4160_w = zfit.Parameter("p4160_w", ztf.constant(p4160_width), floating = False) +p4160_p = zfit.Parameter("p4160_p", ztf.constant(p4160_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4160_s = zfit.Parameter("p4160_s", ztf.constant(p4160_scale), lower_limit=p4160_scale-np.sqrt(p4160_scale), upper_limit=p4160_scale+np.sqrt(p4160_scale)) + +#psi(4415) + +p4415_mass, p4415_width, p4415_phase, p4415_scale = pdg["p4415"] + +p4415_m = zfit.Parameter("p4415_m", ztf.constant(p4415_mass), floating = False) +p4415_w = zfit.Parameter("p4415_w", ztf.constant(p4415_width), floating = False) +p4415_p = zfit.Parameter("p4415_p", ztf.constant(p4415_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4415_s = zfit.Parameter("p4415_s", ztf.constant(p4415_scale), lower_limit=p4415_scale-np.sqrt(p4415_scale), upper_limit=p4415_scale+np.sqrt(p4415_scale)) + + +# ## Dynamic generation of 2 particle contribution + +# In[7]: + + +m_c = 1300 + +Dbar_phase = 0.0 +DDstar_phase = 0.0 +Dstar_mass = pdg['Dst_M'] +Dbar_mass = pdg['D0_M'] +D_mass = pdg['D0_M'] + +Dbar_s = zfit.Parameter("Dbar_s", ztf.constant(0.0), lower_limit=-0.3, upper_limit=0.3) +Dbar_m = zfit.Parameter("Dbar_m", ztf.constant(Dbar_mass), floating = False) +Dbar_p = zfit.Parameter("Dbar_p", ztf.constant(Dbar_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi)#, floating = False) +DDstar_s = zfit.Parameter("DDstar_s", ztf.constant(0.0), lower_limit=-0.3, upper_limit=0.3)#, floating = False) +Dstar_m = zfit.Parameter("Dstar_m", ztf.constant(Dstar_mass), floating = False) +D_m = zfit.Parameter("D_m", ztf.constant(D_mass), floating = False) +DDstar_p = zfit.Parameter("DDstar_p", ztf.constant(DDstar_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi)#, floating = False) + + +# ## Tau parameters + +# In[8]: + + +tau_m = zfit.Parameter("tau_m", ztf.constant(pdg['tau_M']), floating = False) +Ctt = zfit.Parameter("Ctt", ztf.constant(0.0), lower_limit=-1.5, upper_limit=1.5) + + +# ## Load data + +# In[9]: + + +x_min = 2*pdg['muon_M'] +x_max = (pdg["Bplus_M"]-pdg["Ks_M"]-0.1) + +# # Full spectrum + +obs_toy = zfit.Space('q', limits = (x_min, x_max)) + +# Jpsi and Psi2s cut out + +obs1 = zfit.Space('q', limits = (x_min, jpsi_mass - 60.)) +obs2 = zfit.Space('q', limits = (jpsi_mass + 70., psi2s_mass - 50.)) +obs3 = zfit.Space('q', limits = (psi2s_mass + 50., x_max)) + +obs_fit = obs1 + obs2 + obs3 + +# 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: +# part_set = pkl.load(input_file) + +# x_part = part_set['x_part'] + +# x_part = x_part.astype('float64') + +# data = zfit.data.Data.from_numpy(array=x_part, obs=obs) + + +# ## Setup pdf + +# In[10]: + + +total_f = total_pdf_cut(obs=obs_toy, jpsi_mass = jpsi_m, jpsi_scale = jpsi_s, jpsi_phase = jpsi_p, jpsi_width = jpsi_w, + psi2s_mass = psi2s_m, psi2s_scale = psi2s_s, psi2s_phase = psi2s_p, psi2s_width = psi2s_w, + p3770_mass = p3770_m, p3770_scale = p3770_s, p3770_phase = p3770_p, p3770_width = p3770_w, + p4040_mass = p4040_m, p4040_scale = p4040_s, p4040_phase = p4040_p, p4040_width = p4040_w, + p4160_mass = p4160_m, p4160_scale = p4160_s, p4160_phase = p4160_p, p4160_width = p4160_w, + p4415_mass = p4415_m, p4415_scale = p4415_s, p4415_phase = p4415_p, p4415_width = p4415_w, + rho_mass = rho_m, rho_scale = rho_s, rho_phase = rho_p, rho_width = rho_w, + omega_mass = omega_m, omega_scale = omega_s, omega_phase = omega_p, omega_width = omega_w, + phi_mass = phi_m, phi_scale = phi_s, phi_phase = phi_p, phi_width = phi_w, + Dstar_mass = Dstar_m, DDstar_scale = DDstar_s, DDstar_phase = DDstar_p, D_mass = D_m, + Dbar_mass = Dbar_m, Dbar_scale = Dbar_s, Dbar_phase = Dbar_p, + tau_mass = tau_m, C_tt = Ctt, b0_0 = b0_0, b0_1 = b0_1, b0_2 = b0_2, + bplus_0 = bplus_0, bplus_1 = bplus_1, bplus_2 = bplus_2, + bT_0 = bT_0, bT_1 = bT_1, bT_2 = bT_2) + +total_f_fit = total_pdf_full(obs=obs_fit, jpsi_mass = jpsi_m, jpsi_scale = jpsi_s, jpsi_phase = jpsi_p, jpsi_width = jpsi_w, + psi2s_mass = psi2s_m, psi2s_scale = psi2s_s, psi2s_phase = psi2s_p, psi2s_width = psi2s_w, + p3770_mass = p3770_m, p3770_scale = p3770_s, p3770_phase = p3770_p, p3770_width = p3770_w, + p4040_mass = p4040_m, p4040_scale = p4040_s, p4040_phase = p4040_p, p4040_width = p4040_w, + p4160_mass = p4160_m, p4160_scale = p4160_s, p4160_phase = p4160_p, p4160_width = p4160_w, + p4415_mass = p4415_m, p4415_scale = p4415_s, p4415_phase = p4415_p, p4415_width = p4415_w, + rho_mass = rho_m, rho_scale = rho_s, rho_phase = rho_p, rho_width = rho_w, + omega_mass = omega_m, omega_scale = omega_s, omega_phase = omega_p, omega_width = omega_w, + phi_mass = phi_m, phi_scale = phi_s, phi_phase = phi_p, phi_width = phi_w, + Dstar_mass = Dstar_m, DDstar_scale = DDstar_s, DDstar_phase = DDstar_p, D_mass = D_m, + Dbar_mass = Dbar_m, Dbar_scale = Dbar_s, Dbar_phase = Dbar_p, + tau_mass = tau_m, C_tt = Ctt, b0_0 = b0_0, b0_1 = b0_1, b0_2 = b0_2, + bplus_0 = bplus_0, bplus_1 = bplus_1, bplus_2 = bplus_2, + bT_0 = bT_0, bT_1 = bT_1, bT_2 = bT_2) + +# print(total_pdf.obs) + +# print(calcs_test) + +# for param in total_f.get_dependents(): +# print(zfit.run(param)) + + +# In[11]: + + +total_f_fit.normalization(obs_toy) + + +# ## Test if graphs actually work and compute values + +# In[12]: + + +# def total_test_tf(xq): + +# def jpsi_res(q): +# return resonance(q, jpsi_m, jpsi_s, jpsi_p, jpsi_w) + +# def psi2s_res(q): +# return resonance(q, psi2s_m, psi2s_s, psi2s_p, psi2s_w) + +# def cusp(q): +# return bifur_gauss(q, cusp_m, sig_L, sig_R, cusp_s) + +# funcs = jpsi_res(xq) + psi2s_res(xq) + cusp(xq) + +# vec_f = vec(xq, funcs) + +# axiv_nr = axiv_nonres(xq) + +# tot = vec_f + axiv_nr + +# return tot + +# def jpsi_res(q): +# return resonance(q, jpsi_m, jpsi_s, jpsi_p, jpsi_w) + +# calcs = zfit.run(total_test_tf(x_part)) + +test_q = np.linspace(x_min, x_max, int(2e6)) + +probs = total_f_fit.pdf(test_q, norm_range=False) + +calcs_test = zfit.run(probs) +# res_y = zfit.run(jpsi_res(test_q)) +# b0 = [b0_0, b0_1, b0_2] +# bplus = [bplus_0, bplus_1, bplus_2] +# bT = [bT_0, bT_1, bT_2] +# f0_y = zfit.run(tf.math.real(formfactor(test_q,"0", b0, bplus, bT))) +# fplus_y = zfit.run(tf.math.real(formfactor(test_q,"+", b0, bplus, bT))) +# fT_y = zfit.run(tf.math.real(formfactor(test_q,"T", b0, bplus, bT))) + + +# In[13]: + + +plt.clf() +# plt.plot(x_part, calcs, '.') +plt.plot(test_q, calcs_test, label = 'pdf') +# plt.plot(test_q, f0_y, label = '0') +# plt.plot(test_q, fT_y, label = 'T') +# plt.plot(test_q, fplus_y, label = '+') +# plt.plot(test_q, res_y, label = 'res') +plt.legend() +plt.ylim(0.0, 1.5e-6) +# plt.yscale('log') +# plt.xlim(770, 785) +plt.savefig('test.png') +# print(jpsi_width) + + +# In[14]: + + + + +# probs = mixture.prob(test_q) +# probs_np = zfit.run(probs) +# probs_np *= np.max(calcs_test) / np.max(probs_np) +# plt.figure() +# plt.semilogy(test_q, probs_np,label="importance sampling") +# plt.semilogy(test_q, calcs_test, label = 'pdf') + + +# In[15]: + + +# 0.213/(0.00133+0.213+0.015) + + +# ## Adjust scaling of different parts + +# In[16]: + + +total_f.update_integration_options(draws_per_dim=2000000, mc_sampler=None) +# inte = total_f.integrate(limits = (950., 1050.), norm_range=False) +# inte_fl = zfit.run(inte) +# print(inte_fl/4500) +# print(pdg["jpsi_BR"]/pdg["NR_BR"], inte_fl*pdg["psi2s_auc"]/pdg["NR_auc"]) + + +# In[17]: + + +# # print("jpsi:", inte_fl) +# # print("Increase am by factor:", np.sqrt(pdg["jpsi_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# # print("New amp:", pdg["jpsi"][3]*np.sqrt(pdg["jpsi_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + +# # print("psi2s:", inte_fl) +# # print("Increase am by factor:", np.sqrt(pdg["psi2s_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# # print("New amp:", pdg["psi2s"][3]*np.sqrt(pdg["psi2s_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + +# name = "phi" + +# print(name+":", inte_fl) +# print("Increase am by factor:", np.sqrt(pdg[name+"_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# print("New amp:", pdg[name][0]*np.sqrt(pdg[name+"_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + + +# print(x_min) +# print(x_max) +# # total_f.update_integration_options(draws_per_dim=2000000, mc_sampler=None) +# total_f.update_integration_options(mc_sampler=lambda dim, num_results, +# dtype: tf.random_uniform(maxval=1., shape=(num_results, dim), dtype=dtype), +# draws_per_dim=1000000) +# # _ = [] + +# # for i in range(10): + +# # inte = total_f.integrate(limits = (x_min, x_max)) +# # inte_fl = zfit.run(inte) +# # print(inte_fl) +# # _.append(inte_fl) + +# # print("mean:", np.mean(_)) + +# _ = time.time() + +# inte = total_f.integrate(limits = (x_min, x_max)) +# inte_fl = zfit.run(inte) +# print(inte_fl) +# print("Time taken: {}".format(display_time(int(time.time() - _)))) + +# print(pdg['NR_BR']/pdg['NR_auc']*inte_fl) +# print(0.25**2*4.2/1000) + + +# # Sampling +# ## Mixture distribution for sampling + +# In[18]: + + + + +# print(list_of_borders[:9]) +# print(list_of_borders[-9:]) + + +class UniformSampleAndWeights(zfit.util.execution.SessionHolderMixin): + def __call__(self, limits, dtype, n_to_produce): + # n_to_produce = tf.cast(n_to_produce, dtype=tf.int32) + low, high = limits.limit1d + low = tf.cast(low, dtype=dtype) + high = tf.cast(high, dtype=dtype) +# uniform = tfd.Uniform(low=low, high=high) +# uniformjpsi = tfd.Uniform(low=tf.constant(3080, dtype=dtype), high=tf.constant(3112, dtype=dtype)) +# uniformpsi2s = tfd.Uniform(low=tf.constant(3670, dtype=dtype), high=tf.constant(3702, dtype=dtype)) + +# list_of_borders = [] +# _p = [] +# splits = 10 + +# _ = np.linspace(x_min, x_max, splits) + +# for i in range(splits): +# list_of_borders.append(tf.constant(_[i], dtype=dtype)) +# _p.append(tf.constant(1/splits, dtype=dtype)) + +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=_p[:(splits-1)]), +# components_distribution=tfd.Uniform(low=list_of_borders[:(splits-1)], +# high=list_of_borders[-(splits-1):])) + mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.05, dtype=dtype), + tf.constant(0.93, dtype=dtype), + tf.constant(0.05, dtype=dtype), + tf.constant(0.065, dtype=dtype), + tf.constant(0.04, dtype=dtype), + tf.constant(0.05, dtype=dtype)]), + components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), + tf.constant(3090, dtype=dtype), + tf.constant(3681, dtype=dtype), + tf.constant(3070, dtype=dtype), + tf.constant(1000, dtype=dtype), + tf.constant(3660, dtype=dtype)], + high=[tf.constant(x_max, dtype=dtype), + tf.constant(3102, dtype=dtype), + tf.constant(3691, dtype=dtype), + tf.constant(3110, dtype=dtype), + tf.constant(1040, dtype=dtype), + tf.constant(3710, dtype=dtype)])) +# dtype = tf.float64 +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.04, dtype=dtype), +# tf.constant(0.90, dtype=dtype), +# tf.constant(0.02, dtype=dtype), +# tf.constant(0.07, dtype=dtype), +# tf.constant(0.02, dtype=dtype)]), +# components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), +# tf.constant(3089, dtype=dtype), +# tf.constant(3103, dtype=dtype), +# tf.constant(3681, dtype=dtype), +# tf.constant(3691, dtype=dtype)], +# high=[tf.constant(3089, dtype=dtype), +# tf.constant(3103, dtype=dtype), +# tf.constant(3681, dtype=dtype), +# tf.constant(3691, dtype=dtype), +# tf.constant(x_max, dtype=dtype)])) +# mixture = tfd.Uniform(tf.constant(x_min, dtype=dtype), tf.constant(x_max, dtype=dtype)) +# sample = tf.random.uniform((n_to_produce, 1), dtype=dtype) + sample = mixture.sample((n_to_produce, 1)) +# sample = tf.random.uniform((n_to_produce, 1), dtype=dtype) + weights = mixture.prob(sample)[:,0] +# weights = tf.broadcast_to(tf.constant(1., dtype=dtype), shape=(n_to_produce,)) + # sample = tf.expand_dims(sample, axis=-1) +# print(sample, weights) + +# weights = tf.ones(shape=(n_to_produce,), dtype=dtype) + weights_max = None + thresholds = tf.random_uniform(shape=(n_to_produce,), dtype=dtype) + return sample, thresholds, weights, weights_max, n_to_produce + + +# In[19]: + + +# total_f._sample_and_weights = UniformSampleAndWeights + + +# In[20]: + + +# 0.00133/(0.00133+0.213+0.015)*(x_max-3750)/(x_max-x_min) + + +# In[21]: + + +# zfit.settings.set_verbosity(10) + + +# In[22]: + + +# # zfit.run.numeric_checks = False + +# nr_of_toys = 1 +# nevents = int(pdg["number_of_decays"]) +# nevents = pdg["number_of_decays"] +# event_stack = 1000000 +# # zfit.settings.set_verbosity(10) +# calls = int(nevents/event_stack + 1) + +# total_samp = [] + +# start = time.time() + +# sampler = total_f.create_sampler(n=event_stack) + +# for toy in range(nr_of_toys): + +# dirName = 'data/zfit_toys/toy_{0}'.format(toy) + +# if not os.path.exists(dirName): +# os.mkdir(dirName) +# print("Directory " , dirName , " Created ") + +# for call in range(calls): + +# sampler.resample(n=event_stack) +# s = sampler.unstack_x() +# sam = zfit.run(s) +# # clear_output(wait=True) + +# c = call + 1 + +# print("{0}/{1} of Toy {2}/{3}".format(c, calls, toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(c+calls*(toy))*((nr_of_toys-toy)*calls-c))))) + +# with open("data/zfit_toys/toy_{0}/{1}.pkl".format(toy, call), "wb") as f: +# pkl.dump(sam, f, pkl.HIGHEST_PROTOCOL) + + +# In[23]: + + +# with open(r"data/zfit_toys/toy_0/0.pkl", "rb") as input_file: +# sam = pkl.load(input_file) +# print(sam[:10]) + +# with open(r"data/zfit_toys/toy_0/1.pkl", "rb") as input_file: +# sam2 = pkl.load(input_file) +# print(sam2[:10]) + +# print(np.sum(sam-sam2)) + + +# In[24]: + + +# print("Time to generate full toy: {} s".format(int(time.time()-start))) + +# total_samp = [] + +# for call in range(calls): +# with open(r"data/zfit_toys/toy_0/{}.pkl".format(call), "rb") as input_file: +# sam = pkl.load(input_file) +# total_samp = np.append(total_samp, sam) + +# total_samp = total_samp.astype('float64') + +# data2 = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs) + +# data3 = zfit.data.Data.from_numpy(array=total_samp, obs=obs) + +# print(total_samp[:nevents].shape) + + +# In[25]: + + +# plt.clf() + +# bins = int((x_max-x_min)/7) + +# # calcs = zfit.run(total_test_tf(samp)) +# print(total_samp[:nevents].shape) + +# plt.hist(total_samp[:nevents], bins = bins, range = (x_min,x_max), label = 'data') +# # plt.plot(test_q, calcs_test*nevents , label = 'pdf') + +# # plt.plot(sam, calcs, '.') +# # plt.plot(test_q, calcs_test) +# # plt.yscale('log') +# plt.ylim(0, 200) +# # plt.xlim(3080, 3110) + +# plt.legend() + +# plt.savefig('test2.png') + + +# In[26]: + + +# sampler = total_f.create_sampler(n=nevents) +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=sampler, fit_range = (x_min, x_max)) + +# # for param in pdf.get_dependents(): +# # param.set_value(initial_value) + +# sampler.resample(n=nevents) + +# # Randomise initial values +# # for param in pdf.get_dependents(): +# # param.set_value(random value here) + +# # Minimise the NLL +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 10) +# minimum = minimizer.minimize(nll) + + +# In[27]: + + +# jpsi_width + + +# In[28]: + + +# plt.hist(sample, weights=1 / prob(sample)) + + +# # Fitting + +# In[29]: + + +# start = time.time() + +# for param in total_f.get_dependents(): +# param.randomize() + +# # for param in total_f.get_dependents(): +# # print(zfit.run(param)) + +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=data2, fit_range = (x_min, x_max)) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# # param_errors = result.error() + +# # for var, errors in param_errors.items(): +# # print('{}: ^{{+{}}}_{{{}}}'.format(var.name, errors['upper'], errors['lower'])) + +# print("Function minimum:", result.fmin) +# # print("Results:", result.params) +# print("Hesse errors:", result.hesse()) + + +# In[30]: + + +# print("Time taken for fitting: {}".format(display_time(int(time.time()-start)))) + +# # probs = total_f.pdf(test_q) + +# calcs_test = zfit.run(probs) +# res_y = zfit.run(jpsi_res(test_q)) + + +# In[31]: + + +# plt.clf() +# # plt.plot(x_part, calcs, '.') +# plt.plot(test_q, calcs_test, label = 'pdf') +# # plt.plot(test_q, res_y, label = 'res') +# plt.legend() +# plt.ylim(0.0, 10e-6) +# # plt.yscale('log') +# # plt.xlim(3080, 3110) +# plt.savefig('test3.png') +# # print(jpsi_width) + + +# In[32]: + + +# _tot = 4.37e-7+6.02e-5+4.97e-6 +# _probs = [] +# _probs.append(6.02e-5/_tot) +# _probs.append(4.97e-6/_tot) +# _probs.append(4.37e-7/_tot) +# print(_probs) + + +# In[33]: + + +# dtype = 'float64' +# # mixture = tfd.Uniform(tf.constant(x_min, dtype=dtype), tf.constant(x_max, dtype=dtype)) +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.007, dtype=dtype), +# tf.constant(0.917, dtype=dtype), +# tf.constant(0.076, dtype=dtype)]), +# components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), +# tf.constant(3080, dtype=dtype), +# tf.constant(3670, dtype=dtype)], +# high=[tf.constant(x_max, dtype=dtype), +# tf.constant(3112, dtype=dtype), +# tf.constant(3702, dtype=dtype)])) +# # for i in range(10): +# # print(zfit.run(mixture.prob(mixture.sample((10, 1))))) + + +# In[34]: + + +# print((zfit.run(jpsi_p)%(2*np.pi))/np.pi) +# print((zfit.run(psi2s_p)%(2*np.pi))/np.pi) + + +# In[35]: + + +# def jpsi_res(q): +# return resonance(q, _mass = jpsi_mass, scale = jpsi_scale, +# phase = jpsi_phase, width = jpsi_width) + +# def psi2s_res(q): +# return resonance(q, _mass = psi2s_mass, scale = psi2s_scale, +# phase = psi2s_phase, width = psi2s_width) + +# def p3770_res(q): +# return resonance(q, _mass = p3770_mass, scale = p3770_scale, +# phase = p3770_phase, width = p3770_width) + +# def p4040_res(q): +# return resonance(q, _mass = p4040_mass, scale = p4040_scale, +# phase = p4040_phase, width = p4040_width) + +# def p4160_res(q): +# return resonance(q, _mass = p4160_mass, scale = p4160_scale, +# phase = p4160_phase, width = p4160_width) + +# def p4415_res(q): +# return resonance(q, _mass = p4415_mass, scale = p4415_scale, +# phase = p4415_phase, width = p4415_width) + + +# In[36]: + + +# 0.15**2*4.2/1000 +# result.hesse() + + +# ## Constraints + +# In[37]: + + +# 1. Constraint - Real part of sum of Psi contrib and D contribs + +sum_list = [] + +sum_list.append(ztf.to_complex(jpsi_s) * tf.exp(tf.complex(ztf.constant(0.0), jpsi_p)) * ztf.to_complex(jpsi_w / (tf.pow(jpsi_m,3)))) +sum_list.append(ztf.to_complex(psi2s_s) * tf.exp(tf.complex(ztf.constant(0.0), psi2s_p)) * ztf.to_complex(psi2s_w / (tf.pow(psi2s_m,3)))) +sum_list.append(ztf.to_complex(p3770_s) * tf.exp(tf.complex(ztf.constant(0.0), p3770_p)) * ztf.to_complex(p3770_w / (tf.pow(p3770_m,3)))) +sum_list.append(ztf.to_complex(p4040_s) * tf.exp(tf.complex(ztf.constant(0.0), p4040_p)) * ztf.to_complex(p4040_w / (tf.pow(p4040_m,3)))) +sum_list.append(ztf.to_complex(p4160_s) * tf.exp(tf.complex(ztf.constant(0.0), p4160_p)) * ztf.to_complex(p4160_w / (tf.pow(p4160_m,3)))) +sum_list.append(ztf.to_complex(p4415_s) * tf.exp(tf.complex(ztf.constant(0.0), p4415_p)) * ztf.to_complex(p4415_w / (tf.pow(p4415_m,3)))) +sum_list.append(ztf.to_complex(DDstar_s) * tf.exp(tf.complex(ztf.constant(0.0), DDstar_p)) * (ztf.to_complex(1.0 / (10.0*tf.pow(Dstar_m,2)) + 1.0 / (10.0*tf.pow(D_m,2))))) +sum_list.append(ztf.to_complex(Dbar_s) * tf.exp(tf.complex(ztf.constant(0.0), Dbar_p)) * ztf.to_complex(1.0 / (6.0*tf.pow(Dbar_m,2)))) + +sum_ru_1 = ztf.to_complex(ztf.constant(0.0)) + +for part in sum_list: + sum_ru_1 += part + +sum_1 = tf.math.real(sum_ru_1) +# constraint1 = zfit.constraint.GaussianConstraint(params = sum_1, mu = ztf.constant(1.7*10**-8), +# sigma = ztf.constant(2.2*10**-8)) + +constraint1 = tf.pow((sum_1-ztf.constant(1.7*10**-8))/ztf.constant(2.2*10**-8),2)/ztf.constant(2.) + +# 2. Constraint - Abs. of sum of Psi contribs and D contribs + +sum_2 = tf.abs(sum_ru_1) +constraint2 = tf.cond(tf.greater_equal(sum_2, 5.0e-8), lambda: 100000., lambda: 0.) + +# 3. Constraint - Maximum eta of D contribs + +constraint3_0 = tf.cond(tf.greater_equal(tf.abs(Dbar_s), 0.2), lambda: 100000., lambda: 0.) + +constraint3_1 = tf.cond(tf.greater_equal(tf.abs(DDstar_s), 0.2), lambda: 100000., lambda: 0.) + +# 4. Constraint - Formfactor multivariant gaussian covariance fplus + +Cov_matrix = [[ztf.constant( 1.), ztf.constant( 0.45), ztf.constant( 0.19), ztf.constant(0.857), ztf.constant(0.598), ztf.constant(0.531), ztf.constant(0.752), ztf.constant(0.229), ztf.constant(0,117)], + [ztf.constant( 0.45), ztf.constant( 1.), ztf.constant(0.677), ztf.constant(0.708), ztf.constant(0.958), ztf.constant(0.927), ztf.constant(0.227), ztf.constant(0.443), ztf.constant(0.287)], + [ztf.constant( 0.19), ztf.constant(0.677), ztf.constant( 1.), ztf.constant(0.595), ztf.constant(0.770), ztf.constant(0.819),ztf.constant(-0.023), ztf.constant( 0.07), ztf.constant(0.196)], + [ztf.constant(0.857), ztf.constant(0.708), ztf.constant(0.595), ztf.constant( 1.), ztf.constant( 0.83), ztf.constant(0.766), ztf.constant(0.582), ztf.constant(0.237), ztf.constant(0.192)], + [ztf.constant(0.598), ztf.constant(0.958), ztf.constant(0.770), ztf.constant( 0.83), ztf.constant( 1.), ztf.constant(0.973), ztf.constant(0.324), ztf.constant(0.372), ztf.constant(0.272)], + [ztf.constant(0.531), ztf.constant(0.927), ztf.constant(0.819), ztf.constant(0.766), ztf.constant(0.973), ztf.constant( 1.), ztf.constant(0.268), ztf.constant(0.332), ztf.constant(0.269)], + [ztf.constant(0.752), ztf.constant(0.227),ztf.constant(-0.023), ztf.constant(0.582), ztf.constant(0.324), ztf.constant(0.268), ztf.constant( 1.), ztf.constant( 0.59), ztf.constant(0.515)], + [ztf.constant(0.229), ztf.constant(0.443), ztf.constant( 0.07), ztf.constant(0.237), ztf.constant(0.372), ztf.constant(0.332), ztf.constant( 0.59), ztf.constant( 1.), ztf.constant(0.897)], + [ztf.constant(0.117), ztf.constant(0.287), ztf.constant(0.196), ztf.constant(0.192), ztf.constant(0.272), ztf.constant(0.269), ztf.constant(0.515), ztf.constant(0.897), ztf.constant( 1.)]] + +def triGauss(val1,val2,val3,m = Cov_matrix): + + mean1 = ztf.constant(0.466) + mean2 = ztf.constant(-0.885) + mean3 = ztf.constant(-0.213) + sigma1 = ztf.constant(0.014) + sigma2 = ztf.constant(0.128) + sigma3 = ztf.constant(0.548) + x1 = (val1-mean1)/sigma1 + x2 = (val2-mean2)/sigma2 + x3 = (val3-mean3)/sigma3 + rho12 = m[0][1] + rho13 = m[0][2] + rho23 = m[1][2] + w = x1*x1*(rho23*rho23-1) + x2*x2*(rho13*rho13-1)+x3*x3*(rho12*rho12-1)+2*(x1*x2*(rho12-rho13*rho23)+x1*x3*(rho13-rho12*rho23)+x2*x3*(rho23-rho12*rho13)) + d = 2*(rho12*rho12+rho13*rho13+rho23*rho23-2*rho12*rho13*rho23-1) + + fcn = -w/d + chisq = -2*fcn + return chisq + +constraint4 = triGauss(bplus_0, bplus_1, bplus_2) + +# mean1 = ztf.constant(0.466) +# mean2 = ztf.constant(-0.885) +# mean3 = ztf.constant(-0.213) +# sigma1 = ztf.constant(0.014) +# sigma2 = ztf.constant(0.128) +# sigma3 = ztf.constant(0.548) +# constraint4_0 = tf.pow((bplus_0-mean1)/sigma1,2)/ztf.constant(2.) +# constraint4_1 = tf.pow((bplus_1-mean2)/sigma2,2)/ztf.constant(2.) +# constraint4_2 = tf.pow((bplus_2-mean3)/sigma3,2)/ztf.constant(2.) + +# 5. Constraint - Abs. of sum of light contribs + +sum_list_5 = [] + +sum_list_5.append(rho_s*rho_w/rho_m) +sum_list_5.append(omega_s*omega_w/omega_m) +sum_list_5.append(phi_s*phi_w/phi_m) + + +sum_ru_5 = ztf.constant(0.0) + +for part in sum_list_5: + sum_ru_5 += part + +constraint5 = tf.cond(tf.greater_equal(tf.abs(sum_ru_5), ztf.constant(0.02)), lambda: 100000., lambda: 0.) + +# 6. Constraint on phases of Jpsi and Psi2s for cut out fit + + +# constraint6_0 = zfit.constraint.GaussianConstraint(params = jpsi_p, mu = ztf.constant(pdg["jpsi_phase_unc"]), +# sigma = ztf.constant(jpsi_phase)) +# constraint6_1 = zfit.constraint.GaussianConstraint(params = psi2s_p, mu = ztf.constant(pdg["psi2s_phase_unc"]), +# sigma = ztf.constant(psi2s_phase)) + +constraint6_0 = tf.pow((jpsi_p-ztf.constant(jpsi_phase))/ztf.constant(pdg["jpsi_phase_unc"]),2)/ztf.constant(2.) +constraint6_1 = tf.pow((psi2s_p-ztf.constant(psi2s_phase))/ztf.constant(pdg["psi2s_phase_unc"]),2)/ztf.constant(2.) + +# 7. Constraint on Ctt with higher limits + +constraint7 = tf.cond(tf.greater_equal(Ctt*Ctt, 0.25), lambda: 100000., lambda: 0.) + +constraint7dtype = tf.float64 + +# zfit.run(constraint6_0) + +# ztf.convert_to_tensor(constraint6_0) + +#List of all constraints + +constraints = [constraint1, constraint2, constraint3_0, constraint3_1,# constraint4, #constraint4_0, constraint4_1, constraint4_2, + constraint6_0, constraint6_1]#, constraint7] + + +# ## Reset params + +# In[38]: + + +def reset_param_values(): + jpsi_m.set_value(jpsi_mass) + jpsi_s.set_value(jpsi_scale) + jpsi_p.set_value(jpsi_phase) + jpsi_w.set_value(jpsi_width) + psi2s_m.set_value(psi2s_mass) + psi2s_s.set_value(psi2s_scale) + psi2s_p.set_value(psi2s_phase) + psi2s_w.set_value(psi2s_width) + p3770_m.set_value(p3770_mass) + p3770_s.set_value(p3770_scale) + p3770_p.set_value(p3770_phase) + p3770_w.set_value(p3770_width) + p4040_m.set_value(p4040_mass) + p4040_s.set_value(p4040_scale) + p4040_p.set_value(p4040_phase) + p4040_w.set_value(p4040_width) + p4160_m.set_value(p4160_mass) + p4160_s.set_value(p4160_scale) + p4160_p.set_value(p4160_phase) + p4160_w.set_value(p4160_width) + p4415_m.set_value(p4415_mass) + p4415_s.set_value(p4415_scale) + p4415_p.set_value(p4415_phase) + p4415_w.set_value(p4415_width) + rho_m.set_value(rho_mass) + rho_s.set_value(rho_scale) + rho_p.set_value(rho_phase) + rho_w.set_value(rho_width) + omega_m.set_value(omega_mass) + omega_s.set_value(omega_scale) + omega_p.set_value(omega_phase) + omega_w.set_value(omega_width) + phi_m.set_value(phi_mass) + phi_s.set_value(phi_scale) + phi_p.set_value(phi_phase) + phi_w.set_value(phi_width) + Dstar_m.set_value(Dstar_mass) + DDstar_s.set_value(0.0) + DDstar_p.set_value(0.0) + D_m.set_value(D_mass) + Dbar_m.set_value(Dbar_mass) + Dbar_s.set_value(0.0) + Dbar_p.set_value(0.0) + tau_m.set_value(pdg['tau_M']) + Ctt.set_value(0.0) + b0_0.set_value(0.292) + b0_1.set_value(0.281) + b0_2.set_value(0.150) + bplus_0.set_value(0.466) + bplus_1.set_value(-0.885) + bplus_2.set_value(-0.213) + bT_0.set_value(0.460) + bT_1.set_value(-1.089) + bT_2.set_value(-1.114) + + +# # Analysis + +# In[39]: + + +# # zfit.run.numeric_checks = False + +# fitting_range = 'cut' +# total_BR = 1.7e-10 + 4.9e-10 + 2.5e-9 + 6.02e-5 + 4.97e-6 + 1.38e-9 + 4.2e-10 + 2.6e-9 + 6.1e-10 + 4.37e-7 +# cut_BR = 1.0 - (6.02e-5 + 4.97e-6)/total_BR + +# Ctt_list = [] +# Ctt_error_list = [] + +# nr_of_toys = 1 +# if fitting_range == 'cut': +# nevents = int(pdg["number_of_decays"]*cut_BR) +# else: +# nevents = int(pdg["number_of_decays"]) +# # nevents = pdg["number_of_decays"] +# event_stack = 1000000 +# # nevents *= 41 +# # zfit.settings.set_verbosity(10) +# calls = int(nevents/event_stack + 1) + +# total_samp = [] + +# start = time.time() + +# sampler = total_f.create_sampler(n=event_stack) + +# for toy in range(nr_of_toys): + +# ### Generate data + +# # clear_output(wait=True) + +# print("Toy {}: Generating data...".format(toy)) + +# dirName = 'data/zfit_toys/toy_{0}'.format(toy) + +# if not os.path.exists(dirName): +# os.mkdir(dirName) +# print("Directory " , dirName , " Created ") + +# reset_param_values() + +# if fitting_range == 'cut': + +# sampler.resample(n=nevents) +# s = sampler.unstack_x() +# sam = zfit.run(s) +# calls = 0 +# c = 1 + +# else: +# for call in range(calls): + +# sampler.resample(n=event_stack) +# s = sampler.unstack_x() +# sam = zfit.run(s) + +# c = call + 1 + +# with open("data/zfit_toys/toy_{0}/{1}.pkl".format(toy, call), "wb") as f: +# pkl.dump(sam, f, pkl.HIGHEST_PROTOCOL) + +# print("Toy {}: Data generation finished".format(toy)) + +# ### Load data + +# print("Toy {}: Loading data...".format(toy)) + +# if fitting_range == 'cut': + +# total_samp = sam + +# else: + +# for call in range(calls): +# with open(r"data/zfit_toys/toy_0/{}.pkl".format(call), "rb") as input_file: +# sam = pkl.load(input_file) +# total_samp = np.append(total_samp, sam) + +# total_samp = total_samp.astype('float64') + +# if fitting_range == 'full': + +# data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs) + +# print("Toy {}: Loading data finished".format(toy)) + +# ### Fit data + +# print("Toy {}: Fitting pdf...".format(toy)) + +# for param in total_f.get_dependents(): +# param.randomize() + +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=data, fit_range = (x_min, x_max), constraints = constraints) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# print("Toy {}: Fitting finished".format(toy)) + +# print("Function minimum:", result.fmin) +# print("Hesse errors:", result.hesse()) + +# params = result.params +# Ctt_list.append(params[Ctt]['value']) +# Ctt_error_list.append(params[Ctt]['minuit_hesse']['error']) + +# #plotting the result + +# plotdirName = 'data/plots'.format(toy) + +# if not os.path.exists(plotdirName): +# os.mkdir(plotdirName) +# # print("Directory " , dirName , " Created ") + +# probs = total_f.pdf(test_q, norm_range=False) +# calcs_test = zfit.run(probs) +# plt.clf() +# plt.plot(test_q, calcs_test, label = 'pdf') +# plt.legend() +# plt.ylim(0.0, 6e-6) +# plt.savefig(plotdirName + '/toy_fit_full_range{}.png'.format(toy)) + +# print("Toy {0}/{1}".format(toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(c+calls*(toy))*((nr_of_toys-toy)*calls-c))))) + +# if fitting_range == 'cut': + +# _1 = np.where((total_samp >= x_min) & (total_samp <= (jpsi_mass - 60.))) + +# tot_sam_1 = total_samp[_1] + +# _2 = np.where((total_samp >= (jpsi_mass + 70.)) & (total_samp <= (psi2s_mass - 50.))) + +# tot_sam_2 = total_samp[_2] + +# _3 = np.where((total_samp >= (psi2s_mass + 50.)) & (total_samp <= x_max)) + +# tot_sam_3 = total_samp[_3] + +# tot_sam = np.append(tot_sam_1, tot_sam_2) +# tot_sam = np.append(tot_sam, tot_sam_3) + +# data = zfit.data.Data.from_numpy(array=tot_sam[:int(nevents)], obs=obs_fit) + +# print("Toy {}: Loading data finished".format(toy)) + +# ### Fit data + +# print("Toy {}: Fitting pdf...".format(toy)) + +# for param in total_f_fit.get_dependents(): +# param.randomize() + +# nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# print("Function minimum:", result.fmin) +# print("Hesse errors:", result.hesse()) + +# params = result.params + +# if result.converged: +# Ctt_list.append(params[Ctt]['value']) +# Ctt_error_list.append(params[Ctt]['minuit_hesse']['error']) + +# #plotting the result + +# plotdirName = 'data/plots'.format(toy) + +# if not os.path.exists(plotdirName): +# os.mkdir(plotdirName) +# # print("Directory " , dirName , " Created ") + +# plt.clf() +# plt.hist(tot_sam, bins = int((x_max-x_min)/7.), label = 'toy data') +# plt.savefig(plotdirName + '/toy_histo_cut_region{}.png'.format(toy)) + + +# probs = total_f_fit.pdf(test_q, norm_range=False) +# calcs_test = zfit.run(probs) +# plt.clf() +# plt.plot(test_q, calcs_test, label = 'pdf') +# plt.axvline(x=jpsi_mass-60.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=jpsi_mass+70.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=psi2s_mass-50.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=psi2s_mass+50.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.legend() +# plt.ylim(0.0, 1.5e-6) +# plt.savefig(plotdirName + '/toy_fit_cut_region{}.png'.format(toy)) + +# print("Toy {0}/{1}".format(toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(toy+1))*((nr_of_toys-toy-1))))) + + + +# In[40]: + + +# with open("data/results/Ctt_list.pkl", "wb") as f: +# pkl.dump(Ctt_list, f, pkl.HIGHEST_PROTOCOL) +# with open("data/results/Ctt_error_list.pkl", "wb") as f: +# pkl.dump(Ctt_error_list, f, pkl.HIGHEST_PROTOCOL) + + +# In[41]: + + +# print('{0}/{1} fits converged'.format(len(Ctt_list), nr_of_toys)) +# print('Mean Ctt value = {}'.format(np.mean(Ctt_list))) +# print('Mean Ctt error = {}'.format(np.mean(Ctt_error_list))) +# print('95 Sensitivy = {}'.format(((2*np.mean(Ctt_error_list))**2)*4.2/1000)) + + +# In[42]: + + +# plt.hist(tot_sam, bins = int((x_max-x_min)/7.)) + +# plt.show() + +# # _ = np.where((total_samp >= x_min) & (total_samp <= (jpsi_mass - 50.))) + +# tot_sam.shape + + +# In[43]: + + +# Ctt.floating = False + + +# In[44]: + + +# zfit.run(nll.value()) + + +# In[45]: + + +# result.fmin + + +# In[46]: + + +# BR_steps = np.linspace(0.0, 1e-3, 11) + + +# # CLS Code + +# In[47]: + + +# zfit.run.numeric_checks = False + +load = False + +bo5 = True + +bo5_set = 5 + +fitting_range = 'cut' +total_BR = 1.7e-10 + 4.9e-10 + 2.5e-9 + 6.02e-5 + 4.97e-6 + 1.38e-9 + 4.2e-10 + 2.6e-9 + 6.1e-10 + 4.37e-7 +cut_BR = 1.0 - (6.02e-5 + 4.97e-6)/total_BR + +Ctt_list = [] +Ctt_error_list = [] + +nr_of_toys = 1 +nevents = int(pdg["number_of_decays"]*cut_BR) +# nevents = pdg["number_of_decays"] +event_stack = 1000000 +# nevents *= 41 +# zfit.settings.set_verbosity(10) + +mi = 0.0 +ma = 1e-3 +ste = 11 + +BR_steps = np.linspace(mi, ma, ste) + +Ctt_steps = np.sqrt(BR_steps/4.2*1000) + +total_samp = [] + +start = time.time() + +Nll_list = [] + +sampler = total_f.create_sampler(n=nevents) + +__ = 0 + + +#----------------------------------------------------- + +if not load: + + for Ctt_step in Ctt_steps: + + __ += 1 + + newset = True + + for floaty in [True, False]: + + Ctt.floating = floaty + + Nll_list.append([]) + + if bo5: + + while len(Nll_list[-1])/bo5_set < nr_of_toys: + + print('Step: {0}/{1}'.format(__, ste)) + + print('Current Ctt: {0}'.format(Ctt_step)) + print('Ctt floating: {0}'.format(floaty)) + + print('Toy {0}/{1} - Fit {2}/{3}'.format(int(len(Nll_list[-1])/bo5_set), nr_of_toys, len(Nll_list[-1]), bo5_set)) + + reset_param_values() + + if floaty: + Ctt.set_value(Ctt_step) + else: + Ctt.set_value(0.0) + + if newset: + sampler.resample(n=nevents) + s = sampler.unstack_x() + total_samp = zfit.run(s) + calls = 0 + c = 1 + newset = False + + + data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit) + + ### Fit data + + for param in total_f_fit.get_dependents(): + param.randomize() + + nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + + minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) + # minimizer._use_tfgrad = False + result = minimizer.minimize(nll) + + # print("Function minimum:", result.fmin) + # print("Hesse errors:", result.hesse()) + + params = result.params + + if result.converged: + Nll_list[-1].append(result.fmin) + + else: + + while len(Nll_list[-1]) < nr_of_toys: + + print('Step: {0}/{1}'.format(__, ste)) + + print('Current Ctt: {0}'.format(Ctt_step)) + print('Ctt floating: {0}'.format(floaty)) + + print('Toy {0}/{1}'.format(len(Nll_list[-1]), nr_of_toys)) + + reset_param_values() + + if floaty: + Ctt.set_value(Ctt_step) + else: + Ctt.set_value(0.0) + + if floaty: + sampler.resample(n=nevents) + s = sampler.unstack_x() + total_samp = zfit.run(s) + calls = 0 + c = 1 + + + data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit) + + ### Fit data + + for param in total_f_fit.get_dependents(): + param.randomize() + + nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + + minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) + # minimizer._use_tfgrad = False + result = minimizer.minimize(nll) + + # print("Function minimum:", result.fmin) + # print("Hesse errors:", result.hesse()) + + params = result.params + + if result.converged: + Nll_list[-1].append(result.fmin) + + _t = int(time.time()-start) + + print('Time Taken: {}'.format(display_time(int(_t)))) + + print('Predicted time left: {}'.format(display_time(int((_t/(__+1)*(ste-__-1)))))) + + +# In[48]: + + +if load: + Nll_list = [] + CLs_values = [] + + _dir = 'data/CLs/finished/f1d1' + + jobs = os.listdir(_dir) + + for s in range(ste): + CLs_values.append([]) + + for s in range(2*ste): + Nll_list.append([]) + + for job in jobs: + if not os.path.exists("{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(_dir, job, mi,ma,ste)): + print(job) + continue + + with open(r"{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(_dir, job, mi,ma,ste), "rb") as input_file: + _Nll_list = pkl.load(input_file) + + if bo5: + for s in range(2*ste): + Nll_list[s].append(np.min(_Nll_list[s])) + else: + for s in range(2*ste): + Nll_list[s].extend(_Nll_list[s]) + + with open(r"{}/{}/data/CLs/{}-{}_{}s--CLs_list.pkl".format(_dir, job, mi,ma,ste), "rb") as input_file: + _CLs_values = pkl.load(input_file) + + for s in range(ste): + CLs_values[s].extend(_CLs_values[s]) + + print(np.shape(Nll_list)) + + +# In[50]: + + +dirName = 'data/CLs' + +# if bo5 and not load: +# for s in range(2*ste): +# Nll_list[s] = [np.min(Nll_list[s])] + +if bo5: + CLs_values= [] + for i in range(int(len(Nll_list)/2)): + CLs_values.append([]) + for j in range(len(Nll_list[0])): + CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j]) + + +if not load: + + CLs_values = [] + + for i in range(int(len(Nll_list)/2)): + CLs_values.append([]) + for j in range(nr_of_toys): + CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j]) + + if not os.path.exists(dirName): + os.mkdir(dirName) + print("Directory " , dirName , " Created ") + + with open("{}/{}-{}_{}s--CLs_Nll_list.pkl".format(dirName, mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + + with open("{}/{}-{}_{}s--CLs_list.pkl".format(dirName, mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +# print(CLs_values) +print(Nll_list) + + +# ## Plot + +# In[52]: + + +l = [] + +for i in range(len(CLs_values)): + plt.clf() + plt.title('Ctt value: {:.2f}'.format(Ctt_steps[i])) + plt.hist(CLs_values[0], bins = 100, label = 'Ctt fixed to 0') + plt.hist(CLs_values[i], bins = 100, label = 'Ctt floating') + plt.axvline(x=np.mean(CLs_values[0]),color='red', linewidth=0.7, linestyle = 'dotted') + plt.legend() + plt.savefig('data/CLs/plots/CLs-BR({:.1E}).png'.format(BR_steps[i])) + + l.append(len(np.where(np.array(CLs_values[i]) < np.mean(CLs_values[0]))[0])) + + +# In[53]: + + +for s in range(len(l)): + print('BR: {}'.format(BR_steps[s])) + print(2*l[s]/len(CLs_values[0])) + print() + + +# In[54]: + + +# print(np.array(Nll_list[0][:10])-np.array(Nll_list[1][:10])) + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2254886/test.png b/data/CLs/finished/f1d1/2254886/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2254886/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2254891/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2254891/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..ac2b0f3 --- /dev/null +++ b/data/CLs/finished/f1d1/2254891/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2254891/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2254891/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..499d38c --- /dev/null +++ b/data/CLs/finished/f1d1/2254891/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2254891/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2254891/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..ceaff27 --- /dev/null +++ b/data/CLs/finished/f1d1/2254891/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2254891/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2254891/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..f0e7330 --- /dev/null +++ b/data/CLs/finished/f1d1/2254891/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2254891/helperfunctions.py b/data/CLs/finished/f1d1/2254891/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2254891/helperfunctions.py @@ -0,0 +1,33 @@ +# some helperfunctions + +import matplotlib +matplotlib.use("agg") +import matplotlib.pyplot as plt + +#Dislpay time (e.g. while generating points) + +display_intervals = ( + ('w', 604800), # 60 * 60 * 24 * 7 + ('d', 86400), # 60 * 60 * 24 + ('h', 3600), # 60 * 60 + ('min', 60), + ('s', 1), + ) + +def display_time(seconds, granularity=2): + result = [] + + for name, count in display_intervals: + value = seconds // count + if value: + seconds -= value * count + if value == 1: + name = name.rstrip('s') + result.append("{} {}".format(value, name)) + return ', '.join(result[:granularity]) + +def prepare_plot(title): + plt.title(title) + plt.grid() + plt.legend(loc = 'best') + plt.xlabel("q") diff --git a/data/CLs/finished/f1d1/2254891/pdg_const.py b/data/CLs/finished/f1d1/2254891/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2254891/pdg_const.py @@ -0,0 +1,226 @@ +pdg = { + + + ###Particle masses### + + "mbstar" : 5415.4, + "mbstar0" : 5711.0, + "B0_M" : 5279.5, + "Bs_M" : 5366.7, + "Bplus_M" : 5279.3, + "Lb_M" : 5619.4, + "D0_M" : 1864.8, + "Dst_M" : 2010, + "pi_M" : 139.6, + "Jpsi_M" : 3096.9, + "Psi2s_M" : 3685.6, + "kaon_M" : 493.7, + "Ks_M" : 497.6, + "phi_M" : 1019.5, + "rho_M" : 775.26, + "rho_width" : 149.1, + "omega_M" : 782.65, + "omega_width" : 8.49, + + "muon_M" : 105.7, + "tau_M": 1776.86, + + "squark_M" : 95.0, + "bquark_M" : 4180.0, + "cquark_M" : 1275.0, + + "Bplus_tau" : 1.638e-12, + + ###Wilson coefficients### + + "C1" : -0.257, + "C2" : 1.009, + "C3" : -0.005, + "C4" : -0.078, + + "C7eff" : -0.306, + "C9eff" : 4.211, + "C10eff" : -4.103, + +# "C7eff": 0.0, +# "C9eff": 0.0, +# "C10eff": 0.0, + + ###Other constants + + "GF" : 1.1663787e-5, + "alpha_ew" : 1.0/137.0, + "Vts" : 0.0394, + "Vtb" : 1.019, + "number_of_decays": 5404696, + + #Formfactor z coefficients + + #"b0" : [0.285, 0.19, -0.17], + #"bplus" : [0.437, -1.41, -2.5], + #"bT" : [0.440, -1.47, -2.7] + + "b0" : [0.292, 0.281, 0.150], + "bplus" : [0.466, -0.885, -0.213], + "bT" : [0.460, -1.089, -1.114], + + "NR_BR": 4.37e-7, + "NR_auc": 0.00133, + + #Resonances format(mass, width, phase, scale) + + # pre scaling + +# "rho": (775.26, 149.0, -0.35, 1.0), + +# "omega": (782.7, 8.5, 0.26, 1.0), + +# "phi": (1019.46, 4.25, 0.5, 1.0), + +# "jpsi": (3096.0, 0.09, -1.5, 2e-2), +# "jpsi_auc": 0.2126825758464027, + +# "psi2s": (3686.0, 0.3, -1.5, 3.14e-3), +# "psi2s_auc": 2.802257483178487e-10, + +# "p3770": (3773.0, 27.2, -2.13, 1.0e-3), + +# "p4040": (4039.0, 80.0, -2.52, 2.0), + +# "p4160": (4191.0, 70.0, -1.9, 2.2), + +# "p4415": (4421.0, 62.0, -2.52, 1.0), + + + # after scaling (Phase combination --) + + +# "rho": (743.2, 149.0, -0.22, 1.05), + +# "omega": (782.7, 8.5, 0.38, 6.8), + +# "phi": (1013.5, 4.25, 0.62, 19.2), + +# "jpsi": (3096.1, 0.09, 1.63, 9897.0), +# "jpsi_auc": 0.2126825758464027, +# "jpsi_phase_unc": 0.05, + +# "psi2s": (3686.0, 0.3, 1.8, 1396.0), +# "psi2s_auc": 0.0151332263, +# "psi2s_phase_unc": 0.1, + +# "p3770": (3773.0, 27.2, -2.95, 2.5), + +# "p4040": (4039.0, 80.0, -2.75, 1.01), + +# "p4160": (4191.0, 70.0, -2.28, 2.2), + +# "p4415": (4421.0, 62.0, -2.31, 1.24), + + # Phase combination of paper ++ + +# "rho": (743.2, 149.0, -0.35, 1.05), + +# "omega": (782.7, 8.5, 0.26, 6.8), + +# "phi": (1013.5, 4.25, 0.47, 19.2), + +# "jpsi": (3096.1, 0.09, -1.66, 9897.0), +# "jpsi_auc": 0.2126825758464027, +# "jpsi_phase_unc": 0.05, + +# "psi2s": (3686.0, 0.3, -1.93, 1396.0), +# "psi2s_auc": 0.0151332263, +# "psi2s_phase_unc": 0.1, + +# "p3770": (3773.0, 27.2, -2.13, 2.5), + +# "p4040": (4039.0, 80.0, -2.52, 1.01), + +# "p4160": (4191.0, 70.0, -1.90, 2.2), + +# "p4415": (4421.0, 62.0, -2.52, 1.24), + + # Phase combination of paper +- + + # "rho": (743.2, 149.0, -0.26, 1.05), + # + # "omega": (782.7, 8.5, 0.35, 6.8), + # + # "phi": (1013.5, 4.25, 0.58, 19.2), + # + # "jpsi": (3096.1, 0.09, 1.47, 9897.0), + # "jpsi_auc": 0.2126825758464027, + # "jpsi_phase_unc": 0.05, + # + # "psi2s": (3686.0, 0.3, -2.21, 1396.0), + # "psi2s_auc": 0.0151332263, + # "psi2s_phase_unc": 0.1, + # + # "p3770": (3773.0, 27.2, -2.140, 2.5), + # + # "p4040": (4039.0, 80.0, -2.64, 1.01), + # + # "p4160": (4191.0, 70.0, -2.11, 2.2), + # + # "p4415": (4421.0, 62.0, -2.42, 1.24), + + # Phase combination of paper -+ + + "rho": (743.2, 149.0, -0.30, 1.05), + + "omega": (782.7, 8.5, 0.30, 6.8), + + "phi": (1013.5, 4.25, 0.51, 19.2), + + "jpsi": (3096.1, 0.09, -1.5, 9897.0), + "jpsi_auc": 0.2126825758464027, + "jpsi_phase_unc": 0.05, + + "psi2s": (3686.0, 0.3, 2.08, 1396.0), + "psi2s_auc": 0.0151332263, + "psi2s_phase_unc": 0.1, + + "p3770": (3773.0, 27.2, -2.89, 2.5), + + "p4040": (4039.0, 80.0, -2.69, 1.01), + + "p4160": (4191.0, 70.0, -2.13, 2.2), + + "p4415": (4421.0, 62.0, -2.43, 1.24), + + + # zeroing resonances + +# "rho": (775.26, 149.0, -0.35, 0.0), +# "omega": (782.7, 8.5, 0.26, 0.0), +# "phi": (1019.46, 4.25, 0.5, 0.0), +# "jpsi": (3096.0, 0.09, -1.5, 0.0), +# "psi2s": (3686.0, 0.3, -1.5, 0.0), +# "p3770": (3773.0, 27.2, -2.13, 0.0), +# "p4040": (4039.0, 80.0, -2.52, 0.0), +# "p4160": (4147.0, 22.0, -1.9, 0.0), +# "p4415": (4421.0, 62.0, -2.52, 0.0), + + # 2P contributions format(mass, amp, phase) + +# "D_bar": ( + + #general + + "rho_BR": 1.7e-10, + "omega_BR": 4.9e-10, + "phi_BR": 2.5e-9, + "jpsi_BR": 6.02e-5, + "psi2s_BR": 4.97e-6, + "p3770_BR": 1.38e-9, + "p4040_BR": 4.2e-10, + "p4160_BR": 2.6e-9, + "p4415_BR": 6.1e-10, + +# Estimates + "Dbar_scale": 1.46, #with phase = pi + + "DDstar_scale": 2.41, #with phase = pi + + } diff --git a/data/CLs/finished/f1d1/2254891/raremodel-nb1.py b/data/CLs/finished/f1d1/2254891/raremodel-nb1.py new file mode 100644 index 0000000..1a5d9be --- /dev/null +++ b/data/CLs/finished/f1d1/2254891/raremodel-nb1.py @@ -0,0 +1,1939 @@ +#!/usr/bin/env python +# coding: utf-8 + +# # Import + +# In[1]: + + +import os + +# os.environ["CUDA_VISIBLE_DEVICES"] = "-1" + +import numpy as np +from pdg_const import pdg +import matplotlib +import matplotlib.pyplot as plt +import pickle as pkl +import sys +import time +from helperfunctions import display_time, prepare_plot +import cmath as c +import scipy.integrate as integrate +from scipy.optimize import fminbound +from array import array as arr +import collections +from itertools import compress +import tensorflow as tf +import zfit +from zfit import ztf +# from IPython.display import clear_output +import os +import tensorflow_probability as tfp +tfd = tfp.distributions + + +# In[2]: + + +# chunksize = 10000 +# zfit.run.chunking.active = True +# zfit.run.chunking.max_n_points = chunksize + + +# # Build model and graphs +# ## Create graphs + +# In[ ]: + + + + + +# In[3]: + + +def formfactor(q2, subscript, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): #returns real value + #check if subscript is viable + + if subscript != "0" and subscript != "+" and subscript != "T": + raise ValueError('Wrong subscript entered, choose either 0, + or T') + + #get constants + + mK = ztf.constant(pdg['Ks_M']) + mbstar0 = ztf.constant(pdg["mbstar0"]) + mbstar = ztf.constant(pdg["mbstar"]) + + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mB = ztf.constant(pdg['Bplus_M']) + + #N comes from derivation in paper + + N = 3 + + #some helperfunctions + + tpos = (mB - mK)**2 + tzero = (mB + mK)*(ztf.sqrt(mB)-ztf.sqrt(mK))**2 + + z_oben = ztf.sqrt(tpos - q2) - ztf.sqrt(tpos - tzero) + z_unten = ztf.sqrt(tpos - q2) + ztf.sqrt(tpos - tzero) + z = tf.divide(z_oben, z_unten) + + #calculate f0 + + if subscript == "0": + prefactor = 1/(1 - q2/(mbstar0**2)) + _sum = 0 + b0 = [b0_0, b0_1, b0_2] + + for i in range(N): + _sum += b0[i]*(tf.pow(z,i)) + + return ztf.to_complex(prefactor * _sum) + + #calculate f+ or fT + + else: + prefactor = 1/(1 - q2/(mbstar**2)) + _sum = 0 + + if subscript == "T": + bT = [bT_0, bT_1, bT_2] + for i in range(N): + _sum += bT[i] * (tf.pow(z, i) - ((-1)**(i-N)) * (i/N) * tf.pow(z, N)) + else: + bplus = [bplus_0, bplus_1, bplus_2] + for i in range(N): + _sum += bplus[i] * (tf.pow(z, i) - ((-1)**(i-N)) * (i/N) * tf.pow(z, N)) + + return ztf.to_complex(prefactor * _sum) + +def resonance(q, _mass, width, phase, scale): + + q2 = tf.pow(q, 2) + + mmu = ztf.constant(pdg['muon_M']) + + p = 0.5 * ztf.sqrt(q2 - 4*(mmu**2)) + + p0 = 0.5 * ztf.sqrt(_mass**2 - 4*mmu**2) + + gamma_j = tf.divide(p, q) * _mass * width / p0 + + #Calculate the resonance + + _top = tf.complex(_mass * width, ztf.constant(0.0)) + + _bottom = tf.complex(_mass**2 - q2, -_mass*gamma_j) + + com = _top/_bottom + + #Rotate by the phase + + r = ztf.to_complex(scale*tf.abs(com)) + + _phase = tf.angle(com) + + _phase += phase + + com = r * tf.exp(tf.complex(ztf.constant(0.0), _phase)) + + return com + + +def axiv_nonres(q, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): + + GF = ztf.constant(pdg['GF']) + alpha_ew = ztf.constant(pdg['alpha_ew']) + Vtb = ztf.constant(pdg['Vtb']) + Vts = ztf.constant(pdg['Vts']) + C10eff = ztf.constant(pdg['C10eff']) + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mK = ztf.constant(pdg['Ks_M']) + mB = ztf.constant(pdg['Bplus_M']) + + q2 = tf.pow(q, 2) + + #Some helperfunctions + + beta = 1. - 4. * mmu**2. / q2 + + 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.) + + #prefactor in front of whole bracket + + prefactor1 = GF**2. *alpha_ew**2. * (tf.abs(Vtb*Vts))**2. * kabs * beta / (128. * np.pi**5.) + + #left term in bracket + + bracket_left = 2./3. * tf.pow(kabs,2) * tf.pow(beta,2) * tf.pow(tf.abs(ztf.to_complex(C10eff)*formfactor(q2, "+", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)),2) + + #middle term in bracket + + _top = 4. * mmu**2. * (mB**2. - mK**2.) * (mB**2. - mK**2.) + + _under = q2 * mB**2. + + bracket_middle = _top/_under *tf.pow(tf.abs(ztf.to_complex(C10eff) * formfactor(q2, "0", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)), 2) + + #Note sqrt(q2) comes from derivation as we use q2 and plot q + + return prefactor1 * (bracket_left + bracket_middle) * 2 * q + +def vec(q, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): + + q2 = tf.pow(q, 2) + + GF = ztf.constant(pdg['GF']) + alpha_ew = ztf.constant(pdg['alpha_ew']) + Vtb = ztf.constant(pdg['Vtb']) + Vts = ztf.constant(pdg['Vts']) + C7eff = ztf.constant(pdg['C7eff']) + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mK = ztf.constant(pdg['Ks_M']) + mB = ztf.constant(pdg['Bplus_M']) + + #Some helperfunctions + + beta = 1. - 4. * mmu**2. / q2 + + 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) + + #prefactor in front of whole bracket + + prefactor1 = GF**2. *alpha_ew**2. * (tf.abs(Vtb*Vts))**2 * kabs * beta / (128. * np.pi**5.) + + #right term in bracket + + prefactor2 = tf.pow(kabs,2) * (1. - 1./3. * beta) + + abs_bracket = tf.pow(tf.abs(c9eff(q, funcs) * formfactor(q2, "+", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + ztf.to_complex(2.0 * C7eff * (mb + ms)/(mB + mK)) * formfactor(q2, "T", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)),2) + + bracket_right = prefactor2 * abs_bracket + + #Note sqrt(q2) comes from derivation as we use q2 and plot q + + return prefactor1 * bracket_right * 2 * q + +def c9eff(q, funcs): + + C9eff_nr = ztf.to_complex(ztf.constant(pdg['C9eff'])) + + c9 = C9eff_nr + funcs + + return c9 + + +# In[4]: + + +def G(y): + + def inner_rect_bracket(q): + return tf.log(ztf.to_complex((1+tf.sqrt(q))/(1-tf.sqrt(q)))-tf.complex(ztf.constant(0), -1*ztf.constant(np.pi))) + + def inner_right(q): + return ztf.to_complex(2 * tf.atan(1/tf.sqrt(tf.math.real(-q)))) + + big_bracket = tf.where(tf.math.real(y) > ztf.constant(0.0), inner_rect_bracket(y), inner_right(y)) + + return ztf.to_complex(tf.sqrt(tf.abs(y))) * big_bracket + +def h_S(m, q): + + 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))) + +def h_P(m, q): + + 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) + +def two_p_ccbar(mD, m_D_bar, m_D_star, q): + + + #Load constants + nu_D_bar = ztf.to_complex(pdg["nu_D_bar"]) + nu_D = ztf.to_complex(pdg["nu_D"]) + nu_D_star = ztf.to_complex(pdg["nu_D_star"]) + + phase_D_bar = ztf.to_complex(pdg["phase_D_bar"]) + phase_D = ztf.to_complex(pdg["phase_D"]) + phase_D_star = ztf.to_complex(pdg["phase_D_star"]) + + #Calculation + left_part = nu_D_bar * tf.exp(tf.complex(ztf.constant(0.0), phase_D_bar)) * h_S(m_D_bar, q) + + right_part_D = nu_D * tf.exp(tf.complex(ztf.constant(0.0), phase_D)) * h_P(m_D, q) + + right_part_D_star = nu_D_star * tf.exp(tf.complex(ztf.constant(0.0), phase_D_star)) * h_P(m_D_star, q) + + return left_part + right_part_D + right_part_D_star + + +# ## Build pdf + +# In[5]: + + +class total_pdf_cut(zfit.pdf.ZPDF): + _N_OBS = 1 # dimension, can be omitted + _PARAMS = ['b0_0', 'b0_1', 'b0_2', + 'bplus_0', 'bplus_1', 'bplus_2', + 'bT_0', 'bT_1', 'bT_2', + 'rho_mass', 'rho_scale', 'rho_phase', 'rho_width', + 'jpsi_mass', 'jpsi_scale', 'jpsi_phase', 'jpsi_width', + 'psi2s_mass', 'psi2s_scale', 'psi2s_phase', 'psi2s_width', + 'p3770_mass', 'p3770_scale', 'p3770_phase', 'p3770_width', + 'p4040_mass', 'p4040_scale', 'p4040_phase', 'p4040_width', + 'p4160_mass', 'p4160_scale', 'p4160_phase', 'p4160_width', + 'p4415_mass', 'p4415_scale', 'p4415_phase', 'p4415_width', + 'omega_mass', 'omega_scale', 'omega_phase', 'omega_width', + 'phi_mass', 'phi_scale', 'phi_phase', 'phi_width', + 'Dbar_mass', 'Dbar_scale', 'Dbar_phase', + 'Dstar_mass', 'DDstar_scale', 'DDstar_phase', 'D_mass', + 'tau_mass', 'C_tt'] +# the name of the parameters + + def _unnormalized_pdf(self, x): + + x = x.unstack_x() + + b0 = [self.params['b0_0'], self.params['b0_1'], self.params['b0_2']] + bplus = [self.params['bplus_0'], self.params['bplus_1'], self.params['bplus_2']] + bT = [self.params['bT_0'], self.params['bT_1'], self.params['bT_2']] + + def rho_res(q): + return resonance(q, _mass = self.params['rho_mass'], scale = self.params['rho_scale'], + phase = self.params['rho_phase'], width = self.params['rho_width']) + + def omega_res(q): + return resonance(q, _mass = self.params['omega_mass'], scale = self.params['omega_scale'], + phase = self.params['omega_phase'], width = self.params['omega_width']) + + def phi_res(q): + return resonance(q, _mass = self.params['phi_mass'], scale = self.params['phi_scale'], + phase = self.params['phi_phase'], width = self.params['phi_width']) + + def jpsi_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['jpsi_mass'], 2)) * resonance(q, _mass = self.params['jpsi_mass'], + scale = self.params['jpsi_scale'], + phase = self.params['jpsi_phase'], + width = self.params['jpsi_width']) + def psi2s_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['psi2s_mass'], 2)) * resonance(q, _mass = self.params['psi2s_mass'], + scale = self.params['psi2s_scale'], + phase = self.params['psi2s_phase'], + width = self.params['psi2s_width']) + def p3770_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p3770_mass'], 2)) * resonance(q, _mass = self.params['p3770_mass'], + scale = self.params['p3770_scale'], + phase = self.params['p3770_phase'], + width = self.params['p3770_width']) + + def p4040_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4040_mass'], 2)) * resonance(q, _mass = self.params['p4040_mass'], + scale = self.params['p4040_scale'], + phase = self.params['p4040_phase'], + width = self.params['p4040_width']) + + def p4160_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4160_mass'], 2)) * resonance(q, _mass = self.params['p4160_mass'], + scale = self.params['p4160_scale'], + phase = self.params['p4160_phase'], + width = self.params['p4160_width']) + + def p4415_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4415_mass'], 2)) * resonance(q, _mass = self.params['p4415_mass'], + scale = self.params['p4415_scale'], + phase = self.params['p4415_phase'], + width = self.params['p4415_width']) + + def P2_D(q): + 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)) + 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['Dstar_mass'], q)) + ztf.to_complex(h_P(self.params['D_mass'], q))) + return Dbar_contrib + DDstar_contrib + + def ttau_cusp(q): + 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))) + + + 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) + + vec_f = vec(x, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + axiv_nr = axiv_nonres(x, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + tot = vec_f + axiv_nr + + #Cut out jpsi and psi2s + + tot = tf.where(tf.math.logical_or(x < ztf.constant(jpsi_mass-60.), x > ztf.constant(jpsi_mass+70.)), tot, 0.0*tot) + + tot = tf.where(tf.math.logical_or(x < ztf.constant(psi2s_mass-50.), x > ztf.constant(psi2s_mass+50.)), tot, 0.0*tot) + + return tot + +class total_pdf_full(zfit.pdf.ZPDF): + _N_OBS = 1 # dimension, can be omitted + _PARAMS = ['b0_0', 'b0_1', 'b0_2', + 'bplus_0', 'bplus_1', 'bplus_2', + 'bT_0', 'bT_1', 'bT_2', + 'rho_mass', 'rho_scale', 'rho_phase', 'rho_width', + 'jpsi_mass', 'jpsi_scale', 'jpsi_phase', 'jpsi_width', + 'psi2s_mass', 'psi2s_scale', 'psi2s_phase', 'psi2s_width', + 'p3770_mass', 'p3770_scale', 'p3770_phase', 'p3770_width', + 'p4040_mass', 'p4040_scale', 'p4040_phase', 'p4040_width', + 'p4160_mass', 'p4160_scale', 'p4160_phase', 'p4160_width', + 'p4415_mass', 'p4415_scale', 'p4415_phase', 'p4415_width', + 'omega_mass', 'omega_scale', 'omega_phase', 'omega_width', + 'phi_mass', 'phi_scale', 'phi_phase', 'phi_width', + 'Dbar_mass', 'Dbar_scale', 'Dbar_phase', + 'Dstar_mass', 'DDstar_scale', 'DDstar_phase', 'D_mass', + 'tau_mass', 'C_tt'] +# the name of the parameters + + def _unnormalized_pdf(self, x): + + x = x.unstack_x() + + b0 = [self.params['b0_0'], self.params['b0_1'], self.params['b0_2']] + bplus = [self.params['bplus_0'], self.params['bplus_1'], self.params['bplus_2']] + bT = [self.params['bT_0'], self.params['bT_1'], self.params['bT_2']] + + def rho_res(q): + return resonance(q, _mass = self.params['rho_mass'], scale = self.params['rho_scale'], + phase = self.params['rho_phase'], width = self.params['rho_width']) + + def omega_res(q): + return resonance(q, _mass = self.params['omega_mass'], scale = self.params['omega_scale'], + phase = self.params['omega_phase'], width = self.params['omega_width']) + + def phi_res(q): + return resonance(q, _mass = self.params['phi_mass'], scale = self.params['phi_scale'], + phase = self.params['phi_phase'], width = self.params['phi_width']) + + def jpsi_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['jpsi_mass'], 2)) * resonance(q, _mass = self.params['jpsi_mass'], + scale = self.params['jpsi_scale'], + phase = self.params['jpsi_phase'], + width = self.params['jpsi_width']) + def psi2s_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['psi2s_mass'], 2)) * resonance(q, _mass = self.params['psi2s_mass'], + scale = self.params['psi2s_scale'], + phase = self.params['psi2s_phase'], + width = self.params['psi2s_width']) + def p3770_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p3770_mass'], 2)) * resonance(q, _mass = self.params['p3770_mass'], + scale = self.params['p3770_scale'], + phase = self.params['p3770_phase'], + width = self.params['p3770_width']) + + def p4040_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4040_mass'], 2)) * resonance(q, _mass = self.params['p4040_mass'], + scale = self.params['p4040_scale'], + phase = self.params['p4040_phase'], + width = self.params['p4040_width']) + + def p4160_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4160_mass'], 2)) * resonance(q, _mass = self.params['p4160_mass'], + scale = self.params['p4160_scale'], + phase = self.params['p4160_phase'], + width = self.params['p4160_width']) + + def p4415_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4415_mass'], 2)) * resonance(q, _mass = self.params['p4415_mass'], + scale = self.params['p4415_scale'], + phase = self.params['p4415_phase'], + width = self.params['p4415_width']) + + def P2_D(q): + 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)) + 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['Dstar_mass'], q)) + ztf.to_complex(h_P(self.params['D_mass'], q))) + return Dbar_contrib + DDstar_contrib + + def ttau_cusp(q): + 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))) + + + 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) + + vec_f = vec(x, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + axiv_nr = axiv_nonres(x, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + tot = vec_f + axiv_nr + + #Cut out jpsi and psi2s + +# tot = tf.where(tf.math.logical_or(x < ztf.constant(jpsi_mass-60.), x > ztf.constant(jpsi_mass+70.)), tot, 0.0*tot) + +# tot = tf.where(tf.math.logical_or(x < ztf.constant(psi2s_mass-50.), x > ztf.constant(psi2s_mass+50.)), tot, 0.0*tot) + + return tot + + +# ## Setup parameters + +# In[6]: + + +# formfactors + +b0_0 = zfit.Parameter("b0_0", ztf.constant(0.292), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +b0_1 = zfit.Parameter("b0_1", ztf.constant(0.281), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +b0_2 = zfit.Parameter("b0_2", ztf.constant(0.150), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) + +bplus_0 = zfit.Parameter("bplus_0", ztf.constant(0.466), lower_limit = -2.0, upper_limit= 2.0) +bplus_1 = zfit.Parameter("bplus_1", ztf.constant(-0.885), lower_limit = -2.0, upper_limit= 2.0) +bplus_2 = zfit.Parameter("bplus_2", ztf.constant(-0.213), lower_limit = -2.0, upper_limit= 2.0) + +bT_0 = zfit.Parameter("bT_0", ztf.constant(0.460), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +bT_1 = zfit.Parameter("bT_1", ztf.constant(-1.089), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +bT_2 = zfit.Parameter("bT_2", ztf.constant(-1.114), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) + + +#rho + +rho_mass, rho_width, rho_phase, rho_scale = pdg["rho"] + +rho_m = zfit.Parameter("rho_m", ztf.constant(rho_mass), floating = False) #lower_limit = rho_mass - rho_width, upper_limit = rho_mass + rho_width) +rho_w = zfit.Parameter("rho_w", ztf.constant(rho_width), floating = False) +rho_p = zfit.Parameter("rho_p", ztf.constant(rho_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +rho_s = zfit.Parameter("rho_s", ztf.constant(rho_scale), lower_limit=rho_scale-np.sqrt(rho_scale), upper_limit=rho_scale+np.sqrt(rho_scale)) + +#omega + +omega_mass, omega_width, omega_phase, omega_scale = pdg["omega"] + +omega_m = zfit.Parameter("omega_m", ztf.constant(omega_mass), floating = False) +omega_w = zfit.Parameter("omega_w", ztf.constant(omega_width), floating = False) +omega_p = zfit.Parameter("omega_p", ztf.constant(omega_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +omega_s = zfit.Parameter("omega_s", ztf.constant(omega_scale), lower_limit=omega_scale-np.sqrt(omega_scale), upper_limit=omega_scale+np.sqrt(omega_scale)) + + +#phi + +phi_mass, phi_width, phi_phase, phi_scale = pdg["phi"] + +phi_m = zfit.Parameter("phi_m", ztf.constant(phi_mass), floating = False) +phi_w = zfit.Parameter("phi_w", ztf.constant(phi_width), floating = False) +phi_p = zfit.Parameter("phi_p", ztf.constant(phi_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +phi_s = zfit.Parameter("phi_s", ztf.constant(phi_scale), lower_limit=phi_scale-np.sqrt(phi_scale), upper_limit=phi_scale+np.sqrt(phi_scale)) + +#jpsi + +jpsi_mass, jpsi_width, jpsi_phase, jpsi_scale = pdg["jpsi"] + +jpsi_m = zfit.Parameter("jpsi_m", ztf.constant(jpsi_mass), floating = False) +jpsi_w = zfit.Parameter("jpsi_w", ztf.constant(jpsi_width), floating = False) +jpsi_p = zfit.Parameter("jpsi_p", ztf.constant(jpsi_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +jpsi_s = zfit.Parameter("jpsi_s", ztf.constant(jpsi_scale), floating = False) #, lower_limit=jpsi_scale-np.sqrt(jpsi_scale), upper_limit=jpsi_scale+np.sqrt(jpsi_scale)) + +#psi2s + +psi2s_mass, psi2s_width, psi2s_phase, psi2s_scale = pdg["psi2s"] + +psi2s_m = zfit.Parameter("psi2s_m", ztf.constant(psi2s_mass), floating = False) +psi2s_w = zfit.Parameter("psi2s_w", ztf.constant(psi2s_width), floating = False) +psi2s_p = zfit.Parameter("psi2s_p", ztf.constant(psi2s_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +psi2s_s = zfit.Parameter("psi2s_s", ztf.constant(psi2s_scale), floating = False) #, lower_limit=psi2s_scale-np.sqrt(psi2s_scale), upper_limit=psi2s_scale+np.sqrt(psi2s_scale)) + +#psi(3770) + +p3770_mass, p3770_width, p3770_phase, p3770_scale = pdg["p3770"] + +p3770_m = zfit.Parameter("p3770_m", ztf.constant(p3770_mass), floating = False) +p3770_w = zfit.Parameter("p3770_w", ztf.constant(p3770_width), floating = False) +p3770_p = zfit.Parameter("p3770_p", ztf.constant(p3770_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p3770_s = zfit.Parameter("p3770_s", ztf.constant(p3770_scale), lower_limit=p3770_scale-np.sqrt(p3770_scale), upper_limit=p3770_scale+np.sqrt(p3770_scale)) + +#psi(4040) + +p4040_mass, p4040_width, p4040_phase, p4040_scale = pdg["p4040"] + +p4040_m = zfit.Parameter("p4040_m", ztf.constant(p4040_mass), floating = False) +p4040_w = zfit.Parameter("p4040_w", ztf.constant(p4040_width), floating = False) +p4040_p = zfit.Parameter("p4040_p", ztf.constant(p4040_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4040_s = zfit.Parameter("p4040_s", ztf.constant(p4040_scale), lower_limit=p4040_scale-np.sqrt(p4040_scale), upper_limit=p4040_scale+np.sqrt(p4040_scale)) + +#psi(4160) + +p4160_mass, p4160_width, p4160_phase, p4160_scale = pdg["p4160"] + +p4160_m = zfit.Parameter("p4160_m", ztf.constant(p4160_mass), floating = False) +p4160_w = zfit.Parameter("p4160_w", ztf.constant(p4160_width), floating = False) +p4160_p = zfit.Parameter("p4160_p", ztf.constant(p4160_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4160_s = zfit.Parameter("p4160_s", ztf.constant(p4160_scale), lower_limit=p4160_scale-np.sqrt(p4160_scale), upper_limit=p4160_scale+np.sqrt(p4160_scale)) + +#psi(4415) + +p4415_mass, p4415_width, p4415_phase, p4415_scale = pdg["p4415"] + +p4415_m = zfit.Parameter("p4415_m", ztf.constant(p4415_mass), floating = False) +p4415_w = zfit.Parameter("p4415_w", ztf.constant(p4415_width), floating = False) +p4415_p = zfit.Parameter("p4415_p", ztf.constant(p4415_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4415_s = zfit.Parameter("p4415_s", ztf.constant(p4415_scale), lower_limit=p4415_scale-np.sqrt(p4415_scale), upper_limit=p4415_scale+np.sqrt(p4415_scale)) + + +# ## Dynamic generation of 2 particle contribution + +# In[7]: + + +m_c = 1300 + +Dbar_phase = 0.0 +DDstar_phase = 0.0 +Dstar_mass = pdg['Dst_M'] +Dbar_mass = pdg['D0_M'] +D_mass = pdg['D0_M'] + +Dbar_s = zfit.Parameter("Dbar_s", ztf.constant(0.0), lower_limit=-0.3, upper_limit=0.3) +Dbar_m = zfit.Parameter("Dbar_m", ztf.constant(Dbar_mass), floating = False) +Dbar_p = zfit.Parameter("Dbar_p", ztf.constant(Dbar_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi)#, floating = False) +DDstar_s = zfit.Parameter("DDstar_s", ztf.constant(0.0), lower_limit=-0.3, upper_limit=0.3)#, floating = False) +Dstar_m = zfit.Parameter("Dstar_m", ztf.constant(Dstar_mass), floating = False) +D_m = zfit.Parameter("D_m", ztf.constant(D_mass), floating = False) +DDstar_p = zfit.Parameter("DDstar_p", ztf.constant(DDstar_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi)#, floating = False) + + +# ## Tau parameters + +# In[8]: + + +tau_m = zfit.Parameter("tau_m", ztf.constant(pdg['tau_M']), floating = False) +Ctt = zfit.Parameter("Ctt", ztf.constant(0.0), lower_limit=-1.5, upper_limit=1.5) + + +# ## Load data + +# In[9]: + + +x_min = 2*pdg['muon_M'] +x_max = (pdg["Bplus_M"]-pdg["Ks_M"]-0.1) + +# # Full spectrum + +obs_toy = zfit.Space('q', limits = (x_min, x_max)) + +# Jpsi and Psi2s cut out + +obs1 = zfit.Space('q', limits = (x_min, jpsi_mass - 60.)) +obs2 = zfit.Space('q', limits = (jpsi_mass + 70., psi2s_mass - 50.)) +obs3 = zfit.Space('q', limits = (psi2s_mass + 50., x_max)) + +obs_fit = obs1 + obs2 + obs3 + +# 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: +# part_set = pkl.load(input_file) + +# x_part = part_set['x_part'] + +# x_part = x_part.astype('float64') + +# data = zfit.data.Data.from_numpy(array=x_part, obs=obs) + + +# ## Setup pdf + +# In[10]: + + +total_f = total_pdf_cut(obs=obs_toy, jpsi_mass = jpsi_m, jpsi_scale = jpsi_s, jpsi_phase = jpsi_p, jpsi_width = jpsi_w, + psi2s_mass = psi2s_m, psi2s_scale = psi2s_s, psi2s_phase = psi2s_p, psi2s_width = psi2s_w, + p3770_mass = p3770_m, p3770_scale = p3770_s, p3770_phase = p3770_p, p3770_width = p3770_w, + p4040_mass = p4040_m, p4040_scale = p4040_s, p4040_phase = p4040_p, p4040_width = p4040_w, + p4160_mass = p4160_m, p4160_scale = p4160_s, p4160_phase = p4160_p, p4160_width = p4160_w, + p4415_mass = p4415_m, p4415_scale = p4415_s, p4415_phase = p4415_p, p4415_width = p4415_w, + rho_mass = rho_m, rho_scale = rho_s, rho_phase = rho_p, rho_width = rho_w, + omega_mass = omega_m, omega_scale = omega_s, omega_phase = omega_p, omega_width = omega_w, + phi_mass = phi_m, phi_scale = phi_s, phi_phase = phi_p, phi_width = phi_w, + Dstar_mass = Dstar_m, DDstar_scale = DDstar_s, DDstar_phase = DDstar_p, D_mass = D_m, + Dbar_mass = Dbar_m, Dbar_scale = Dbar_s, Dbar_phase = Dbar_p, + tau_mass = tau_m, C_tt = Ctt, b0_0 = b0_0, b0_1 = b0_1, b0_2 = b0_2, + bplus_0 = bplus_0, bplus_1 = bplus_1, bplus_2 = bplus_2, + bT_0 = bT_0, bT_1 = bT_1, bT_2 = bT_2) + +total_f_fit = total_pdf_full(obs=obs_fit, jpsi_mass = jpsi_m, jpsi_scale = jpsi_s, jpsi_phase = jpsi_p, jpsi_width = jpsi_w, + psi2s_mass = psi2s_m, psi2s_scale = psi2s_s, psi2s_phase = psi2s_p, psi2s_width = psi2s_w, + p3770_mass = p3770_m, p3770_scale = p3770_s, p3770_phase = p3770_p, p3770_width = p3770_w, + p4040_mass = p4040_m, p4040_scale = p4040_s, p4040_phase = p4040_p, p4040_width = p4040_w, + p4160_mass = p4160_m, p4160_scale = p4160_s, p4160_phase = p4160_p, p4160_width = p4160_w, + p4415_mass = p4415_m, p4415_scale = p4415_s, p4415_phase = p4415_p, p4415_width = p4415_w, + rho_mass = rho_m, rho_scale = rho_s, rho_phase = rho_p, rho_width = rho_w, + omega_mass = omega_m, omega_scale = omega_s, omega_phase = omega_p, omega_width = omega_w, + phi_mass = phi_m, phi_scale = phi_s, phi_phase = phi_p, phi_width = phi_w, + Dstar_mass = Dstar_m, DDstar_scale = DDstar_s, DDstar_phase = DDstar_p, D_mass = D_m, + Dbar_mass = Dbar_m, Dbar_scale = Dbar_s, Dbar_phase = Dbar_p, + tau_mass = tau_m, C_tt = Ctt, b0_0 = b0_0, b0_1 = b0_1, b0_2 = b0_2, + bplus_0 = bplus_0, bplus_1 = bplus_1, bplus_2 = bplus_2, + bT_0 = bT_0, bT_1 = bT_1, bT_2 = bT_2) + +# print(total_pdf.obs) + +# print(calcs_test) + +# for param in total_f.get_dependents(): +# print(zfit.run(param)) + + +# In[11]: + + +total_f_fit.normalization(obs_toy) + + +# ## Test if graphs actually work and compute values + +# In[12]: + + +# def total_test_tf(xq): + +# def jpsi_res(q): +# return resonance(q, jpsi_m, jpsi_s, jpsi_p, jpsi_w) + +# def psi2s_res(q): +# return resonance(q, psi2s_m, psi2s_s, psi2s_p, psi2s_w) + +# def cusp(q): +# return bifur_gauss(q, cusp_m, sig_L, sig_R, cusp_s) + +# funcs = jpsi_res(xq) + psi2s_res(xq) + cusp(xq) + +# vec_f = vec(xq, funcs) + +# axiv_nr = axiv_nonres(xq) + +# tot = vec_f + axiv_nr + +# return tot + +# def jpsi_res(q): +# return resonance(q, jpsi_m, jpsi_s, jpsi_p, jpsi_w) + +# calcs = zfit.run(total_test_tf(x_part)) + +test_q = np.linspace(x_min, x_max, int(2e6)) + +probs = total_f_fit.pdf(test_q, norm_range=False) + +calcs_test = zfit.run(probs) +# res_y = zfit.run(jpsi_res(test_q)) +# b0 = [b0_0, b0_1, b0_2] +# bplus = [bplus_0, bplus_1, bplus_2] +# bT = [bT_0, bT_1, bT_2] +# f0_y = zfit.run(tf.math.real(formfactor(test_q,"0", b0, bplus, bT))) +# fplus_y = zfit.run(tf.math.real(formfactor(test_q,"+", b0, bplus, bT))) +# fT_y = zfit.run(tf.math.real(formfactor(test_q,"T", b0, bplus, bT))) + + +# In[13]: + + +plt.clf() +# plt.plot(x_part, calcs, '.') +plt.plot(test_q, calcs_test, label = 'pdf') +# plt.plot(test_q, f0_y, label = '0') +# plt.plot(test_q, fT_y, label = 'T') +# plt.plot(test_q, fplus_y, label = '+') +# plt.plot(test_q, res_y, label = 'res') +plt.legend() +plt.ylim(0.0, 1.5e-6) +# plt.yscale('log') +# plt.xlim(770, 785) +plt.savefig('test.png') +# print(jpsi_width) + + +# In[14]: + + + + +# probs = mixture.prob(test_q) +# probs_np = zfit.run(probs) +# probs_np *= np.max(calcs_test) / np.max(probs_np) +# plt.figure() +# plt.semilogy(test_q, probs_np,label="importance sampling") +# plt.semilogy(test_q, calcs_test, label = 'pdf') + + +# In[15]: + + +# 0.213/(0.00133+0.213+0.015) + + +# ## Adjust scaling of different parts + +# In[16]: + + +total_f.update_integration_options(draws_per_dim=2000000, mc_sampler=None) +# inte = total_f.integrate(limits = (950., 1050.), norm_range=False) +# inte_fl = zfit.run(inte) +# print(inte_fl/4500) +# print(pdg["jpsi_BR"]/pdg["NR_BR"], inte_fl*pdg["psi2s_auc"]/pdg["NR_auc"]) + + +# In[17]: + + +# # print("jpsi:", inte_fl) +# # print("Increase am by factor:", np.sqrt(pdg["jpsi_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# # print("New amp:", pdg["jpsi"][3]*np.sqrt(pdg["jpsi_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + +# # print("psi2s:", inte_fl) +# # print("Increase am by factor:", np.sqrt(pdg["psi2s_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# # print("New amp:", pdg["psi2s"][3]*np.sqrt(pdg["psi2s_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + +# name = "phi" + +# print(name+":", inte_fl) +# print("Increase am by factor:", np.sqrt(pdg[name+"_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# print("New amp:", pdg[name][0]*np.sqrt(pdg[name+"_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + + +# print(x_min) +# print(x_max) +# # total_f.update_integration_options(draws_per_dim=2000000, mc_sampler=None) +# total_f.update_integration_options(mc_sampler=lambda dim, num_results, +# dtype: tf.random_uniform(maxval=1., shape=(num_results, dim), dtype=dtype), +# draws_per_dim=1000000) +# # _ = [] + +# # for i in range(10): + +# # inte = total_f.integrate(limits = (x_min, x_max)) +# # inte_fl = zfit.run(inte) +# # print(inte_fl) +# # _.append(inte_fl) + +# # print("mean:", np.mean(_)) + +# _ = time.time() + +# inte = total_f.integrate(limits = (x_min, x_max)) +# inte_fl = zfit.run(inte) +# print(inte_fl) +# print("Time taken: {}".format(display_time(int(time.time() - _)))) + +# print(pdg['NR_BR']/pdg['NR_auc']*inte_fl) +# print(0.25**2*4.2/1000) + + +# # Sampling +# ## Mixture distribution for sampling + +# In[18]: + + + + +# print(list_of_borders[:9]) +# print(list_of_borders[-9:]) + + +class UniformSampleAndWeights(zfit.util.execution.SessionHolderMixin): + def __call__(self, limits, dtype, n_to_produce): + # n_to_produce = tf.cast(n_to_produce, dtype=tf.int32) + low, high = limits.limit1d + low = tf.cast(low, dtype=dtype) + high = tf.cast(high, dtype=dtype) +# uniform = tfd.Uniform(low=low, high=high) +# uniformjpsi = tfd.Uniform(low=tf.constant(3080, dtype=dtype), high=tf.constant(3112, dtype=dtype)) +# uniformpsi2s = tfd.Uniform(low=tf.constant(3670, dtype=dtype), high=tf.constant(3702, dtype=dtype)) + +# list_of_borders = [] +# _p = [] +# splits = 10 + +# _ = np.linspace(x_min, x_max, splits) + +# for i in range(splits): +# list_of_borders.append(tf.constant(_[i], dtype=dtype)) +# _p.append(tf.constant(1/splits, dtype=dtype)) + +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=_p[:(splits-1)]), +# components_distribution=tfd.Uniform(low=list_of_borders[:(splits-1)], +# high=list_of_borders[-(splits-1):])) + mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.05, dtype=dtype), + tf.constant(0.93, dtype=dtype), + tf.constant(0.05, dtype=dtype), + tf.constant(0.065, dtype=dtype), + tf.constant(0.04, dtype=dtype), + tf.constant(0.05, dtype=dtype)]), + components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), + tf.constant(3090, dtype=dtype), + tf.constant(3681, dtype=dtype), + tf.constant(3070, dtype=dtype), + tf.constant(1000, dtype=dtype), + tf.constant(3660, dtype=dtype)], + high=[tf.constant(x_max, dtype=dtype), + tf.constant(3102, dtype=dtype), + tf.constant(3691, dtype=dtype), + tf.constant(3110, dtype=dtype), + tf.constant(1040, dtype=dtype), + tf.constant(3710, dtype=dtype)])) +# dtype = tf.float64 +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.04, dtype=dtype), +# tf.constant(0.90, dtype=dtype), +# tf.constant(0.02, dtype=dtype), +# tf.constant(0.07, dtype=dtype), +# tf.constant(0.02, dtype=dtype)]), +# components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), +# tf.constant(3089, dtype=dtype), +# tf.constant(3103, dtype=dtype), +# tf.constant(3681, dtype=dtype), +# tf.constant(3691, dtype=dtype)], +# high=[tf.constant(3089, dtype=dtype), +# tf.constant(3103, dtype=dtype), +# tf.constant(3681, dtype=dtype), +# tf.constant(3691, dtype=dtype), +# tf.constant(x_max, dtype=dtype)])) +# mixture = tfd.Uniform(tf.constant(x_min, dtype=dtype), tf.constant(x_max, dtype=dtype)) +# sample = tf.random.uniform((n_to_produce, 1), dtype=dtype) + sample = mixture.sample((n_to_produce, 1)) +# sample = tf.random.uniform((n_to_produce, 1), dtype=dtype) + weights = mixture.prob(sample)[:,0] +# weights = tf.broadcast_to(tf.constant(1., dtype=dtype), shape=(n_to_produce,)) + # sample = tf.expand_dims(sample, axis=-1) +# print(sample, weights) + +# weights = tf.ones(shape=(n_to_produce,), dtype=dtype) + weights_max = None + thresholds = tf.random_uniform(shape=(n_to_produce,), dtype=dtype) + return sample, thresholds, weights, weights_max, n_to_produce + + +# In[19]: + + +# total_f._sample_and_weights = UniformSampleAndWeights + + +# In[20]: + + +# 0.00133/(0.00133+0.213+0.015)*(x_max-3750)/(x_max-x_min) + + +# In[21]: + + +# zfit.settings.set_verbosity(10) + + +# In[22]: + + +# # zfit.run.numeric_checks = False + +# nr_of_toys = 1 +# nevents = int(pdg["number_of_decays"]) +# nevents = pdg["number_of_decays"] +# event_stack = 1000000 +# # zfit.settings.set_verbosity(10) +# calls = int(nevents/event_stack + 1) + +# total_samp = [] + +# start = time.time() + +# sampler = total_f.create_sampler(n=event_stack) + +# for toy in range(nr_of_toys): + +# dirName = 'data/zfit_toys/toy_{0}'.format(toy) + +# if not os.path.exists(dirName): +# os.mkdir(dirName) +# print("Directory " , dirName , " Created ") + +# for call in range(calls): + +# sampler.resample(n=event_stack) +# s = sampler.unstack_x() +# sam = zfit.run(s) +# # clear_output(wait=True) + +# c = call + 1 + +# print("{0}/{1} of Toy {2}/{3}".format(c, calls, toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(c+calls*(toy))*((nr_of_toys-toy)*calls-c))))) + +# with open("data/zfit_toys/toy_{0}/{1}.pkl".format(toy, call), "wb") as f: +# pkl.dump(sam, f, pkl.HIGHEST_PROTOCOL) + + +# In[23]: + + +# with open(r"data/zfit_toys/toy_0/0.pkl", "rb") as input_file: +# sam = pkl.load(input_file) +# print(sam[:10]) + +# with open(r"data/zfit_toys/toy_0/1.pkl", "rb") as input_file: +# sam2 = pkl.load(input_file) +# print(sam2[:10]) + +# print(np.sum(sam-sam2)) + + +# In[24]: + + +# print("Time to generate full toy: {} s".format(int(time.time()-start))) + +# total_samp = [] + +# for call in range(calls): +# with open(r"data/zfit_toys/toy_0/{}.pkl".format(call), "rb") as input_file: +# sam = pkl.load(input_file) +# total_samp = np.append(total_samp, sam) + +# total_samp = total_samp.astype('float64') + +# data2 = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs) + +# data3 = zfit.data.Data.from_numpy(array=total_samp, obs=obs) + +# print(total_samp[:nevents].shape) + + +# In[25]: + + +# plt.clf() + +# bins = int((x_max-x_min)/7) + +# # calcs = zfit.run(total_test_tf(samp)) +# print(total_samp[:nevents].shape) + +# plt.hist(total_samp[:nevents], bins = bins, range = (x_min,x_max), label = 'data') +# # plt.plot(test_q, calcs_test*nevents , label = 'pdf') + +# # plt.plot(sam, calcs, '.') +# # plt.plot(test_q, calcs_test) +# # plt.yscale('log') +# plt.ylim(0, 200) +# # plt.xlim(3080, 3110) + +# plt.legend() + +# plt.savefig('test2.png') + + +# In[26]: + + +# sampler = total_f.create_sampler(n=nevents) +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=sampler, fit_range = (x_min, x_max)) + +# # for param in pdf.get_dependents(): +# # param.set_value(initial_value) + +# sampler.resample(n=nevents) + +# # Randomise initial values +# # for param in pdf.get_dependents(): +# # param.set_value(random value here) + +# # Minimise the NLL +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 10) +# minimum = minimizer.minimize(nll) + + +# In[27]: + + +# jpsi_width + + +# In[28]: + + +# plt.hist(sample, weights=1 / prob(sample)) + + +# # Fitting + +# In[29]: + + +# start = time.time() + +# for param in total_f.get_dependents(): +# param.randomize() + +# # for param in total_f.get_dependents(): +# # print(zfit.run(param)) + +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=data2, fit_range = (x_min, x_max)) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# # param_errors = result.error() + +# # for var, errors in param_errors.items(): +# # print('{}: ^{{+{}}}_{{{}}}'.format(var.name, errors['upper'], errors['lower'])) + +# print("Function minimum:", result.fmin) +# # print("Results:", result.params) +# print("Hesse errors:", result.hesse()) + + +# In[30]: + + +# print("Time taken for fitting: {}".format(display_time(int(time.time()-start)))) + +# # probs = total_f.pdf(test_q) + +# calcs_test = zfit.run(probs) +# res_y = zfit.run(jpsi_res(test_q)) + + +# In[31]: + + +# plt.clf() +# # plt.plot(x_part, calcs, '.') +# plt.plot(test_q, calcs_test, label = 'pdf') +# # plt.plot(test_q, res_y, label = 'res') +# plt.legend() +# plt.ylim(0.0, 10e-6) +# # plt.yscale('log') +# # plt.xlim(3080, 3110) +# plt.savefig('test3.png') +# # print(jpsi_width) + + +# In[32]: + + +# _tot = 4.37e-7+6.02e-5+4.97e-6 +# _probs = [] +# _probs.append(6.02e-5/_tot) +# _probs.append(4.97e-6/_tot) +# _probs.append(4.37e-7/_tot) +# print(_probs) + + +# In[33]: + + +# dtype = 'float64' +# # mixture = tfd.Uniform(tf.constant(x_min, dtype=dtype), tf.constant(x_max, dtype=dtype)) +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.007, dtype=dtype), +# tf.constant(0.917, dtype=dtype), +# tf.constant(0.076, dtype=dtype)]), +# components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), +# tf.constant(3080, dtype=dtype), +# tf.constant(3670, dtype=dtype)], +# high=[tf.constant(x_max, dtype=dtype), +# tf.constant(3112, dtype=dtype), +# tf.constant(3702, dtype=dtype)])) +# # for i in range(10): +# # print(zfit.run(mixture.prob(mixture.sample((10, 1))))) + + +# In[34]: + + +# print((zfit.run(jpsi_p)%(2*np.pi))/np.pi) +# print((zfit.run(psi2s_p)%(2*np.pi))/np.pi) + + +# In[35]: + + +# def jpsi_res(q): +# return resonance(q, _mass = jpsi_mass, scale = jpsi_scale, +# phase = jpsi_phase, width = jpsi_width) + +# def psi2s_res(q): +# return resonance(q, _mass = psi2s_mass, scale = psi2s_scale, +# phase = psi2s_phase, width = psi2s_width) + +# def p3770_res(q): +# return resonance(q, _mass = p3770_mass, scale = p3770_scale, +# phase = p3770_phase, width = p3770_width) + +# def p4040_res(q): +# return resonance(q, _mass = p4040_mass, scale = p4040_scale, +# phase = p4040_phase, width = p4040_width) + +# def p4160_res(q): +# return resonance(q, _mass = p4160_mass, scale = p4160_scale, +# phase = p4160_phase, width = p4160_width) + +# def p4415_res(q): +# return resonance(q, _mass = p4415_mass, scale = p4415_scale, +# phase = p4415_phase, width = p4415_width) + + +# In[36]: + + +# 0.15**2*4.2/1000 +# result.hesse() + + +# ## Constraints + +# In[37]: + + +# 1. Constraint - Real part of sum of Psi contrib and D contribs + +sum_list = [] + +sum_list.append(ztf.to_complex(jpsi_s) * tf.exp(tf.complex(ztf.constant(0.0), jpsi_p)) * ztf.to_complex(jpsi_w / (tf.pow(jpsi_m,3)))) +sum_list.append(ztf.to_complex(psi2s_s) * tf.exp(tf.complex(ztf.constant(0.0), psi2s_p)) * ztf.to_complex(psi2s_w / (tf.pow(psi2s_m,3)))) +sum_list.append(ztf.to_complex(p3770_s) * tf.exp(tf.complex(ztf.constant(0.0), p3770_p)) * ztf.to_complex(p3770_w / (tf.pow(p3770_m,3)))) +sum_list.append(ztf.to_complex(p4040_s) * tf.exp(tf.complex(ztf.constant(0.0), p4040_p)) * ztf.to_complex(p4040_w / (tf.pow(p4040_m,3)))) +sum_list.append(ztf.to_complex(p4160_s) * tf.exp(tf.complex(ztf.constant(0.0), p4160_p)) * ztf.to_complex(p4160_w / (tf.pow(p4160_m,3)))) +sum_list.append(ztf.to_complex(p4415_s) * tf.exp(tf.complex(ztf.constant(0.0), p4415_p)) * ztf.to_complex(p4415_w / (tf.pow(p4415_m,3)))) +sum_list.append(ztf.to_complex(DDstar_s) * tf.exp(tf.complex(ztf.constant(0.0), DDstar_p)) * (ztf.to_complex(1.0 / (10.0*tf.pow(Dstar_m,2)) + 1.0 / (10.0*tf.pow(D_m,2))))) +sum_list.append(ztf.to_complex(Dbar_s) * tf.exp(tf.complex(ztf.constant(0.0), Dbar_p)) * ztf.to_complex(1.0 / (6.0*tf.pow(Dbar_m,2)))) + +sum_ru_1 = ztf.to_complex(ztf.constant(0.0)) + +for part in sum_list: + sum_ru_1 += part + +sum_1 = tf.math.real(sum_ru_1) +# constraint1 = zfit.constraint.GaussianConstraint(params = sum_1, mu = ztf.constant(1.7*10**-8), +# sigma = ztf.constant(2.2*10**-8)) + +constraint1 = tf.pow((sum_1-ztf.constant(1.7*10**-8))/ztf.constant(2.2*10**-8),2)/ztf.constant(2.) + +# 2. Constraint - Abs. of sum of Psi contribs and D contribs + +sum_2 = tf.abs(sum_ru_1) +constraint2 = tf.cond(tf.greater_equal(sum_2, 5.0e-8), lambda: 100000., lambda: 0.) + +# 3. Constraint - Maximum eta of D contribs + +constraint3_0 = tf.cond(tf.greater_equal(tf.abs(Dbar_s), 0.2), lambda: 100000., lambda: 0.) + +constraint3_1 = tf.cond(tf.greater_equal(tf.abs(DDstar_s), 0.2), lambda: 100000., lambda: 0.) + +# 4. Constraint - Formfactor multivariant gaussian covariance fplus + +Cov_matrix = [[ztf.constant( 1.), ztf.constant( 0.45), ztf.constant( 0.19), ztf.constant(0.857), ztf.constant(0.598), ztf.constant(0.531), ztf.constant(0.752), ztf.constant(0.229), ztf.constant(0,117)], + [ztf.constant( 0.45), ztf.constant( 1.), ztf.constant(0.677), ztf.constant(0.708), ztf.constant(0.958), ztf.constant(0.927), ztf.constant(0.227), ztf.constant(0.443), ztf.constant(0.287)], + [ztf.constant( 0.19), ztf.constant(0.677), ztf.constant( 1.), ztf.constant(0.595), ztf.constant(0.770), ztf.constant(0.819),ztf.constant(-0.023), ztf.constant( 0.07), ztf.constant(0.196)], + [ztf.constant(0.857), ztf.constant(0.708), ztf.constant(0.595), ztf.constant( 1.), ztf.constant( 0.83), ztf.constant(0.766), ztf.constant(0.582), ztf.constant(0.237), ztf.constant(0.192)], + [ztf.constant(0.598), ztf.constant(0.958), ztf.constant(0.770), ztf.constant( 0.83), ztf.constant( 1.), ztf.constant(0.973), ztf.constant(0.324), ztf.constant(0.372), ztf.constant(0.272)], + [ztf.constant(0.531), ztf.constant(0.927), ztf.constant(0.819), ztf.constant(0.766), ztf.constant(0.973), ztf.constant( 1.), ztf.constant(0.268), ztf.constant(0.332), ztf.constant(0.269)], + [ztf.constant(0.752), ztf.constant(0.227),ztf.constant(-0.023), ztf.constant(0.582), ztf.constant(0.324), ztf.constant(0.268), ztf.constant( 1.), ztf.constant( 0.59), ztf.constant(0.515)], + [ztf.constant(0.229), ztf.constant(0.443), ztf.constant( 0.07), ztf.constant(0.237), ztf.constant(0.372), ztf.constant(0.332), ztf.constant( 0.59), ztf.constant( 1.), ztf.constant(0.897)], + [ztf.constant(0.117), ztf.constant(0.287), ztf.constant(0.196), ztf.constant(0.192), ztf.constant(0.272), ztf.constant(0.269), ztf.constant(0.515), ztf.constant(0.897), ztf.constant( 1.)]] + +def triGauss(val1,val2,val3,m = Cov_matrix): + + mean1 = ztf.constant(0.466) + mean2 = ztf.constant(-0.885) + mean3 = ztf.constant(-0.213) + sigma1 = ztf.constant(0.014) + sigma2 = ztf.constant(0.128) + sigma3 = ztf.constant(0.548) + x1 = (val1-mean1)/sigma1 + x2 = (val2-mean2)/sigma2 + x3 = (val3-mean3)/sigma3 + rho12 = m[0][1] + rho13 = m[0][2] + rho23 = m[1][2] + w = x1*x1*(rho23*rho23-1) + x2*x2*(rho13*rho13-1)+x3*x3*(rho12*rho12-1)+2*(x1*x2*(rho12-rho13*rho23)+x1*x3*(rho13-rho12*rho23)+x2*x3*(rho23-rho12*rho13)) + d = 2*(rho12*rho12+rho13*rho13+rho23*rho23-2*rho12*rho13*rho23-1) + + fcn = -w/d + chisq = -2*fcn + return chisq + +constraint4 = triGauss(bplus_0, bplus_1, bplus_2) + +# mean1 = ztf.constant(0.466) +# mean2 = ztf.constant(-0.885) +# mean3 = ztf.constant(-0.213) +# sigma1 = ztf.constant(0.014) +# sigma2 = ztf.constant(0.128) +# sigma3 = ztf.constant(0.548) +# constraint4_0 = tf.pow((bplus_0-mean1)/sigma1,2)/ztf.constant(2.) +# constraint4_1 = tf.pow((bplus_1-mean2)/sigma2,2)/ztf.constant(2.) +# constraint4_2 = tf.pow((bplus_2-mean3)/sigma3,2)/ztf.constant(2.) + +# 5. Constraint - Abs. of sum of light contribs + +sum_list_5 = [] + +sum_list_5.append(rho_s*rho_w/rho_m) +sum_list_5.append(omega_s*omega_w/omega_m) +sum_list_5.append(phi_s*phi_w/phi_m) + + +sum_ru_5 = ztf.constant(0.0) + +for part in sum_list_5: + sum_ru_5 += part + +constraint5 = tf.cond(tf.greater_equal(tf.abs(sum_ru_5), ztf.constant(0.02)), lambda: 100000., lambda: 0.) + +# 6. Constraint on phases of Jpsi and Psi2s for cut out fit + + +# constraint6_0 = zfit.constraint.GaussianConstraint(params = jpsi_p, mu = ztf.constant(pdg["jpsi_phase_unc"]), +# sigma = ztf.constant(jpsi_phase)) +# constraint6_1 = zfit.constraint.GaussianConstraint(params = psi2s_p, mu = ztf.constant(pdg["psi2s_phase_unc"]), +# sigma = ztf.constant(psi2s_phase)) + +constraint6_0 = tf.pow((jpsi_p-ztf.constant(jpsi_phase))/ztf.constant(pdg["jpsi_phase_unc"]),2)/ztf.constant(2.) +constraint6_1 = tf.pow((psi2s_p-ztf.constant(psi2s_phase))/ztf.constant(pdg["psi2s_phase_unc"]),2)/ztf.constant(2.) + +# 7. Constraint on Ctt with higher limits + +constraint7 = tf.cond(tf.greater_equal(Ctt*Ctt, 0.25), lambda: 100000., lambda: 0.) + +constraint7dtype = tf.float64 + +# zfit.run(constraint6_0) + +# ztf.convert_to_tensor(constraint6_0) + +#List of all constraints + +constraints = [constraint1, constraint2, constraint3_0, constraint3_1,# constraint4, #constraint4_0, constraint4_1, constraint4_2, + constraint6_0, constraint6_1]#, constraint7] + + +# ## Reset params + +# In[38]: + + +def reset_param_values(): + jpsi_m.set_value(jpsi_mass) + jpsi_s.set_value(jpsi_scale) + jpsi_p.set_value(jpsi_phase) + jpsi_w.set_value(jpsi_width) + psi2s_m.set_value(psi2s_mass) + psi2s_s.set_value(psi2s_scale) + psi2s_p.set_value(psi2s_phase) + psi2s_w.set_value(psi2s_width) + p3770_m.set_value(p3770_mass) + p3770_s.set_value(p3770_scale) + p3770_p.set_value(p3770_phase) + p3770_w.set_value(p3770_width) + p4040_m.set_value(p4040_mass) + p4040_s.set_value(p4040_scale) + p4040_p.set_value(p4040_phase) + p4040_w.set_value(p4040_width) + p4160_m.set_value(p4160_mass) + p4160_s.set_value(p4160_scale) + p4160_p.set_value(p4160_phase) + p4160_w.set_value(p4160_width) + p4415_m.set_value(p4415_mass) + p4415_s.set_value(p4415_scale) + p4415_p.set_value(p4415_phase) + p4415_w.set_value(p4415_width) + rho_m.set_value(rho_mass) + rho_s.set_value(rho_scale) + rho_p.set_value(rho_phase) + rho_w.set_value(rho_width) + omega_m.set_value(omega_mass) + omega_s.set_value(omega_scale) + omega_p.set_value(omega_phase) + omega_w.set_value(omega_width) + phi_m.set_value(phi_mass) + phi_s.set_value(phi_scale) + phi_p.set_value(phi_phase) + phi_w.set_value(phi_width) + Dstar_m.set_value(Dstar_mass) + DDstar_s.set_value(0.0) + DDstar_p.set_value(0.0) + D_m.set_value(D_mass) + Dbar_m.set_value(Dbar_mass) + Dbar_s.set_value(0.0) + Dbar_p.set_value(0.0) + tau_m.set_value(pdg['tau_M']) + Ctt.set_value(0.0) + b0_0.set_value(0.292) + b0_1.set_value(0.281) + b0_2.set_value(0.150) + bplus_0.set_value(0.466) + bplus_1.set_value(-0.885) + bplus_2.set_value(-0.213) + bT_0.set_value(0.460) + bT_1.set_value(-1.089) + bT_2.set_value(-1.114) + + +# # Analysis + +# In[39]: + + +# # zfit.run.numeric_checks = False + +# fitting_range = 'cut' +# total_BR = 1.7e-10 + 4.9e-10 + 2.5e-9 + 6.02e-5 + 4.97e-6 + 1.38e-9 + 4.2e-10 + 2.6e-9 + 6.1e-10 + 4.37e-7 +# cut_BR = 1.0 - (6.02e-5 + 4.97e-6)/total_BR + +# Ctt_list = [] +# Ctt_error_list = [] + +# nr_of_toys = 1 +# if fitting_range == 'cut': +# nevents = int(pdg["number_of_decays"]*cut_BR) +# else: +# nevents = int(pdg["number_of_decays"]) +# # nevents = pdg["number_of_decays"] +# event_stack = 1000000 +# # nevents *= 41 +# # zfit.settings.set_verbosity(10) +# calls = int(nevents/event_stack + 1) + +# total_samp = [] + +# start = time.time() + +# sampler = total_f.create_sampler(n=event_stack) + +# for toy in range(nr_of_toys): + +# ### Generate data + +# # clear_output(wait=True) + +# print("Toy {}: Generating data...".format(toy)) + +# dirName = 'data/zfit_toys/toy_{0}'.format(toy) + +# if not os.path.exists(dirName): +# os.mkdir(dirName) +# print("Directory " , dirName , " Created ") + +# reset_param_values() + +# if fitting_range == 'cut': + +# sampler.resample(n=nevents) +# s = sampler.unstack_x() +# sam = zfit.run(s) +# calls = 0 +# c = 1 + +# else: +# for call in range(calls): + +# sampler.resample(n=event_stack) +# s = sampler.unstack_x() +# sam = zfit.run(s) + +# c = call + 1 + +# with open("data/zfit_toys/toy_{0}/{1}.pkl".format(toy, call), "wb") as f: +# pkl.dump(sam, f, pkl.HIGHEST_PROTOCOL) + +# print("Toy {}: Data generation finished".format(toy)) + +# ### Load data + +# print("Toy {}: Loading data...".format(toy)) + +# if fitting_range == 'cut': + +# total_samp = sam + +# else: + +# for call in range(calls): +# with open(r"data/zfit_toys/toy_0/{}.pkl".format(call), "rb") as input_file: +# sam = pkl.load(input_file) +# total_samp = np.append(total_samp, sam) + +# total_samp = total_samp.astype('float64') + +# if fitting_range == 'full': + +# data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs) + +# print("Toy {}: Loading data finished".format(toy)) + +# ### Fit data + +# print("Toy {}: Fitting pdf...".format(toy)) + +# for param in total_f.get_dependents(): +# param.randomize() + +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=data, fit_range = (x_min, x_max), constraints = constraints) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# print("Toy {}: Fitting finished".format(toy)) + +# print("Function minimum:", result.fmin) +# print("Hesse errors:", result.hesse()) + +# params = result.params +# Ctt_list.append(params[Ctt]['value']) +# Ctt_error_list.append(params[Ctt]['minuit_hesse']['error']) + +# #plotting the result + +# plotdirName = 'data/plots'.format(toy) + +# if not os.path.exists(plotdirName): +# os.mkdir(plotdirName) +# # print("Directory " , dirName , " Created ") + +# probs = total_f.pdf(test_q, norm_range=False) +# calcs_test = zfit.run(probs) +# plt.clf() +# plt.plot(test_q, calcs_test, label = 'pdf') +# plt.legend() +# plt.ylim(0.0, 6e-6) +# plt.savefig(plotdirName + '/toy_fit_full_range{}.png'.format(toy)) + +# print("Toy {0}/{1}".format(toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(c+calls*(toy))*((nr_of_toys-toy)*calls-c))))) + +# if fitting_range == 'cut': + +# _1 = np.where((total_samp >= x_min) & (total_samp <= (jpsi_mass - 60.))) + +# tot_sam_1 = total_samp[_1] + +# _2 = np.where((total_samp >= (jpsi_mass + 70.)) & (total_samp <= (psi2s_mass - 50.))) + +# tot_sam_2 = total_samp[_2] + +# _3 = np.where((total_samp >= (psi2s_mass + 50.)) & (total_samp <= x_max)) + +# tot_sam_3 = total_samp[_3] + +# tot_sam = np.append(tot_sam_1, tot_sam_2) +# tot_sam = np.append(tot_sam, tot_sam_3) + +# data = zfit.data.Data.from_numpy(array=tot_sam[:int(nevents)], obs=obs_fit) + +# print("Toy {}: Loading data finished".format(toy)) + +# ### Fit data + +# print("Toy {}: Fitting pdf...".format(toy)) + +# for param in total_f_fit.get_dependents(): +# param.randomize() + +# nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# print("Function minimum:", result.fmin) +# print("Hesse errors:", result.hesse()) + +# params = result.params + +# if result.converged: +# Ctt_list.append(params[Ctt]['value']) +# Ctt_error_list.append(params[Ctt]['minuit_hesse']['error']) + +# #plotting the result + +# plotdirName = 'data/plots'.format(toy) + +# if not os.path.exists(plotdirName): +# os.mkdir(plotdirName) +# # print("Directory " , dirName , " Created ") + +# plt.clf() +# plt.hist(tot_sam, bins = int((x_max-x_min)/7.), label = 'toy data') +# plt.savefig(plotdirName + '/toy_histo_cut_region{}.png'.format(toy)) + + +# probs = total_f_fit.pdf(test_q, norm_range=False) +# calcs_test = zfit.run(probs) +# plt.clf() +# plt.plot(test_q, calcs_test, label = 'pdf') +# plt.axvline(x=jpsi_mass-60.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=jpsi_mass+70.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=psi2s_mass-50.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=psi2s_mass+50.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.legend() +# plt.ylim(0.0, 1.5e-6) +# plt.savefig(plotdirName + '/toy_fit_cut_region{}.png'.format(toy)) + +# print("Toy {0}/{1}".format(toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(toy+1))*((nr_of_toys-toy-1))))) + + + +# In[40]: + + +# with open("data/results/Ctt_list.pkl", "wb") as f: +# pkl.dump(Ctt_list, f, pkl.HIGHEST_PROTOCOL) +# with open("data/results/Ctt_error_list.pkl", "wb") as f: +# pkl.dump(Ctt_error_list, f, pkl.HIGHEST_PROTOCOL) + + +# In[41]: + + +# print('{0}/{1} fits converged'.format(len(Ctt_list), nr_of_toys)) +# print('Mean Ctt value = {}'.format(np.mean(Ctt_list))) +# print('Mean Ctt error = {}'.format(np.mean(Ctt_error_list))) +# print('95 Sensitivy = {}'.format(((2*np.mean(Ctt_error_list))**2)*4.2/1000)) + + +# In[42]: + + +# plt.hist(tot_sam, bins = int((x_max-x_min)/7.)) + +# plt.show() + +# # _ = np.where((total_samp >= x_min) & (total_samp <= (jpsi_mass - 50.))) + +# tot_sam.shape + + +# In[43]: + + +# Ctt.floating = False + + +# In[44]: + + +# zfit.run(nll.value()) + + +# In[45]: + + +# result.fmin + + +# In[46]: + + +# BR_steps = np.linspace(0.0, 1e-3, 11) + + +# # CLS Code + +# In[47]: + + +# zfit.run.numeric_checks = False + +load = False + +bo5 = True + +bo5_set = 5 + +fitting_range = 'cut' +total_BR = 1.7e-10 + 4.9e-10 + 2.5e-9 + 6.02e-5 + 4.97e-6 + 1.38e-9 + 4.2e-10 + 2.6e-9 + 6.1e-10 + 4.37e-7 +cut_BR = 1.0 - (6.02e-5 + 4.97e-6)/total_BR + +Ctt_list = [] +Ctt_error_list = [] + +nr_of_toys = 1 +nevents = int(pdg["number_of_decays"]*cut_BR) +# nevents = pdg["number_of_decays"] +event_stack = 1000000 +# nevents *= 41 +# zfit.settings.set_verbosity(10) + +mi = 0.0 +ma = 1e-3 +ste = 11 + +BR_steps = np.linspace(mi, ma, ste) + +Ctt_steps = np.sqrt(BR_steps/4.2*1000) + +total_samp = [] + +start = time.time() + +Nll_list = [] + +sampler = total_f.create_sampler(n=nevents) + +__ = 0 + + +#----------------------------------------------------- + +if not load: + + for Ctt_step in Ctt_steps: + + __ += 1 + + newset = True + + for floaty in [True, False]: + + Ctt.floating = floaty + + Nll_list.append([]) + + if bo5: + + while len(Nll_list[-1])/bo5_set < nr_of_toys: + + print('Step: {0}/{1}'.format(__, ste)) + + print('Current Ctt: {0}'.format(Ctt_step)) + print('Ctt floating: {0}'.format(floaty)) + + print('Toy {0}/{1} - Fit {2}/{3}'.format(int(len(Nll_list[-1])/bo5_set), nr_of_toys, len(Nll_list[-1]), bo5_set)) + + reset_param_values() + + if floaty: + Ctt.set_value(Ctt_step) + else: + Ctt.set_value(0.0) + + if newset: + sampler.resample(n=nevents) + s = sampler.unstack_x() + total_samp = zfit.run(s) + calls = 0 + c = 1 + newset = False + + + data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit) + + ### Fit data + + for param in total_f_fit.get_dependents(): + param.randomize() + + nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + + minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) + # minimizer._use_tfgrad = False + result = minimizer.minimize(nll) + + # print("Function minimum:", result.fmin) + # print("Hesse errors:", result.hesse()) + + params = result.params + + if result.converged: + Nll_list[-1].append(result.fmin) + + else: + + while len(Nll_list[-1]) < nr_of_toys: + + print('Step: {0}/{1}'.format(__, ste)) + + print('Current Ctt: {0}'.format(Ctt_step)) + print('Ctt floating: {0}'.format(floaty)) + + print('Toy {0}/{1}'.format(len(Nll_list[-1]), nr_of_toys)) + + reset_param_values() + + if floaty: + Ctt.set_value(Ctt_step) + else: + Ctt.set_value(0.0) + + if floaty: + sampler.resample(n=nevents) + s = sampler.unstack_x() + total_samp = zfit.run(s) + calls = 0 + c = 1 + + + data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit) + + ### Fit data + + for param in total_f_fit.get_dependents(): + param.randomize() + + nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + + minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) + # minimizer._use_tfgrad = False + result = minimizer.minimize(nll) + + # print("Function minimum:", result.fmin) + # print("Hesse errors:", result.hesse()) + + params = result.params + + if result.converged: + Nll_list[-1].append(result.fmin) + + _t = int(time.time()-start) + + print('Time Taken: {}'.format(display_time(int(_t)))) + + print('Predicted time left: {}'.format(display_time(int((_t/(__+1)*(ste-__-1)))))) + + +# In[48]: + + +if load: + Nll_list = [] + CLs_values = [] + + _dir = 'data/CLs/finished/f1d1' + + jobs = os.listdir(_dir) + + for s in range(ste): + CLs_values.append([]) + + for s in range(2*ste): + Nll_list.append([]) + + for job in jobs: + if not os.path.exists("{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(_dir, job, mi,ma,ste)): + print(job) + continue + + with open(r"{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(_dir, job, mi,ma,ste), "rb") as input_file: + _Nll_list = pkl.load(input_file) + + if bo5: + for s in range(2*ste): + Nll_list[s].append(np.min(_Nll_list[s])) + else: + for s in range(2*ste): + Nll_list[s].extend(_Nll_list[s]) + + with open(r"{}/{}/data/CLs/{}-{}_{}s--CLs_list.pkl".format(_dir, job, mi,ma,ste), "rb") as input_file: + _CLs_values = pkl.load(input_file) + + for s in range(ste): + CLs_values[s].extend(_CLs_values[s]) + + print(np.shape(Nll_list)) + + +# In[50]: + + +dirName = 'data/CLs' + +# if bo5 and not load: +# for s in range(2*ste): +# Nll_list[s] = [np.min(Nll_list[s])] + +if bo5: + CLs_values= [] + for i in range(int(len(Nll_list)/2)): + CLs_values.append([]) + for j in range(len(Nll_list[0])): + CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j]) + + +if not load: + + CLs_values = [] + + for i in range(int(len(Nll_list)/2)): + CLs_values.append([]) + for j in range(nr_of_toys): + CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j]) + + if not os.path.exists(dirName): + os.mkdir(dirName) + print("Directory " , dirName , " Created ") + + with open("{}/{}-{}_{}s--CLs_Nll_list.pkl".format(dirName, mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + + with open("{}/{}-{}_{}s--CLs_list.pkl".format(dirName, mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +# print(CLs_values) +print(Nll_list) + + +# ## Plot + +# In[52]: + + +l = [] + +for i in range(len(CLs_values)): + plt.clf() + plt.title('Ctt value: {:.2f}'.format(Ctt_steps[i])) + plt.hist(CLs_values[0], bins = 100, label = 'Ctt fixed to 0') + plt.hist(CLs_values[i], bins = 100, label = 'Ctt floating') + plt.axvline(x=np.mean(CLs_values[0]),color='red', linewidth=0.7, linestyle = 'dotted') + plt.legend() + plt.savefig('data/CLs/plots/CLs-BR({:.1E}).png'.format(BR_steps[i])) + + l.append(len(np.where(np.array(CLs_values[i]) < np.mean(CLs_values[0]))[0])) + + +# In[53]: + + +for s in range(len(l)): + print('BR: {}'.format(BR_steps[s])) + print(2*l[s]/len(CLs_values[0])) + print() + + +# In[54]: + + +# print(np.array(Nll_list[0][:10])-np.array(Nll_list[1][:10])) + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2254891/test.png b/data/CLs/finished/f1d1/2254891/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2254891/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2254896/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2254896/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..30cf970 --- /dev/null +++ b/data/CLs/finished/f1d1/2254896/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2254896/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2254896/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..4d627a4 --- /dev/null +++ b/data/CLs/finished/f1d1/2254896/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2254896/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2254896/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..f1667f8 --- /dev/null +++ b/data/CLs/finished/f1d1/2254896/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2254896/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2254896/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..f517f52 --- /dev/null +++ b/data/CLs/finished/f1d1/2254896/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2254896/helperfunctions.py b/data/CLs/finished/f1d1/2254896/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2254896/helperfunctions.py @@ -0,0 +1,33 @@ +# some helperfunctions + +import matplotlib +matplotlib.use("agg") +import matplotlib.pyplot as plt + +#Dislpay time (e.g. while generating points) + +display_intervals = ( + ('w', 604800), # 60 * 60 * 24 * 7 + ('d', 86400), # 60 * 60 * 24 + ('h', 3600), # 60 * 60 + ('min', 60), + ('s', 1), + ) + +def display_time(seconds, granularity=2): + result = [] + + for name, count in display_intervals: + value = seconds // count + if value: + seconds -= value * count + if value == 1: + name = name.rstrip('s') + result.append("{} {}".format(value, name)) + return ', '.join(result[:granularity]) + +def prepare_plot(title): + plt.title(title) + plt.grid() + plt.legend(loc = 'best') + plt.xlabel("q") diff --git a/data/CLs/finished/f1d1/2254896/pdg_const.py b/data/CLs/finished/f1d1/2254896/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2254896/pdg_const.py @@ -0,0 +1,226 @@ +pdg = { + + + ###Particle masses### + + "mbstar" : 5415.4, + "mbstar0" : 5711.0, + "B0_M" : 5279.5, + "Bs_M" : 5366.7, + "Bplus_M" : 5279.3, + "Lb_M" : 5619.4, + "D0_M" : 1864.8, + "Dst_M" : 2010, + "pi_M" : 139.6, + "Jpsi_M" : 3096.9, + "Psi2s_M" : 3685.6, + "kaon_M" : 493.7, + "Ks_M" : 497.6, + "phi_M" : 1019.5, + "rho_M" : 775.26, + "rho_width" : 149.1, + "omega_M" : 782.65, + "omega_width" : 8.49, + + "muon_M" : 105.7, + "tau_M": 1776.86, + + "squark_M" : 95.0, + "bquark_M" : 4180.0, + "cquark_M" : 1275.0, + + "Bplus_tau" : 1.638e-12, + + ###Wilson coefficients### + + "C1" : -0.257, + "C2" : 1.009, + "C3" : -0.005, + "C4" : -0.078, + + "C7eff" : -0.306, + "C9eff" : 4.211, + "C10eff" : -4.103, + +# "C7eff": 0.0, +# "C9eff": 0.0, +# "C10eff": 0.0, + + ###Other constants + + "GF" : 1.1663787e-5, + "alpha_ew" : 1.0/137.0, + "Vts" : 0.0394, + "Vtb" : 1.019, + "number_of_decays": 5404696, + + #Formfactor z coefficients + + #"b0" : [0.285, 0.19, -0.17], + #"bplus" : [0.437, -1.41, -2.5], + #"bT" : [0.440, -1.47, -2.7] + + "b0" : [0.292, 0.281, 0.150], + "bplus" : [0.466, -0.885, -0.213], + "bT" : [0.460, -1.089, -1.114], + + "NR_BR": 4.37e-7, + "NR_auc": 0.00133, + + #Resonances format(mass, width, phase, scale) + + # pre scaling + +# "rho": (775.26, 149.0, -0.35, 1.0), + +# "omega": (782.7, 8.5, 0.26, 1.0), + +# "phi": (1019.46, 4.25, 0.5, 1.0), + +# "jpsi": (3096.0, 0.09, -1.5, 2e-2), +# "jpsi_auc": 0.2126825758464027, + +# "psi2s": (3686.0, 0.3, -1.5, 3.14e-3), +# "psi2s_auc": 2.802257483178487e-10, + +# "p3770": (3773.0, 27.2, -2.13, 1.0e-3), + +# "p4040": (4039.0, 80.0, -2.52, 2.0), + +# "p4160": (4191.0, 70.0, -1.9, 2.2), + +# "p4415": (4421.0, 62.0, -2.52, 1.0), + + + # after scaling (Phase combination --) + + +# "rho": (743.2, 149.0, -0.22, 1.05), + +# "omega": (782.7, 8.5, 0.38, 6.8), + +# "phi": (1013.5, 4.25, 0.62, 19.2), + +# "jpsi": (3096.1, 0.09, 1.63, 9897.0), +# "jpsi_auc": 0.2126825758464027, +# "jpsi_phase_unc": 0.05, + +# "psi2s": (3686.0, 0.3, 1.8, 1396.0), +# "psi2s_auc": 0.0151332263, +# "psi2s_phase_unc": 0.1, + +# "p3770": (3773.0, 27.2, -2.95, 2.5), + +# "p4040": (4039.0, 80.0, -2.75, 1.01), + +# "p4160": (4191.0, 70.0, -2.28, 2.2), + +# "p4415": (4421.0, 62.0, -2.31, 1.24), + + # Phase combination of paper ++ + +# "rho": (743.2, 149.0, -0.35, 1.05), + +# "omega": (782.7, 8.5, 0.26, 6.8), + +# "phi": (1013.5, 4.25, 0.47, 19.2), + +# "jpsi": (3096.1, 0.09, -1.66, 9897.0), +# "jpsi_auc": 0.2126825758464027, +# "jpsi_phase_unc": 0.05, + +# "psi2s": (3686.0, 0.3, -1.93, 1396.0), +# "psi2s_auc": 0.0151332263, +# "psi2s_phase_unc": 0.1, + +# "p3770": (3773.0, 27.2, -2.13, 2.5), + +# "p4040": (4039.0, 80.0, -2.52, 1.01), + +# "p4160": (4191.0, 70.0, -1.90, 2.2), + +# "p4415": (4421.0, 62.0, -2.52, 1.24), + + # Phase combination of paper +- + + # "rho": (743.2, 149.0, -0.26, 1.05), + # + # "omega": (782.7, 8.5, 0.35, 6.8), + # + # "phi": (1013.5, 4.25, 0.58, 19.2), + # + # "jpsi": (3096.1, 0.09, 1.47, 9897.0), + # "jpsi_auc": 0.2126825758464027, + # "jpsi_phase_unc": 0.05, + # + # "psi2s": (3686.0, 0.3, -2.21, 1396.0), + # "psi2s_auc": 0.0151332263, + # "psi2s_phase_unc": 0.1, + # + # "p3770": (3773.0, 27.2, -2.140, 2.5), + # + # "p4040": (4039.0, 80.0, -2.64, 1.01), + # + # "p4160": (4191.0, 70.0, -2.11, 2.2), + # + # "p4415": (4421.0, 62.0, -2.42, 1.24), + + # Phase combination of paper -+ + + "rho": (743.2, 149.0, -0.30, 1.05), + + "omega": (782.7, 8.5, 0.30, 6.8), + + "phi": (1013.5, 4.25, 0.51, 19.2), + + "jpsi": (3096.1, 0.09, -1.5, 9897.0), + "jpsi_auc": 0.2126825758464027, + "jpsi_phase_unc": 0.05, + + "psi2s": (3686.0, 0.3, 2.08, 1396.0), + "psi2s_auc": 0.0151332263, + "psi2s_phase_unc": 0.1, + + "p3770": (3773.0, 27.2, -2.89, 2.5), + + "p4040": (4039.0, 80.0, -2.69, 1.01), + + "p4160": (4191.0, 70.0, -2.13, 2.2), + + "p4415": (4421.0, 62.0, -2.43, 1.24), + + + # zeroing resonances + +# "rho": (775.26, 149.0, -0.35, 0.0), +# "omega": (782.7, 8.5, 0.26, 0.0), +# "phi": (1019.46, 4.25, 0.5, 0.0), +# "jpsi": (3096.0, 0.09, -1.5, 0.0), +# "psi2s": (3686.0, 0.3, -1.5, 0.0), +# "p3770": (3773.0, 27.2, -2.13, 0.0), +# "p4040": (4039.0, 80.0, -2.52, 0.0), +# "p4160": (4147.0, 22.0, -1.9, 0.0), +# "p4415": (4421.0, 62.0, -2.52, 0.0), + + # 2P contributions format(mass, amp, phase) + +# "D_bar": ( + + #general + + "rho_BR": 1.7e-10, + "omega_BR": 4.9e-10, + "phi_BR": 2.5e-9, + "jpsi_BR": 6.02e-5, + "psi2s_BR": 4.97e-6, + "p3770_BR": 1.38e-9, + "p4040_BR": 4.2e-10, + "p4160_BR": 2.6e-9, + "p4415_BR": 6.1e-10, + +# Estimates + "Dbar_scale": 1.46, #with phase = pi + + "DDstar_scale": 2.41, #with phase = pi + + } diff --git a/data/CLs/finished/f1d1/2254896/raremodel-nb1.py b/data/CLs/finished/f1d1/2254896/raremodel-nb1.py new file mode 100644 index 0000000..1a5d9be --- /dev/null +++ b/data/CLs/finished/f1d1/2254896/raremodel-nb1.py @@ -0,0 +1,1939 @@ +#!/usr/bin/env python +# coding: utf-8 + +# # Import + +# In[1]: + + +import os + +# os.environ["CUDA_VISIBLE_DEVICES"] = "-1" + +import numpy as np +from pdg_const import pdg +import matplotlib +import matplotlib.pyplot as plt +import pickle as pkl +import sys +import time +from helperfunctions import display_time, prepare_plot +import cmath as c +import scipy.integrate as integrate +from scipy.optimize import fminbound +from array import array as arr +import collections +from itertools import compress +import tensorflow as tf +import zfit +from zfit import ztf +# from IPython.display import clear_output +import os +import tensorflow_probability as tfp +tfd = tfp.distributions + + +# In[2]: + + +# chunksize = 10000 +# zfit.run.chunking.active = True +# zfit.run.chunking.max_n_points = chunksize + + +# # Build model and graphs +# ## Create graphs + +# In[ ]: + + + + + +# In[3]: + + +def formfactor(q2, subscript, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): #returns real value + #check if subscript is viable + + if subscript != "0" and subscript != "+" and subscript != "T": + raise ValueError('Wrong subscript entered, choose either 0, + or T') + + #get constants + + mK = ztf.constant(pdg['Ks_M']) + mbstar0 = ztf.constant(pdg["mbstar0"]) + mbstar = ztf.constant(pdg["mbstar"]) + + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mB = ztf.constant(pdg['Bplus_M']) + + #N comes from derivation in paper + + N = 3 + + #some helperfunctions + + tpos = (mB - mK)**2 + tzero = (mB + mK)*(ztf.sqrt(mB)-ztf.sqrt(mK))**2 + + z_oben = ztf.sqrt(tpos - q2) - ztf.sqrt(tpos - tzero) + z_unten = ztf.sqrt(tpos - q2) + ztf.sqrt(tpos - tzero) + z = tf.divide(z_oben, z_unten) + + #calculate f0 + + if subscript == "0": + prefactor = 1/(1 - q2/(mbstar0**2)) + _sum = 0 + b0 = [b0_0, b0_1, b0_2] + + for i in range(N): + _sum += b0[i]*(tf.pow(z,i)) + + return ztf.to_complex(prefactor * _sum) + + #calculate f+ or fT + + else: + prefactor = 1/(1 - q2/(mbstar**2)) + _sum = 0 + + if subscript == "T": + bT = [bT_0, bT_1, bT_2] + for i in range(N): + _sum += bT[i] * (tf.pow(z, i) - ((-1)**(i-N)) * (i/N) * tf.pow(z, N)) + else: + bplus = [bplus_0, bplus_1, bplus_2] + for i in range(N): + _sum += bplus[i] * (tf.pow(z, i) - ((-1)**(i-N)) * (i/N) * tf.pow(z, N)) + + return ztf.to_complex(prefactor * _sum) + +def resonance(q, _mass, width, phase, scale): + + q2 = tf.pow(q, 2) + + mmu = ztf.constant(pdg['muon_M']) + + p = 0.5 * ztf.sqrt(q2 - 4*(mmu**2)) + + p0 = 0.5 * ztf.sqrt(_mass**2 - 4*mmu**2) + + gamma_j = tf.divide(p, q) * _mass * width / p0 + + #Calculate the resonance + + _top = tf.complex(_mass * width, ztf.constant(0.0)) + + _bottom = tf.complex(_mass**2 - q2, -_mass*gamma_j) + + com = _top/_bottom + + #Rotate by the phase + + r = ztf.to_complex(scale*tf.abs(com)) + + _phase = tf.angle(com) + + _phase += phase + + com = r * tf.exp(tf.complex(ztf.constant(0.0), _phase)) + + return com + + +def axiv_nonres(q, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): + + GF = ztf.constant(pdg['GF']) + alpha_ew = ztf.constant(pdg['alpha_ew']) + Vtb = ztf.constant(pdg['Vtb']) + Vts = ztf.constant(pdg['Vts']) + C10eff = ztf.constant(pdg['C10eff']) + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mK = ztf.constant(pdg['Ks_M']) + mB = ztf.constant(pdg['Bplus_M']) + + q2 = tf.pow(q, 2) + + #Some helperfunctions + + beta = 1. - 4. * mmu**2. / q2 + + 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.) + + #prefactor in front of whole bracket + + prefactor1 = GF**2. *alpha_ew**2. * (tf.abs(Vtb*Vts))**2. * kabs * beta / (128. * np.pi**5.) + + #left term in bracket + + bracket_left = 2./3. * tf.pow(kabs,2) * tf.pow(beta,2) * tf.pow(tf.abs(ztf.to_complex(C10eff)*formfactor(q2, "+", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)),2) + + #middle term in bracket + + _top = 4. * mmu**2. * (mB**2. - mK**2.) * (mB**2. - mK**2.) + + _under = q2 * mB**2. + + bracket_middle = _top/_under *tf.pow(tf.abs(ztf.to_complex(C10eff) * formfactor(q2, "0", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)), 2) + + #Note sqrt(q2) comes from derivation as we use q2 and plot q + + return prefactor1 * (bracket_left + bracket_middle) * 2 * q + +def vec(q, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2): + + q2 = tf.pow(q, 2) + + GF = ztf.constant(pdg['GF']) + alpha_ew = ztf.constant(pdg['alpha_ew']) + Vtb = ztf.constant(pdg['Vtb']) + Vts = ztf.constant(pdg['Vts']) + C7eff = ztf.constant(pdg['C7eff']) + + mmu = ztf.constant(pdg['muon_M']) + mb = ztf.constant(pdg['bquark_M']) + ms = ztf.constant(pdg['squark_M']) + mK = ztf.constant(pdg['Ks_M']) + mB = ztf.constant(pdg['Bplus_M']) + + #Some helperfunctions + + beta = 1. - 4. * mmu**2. / q2 + + 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) + + #prefactor in front of whole bracket + + prefactor1 = GF**2. *alpha_ew**2. * (tf.abs(Vtb*Vts))**2 * kabs * beta / (128. * np.pi**5.) + + #right term in bracket + + prefactor2 = tf.pow(kabs,2) * (1. - 1./3. * beta) + + abs_bracket = tf.pow(tf.abs(c9eff(q, funcs) * formfactor(q2, "+", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + ztf.to_complex(2.0 * C7eff * (mb + ms)/(mB + mK)) * formfactor(q2, "T", b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2)),2) + + bracket_right = prefactor2 * abs_bracket + + #Note sqrt(q2) comes from derivation as we use q2 and plot q + + return prefactor1 * bracket_right * 2 * q + +def c9eff(q, funcs): + + C9eff_nr = ztf.to_complex(ztf.constant(pdg['C9eff'])) + + c9 = C9eff_nr + funcs + + return c9 + + +# In[4]: + + +def G(y): + + def inner_rect_bracket(q): + return tf.log(ztf.to_complex((1+tf.sqrt(q))/(1-tf.sqrt(q)))-tf.complex(ztf.constant(0), -1*ztf.constant(np.pi))) + + def inner_right(q): + return ztf.to_complex(2 * tf.atan(1/tf.sqrt(tf.math.real(-q)))) + + big_bracket = tf.where(tf.math.real(y) > ztf.constant(0.0), inner_rect_bracket(y), inner_right(y)) + + return ztf.to_complex(tf.sqrt(tf.abs(y))) * big_bracket + +def h_S(m, q): + + 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))) + +def h_P(m, q): + + 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) + +def two_p_ccbar(mD, m_D_bar, m_D_star, q): + + + #Load constants + nu_D_bar = ztf.to_complex(pdg["nu_D_bar"]) + nu_D = ztf.to_complex(pdg["nu_D"]) + nu_D_star = ztf.to_complex(pdg["nu_D_star"]) + + phase_D_bar = ztf.to_complex(pdg["phase_D_bar"]) + phase_D = ztf.to_complex(pdg["phase_D"]) + phase_D_star = ztf.to_complex(pdg["phase_D_star"]) + + #Calculation + left_part = nu_D_bar * tf.exp(tf.complex(ztf.constant(0.0), phase_D_bar)) * h_S(m_D_bar, q) + + right_part_D = nu_D * tf.exp(tf.complex(ztf.constant(0.0), phase_D)) * h_P(m_D, q) + + right_part_D_star = nu_D_star * tf.exp(tf.complex(ztf.constant(0.0), phase_D_star)) * h_P(m_D_star, q) + + return left_part + right_part_D + right_part_D_star + + +# ## Build pdf + +# In[5]: + + +class total_pdf_cut(zfit.pdf.ZPDF): + _N_OBS = 1 # dimension, can be omitted + _PARAMS = ['b0_0', 'b0_1', 'b0_2', + 'bplus_0', 'bplus_1', 'bplus_2', + 'bT_0', 'bT_1', 'bT_2', + 'rho_mass', 'rho_scale', 'rho_phase', 'rho_width', + 'jpsi_mass', 'jpsi_scale', 'jpsi_phase', 'jpsi_width', + 'psi2s_mass', 'psi2s_scale', 'psi2s_phase', 'psi2s_width', + 'p3770_mass', 'p3770_scale', 'p3770_phase', 'p3770_width', + 'p4040_mass', 'p4040_scale', 'p4040_phase', 'p4040_width', + 'p4160_mass', 'p4160_scale', 'p4160_phase', 'p4160_width', + 'p4415_mass', 'p4415_scale', 'p4415_phase', 'p4415_width', + 'omega_mass', 'omega_scale', 'omega_phase', 'omega_width', + 'phi_mass', 'phi_scale', 'phi_phase', 'phi_width', + 'Dbar_mass', 'Dbar_scale', 'Dbar_phase', + 'Dstar_mass', 'DDstar_scale', 'DDstar_phase', 'D_mass', + 'tau_mass', 'C_tt'] +# the name of the parameters + + def _unnormalized_pdf(self, x): + + x = x.unstack_x() + + b0 = [self.params['b0_0'], self.params['b0_1'], self.params['b0_2']] + bplus = [self.params['bplus_0'], self.params['bplus_1'], self.params['bplus_2']] + bT = [self.params['bT_0'], self.params['bT_1'], self.params['bT_2']] + + def rho_res(q): + return resonance(q, _mass = self.params['rho_mass'], scale = self.params['rho_scale'], + phase = self.params['rho_phase'], width = self.params['rho_width']) + + def omega_res(q): + return resonance(q, _mass = self.params['omega_mass'], scale = self.params['omega_scale'], + phase = self.params['omega_phase'], width = self.params['omega_width']) + + def phi_res(q): + return resonance(q, _mass = self.params['phi_mass'], scale = self.params['phi_scale'], + phase = self.params['phi_phase'], width = self.params['phi_width']) + + def jpsi_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['jpsi_mass'], 2)) * resonance(q, _mass = self.params['jpsi_mass'], + scale = self.params['jpsi_scale'], + phase = self.params['jpsi_phase'], + width = self.params['jpsi_width']) + def psi2s_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['psi2s_mass'], 2)) * resonance(q, _mass = self.params['psi2s_mass'], + scale = self.params['psi2s_scale'], + phase = self.params['psi2s_phase'], + width = self.params['psi2s_width']) + def p3770_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p3770_mass'], 2)) * resonance(q, _mass = self.params['p3770_mass'], + scale = self.params['p3770_scale'], + phase = self.params['p3770_phase'], + width = self.params['p3770_width']) + + def p4040_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4040_mass'], 2)) * resonance(q, _mass = self.params['p4040_mass'], + scale = self.params['p4040_scale'], + phase = self.params['p4040_phase'], + width = self.params['p4040_width']) + + def p4160_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4160_mass'], 2)) * resonance(q, _mass = self.params['p4160_mass'], + scale = self.params['p4160_scale'], + phase = self.params['p4160_phase'], + width = self.params['p4160_width']) + + def p4415_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4415_mass'], 2)) * resonance(q, _mass = self.params['p4415_mass'], + scale = self.params['p4415_scale'], + phase = self.params['p4415_phase'], + width = self.params['p4415_width']) + + def P2_D(q): + 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)) + 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['Dstar_mass'], q)) + ztf.to_complex(h_P(self.params['D_mass'], q))) + return Dbar_contrib + DDstar_contrib + + def ttau_cusp(q): + 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))) + + + 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) + + vec_f = vec(x, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + axiv_nr = axiv_nonres(x, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + tot = vec_f + axiv_nr + + #Cut out jpsi and psi2s + + tot = tf.where(tf.math.logical_or(x < ztf.constant(jpsi_mass-60.), x > ztf.constant(jpsi_mass+70.)), tot, 0.0*tot) + + tot = tf.where(tf.math.logical_or(x < ztf.constant(psi2s_mass-50.), x > ztf.constant(psi2s_mass+50.)), tot, 0.0*tot) + + return tot + +class total_pdf_full(zfit.pdf.ZPDF): + _N_OBS = 1 # dimension, can be omitted + _PARAMS = ['b0_0', 'b0_1', 'b0_2', + 'bplus_0', 'bplus_1', 'bplus_2', + 'bT_0', 'bT_1', 'bT_2', + 'rho_mass', 'rho_scale', 'rho_phase', 'rho_width', + 'jpsi_mass', 'jpsi_scale', 'jpsi_phase', 'jpsi_width', + 'psi2s_mass', 'psi2s_scale', 'psi2s_phase', 'psi2s_width', + 'p3770_mass', 'p3770_scale', 'p3770_phase', 'p3770_width', + 'p4040_mass', 'p4040_scale', 'p4040_phase', 'p4040_width', + 'p4160_mass', 'p4160_scale', 'p4160_phase', 'p4160_width', + 'p4415_mass', 'p4415_scale', 'p4415_phase', 'p4415_width', + 'omega_mass', 'omega_scale', 'omega_phase', 'omega_width', + 'phi_mass', 'phi_scale', 'phi_phase', 'phi_width', + 'Dbar_mass', 'Dbar_scale', 'Dbar_phase', + 'Dstar_mass', 'DDstar_scale', 'DDstar_phase', 'D_mass', + 'tau_mass', 'C_tt'] +# the name of the parameters + + def _unnormalized_pdf(self, x): + + x = x.unstack_x() + + b0 = [self.params['b0_0'], self.params['b0_1'], self.params['b0_2']] + bplus = [self.params['bplus_0'], self.params['bplus_1'], self.params['bplus_2']] + bT = [self.params['bT_0'], self.params['bT_1'], self.params['bT_2']] + + def rho_res(q): + return resonance(q, _mass = self.params['rho_mass'], scale = self.params['rho_scale'], + phase = self.params['rho_phase'], width = self.params['rho_width']) + + def omega_res(q): + return resonance(q, _mass = self.params['omega_mass'], scale = self.params['omega_scale'], + phase = self.params['omega_phase'], width = self.params['omega_width']) + + def phi_res(q): + return resonance(q, _mass = self.params['phi_mass'], scale = self.params['phi_scale'], + phase = self.params['phi_phase'], width = self.params['phi_width']) + + def jpsi_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['jpsi_mass'], 2)) * resonance(q, _mass = self.params['jpsi_mass'], + scale = self.params['jpsi_scale'], + phase = self.params['jpsi_phase'], + width = self.params['jpsi_width']) + def psi2s_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['psi2s_mass'], 2)) * resonance(q, _mass = self.params['psi2s_mass'], + scale = self.params['psi2s_scale'], + phase = self.params['psi2s_phase'], + width = self.params['psi2s_width']) + def p3770_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p3770_mass'], 2)) * resonance(q, _mass = self.params['p3770_mass'], + scale = self.params['p3770_scale'], + phase = self.params['p3770_phase'], + width = self.params['p3770_width']) + + def p4040_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4040_mass'], 2)) * resonance(q, _mass = self.params['p4040_mass'], + scale = self.params['p4040_scale'], + phase = self.params['p4040_phase'], + width = self.params['p4040_width']) + + def p4160_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4160_mass'], 2)) * resonance(q, _mass = self.params['p4160_mass'], + scale = self.params['p4160_scale'], + phase = self.params['p4160_phase'], + width = self.params['p4160_width']) + + def p4415_res(q): + return ztf.to_complex(tf.pow(q, 2) / tf.pow(self.params['p4415_mass'], 2)) * resonance(q, _mass = self.params['p4415_mass'], + scale = self.params['p4415_scale'], + phase = self.params['p4415_phase'], + width = self.params['p4415_width']) + + def P2_D(q): + 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)) + 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['Dstar_mass'], q)) + ztf.to_complex(h_P(self.params['D_mass'], q))) + return Dbar_contrib + DDstar_contrib + + def ttau_cusp(q): + 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))) + + + 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) + + vec_f = vec(x, funcs, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + axiv_nr = axiv_nonres(x, b0_0, b0_1, b0_2, bplus_0, bplus_1, bplus_2, bT_0, bT_1, bT_2) + + tot = vec_f + axiv_nr + + #Cut out jpsi and psi2s + +# tot = tf.where(tf.math.logical_or(x < ztf.constant(jpsi_mass-60.), x > ztf.constant(jpsi_mass+70.)), tot, 0.0*tot) + +# tot = tf.where(tf.math.logical_or(x < ztf.constant(psi2s_mass-50.), x > ztf.constant(psi2s_mass+50.)), tot, 0.0*tot) + + return tot + + +# ## Setup parameters + +# In[6]: + + +# formfactors + +b0_0 = zfit.Parameter("b0_0", ztf.constant(0.292), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +b0_1 = zfit.Parameter("b0_1", ztf.constant(0.281), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +b0_2 = zfit.Parameter("b0_2", ztf.constant(0.150), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) + +bplus_0 = zfit.Parameter("bplus_0", ztf.constant(0.466), lower_limit = -2.0, upper_limit= 2.0) +bplus_1 = zfit.Parameter("bplus_1", ztf.constant(-0.885), lower_limit = -2.0, upper_limit= 2.0) +bplus_2 = zfit.Parameter("bplus_2", ztf.constant(-0.213), lower_limit = -2.0, upper_limit= 2.0) + +bT_0 = zfit.Parameter("bT_0", ztf.constant(0.460), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +bT_1 = zfit.Parameter("bT_1", ztf.constant(-1.089), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) +bT_2 = zfit.Parameter("bT_2", ztf.constant(-1.114), floating = False) #, lower_limit = -2.0, upper_limit= 2.0) + + +#rho + +rho_mass, rho_width, rho_phase, rho_scale = pdg["rho"] + +rho_m = zfit.Parameter("rho_m", ztf.constant(rho_mass), floating = False) #lower_limit = rho_mass - rho_width, upper_limit = rho_mass + rho_width) +rho_w = zfit.Parameter("rho_w", ztf.constant(rho_width), floating = False) +rho_p = zfit.Parameter("rho_p", ztf.constant(rho_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +rho_s = zfit.Parameter("rho_s", ztf.constant(rho_scale), lower_limit=rho_scale-np.sqrt(rho_scale), upper_limit=rho_scale+np.sqrt(rho_scale)) + +#omega + +omega_mass, omega_width, omega_phase, omega_scale = pdg["omega"] + +omega_m = zfit.Parameter("omega_m", ztf.constant(omega_mass), floating = False) +omega_w = zfit.Parameter("omega_w", ztf.constant(omega_width), floating = False) +omega_p = zfit.Parameter("omega_p", ztf.constant(omega_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +omega_s = zfit.Parameter("omega_s", ztf.constant(omega_scale), lower_limit=omega_scale-np.sqrt(omega_scale), upper_limit=omega_scale+np.sqrt(omega_scale)) + + +#phi + +phi_mass, phi_width, phi_phase, phi_scale = pdg["phi"] + +phi_m = zfit.Parameter("phi_m", ztf.constant(phi_mass), floating = False) +phi_w = zfit.Parameter("phi_w", ztf.constant(phi_width), floating = False) +phi_p = zfit.Parameter("phi_p", ztf.constant(phi_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +phi_s = zfit.Parameter("phi_s", ztf.constant(phi_scale), lower_limit=phi_scale-np.sqrt(phi_scale), upper_limit=phi_scale+np.sqrt(phi_scale)) + +#jpsi + +jpsi_mass, jpsi_width, jpsi_phase, jpsi_scale = pdg["jpsi"] + +jpsi_m = zfit.Parameter("jpsi_m", ztf.constant(jpsi_mass), floating = False) +jpsi_w = zfit.Parameter("jpsi_w", ztf.constant(jpsi_width), floating = False) +jpsi_p = zfit.Parameter("jpsi_p", ztf.constant(jpsi_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +jpsi_s = zfit.Parameter("jpsi_s", ztf.constant(jpsi_scale), floating = False) #, lower_limit=jpsi_scale-np.sqrt(jpsi_scale), upper_limit=jpsi_scale+np.sqrt(jpsi_scale)) + +#psi2s + +psi2s_mass, psi2s_width, psi2s_phase, psi2s_scale = pdg["psi2s"] + +psi2s_m = zfit.Parameter("psi2s_m", ztf.constant(psi2s_mass), floating = False) +psi2s_w = zfit.Parameter("psi2s_w", ztf.constant(psi2s_width), floating = False) +psi2s_p = zfit.Parameter("psi2s_p", ztf.constant(psi2s_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +psi2s_s = zfit.Parameter("psi2s_s", ztf.constant(psi2s_scale), floating = False) #, lower_limit=psi2s_scale-np.sqrt(psi2s_scale), upper_limit=psi2s_scale+np.sqrt(psi2s_scale)) + +#psi(3770) + +p3770_mass, p3770_width, p3770_phase, p3770_scale = pdg["p3770"] + +p3770_m = zfit.Parameter("p3770_m", ztf.constant(p3770_mass), floating = False) +p3770_w = zfit.Parameter("p3770_w", ztf.constant(p3770_width), floating = False) +p3770_p = zfit.Parameter("p3770_p", ztf.constant(p3770_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p3770_s = zfit.Parameter("p3770_s", ztf.constant(p3770_scale), lower_limit=p3770_scale-np.sqrt(p3770_scale), upper_limit=p3770_scale+np.sqrt(p3770_scale)) + +#psi(4040) + +p4040_mass, p4040_width, p4040_phase, p4040_scale = pdg["p4040"] + +p4040_m = zfit.Parameter("p4040_m", ztf.constant(p4040_mass), floating = False) +p4040_w = zfit.Parameter("p4040_w", ztf.constant(p4040_width), floating = False) +p4040_p = zfit.Parameter("p4040_p", ztf.constant(p4040_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4040_s = zfit.Parameter("p4040_s", ztf.constant(p4040_scale), lower_limit=p4040_scale-np.sqrt(p4040_scale), upper_limit=p4040_scale+np.sqrt(p4040_scale)) + +#psi(4160) + +p4160_mass, p4160_width, p4160_phase, p4160_scale = pdg["p4160"] + +p4160_m = zfit.Parameter("p4160_m", ztf.constant(p4160_mass), floating = False) +p4160_w = zfit.Parameter("p4160_w", ztf.constant(p4160_width), floating = False) +p4160_p = zfit.Parameter("p4160_p", ztf.constant(p4160_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4160_s = zfit.Parameter("p4160_s", ztf.constant(p4160_scale), lower_limit=p4160_scale-np.sqrt(p4160_scale), upper_limit=p4160_scale+np.sqrt(p4160_scale)) + +#psi(4415) + +p4415_mass, p4415_width, p4415_phase, p4415_scale = pdg["p4415"] + +p4415_m = zfit.Parameter("p4415_m", ztf.constant(p4415_mass), floating = False) +p4415_w = zfit.Parameter("p4415_w", ztf.constant(p4415_width), floating = False) +p4415_p = zfit.Parameter("p4415_p", ztf.constant(p4415_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi) +p4415_s = zfit.Parameter("p4415_s", ztf.constant(p4415_scale), lower_limit=p4415_scale-np.sqrt(p4415_scale), upper_limit=p4415_scale+np.sqrt(p4415_scale)) + + +# ## Dynamic generation of 2 particle contribution + +# In[7]: + + +m_c = 1300 + +Dbar_phase = 0.0 +DDstar_phase = 0.0 +Dstar_mass = pdg['Dst_M'] +Dbar_mass = pdg['D0_M'] +D_mass = pdg['D0_M'] + +Dbar_s = zfit.Parameter("Dbar_s", ztf.constant(0.0), lower_limit=-0.3, upper_limit=0.3) +Dbar_m = zfit.Parameter("Dbar_m", ztf.constant(Dbar_mass), floating = False) +Dbar_p = zfit.Parameter("Dbar_p", ztf.constant(Dbar_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi)#, floating = False) +DDstar_s = zfit.Parameter("DDstar_s", ztf.constant(0.0), lower_limit=-0.3, upper_limit=0.3)#, floating = False) +Dstar_m = zfit.Parameter("Dstar_m", ztf.constant(Dstar_mass), floating = False) +D_m = zfit.Parameter("D_m", ztf.constant(D_mass), floating = False) +DDstar_p = zfit.Parameter("DDstar_p", ztf.constant(DDstar_phase), lower_limit=-2*np.pi, upper_limit=2*np.pi)#, floating = False) + + +# ## Tau parameters + +# In[8]: + + +tau_m = zfit.Parameter("tau_m", ztf.constant(pdg['tau_M']), floating = False) +Ctt = zfit.Parameter("Ctt", ztf.constant(0.0), lower_limit=-1.5, upper_limit=1.5) + + +# ## Load data + +# In[9]: + + +x_min = 2*pdg['muon_M'] +x_max = (pdg["Bplus_M"]-pdg["Ks_M"]-0.1) + +# # Full spectrum + +obs_toy = zfit.Space('q', limits = (x_min, x_max)) + +# Jpsi and Psi2s cut out + +obs1 = zfit.Space('q', limits = (x_min, jpsi_mass - 60.)) +obs2 = zfit.Space('q', limits = (jpsi_mass + 70., psi2s_mass - 50.)) +obs3 = zfit.Space('q', limits = (psi2s_mass + 50., x_max)) + +obs_fit = obs1 + obs2 + obs3 + +# 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: +# part_set = pkl.load(input_file) + +# x_part = part_set['x_part'] + +# x_part = x_part.astype('float64') + +# data = zfit.data.Data.from_numpy(array=x_part, obs=obs) + + +# ## Setup pdf + +# In[10]: + + +total_f = total_pdf_cut(obs=obs_toy, jpsi_mass = jpsi_m, jpsi_scale = jpsi_s, jpsi_phase = jpsi_p, jpsi_width = jpsi_w, + psi2s_mass = psi2s_m, psi2s_scale = psi2s_s, psi2s_phase = psi2s_p, psi2s_width = psi2s_w, + p3770_mass = p3770_m, p3770_scale = p3770_s, p3770_phase = p3770_p, p3770_width = p3770_w, + p4040_mass = p4040_m, p4040_scale = p4040_s, p4040_phase = p4040_p, p4040_width = p4040_w, + p4160_mass = p4160_m, p4160_scale = p4160_s, p4160_phase = p4160_p, p4160_width = p4160_w, + p4415_mass = p4415_m, p4415_scale = p4415_s, p4415_phase = p4415_p, p4415_width = p4415_w, + rho_mass = rho_m, rho_scale = rho_s, rho_phase = rho_p, rho_width = rho_w, + omega_mass = omega_m, omega_scale = omega_s, omega_phase = omega_p, omega_width = omega_w, + phi_mass = phi_m, phi_scale = phi_s, phi_phase = phi_p, phi_width = phi_w, + Dstar_mass = Dstar_m, DDstar_scale = DDstar_s, DDstar_phase = DDstar_p, D_mass = D_m, + Dbar_mass = Dbar_m, Dbar_scale = Dbar_s, Dbar_phase = Dbar_p, + tau_mass = tau_m, C_tt = Ctt, b0_0 = b0_0, b0_1 = b0_1, b0_2 = b0_2, + bplus_0 = bplus_0, bplus_1 = bplus_1, bplus_2 = bplus_2, + bT_0 = bT_0, bT_1 = bT_1, bT_2 = bT_2) + +total_f_fit = total_pdf_full(obs=obs_fit, jpsi_mass = jpsi_m, jpsi_scale = jpsi_s, jpsi_phase = jpsi_p, jpsi_width = jpsi_w, + psi2s_mass = psi2s_m, psi2s_scale = psi2s_s, psi2s_phase = psi2s_p, psi2s_width = psi2s_w, + p3770_mass = p3770_m, p3770_scale = p3770_s, p3770_phase = p3770_p, p3770_width = p3770_w, + p4040_mass = p4040_m, p4040_scale = p4040_s, p4040_phase = p4040_p, p4040_width = p4040_w, + p4160_mass = p4160_m, p4160_scale = p4160_s, p4160_phase = p4160_p, p4160_width = p4160_w, + p4415_mass = p4415_m, p4415_scale = p4415_s, p4415_phase = p4415_p, p4415_width = p4415_w, + rho_mass = rho_m, rho_scale = rho_s, rho_phase = rho_p, rho_width = rho_w, + omega_mass = omega_m, omega_scale = omega_s, omega_phase = omega_p, omega_width = omega_w, + phi_mass = phi_m, phi_scale = phi_s, phi_phase = phi_p, phi_width = phi_w, + Dstar_mass = Dstar_m, DDstar_scale = DDstar_s, DDstar_phase = DDstar_p, D_mass = D_m, + Dbar_mass = Dbar_m, Dbar_scale = Dbar_s, Dbar_phase = Dbar_p, + tau_mass = tau_m, C_tt = Ctt, b0_0 = b0_0, b0_1 = b0_1, b0_2 = b0_2, + bplus_0 = bplus_0, bplus_1 = bplus_1, bplus_2 = bplus_2, + bT_0 = bT_0, bT_1 = bT_1, bT_2 = bT_2) + +# print(total_pdf.obs) + +# print(calcs_test) + +# for param in total_f.get_dependents(): +# print(zfit.run(param)) + + +# In[11]: + + +total_f_fit.normalization(obs_toy) + + +# ## Test if graphs actually work and compute values + +# In[12]: + + +# def total_test_tf(xq): + +# def jpsi_res(q): +# return resonance(q, jpsi_m, jpsi_s, jpsi_p, jpsi_w) + +# def psi2s_res(q): +# return resonance(q, psi2s_m, psi2s_s, psi2s_p, psi2s_w) + +# def cusp(q): +# return bifur_gauss(q, cusp_m, sig_L, sig_R, cusp_s) + +# funcs = jpsi_res(xq) + psi2s_res(xq) + cusp(xq) + +# vec_f = vec(xq, funcs) + +# axiv_nr = axiv_nonres(xq) + +# tot = vec_f + axiv_nr + +# return tot + +# def jpsi_res(q): +# return resonance(q, jpsi_m, jpsi_s, jpsi_p, jpsi_w) + +# calcs = zfit.run(total_test_tf(x_part)) + +test_q = np.linspace(x_min, x_max, int(2e6)) + +probs = total_f_fit.pdf(test_q, norm_range=False) + +calcs_test = zfit.run(probs) +# res_y = zfit.run(jpsi_res(test_q)) +# b0 = [b0_0, b0_1, b0_2] +# bplus = [bplus_0, bplus_1, bplus_2] +# bT = [bT_0, bT_1, bT_2] +# f0_y = zfit.run(tf.math.real(formfactor(test_q,"0", b0, bplus, bT))) +# fplus_y = zfit.run(tf.math.real(formfactor(test_q,"+", b0, bplus, bT))) +# fT_y = zfit.run(tf.math.real(formfactor(test_q,"T", b0, bplus, bT))) + + +# In[13]: + + +plt.clf() +# plt.plot(x_part, calcs, '.') +plt.plot(test_q, calcs_test, label = 'pdf') +# plt.plot(test_q, f0_y, label = '0') +# plt.plot(test_q, fT_y, label = 'T') +# plt.plot(test_q, fplus_y, label = '+') +# plt.plot(test_q, res_y, label = 'res') +plt.legend() +plt.ylim(0.0, 1.5e-6) +# plt.yscale('log') +# plt.xlim(770, 785) +plt.savefig('test.png') +# print(jpsi_width) + + +# In[14]: + + + + +# probs = mixture.prob(test_q) +# probs_np = zfit.run(probs) +# probs_np *= np.max(calcs_test) / np.max(probs_np) +# plt.figure() +# plt.semilogy(test_q, probs_np,label="importance sampling") +# plt.semilogy(test_q, calcs_test, label = 'pdf') + + +# In[15]: + + +# 0.213/(0.00133+0.213+0.015) + + +# ## Adjust scaling of different parts + +# In[16]: + + +total_f.update_integration_options(draws_per_dim=2000000, mc_sampler=None) +# inte = total_f.integrate(limits = (950., 1050.), norm_range=False) +# inte_fl = zfit.run(inte) +# print(inte_fl/4500) +# print(pdg["jpsi_BR"]/pdg["NR_BR"], inte_fl*pdg["psi2s_auc"]/pdg["NR_auc"]) + + +# In[17]: + + +# # print("jpsi:", inte_fl) +# # print("Increase am by factor:", np.sqrt(pdg["jpsi_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# # print("New amp:", pdg["jpsi"][3]*np.sqrt(pdg["jpsi_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + +# # print("psi2s:", inte_fl) +# # print("Increase am by factor:", np.sqrt(pdg["psi2s_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# # print("New amp:", pdg["psi2s"][3]*np.sqrt(pdg["psi2s_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + +# name = "phi" + +# print(name+":", inte_fl) +# print("Increase am by factor:", np.sqrt(pdg[name+"_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) +# print("New amp:", pdg[name][0]*np.sqrt(pdg[name+"_BR"]/pdg["NR_BR"]*pdg["NR_auc"]/inte_fl)) + + +# print(x_min) +# print(x_max) +# # total_f.update_integration_options(draws_per_dim=2000000, mc_sampler=None) +# total_f.update_integration_options(mc_sampler=lambda dim, num_results, +# dtype: tf.random_uniform(maxval=1., shape=(num_results, dim), dtype=dtype), +# draws_per_dim=1000000) +# # _ = [] + +# # for i in range(10): + +# # inte = total_f.integrate(limits = (x_min, x_max)) +# # inte_fl = zfit.run(inte) +# # print(inte_fl) +# # _.append(inte_fl) + +# # print("mean:", np.mean(_)) + +# _ = time.time() + +# inte = total_f.integrate(limits = (x_min, x_max)) +# inte_fl = zfit.run(inte) +# print(inte_fl) +# print("Time taken: {}".format(display_time(int(time.time() - _)))) + +# print(pdg['NR_BR']/pdg['NR_auc']*inte_fl) +# print(0.25**2*4.2/1000) + + +# # Sampling +# ## Mixture distribution for sampling + +# In[18]: + + + + +# print(list_of_borders[:9]) +# print(list_of_borders[-9:]) + + +class UniformSampleAndWeights(zfit.util.execution.SessionHolderMixin): + def __call__(self, limits, dtype, n_to_produce): + # n_to_produce = tf.cast(n_to_produce, dtype=tf.int32) + low, high = limits.limit1d + low = tf.cast(low, dtype=dtype) + high = tf.cast(high, dtype=dtype) +# uniform = tfd.Uniform(low=low, high=high) +# uniformjpsi = tfd.Uniform(low=tf.constant(3080, dtype=dtype), high=tf.constant(3112, dtype=dtype)) +# uniformpsi2s = tfd.Uniform(low=tf.constant(3670, dtype=dtype), high=tf.constant(3702, dtype=dtype)) + +# list_of_borders = [] +# _p = [] +# splits = 10 + +# _ = np.linspace(x_min, x_max, splits) + +# for i in range(splits): +# list_of_borders.append(tf.constant(_[i], dtype=dtype)) +# _p.append(tf.constant(1/splits, dtype=dtype)) + +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=_p[:(splits-1)]), +# components_distribution=tfd.Uniform(low=list_of_borders[:(splits-1)], +# high=list_of_borders[-(splits-1):])) + mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.05, dtype=dtype), + tf.constant(0.93, dtype=dtype), + tf.constant(0.05, dtype=dtype), + tf.constant(0.065, dtype=dtype), + tf.constant(0.04, dtype=dtype), + tf.constant(0.05, dtype=dtype)]), + components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), + tf.constant(3090, dtype=dtype), + tf.constant(3681, dtype=dtype), + tf.constant(3070, dtype=dtype), + tf.constant(1000, dtype=dtype), + tf.constant(3660, dtype=dtype)], + high=[tf.constant(x_max, dtype=dtype), + tf.constant(3102, dtype=dtype), + tf.constant(3691, dtype=dtype), + tf.constant(3110, dtype=dtype), + tf.constant(1040, dtype=dtype), + tf.constant(3710, dtype=dtype)])) +# dtype = tf.float64 +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.04, dtype=dtype), +# tf.constant(0.90, dtype=dtype), +# tf.constant(0.02, dtype=dtype), +# tf.constant(0.07, dtype=dtype), +# tf.constant(0.02, dtype=dtype)]), +# components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), +# tf.constant(3089, dtype=dtype), +# tf.constant(3103, dtype=dtype), +# tf.constant(3681, dtype=dtype), +# tf.constant(3691, dtype=dtype)], +# high=[tf.constant(3089, dtype=dtype), +# tf.constant(3103, dtype=dtype), +# tf.constant(3681, dtype=dtype), +# tf.constant(3691, dtype=dtype), +# tf.constant(x_max, dtype=dtype)])) +# mixture = tfd.Uniform(tf.constant(x_min, dtype=dtype), tf.constant(x_max, dtype=dtype)) +# sample = tf.random.uniform((n_to_produce, 1), dtype=dtype) + sample = mixture.sample((n_to_produce, 1)) +# sample = tf.random.uniform((n_to_produce, 1), dtype=dtype) + weights = mixture.prob(sample)[:,0] +# weights = tf.broadcast_to(tf.constant(1., dtype=dtype), shape=(n_to_produce,)) + # sample = tf.expand_dims(sample, axis=-1) +# print(sample, weights) + +# weights = tf.ones(shape=(n_to_produce,), dtype=dtype) + weights_max = None + thresholds = tf.random_uniform(shape=(n_to_produce,), dtype=dtype) + return sample, thresholds, weights, weights_max, n_to_produce + + +# In[19]: + + +# total_f._sample_and_weights = UniformSampleAndWeights + + +# In[20]: + + +# 0.00133/(0.00133+0.213+0.015)*(x_max-3750)/(x_max-x_min) + + +# In[21]: + + +# zfit.settings.set_verbosity(10) + + +# In[22]: + + +# # zfit.run.numeric_checks = False + +# nr_of_toys = 1 +# nevents = int(pdg["number_of_decays"]) +# nevents = pdg["number_of_decays"] +# event_stack = 1000000 +# # zfit.settings.set_verbosity(10) +# calls = int(nevents/event_stack + 1) + +# total_samp = [] + +# start = time.time() + +# sampler = total_f.create_sampler(n=event_stack) + +# for toy in range(nr_of_toys): + +# dirName = 'data/zfit_toys/toy_{0}'.format(toy) + +# if not os.path.exists(dirName): +# os.mkdir(dirName) +# print("Directory " , dirName , " Created ") + +# for call in range(calls): + +# sampler.resample(n=event_stack) +# s = sampler.unstack_x() +# sam = zfit.run(s) +# # clear_output(wait=True) + +# c = call + 1 + +# print("{0}/{1} of Toy {2}/{3}".format(c, calls, toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(c+calls*(toy))*((nr_of_toys-toy)*calls-c))))) + +# with open("data/zfit_toys/toy_{0}/{1}.pkl".format(toy, call), "wb") as f: +# pkl.dump(sam, f, pkl.HIGHEST_PROTOCOL) + + +# In[23]: + + +# with open(r"data/zfit_toys/toy_0/0.pkl", "rb") as input_file: +# sam = pkl.load(input_file) +# print(sam[:10]) + +# with open(r"data/zfit_toys/toy_0/1.pkl", "rb") as input_file: +# sam2 = pkl.load(input_file) +# print(sam2[:10]) + +# print(np.sum(sam-sam2)) + + +# In[24]: + + +# print("Time to generate full toy: {} s".format(int(time.time()-start))) + +# total_samp = [] + +# for call in range(calls): +# with open(r"data/zfit_toys/toy_0/{}.pkl".format(call), "rb") as input_file: +# sam = pkl.load(input_file) +# total_samp = np.append(total_samp, sam) + +# total_samp = total_samp.astype('float64') + +# data2 = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs) + +# data3 = zfit.data.Data.from_numpy(array=total_samp, obs=obs) + +# print(total_samp[:nevents].shape) + + +# In[25]: + + +# plt.clf() + +# bins = int((x_max-x_min)/7) + +# # calcs = zfit.run(total_test_tf(samp)) +# print(total_samp[:nevents].shape) + +# plt.hist(total_samp[:nevents], bins = bins, range = (x_min,x_max), label = 'data') +# # plt.plot(test_q, calcs_test*nevents , label = 'pdf') + +# # plt.plot(sam, calcs, '.') +# # plt.plot(test_q, calcs_test) +# # plt.yscale('log') +# plt.ylim(0, 200) +# # plt.xlim(3080, 3110) + +# plt.legend() + +# plt.savefig('test2.png') + + +# In[26]: + + +# sampler = total_f.create_sampler(n=nevents) +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=sampler, fit_range = (x_min, x_max)) + +# # for param in pdf.get_dependents(): +# # param.set_value(initial_value) + +# sampler.resample(n=nevents) + +# # Randomise initial values +# # for param in pdf.get_dependents(): +# # param.set_value(random value here) + +# # Minimise the NLL +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 10) +# minimum = minimizer.minimize(nll) + + +# In[27]: + + +# jpsi_width + + +# In[28]: + + +# plt.hist(sample, weights=1 / prob(sample)) + + +# # Fitting + +# In[29]: + + +# start = time.time() + +# for param in total_f.get_dependents(): +# param.randomize() + +# # for param in total_f.get_dependents(): +# # print(zfit.run(param)) + +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=data2, fit_range = (x_min, x_max)) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# # param_errors = result.error() + +# # for var, errors in param_errors.items(): +# # print('{}: ^{{+{}}}_{{{}}}'.format(var.name, errors['upper'], errors['lower'])) + +# print("Function minimum:", result.fmin) +# # print("Results:", result.params) +# print("Hesse errors:", result.hesse()) + + +# In[30]: + + +# print("Time taken for fitting: {}".format(display_time(int(time.time()-start)))) + +# # probs = total_f.pdf(test_q) + +# calcs_test = zfit.run(probs) +# res_y = zfit.run(jpsi_res(test_q)) + + +# In[31]: + + +# plt.clf() +# # plt.plot(x_part, calcs, '.') +# plt.plot(test_q, calcs_test, label = 'pdf') +# # plt.plot(test_q, res_y, label = 'res') +# plt.legend() +# plt.ylim(0.0, 10e-6) +# # plt.yscale('log') +# # plt.xlim(3080, 3110) +# plt.savefig('test3.png') +# # print(jpsi_width) + + +# In[32]: + + +# _tot = 4.37e-7+6.02e-5+4.97e-6 +# _probs = [] +# _probs.append(6.02e-5/_tot) +# _probs.append(4.97e-6/_tot) +# _probs.append(4.37e-7/_tot) +# print(_probs) + + +# In[33]: + + +# dtype = 'float64' +# # mixture = tfd.Uniform(tf.constant(x_min, dtype=dtype), tf.constant(x_max, dtype=dtype)) +# mixture = tfd.MixtureSameFamily(mixture_distribution=tfd.Categorical(probs=[tf.constant(0.007, dtype=dtype), +# tf.constant(0.917, dtype=dtype), +# tf.constant(0.076, dtype=dtype)]), +# components_distribution=tfd.Uniform(low=[tf.constant(x_min, dtype=dtype), +# tf.constant(3080, dtype=dtype), +# tf.constant(3670, dtype=dtype)], +# high=[tf.constant(x_max, dtype=dtype), +# tf.constant(3112, dtype=dtype), +# tf.constant(3702, dtype=dtype)])) +# # for i in range(10): +# # print(zfit.run(mixture.prob(mixture.sample((10, 1))))) + + +# In[34]: + + +# print((zfit.run(jpsi_p)%(2*np.pi))/np.pi) +# print((zfit.run(psi2s_p)%(2*np.pi))/np.pi) + + +# In[35]: + + +# def jpsi_res(q): +# return resonance(q, _mass = jpsi_mass, scale = jpsi_scale, +# phase = jpsi_phase, width = jpsi_width) + +# def psi2s_res(q): +# return resonance(q, _mass = psi2s_mass, scale = psi2s_scale, +# phase = psi2s_phase, width = psi2s_width) + +# def p3770_res(q): +# return resonance(q, _mass = p3770_mass, scale = p3770_scale, +# phase = p3770_phase, width = p3770_width) + +# def p4040_res(q): +# return resonance(q, _mass = p4040_mass, scale = p4040_scale, +# phase = p4040_phase, width = p4040_width) + +# def p4160_res(q): +# return resonance(q, _mass = p4160_mass, scale = p4160_scale, +# phase = p4160_phase, width = p4160_width) + +# def p4415_res(q): +# return resonance(q, _mass = p4415_mass, scale = p4415_scale, +# phase = p4415_phase, width = p4415_width) + + +# In[36]: + + +# 0.15**2*4.2/1000 +# result.hesse() + + +# ## Constraints + +# In[37]: + + +# 1. Constraint - Real part of sum of Psi contrib and D contribs + +sum_list = [] + +sum_list.append(ztf.to_complex(jpsi_s) * tf.exp(tf.complex(ztf.constant(0.0), jpsi_p)) * ztf.to_complex(jpsi_w / (tf.pow(jpsi_m,3)))) +sum_list.append(ztf.to_complex(psi2s_s) * tf.exp(tf.complex(ztf.constant(0.0), psi2s_p)) * ztf.to_complex(psi2s_w / (tf.pow(psi2s_m,3)))) +sum_list.append(ztf.to_complex(p3770_s) * tf.exp(tf.complex(ztf.constant(0.0), p3770_p)) * ztf.to_complex(p3770_w / (tf.pow(p3770_m,3)))) +sum_list.append(ztf.to_complex(p4040_s) * tf.exp(tf.complex(ztf.constant(0.0), p4040_p)) * ztf.to_complex(p4040_w / (tf.pow(p4040_m,3)))) +sum_list.append(ztf.to_complex(p4160_s) * tf.exp(tf.complex(ztf.constant(0.0), p4160_p)) * ztf.to_complex(p4160_w / (tf.pow(p4160_m,3)))) +sum_list.append(ztf.to_complex(p4415_s) * tf.exp(tf.complex(ztf.constant(0.0), p4415_p)) * ztf.to_complex(p4415_w / (tf.pow(p4415_m,3)))) +sum_list.append(ztf.to_complex(DDstar_s) * tf.exp(tf.complex(ztf.constant(0.0), DDstar_p)) * (ztf.to_complex(1.0 / (10.0*tf.pow(Dstar_m,2)) + 1.0 / (10.0*tf.pow(D_m,2))))) +sum_list.append(ztf.to_complex(Dbar_s) * tf.exp(tf.complex(ztf.constant(0.0), Dbar_p)) * ztf.to_complex(1.0 / (6.0*tf.pow(Dbar_m,2)))) + +sum_ru_1 = ztf.to_complex(ztf.constant(0.0)) + +for part in sum_list: + sum_ru_1 += part + +sum_1 = tf.math.real(sum_ru_1) +# constraint1 = zfit.constraint.GaussianConstraint(params = sum_1, mu = ztf.constant(1.7*10**-8), +# sigma = ztf.constant(2.2*10**-8)) + +constraint1 = tf.pow((sum_1-ztf.constant(1.7*10**-8))/ztf.constant(2.2*10**-8),2)/ztf.constant(2.) + +# 2. Constraint - Abs. of sum of Psi contribs and D contribs + +sum_2 = tf.abs(sum_ru_1) +constraint2 = tf.cond(tf.greater_equal(sum_2, 5.0e-8), lambda: 100000., lambda: 0.) + +# 3. Constraint - Maximum eta of D contribs + +constraint3_0 = tf.cond(tf.greater_equal(tf.abs(Dbar_s), 0.2), lambda: 100000., lambda: 0.) + +constraint3_1 = tf.cond(tf.greater_equal(tf.abs(DDstar_s), 0.2), lambda: 100000., lambda: 0.) + +# 4. Constraint - Formfactor multivariant gaussian covariance fplus + +Cov_matrix = [[ztf.constant( 1.), ztf.constant( 0.45), ztf.constant( 0.19), ztf.constant(0.857), ztf.constant(0.598), ztf.constant(0.531), ztf.constant(0.752), ztf.constant(0.229), ztf.constant(0,117)], + [ztf.constant( 0.45), ztf.constant( 1.), ztf.constant(0.677), ztf.constant(0.708), ztf.constant(0.958), ztf.constant(0.927), ztf.constant(0.227), ztf.constant(0.443), ztf.constant(0.287)], + [ztf.constant( 0.19), ztf.constant(0.677), ztf.constant( 1.), ztf.constant(0.595), ztf.constant(0.770), ztf.constant(0.819),ztf.constant(-0.023), ztf.constant( 0.07), ztf.constant(0.196)], + [ztf.constant(0.857), ztf.constant(0.708), ztf.constant(0.595), ztf.constant( 1.), ztf.constant( 0.83), ztf.constant(0.766), ztf.constant(0.582), ztf.constant(0.237), ztf.constant(0.192)], + [ztf.constant(0.598), ztf.constant(0.958), ztf.constant(0.770), ztf.constant( 0.83), ztf.constant( 1.), ztf.constant(0.973), ztf.constant(0.324), ztf.constant(0.372), ztf.constant(0.272)], + [ztf.constant(0.531), ztf.constant(0.927), ztf.constant(0.819), ztf.constant(0.766), ztf.constant(0.973), ztf.constant( 1.), ztf.constant(0.268), ztf.constant(0.332), ztf.constant(0.269)], + [ztf.constant(0.752), ztf.constant(0.227),ztf.constant(-0.023), ztf.constant(0.582), ztf.constant(0.324), ztf.constant(0.268), ztf.constant( 1.), ztf.constant( 0.59), ztf.constant(0.515)], + [ztf.constant(0.229), ztf.constant(0.443), ztf.constant( 0.07), ztf.constant(0.237), ztf.constant(0.372), ztf.constant(0.332), ztf.constant( 0.59), ztf.constant( 1.), ztf.constant(0.897)], + [ztf.constant(0.117), ztf.constant(0.287), ztf.constant(0.196), ztf.constant(0.192), ztf.constant(0.272), ztf.constant(0.269), ztf.constant(0.515), ztf.constant(0.897), ztf.constant( 1.)]] + +def triGauss(val1,val2,val3,m = Cov_matrix): + + mean1 = ztf.constant(0.466) + mean2 = ztf.constant(-0.885) + mean3 = ztf.constant(-0.213) + sigma1 = ztf.constant(0.014) + sigma2 = ztf.constant(0.128) + sigma3 = ztf.constant(0.548) + x1 = (val1-mean1)/sigma1 + x2 = (val2-mean2)/sigma2 + x3 = (val3-mean3)/sigma3 + rho12 = m[0][1] + rho13 = m[0][2] + rho23 = m[1][2] + w = x1*x1*(rho23*rho23-1) + x2*x2*(rho13*rho13-1)+x3*x3*(rho12*rho12-1)+2*(x1*x2*(rho12-rho13*rho23)+x1*x3*(rho13-rho12*rho23)+x2*x3*(rho23-rho12*rho13)) + d = 2*(rho12*rho12+rho13*rho13+rho23*rho23-2*rho12*rho13*rho23-1) + + fcn = -w/d + chisq = -2*fcn + return chisq + +constraint4 = triGauss(bplus_0, bplus_1, bplus_2) + +# mean1 = ztf.constant(0.466) +# mean2 = ztf.constant(-0.885) +# mean3 = ztf.constant(-0.213) +# sigma1 = ztf.constant(0.014) +# sigma2 = ztf.constant(0.128) +# sigma3 = ztf.constant(0.548) +# constraint4_0 = tf.pow((bplus_0-mean1)/sigma1,2)/ztf.constant(2.) +# constraint4_1 = tf.pow((bplus_1-mean2)/sigma2,2)/ztf.constant(2.) +# constraint4_2 = tf.pow((bplus_2-mean3)/sigma3,2)/ztf.constant(2.) + +# 5. Constraint - Abs. of sum of light contribs + +sum_list_5 = [] + +sum_list_5.append(rho_s*rho_w/rho_m) +sum_list_5.append(omega_s*omega_w/omega_m) +sum_list_5.append(phi_s*phi_w/phi_m) + + +sum_ru_5 = ztf.constant(0.0) + +for part in sum_list_5: + sum_ru_5 += part + +constraint5 = tf.cond(tf.greater_equal(tf.abs(sum_ru_5), ztf.constant(0.02)), lambda: 100000., lambda: 0.) + +# 6. Constraint on phases of Jpsi and Psi2s for cut out fit + + +# constraint6_0 = zfit.constraint.GaussianConstraint(params = jpsi_p, mu = ztf.constant(pdg["jpsi_phase_unc"]), +# sigma = ztf.constant(jpsi_phase)) +# constraint6_1 = zfit.constraint.GaussianConstraint(params = psi2s_p, mu = ztf.constant(pdg["psi2s_phase_unc"]), +# sigma = ztf.constant(psi2s_phase)) + +constraint6_0 = tf.pow((jpsi_p-ztf.constant(jpsi_phase))/ztf.constant(pdg["jpsi_phase_unc"]),2)/ztf.constant(2.) +constraint6_1 = tf.pow((psi2s_p-ztf.constant(psi2s_phase))/ztf.constant(pdg["psi2s_phase_unc"]),2)/ztf.constant(2.) + +# 7. Constraint on Ctt with higher limits + +constraint7 = tf.cond(tf.greater_equal(Ctt*Ctt, 0.25), lambda: 100000., lambda: 0.) + +constraint7dtype = tf.float64 + +# zfit.run(constraint6_0) + +# ztf.convert_to_tensor(constraint6_0) + +#List of all constraints + +constraints = [constraint1, constraint2, constraint3_0, constraint3_1,# constraint4, #constraint4_0, constraint4_1, constraint4_2, + constraint6_0, constraint6_1]#, constraint7] + + +# ## Reset params + +# In[38]: + + +def reset_param_values(): + jpsi_m.set_value(jpsi_mass) + jpsi_s.set_value(jpsi_scale) + jpsi_p.set_value(jpsi_phase) + jpsi_w.set_value(jpsi_width) + psi2s_m.set_value(psi2s_mass) + psi2s_s.set_value(psi2s_scale) + psi2s_p.set_value(psi2s_phase) + psi2s_w.set_value(psi2s_width) + p3770_m.set_value(p3770_mass) + p3770_s.set_value(p3770_scale) + p3770_p.set_value(p3770_phase) + p3770_w.set_value(p3770_width) + p4040_m.set_value(p4040_mass) + p4040_s.set_value(p4040_scale) + p4040_p.set_value(p4040_phase) + p4040_w.set_value(p4040_width) + p4160_m.set_value(p4160_mass) + p4160_s.set_value(p4160_scale) + p4160_p.set_value(p4160_phase) + p4160_w.set_value(p4160_width) + p4415_m.set_value(p4415_mass) + p4415_s.set_value(p4415_scale) + p4415_p.set_value(p4415_phase) + p4415_w.set_value(p4415_width) + rho_m.set_value(rho_mass) + rho_s.set_value(rho_scale) + rho_p.set_value(rho_phase) + rho_w.set_value(rho_width) + omega_m.set_value(omega_mass) + omega_s.set_value(omega_scale) + omega_p.set_value(omega_phase) + omega_w.set_value(omega_width) + phi_m.set_value(phi_mass) + phi_s.set_value(phi_scale) + phi_p.set_value(phi_phase) + phi_w.set_value(phi_width) + Dstar_m.set_value(Dstar_mass) + DDstar_s.set_value(0.0) + DDstar_p.set_value(0.0) + D_m.set_value(D_mass) + Dbar_m.set_value(Dbar_mass) + Dbar_s.set_value(0.0) + Dbar_p.set_value(0.0) + tau_m.set_value(pdg['tau_M']) + Ctt.set_value(0.0) + b0_0.set_value(0.292) + b0_1.set_value(0.281) + b0_2.set_value(0.150) + bplus_0.set_value(0.466) + bplus_1.set_value(-0.885) + bplus_2.set_value(-0.213) + bT_0.set_value(0.460) + bT_1.set_value(-1.089) + bT_2.set_value(-1.114) + + +# # Analysis + +# In[39]: + + +# # zfit.run.numeric_checks = False + +# fitting_range = 'cut' +# total_BR = 1.7e-10 + 4.9e-10 + 2.5e-9 + 6.02e-5 + 4.97e-6 + 1.38e-9 + 4.2e-10 + 2.6e-9 + 6.1e-10 + 4.37e-7 +# cut_BR = 1.0 - (6.02e-5 + 4.97e-6)/total_BR + +# Ctt_list = [] +# Ctt_error_list = [] + +# nr_of_toys = 1 +# if fitting_range == 'cut': +# nevents = int(pdg["number_of_decays"]*cut_BR) +# else: +# nevents = int(pdg["number_of_decays"]) +# # nevents = pdg["number_of_decays"] +# event_stack = 1000000 +# # nevents *= 41 +# # zfit.settings.set_verbosity(10) +# calls = int(nevents/event_stack + 1) + +# total_samp = [] + +# start = time.time() + +# sampler = total_f.create_sampler(n=event_stack) + +# for toy in range(nr_of_toys): + +# ### Generate data + +# # clear_output(wait=True) + +# print("Toy {}: Generating data...".format(toy)) + +# dirName = 'data/zfit_toys/toy_{0}'.format(toy) + +# if not os.path.exists(dirName): +# os.mkdir(dirName) +# print("Directory " , dirName , " Created ") + +# reset_param_values() + +# if fitting_range == 'cut': + +# sampler.resample(n=nevents) +# s = sampler.unstack_x() +# sam = zfit.run(s) +# calls = 0 +# c = 1 + +# else: +# for call in range(calls): + +# sampler.resample(n=event_stack) +# s = sampler.unstack_x() +# sam = zfit.run(s) + +# c = call + 1 + +# with open("data/zfit_toys/toy_{0}/{1}.pkl".format(toy, call), "wb") as f: +# pkl.dump(sam, f, pkl.HIGHEST_PROTOCOL) + +# print("Toy {}: Data generation finished".format(toy)) + +# ### Load data + +# print("Toy {}: Loading data...".format(toy)) + +# if fitting_range == 'cut': + +# total_samp = sam + +# else: + +# for call in range(calls): +# with open(r"data/zfit_toys/toy_0/{}.pkl".format(call), "rb") as input_file: +# sam = pkl.load(input_file) +# total_samp = np.append(total_samp, sam) + +# total_samp = total_samp.astype('float64') + +# if fitting_range == 'full': + +# data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs) + +# print("Toy {}: Loading data finished".format(toy)) + +# ### Fit data + +# print("Toy {}: Fitting pdf...".format(toy)) + +# for param in total_f.get_dependents(): +# param.randomize() + +# nll = zfit.loss.UnbinnedNLL(model=total_f, data=data, fit_range = (x_min, x_max), constraints = constraints) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# print("Toy {}: Fitting finished".format(toy)) + +# print("Function minimum:", result.fmin) +# print("Hesse errors:", result.hesse()) + +# params = result.params +# Ctt_list.append(params[Ctt]['value']) +# Ctt_error_list.append(params[Ctt]['minuit_hesse']['error']) + +# #plotting the result + +# plotdirName = 'data/plots'.format(toy) + +# if not os.path.exists(plotdirName): +# os.mkdir(plotdirName) +# # print("Directory " , dirName , " Created ") + +# probs = total_f.pdf(test_q, norm_range=False) +# calcs_test = zfit.run(probs) +# plt.clf() +# plt.plot(test_q, calcs_test, label = 'pdf') +# plt.legend() +# plt.ylim(0.0, 6e-6) +# plt.savefig(plotdirName + '/toy_fit_full_range{}.png'.format(toy)) + +# print("Toy {0}/{1}".format(toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(c+calls*(toy))*((nr_of_toys-toy)*calls-c))))) + +# if fitting_range == 'cut': + +# _1 = np.where((total_samp >= x_min) & (total_samp <= (jpsi_mass - 60.))) + +# tot_sam_1 = total_samp[_1] + +# _2 = np.where((total_samp >= (jpsi_mass + 70.)) & (total_samp <= (psi2s_mass - 50.))) + +# tot_sam_2 = total_samp[_2] + +# _3 = np.where((total_samp >= (psi2s_mass + 50.)) & (total_samp <= x_max)) + +# tot_sam_3 = total_samp[_3] + +# tot_sam = np.append(tot_sam_1, tot_sam_2) +# tot_sam = np.append(tot_sam, tot_sam_3) + +# data = zfit.data.Data.from_numpy(array=tot_sam[:int(nevents)], obs=obs_fit) + +# print("Toy {}: Loading data finished".format(toy)) + +# ### Fit data + +# print("Toy {}: Fitting pdf...".format(toy)) + +# for param in total_f_fit.get_dependents(): +# param.randomize() + +# nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + +# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) +# # minimizer._use_tfgrad = False +# result = minimizer.minimize(nll) + +# print("Function minimum:", result.fmin) +# print("Hesse errors:", result.hesse()) + +# params = result.params + +# if result.converged: +# Ctt_list.append(params[Ctt]['value']) +# Ctt_error_list.append(params[Ctt]['minuit_hesse']['error']) + +# #plotting the result + +# plotdirName = 'data/plots'.format(toy) + +# if not os.path.exists(plotdirName): +# os.mkdir(plotdirName) +# # print("Directory " , dirName , " Created ") + +# plt.clf() +# plt.hist(tot_sam, bins = int((x_max-x_min)/7.), label = 'toy data') +# plt.savefig(plotdirName + '/toy_histo_cut_region{}.png'.format(toy)) + + +# probs = total_f_fit.pdf(test_q, norm_range=False) +# calcs_test = zfit.run(probs) +# plt.clf() +# plt.plot(test_q, calcs_test, label = 'pdf') +# plt.axvline(x=jpsi_mass-60.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=jpsi_mass+70.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=psi2s_mass-50.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.axvline(x=psi2s_mass+50.,color='red', linewidth=0.7, linestyle = 'dotted') +# plt.legend() +# plt.ylim(0.0, 1.5e-6) +# plt.savefig(plotdirName + '/toy_fit_cut_region{}.png'.format(toy)) + +# print("Toy {0}/{1}".format(toy+1, nr_of_toys)) +# print("Time taken: {}".format(display_time(int(time.time() - start)))) +# print("Projected time left: {}".format(display_time(int((time.time() - start)/(toy+1))*((nr_of_toys-toy-1))))) + + + +# In[40]: + + +# with open("data/results/Ctt_list.pkl", "wb") as f: +# pkl.dump(Ctt_list, f, pkl.HIGHEST_PROTOCOL) +# with open("data/results/Ctt_error_list.pkl", "wb") as f: +# pkl.dump(Ctt_error_list, f, pkl.HIGHEST_PROTOCOL) + + +# In[41]: + + +# print('{0}/{1} fits converged'.format(len(Ctt_list), nr_of_toys)) +# print('Mean Ctt value = {}'.format(np.mean(Ctt_list))) +# print('Mean Ctt error = {}'.format(np.mean(Ctt_error_list))) +# print('95 Sensitivy = {}'.format(((2*np.mean(Ctt_error_list))**2)*4.2/1000)) + + +# In[42]: + + +# plt.hist(tot_sam, bins = int((x_max-x_min)/7.)) + +# plt.show() + +# # _ = np.where((total_samp >= x_min) & (total_samp <= (jpsi_mass - 50.))) + +# tot_sam.shape + + +# In[43]: + + +# Ctt.floating = False + + +# In[44]: + + +# zfit.run(nll.value()) + + +# In[45]: + + +# result.fmin + + +# In[46]: + + +# BR_steps = np.linspace(0.0, 1e-3, 11) + + +# # CLS Code + +# In[47]: + + +# zfit.run.numeric_checks = False + +load = False + +bo5 = True + +bo5_set = 5 + +fitting_range = 'cut' +total_BR = 1.7e-10 + 4.9e-10 + 2.5e-9 + 6.02e-5 + 4.97e-6 + 1.38e-9 + 4.2e-10 + 2.6e-9 + 6.1e-10 + 4.37e-7 +cut_BR = 1.0 - (6.02e-5 + 4.97e-6)/total_BR + +Ctt_list = [] +Ctt_error_list = [] + +nr_of_toys = 1 +nevents = int(pdg["number_of_decays"]*cut_BR) +# nevents = pdg["number_of_decays"] +event_stack = 1000000 +# nevents *= 41 +# zfit.settings.set_verbosity(10) + +mi = 0.0 +ma = 1e-3 +ste = 11 + +BR_steps = np.linspace(mi, ma, ste) + +Ctt_steps = np.sqrt(BR_steps/4.2*1000) + +total_samp = [] + +start = time.time() + +Nll_list = [] + +sampler = total_f.create_sampler(n=nevents) + +__ = 0 + + +#----------------------------------------------------- + +if not load: + + for Ctt_step in Ctt_steps: + + __ += 1 + + newset = True + + for floaty in [True, False]: + + Ctt.floating = floaty + + Nll_list.append([]) + + if bo5: + + while len(Nll_list[-1])/bo5_set < nr_of_toys: + + print('Step: {0}/{1}'.format(__, ste)) + + print('Current Ctt: {0}'.format(Ctt_step)) + print('Ctt floating: {0}'.format(floaty)) + + print('Toy {0}/{1} - Fit {2}/{3}'.format(int(len(Nll_list[-1])/bo5_set), nr_of_toys, len(Nll_list[-1]), bo5_set)) + + reset_param_values() + + if floaty: + Ctt.set_value(Ctt_step) + else: + Ctt.set_value(0.0) + + if newset: + sampler.resample(n=nevents) + s = sampler.unstack_x() + total_samp = zfit.run(s) + calls = 0 + c = 1 + newset = False + + + data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit) + + ### Fit data + + for param in total_f_fit.get_dependents(): + param.randomize() + + nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + + minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) + # minimizer._use_tfgrad = False + result = minimizer.minimize(nll) + + # print("Function minimum:", result.fmin) + # print("Hesse errors:", result.hesse()) + + params = result.params + + if result.converged: + Nll_list[-1].append(result.fmin) + + else: + + while len(Nll_list[-1]) < nr_of_toys: + + print('Step: {0}/{1}'.format(__, ste)) + + print('Current Ctt: {0}'.format(Ctt_step)) + print('Ctt floating: {0}'.format(floaty)) + + print('Toy {0}/{1}'.format(len(Nll_list[-1]), nr_of_toys)) + + reset_param_values() + + if floaty: + Ctt.set_value(Ctt_step) + else: + Ctt.set_value(0.0) + + if floaty: + sampler.resample(n=nevents) + s = sampler.unstack_x() + total_samp = zfit.run(s) + calls = 0 + c = 1 + + + data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit) + + ### Fit data + + for param in total_f_fit.get_dependents(): + param.randomize() + + nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints) + + minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5) + # minimizer._use_tfgrad = False + result = minimizer.minimize(nll) + + # print("Function minimum:", result.fmin) + # print("Hesse errors:", result.hesse()) + + params = result.params + + if result.converged: + Nll_list[-1].append(result.fmin) + + _t = int(time.time()-start) + + print('Time Taken: {}'.format(display_time(int(_t)))) + + print('Predicted time left: {}'.format(display_time(int((_t/(__+1)*(ste-__-1)))))) + + +# In[48]: + + +if load: + Nll_list = [] + CLs_values = [] + + _dir = 'data/CLs/finished/f1d1' + + jobs = os.listdir(_dir) + + for s in range(ste): + CLs_values.append([]) + + for s in range(2*ste): + Nll_list.append([]) + + for job in jobs: + if not os.path.exists("{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(_dir, job, mi,ma,ste)): + print(job) + continue + + with open(r"{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(_dir, job, mi,ma,ste), "rb") as input_file: + _Nll_list = pkl.load(input_file) + + if bo5: + for s in range(2*ste): + Nll_list[s].append(np.min(_Nll_list[s])) + else: + for s in range(2*ste): + Nll_list[s].extend(_Nll_list[s]) + + with open(r"{}/{}/data/CLs/{}-{}_{}s--CLs_list.pkl".format(_dir, job, mi,ma,ste), "rb") as input_file: + _CLs_values = pkl.load(input_file) + + for s in range(ste): + CLs_values[s].extend(_CLs_values[s]) + + print(np.shape(Nll_list)) + + +# In[50]: + + +dirName = 'data/CLs' + +# if bo5 and not load: +# for s in range(2*ste): +# Nll_list[s] = [np.min(Nll_list[s])] + +if bo5: + CLs_values= [] + for i in range(int(len(Nll_list)/2)): + CLs_values.append([]) + for j in range(len(Nll_list[0])): + CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j]) + + +if not load: + + CLs_values = [] + + for i in range(int(len(Nll_list)/2)): + CLs_values.append([]) + for j in range(nr_of_toys): + CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j]) + + if not os.path.exists(dirName): + os.mkdir(dirName) + print("Directory " , dirName , " Created ") + + with open("{}/{}-{}_{}s--CLs_Nll_list.pkl".format(dirName, mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + + with open("{}/{}-{}_{}s--CLs_list.pkl".format(dirName, mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +# print(CLs_values) +print(Nll_list) + + +# ## Plot + +# In[52]: + + +l = [] + +for i in range(len(CLs_values)): + plt.clf() + plt.title('Ctt value: {:.2f}'.format(Ctt_steps[i])) + plt.hist(CLs_values[0], bins = 100, label = 'Ctt fixed to 0') + plt.hist(CLs_values[i], bins = 100, label = 'Ctt floating') + plt.axvline(x=np.mean(CLs_values[0]),color='red', linewidth=0.7, linestyle = 'dotted') + plt.legend() + plt.savefig('data/CLs/plots/CLs-BR({:.1E}).png'.format(BR_steps[i])) + + l.append(len(np.where(np.array(CLs_values[i]) < np.mean(CLs_values[0]))[0])) + + +# In[53]: + + +for s in range(len(l)): + print('BR: {}'.format(BR_steps[s])) + print(2*l[s]/len(CLs_values[0])) + print() + + +# In[54]: + + +# print(np.array(Nll_list[0][:10])-np.array(Nll_list[1][:10])) + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2254896/test.png b/data/CLs/finished/f1d1/2254896/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2254896/test.png Binary files differ diff --git "a/data/CLs/plots/CLs-BR\0500.0E+00\051.png" "b/data/CLs/plots/CLs-BR\0500.0E+00\051.png" index 8304527..01d64f6 100644 --- "a/data/CLs/plots/CLs-BR\0500.0E+00\051.png" +++ "b/data/CLs/plots/CLs-BR\0500.0E+00\051.png" Binary files differ diff --git "a/data/CLs/plots/CLs-BR\0501.0E-03\051.png" "b/data/CLs/plots/CLs-BR\0501.0E-03\051.png" index 2dee2b0..87b41c9 100644 --- "a/data/CLs/plots/CLs-BR\0501.0E-03\051.png" +++ "b/data/CLs/plots/CLs-BR\0501.0E-03\051.png" Binary files differ diff --git "a/data/CLs/plots/CLs-BR\0501.0E-04\051.png" "b/data/CLs/plots/CLs-BR\0501.0E-04\051.png" index 9505d8e..a01c16a 100644 --- "a/data/CLs/plots/CLs-BR\0501.0E-04\051.png" +++ "b/data/CLs/plots/CLs-BR\0501.0E-04\051.png" Binary files differ diff --git "a/data/CLs/plots/CLs-BR\0502.0E-04\051.png" "b/data/CLs/plots/CLs-BR\0502.0E-04\051.png" index 3741d0f..f7ccf1a 100644 --- "a/data/CLs/plots/CLs-BR\0502.0E-04\051.png" +++ "b/data/CLs/plots/CLs-BR\0502.0E-04\051.png" Binary files differ diff --git "a/data/CLs/plots/CLs-BR\0503.0E-04\051.png" "b/data/CLs/plots/CLs-BR\0503.0E-04\051.png" index f137c0e..139b1e4 100644 --- "a/data/CLs/plots/CLs-BR\0503.0E-04\051.png" +++ "b/data/CLs/plots/CLs-BR\0503.0E-04\051.png" Binary files differ diff --git "a/data/CLs/plots/CLs-BR\0504.0E-04\051.png" "b/data/CLs/plots/CLs-BR\0504.0E-04\051.png" index 3a9691f..f2d333c 100644 --- "a/data/CLs/plots/CLs-BR\0504.0E-04\051.png" +++ "b/data/CLs/plots/CLs-BR\0504.0E-04\051.png" Binary files differ diff --git "a/data/CLs/plots/CLs-BR\0505.0E-04\051.png" "b/data/CLs/plots/CLs-BR\0505.0E-04\051.png" index 7514ea7..5a3f99e 100644 --- "a/data/CLs/plots/CLs-BR\0505.0E-04\051.png" +++ "b/data/CLs/plots/CLs-BR\0505.0E-04\051.png" Binary files differ diff --git "a/data/CLs/plots/CLs-BR\0506.0E-04\051.png" "b/data/CLs/plots/CLs-BR\0506.0E-04\051.png" index dec8751..9943f52 100644 --- "a/data/CLs/plots/CLs-BR\0506.0E-04\051.png" +++ "b/data/CLs/plots/CLs-BR\0506.0E-04\051.png" Binary files differ diff --git "a/data/CLs/plots/CLs-BR\0507.0E-04\051.png" "b/data/CLs/plots/CLs-BR\0507.0E-04\051.png" index 078ef89..7945903 100644 --- "a/data/CLs/plots/CLs-BR\0507.0E-04\051.png" +++ "b/data/CLs/plots/CLs-BR\0507.0E-04\051.png" Binary files differ diff --git "a/data/CLs/plots/CLs-BR\0508.0E-04\051.png" "b/data/CLs/plots/CLs-BR\0508.0E-04\051.png" index bcede32..4ffe10c 100644 --- "a/data/CLs/plots/CLs-BR\0508.0E-04\051.png" +++ "b/data/CLs/plots/CLs-BR\0508.0E-04\051.png" Binary files differ diff --git "a/data/CLs/plots/CLs-BR\0509.0E-04\051.png" "b/data/CLs/plots/CLs-BR\0509.0E-04\051.png" index bf781d4..afedc52 100644 --- "a/data/CLs/plots/CLs-BR\0509.0E-04\051.png" +++ "b/data/CLs/plots/CLs-BR\0509.0E-04\051.png" Binary files differ diff --git a/raremodel-nb.ipynb b/raremodel-nb.ipynb index a4e9462..b2495bc 100644 --- a/raremodel-nb.ipynb +++ b/raremodel-nb.ipynb @@ -1941,7 +1941,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 48, "metadata": { "scrolled": true }, @@ -1952,50 +1952,14 @@ "text": [ "WARNING:tensorflow:From C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\sample.py:163: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n", "Instructions for updating:\n", - "Use tf.cast instead.\n", - "Step: 1/11\n", - "Current Ctt: 0.0\n", - "Ctt floating: True\n", - "Toy 0/1 - Fit 0/5\n", - "------------------------------------------------------------------\n", - "| FCN = 2.977E+05 | Ncalls=1285 (1285 total) |\n", - "| EDM = 0.000105 (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", - "Step: 1/11\n", - "Current Ctt: 0.0\n", - "Ctt floating: True\n", - "Toy 0/1 - Fit 1/5\n" - ] - }, - { - "ename": "RuntimeError", - "evalue": "exception was raised in user function\nUser function arguments:\n p4160_s = +2.119363\n rho_p = -0.447764\n p4160_p = -2.229073\n psi2s_p = +1.949040\n p4040_p = -3.142631\n bplus_2 = +0.271685\n jpsi_p = +1.695023\n Dbar_p = -4.211679\n p3770_s = +2.169347\n DDstar_p = -0.888402\n omega_s = +8.642103\n Dbar_s = +0.300000\n omega_p = -5.921044\n phi_p = +0.634553\n p3770_p = +3.029698\n DDstar_s = -0.300000\n p4415_s = +1.310081\n phi_s = +19.818317\n p4415_p = -2.586828\n bplus_0 = -0.489758\n bplus_1 = +0.923919\n Ctt = +0.196407\n rho_s = +1.120975\n p4040_s = +1.079351\nOriginal python exception in user function:\nKeyboardInterrupt: \n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\minimizer_minuit.py\", line 101, in func\n loss_evaluated = self.sess.run(loss_val)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 929, in run\n run_metadata_ptr)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1152, in _run\n feed_dict_tensor, options, run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1328, in _do_run\n run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1334, in _do_call\n return fn(*args)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1319, in _run_fn\n options, feed_dict, fetch_list, target_list, run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1407, in _call_tf_sessionrun\n run_metadata)\n", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mRuntimeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 94\u001b[0m \u001b[0mminimizer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mzfit\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mminimize\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mMinuitMinimizer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mverbosity\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 95\u001b[0m \u001b[1;31m# minimizer._use_tfgrad = False\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 96\u001b[1;33m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mminimizer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mminimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnll\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 97\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 98\u001b[0m \u001b[1;31m# print(\"Function minimum:\", result.fmin)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\baseminimizer.py\u001b[0m in \u001b[0;36mminimize\u001b[1;34m(self, loss, params)\u001b[0m\n\u001b[0;32m 205\u001b[0m \u001b[0mtuple\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstack\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0menter_context\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mparam\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mset_sess\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msess\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mparam\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 206\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 207\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_hook_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 208\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mFailMinimizeNaN\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merror\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# iminuit raises RuntimeError if user raises Error\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 209\u001b[0m \u001b[0mfail_result\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstrategy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit_result\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\baseminimizer.py\u001b[0m in \u001b[0;36m_hook_minimize\u001b[1;34m(self, loss, params)\u001b[0m\n\u001b[0;32m 214\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 215\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_hook_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 216\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 217\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 218\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_call_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\baseminimizer.py\u001b[0m in \u001b[0;36m_call_minimize\u001b[1;34m(self, loss, params)\u001b[0m\n\u001b[0;32m 218\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_call_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 219\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 220\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_minimize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mloss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 221\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mNotImplementedError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merror\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 222\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\minimizer_minuit.py\u001b[0m in \u001b[0;36m_minimize\u001b[1;34m(self, loss, params)\u001b[0m\n\u001b[0;32m 136\u001b[0m minimizer_setter)\n\u001b[0;32m 137\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_minuit_minimizer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mminimizer\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 138\u001b[1;33m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mminimizer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmigrad\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m**\u001b[0m\u001b[0mminimize_options\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 139\u001b[0m \u001b[0mparams_result\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mp_dict\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mp_dict\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 140\u001b[0m \u001b[0mresult_vals\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mres\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"value\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mres\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mparams_result\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32miminuit\\_libiminuit.pyx\u001b[0m in \u001b[0;36miminuit._libiminuit.Minuit.migrad\u001b[1;34m()\u001b[0m\n", - "\u001b[1;31mRuntimeError\u001b[0m: exception was raised in user function\nUser function arguments:\n p4160_s = +2.119363\n rho_p = -0.447764\n p4160_p = -2.229073\n psi2s_p = +1.949040\n p4040_p = -3.142631\n bplus_2 = +0.271685\n jpsi_p = +1.695023\n Dbar_p = -4.211679\n p3770_s = +2.169347\n DDstar_p = -0.888402\n omega_s = +8.642103\n Dbar_s = +0.300000\n omega_p = -5.921044\n phi_p = +0.634553\n p3770_p = +3.029698\n DDstar_s = -0.300000\n p4415_s = +1.310081\n phi_s = +19.818317\n p4415_p = -2.586828\n bplus_0 = -0.489758\n bplus_1 = +0.923919\n Ctt = +0.196407\n rho_s = +1.120975\n p4040_s = +1.079351\nOriginal python exception in user function:\nKeyboardInterrupt: \n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\minimizers\\minimizer_minuit.py\", line 101, in func\n loss_evaluated = self.sess.run(loss_val)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 929, in run\n run_metadata_ptr)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1152, in _run\n feed_dict_tensor, options, run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1328, in _do_run\n run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1334, in _do_call\n return fn(*args)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1319, in _run_fn\n options, feed_dict, fetch_list, target_list, run_metadata)\n File \"C:\\Users\\sa_li\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\client\\session.py\", line 1407, in _call_tf_sessionrun\n run_metadata)\n" + "Use tf.cast instead.\n" ] } ], "source": [ "# zfit.run.numeric_checks = False \n", "\n", - "load = False\n", + "load = True\n", "\n", "bo5 = True\n", "\n", @@ -2033,7 +1997,6 @@ "\n", "__ = 0\n", "\n", - "\n", "#-----------------------------------------------------\n", "\n", "if not load:\n", @@ -2052,51 +2015,53 @@ " \n", " if bo5:\n", " \n", - " while len(Nll_list[-1])/bo5_set < nr_of_toys:\n", + " if __ < 6:\n", + " \n", + " while len(Nll_list[-1])/bo5_set < nr_of_toys:\n", "\n", - " print('Step: {0}/{1}'.format(__, ste))\n", + " print('Step: {0}/{1}'.format(__, ste))\n", "\n", - " print('Current Ctt: {0}'.format(Ctt_step))\n", - " print('Ctt floating: {0}'.format(floaty))\n", + " print('Current Ctt: {0}'.format(Ctt_step))\n", + " print('Ctt floating: {0}'.format(floaty))\n", "\n", - " print('Toy {0}/{1} - Fit {2}/{3}'.format(int(len(Nll_list[-1])/bo5_set), nr_of_toys, len(Nll_list[-1]), bo5_set))\n", + " print('Toy {0}/{1} - Fit {2}/{3}'.format(int(len(Nll_list[-1])/bo5_set), nr_of_toys, len(Nll_list[-1]), bo5_set))\n", "\n", - " reset_param_values()\n", + " reset_param_values()\n", "\n", - " if floaty:\n", - " Ctt.set_value(Ctt_step)\n", - " else:\n", - " Ctt.set_value(0.0)\n", + " if floaty:\n", + " Ctt.set_value(Ctt_step)\n", + " else:\n", + " Ctt.set_value(0.0)\n", "\n", - " if newset:\n", - " sampler.resample(n=nevents)\n", - " s = sampler.unstack_x()\n", - " total_samp = zfit.run(s)\n", - " calls = 0\n", - " c = 1\n", - " newset = False\n", + " if newset:\n", + " sampler.resample(n=nevents)\n", + " s = sampler.unstack_x()\n", + " total_samp = zfit.run(s)\n", + " calls = 0\n", + " c = 1\n", + " newset = False\n", "\n", "\n", - " data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit)\n", + " data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit)\n", "\n", - " ### Fit data\n", + " ### Fit data\n", "\n", - " for param in total_f_fit.get_dependents():\n", - " param.randomize()\n", + " for param in total_f_fit.get_dependents():\n", + " param.randomize()\n", "\n", - " nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints)\n", + " nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints)\n", "\n", - " minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5)\n", - " # minimizer._use_tfgrad = False\n", - " result = minimizer.minimize(nll)\n", + " minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5)\n", + " # minimizer._use_tfgrad = False\n", + " result = minimizer.minimize(nll)\n", "\n", - " # print(\"Function minimum:\", result.fmin)\n", - " # print(\"Hesse errors:\", result.hesse())\n", + " # print(\"Function minimum:\", result.fmin)\n", + " # print(\"Hesse errors:\", result.hesse())\n", "\n", - " params = result.params\n", + " params = result.params\n", "\n", - " if result.converged:\n", - " Nll_list[-1].append(result.fmin)\n", + " if result.converged:\n", + " Nll_list[-1].append(result.fmin)\n", "\n", " else:\n", "\n", @@ -2154,7 +2119,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 49, "metadata": {}, "outputs": [ { @@ -2164,43 +2129,8 @@ "(22, 1)\n", "(22, 2)\n", "(22, 3)\n", - "2254611\n", "(22, 4)\n", - "(22, 5)\n", - "(22, 6)\n", - "(22, 7)\n", - "(22, 8)\n", - "(22, 9)\n", - "2254618\n", - "(22, 10)\n", - "(22, 11)\n", - "2254621\n", - "(22, 12)\n", - "(22, 13)\n", - "(22, 14)\n", - "(22, 15)\n", - "(22, 16)\n", - "(22, 17)\n", - "slurm-2254608.out\n", - "slurm-2254609.out\n", - "slurm-2254610.out\n", - "slurm-2254611.out\n", - "slurm-2254612.out\n", - "slurm-2254613.out\n", - "slurm-2254614.out\n", - "slurm-2254615.out\n", - "slurm-2254616.out\n", - "slurm-2254617.out\n", - "slurm-2254618.out\n", - "slurm-2254619.out\n", - "slurm-2254620.out\n", - "slurm-2254621.out\n", - "slurm-2254622.out\n", - "slurm-2254623.out\n", - "slurm-2254624.out\n", - "slurm-2254625.out\n", - "slurm-2254626.out\n", - "slurm-2254627.out\n" + "bo1\n" ] } ], @@ -2264,20 +2194,20 @@ "\n", "\n", "if not load:\n", - " \n", - " CLs_values = []\n", - " \n", - " for i in range(int(len(Nll_list)/2)):\n", - " CLs_values.append([])\n", - " for j in range(nr_of_toys):\n", - " CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j])\n", - " \n", + " \n", " if not os.path.exists(dirName):\n", " os.mkdir(dirName)\n", " print(\"Directory \" , dirName , \" Created \")\n", "\n", " with open(\"{}/{}-{}_{}s--CLs_Nll_list.pkl\".format(dirName, mi,ma,ste), \"wb\") as f:\n", " pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL)\n", + " \n", + " CLs_values = []\n", + " \n", + " for i in range(int(len(Nll_list)/2)):\n", + " CLs_values.append([])\n", + " for j in range(nr_of_toys):\n", + " CLs_values[i].append(Nll_list[2*i][j]-Nll_list[2*i+1][j])\n", "\n", " with open(\"{}/{}-{}_{}s--CLs_list.pkl\".format(dirName, mi,ma,ste), \"wb\") as f:\n", " pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL)" @@ -2287,18 +2217,10 @@ "cell_type": "code", "execution_count": 51, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[297763.5594876504], [297746.64841404365], [297789.27553325286], [298009.1505843799], [297607.1352560189], [297946.41725542664], [297743.2276395804], [297746.19702565676], [297661.1715722469], [297643.5799308492], [297659.81889337697], [297709.2817569911], [297762.47125993785], [297817.7748216014], [297549.04609343264], [297889.4714059658], [297755.38809197885], [297957.7457254501], [297726.10922358127], [297884.90020829753], [297620.82176273526], [297646.6438885114]]\n" - ] - } - ], + "outputs": [], "source": [ "# print(CLs_values)\n", - "print(Nll_list)" + "# print(Nll_list)" ] }, { @@ -2310,12 +2232,12 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 56, "metadata": {}, "outputs": [ { "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEICAYAAABPgw/pAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAcjUlEQVR4nO3de3hU9Z3H8fe3yG0rohW2rQRNtChyDRIUHgtSREWxqF2ooG7BC9QVut7WFbRFpV7QWlErWqkXXKsEQVlQ8VbUSlVsggYkQRAES0AwRkrlEhD73T9mYMcwMQPM+SUz+byeh8fMOWfO55eDz4eTX2Z+Y+6OiIhkvm/V9QBERCQ9VOgiIllChS4ikiVU6CIiWUKFLiKSJVToIiJZQoUuDZKZ3Whmf6zrcYikkwpdgjGz88ys2Mw2m9knZvaCmf0wvm+PgjWz183skroZ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EX2Re7Y9H7s1uqJA2s9Zv369VxxxRUUFRXRtGlTcnNzufvuu2nSpAlvvfUW5513HgAlJSWsW7eOM844I+l5hg0bRmlpKRdeeCEbN26kT58+9O+/f78qev3117nzzjt57rnnvra9trHU5LbbbuPhhx+mUaNG3HvvvZx22mn7NT6J0LnnBolRoUvWcHfOOecchg8fTmFhIRAryw0bNvDVV1/x5JNPfq3Qi4uLk5bo+vXreeutt/j444+DjPubxlKTsrIyCgsLKS0tZd26dfTv35/ly5fTqFGjCEcq++z++4Os56IpF8kar732Go0bN+bSSy/dvS0/P5/evXszduxY5s+fT35+Prfffjvjx49n+vTp5OfnM3369K+d59RTT+XTTz8lPz+f+fPnM2LECGbOnMmmTZs45phjWLZsGRC7i//DH/4AwMsvv0yvXr047rjjGDJkCJs3bwbgxRdfpH379vzwhz/kmWee2WPMO3bs2GMsn3/+OWeffTZdunShZ8+eLF68eI/nzZ49m6FDh9K0aVPy8vL4wQ9+wF//+te0XUtJs3q0OJdIRliyZAndu3dPum/ixIn07t2bkpISrr32WiZMmMC5555LSUkJ51b7cXjOnDkcddRRlJSU0Lt3793bW7ZsyX333ceIESMoLCxk48aNjBw5ks8++4ybb76ZP/3pT7z77rsUFBRw1113UVVVxciRI3n22WeZP38+69ev32NcTZo02WMsN9xwA926dWPx4sXceuut/OxnP9vjeWvXrqVtwqfg5OTksHbt2n29dBK1QItzacpFZC+ccsopzJgxg9GjR7No0SIAFixYQFlZGSeeeCIQu+vu1asXH3zwAXl5ebRr1w6ACy64gClTptSa8Ze//IWnn34agH79+lFZWcmmTZto2bLl7mPc91xOSa9qqcfGjQsSozt0yRodO3Zk4cKFkWb885//ZOnSpTRv3pzPP/8ciJXrKaecQklJCSUlJZSVlfHwww8D+1ayqZR1Tk4Oa9b8/yKo5eXlHHbYYXudJYH8Jul6hWmnQpes0a9fP7Zv3757XhugqKiIP//5z7Ro0YIvvvhi9/bqj1M1adIkjj32WKZNm8ZFF13El19+Sc+ePXnzzTdZsWIFAFu3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BEidGdOzZ08OPfTQPV5zySWXUF1dzY4dO3jzzTf5y1/+wqmnnrrP+9OcLv2XsGgO/pxFfSZSc2bGE088wU033cT06dMpKCjYfdpicXExXbt25aSTTmLcuHGMHTuW6dOnU1payq233triOHo29fX13H///bz88ssUFhYydOhQpk2bxve//31mz57N6NGj2bFjBwDTpk2jX79+zJo1i4suuoiePXty5plnsnJly+srv/a1r+2RZcqUKVxzzTWceOKJHHzwwTz00EMtXjNgwACuuOIK+vfvT9euXZk5c+YBn+ECYNl+PGgPZWVlnpcbXHTC07NC1SFOW1y8GCoqWr5Apy2yZs0ajj/++IgCyf7I9mdiZsvcvSzb9prLRcKiuVwkwVToEpbFi+NOIBIZFbqEpaoq7gQikVGhS1jKsh56FEkEFbqERSN0STAVuoSlsDDuBCKR0XnoEpZGTTOUs8xTH/Pyfm2fPhnF9LnLly+nsrKSESNG7HPk2bNnc9555+2+ivO6667j5ptvpn///vv8Xu1BI3QJi85y6bB2TZ9bUVHB+vXrWb16NXfccQebNm1iw4YNzJnzt+sD6urqWLRoUdb32TV97ooVK/jud797QJlmz55NY8Yg4P777++wZQ4qdAnNrFlxJ5BWRDV9bqbnnnuOk08+mYEDB3LttdfuvjJ06tSpDB48mBNOOIGqqircnXnz5lFbW8tVV11FaWkpn3zyCRUVFey6IPKQQw7htttu46STTqK8vJxNmzYBsH79esrLyxk8eDCTJ0/mkEMOifJ/2x5U6BKWBQviTiCtiHr63KamJsaNG8fcuXN57bXX2LlzJ7/4ReqOmRMmTKCmpoaVK1fyySefsHDhQkaMGEFZWRmPPPIIdXV1HHTQQXt8zkcffUR5eTnLly9n6NChu+egufHGG7nxxhupqanJy4Rb+0KFLmEZM6btbSSR1q5dS0lJCf3SNwofO3YsL7zwApD66eC0005j4MCB/P73v2fVqlVtvl/37t2prKwEYNCgQWzYsAGAl156iZEjRwLsPubfXlToEpb0P0DpeAYMGMCyCO8o1dq8VU1NTXznO99h3rx5vPbaa4wfP56mpqY2369bt267p8Xt0qULO3fu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wGPAUcB/ASPdPTET7JnZmcAS4DXgi/TifyV1HD0x+61CFxFJCB1yERFJCBW6iEhCqNBFRBJChS4ikhAqdBGRhFChi4gkhApdRCQh/j/paS3vCad70QAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] @@ -2329,12 +2251,16 @@ "source": [ "l = []\n", "\n", + "if not os.path.exists('data/CLs/plots'):\n", + " os.mkdir('data/CLs/plots')\n", + " print(\"Directory \" , 'data/CLs/plots' , \" Created \")\n", + "\n", "for i in range(len(CLs_values)):\n", " plt.clf()\n", " plt.title('Ctt value: {:.2f}'.format(Ctt_steps[i]))\n", - " plt.hist(CLs_values[0], bins = 100, label = 'Ctt fixed to 0')\n", - " plt.hist(CLs_values[i], bins = 100, label = 'Ctt floating')\n", - " plt.axvline(x=np.mean(CLs_values[0]),color='red', linewidth=0.7, linestyle = 'dotted')\n", + " plt.hist(CLs_values[0], bins = 100, range = (-25, 25), label = 'Ctt fixed to 0')\n", + " plt.hist(CLs_values[i], bins = 100, range = (-25, 25), label = 'Ctt floating')\n", + " plt.axvline(x=np.mean(CLs_values[0]),color='red', linewidth=1.0, linestyle = 'dotted')\n", " plt.legend()\n", " plt.savefig('data/CLs/plots/CLs-BR({:.1E}).png'.format(BR_steps[i]))\n", " \n", @@ -2343,59 +2269,59 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "BR: 0.0\n", - "0.0\n", + "BR: 0.0000\n", + "1.0\n", "\n", "BR: 0.0001\n", - "2.0\n", + "1.0\n", "\n", "BR: 0.0002\n", - "2.0\n", - "\n", - "BR: 0.00030000000000000003\n", - "2.0\n", - "\n", - "BR: 0.0004\n", "0.0\n", "\n", - "BR: 0.0005\n", - "2.0\n", + "BR: 0.0003\n", + "1.0\n", "\n", - "BR: 0.0006000000000000001\n", - "2.0\n", + "BR: 0.0004\n", + "1.0\n", + "\n", + "BR: 0.0005\n", + "1.5\n", + "\n", + "BR: 0.0006\n", + "0.5\n", "\n", "BR: 0.0007\n", - "2.0\n", + "0.0\n", "\n", "BR: 0.0008\n", - "2.0\n", + "0.5\n", "\n", - "BR: 0.0009000000000000001\n", - "2.0\n", + "BR: 0.0009\n", + "0.5\n", "\n", - "BR: 0.001\n", - "2.0\n", + "BR: 0.0010\n", + "0.5\n", "\n" ] } ], "source": [ "for s in range(len(l)):\n", - " print('BR: {}'.format(BR_steps[s]))\n", + " print('BR: {:.4f}'.format(BR_steps[s]))\n", " print(2*l[s]/len(CLs_values[0]))\n", " print()" ] }, { "cell_type": "code", - "execution_count": 54, + "execution_count": null, "metadata": {}, "outputs": [], "source": [