|
1 | 1 | {
|
2 | 2 | "cells": [
|
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": { |
| 7 | + "jupyter": { |
| 8 | + "source_hidden": true |
| 9 | + }, |
| 10 | + "tags": [ |
| 11 | + "remove-cell" |
| 12 | + ] |
| 13 | + }, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "%config Completer.use_jedi = False" |
| 17 | + ] |
| 18 | + }, |
3 | 19 | {
|
4 | 20 | "cell_type": "markdown",
|
5 | 21 | "metadata": {},
|
|
11 | 27 | "cell_type": "markdown",
|
12 | 28 | "metadata": {},
|
13 | 29 | "source": [
|
14 |
| - "In this section, we will use the [AmplitudeModel](expertsystem.amplitude.model.AmplitudeModel) that we created with the expert system in [the previous step](./1_create_model) to generate a data sample via hit & miss Monte Carlo. We do this with the [tensorwaves.data.generate](tensorwaves.data.generate) module.\n", |
| 30 | + "In this section, we will use the {class}`~expertsystem.amplitude.helicity.HelicityModel` that we created with the expert system in [the previous step](./1_create_model) to generate a data sample via hit & miss Monte Carlo. We do this with the {mod}`tensorwaves.data.generate` module.\n", |
15 | 31 | "\n",
|
16 |
| - "First, we {func}`~.expertsystem.io.load` an {class}`~expertsystem.amplitude.model.AmplitudeModel` that was created in the previous step:" |
| 32 | + "First, we {func}`~.expertsystem.io.load` an {class}`~expertsystem.amplitude.helicity.HelicityModel` that was created in the previous step:" |
17 | 33 | ]
|
18 | 34 | },
|
19 | 35 | {
|
|
22 | 38 | "metadata": {},
|
23 | 39 | "outputs": [],
|
24 | 40 | "source": [
|
25 |
| - "from expertsystem import io\n", |
| 41 | + "# TODO: pickling of the HelicityModel does not work, so we have to currently redo all steps from before...\n", |
| 42 | + "import expertsystem as es\n", |
26 | 43 | "\n",
|
27 |
| - "model = io.load(\"amplitude_model_helicity.yml\")" |
| 44 | + "result = es.generate_transitions(\n", |
| 45 | + " initial_state=(\"J/psi(1S)\", [-1, +1]),\n", |
| 46 | + " final_state=[\"gamma\", \"pi0\", \"pi0\"],\n", |
| 47 | + " allowed_intermediate_particles=[\"f(0)\"],\n", |
| 48 | + " allowed_interaction_types=\"strong and EM\",\n", |
| 49 | + ")\n", |
| 50 | + "model = es.generate_amplitudes(result)\n", |
| 51 | + "from expertsystem.amplitude.dynamics import set_resonance_dynamics\n", |
| 52 | + "from expertsystem.amplitude.dynamics.builder import (\n", |
| 53 | + " create_relativistic_breit_wigner_with_ff,\n", |
| 54 | + ")\n", |
| 55 | + "\n", |
| 56 | + "for name in result.get_intermediate_particles().names:\n", |
| 57 | + " set_resonance_dynamics(\n", |
| 58 | + " model, name, create_relativistic_breit_wigner_with_ff\n", |
| 59 | + " )" |
28 | 60 | ]
|
29 | 61 | },
|
30 | 62 | {
|
|
38 | 70 | "cell_type": "markdown",
|
39 | 71 | "metadata": {},
|
40 | 72 | "source": [
|
41 |
| - "An [AmplitudeModel](expertsystem.amplitude.model.AmplitudeModel) defines the kinematics, the particles involved in the reaction, the dynamics used for the model on which to perform the eventual optimization, etc." |
| 73 | + "A {class}`~expertsystem.amplitude.helicity.HelicityModel` defines the kinematics, the particles involved in the reaction, the dynamics used for the model on which to perform the eventual optimization, etc." |
42 | 74 | ]
|
43 | 75 | },
|
44 | 76 | {
|
|
47 | 79 | "metadata": {},
|
48 | 80 | "outputs": [],
|
49 | 81 | "source": [
|
| 82 | + "# TODO: this part will be changed once the kinematics is ported to the expertsystem!\n", |
50 | 83 | "from tensorwaves.physics.helicity_formalism.kinematics import (\n",
|
51 | 84 | " HelicityKinematics,\n",
|
| 85 | + " ParticleReactionKinematicsInfo,\n", |
| 86 | + " SubSystem,\n", |
| 87 | + ")\n", |
| 88 | + "\n", |
| 89 | + "kin = HelicityKinematics(\n", |
| 90 | + " ParticleReactionKinematicsInfo(\n", |
| 91 | + " initial_state_names=[\n", |
| 92 | + " x.name for x in model.kinematics.initial_state.values()\n", |
| 93 | + " ],\n", |
| 94 | + " final_state_names=[\n", |
| 95 | + " x.name for x in model.kinematics.final_state.values()\n", |
| 96 | + " ],\n", |
| 97 | + " particles=model.particles,\n", |
| 98 | + " fs_id_event_pos_mapping=dict(\n", |
| 99 | + " {k: i for i, k in enumerate(model.kinematics.final_state.keys())}\n", |
| 100 | + " ),\n", |
| 101 | + " )\n", |
52 | 102 | ")\n",
|
| 103 | + "kin.register_subsystem(SubSystem([[3, 4], [2]], [], []))\n", |
| 104 | + "kin.register_subsystem(SubSystem([[3], [4]], [2], []))\n", |
| 105 | + "kin.register_invariant_mass([2, 4])\n", |
| 106 | + "\n", |
| 107 | + "import pickle\n", |
| 108 | + "\n", |
| 109 | + "with open(\"kinematics.pickle\", \"wb\") as kin_file:\n", |
| 110 | + " pickle.dump(kin, kin_file)\n", |
53 | 111 | "\n",
|
54 |
| - "kin = HelicityKinematics.from_model(model)\n", |
55 | 112 | "print(\"Initial state mass:\", kin.reaction_kinematics_info.initial_state_masses)\n",
|
56 | 113 | "print(\"Final state masses:\", kin.reaction_kinematics_info.final_state_masses)\n",
|
57 | 114 | "print(\"Involved particles:\", model.particles.names)"
|
|
110 | 167 | "cell_type": "markdown",
|
111 | 168 | "metadata": {},
|
112 | 169 | "source": [
|
113 |
| - "'Data samples' are more complicated than phase space samples in that they represent the intensity profile resulting from a reaction. You therefore need an [IntensityTF](tensorwaves.physics.helicity_formalism.amplitude.IntensityTF) object (or, more generally, a [Function](tensorwaves.interfaces.Function) instance) and a phase space over which to generate that intensity distribution. We call such a data sample an **intensity-based sample**.\n", |
| 170 | + "'Data samples' are more complicated than phase space samples in that they represent the intensity profile resulting from a reaction. You therefore need an {class}`~tensorwaves.physics.amplitude.Intensity` object (or, more generally, a [Function](tensorwaves.interfaces.Function) instance) and a phase space over which to generate that intensity distribution. We call such a data sample an **intensity-based sample**.\n", |
| 171 | + "\n", |
| 172 | + "An intensity-based sample is generated with the function [generate_data](tensorwaves.data.generate.generate_data). Its usage is similar to [generate_phsp](tensorwaves.data.generate.generate_phsp), but now you have to give an [Intensity](tensorwaves.physics.amplitude.Intensity) in addition to the [Kinematics](tensorwaves.interfaces.Kinematics) object. An [Intensity](tensorwaves.physics.amplitude.Intensity) object can be created with the [SympyModel](tensorwaves.physics.amplitude.SympyModel) class:" |
| 173 | + ] |
| 174 | + }, |
| 175 | + { |
| 176 | + "cell_type": "code", |
| 177 | + "execution_count": null, |
| 178 | + "metadata": {}, |
| 179 | + "outputs": [], |
| 180 | + "source": [ |
| 181 | + "from tensorwaves.physics.amplitude import Intensity, SympyModel\n", |
| 182 | + "\n", |
| 183 | + "sympy_model = SympyModel(\n", |
| 184 | + " expression=model.expression.full_expression,\n", |
| 185 | + " parameters={k: v.value for k, v in model.parameters.items()},\n", |
| 186 | + " variables={},\n", |
| 187 | + ")\n", |
114 | 188 | "\n",
|
115 |
| - "An intensity-based sample is generated with the function [generate_data](tensorwaves.data.generate.generate_data). Its usage is similar to [generate_phsp](tensorwaves.data.generate.generate_phsp), but now you have to give an [IntensityTF](tensorwaves.physics.helicity_formalism.amplitude.IntensityTF) in addition to the [Kinematics](tensorwaves.interfaces.Kinematics) object. An [IntensityTF](tensorwaves.physics.helicity_formalism.amplitude.IntensityTF) object can be created with the [IntensityBuilder](tensorwaves.physics.helicity_formalism.amplitude.IntensityBuilder) class:" |
| 189 | + "intensity = Intensity(sympy_model)" |
116 | 190 | ]
|
117 | 191 | },
|
118 | 192 | {
|
|
121 | 195 | "metadata": {},
|
122 | 196 | "outputs": [],
|
123 | 197 | "source": [
|
124 |
| - "from tensorwaves.physics.helicity_formalism.amplitude import IntensityBuilder\n", |
| 198 | + "import pickle\n", |
125 | 199 | "\n",
|
126 |
| - "builder = IntensityBuilder(model.particles, kin)\n", |
127 |
| - "intensity = builder.create_intensity(model)" |
| 200 | + "with open(\"sympy_model.pickle\", \"wb\") as model_file:\n", |
| 201 | + " pickle.dump(sympy_model, model_file)" |
128 | 202 | ]
|
129 | 203 | },
|
130 | 204 | {
|
|
177 | 251 | "cell_type": "markdown",
|
178 | 252 | "metadata": {},
|
179 | 253 | "source": [
|
180 |
| - "The data set is just a [dict](dict) of kinematic variables (keys are the names, values is a list of computed values for each event). The numbers you see here are final state IDs as defined in the [AmplitudeModel](expertsystem.amplitude.model.AmplitudeModel) member of the [AmplitudeModel](expertsystem.amplitude.model.AmplitudeModel):" |
| 254 | + "The data set is just a [dict](dict) of kinematic variables (keys are the names, values is a list of computed values for each event). The numbers you see here are final state IDs as defined in the {class}`~expertsystem.amplitude.helicity.HelicityModel` member of the {class}`~expertsystem.amplitude.helicity.HelicityModel`:" |
181 | 255 | ]
|
182 | 256 | },
|
183 | 257 | {
|
|
301 | 375 | "cell_type": "markdown",
|
302 | 376 | "metadata": {},
|
303 | 377 | "source": [
|
304 |
| - "In the [next step](./3_perform_fit), we will illustrate how to 'perform a fit' with [tensorwaves](tensorwaves) by optimizing the intensity model to these data samples." |
| 378 | + "In the [next step](./3_perform_fit), we will illustrate how to 'perform a fit' with {mod}`tensorwaves` by optimizing the intensity model to these data samples." |
305 | 379 | ]
|
306 | 380 | }
|
307 | 381 | ],
|
|
0 commit comments