diff --git a/.ipynb_checkpoints/raremodel-nb-checkpoint.ipynb b/.ipynb_checkpoints/raremodel-nb-checkpoint.ipynb index 705aece..7b99362 100644 --- a/.ipynb_checkpoints/raremodel-nb-checkpoint.ipynb +++ b/.ipynb_checkpoints/raremodel-nb-checkpoint.ipynb @@ -1941,24 +1941,103 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 78, "metadata": { - "scrolled": true + "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "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: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: True\n", + "Toy 0/5\n" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mMultipleLimitsNotImplementedError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\basemodel.py\u001b[0m in \u001b[0;36m_limits_numeric_integrate\u001b[1;34m(self, limits, norm_range, name)\u001b[0m\n\u001b[0;32m 514\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--> 515\u001b[1;33m \u001b[0mintegral\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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 516\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mMultipleLimitsNotImplementedError\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\\core\\basemodel.py\u001b[0m in \u001b[0;36m_call_numeric_integrate\u001b[1;34m(self, limits, norm_range, name)\u001b[0m\n\u001b[0;32m 527\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 528\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_fallback_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\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 529\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\basemodel.py\u001b[0m in \u001b[0;36m_fallback_numeric_integrate\u001b[1;34m(self, limits, norm_range)\u001b[0m\n\u001b[0;32m 530\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_fallback_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\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--> 531\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_auto_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_func_to_integrate\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\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 532\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\limits.py\u001b[0m in \u001b[0;36mnew_func\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 1126\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1127\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\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 1128\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\basemodel.py\u001b[0m in \u001b[0;36m_auto_numeric_integrate\u001b[1;34m(self, func, limits, x, norm_range, **overwrite_options)\u001b[0m\n\u001b[0;32m 766\u001b[0m **overwrite_options)\n\u001b[1;32m--> 767\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_integration\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mauto_numeric_integrator\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m**\u001b[0m\u001b[0mintegration_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 768\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\limits.py\u001b[0m in \u001b[0;36mnew_func\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 1149\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mn_limits\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[0m\n\u001b[1;32m-> 1150\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mMultipleLimitsNotImplementedError\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1151\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mMultipleLimitsNotImplementedError\u001b[0m: ", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mKeyboardInterrupt\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 87\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 88\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---> 89\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 90\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 91\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 46\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 47\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_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[0mZfitLoss\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mList\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mParameter\u001b[0m\u001b[1;33m]\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---> 48\u001b[1;33m \u001b[0mgradients\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mloss\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgradients\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 49\u001b[0m \u001b[0mloss_val\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mloss\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalue\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 50\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_check_gradients\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[0mgradients\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mgradients\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\\core\\loss.py\u001b[0m in \u001b[0;36mgradients\u001b[1;34m(self, params)\u001b[0m\n\u001b[0;32m 156\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 157\u001b[0m \u001b[0mparams\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconvert_to_container\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[1;32m--> 158\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_gradients\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 159\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 160\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0madd_constraints\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mconstraints\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\\core\\loss.py\u001b[0m in \u001b[0;36m_gradients\u001b[1;34m(self, params)\u001b[0m\n\u001b[0;32m 249\u001b[0m \u001b[0mparams_todo\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mparam\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 250\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mparams_todo\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 251\u001b[1;33m \u001b[0mgradients\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mp\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mgrad\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mp\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mgrad\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mparams_todo\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msuper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_gradients\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mparams_todo\u001b[0m\u001b[1;33m)\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[0m\u001b[0;32m 252\u001b[0m \u001b[0mparams_cache\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgradients\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 253\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\loss.py\u001b[0m in \u001b[0;36m_gradients\u001b[1;34m(self, params)\u001b[0m\n\u001b[0;32m 218\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 219\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_gradients\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\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--> 220\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgradients\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\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;33m\u001b[0m\u001b[0m\n\u001b[0;32m 222\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\loss.py\u001b[0m in \u001b[0;36mvalue\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 196\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 197\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\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--> 198\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_value\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[0m\u001b[0;32m 199\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 200\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_value\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\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\\core\\loss.py\u001b[0m in \u001b[0;36m_value\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 232\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_value\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\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 233\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_cache\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'loss'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 234\u001b[1;33m \u001b[0mloss\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msuper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_value\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[0m\u001b[0;32m 235\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_cache\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'loss'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mloss\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 236\u001b[0m \u001b[1;32melse\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\\core\\loss.py\u001b[0m in \u001b[0;36m_value\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 201\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[0;32m 202\u001b[0m return self._loss_func(model=self.model, data=self.data, fit_range=self.fit_range,\n\u001b[1;32m--> 203\u001b[1;33m constraints=self.constraints)\n\u001b[0m\u001b[0;32m 204\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mNotImplementedError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 205\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mNotImplementedError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"_loss_func not properly defined!\"\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\\core\\loss.py\u001b[0m in \u001b[0;36m_loss_func\u001b[1;34m(self, model, data, fit_range, constraints)\u001b[0m\n\u001b[0;32m 264\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 265\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_loss_func\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfit_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mconstraints\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--> 266\u001b[1;33m \u001b[0mnll\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_unbinned_nll_tf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmodel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfit_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfit_range\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 267\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mconstraints\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 268\u001b[0m \u001b[0mconstraints\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreduce_sum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mc\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mconstraints\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\\core\\loss.py\u001b[0m in \u001b[0;36m_unbinned_nll_tf\u001b[1;34m(model, data, fit_range)\u001b[0m\n\u001b[0;32m 37\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mis_container\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmodel\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 38\u001b[0m nlls = [_unbinned_nll_tf(model=p, data=d, fit_range=r)\n\u001b[1;32m---> 39\u001b[1;33m for p, d, r in zip(model, data, fit_range)]\n\u001b[0m\u001b[0;32m 40\u001b[0m \u001b[0mnll_finished\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreduce_sum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnlls\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 41\u001b[0m \u001b[1;32melse\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\\core\\loss.py\u001b[0m in \u001b[0;36m\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m 37\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mis_container\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmodel\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 38\u001b[0m nlls = [_unbinned_nll_tf(model=p, data=d, fit_range=r)\n\u001b[1;32m---> 39\u001b[1;33m for p, d, r in zip(model, data, fit_range)]\n\u001b[0m\u001b[0;32m 40\u001b[0m \u001b[0mnll_finished\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreduce_sum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnlls\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 41\u001b[0m \u001b[1;32melse\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\\core\\loss.py\u001b[0m in \u001b[0;36m_unbinned_nll_tf\u001b[1;34m(model, data, fit_range)\u001b[0m\n\u001b[0;32m 41\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 42\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mset_data_range\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfit_range\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---> 43\u001b[1;33m \u001b[0mprobs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfit_range\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 44\u001b[0m \u001b[0mlog_probs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlog\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprobs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 45\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mweights\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\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\\core\\basepdf.py\u001b[0m in \u001b[0;36mpdf\u001b[1;34m(self, x, norm_range, name)\u001b[0m\n\u001b[0;32m 312\u001b[0m \u001b[0mnorm_range\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_check_input_norm_range\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcaller_name\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnone_is_error\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 313\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_convert_sort_x\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 314\u001b[1;33m \u001b[0mvalue\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_single_hook_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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 315\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mrun\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnumeric_checks\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 316\u001b[0m \u001b[0massert_op\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcheck_numerics\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmessage\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"Check if pdf output contains any NaNs of Infs\"\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\\core\\basepdf.py\u001b[0m in \u001b[0;36m_single_hook_pdf\u001b[1;34m(self, x, norm_range, name)\u001b[0m\n\u001b[0;32m 322\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 323\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_single_hook_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\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--> 324\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_hook_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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 325\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 326\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_hook_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"_hook_pdf\"\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\\core\\basepdf.py\u001b[0m in \u001b[0;36m_hook_pdf\u001b[1;34m(self, x, norm_range, name)\u001b[0m\n\u001b[0;32m 325\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 326\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_hook_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"_hook_pdf\"\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--> 327\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_norm_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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 328\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 329\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_norm_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'norm_pdf'\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\\core\\basepdf.py\u001b[0m in \u001b[0;36m_norm_pdf\u001b[1;34m(self, x, norm_range, name)\u001b[0m\n\u001b[0;32m 328\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 329\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_norm_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'norm_pdf'\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--> 330\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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 331\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 332\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_call_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\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\\core\\basepdf.py\u001b[0m in \u001b[0;36m_call_pdf\u001b[1;34m(self, x, norm_range, name)\u001b[0m\n\u001b[0;32m 336\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0msuppress\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNotImplementedError\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 337\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_log_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\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--> 338\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_fallback_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\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 339\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 340\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_fallback_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\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\\core\\basepdf.py\u001b[0m in \u001b[0;36m_fallback_pdf\u001b[1;34m(self, x, norm_range)\u001b[0m\n\u001b[0;32m 341\u001b[0m \u001b[0mpdf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call_unnormalized_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"_call_unnormalized_pdf\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 342\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlimits\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# identity check!\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 343\u001b[1;33m \u001b[0mpdf\u001b[0m \u001b[1;33m/=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_hook_normalization\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\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 344\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mpdf\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 345\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\basepdf.py\u001b[0m in \u001b[0;36m_hook_normalization\u001b[1;34m(self, limits, name)\u001b[0m\n\u001b[0;32m 244\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 245\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_hook_normalization\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"_hook_normalization\"\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--> 246\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call_normalization\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# no _norm_* needed\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 247\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 248\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_call_normalization\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\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\\core\\basepdf.py\u001b[0m in \u001b[0;36m_call_normalization\u001b[1;34m(self, limits, name)\u001b[0m\n\u001b[0;32m 251\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0msuppress\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNotImplementedError\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 252\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_normalization\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 253\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_fallback_normalization\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\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 254\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 255\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_fallback_normalization\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\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\\core\\basepdf.py\u001b[0m in \u001b[0;36m_fallback_normalization\u001b[1;34m(self, limits)\u001b[0m\n\u001b[0;32m 254\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 255\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_fallback_normalization\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\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--> 256\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_hook_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\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 257\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 258\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0mabc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mabstractmethod\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\\core\\basemodel.py\u001b[0m in \u001b[0;36m_hook_integrate\u001b[1;34m(self, limits, norm_range, name)\u001b[0m\n\u001b[0;32m 312\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 313\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_hook_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'hook_integrate'\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--> 314\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_norm_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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 315\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 316\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_norm_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'norm_integrate'\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\\core\\basemodel.py\u001b[0m in \u001b[0;36m_norm_integrate\u001b[1;34m(self, limits, norm_range, name)\u001b[0m\n\u001b[0;32m 316\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_norm_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'norm_integrate'\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 317\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--> 318\u001b[1;33m \u001b[0mintegral\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_limits_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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 319\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mNormRangeNotImplementedError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 320\u001b[0m \u001b[0munnormalized_integral\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_limits_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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\\core\\basemodel.py\u001b[0m in \u001b[0;36m_limits_integrate\u001b[1;34m(self, limits, norm_range, name)\u001b[0m\n\u001b[0;32m 325\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_limits_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\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 326\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--> 327\u001b[1;33m \u001b[0mintegral\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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 328\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mMultipleLimitsNotImplementedError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 329\u001b[0m \u001b[0mintegrals\u001b[0m \u001b[1;33m=\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\\core\\basemodel.py\u001b[0m in \u001b[0;36m_call_integrate\u001b[1;34m(self, limits, norm_range, name)\u001b[0m\n\u001b[0;32m 339\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0msuppress\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNotImplementedError\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 340\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_hook_analytic_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 341\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_fallback_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\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 342\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 343\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_fallback_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\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\\core\\basemodel.py\u001b[0m in \u001b[0;36m_fallback_integrate\u001b[1;34m(self, limits, norm_range)\u001b[0m\n\u001b[0;32m 354\u001b[0m \u001b[0mintegral\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_auto_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mpart_int\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 355\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mintegral\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 356\u001b[1;33m \u001b[0mintegral\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_hook_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\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 357\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mintegral\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 358\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\basemodel.py\u001b[0m in \u001b[0;36m_hook_numeric_integrate\u001b[1;34m(self, limits, norm_range, name)\u001b[0m\n\u001b[0;32m 498\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 499\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_hook_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'hook_numeric_integrate'\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--> 500\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_norm_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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 501\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 502\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_norm_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'norm_numeric_integrate'\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\\core\\basemodel.py\u001b[0m in \u001b[0;36m_norm_numeric_integrate\u001b[1;34m(self, limits, norm_range, name)\u001b[0m\n\u001b[0;32m 502\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_norm_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'norm_numeric_integrate'\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 503\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--> 504\u001b[1;33m \u001b[0mintegral\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_limits_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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 505\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mNormRangeNotImplementedError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 506\u001b[0m \u001b[1;32massert\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlimits\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"Internal: the caught Error should not be raised.\"\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\\core\\basemodel.py\u001b[0m in \u001b[0;36m_limits_numeric_integrate\u001b[1;34m(self, limits, norm_range, name)\u001b[0m\n\u001b[0;32m 517\u001b[0m \u001b[0mintegrals\u001b[0m \u001b[1;33m=\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 518\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0msub_limits\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0miter_limits\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mas_tuple\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\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--> 519\u001b[1;33m \u001b[0mintegrals\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msub_limits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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[0m\u001b[0;32m 520\u001b[0m \u001b[0mintegral\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreduce_sum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstack\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mintegrals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 521\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\basemodel.py\u001b[0m in \u001b[0;36m_call_numeric_integrate\u001b[1;34m(self, limits, norm_range, name)\u001b[0m\n\u001b[0;32m 526\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0msuppress\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mNotImplementedError\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 527\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 528\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_fallback_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\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 529\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 530\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_fallback_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\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\\core\\basemodel.py\u001b[0m in \u001b[0;36m_fallback_numeric_integrate\u001b[1;34m(self, limits, norm_range)\u001b[0m\n\u001b[0;32m 529\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 530\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_fallback_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\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--> 531\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_auto_numeric_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_func_to_integrate\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlimits\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlimits\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnorm_range\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnorm_range\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 532\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 533\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0m_BaseModel_register_check_support\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;32mTrue\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\\core\\limits.py\u001b[0m in \u001b[0;36mnew_func\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 1125\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mNormRangeNotImplementedError\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 1126\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1127\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\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 1128\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1129\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mnew_func\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\\core\\basemodel.py\u001b[0m in \u001b[0;36m_auto_numeric_integrate\u001b[1;34m(self, func, limits, x, norm_range, **overwrite_options)\u001b[0m\n\u001b[0;32m 765\u001b[0m \"draws_per_dim\": self.integration.draws_per_dim},\n\u001b[0;32m 766\u001b[0m **overwrite_options)\n\u001b[1;32m--> 767\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_integration\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mauto_numeric_integrator\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m**\u001b[0m\u001b[0mintegration_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 768\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 769\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0msupports\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\\core\\limits.py\u001b[0m in \u001b[0;36mnew_func\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 1150\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mMultipleLimitsNotImplementedError\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1151\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1152\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\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 1153\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1154\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mnew_func\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\\core\\limits.py\u001b[0m in \u001b[0;36mnew_func\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 1125\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mNormRangeNotImplementedError\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 1126\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1127\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\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 1128\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1129\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mnew_func\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\\core\\integration.py\u001b[0m in \u001b[0;36mauto_integrate\u001b[1;34m(func, limits, n_axes, x, method, dtype, mc_sampler, mc_options)\u001b[0m\n\u001b[0;32m 36\u001b[0m integral = mc_integrate(x=x, func=func, limits=limits, n_axes=n_axes, method=method, dtype=dtype,\n\u001b[0;32m 37\u001b[0m \u001b[0mmc_sampler\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmc_sampler\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdraws_per_dim\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdraws_per_dim\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 38\u001b[1;33m importance_sampling=None)\n\u001b[0m\u001b[0;32m 39\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mintegral\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 40\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\zfit\\core\\integration.py\u001b[0m in \u001b[0;36mmc_integrate\u001b[1;34m(func, limits, axes, x, n_axes, draws_per_dim, method, dtype, mc_sampler, importance_sampling)\u001b[0m\n\u001b[0;32m 139\u001b[0m \u001b[1;31m# convert rnd samples with value to feedable vector\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[0mreduce_axis\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m1\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mpartial\u001b[0m \u001b[1;32melse\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 141\u001b[1;33m \u001b[0mavg\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreduce_mean\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mreduce_axis\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 142\u001b[0m \u001b[1;31m# avg = tfp.monte_carlo.expectation(f=func, samples=x, axis=reduce_axis)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 143\u001b[0m \u001b[1;31m# TODO: importance sampling?\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\\core\\basepdf.py\u001b[0m in \u001b[0;36m_func_to_integrate\u001b[1;34m(self, x)\u001b[0m\n\u001b[0;32m 141\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 142\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_func_to_integrate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mztyping\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mXType\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--> 143\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0munnormalized_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\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 144\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 145\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_func_to_sample_from\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\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\\core\\basepdf.py\u001b[0m in \u001b[0;36munnormalized_pdf\u001b[1;34m(self, x, component_norm_range, name)\u001b[0m\n\u001b[0;32m 279\u001b[0m component_norm_range = self._check_input_norm_range(component_norm_range, caller_name=name,\n\u001b[0;32m 280\u001b[0m none_is_error=False)\n\u001b[1;32m--> 281\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_single_hook_unnormalized_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcomponent_norm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\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 282\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 283\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_single_hook_unnormalized_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcomponent_norm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\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\\core\\basepdf.py\u001b[0m in \u001b[0;36m_single_hook_unnormalized_pdf\u001b[1;34m(self, x, component_norm_range, name)\u001b[0m\n\u001b[0;32m 282\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 283\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_single_hook_unnormalized_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcomponent_norm_range\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\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--> 284\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call_unnormalized_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\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 285\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 286\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_call_unnormalized_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\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\\core\\basepdf.py\u001b[0m in \u001b[0;36m_call_unnormalized_pdf\u001b[1;34m(self, x, name)\u001b[0m\n\u001b[0;32m 287\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_name_scope\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalues\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m]\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 288\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--> 289\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_unnormalized_pdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\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 290\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mValueError\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 291\u001b[0m raise ShapeIncompatibleError(\"Most probably, the number of obs the pdf was designed for\"\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36m_unnormalized_pdf\u001b[1;34m(self, x)\u001b[0m\n\u001b[0;32m 179\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 180\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 181\u001b[1;33m \u001b[0mfuncs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrho_res\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0momega_res\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mphi_res\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mjpsi_res\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mpsi2s_res\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mp3770_res\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mp4040_res\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m \u001b[0mp4160_res\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mp4415_res\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mP2_D\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mttau_cusp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\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 182\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 183\u001b[0m \u001b[0mvec_f\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvec\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfuncs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb0_0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb0_1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb0_2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbplus_0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbplus_1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbplus_2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbT_0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbT_1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbT_2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36mttau_cusp\u001b[1;34m(q)\u001b[0m\n\u001b[0;32m 176\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 177\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mttau_cusp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mq\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--> 178\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'C_tt'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m*\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mh_S\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'tau_mass'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m-\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mh_P\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'tau_mass'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mq\u001b[0m\u001b[1;33m)\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[0m\u001b[0;32m 179\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 180\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36mh_P\u001b[1;34m(m, q)\u001b[0m\n\u001b[0;32m 17\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mh_P\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mq\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 18\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 19\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m-\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m/\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mq\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mh_S\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mq\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 20\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 21\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mtwo_p_ccbar\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmD\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mm_D_bar\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mm_D_star\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mq\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\u001b[0m in \u001b[0;36mh_S\u001b[1;34m(m, q)\u001b[0m\n\u001b[0;32m 13\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mh_S\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mq\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 14\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 15\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m-\u001b[0m \u001b[0mG\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m-\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m/\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mq\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m)\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[0m\u001b[0;32m 16\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 17\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mh_P\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mm\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mq\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\u001b[0m in \u001b[0;36mG\u001b[1;34m(y)\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0matan\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\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 8\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m \u001b[0mbig_bracket\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwhere\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconstant\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0.0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0minner_rect_bracket\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0minner_right\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\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[0m\u001b[0;32m 10\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mabs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mbig_bracket\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36minner_rect_bracket\u001b[1;34m(q)\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0minner_rect_bracket\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mq\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----> 4\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlog\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_complex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcomplex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconstant\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mztf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconstant\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpi\u001b[0m\u001b[1;33m)\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[0m\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0minner_right\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mq\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\\ztf\\zextension.py\u001b[0m in \u001b[0;36mconstant\u001b[1;34m(value, dtype, shape, name, verify_shape)\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 16\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mconstant\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mztypes\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfloat\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mshape\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"Const\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mverify_shape\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\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---> 17\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconstant\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mshape\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mverify_shape\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mverify_shape\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 18\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\framework\\constant_op.py\u001b[0m in \u001b[0;36mconstant_v1\u001b[1;34m(value, dtype, shape, name, verify_shape)\u001b[0m\n\u001b[0;32m 177\u001b[0m \"\"\"\n\u001b[0;32m 178\u001b[0m return _constant_impl(value, dtype, shape, name, verify_shape=verify_shape,\n\u001b[1;32m--> 179\u001b[1;33m allow_broadcast=False)\n\u001b[0m\u001b[0;32m 180\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 181\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\framework\\constant_op.py\u001b[0m in \u001b[0;36m_constant_impl\u001b[1;34m(value, dtype, shape, name, verify_shape, allow_broadcast)\u001b[0m\n\u001b[0;32m 287\u001b[0m attrs={\"value\": tensor_value,\n\u001b[0;32m 288\u001b[0m \"dtype\": dtype_value},\n\u001b[1;32m--> 289\u001b[1;33m name=name).outputs[0]\n\u001b[0m\u001b[0;32m 290\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mconst_tensor\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 291\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\util\\deprecation.py\u001b[0m in \u001b[0;36mnew_func\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 505\u001b[0m \u001b[1;34m'in a future version'\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mdate\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32melse\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'after %s'\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0mdate\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 506\u001b[0m instructions)\n\u001b[1;32m--> 507\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\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 508\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 509\u001b[0m doc = _add_deprecated_arg_notice_to_docstring(\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\u001b[0m in \u001b[0;36mcreate_op\u001b[1;34m(***failed resolving arguments***)\u001b[0m\n\u001b[0;32m 3298\u001b[0m \u001b[0minput_types\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0minput_types\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3299\u001b[0m \u001b[0moriginal_op\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_default_original_op\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 3300\u001b[1;33m op_def=op_def)\n\u001b[0m\u001b[0;32m 3301\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_create_op_helper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mret\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcompute_device\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcompute_device\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3302\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mret\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\.conda\\envs\\rmd\\lib\\site-packages\\tensorflow\\python\\framework\\ops.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, node_def, g, inputs, output_types, control_inputs, input_types, original_op, op_def)\u001b[0m\n\u001b[0;32m 1815\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1816\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mop_def\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1817\u001b[1;33m \u001b[0mop_def\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_graph\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_op_def\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnode_def\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mop\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 1818\u001b[0m \u001b[1;31m# TODO(skyewm): op_def_library.apply_op() flattens the incoming inputs.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1819\u001b[0m \u001b[1;31m# Refactor so we don't have to do this here.\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\\tensorflow\\python\\framework\\ops.py\u001b[0m in \u001b[0;36m_get_op_def\u001b[1;34m(self, type)\u001b[0m\n\u001b[0;32m 3685\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0mc_api_util\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtf_buffer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mbuf\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3686\u001b[0m \u001b[1;31m# pylint: disable=protected-access\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 3687\u001b[1;33m \u001b[0mc_api\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mTF_GraphGetOpDef\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_c_graph\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcompat\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mas_bytes\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbuf\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 3688\u001b[0m \u001b[1;31m# pylint: enable=protected-access\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3689\u001b[0m \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mc_api\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mTF_GetBuffer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbuf\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mKeyboardInterrupt\u001b[0m: " ] } ], "source": [ "# zfit.run.numeric_checks = False \n", "\n", + "load = False\n", + "\n", "fitting_range = 'cut'\n", "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\n", "cut_BR = 1.0 - (6.02e-5 + 4.97e-6)/total_BR\n", @@ -1991,108 +2070,100 @@ "\n", "__ = -1\n", "\n", - "# for Ctt_step in Ctt_steps:\n", - " \n", - "# __ += 1\n", - " \n", - "# for floaty in [True, False]:\n", "\n", - "# Ctt_floating = floaty\n", - " \n", - "# Nll_list.append([])\n", + "#-----------------------------------------------------\n", "\n", - "# while len(Nll_list[-1]) < nr_of_toys:\n", - " \n", - "# print('Step: {0}/{1}'.format(__, ste))\n", - " \n", - "# print('Current Ctt: {0}'.format(Ctt_step))\n", - "# print('Ctt floating: {0}'.format(floaty))\n", - " \n", - "# print('Toy {0}/{1}'.format(len(Nll_list[-1]), nr_of_toys))\n", - " \n", - "# reset_param_values()\n", - " \n", - "# if floaty:\n", - "# Ctt.set_value(Ctt_step)\n", - "# else:\n", - "# Ctt.set_value(0.0)\n", - " \n", - "# if floaty:\n", - "# sampler.resample(n=nevents)\n", - "# s = sampler.unstack_x()\n", - "# total_samp = zfit.run(s)\n", - "# calls = 0\n", - "# c = 1\n", + "if not load:\n", "\n", - "# data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit)\n", + " for Ctt_step in Ctt_steps:\n", "\n", - "# ### Fit data\n", + " __ += 1\n", "\n", - "# for param in total_f_fit.get_dependents():\n", - "# param.randomize()\n", + "# if __ != 8:\n", + "# break\n", "\n", - "# nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints)\n", + " for floaty in [True, False]:\n", "\n", - "# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5)\n", - "# # minimizer._use_tfgrad = False\n", - "# result = minimizer.minimize(nll)\n", + " Ctt.floating = floaty\n", "\n", - "# # print(\"Function minimum:\", result.fmin)\n", - "# # print(\"Hesse errors:\", result.hesse())\n", + " Nll_list.append([])\n", "\n", - "# params = result.params\n", + " while len(Nll_list[-1]) < nr_of_toys:\n", "\n", - "# if result.converged:\n", - "# Nll_list[-1].append(result.fmin)\n", - " \n", - "# _t = int(time.time()-start)\n", - " \n", - "# print('Time Taken: {}'.format(display_time(int(_t))))\n", - " \n", - "# print('Predicted time left: {}'.format(display_time(int((_t/(__+1)*(ste-__-1))))))\n" + " print('Step: {0}/{1}'.format(__, ste))\n", + "\n", + " print('Current Ctt: {0}'.format(Ctt_step))\n", + " print('Ctt floating: {0}'.format(floaty))\n", + "\n", + " print('Toy {0}/{1}'.format(len(Nll_list[-1]), nr_of_toys))\n", + "\n", + " reset_param_values()\n", + "\n", + " if floaty:\n", + " Ctt.set_value(Ctt_step)\n", + " else:\n", + " Ctt.set_value(0.0)\n", + "\n", + " if floaty:\n", + " sampler.resample(n=nevents)\n", + " s = sampler.unstack_x()\n", + " total_samp = zfit.run(s)\n", + " calls = 0\n", + " c = 1\n", + "\n", + " data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit)\n", + "\n", + " ### Fit data\n", + "\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", + "\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", + "\n", + " params = result.params\n", + "\n", + " if result.converged:\n", + " Nll_list[-1].append(result.fmin)\n", + "\n", + " _t = int(time.time()-start)\n", + "\n", + " print('Time Taken: {}'.format(display_time(int(_t))))\n", + "\n", + " print('Predicted time left: {}'.format(display_time(int((_t/(__+1)*(ste-__-1))))))\n" ] }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 74, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "(11, 5)\n", - "2253432\n", - "(11, 10)\n", - "(11, 15)\n", - "(11, 20)\n", - "(11, 25)\n", - "(11, 30)\n", - "(11, 35)\n", - "(11, 40)\n", - "(11, 45)\n", - "(11, 50)\n", - "(11, 55)\n", - "(11, 60)\n", - "(11, 65)\n", - "(11, 70)\n", - "(11, 75)\n", - "(11, 80)\n", - "(11, 85)\n", - "(11, 90)\n", - "(11, 95)\n" + "ename": "IndexError", + "evalue": "list index out of range", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mIndexError\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 28\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 29\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0ms\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mste\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---> 30\u001b[1;33m \u001b[0mNll_list\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mextend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_Nll_list\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0ms\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[0m\u001b[0;32m 31\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 32\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34mr\"{}/{}/data/CLs/{}-{}_{}s--CLs_list.pkl\"\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_dir\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mjob\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mste\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"rb\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0minput_file\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mIndexError\u001b[0m: list index out of range" ] } ], "source": [ - "load = True\n", - "\n", "if load:\n", " Nll_list = []\n", " CLs_values = []\n", - " jobs = os.listdir('data/CLs/finished/')\n", "\n", - " _dir = 'data/CLs/finished/'\n", + " _dir = 'data/CLs/finished/f1d41'\n", + " \n", + " jobs = os.listdir(_dir)\n", " \n", " for s in range(ste):\n", " CLs_values.append([])\n", @@ -2103,7 +2174,7 @@ " __ = 0\n", " \n", " for job in jobs:\n", - " if not os.path.exists(\"{}{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl\".format(_dir, job, mi,ma,ste)):\n", + " if not os.path.exists(\"{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl\".format(_dir, job, mi,ma,ste)):\n", " print(job)\n", " continue\n", " __ +=1\n", @@ -2111,13 +2182,13 @@ "# if __ > 2:\n", "# break\n", " \n", - " with open(r\"{}{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl\".format(_dir, job, mi,ma,ste), \"rb\") as input_file:\n", + " with open(r\"{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl\".format(_dir, job, mi,ma,ste), \"rb\") as input_file:\n", " _Nll_list = pkl.load(input_file)\n", " \n", " for s in range(2*ste):\n", " Nll_list[s].extend(_Nll_list[s])\n", " \n", - " with open(r\"{}{}/data/CLs/{}-{}_{}s--CLs_list.pkl\".format(_dir, job, mi,ma,ste), \"rb\") as input_file:\n", + " with open(r\"{}/{}/data/CLs/{}-{}_{}s--CLs_list.pkl\".format(_dir, job, mi,ma,ste), \"rb\") as input_file:\n", " _CLs_values = pkl.load(input_file)\n", " \n", " for s in range(ste):\n", @@ -2128,7 +2199,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 63, "metadata": {}, "outputs": [], "source": [ @@ -2148,16 +2219,16 @@ " os.mkdir(dirName)\n", " print(\"Directory \" , dirName , \" Created \")\n", "\n", - " with open(\"data/CLs/{}-{}_{}s--CLs_Nll_list.pkl\".format(mi,ma,ste), \"wb\") as f:\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", - " with open(\"data/CLs/{}-{}_{}s--CLs_list.pkl\".format(mi,ma,ste), \"wb\") as f:\n", + " with open(\"{}/{}-{}_{}s--CLs_list.pkl\".format(dirName, mi,ma,ste), \"wb\") as f:\n", " pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL)" ] }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 64, "metadata": {}, "outputs": [], "source": [ @@ -2173,7 +2244,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 65, "metadata": {}, "outputs": [ { @@ -2206,7 +2277,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 66, "metadata": {}, "outputs": [ { @@ -2258,10 +2329,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# print(np.array(Nll_list[0][:10])-np.array(Nll_list[1][:10]))" + ] }, { "cell_type": "code", diff --git a/__pycache__/pdg_const.cpython-37.pyc b/__pycache__/pdg_const.cpython-37.pyc index fbbaa17..fbac169 100644 --- a/__pycache__/pdg_const.cpython-37.pyc +++ b/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl index 68a2d71..8848959 100644 --- a/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ b/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/0.0-0.001_11s--CLs_list.pkl index 48555da..92c3c88 100644 --- a/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ b/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/2253431/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253431/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index f348758..0000000 --- a/data/CLs/finished/2253431/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253431/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253431/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index f036d2d..0000000 --- a/data/CLs/finished/2253431/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253431/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253431/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index f2f8a0b..0000000 --- a/data/CLs/finished/2253431/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253431/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253431/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 48555da..0000000 --- a/data/CLs/finished/2253431/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253431/helperfunctions.py b/data/CLs/finished/2253431/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253431/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253431/pdg_const.py b/data/CLs/finished/2253431/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253431/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253431/raremodel-nb.py b/data/CLs/finished/2253431/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253431/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253431/test.png b/data/CLs/finished/2253431/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253431/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253432/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253432/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index b8817d2..0000000 --- a/data/CLs/finished/2253432/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253432/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253432/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index 75fe734..0000000 --- a/data/CLs/finished/2253432/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253432/helperfunctions.py b/data/CLs/finished/2253432/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253432/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253432/pdg_const.py b/data/CLs/finished/2253432/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253432/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253432/raremodel-nb.py b/data/CLs/finished/2253432/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253432/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253432/test.png b/data/CLs/finished/2253432/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253432/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253433/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253433/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index ccdcb76..0000000 --- a/data/CLs/finished/2253433/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253433/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253433/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index 3855f2c..0000000 --- a/data/CLs/finished/2253433/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253433/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253433/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index f2eb1f4..0000000 --- a/data/CLs/finished/2253433/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253433/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253433/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index d9996b2..0000000 --- a/data/CLs/finished/2253433/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253433/helperfunctions.py b/data/CLs/finished/2253433/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253433/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253433/pdg_const.py b/data/CLs/finished/2253433/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253433/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253433/raremodel-nb.py b/data/CLs/finished/2253433/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253433/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253433/test.png b/data/CLs/finished/2253433/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253433/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253434/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253434/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index 245385f..0000000 --- a/data/CLs/finished/2253434/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253434/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253434/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index abcbe46..0000000 --- a/data/CLs/finished/2253434/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253434/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253434/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index cffa395..0000000 --- a/data/CLs/finished/2253434/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253434/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253434/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 39c9ba5..0000000 --- a/data/CLs/finished/2253434/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253434/helperfunctions.py b/data/CLs/finished/2253434/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253434/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253434/pdg_const.py b/data/CLs/finished/2253434/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253434/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253434/raremodel-nb.py b/data/CLs/finished/2253434/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253434/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253434/test.png b/data/CLs/finished/2253434/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253434/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253435/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253435/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index 415ca46..0000000 --- a/data/CLs/finished/2253435/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253435/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253435/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index 6f5e4b1..0000000 --- a/data/CLs/finished/2253435/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253435/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253435/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 30a1202..0000000 --- a/data/CLs/finished/2253435/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253435/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253435/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 21e44aa..0000000 --- a/data/CLs/finished/2253435/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253435/helperfunctions.py b/data/CLs/finished/2253435/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253435/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253435/pdg_const.py b/data/CLs/finished/2253435/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253435/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253435/raremodel-nb.py b/data/CLs/finished/2253435/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253435/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253435/test.png b/data/CLs/finished/2253435/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253435/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253436/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253436/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index 2dcc1ff..0000000 --- a/data/CLs/finished/2253436/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253436/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253436/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index aab4b08..0000000 --- a/data/CLs/finished/2253436/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253436/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253436/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 4bd8ee9..0000000 --- a/data/CLs/finished/2253436/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253436/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253436/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 1a4d11f..0000000 --- a/data/CLs/finished/2253436/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253436/helperfunctions.py b/data/CLs/finished/2253436/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253436/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253436/pdg_const.py b/data/CLs/finished/2253436/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253436/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253436/raremodel-nb.py b/data/CLs/finished/2253436/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253436/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253436/test.png b/data/CLs/finished/2253436/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253436/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253437/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253437/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index a952cc2..0000000 --- a/data/CLs/finished/2253437/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253437/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253437/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index 3ebfc8b..0000000 --- a/data/CLs/finished/2253437/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253437/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253437/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index a7f1971..0000000 --- a/data/CLs/finished/2253437/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253437/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253437/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 10c75e5..0000000 --- a/data/CLs/finished/2253437/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253437/helperfunctions.py b/data/CLs/finished/2253437/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253437/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253437/pdg_const.py b/data/CLs/finished/2253437/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253437/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253437/raremodel-nb.py b/data/CLs/finished/2253437/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253437/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253437/test.png b/data/CLs/finished/2253437/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253437/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253438/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253438/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index 4a24a80..0000000 --- a/data/CLs/finished/2253438/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253438/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253438/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index 7a4ec24..0000000 --- a/data/CLs/finished/2253438/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253438/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253438/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 9d4a4b1..0000000 --- a/data/CLs/finished/2253438/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253438/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253438/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 43b12af..0000000 --- a/data/CLs/finished/2253438/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253438/helperfunctions.py b/data/CLs/finished/2253438/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253438/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253438/pdg_const.py b/data/CLs/finished/2253438/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253438/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253438/raremodel-nb.py b/data/CLs/finished/2253438/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253438/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253438/test.png b/data/CLs/finished/2253438/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253438/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253439/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253439/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index daf9afe..0000000 --- a/data/CLs/finished/2253439/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253439/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253439/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index 177b05f..0000000 --- a/data/CLs/finished/2253439/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253439/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253439/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 75c8434..0000000 --- a/data/CLs/finished/2253439/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253439/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253439/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 2b7636d..0000000 --- a/data/CLs/finished/2253439/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253439/helperfunctions.py b/data/CLs/finished/2253439/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253439/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253439/pdg_const.py b/data/CLs/finished/2253439/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253439/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253439/raremodel-nb.py b/data/CLs/finished/2253439/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253439/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253439/test.png b/data/CLs/finished/2253439/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253439/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253440/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253440/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index 396b3f6..0000000 --- a/data/CLs/finished/2253440/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253440/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253440/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index 0e22fd9..0000000 --- a/data/CLs/finished/2253440/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253440/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253440/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 08f8c23..0000000 --- a/data/CLs/finished/2253440/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253440/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253440/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index a6c9d79..0000000 --- a/data/CLs/finished/2253440/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253440/helperfunctions.py b/data/CLs/finished/2253440/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253440/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253440/pdg_const.py b/data/CLs/finished/2253440/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253440/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253440/raremodel-nb.py b/data/CLs/finished/2253440/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253440/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253440/test.png b/data/CLs/finished/2253440/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253440/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253441/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253441/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index 1b7184a..0000000 --- a/data/CLs/finished/2253441/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253441/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253441/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index efb6c2a..0000000 --- a/data/CLs/finished/2253441/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253441/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253441/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 37d8fff..0000000 --- a/data/CLs/finished/2253441/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253441/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253441/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index a624b87..0000000 --- a/data/CLs/finished/2253441/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253441/helperfunctions.py b/data/CLs/finished/2253441/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253441/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253441/pdg_const.py b/data/CLs/finished/2253441/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253441/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253441/raremodel-nb.py b/data/CLs/finished/2253441/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253441/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253441/test.png b/data/CLs/finished/2253441/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253441/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253442/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253442/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index 2f8722e..0000000 --- a/data/CLs/finished/2253442/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253442/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253442/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index b103199..0000000 --- a/data/CLs/finished/2253442/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253442/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253442/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 09eb853..0000000 --- a/data/CLs/finished/2253442/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253442/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253442/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index ed83943..0000000 --- a/data/CLs/finished/2253442/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253442/helperfunctions.py b/data/CLs/finished/2253442/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253442/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253442/pdg_const.py b/data/CLs/finished/2253442/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253442/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253442/raremodel-nb.py b/data/CLs/finished/2253442/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253442/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253442/test.png b/data/CLs/finished/2253442/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253442/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253443/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253443/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index a0f1063..0000000 --- a/data/CLs/finished/2253443/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253443/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253443/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index d8cfa10..0000000 --- a/data/CLs/finished/2253443/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253443/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253443/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 32171e3..0000000 --- a/data/CLs/finished/2253443/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253443/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253443/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 1bdab9d..0000000 --- a/data/CLs/finished/2253443/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253443/helperfunctions.py b/data/CLs/finished/2253443/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253443/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253443/pdg_const.py b/data/CLs/finished/2253443/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253443/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253443/raremodel-nb.py b/data/CLs/finished/2253443/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253443/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253443/test.png b/data/CLs/finished/2253443/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253443/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253444/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253444/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index 2c66cb7..0000000 --- a/data/CLs/finished/2253444/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253444/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253444/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index ff12e62..0000000 --- a/data/CLs/finished/2253444/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253444/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253444/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 76ce4c8..0000000 --- a/data/CLs/finished/2253444/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253444/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253444/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 0d7cb79..0000000 --- a/data/CLs/finished/2253444/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253444/helperfunctions.py b/data/CLs/finished/2253444/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253444/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253444/pdg_const.py b/data/CLs/finished/2253444/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253444/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253444/raremodel-nb.py b/data/CLs/finished/2253444/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253444/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253444/test.png b/data/CLs/finished/2253444/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253444/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253445/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253445/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index 2e62a66..0000000 --- a/data/CLs/finished/2253445/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253445/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253445/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index 793acd9..0000000 --- a/data/CLs/finished/2253445/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253445/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253445/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index e39e340..0000000 --- a/data/CLs/finished/2253445/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253445/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253445/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index b792ace..0000000 --- a/data/CLs/finished/2253445/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253445/helperfunctions.py b/data/CLs/finished/2253445/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253445/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253445/pdg_const.py b/data/CLs/finished/2253445/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253445/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253445/raremodel-nb.py b/data/CLs/finished/2253445/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253445/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253445/test.png b/data/CLs/finished/2253445/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253445/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253446/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253446/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index e8d5d41..0000000 --- a/data/CLs/finished/2253446/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253446/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253446/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index 877a535..0000000 --- a/data/CLs/finished/2253446/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253446/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253446/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 630fd13..0000000 --- a/data/CLs/finished/2253446/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253446/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253446/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 15995d5..0000000 --- a/data/CLs/finished/2253446/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253446/helperfunctions.py b/data/CLs/finished/2253446/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253446/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253446/pdg_const.py b/data/CLs/finished/2253446/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253446/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253446/raremodel-nb.py b/data/CLs/finished/2253446/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253446/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253446/test.png b/data/CLs/finished/2253446/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253446/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253447/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253447/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index 3851f70..0000000 --- a/data/CLs/finished/2253447/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253447/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253447/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index dbddaf8..0000000 --- a/data/CLs/finished/2253447/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253447/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253447/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 5f59c52..0000000 --- a/data/CLs/finished/2253447/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253447/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253447/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 28c9d1d..0000000 --- a/data/CLs/finished/2253447/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253447/helperfunctions.py b/data/CLs/finished/2253447/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253447/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253447/pdg_const.py b/data/CLs/finished/2253447/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253447/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253447/raremodel-nb.py b/data/CLs/finished/2253447/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253447/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253447/test.png b/data/CLs/finished/2253447/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253447/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253448/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253448/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index b8a67cc..0000000 --- a/data/CLs/finished/2253448/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253448/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253448/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index bf09300..0000000 --- a/data/CLs/finished/2253448/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253448/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253448/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index acd655d..0000000 --- a/data/CLs/finished/2253448/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253448/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253448/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index b124a77..0000000 --- a/data/CLs/finished/2253448/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253448/helperfunctions.py b/data/CLs/finished/2253448/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253448/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253448/pdg_const.py b/data/CLs/finished/2253448/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253448/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253448/raremodel-nb.py b/data/CLs/finished/2253448/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253448/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253448/test.png b/data/CLs/finished/2253448/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253448/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253449/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253449/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index 4f5c6f6..0000000 --- a/data/CLs/finished/2253449/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253449/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253449/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index 9ba5412..0000000 --- a/data/CLs/finished/2253449/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253449/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253449/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index b04bbd1..0000000 --- a/data/CLs/finished/2253449/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253449/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253449/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 1073872..0000000 --- a/data/CLs/finished/2253449/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253449/helperfunctions.py b/data/CLs/finished/2253449/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253449/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253449/pdg_const.py b/data/CLs/finished/2253449/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253449/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253449/raremodel-nb.py b/data/CLs/finished/2253449/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253449/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253449/test.png b/data/CLs/finished/2253449/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253449/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253450/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/2253450/__pycache__/helperfunctions.cpython-37.pyc deleted file mode 100644 index d8dbb04..0000000 --- a/data/CLs/finished/2253450/__pycache__/helperfunctions.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253450/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/2253450/__pycache__/pdg_const.cpython-37.pyc deleted file mode 100644 index 6abad45..0000000 --- a/data/CLs/finished/2253450/__pycache__/pdg_const.cpython-37.pyc +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253450/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/2253450/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl deleted file mode 100644 index 04c8ecc..0000000 --- a/data/CLs/finished/2253450/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253450/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/2253450/data/CLs/0.0-0.001_11s--CLs_list.pkl deleted file mode 100644 index 8af05c0..0000000 --- a/data/CLs/finished/2253450/data/CLs/0.0-0.001_11s--CLs_list.pkl +++ /dev/null Binary files differ diff --git a/data/CLs/finished/2253450/helperfunctions.py b/data/CLs/finished/2253450/helperfunctions.py deleted file mode 100644 index 88e120f..0000000 --- a/data/CLs/finished/2253450/helperfunctions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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/2253450/pdg_const.py b/data/CLs/finished/2253450/pdg_const.py deleted file mode 100644 index 6645dd7..0000000 --- a/data/CLs/finished/2253450/pdg_const.py +++ /dev/null @@ -1,226 +0,0 @@ -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/2253450/raremodel-nb.py b/data/CLs/finished/2253450/raremodel-nb.py deleted file mode 100644 index ea561e0..0000000 --- a/data/CLs/finished/2253450/raremodel-nb.py +++ /dev/null @@ -1,1791 +0,0 @@ -#!/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 - -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 = 5 -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) - -__ = -1 - -for Ctt_step in Ctt_steps: - - __ += 1 - - for floaty in [True, False]: - - Ctt_floating = floaty - - Nll_list.append([]) - - 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[50]: - - -dirName = 'data/CLs' - -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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) - -with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: - pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) - - -# In[51]: - - -print(CLs_values) - - -# In[ ]: - - - - - -# In[ ]: - - - - diff --git a/data/CLs/finished/2253450/test.png b/data/CLs/finished/2253450/test.png deleted file mode 100644 index 1455457..0000000 --- a/data/CLs/finished/2253450/test.png +++ /dev/null Binary files differ diff --git a/data/CLs/finished/f1d1/2253431/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253431/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..f348758 --- /dev/null +++ b/data/CLs/finished/f1d1/2253431/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253431/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253431/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..f036d2d --- /dev/null +++ b/data/CLs/finished/f1d1/2253431/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253431/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253431/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..f2f8a0b --- /dev/null +++ b/data/CLs/finished/f1d1/2253431/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253431/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253431/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..48555da --- /dev/null +++ b/data/CLs/finished/f1d1/2253431/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253431/helperfunctions.py b/data/CLs/finished/f1d1/2253431/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253431/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/2253431/pdg_const.py b/data/CLs/finished/f1d1/2253431/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253431/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/2253431/raremodel-nb.py b/data/CLs/finished/f1d1/2253431/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253431/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253431/test.png b/data/CLs/finished/f1d1/2253431/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253431/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253433/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253433/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..ccdcb76 --- /dev/null +++ b/data/CLs/finished/f1d1/2253433/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253433/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253433/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..3855f2c --- /dev/null +++ b/data/CLs/finished/f1d1/2253433/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253433/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253433/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..f2eb1f4 --- /dev/null +++ b/data/CLs/finished/f1d1/2253433/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253433/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253433/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..d9996b2 --- /dev/null +++ b/data/CLs/finished/f1d1/2253433/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253433/helperfunctions.py b/data/CLs/finished/f1d1/2253433/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253433/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/2253433/pdg_const.py b/data/CLs/finished/f1d1/2253433/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253433/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/2253433/raremodel-nb.py b/data/CLs/finished/f1d1/2253433/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253433/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253433/test.png b/data/CLs/finished/f1d1/2253433/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253433/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253434/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253434/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..245385f --- /dev/null +++ b/data/CLs/finished/f1d1/2253434/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253434/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253434/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..abcbe46 --- /dev/null +++ b/data/CLs/finished/f1d1/2253434/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253434/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253434/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..cffa395 --- /dev/null +++ b/data/CLs/finished/f1d1/2253434/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253434/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253434/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..39c9ba5 --- /dev/null +++ b/data/CLs/finished/f1d1/2253434/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253434/helperfunctions.py b/data/CLs/finished/f1d1/2253434/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253434/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/2253434/pdg_const.py b/data/CLs/finished/f1d1/2253434/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253434/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/2253434/raremodel-nb.py b/data/CLs/finished/f1d1/2253434/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253434/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253434/test.png b/data/CLs/finished/f1d1/2253434/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253434/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253435/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253435/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..415ca46 --- /dev/null +++ b/data/CLs/finished/f1d1/2253435/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253435/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253435/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..6f5e4b1 --- /dev/null +++ b/data/CLs/finished/f1d1/2253435/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253435/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253435/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..30a1202 --- /dev/null +++ b/data/CLs/finished/f1d1/2253435/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253435/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253435/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..21e44aa --- /dev/null +++ b/data/CLs/finished/f1d1/2253435/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253435/helperfunctions.py b/data/CLs/finished/f1d1/2253435/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253435/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/2253435/pdg_const.py b/data/CLs/finished/f1d1/2253435/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253435/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/2253435/raremodel-nb.py b/data/CLs/finished/f1d1/2253435/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253435/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253435/test.png b/data/CLs/finished/f1d1/2253435/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253435/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253436/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253436/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..2dcc1ff --- /dev/null +++ b/data/CLs/finished/f1d1/2253436/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253436/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253436/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..aab4b08 --- /dev/null +++ b/data/CLs/finished/f1d1/2253436/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253436/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253436/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..4bd8ee9 --- /dev/null +++ b/data/CLs/finished/f1d1/2253436/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253436/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253436/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..1a4d11f --- /dev/null +++ b/data/CLs/finished/f1d1/2253436/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253436/helperfunctions.py b/data/CLs/finished/f1d1/2253436/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253436/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/2253436/pdg_const.py b/data/CLs/finished/f1d1/2253436/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253436/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/2253436/raremodel-nb.py b/data/CLs/finished/f1d1/2253436/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253436/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253436/test.png b/data/CLs/finished/f1d1/2253436/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253436/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253437/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253437/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..a952cc2 --- /dev/null +++ b/data/CLs/finished/f1d1/2253437/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253437/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253437/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..3ebfc8b --- /dev/null +++ b/data/CLs/finished/f1d1/2253437/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253437/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253437/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..a7f1971 --- /dev/null +++ b/data/CLs/finished/f1d1/2253437/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253437/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253437/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..10c75e5 --- /dev/null +++ b/data/CLs/finished/f1d1/2253437/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253437/helperfunctions.py b/data/CLs/finished/f1d1/2253437/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253437/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/2253437/pdg_const.py b/data/CLs/finished/f1d1/2253437/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253437/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/2253437/raremodel-nb.py b/data/CLs/finished/f1d1/2253437/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253437/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253437/test.png b/data/CLs/finished/f1d1/2253437/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253437/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253438/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253438/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..4a24a80 --- /dev/null +++ b/data/CLs/finished/f1d1/2253438/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253438/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253438/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..7a4ec24 --- /dev/null +++ b/data/CLs/finished/f1d1/2253438/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253438/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253438/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..9d4a4b1 --- /dev/null +++ b/data/CLs/finished/f1d1/2253438/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253438/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253438/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..43b12af --- /dev/null +++ b/data/CLs/finished/f1d1/2253438/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253438/helperfunctions.py b/data/CLs/finished/f1d1/2253438/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253438/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/2253438/pdg_const.py b/data/CLs/finished/f1d1/2253438/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253438/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/2253438/raremodel-nb.py b/data/CLs/finished/f1d1/2253438/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253438/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253438/test.png b/data/CLs/finished/f1d1/2253438/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253438/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253439/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253439/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..daf9afe --- /dev/null +++ b/data/CLs/finished/f1d1/2253439/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253439/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253439/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..177b05f --- /dev/null +++ b/data/CLs/finished/f1d1/2253439/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253439/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253439/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..75c8434 --- /dev/null +++ b/data/CLs/finished/f1d1/2253439/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253439/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253439/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..2b7636d --- /dev/null +++ b/data/CLs/finished/f1d1/2253439/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253439/helperfunctions.py b/data/CLs/finished/f1d1/2253439/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253439/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/2253439/pdg_const.py b/data/CLs/finished/f1d1/2253439/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253439/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/2253439/raremodel-nb.py b/data/CLs/finished/f1d1/2253439/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253439/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253439/test.png b/data/CLs/finished/f1d1/2253439/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253439/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253440/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253440/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..396b3f6 --- /dev/null +++ b/data/CLs/finished/f1d1/2253440/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253440/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253440/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..0e22fd9 --- /dev/null +++ b/data/CLs/finished/f1d1/2253440/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253440/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253440/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..08f8c23 --- /dev/null +++ b/data/CLs/finished/f1d1/2253440/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253440/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253440/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..a6c9d79 --- /dev/null +++ b/data/CLs/finished/f1d1/2253440/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253440/helperfunctions.py b/data/CLs/finished/f1d1/2253440/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253440/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/2253440/pdg_const.py b/data/CLs/finished/f1d1/2253440/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253440/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/2253440/raremodel-nb.py b/data/CLs/finished/f1d1/2253440/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253440/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253440/test.png b/data/CLs/finished/f1d1/2253440/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253440/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253441/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253441/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..1b7184a --- /dev/null +++ b/data/CLs/finished/f1d1/2253441/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253441/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253441/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..efb6c2a --- /dev/null +++ b/data/CLs/finished/f1d1/2253441/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253441/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253441/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..37d8fff --- /dev/null +++ b/data/CLs/finished/f1d1/2253441/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253441/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253441/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..a624b87 --- /dev/null +++ b/data/CLs/finished/f1d1/2253441/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253441/helperfunctions.py b/data/CLs/finished/f1d1/2253441/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253441/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/2253441/pdg_const.py b/data/CLs/finished/f1d1/2253441/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253441/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/2253441/raremodel-nb.py b/data/CLs/finished/f1d1/2253441/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253441/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253441/test.png b/data/CLs/finished/f1d1/2253441/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253441/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253442/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253442/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..2f8722e --- /dev/null +++ b/data/CLs/finished/f1d1/2253442/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253442/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253442/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..b103199 --- /dev/null +++ b/data/CLs/finished/f1d1/2253442/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253442/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253442/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..09eb853 --- /dev/null +++ b/data/CLs/finished/f1d1/2253442/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253442/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253442/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..ed83943 --- /dev/null +++ b/data/CLs/finished/f1d1/2253442/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253442/helperfunctions.py b/data/CLs/finished/f1d1/2253442/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253442/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/2253442/pdg_const.py b/data/CLs/finished/f1d1/2253442/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253442/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/2253442/raremodel-nb.py b/data/CLs/finished/f1d1/2253442/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253442/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253442/test.png b/data/CLs/finished/f1d1/2253442/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253442/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253443/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253443/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..a0f1063 --- /dev/null +++ b/data/CLs/finished/f1d1/2253443/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253443/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253443/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..d8cfa10 --- /dev/null +++ b/data/CLs/finished/f1d1/2253443/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253443/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253443/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..32171e3 --- /dev/null +++ b/data/CLs/finished/f1d1/2253443/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253443/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253443/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..1bdab9d --- /dev/null +++ b/data/CLs/finished/f1d1/2253443/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253443/helperfunctions.py b/data/CLs/finished/f1d1/2253443/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253443/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/2253443/pdg_const.py b/data/CLs/finished/f1d1/2253443/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253443/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/2253443/raremodel-nb.py b/data/CLs/finished/f1d1/2253443/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253443/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253443/test.png b/data/CLs/finished/f1d1/2253443/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253443/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253444/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253444/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..2c66cb7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253444/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253444/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253444/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..ff12e62 --- /dev/null +++ b/data/CLs/finished/f1d1/2253444/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253444/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253444/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..76ce4c8 --- /dev/null +++ b/data/CLs/finished/f1d1/2253444/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253444/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253444/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..0d7cb79 --- /dev/null +++ b/data/CLs/finished/f1d1/2253444/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253444/helperfunctions.py b/data/CLs/finished/f1d1/2253444/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253444/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/2253444/pdg_const.py b/data/CLs/finished/f1d1/2253444/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253444/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/2253444/raremodel-nb.py b/data/CLs/finished/f1d1/2253444/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253444/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253444/test.png b/data/CLs/finished/f1d1/2253444/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253444/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253445/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253445/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..2e62a66 --- /dev/null +++ b/data/CLs/finished/f1d1/2253445/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253445/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253445/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..793acd9 --- /dev/null +++ b/data/CLs/finished/f1d1/2253445/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253445/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253445/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..e39e340 --- /dev/null +++ b/data/CLs/finished/f1d1/2253445/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253445/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253445/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..b792ace --- /dev/null +++ b/data/CLs/finished/f1d1/2253445/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253445/helperfunctions.py b/data/CLs/finished/f1d1/2253445/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253445/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/2253445/pdg_const.py b/data/CLs/finished/f1d1/2253445/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253445/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/2253445/raremodel-nb.py b/data/CLs/finished/f1d1/2253445/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253445/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253445/test.png b/data/CLs/finished/f1d1/2253445/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253445/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253446/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253446/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..e8d5d41 --- /dev/null +++ b/data/CLs/finished/f1d1/2253446/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253446/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253446/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..877a535 --- /dev/null +++ b/data/CLs/finished/f1d1/2253446/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253446/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253446/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..630fd13 --- /dev/null +++ b/data/CLs/finished/f1d1/2253446/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253446/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253446/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..15995d5 --- /dev/null +++ b/data/CLs/finished/f1d1/2253446/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253446/helperfunctions.py b/data/CLs/finished/f1d1/2253446/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253446/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/2253446/pdg_const.py b/data/CLs/finished/f1d1/2253446/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253446/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/2253446/raremodel-nb.py b/data/CLs/finished/f1d1/2253446/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253446/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253446/test.png b/data/CLs/finished/f1d1/2253446/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253446/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253447/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253447/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..3851f70 --- /dev/null +++ b/data/CLs/finished/f1d1/2253447/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253447/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253447/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..dbddaf8 --- /dev/null +++ b/data/CLs/finished/f1d1/2253447/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253447/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253447/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..5f59c52 --- /dev/null +++ b/data/CLs/finished/f1d1/2253447/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253447/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253447/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..28c9d1d --- /dev/null +++ b/data/CLs/finished/f1d1/2253447/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253447/helperfunctions.py b/data/CLs/finished/f1d1/2253447/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253447/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/2253447/pdg_const.py b/data/CLs/finished/f1d1/2253447/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253447/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/2253447/raremodel-nb.py b/data/CLs/finished/f1d1/2253447/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253447/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253447/test.png b/data/CLs/finished/f1d1/2253447/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253447/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253448/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253448/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..b8a67cc --- /dev/null +++ b/data/CLs/finished/f1d1/2253448/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253448/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253448/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..bf09300 --- /dev/null +++ b/data/CLs/finished/f1d1/2253448/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253448/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253448/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..acd655d --- /dev/null +++ b/data/CLs/finished/f1d1/2253448/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253448/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253448/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..b124a77 --- /dev/null +++ b/data/CLs/finished/f1d1/2253448/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253448/helperfunctions.py b/data/CLs/finished/f1d1/2253448/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253448/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/2253448/pdg_const.py b/data/CLs/finished/f1d1/2253448/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253448/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/2253448/raremodel-nb.py b/data/CLs/finished/f1d1/2253448/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253448/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253448/test.png b/data/CLs/finished/f1d1/2253448/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253448/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253449/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253449/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..4f5c6f6 --- /dev/null +++ b/data/CLs/finished/f1d1/2253449/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253449/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253449/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..9ba5412 --- /dev/null +++ b/data/CLs/finished/f1d1/2253449/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253449/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253449/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..b04bbd1 --- /dev/null +++ b/data/CLs/finished/f1d1/2253449/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253449/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253449/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..1073872 --- /dev/null +++ b/data/CLs/finished/f1d1/2253449/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253449/helperfunctions.py b/data/CLs/finished/f1d1/2253449/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253449/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/2253449/pdg_const.py b/data/CLs/finished/f1d1/2253449/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253449/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/2253449/raremodel-nb.py b/data/CLs/finished/f1d1/2253449/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253449/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253449/test.png b/data/CLs/finished/f1d1/2253449/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253449/test.png Binary files differ diff --git a/data/CLs/finished/f1d1/2253450/__pycache__/helperfunctions.cpython-37.pyc b/data/CLs/finished/f1d1/2253450/__pycache__/helperfunctions.cpython-37.pyc new file mode 100644 index 0000000..d8dbb04 --- /dev/null +++ b/data/CLs/finished/f1d1/2253450/__pycache__/helperfunctions.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253450/__pycache__/pdg_const.cpython-37.pyc b/data/CLs/finished/f1d1/2253450/__pycache__/pdg_const.cpython-37.pyc new file mode 100644 index 0000000..6abad45 --- /dev/null +++ b/data/CLs/finished/f1d1/2253450/__pycache__/pdg_const.cpython-37.pyc Binary files differ diff --git a/data/CLs/finished/f1d1/2253450/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl b/data/CLs/finished/f1d1/2253450/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl new file mode 100644 index 0000000..04c8ecc --- /dev/null +++ b/data/CLs/finished/f1d1/2253450/data/CLs/0.0-0.001_11s--CLs_Nll_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253450/data/CLs/0.0-0.001_11s--CLs_list.pkl b/data/CLs/finished/f1d1/2253450/data/CLs/0.0-0.001_11s--CLs_list.pkl new file mode 100644 index 0000000..8af05c0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253450/data/CLs/0.0-0.001_11s--CLs_list.pkl Binary files differ diff --git a/data/CLs/finished/f1d1/2253450/helperfunctions.py b/data/CLs/finished/f1d1/2253450/helperfunctions.py new file mode 100644 index 0000000..88e120f --- /dev/null +++ b/data/CLs/finished/f1d1/2253450/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/2253450/pdg_const.py b/data/CLs/finished/f1d1/2253450/pdg_const.py new file mode 100644 index 0000000..6645dd7 --- /dev/null +++ b/data/CLs/finished/f1d1/2253450/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/2253450/raremodel-nb.py b/data/CLs/finished/f1d1/2253450/raremodel-nb.py new file mode 100644 index 0000000..ea561e0 --- /dev/null +++ b/data/CLs/finished/f1d1/2253450/raremodel-nb.py @@ -0,0 +1,1791 @@ +#!/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 + +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 = 5 +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) + +__ = -1 + +for Ctt_step in Ctt_steps: + + __ += 1 + + for floaty in [True, False]: + + Ctt_floating = floaty + + Nll_list.append([]) + + 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[50]: + + +dirName = 'data/CLs' + +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("data/CLs/{}-{}_{}s--CLs_Nll_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(Nll_list, f, pkl.HIGHEST_PROTOCOL) + +with open("data/CLs/{}-{}_{}s--CLs_list.pkl".format(mi,ma,ste), "wb") as f: + pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL) + + +# In[51]: + + +print(CLs_values) + + +# In[ ]: + + + + + +# In[ ]: + + + + diff --git a/data/CLs/finished/f1d1/2253450/test.png b/data/CLs/finished/f1d1/2253450/test.png new file mode 100644 index 0000000..1455457 --- /dev/null +++ b/data/CLs/finished/f1d1/2253450/test.png Binary files differ diff --git a/raremodel-nb.ipynb b/raremodel-nb.ipynb index 705aece..986d3c6 100644 --- a/raremodel-nb.ipynb +++ b/raremodel-nb.ipynb @@ -1941,9 +1941,9 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": null, "metadata": { - "scrolled": true + "scrolled": false }, "outputs": [ { @@ -1952,13 +1952,1321 @@ "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" + "Use tf.cast instead.\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: True\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1540 (1540 total) |\n", + "| EDM = 1.79E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: True\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1352 (1352 total) |\n", + "| EDM = 0.00228 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: True\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1307 (1307 total) |\n", + "| EDM = 2.89E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: True\n", + "Toy 2/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=200 (200 total) |\n", + "| EDM = 7.84E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: True\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.987E+05 | Ncalls=624 (635 total) |\n", + "| EDM = 3.22E+06 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: True\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=924 (924 total) |\n", + "| EDM = 5.94E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: True\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1629 (1629 total) |\n", + "| EDM = 0.000463 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: False\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1302 (1302 total) |\n", + "| EDM = 0.00223 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: False\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1575 (1575 total) |\n", + "| EDM = 0.000754 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: False\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1969 (1969 total) |\n", + "| EDM = 0.000171 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: False\n", + "Toy 2/5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1244 (1244 total) |\n", + "| EDM = 0.000128 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: False\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1348 (1348 total) |\n", + "| EDM = 9.9E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: False\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1343 (1343 total) |\n", + "| EDM = 0.00315 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 0/11\n", + "Current Ctt: 0.0\n", + "Ctt floating: False\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1476 (1476 total) |\n", + "| EDM = 8.91E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Time Taken: 25 min, 36 s\n", + "Predicted time left: 4 h, 16 min\n", + "Step: 1/11\n", + "Current Ctt: 0.1543033499620919\n", + "Ctt floating: True\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.992E+05 | Ncalls=513 (524 total) |\n", + "| EDM = 4.32E+05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 1/11\n", + "Current Ctt: 0.1543033499620919\n", + "Ctt floating: True\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1397 (1397 total) |\n", + "| EDM = 0.000208 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 1/11\n", + "Current Ctt: 0.1543033499620919\n", + "Ctt floating: True\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=214 (214 total) |\n", + "| EDM = 4.6E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 1/11\n", + "Current Ctt: 0.1543033499620919\n", + "Ctt floating: True\n", + "Toy 2/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1724 (1724 total) |\n", + "| EDM = 0.000826 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 1/11\n", + "Current Ctt: 0.1543033499620919\n", + "Ctt floating: True\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1394 (1394 total) |\n", + "| EDM = 3.37E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 1/11\n", + "Current Ctt: 0.1543033499620919\n", + "Ctt floating: True\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1300 (1300 total) |\n", + "| EDM = 0.000951 (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.1543033499620919\n", + "Ctt floating: False\n", + "Toy 0/5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "------------------------------------------------------------------\n", + "| FCN = 2.981E+05 | Ncalls=1409 (1409 total) |\n", + "| EDM = 2.19E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 1/11\n", + "Current Ctt: 0.1543033499620919\n", + "Ctt floating: False\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=2071 (2071 total) |\n", + "| EDM = 8.39E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 1/11\n", + "Current Ctt: 0.1543033499620919\n", + "Ctt floating: False\n", + "Toy 2/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1172 (1172 total) |\n", + "| EDM = 8E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 1/11\n", + "Current Ctt: 0.1543033499620919\n", + "Ctt floating: False\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.98E+05 | Ncalls=1204 (1204 total) |\n", + "| EDM = 8.3E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 1/11\n", + "Current Ctt: 0.1543033499620919\n", + "Ctt floating: False\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1296 (1296 total) |\n", + "| EDM = 4.11E-06 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Time Taken: 57 min, 35 s\n", + "Predicted time left: 4 h, 19 min\n", + "Step: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: True\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1351 (1351 total) |\n", + "| EDM = 0.000163 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: True\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1276 (1276 total) |\n", + "| EDM = 0.00302 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: True\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.98E+05 | Ncalls=1278 (1278 total) |\n", + "| EDM = 6.48E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: True\n", + "Toy 2/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1896 (1896 total) |\n", + "| EDM = 9.77E-06 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: True\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1413 (1413 total) |\n", + "| EDM = 1.93E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: True\n", + "Toy 4/5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1878 (1878 total) |\n", + "| EDM = 9.96E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: False\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1216 (1216 total) |\n", + "| EDM = 0.00107 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: False\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1523 (1523 total) |\n", + "| EDM = 0.00023 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: False\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1830 (1830 total) |\n", + "| EDM = 0.000255 (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: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: False\n", + "Toy 2/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1843 (1843 total) |\n", + "| EDM = 0.000117 (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: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: False\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=708 (708 total) |\n", + "| EDM = 0.000216 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 2/11\n", + "Current Ctt: 0.2182178902359924\n", + "Ctt floating: False\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1397 (1397 total) |\n", + "| EDM = 8.49E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Time Taken: 1 h, 51 min\n", + "Predicted time left: 4 h, 57 min\n", + "Step: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: True\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1414 (1414 total) |\n", + "| EDM = 3.49E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: True\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.98E+05 | Ncalls=2076 (2076 total) |\n", + "| EDM = 0.0016 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: True\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=851 (851 total) |\n", + "| EDM = 4.47E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: True\n", + "Toy 2/5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1347 (1347 total) |\n", + "| EDM = 0.000468 (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: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: True\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1394 (1394 total) |\n", + "| EDM = 0.00102 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: True\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1572 (1572 total) |\n", + "| EDM = 0.00194 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: True\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1758 (1758 total) |\n", + "| EDM = 4.71E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: True\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1294 (1294 total) |\n", + "| EDM = 5.89E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: False\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1231 (1231 total) |\n", + "| EDM = 3.42E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: False\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1347 (1347 total) |\n", + "| EDM = 4.39E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: False\n", + "Toy 2/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1570 (1570 total) |\n", + "| EDM = 3.26E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: False\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1335 (1335 total) |\n", + "| EDM = 0.000102 (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: 3/11\n", + "Current Ctt: 0.2672612419124244\n", + "Ctt floating: False\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1408 (1408 total) |\n", + "| EDM = 0.00022 (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", + "Time Taken: 3 h, 22 min\n", + "Predicted time left: 5 h, 54 min\n", + "Step: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: True\n", + "Toy 0/5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "------------------------------------------------------------------\n", + "| FCN = 2.98E+05 | Ncalls=1299 (1299 total) |\n", + "| EDM = 7.13E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: True\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.98E+05 | Ncalls=1375 (1375 total) |\n", + "| EDM = 0.000111 (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: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: True\n", + "Toy 2/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.98E+05 | Ncalls=1293 (1293 total) |\n", + "| EDM = 0.000128 (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: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: True\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1008 (1008 total) |\n", + "| EDM = 3.84E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: True\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1732 (1732 total) |\n", + "| EDM = 0.00489 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: True\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1324 (1324 total) |\n", + "| EDM = 7.77E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: False\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1352 (1352 total) |\n", + "| EDM = 4.63E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: False\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1700 (1700 total) |\n", + "| EDM = 2.25E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: False\n", + "Toy 2/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1359 (1359 total) |\n", + "| EDM = 0.000126 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: False\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1290 (1290 total) |\n", + "| EDM = 6.25E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: False\n", + "Toy 4/5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=2433 (2433 total) |\n", + "| EDM = 0.00226 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: False\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1224 (1224 total) |\n", + "| EDM = 0.0075 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 4/11\n", + "Current Ctt: 0.3086066999241838\n", + "Ctt floating: False\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1491 (1491 total) |\n", + "| EDM = 0.000199 (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", + "Time Taken: 5 h, 34 min\n", + "Predicted time left: 6 h, 41 min\n", + "Step: 5/11\n", + "Current Ctt: 0.3450327796711771\n", + "Ctt floating: True\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1504 (1504 total) |\n", + "| EDM = 9.15E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 5/11\n", + "Current Ctt: 0.3450327796711771\n", + "Ctt floating: True\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.98E+05 | Ncalls=1368 (1368 total) |\n", + "| EDM = 0.00975 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| False | True | True | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 5/11\n", + "Current Ctt: 0.3450327796711771\n", + "Ctt floating: True\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1264 (1264 total) |\n", + "| EDM = 6.96E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 5/11\n", + "Current Ctt: 0.3450327796711771\n", + "Ctt floating: True\n", + "Toy 2/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.98E+05 | Ncalls=1440 (1440 total) |\n", + "| EDM = 9.28E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 5/11\n", + "Current Ctt: 0.3450327796711771\n", + "Ctt floating: True\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1390 (1390 total) |\n", + "| EDM = 0.000198 (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: 5/11\n", + "Current Ctt: 0.3450327796711771\n", + "Ctt floating: True\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=744 (744 total) |\n", + "| EDM = 0.000793 (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: 5/11\n", + "Current Ctt: 0.3450327796711771\n", + "Ctt floating: False\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1166 (1166 total) |\n", + "| EDM = 5.78E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 5/11\n", + "Current Ctt: 0.3450327796711771\n", + "Ctt floating: False\n", + "Toy 1/5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1331 (1331 total) |\n", + "| EDM = 6.52E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 5/11\n", + "Current Ctt: 0.3450327796711771\n", + "Ctt floating: False\n", + "Toy 2/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1113 (1113 total) |\n", + "| EDM = 4.95E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 5/11\n", + "Current Ctt: 0.3450327796711771\n", + "Ctt floating: False\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1416 (1416 total) |\n", + "| EDM = 8.74E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | True | True | False |\n", + "------------------------------------------------------------------\n", + "Step: 5/11\n", + "Current Ctt: 0.3450327796711771\n", + "Ctt floating: False\n", + "Toy 4/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1489 (1489 total) |\n", + "| EDM = 0.000145 (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", + "Time Taken: 8 h, 7 min\n", + "Predicted time left: 6 h, 46 min\n", + "Step: 6/11\n", + "Current Ctt: 0.37796447300922725\n", + "Ctt floating: True\n", + "Toy 0/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.977E+05 | Ncalls=1414 (1414 total) |\n", + "| EDM = 0.000113 (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: 6/11\n", + "Current Ctt: 0.37796447300922725\n", + "Ctt floating: True\n", + "Toy 1/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.978E+05 | Ncalls=1641 (1641 total) |\n", + "| EDM = 0.000171 (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: 6/11\n", + "Current Ctt: 0.37796447300922725\n", + "Ctt floating: True\n", + "Toy 2/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.979E+05 | Ncalls=1557 (1557 total) |\n", + "| EDM = 0.00043 (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: 6/11\n", + "Current Ctt: 0.37796447300922725\n", + "Ctt floating: True\n", + "Toy 3/5\n", + "------------------------------------------------------------------\n", + "| FCN = 2.98E+05 | Ncalls=1311 (1311 total) |\n", + "| EDM = 1.85E-05 (Goal: 5E-06) | up = 0.5 |\n", + "------------------------------------------------------------------\n", + "| Valid Min. | Valid Param. | Above EDM | Reached call limit |\n", + "------------------------------------------------------------------\n", + "| True | True | False | False |\n", + "------------------------------------------------------------------\n", + "| Hesse failed | Has cov. | Accurate | Pos. def. | Forced |\n", + "------------------------------------------------------------------\n", + "| False | True | False | False | True |\n", + "------------------------------------------------------------------\n", + "Step: 6/11\n", + "Current Ctt: 0.37796447300922725\n", + "Ctt floating: True\n", + "Toy 4/5\n" ] } ], "source": [ "# zfit.run.numeric_checks = False \n", "\n", + "load = False\n", + "\n", "fitting_range = 'cut'\n", "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\n", "cut_BR = 1.0 - (6.02e-5 + 4.97e-6)/total_BR\n", @@ -1991,108 +3299,88 @@ "\n", "__ = -1\n", "\n", - "# for Ctt_step in Ctt_steps:\n", - " \n", - "# __ += 1\n", - " \n", - "# for floaty in [True, False]:\n", "\n", - "# Ctt_floating = floaty\n", - " \n", - "# Nll_list.append([])\n", + "#-----------------------------------------------------\n", "\n", - "# while len(Nll_list[-1]) < nr_of_toys:\n", - " \n", - "# print('Step: {0}/{1}'.format(__, ste))\n", - " \n", - "# print('Current Ctt: {0}'.format(Ctt_step))\n", - "# print('Ctt floating: {0}'.format(floaty))\n", - " \n", - "# print('Toy {0}/{1}'.format(len(Nll_list[-1]), nr_of_toys))\n", - " \n", - "# reset_param_values()\n", - " \n", - "# if floaty:\n", - "# Ctt.set_value(Ctt_step)\n", - "# else:\n", - "# Ctt.set_value(0.0)\n", - " \n", - "# if floaty:\n", - "# sampler.resample(n=nevents)\n", - "# s = sampler.unstack_x()\n", - "# total_samp = zfit.run(s)\n", - "# calls = 0\n", - "# c = 1\n", + "if not load:\n", "\n", - "# data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit)\n", + " for Ctt_step in Ctt_steps:\n", "\n", - "# ### Fit data\n", + " __ += 1\n", "\n", - "# for param in total_f_fit.get_dependents():\n", - "# param.randomize()\n", + "# if __ != 8:\n", + "# break\n", "\n", - "# nll = zfit.loss.UnbinnedNLL(model=total_f_fit, data=data, constraints = constraints)\n", + " for floaty in [True, False]:\n", "\n", - "# minimizer = zfit.minimize.MinuitMinimizer(verbosity = 5)\n", - "# # minimizer._use_tfgrad = False\n", - "# result = minimizer.minimize(nll)\n", + " Ctt.floating = floaty\n", "\n", - "# # print(\"Function minimum:\", result.fmin)\n", - "# # print(\"Hesse errors:\", result.hesse())\n", + " Nll_list.append([])\n", "\n", - "# params = result.params\n", + " while len(Nll_list[-1]) < nr_of_toys:\n", "\n", - "# if result.converged:\n", - "# Nll_list[-1].append(result.fmin)\n", - " \n", - "# _t = int(time.time()-start)\n", - " \n", - "# print('Time Taken: {}'.format(display_time(int(_t))))\n", - " \n", - "# print('Predicted time left: {}'.format(display_time(int((_t/(__+1)*(ste-__-1))))))\n" + " print('Step: {0}/{1}'.format(__, ste))\n", + "\n", + " print('Current Ctt: {0}'.format(Ctt_step))\n", + " print('Ctt floating: {0}'.format(floaty))\n", + "\n", + " print('Toy {0}/{1}'.format(len(Nll_list[-1]), nr_of_toys))\n", + "\n", + " reset_param_values()\n", + "\n", + " if floaty:\n", + " Ctt.set_value(Ctt_step)\n", + " else:\n", + " Ctt.set_value(0.0)\n", + "\n", + " if floaty:\n", + " sampler.resample(n=nevents)\n", + " s = sampler.unstack_x()\n", + " total_samp = zfit.run(s)\n", + " calls = 0\n", + " c = 1\n", + "\n", + " data = zfit.data.Data.from_numpy(array=total_samp[:int(nevents)], obs=obs_fit)\n", + "\n", + " ### Fit data\n", + "\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", + "\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", + "\n", + " params = result.params\n", + "\n", + " if result.converged:\n", + " Nll_list[-1].append(result.fmin)\n", + "\n", + " _t = int(time.time()-start)\n", + "\n", + " print('Time Taken: {}'.format(display_time(int(_t))))\n", + "\n", + " print('Predicted time left: {}'.format(display_time(int((_t/(__+1)*(ste-__-1))))))\n" ] }, { "cell_type": "code", - "execution_count": 81, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(11, 5)\n", - "2253432\n", - "(11, 10)\n", - "(11, 15)\n", - "(11, 20)\n", - "(11, 25)\n", - "(11, 30)\n", - "(11, 35)\n", - "(11, 40)\n", - "(11, 45)\n", - "(11, 50)\n", - "(11, 55)\n", - "(11, 60)\n", - "(11, 65)\n", - "(11, 70)\n", - "(11, 75)\n", - "(11, 80)\n", - "(11, 85)\n", - "(11, 90)\n", - "(11, 95)\n" - ] - } - ], + "outputs": [], "source": [ - "load = True\n", - "\n", "if load:\n", " Nll_list = []\n", " CLs_values = []\n", - " jobs = os.listdir('data/CLs/finished/')\n", "\n", - " _dir = 'data/CLs/finished/'\n", + " _dir = 'data/CLs/finished/f1d1'\n", + " \n", + " jobs = os.listdir(_dir)\n", " \n", " for s in range(ste):\n", " CLs_values.append([])\n", @@ -2103,7 +3391,7 @@ " __ = 0\n", " \n", " for job in jobs:\n", - " if not os.path.exists(\"{}{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl\".format(_dir, job, mi,ma,ste)):\n", + " if not os.path.exists(\"{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl\".format(_dir, job, mi,ma,ste)):\n", " print(job)\n", " continue\n", " __ +=1\n", @@ -2111,13 +3399,13 @@ "# if __ > 2:\n", "# break\n", " \n", - " with open(r\"{}{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl\".format(_dir, job, mi,ma,ste), \"rb\") as input_file:\n", + " with open(r\"{}/{}/data/CLs/{}-{}_{}s--CLs_Nll_list.pkl\".format(_dir, job, mi,ma,ste), \"rb\") as input_file:\n", " _Nll_list = pkl.load(input_file)\n", " \n", " for s in range(2*ste):\n", " Nll_list[s].extend(_Nll_list[s])\n", " \n", - " with open(r\"{}{}/data/CLs/{}-{}_{}s--CLs_list.pkl\".format(_dir, job, mi,ma,ste), \"rb\") as input_file:\n", + " with open(r\"{}/{}/data/CLs/{}-{}_{}s--CLs_list.pkl\".format(_dir, job, mi,ma,ste), \"rb\") as input_file:\n", " _CLs_values = pkl.load(input_file)\n", " \n", " for s in range(ste):\n", @@ -2128,7 +3416,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -2148,16 +3436,16 @@ " os.mkdir(dirName)\n", " print(\"Directory \" , dirName , \" Created \")\n", "\n", - " with open(\"data/CLs/{}-{}_{}s--CLs_Nll_list.pkl\".format(mi,ma,ste), \"wb\") as f:\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", - " with open(\"data/CLs/{}-{}_{}s--CLs_list.pkl\".format(mi,ma,ste), \"wb\") as f:\n", + " with open(\"{}/{}-{}_{}s--CLs_list.pkl\".format(dirName, mi,ma,ste), \"wb\") as f:\n", " pkl.dump(CLs_values, f, pkl.HIGHEST_PROTOCOL)" ] }, { "cell_type": "code", - "execution_count": 83, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -2173,22 +3461,9 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAEICAYAAABGaK+TAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3deZRU1bn+8e8bpkZFRCGDtqbRqAiCjTaKURBxFuNwI3GIBvQKMUqC0V+uqAki1wGNicPSaAhGTMIUUa5TNBqjhsSByQYZBCFiaBFEJEQRUPT9/bFPN03Pp6uqdxc8n7V6ddWuU+c8farq7VNn2NvcHRERyT9fih1AREQaRwVcRCRPqYCLiOQpFXARkTylAi4ikqdUwEVE8pQKuOwwzGyUmf0hdg6RbFEBl5wys/PNbJaZfWxm75nZ02Z2dPJYtYJqZi+a2SVx0maPmR1nZm+a2Sdm9oKZfb0BzznGzNzMbqzU1sbM7jCzlWa2zsx+ZWatcpte8oUKuOSMmV0J3AncDHwF2Af4FXBGzFy5ZmYdgUeBnwG7A7OAKfU8pxVwF/BalYdGACXAwcABwKHAT7McWfKUCrjkhJm1B0YDl7v7o+6+wd0/c/cn3P0nZnYycC1wTrJ1PtfMbgL6APckbffUMN9nzGxYlba5ZvZfye27zGyFmf3HzGabWZ9a8vUzs7IqbcvN7Pjk9pfMbISZLTOztWb2RzPbvYF//n8BC9z9YXffBIwCDjGzLnU85yrgWeDNKu3fAu529w/dfQ1wN3BxA3PIdk4FXHLlSKAAmFbTg+7+DGHLfIq77+Luh7j7dcB0YFjSNqyGp04Eziu/Y2Zdga8DTyVNM4FiwpbvROBhMytoRP4fAWcCxwB7AuuAeystd56ZnV/Lc7sBcyv9rRuAZUl7NcnulYsJ//CqPZz8VL5fmPyDlB2cCrjkyh7AB+6+JcvznQYUV9qn/F3gUXffDODuf3D3te6+xd1/AbQBDmzEcr4PXOfuZcm8RwFnm1nLZDk93H1iLc/dBVhfpW090K6W6e8GfubuH9fw2NPAcDPrZGZfJfxjAdip4X+KbK9UwCVX1gIdywtetrj7R4St7XOTpnOBCeWPm9lVZrbIzNab2b+B9kDHRizq68A0M/t3Mp9FwOeEffn1+RjYtUrbrsBHVSc0s28B7dy9tn3kNwGvA6XAy8D/AZ8B7zfkj5Dtmwq45MorwCbCboja1NQVZkO6x5wEnGdmRwJtgRcAkv3dVwPfATq4+26ELV+rYR4bqLQVa2YtgE6VHl8BnOLuu1X6KXD3dxuQbwFwSKV57wzsl7RXdRxQYmarzGwVcA5whZk9BuDuG919mLvv5e77Ev4xznb3zxuQQ7ZzKuCSE+6+HhgJ3GtmZ5rZTmbWysxOMbPbkslWA0VmVvl9uBrYt57Z/4mwhTyasA/9i6S9HbAFWAO0NLORVN8SLrcEKDCzAckZID8l7G4pdz9wU/mummQXRkPPnpkGHGxm3072v48E5rl71QOUEM5UOYCw374YeBz4DXBRsty9zGxPC3on01/fwByynVMBl5xx918CVxKK4xrCVu0wwm4AgIeT32vNbE5y+y7CvuZ1ZnZ3LfPdTDhN73jCgcpyfybsM14CvEP4BrCilnmsBy4DxgHvErbIK5+VchehmD5rZh8BrwJHlD9oZgvM7Lu1zHsN8G3C7o91yfPOrfTc+83s/mTaj9x9VfkPsBHY4O4fJpPvR9h1sgF4CBjh7s/WtFzZ8ZgGdBARyU/aAhcRyVMq4CIieUoFXEQkT6mAi4jkqaxeZFGfjh07elFRUVMuUkQaauNGaNs2dgqpwezZsz9w905V25u0gBcVFTFr1qymXKSINNTUqXD22bFTSA3M7J2a2rULRUSC9uofK9+ogItIsPPOsRNISirgIhK89VbsBJJSk+4Dr8lnn31GWVkZmzZtih1FgIKCAgoLC2nVSqN27XCOOSZ2AkkpegEvKyujXbt2FBUVYVZTp3HSVNydtWvXUlZWRufOnWPHkaY2aRJcc03sFJJC9F0omzZtYo899lDxbgbMjD322EPfhnZUV10VO4GkFL2AAyrezYheix3YLbfETiApNYsCLiLNwPXqZjzfRN8HXlXRiKfqnyiF5WMG1DvNqlWruOKKK5g5cyZt2rShqKiIO++8k9atW/Pyyy9z/vlh7NrS0lJWrlzJqaeeWuN8zjvvPBYsWMBFF13EunXr6Nu3L8cff3xG+V988UVuv/12nnzyyW3a68tSm1tuuYUHHniAFi1acPfdd3PSSSdllE+2I6NHw8iRsVNICs2ugDc1d+ess85i0KBBTJ48GQjFcfXq1Xz++edMnDhxmwI+a9asGovmqlWrePnll3nnnRovmMq6urLUZuHChUyePJkFCxawcuVKjj/+eJYsWUKLFi1ymFTyxuWX19hceaOqIRtE0nR2+F0oL7zwAq1ateLSSy+taCsuLqZPnz6MGDGC6dOnU1xczK233srIkSOZMmUKxcXFTJmy7Ri0J554Iu+//z7FxcVMnz6dwYMHM3XqVNavX8+BBx7I4sWLgbCV/pvf/AaAZ599liOPPJJDDz2UgQMH8vHHYVDyZ555hi5dunD00Ufz6KOPVsv86aefVsvy4YcfcuaZZ9KjRw969+7NvHnzqj3vscce49xzz6VNmzZ07tyZb3zjG8yYMSNr61LyXLIBI/ljhy/g8+fP57DDDqvxsTFjxtCnTx9KS0u5+uqrGT16NOeccw6lpaWcc84520z7+OOPs99++1FaWkqfPn0q2tu3b88999zD4MGDmTx5MuvWrWPIkCF88MEH3HjjjfzlL39hzpw5lJSU8Mtf/pJNmzYxZMgQnnjiCaZPn86qVauq5WrdunW1LNdffz09e/Zk3rx53HzzzXzve9+r9rx3332Xvffeu+J+YWEh777bkDF6ZYfQt2/sBJLSDl/Am8IJJ5xA9+7dufzyyxk3bhwAr776KgsXLuSoo46iuLiYhx56iHfeeYc333yTzp07s//++2NmXHDBBQ1axt///ncuvPBCAPr378/atWtZv379NtPUNHyezjqRCkuXxk4gKe3w+8C7devG1KlTc7qML774gkWLFtG2bVs+/PBDCgsLcXdOOOEEJk2atM20paWljSqqDSnOhYWFrFixdYzfsrIy9txzz9TLku2UupLNOzv8Fnj//v3ZvHlzxX5pgJkzZ/LSSy/Rrl07Pvroo4r2qvcb6o477uCggw5i0qRJXHzxxXz22Wf07t2bf/zjHyxNtno++eQTlixZQpcuXXj77bdZtmwZQLUCX1uWvn37MmHCBCCcudKxY0d23XXXbZ5z+umnM3nyZDZv3szbb7/NW2+9xeGHH57675HtVIcOsRNISs1uC7ypj3KbGdOmTeOKK65gzJgxFBQUVJxGWFRURMuWLTnkkEMYPHgwgwYNYsyYMRQXF3PNNddU2w9ekyVLljBu3DhmzJhBu3bt6Nu3LzfeeCM33HAD48eP57zzzmPz5s0A3HjjjRxwwAGMHTuWAQMG0LFjR44++mjmz59fbb7HHnvsNllGjRrFRRddRI8ePdhpp5146KGHqj2nW7dufOc736Fr1660bNmSe++9V2egyFYLFsARR8ROISlYTV+9c6WkpMSrDuiwaNEiDjrooCbLIPXTa7KDWrECKh3kLqfTCOMzs9nuXlK1fYffhSIiiRq+tUnzpgIuIoF6Isw7KuAiEtx0U+wEkpIKuIgE6gcl76iAi0hwww2xE0hKKuAiEvzgB7ETSErN7jxwRrXP8vzW1ztJLrqTnTt3Lqeddhpnn3126sjjx4/nxBNPrLhK8pJLLuHKK6+ka9euqecl0mCPPKIinmfq3QI3s9+a2ftmNr9S2+5m9pyZvZX8zttLuMq7k+3Xrx/Lli1j4cKF3HzzzaxevZrly5czceLEimlLS0v505/+VON8yruTnTdvHj/+8Y8zyjR+/HhWrlxZcX/cuHEq3pJ7Rx4ZO4Gk1JBdKOOBk6u0jQCed/f9geeT+3kpV93JVvb888/Ts2dPunfvzsUXX1xx5eXo0aPp1asXBx98MEOHDsXdmTp1KrNmzeK73/0uxcXFbNy4kX79+lF+AdQuu+zCddddxyGHHELv3r1ZvXo1AMuWLaN379706tWLkSNHsssuu+Rytcn2qIn6spfsqbeAu/vfgA+rNJ8BlJ/1/xBwZpZzNZlcdye7adMmBg8ezJQpU3jjjTfYsmUL9913HwDDhg1j5syZzJ8/n40bN/Lkk09y9tlnU1JSwoQJEygtLaVtlQ6GNmzYQO/evZk7dy59+/at6MNl+PDhDB8+nJkzZ6qDKmmcVq1iJ5CUGnsQ8yvu/h5A8vvL2Yu0fVm8eDGdO3fmgAMOAGDQoEH87W9/A8LW/xFHHEH37t3561//yoIFC+qdX+vWrTnttNMAOOyww1i+fDkAr7zyCgMHDgSo2GcvkkqnTrETSEo5PwvFzIaa2Swzm7VmzZpcLy61bt26MXv27JzNv7a+ZjZt2sRll13G1KlTeeONNxgyZAibNm2qd36tWrWq6Ca2RYsWbNmyJat5ZQc2d27sBJJSYwv4ajP7GkDy+/3aJnT3se5e4u4lnZrhf/hcdyfbpUsXli9fXtFt7O9//3uOOeaYimLdsWNHPv744236JG/Mcnr37s0jjzwCUDG2p0gqp5wSO4Gk1NjTCB8HBgFjkt+PZS1RA077y6ZcdydbUFDAgw8+yMCBA9myZQu9evXi0ksvpU2bNgwZMoTu3btTVFREr169Kp4zePBgLr30Utq2bcsrr7zSoL/jzjvv5IILLuAXv/gFAwYMoH37LJ+OKdu/Bx7Q1Zh5pt7uZM1sEtAP6AisBq4H/g/4I7AP8C9goLtXPdBZjbqTzZ1PPvmEtm3bYmZMnjyZSZMm8dhjjfu/qtdEKlN3svHV1p1svVvg7n5eLQ8dl3EqyZrZs2czbNgw3J3ddtuN3/72t7EjSb4ZPVpb4Hmm+V2JKY3Sp08f5uoglGRCxTvvNIu+UJpyVCCpm16LHdjo0bETSErRC3hBQQFr165V4WgG3J21a9dSUFAQO4rEMGRI7ASSUvRdKIWFhZSVldEczxHfERUUFFBYWBg7hsTwxBMwdGjsFJJC9ALeqlUrOnfuHDuGiNTSpYQ0X9F3oYhIM/Hee7ETSEoq4CIS6DhU3lEBF5Fgr71iJ5CUVMBFJJg5M3YCSUkFXESCM86InUBSUgEXkWDs2NgJJCUVcBEJdCl93lEBF5FAl9LnHRVwEQl+9rPYCSQlFXARCf73f2MnkJRUwEUk+O//jp1AUlIBF5Hg6adjJ5CUVMBFJOjRI3YCSUkFXESCDz6InUBSUgEXkeDTT2MnkJRUwEUkKCqKnUBSUgEXkeDll2MnkJRUwEUkGDgwdgJJSQVcRIL77oudQFJSAReRQJ1Z5R0VcBEJ1JlV3lEBF5Hg2mtjJ5CUVMBFJLj11tgJJCUVcBEJLrwwdgJJKaMCbmY/NrMFZjbfzCaZWUG2golIE3v++dgJJKVGF3Az2wv4EVDi7gcDLYBzsxVMRJrYQQfFTiApZboLpSXQ1sxaAjsBKzOPJCJRrF8fO4Gk1OgC7u7vArcD/wLeA9a7+7NVpzOzoWY2y8xmrVmzpvFJRSS3NmyInUBSymQXSgfgDKAzsCews5ldUHU6dx/r7iXuXtKpU6fGJxWR3Np//9gJJKVMdqEcD7zt7mvc/TPgUeCb2YklIk3uxRdjJ5CUMing/wJ6m9lOZmbAccCi7MQSkSZ3/vmxE0hKmewDfw2YCswB3kjmNTZLuUSkqd17b+wEklLLTJ7s7tcD12cpi4jEpM6s8o6uxBSRQJ1Z5R0VcBEJrr46dgJJSQVcRII77oidQFJSAReR4JxzYieQlFTARSSYPj12AklJBVxEgv32i51AUlIBF5Fg48bYCSQlFXARCdati51AUlIBF5GgW7fYCSQlFXARCZ57LnYCSUkFXESCQYNiJ5CUVMBFJLjrrtgJJCUVcBEJrle/dPkmo94IRWQ7csMNFUW8aMRT2zy0vCDpK3wUMEpjZzYX2gIXkeAnP4mdQFJSAReRQAM65B0VcBEJzjordgJJSQVcRILXXoudQFJSAReRYO+9YyeQlFTARST4/PPYCSQlFXARCVavjp1AUlIBF5GgZ8/YCSQlFXARCZ56qv5ppFlRAReRYMiQ2AkkJRVwEQk0Kn3eUQEXkWDkyNgJJCUVcBEJbrghdgJJSQVcRIKrroqdQFJSAReR4Ne/jp1AUsqogJvZbmY21czeNLNFZnZktoKJSBP71rdiJ5CUMt0Cvwt4xt27AIcAizKPJCJRzJkTO4Gk1OgRecxsV6AvMBjA3T8FPs1OLBFpcl/9auwEklImW+D7AmuAB83sdTMbZ2Y7V53IzIaa2Swzm7VmzZoMFiciOfUlHRLLN5m8Yi2BQ4H73L0nsAEYUXUidx/r7iXuXtKpU6cMFiciOVVWFjuBpJRJAS8Dyty9vBf4qYSCLiL56PDDYyeQlBpdwN19FbDCzA5Mmo4DFmYllYg0vWnTYieQlBp9EDPxQ2CCmbUG/glclHkkEYni8stjJ5CUMjpq4e6lyf7tHu5+pruvy1YwEWlit98eO4GkpMPOIhKoM6u8owIuIsHo0bETSEoq4CISDB8eO4GkpAIuIsGDD8ZOICmpgItIcNJJsRNISirgIhK88UbsBJKSCriIBHvsETuBpKQCLiJBmzaxE0hKKuAiErz9duwEkpIKuIgERx0VO4GkpAIuIsHDD8dOICmpgItIoAt58o4KuIgEt90WO4GklGl3siKSA0Ujnqq4vXzMgMxnOKo9RZsm1j2/BnZmVZ6tvlxZ/xukGm2Bi0igzqzyjgq4iAQ//GHsBJKSCriIBH/4Q+wEkpIKuIgE/fvHTiApqYCLSPDmm7ETSEoq4CIStGsXO4GkpAIuIoEKeN5RAReRYPHi2AkkJRVwEQmOPTZ2AklJBVxEggkTYieQlFTARST4yU9iJ5CUVMBFJLjlltgJJCUVcBEJGtiZlTQfKuAiEqgzq7yTcQE3sxZm9rqZPZmNQCISyWWXxU4gKWVjC3w4sCgL8xGRmKZMiZ1AUsqogJtZITAAGJedOCISTZ8+sRNISpmOyHMn8D9ArdfgmtlQYCjAPvvsk+HiRCQrRrWHUeu3HTXniE+hR4+sL2p5wfnA+hof06g9mWn0FriZnQa87+6z65rO3ce6e4m7l3Tq1KmxixORXGvbNnYCSSmTXShHAaeb2XJgMtDfzNQjvEi+6tAhdgJJqdEF3N2vcfdCdy8CzgX+6u4XZC2ZiDSt+fNjJ5CUdB64iAQnnhg7gaSUlQLu7i+6+2nZmJeIRDJ+fOwEkpK2wEUkuPba2AkkJRVwEQluuil2AklJBVxEAnVmlXdUwEUkUGdWeUcFXESC738/dgJJSQVcRIJp02InkJRUwEUkOOKI2AkkJRVwEQlWrIidQFJSAReRoEWL2AkkJRVwEQm+8pXYCSQlFXARCV5/PXYCSUkFXESCARpQId+ogItIME4jI+abTIdUE5GUyocRW15wPoyqeaix+p4LtQ9BVjH/2oYoG9W+5vZKl9IvLzifok0Ta5ys/LH6lhOGUqu0zHr+1uY4vFpzzFSZtsBFJLjhhtgJJCUVcBEJrr8+dgJJSQVcRAJ1ZpV3VMBFJLjkktgJJCUVcBEJnnqq/mmkWVEBF5GgZ8/YCSQlFXARCVavjp1AUlIBF5Hg889jJ5CUVMBFJNh779gJJCUVcBEJXnstdgJJSQVcRIKzzoqdQFJSAReR4Ne/jp1AUlIBF5GgUmdWkh9UwEUk0KX0eUcFXESC666LnUBSanQBN7O9zewFM1tkZgvMbHg2g4lIE7v55tgJJKVMBnTYAlzl7nPMrB0w28yec/eFWcomIk1p8ODYCSSlRm+Bu/t77j4nuf0RsAjYK1vBRKSJPfts7ASSUlaGVDOzIqAnUO1KADMbCgwF2GeffbKxOJFGae7DY1Uddqzq0GVVbfP3NGJ4tqrOfGk9pW+VD/e2tX2bodGqZCvPse3wafUPnVbXkG1b59O+2vzqHS6ujmWWa5avfSNlfBDTzHYBHgGucPf/VH3c3ce6e4m7l3Tq1CnTxYlIjrTf9HHsCJJSRgXczFoRivcEd380O5FEJIaCLZtjR5CUMjkLxYAHgEXu/svsRRKRGN7Z7WuxI0hKmWyBHwVcCPQ3s9Lk59Qs5RKRJtarbEHsCJJSow9iuvvfActiFhGJ6MkufWJHkJR0JaaIAHDh63+KHUFSUgEXEQDuPuq82BEkJRVwEQHgR/+YFDuCpKQCLiIA/Kr3wNgRJCUVcBEBYOgMXcqRb1TARQSAx7r2ix1BUlIBFxEAjvzXvNgRJCUVcBEB4J+7qzPRfKMCLiIA7PzpxtgRJCUVcBEBVMDzkQq4iACwbPfC2BEkJRVwEQHgmzqImXdUwEUEgGndjo0dQVLKypBqTSGXQyJtr8MtSTq1vQ9qG9KsxvdK+TBgFffXV3tseQFbhxOrOn3VZSRDlRVtmljj0Gblj9WYM5l3eG71odGqTj9v7iA4pk21Zac2qn3FMutaXrU8tQ2xVmkdVcxz1NbnpBnOrWJ+yXQNec3rHP6tyjB4jZ6mkbQFLiJBpeIt+UEFXESClzSkWr5RAReR4KjWsRNISirgIhK8+mnsBJKSCriIBN1axU4gKamAi0jwry2xE0hKKuAiEnRQOcg3esVEJNAGeN5RAReRYKPHTiApqYCLSPBllYN8o1dMRIJl2oeSb1TARSQo1oU8+UYFXESC13QhT75RAReRQJ1Z5R0VcBEJ1JlV3smogJvZyWa22MyWmtmIbIUSkQi+qX3g+abRBdzMWgD3AqcAXYHzzKxrtoKJSBOboX3g+SaTLfDDgaXu/k93/xSYDJyRnVgi0uQOUmdW+cbcG3f1lZmdDZzs7pck9y8EjnD3YVWmGwoMTe4eCCxuwOw7Ah80KljuNddsypWOcqWjXOllM9vX3b1T1cZMxsS0Gtqq/Tdw97HA2FQzNpvl7iWNDZZLzTWbcqWjXOkoV3pNkS2TXShlwN6V7hcCKzOLIyIiDZVJAZ8J7G9mnc2sNXAu8Hh2YomISH0avQvF3beY2TDgz0AL4LfuviBLuVLtcmlizTWbcqWjXOkoV3o5z9bog5giIhKXrsQUEclTKuAiInkqSgE3s4FmtsDMvjCzkkrtJ5jZbDN7I/ndv9JjhyXtS83sbjOzpH13M3vOzN5KfnfIdq7ksWuSZS82s5MqtdfYnUBycPe1JNeU5EBvxsys2MxeNbNSM5tlZocn7Zasl6VmNs/MDq30nEFJjrfMbFA2ctSS7YfJulhgZrdVak+17nKY7/+ZmZtZx+R+1HVmZj83szeTZU8zs90qPdYs1lmsZVZa9t5m9oKZLUreV8OT9ho/93W9pjnK18LMXjezJ5P7NX7uzaxNcn9p8nhRVgK4e5P/AAcRLup5ESip1N4T2DO5fTDwbqXHZgBHEs4/fxo4JWm/DRiR3B4B3JqDXF2BuUAboDOwjHDgtkVye1+gdTJN1+Q5fwTOTW7fD/wgS+vu2Up/+6nAi5VuP52sn97Aa0n77sA/k98dktsdcvCaHgv8BWiT3P9yY9ddjt5zexMOuL8DdGwm6+xEoGVy+9by925zWWdJliZfZpXlfw04NLndDliSrJ8aP/e1vaY5zHclMBF4Mrlf4+ceuAy4P7l9LjAlG8uPsgXu7ovcvdoVme7+uruXn0u+AChI/nN9DdjV3V/xsAZ+B5yZTHcG8FBy+6FK7VnLlSxjsrtvdve3gaWErgRq7E4g+XbQH5iajVxVYwK7Jrfbs/Xc+zOA33nwKrBbst5OAp5z9w/dfR3wHHBylrJU9gNgjLtvBnD39yvlavC6y0GucncA/8O2F5tFXWfu/qy7lw+D8yrhWoryXM1hnRFpmRXc/T13n5Pc/ghYBOxF7Z/72l7TrDOzQmAAMC65X9fnvnLeqcBx5XsRMtGc94F/G3g9KQh7ES4cKleWtAF8xd3fg/BiA1/OQZa9gBU1LL+29j2Af1f6cFbOm6krgJ+b2QrgduCaRmbMtgOAPsnXw5fMrFczyYWZnU74Nje3ykPRs1VyMWHLsbnlirHMGiW7HXoCr1H7574p895J2Cj4Irlf1+e+Ilfy+Ppk+oxkcil9nczsL8BXa3joOnd/rJ7ndiN8pTyxvKmGyRp1/mMjc9W2/Jr+AXod0zdIXRmB44Afu/sjZvYd4AHg+DqW2STrjvBe6kD42toL+KOZ7VvH8mtbd41ST7Zr2fpe2uZptWRo0vebmV0HbAEm1JMrq+usgbK2LjIKYbYL8Ahwhbv/p46N1ybJa2anAe+7+2wz69eAZeckV84KuLsf35jnJV9LpgHfc/dlSXMZW79ewraX7a82s6+5+3vJV6X3qUMjc9XVbUBN7R8Qvrq1TP7bpupmoK6MZvY7YHhy92GSr291ZCwD+lVpf7GhWVLk+gHwaLKLa4aZfUHozCftumuU2rKZWXfCfuS5yYe+EJhj4eBv1HWW5BsEnAYcl6w76shFHe25Er3LDDNrRSjeE9z90aS5ts99U+U9CjjdzE4FCgi7Ne+k9s99ea4yM2tJ2P35YcYpcrmDv74fqh8s3I1wkOTbNUw7k7B1V34Q89Sk/edsezDjthzk6sa2B5X+STi40zK53ZmtB3i6Jc95mG0PZlyWpXW2COiX3D4OmJ3cHsC2B29mJO27A28Tto47JLd3z8FreSkwOrl9AOHrojVm3eX4PbecrQcxY6+zk4GFQKcq7c1mncV6nSot3wjHvO6s0l7j57621zTHGfux9SBmjZ974HK2PYj5x6wsu6leiCp/8FmE/0ibgdXAn5P2nwIbgNJKP+VnM5QA8wlHxO9h61WkewDPA28lvxv9QastV/LYdcmyF5OcBZK0n0o4Mr6M8LW4vH1fwpkzS5MXtU2W1t3RwOzkg/QacFilN/q9SY432PYf0MVJjqXARTl6TVsDf0heozlA/8auuxy/95aztYDHXmdLCf/oyt/r9zfTddbky6y07KMJuxrmVVpPp9b2ua/rNc1hxn5sLeA1fu4JW+kPJ4a0E9AAAAA9SURBVO0zgH2zsWxdSi8ikqea81koIiJSBxVwEZE8pQIuIpKnVMBFRPKUCriISJ5SARcRyVMq4CIieer/A2DqAXgIvrpXAAAAAElFTkSuQmCC\n", - "text/plain": [ - "
" - ] - }, - "metadata": { - "needs_background": "light" - }, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "l = []\n", "\n", @@ -2206,49 +3481,9 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "BR: 0.0\n", - "0.8210526315789474\n", - "\n", - "BR: 0.0001\n", - "0.631578947368421\n", - "\n", - "BR: 0.0002\n", - "0.8210526315789474\n", - "\n", - "BR: 0.00030000000000000003\n", - "0.8\n", - "\n", - "BR: 0.0004\n", - "0.5052631578947369\n", - "\n", - "BR: 0.0005\n", - "0.7789473684210526\n", - "\n", - "BR: 0.0006000000000000001\n", - "0.5473684210526316\n", - "\n", - "BR: 0.0007\n", - "0.5473684210526316\n", - "\n", - "BR: 0.0008\n", - "0.5894736842105263\n", - "\n", - "BR: 0.0009000000000000001\n", - "0.5263157894736842\n", - "\n", - "BR: 0.001\n", - "0.7368421052631579\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "for s in range(len(l)):\n", " print('BR: {}'.format(BR_steps[s]))\n", @@ -2261,7 +3496,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# print(np.array(Nll_list[0][:10])-np.array(Nll_list[1][:10]))" + ] }, { "cell_type": "code",