Skip to content

Commit

Permalink
DOC: use invariants and masses attributes (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Apr 29, 2024
1 parent 379c56c commit 9b6fbbc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 136 deletions.
26 changes: 2 additions & 24 deletions docs/comparison/d2kkk.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -268,28 +268,6 @@
"Latex(aslatex(DPD_MODEL.variables))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"masses = {\n",
" symbol: sp.sympify(value)\n",
" for symbol, value in DPD_MODEL.parameter_defaults.items()\n",
" if symbol.name.startswith(\"m\")\n",
" if len(symbol.name) == 2\n",
"}\n",
"Latex(aslatex(masses))"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -390,9 +368,9 @@
"outputs": [],
"source": [
"p1, p2, p3 = tuple(FourMomentumSymbol(f\"p{i}\", shape=[]) for i in (0, 1, 2))\n",
"s1, s2, s3 = sp.symbols(\"sigma1:4\", nonnegative=True)\n",
"s1, s2, s3 = sorted(DPD_MODEL.invariants, key=str)\n",
"mass_definitions = {\n",
" **masses,\n",
" **DPD_MODEL.masses,\n",
" s1: InvariantMass(p2 + p3) ** 2,\n",
" s2: InvariantMass(p1 + p3) ** 2,\n",
" s3: InvariantMass(p1 + p2) ** 2,\n",
Expand Down
26 changes: 2 additions & 24 deletions docs/comparison/jpsi2phipipi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -261,28 +261,6 @@
"Latex(aslatex(DPD_MODEL.variables))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"masses = {\n",
" symbol: sp.sympify(value)\n",
" for symbol, value in DPD_MODEL.parameter_defaults.items()\n",
" if symbol.name.startswith(\"m\")\n",
" if len(symbol.name) == 2\n",
"}\n",
"Latex(aslatex(masses))"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -374,9 +352,9 @@
"outputs": [],
"source": [
"p1, p2, p3 = tuple(FourMomentumSymbol(f\"p{i}\", shape=[]) for i in (0, 1, 2))\n",
"s1, s2, s3 = sp.symbols(\"sigma1:4\", nonnegative=True)\n",
"s1, s2, s3 = sorted(DPD_MODEL.invariants, key=str)\n",
"mass_definitions = {\n",
" **masses,\n",
" **DPD_MODEL.masses,\n",
" s1: InvariantMass(p2 + p3) ** 2,\n",
" s2: InvariantMass(p1 + p3) ** 2,\n",
" s3: InvariantMass(p1 + p2) ** 2,\n",
Expand Down
26 changes: 2 additions & 24 deletions docs/comparison/jpsi2pipipi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -261,28 +261,6 @@
"Latex(aslatex(DPD_MODEL.variables))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"masses = {\n",
" symbol: sp.sympify(value)\n",
" for symbol, value in DPD_MODEL.parameter_defaults.items()\n",
" if symbol.name.startswith(\"m\")\n",
" if len(symbol.name) == 2\n",
"}\n",
"Latex(aslatex(masses))"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -374,9 +352,9 @@
"outputs": [],
"source": [
"p1, p2, p3 = tuple(FourMomentumSymbol(f\"p{i}\", shape=[]) for i in (0, 1, 2))\n",
"s1, s2, s3 = sp.symbols(\"sigma1:4\", nonnegative=True)\n",
"s1, s2, s3 = sorted(DPD_MODEL.invariants, key=str)\n",
"mass_definitions = {\n",
" **masses,\n",
" **DPD_MODEL.masses,\n",
" s1: InvariantMass(p2 + p3) ** 2,\n",
" s2: InvariantMass(p1 + p3) ** 2,\n",
" s3: InvariantMass(p1 + p2) ** 2,\n",
Expand Down
95 changes: 31 additions & 64 deletions docs/jpsi2ksp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"import qrules\n",
"import sympy as sp\n",
"from ampform.dynamics import BlattWeisskopfSquared, EnergyDependentWidth\n",
"from ampform.kinematics.phasespace import compute_third_mandelstam\n",
"from ampform.sympy import perform_cached_doit\n",
"from IPython.display import Latex, Markdown\n",
"from tensorwaves.data.transform import SympyDataTransformer\n",
Expand Down Expand Up @@ -409,7 +408,7 @@
{
"cell_type": "markdown",
"metadata": {
"jp-MarkdownHeadingCollapsed": true
"tags": []
},
"source": [
"## Preparing for input data"
Expand All @@ -436,29 +435,9 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We set each helicity coupling to $1$, so that each each parameter {class}`~sympy.core.symbol.Symbol` in the expression has a definition:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"couplings = {\n",
" s: 1\n",
" for s in full_intensity_expr.free_symbols\n",
" if isinstance(s, sp.Indexed)\n",
" if \"production\" in str(s) or \"decay\" in str(s)\n",
"}\n",
"model.parameter_defaults.update(couplings)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"With this, the remaining {class}`~sympy.core.symbol.Symbol`s in the full expression are kinematic variables.[^1]\n",
"\n",
Expand All @@ -469,21 +448,22 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"sp.Array(full_intensity_expr.free_symbols - set(model.parameter_defaults))"
"sp.Array(\n",
" sorted(full_intensity_expr.free_symbols - set(model.parameter_defaults), key=str)\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"The $\\theta$ and $\\zeta$ angles are defined by the {attr}`~.AmplitudeModel.variables` attribute (they are shown under {ref}`jpsi2ksp:Model formulation`). Those definitions allow us to create a converter that computes kinematic variables from masses and Mandelstam variables:"
]
Expand Down Expand Up @@ -511,7 +491,9 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"The data input for this data transformer can be several things. One can compute them from a (generated) data sample of four-momenta. Or one can compute them for a Dalitz plane. We do the latter in this section.\n",
"\n",
Expand All @@ -522,31 +504,11 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
},
"tags": [
"hide-input"
]
"tags": []
},
"outputs": [],
"source": [
"masses = {\n",
" symbol: value\n",
" for symbol, value in model.parameter_defaults.items()\n",
" if str(symbol).startswith(\"m\")\n",
" if len(str(symbol)) == 2\n",
"}\n",
"Latex(aslatex(masses))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dalitz_data = {str(s): float(v) for s, v in masses.items()}"
"dalitz_data = {str(s): float(v) for s, v in model.masses.items()}"
]
},
{
Expand All @@ -573,7 +535,9 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"The remaining Mandelstam variable can be expressed in terms of the others as follows:"
]
Expand All @@ -582,24 +546,21 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": true
},
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"s1, s2, s3 = sp.symbols(\"sigma1:4\", nonnegative=True)\n",
"m0, m1, m2, m3 = sp.symbols(\"m:4\", nonnegative=True)\n",
"s1_expr = compute_third_mandelstam(s3, s2, m0, m1, m2, m3)\n",
"(s1, s1_expr), *_ = model.invariants.items()\n",
"Latex(aslatex({s1: s1_expr}))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"That completes the data sample over which we want to evaluate the intensity model defined above:"
]
Expand All @@ -621,15 +582,19 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"We can now extend the sample with angle definitions so that we have a data sample over which the intensity can be evaluated."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"angle_data = masses_to_angles(dalitz_data)\n",
Expand All @@ -653,7 +618,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"free_parameters = {\n",
Expand Down

0 comments on commit 9b6fbbc

Please sign in to comment.