Skip to content

Commit

Permalink
enh: add zfit physics
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-eschle committed Apr 15, 2024
1 parent 5ea0306 commit a4e1347
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 42 deletions.
58 changes: 37 additions & 21 deletions _website/tutorials/introduction/upgrade_guide_020.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"# standard imports\n",
"import zfit\n",
"import zfit.z.numpy as znp # use this \"numpy-like\" for mathematical operations\n",
"import zfit_physics as zphys # physics module, with new physics-inspired PDFs\n",
"from zfit import z"
]
},
Expand All @@ -35,6 +36,8 @@
"outputs": [],
"source": [
"# example usage of the numpy-like backend, use it if possible\n",
"\n",
"\n",
"@z.function\n",
"def maximum(x, y):\n",
" return znp.maximum(x, y)\n",
Expand Down Expand Up @@ -133,7 +136,7 @@
"outputs": [],
"source": [
"# this allows, for example, for a more intuitive way\n",
"np.linspace(*obs12.v1.limits, 7)"
"np.linspace(*obs12.v1.limits, num=7)"
]
},
{
Expand Down Expand Up @@ -205,7 +208,7 @@
"source": [
"## PDFs\n",
"\n",
"- there are a plethora of new PDFs, mostly covering physics inspired use-cases. Amongst the interesting ones are a `GeneralizedCB`, a more general version of the `DoubleCB` that should be preferred in the future. Also a Voigt profile is available, Bernstein polynomials, QGauss, GaussExpTail, etc.\n",
"- there are a plethora of new PDFs, mostly covering physics inspired use-cases. Amongst the interesting ones are a `GeneralizedCB`, a more general version of the `DoubleCB` that should be preferred in the future. A Voigt profile is available, Bernstein polynomials, QGauss, GaussExpTail, etc. and in [zfit-physics](https://zfit.readthedocs.io/en/latest/user_api/zfit.pdf.html#physics-pdfs) HEP specific PDFS , from `CMSShape`, `Cruijff`, `Novosibirsk` and more. \n",
"- the `TruncatedPDF` has been added to allow for a more flexible way of truncating a PDF. Any PDF can be converted to a truncated version using `to_truncated` (which, by default, truncates to the limits of the space).\n",
"- PDFs have a new `plot` method that allows for a quick plotting of the PDF (it takes an \"obs\" argument that allows to simply project it!). This is still experimental and may changes, the main purpose is to allow for a quick check of the PDF in interactive environments. The function is fully compatible with matplotlib and takes an `ax` argument, it also allows to pass through any keyword arguments to the plotting function."
]
Expand All @@ -217,7 +220,8 @@
"metadata": {},
"outputs": [],
"source": [
"# all the new PDFs"
"# all the new PDFs\n",
"print(zfit.pdf.__all__)"
]
},
{
Expand All @@ -226,6 +230,16 @@
"id": "18",
"metadata": {},
"outputs": [],
"source": [
"print(zphys.pdf.__all__)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19",
"metadata": {},
"outputs": [],
"source": [
"# create a PDF\n",
"pdf = zfit.pdf.Gauss(\n",
Expand All @@ -240,7 +254,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "19",
"id": "20",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -251,7 +265,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "20",
"id": "21",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -261,7 +275,7 @@
},
{
"cell_type": "markdown",
"id": "21",
"id": "22",
"metadata": {},
"source": [
"## Loss and minimizer\n",
Expand All @@ -281,7 +295,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "22",
"id": "23",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -294,7 +308,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "23",
"id": "24",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -304,7 +318,7 @@
},
{
"cell_type": "markdown",
"id": "24",
"id": "25",
"metadata": {},
"source": [
"## Result\n",
Expand All @@ -317,7 +331,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "25",
"id": "26",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -330,7 +344,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "26",
"id": "27",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -341,7 +355,7 @@
},
{
"cell_type": "markdown",
"id": "27",
"id": "28",
"metadata": {},
"source": [
"## Serialization\n",
Expand All @@ -357,7 +371,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "28",
"id": "29",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -368,7 +382,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "29",
"id": "30",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -380,7 +394,7 @@
},
{
"cell_type": "markdown",
"id": "30",
"id": "31",
"metadata": {},
"source": [
"## Parameters as arguments\n",
Expand All @@ -393,7 +407,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "31",
"id": "32",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -408,7 +422,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "32",
"id": "33",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -431,7 +445,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "33",
"id": "34",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -444,11 +458,13 @@
{
"cell_type": "code",
"execution_count": null,
"id": "34",
"id": "35",
"metadata": {},
"outputs": [],
"source": [
"# creating a PDF looks also different, but here we use the name of the parametrization and the axis (integers)\n",
"\n",
"\n",
"class MyGauss2D(zfit.pdf.ZPDF):\n",
" _PARAMS = (\"mu\", \"sigma\")\n",
" _N_OBS = 2\n",
Expand All @@ -465,7 +481,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "35",
"id": "36",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -476,7 +492,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "36",
"id": "37",
"metadata": {},
"outputs": [],
"source": []
Expand Down
Loading

0 comments on commit a4e1347

Please sign in to comment.