{ "cells": [ { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Download this notebook :download:`here `." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Quickstart: Create an amplitude model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Your analysis starts by defining an amplitude model that describes the\n", "reaction process you want to study. Such a model is generally very complex\n", "and requires a fair amount of effort by the analyst (you). This also gives a\n", "lot of room for mistakes.\n", "\n", "The [‘expert system’](https://en.wikipedia.org/wiki/Expert_system) is\n", "responsible to give you advice on the form of an amplitude model based\n", "on the problem set you define (initial state, final state, allowed\n", "interactions, intermediate states, etc.). Internally, the system propagates\n", "the quantum numbers through the reaction graph while satisfying the specified\n", "conservation rules. How to control this procedure is explained in more detail\n", "below.\n", "\n", "Afterwards, the amplitude model of the expert system can be exported into [ComPWA](https://compwa.github.io/) or [Tensorwaves](https://pwa.readthedocs.io/projects/tensorwaves/en/latest/). The\n", "model can for instance be used to generate a data set (toy Monte Carlo) for\n", "this reaction and to optimize its parameters to resemble an actual data set\n", "as good as possible." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.1. Define the problem set" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "We first define the boundary conditions of our physics problem, such as\n", "initial state, final state, formalism type, etc. and pass all of that\n", "information to the :class:`.StateTransitionManager`. This is the main user\n", "interface class of the `expertsystem`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from expertsystem.ui import (\n", " StateTransitionManager,\n", " InteractionTypes,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "stm = StateTransitionManager(\n", " initial_state=[\"J/psi\"],\n", " final_state=[\"gamma\", \"pi0\", \"pi0\"],\n", " formalism_type=\"helicity\",\n", " topology_building=\"isobar\",\n", ")" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. note::\n", " The :class:`.StateTransitionManager` (STM) is the main user interface\n", " class of the `expertsystem`. The boundary conditions of your\n", " physics problem, such as the initial state, final state, formalism type,\n", " etc., are defined through this interface.\n", "\n", " * :meth:`.prepare_graphs` of the STM creates all topology graphs ―\n", " here, using the isobar model (a tree of two-body decays). The function\n", " also initializes the graphs with the initial and final state and a set\n", " of conservation laws at each interaction node.\n", "\n", " * By default, all three interaction types (strong, EM, weak) are used in\n", " the preparation stage. However, it is also possible to choose the\n", " allowed interaction types globally via\n", " :meth:`.set_allowed_interaction_types`.\n", "\n", " After the preparation step, you can modify the settings returned by\n", " :meth:`.prepare_graphs` to your liking. Since the output of this function\n", " contains quite a lot of information, the\n", " :mod:`expertsystem UI ` aids in the\n", " configuration (especially the STM).\n", " \n", " * A subset of particles that are allowed as intermediate states can also\n", " be specified: either through the\n", " `STM's constructor <.StateTransitionManager>` or by\n", " setting the instance attribute ``allowed_intermediate_particles``." ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. hint::\n", " How does the :class:`.StateTransitionManager` know what a ``\"J/psi\"`` is?\n", " It simply uses a default particle list that is shipped the repository (see\n", " `here `__)\n", " and is handled by the :mod:`.particle` module. See :doc:`/usage/particles` for how to add custom particle definitions." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.2. Prepare topologies" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create all topology graphs using the **isobar model** (tree of two-body\n", "decays) and initialize the graphs with the initial and final state. Remember\n", "that each interaction node defines its own set of conservation laws." ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "The :class:`.StateTransitionManager` (STM) defines three interaction types:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "| Interaction | Strength |\n", "| -------------------- | --------- |\n", "| strong | $60$ |\n", "| electromagnetic (EM) | $1$ |\n", "| weak | $10^{-4}$ |" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "By default, all three are used in the preparation stage. The function\n", ":meth:`.prepare_graphs` of the STM generates graphs with all possible\n", "combinations of interaction nodes. An overall interaction strength is\n", "assigned to each graph and they are grouped according to this strength." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "graph_interaction_settings_groups = stm.prepare_graphs()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.3. Find solutions" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "If you are happy with the default settings generated by the\n", ":class:`.StateTransitionManager`, just start with solving directly!" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. note::\n", " This step takes about 30 sec on an Intel(R) Core(TM) i7-6820HQ CPU\n", " @ 2.70GHz running multi-threaded" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "solutions, violated_rules = stm.find_solutions(graph_interaction_settings_groups)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from expertsystem.topology.graph import get_intermediate_state_edges\n", "\n", "\n", "def print_intermediate_states(solutions):\n", " \"\"\"Just a little function to print the intermediate states.\"\"\"\n", " print(\"intermediate states:\")\n", " intermediate_states = set()\n", " for g in solutions:\n", " edge_id = get_intermediate_state_edges(g)[0]\n", " intermediate_states.add(g.edge_props[edge_id][\"Name\"])\n", " print(intermediate_states)\n", "\n", "\n", "print(\"found\", len(solutions), \"solutions!\")\n", "print_intermediate_states(solutions)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we have a lot of solutions that are actually heavily suppressed\n", "(they involve two weak decays)." ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "In general, you can modify the dictionary returned by\n", ":meth:`.prepare_graphs` directly, but the STM also comes with functionality\n", "to globally choose the allowed interaction types." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So, go ahead and **disable** the **EM** and **weak** interaction:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "stm.set_allowed_interaction_types([InteractionTypes.Strong])\n", "graph_interaction_settings_groups = stm.prepare_graphs()\n", "solutions, violated_rules = stm.find_solutions(graph_interaction_settings_groups)\n", "\n", "print(\"found\", len(solutions), \"solutions!\")\n", "print_intermediate_states(solutions)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Huh, what happened here? Actually, since a $\\gamma$ particle appears in one\n", "of the interaction nodes, the expert system knows that this node **must\n", "involve EM interactions**! Because the node can be an effective interaction,\n", "the weak interaction cannot be excluded, as it contains only a subset of\n", "conservation laws.\n", "\n", "Since only the strong interaction was supposed to be used, this results in a\n", "warning and the STM automatically corrects the mistake.\n", "\n", "Once the EM interaction is included, this warning disappears. Be aware,\n", "however, that the EM interaction is now available globally. Hence, there now\n", "might be solutions in which both nodes are electromagnetic." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "stm.set_allowed_interaction_types([InteractionTypes.Strong, InteractionTypes.EM])\n", "graph_interaction_settings_groups = stm.prepare_graphs()\n", "solutions, violated_rules = stm.find_solutions(graph_interaction_settings_groups)\n", "\n", "print(\"found\", len(solutions), \"solutions!\")\n", "print_intermediate_states(solutions)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Great! Now we selected only the strongest contributions. Be aware, though,\n", "that there are more effects that can suppress certain decays, like small\n", "branching ratios. In this example, the initial state $J/\\Psi$ can decay into\n", "$\\pi^0 + \\rho^0$ or $\\pi^0 + \\omega$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "| decay | branching ratio |\n", "| ----------------------------------- | --------------- |\n", "| $$\\omega \\rightarrow \\gamma+\\pi^0$$ | 0.0828 |\n", "| $$\\rho^0 \\rightarrow \\gamma+\\pi^0$$ | 0.0006 |" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Unfortunately, the $\\rho^0$ mainly decays into $\\pi+\\pi$, not $\\gamma+\\pi^0$\n", "and is therefore suppressed. This information is currently not known to the\n", "expert system, but it is possible to hand the expert system a list of allowed\n", "intermediate states." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# particles are found by name comparison,\n", "# i.e. f2 will find all f2's and f all f's independent of their spin\n", "stm.allowed_intermediate_particles = [\"f\"]\n", "\n", "solutions, violated_rules = stm.find_solutions(graph_interaction_settings_groups)\n", "\n", "print(\"found \" + str(len(solutions)) + \" solutions!\")\n", "print_intermediate_states(solutions)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we have selected all amplitudes that involve **f** states. The warnings\n", "appear only to notify the user that the list of solutions is not exhaustive:\n", "for certain edges in the graph, no suitable particle was found (since\n", "only f states were allowed)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.4. Write amplitude model to recipe file" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Now that we are satisfied with the intermediate resonances, we are all set convert the solutions that the STM found to an amplitude model! This can be done with the `.StateTransitionManager.write_amplitude_model` method." ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Depending on the formalism type that you chose :ref:`when constructing the STM `, `.write_amplitude_model` will use for instance :class:`.CanonicalAmplitudeGenerator` if you chose to work with formalism type :code:`\"helicity\"`. The output will be written to a **recipe file** in either XML and YAML format. The format is determined form the file extension you use." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "stm.write_amplitude_model(solutions, output_file=\"model.xml\")\n", "stm.write_amplitude_model(solutions, output_file=\"model.yml\")" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. note::\n", "\n", " In this example, we used the helicity formalism. If you want to work with the canonical formalism, you have to construct the :class:`.StateTransitionManager` with argument :code:`formalism_type=\"canonical-helicity\"` instead of :code:`formalism_type=\"helicity\"`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Have a look through the sections of the resulting XML or YAML recipe file to see what you\n", "recognize from the problem set defined above. There may also be some things\n", "you want to change in there manually, so **make sure you store this recipe\n", "file** carefully (e.g. track it with Git) as to avoid overwriting it your\n", "changes after rerunning the expert system." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now you can use this recipe file as an amplitude model in a PWA framework!" ] } ], "metadata": { "celltoolbar": "Raw Cell Format", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.4" } }, "nbformat": 4, "nbformat_minor": 2 }