{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "*This notebook was created by Sergey Tomin (sergey.tomin@desy.de). Source and license info is on [GitHub](https://github.com/ocelot-collab/ocelot). January 2018.*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# [Tracking](https://github.com/ocelot-collab/ocelot/blob/dev/demos/ipython_tutorials/2_tracking.ipynb)\n", "\n", "As an example, we will use lattice file (converted to Ocelot format) of the European XFEL Injector. \n", "\n", "##### This example will cover the following topics:\n", "- calculation of the linear optics for the European XFEL Injector.\n", "- Tracking of the particles in first and second order approximation without collective effects.\n", "\n", "#### Coordinates\n", "Coordinates in Ocelot are following:\n", "$$ \n", "\\left (x, \\quad x' = \\frac{p_x}{p_0} \\right), \\qquad \\left (y, \\quad y' = \\frac{p_y}{p_0} \\right), \\qquad \\left (\\tau = c\\Delta t, \\quad p = \\frac{\\Delta E}{p_0 c} \\right)\n", "$$\n", "\n", "### Definitions\n", "- $\\tau = c t - \\frac{s}{\\beta_0}$: Longitudinal coordinate of the particle.\n", "- $s$: Independent variable representing the distance along the beam line (equivalent to the path length of the reference particle).\n", "- $v_0$ and $p_0$: Velocity and momentum of the reference particle, respectively.\n", "- $t$: Time at which a particle reaches position $s$ along the beam line.\n", "- $\\Delta E = E - E_0$, where $E = \\gamma m_0 c^2$ is the total energy of the particle.\n", "\n", "See more in [Ocelot Coordinate System](https://www.ocelot-collab.com/docs/docu/OCELOT%20fundamentals/coordinate_system)\n", "\n", "#### Requirements \n", "* injector_lattice.py - input file, the Injector lattice.\n", "* beam_130MeV.ast - input file, initial beam distribution in [ASTRA](http://www.desy.de/~mpyflo/) format." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "initializing ocelot...\n" ] } ], "source": [ "# the output of plotting commands is displayed inline within frontends, \n", "# directly below the code cell that produced it\n", "%matplotlib inline\n", "\n", "# this python library provides generic shallow (copy) and \n", "# deep copy (deepcopy) operations \n", "from copy import deepcopy\n", "\n", "import time\n", "\n", "# import from Ocelot main modules and functions\n", "from ocelot import *\n", "\n", "# import from Ocelot graphical modules\n", "from ocelot.gui.accelerator import *\n", "\n", "# import injector lattice\n", "from injector_lattice import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to see injector_lattice.py file you can run following command (lattice file is very large):\n", "```\n", "$ %load injector_lattice.py\n", "```\n", "The variable *cell* contains all the elements of the lattice in right order.\n", "\n", "And again Ocelot will work with class [MagneticLattice](https://www.ocelot-collab.com/docs/docu/OCELOT%20fundamentals/magnet-lattice) instead of simple sequence of element. So we have to run following command. \n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "lat = MagneticLattice(cell, stop=None)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Design optics calculation for the EuXFEL Injector\n", "For linear accelerators, the initial [Twiss](https://www.ocelot-collab.com/docs/docu/OCELOT%20fundamentals/twiss) parameters and initial beam energy must be defined to compute the optics.\n", "\n", "To calculate Twiss paramters along the beamline [`twiss`](https://www.ocelot-collab.com/docs/docu/OCELOT%20fundamentals/twiss) is used\n", "\n", "
unit_step is ignored if no physics processes are added \n",
"(excluding kick-like ones such as BeamTransform). In this case, tracking is done element-by-element.\n",
"track() function returns a list of \n",
"Twiss objects (tws_track) and the final \n",
"ParticleArray (p_array).Twiss objects contain key beam properties such as size, position, emittance, and second moments at each step along the lattice.\n",
"