.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/coordinates.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_coordinates.py: Coordinates =========== Example to familiarize with the coordinate system used by SRW. .. GENERATED FROM PYTHON SOURCE LINES 9-10 Import PySRW module .. GENERATED FROM PYTHON SOURCE LINES 10-13 .. code-block:: default import pysrw as srw .. GENERATED FROM PYTHON SOURCE LINES 14-15 For this example, we use the same dipole as :doc:`simple_dipole` .. GENERATED FROM PYTHON SOURCE LINES 15-24 .. code-block:: default energy = 3.0 # GeV rho = 7.047 # m length = 1.384 # m gap = 36e-3 # m dipole = srw.magnets.Dipole(energy=energy, bendingR=rho, coreL=length, edgeL=gap, centerCoord=[0,0,0]) .. GENERATED FROM PYTHON SOURCE LINES 25-28 We include the dipole in a :py:func:`~pysrw.magnets.MagnetsContainer`. We set `lengthPadFraction` = 2 to define an integration range twice as long as the total length of the dipole. .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: default mag_container = srw.magnets.MagnetsContainer([dipole], lengthPadFraction=2.0) .. GENERATED FROM PYTHON SOURCE LINES 31-32 The limits of the integration are therefore .. GENERATED FROM PYTHON SOURCE LINES 32-35 .. code-block:: default zStart, zEnd, res = mag_container.getIntegrationParams() print(f"Start: {zStart:.2f} - End: {zEnd:.2f}") .. rst-class:: sphx-glr-script-out .. code-block:: none Start: -2.18 - End: 2.18 .. GENERATED FROM PYTHON SOURCE LINES 36-39 We use the default values for the :py:func:`~pysrw.emitters.ParticleBeam` initial position. This produces a beam that arrives at the centre of the dipole (z=0) at the rasverse position [0,0] and with angles [0,0]. .. GENERATED FROM PYTHON SOURCE LINES 39-42 .. code-block:: default beam = srw.emitters.ParticleBeam(energy, xPos=0, yPos=0, zPos=0, xAngle=0, yAngle=0) .. GENERATED FROM PYTHON SOURCE LINES 43-50 The particle trajectory can be computed and plotted using the function :py:func:`~pysrw.plots.plotTrajectory`. We leave the default values of `sStart` and `sEnd` which are assumed as zStart and zEnd. Note that the positions along the curvilinear coordinate 's' do not exactly correspond to the longitudinal positions 'z'. However, when transverse deflections are small, the difference between 's' and 'z' is almost negligible. .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: default traj = srw.computeTrajectory(beam, mag_container) srw.plotTrajectory(traj) .. image-sg:: /examples/images/sphx_glr_coordinates_001.png :alt: coordinates :srcset: /examples/images/sphx_glr_coordinates_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 54-59 As a second case, we simulate a beam travelling along the axis [0,0] and then deflected by the dipole. We need to change the beam definition, setting the initial condition outside of the diple instead of at the dipole centre. Note that this does not affect the position of the dipole, which has still the centre at z = 0. .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. code-block:: default beam = srw.emitters.ParticleBeam(energy, xPos=0, yPos=0, zPos=-1.5, xAngle=0, yAngle=0) .. GENERATED FROM PYTHON SOURCE LINES 63-70 To recompute the trajectory in this case, it is convenient to change the `sStart` and `sEnd` parameters. If we leave the default values, the trajectory computation ranges from sStart = -2.18 and sEnd = 2.18. Since the particle initial position is defined at z = -1.5, these limits do not cover the dipole extension as the trajectory starts more than 2 m before the magnet and ends approximately at z = 0.68, not entirely outside of the magnetic region. .. GENERATED FROM PYTHON SOURCE LINES 70-73 .. code-block:: default traj = srw.computeTrajectory(beam, mag_container) srw.plotTrajectory(traj) .. image-sg:: /examples/images/sphx_glr_coordinates_002.png :alt: coordinates :srcset: /examples/images/sphx_glr_coordinates_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 74-78 We can adjust the limits by choosing a `sStart` = 0 and `sEnd` = 4, so that the trajectory starts at the dipole entrance at `sStart` = -1.5, where the particle initial conditions were defined, and follows the beam for 4 m along the trajectory, thus well outside of the dipole. .. GENERATED FROM PYTHON SOURCE LINES 78-79 .. code-block:: default traj = srw.computeTrajectory(beam, mag_container, sStart=0, sEnd=4) srw.plotTrajectory(traj) .. image-sg:: /examples/images/sphx_glr_coordinates_003.png :alt: coordinates :srcset: /examples/images/sphx_glr_coordinates_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.260 seconds) **Estimated memory usage:** 112 MB .. _sphx_glr_download_examples_coordinates.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: coordinates.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: coordinates.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_