{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Coordinates\n\nExample to familiarize with the coordinate system used by SRW.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import PySRW module\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pysrw as srw" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For this example, we use the same dipole as :doc:`simple_dipole`\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "energy = 3.0 # GeV\nrho = 7.047 # m\nlength = 1.384 # m\ngap = 36e-3 # m\n\ndipole = srw.magnets.Dipole(energy=energy, bendingR=rho, \n coreL=length, edgeL=gap, centerCoord=[0,0,0])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We include the dipole in a :py:func:`~pysrw.magnets.MagnetsContainer`.\nWe set `lengthPadFraction` = 2 to define an integration range twice as long \nas the total length of the dipole.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "mag_container = srw.magnets.MagnetsContainer([dipole], lengthPadFraction=2.0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The limits of the integration are therefore\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "zStart, zEnd, res = mag_container.getIntegrationParams()\nprint(f\"Start: {zStart:.2f} - End: {zEnd:.2f}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We use the default values for the :py:func:`~pysrw.emitters.ParticleBeam` \ninitial position. This produces a beam that arrives at the centre of the \ndipole (z=0) at the rasverse position [0,0] and with angles [0,0].\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "beam = srw.emitters.ParticleBeam(energy, xPos=0, yPos=0, zPos=0, \n xAngle=0, yAngle=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The particle trajectory can be computed and plotted using the \nfunction :py:func:`~pysrw.plots.plotTrajectory`. We leave the default values \nof `sStart` and `sEnd` which are assumed as zStart and zEnd. \nNote that the positions along the curvilinear coordinate 's' \ndo not exactly correspond to the longitudinal positions 'z'. However, when \ntransverse deflections are small, the difference between 's' and 'z' is \nalmost negligible.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "traj = srw.computeTrajectory(beam, mag_container)\nsrw.plotTrajectory(traj)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As a second case, we simulate a beam travelling along the axis [0,0] and\nthen deflected by the dipole. We need to change the beam definition, setting\nthe initial condition outside of the diple instead of at the dipole centre.\nNote that this does not affect the position of the dipole, which has still \nthe centre at z = 0. \n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "beam = srw.emitters.ParticleBeam(energy, xPos=0, yPos=0, zPos=-1.5, \n xAngle=0, yAngle=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To recompute the trajectory in this case, it is convenient to change the \n`sStart` and `sEnd` parameters. If we leave the default values, the \ntrajectory computation ranges from sStart = -2.18 and sEnd = 2.18.\nSince the particle initial position is defined at z = -1.5, these limits \ndo not cover the dipole extension as the trajectory starts\nmore than 2 m before the magnet and ends approximately at z = 0.68, not \nentirely outside of the magnetic region.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "traj = srw.computeTrajectory(beam, mag_container)\nsrw.plotTrajectory(traj)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can adjust the limits by choosing a `sStart` = 0 and `sEnd` = 4, so that\nthe trajectory starts at the dipole entrance at `sStart` = -1.5, where the \nparticle initial conditions were defined, and follows the beam for 4 m along \nthe trajectory, thus well outside of the dipole.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "traj = srw.computeTrajectory(beam, mag_container, sStart=0, sEnd=4)\nsrw.plotTrajectory(traj)" ] } ], "metadata": { "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.9.9" } }, "nbformat": 4, "nbformat_minor": 0 }