{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Spectrum\n\nBasic example of computation of synchrotron radiation spectrum.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import modules required for simulations and for comparison with the \ntheoretical distribution of dipole radiation.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\nfrom scipy.special import kv\nfrom scipy.constants import e, epsilon_0, mu_0, c, pi, h\n\nimport pysrw as srw" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We use the same source used for the simulation of the spatial distribution\nin the example :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)\n\nmag_container = srw.magnets.MagnetsContainer([dipole])\n\nbeam = srw.emitters.ParticleBeam(energy, xPos=0, yPos=0, zPos=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The simulation of the radiation spectrum requires an \n:py:class:`~pysrw.wavefronts.Observer`. The spectrum is computed at the \nobserver centre, all other parameters can be ignored\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "observer = srw.wavefronts.Observer(centerCoord=[0, 0, 5])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The computation is performed with \n:py:func:`~pysrw.computations.computeSpectrum`. In this example we request \nthe computation of 1000 points between 0.01 and 10 nm. Keep in mind that the\npoints are uniformely sampled along the photon energy axis. The points in the\nwavelength axis won't be evenly distributed.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "wfr = srw.computeSpectrum(particleBeam=beam, \n magnetsContainer=mag_container,\n observer=observer, \n fromWavelength=.01, toWavelength=10, numPoints=1000,\n srApprox=\"auto-wiggler\")\nspectrum = wfr.getSpectrumI()\nsrw.plotSpectrum(spectrum, axisScale=[\"log\", \"log\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We compute the corresponding theoretical spectral distribution from the \nSchwinger model\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "r_p = observer.zPos\ntheta = 0\nwl = wfr.wlax # nm\nwl_c = dipole.getLambdaCritical() # nm\ngamma = beam.nominalParticle.gamma\n\ngt_sqr = (gamma * theta)**2\nxi = wl_c/ (2 * wl) * (1 + gt_sqr)**(3/2)\n\ne_theo_h = (-np.sqrt(3)*e*gamma) / ((2*pi)**(3/2) * epsilon_0 * c *r_p) *\\\n (wl_c / (2 * wl)) * (1 + gt_sqr) * kv(2/3, xi)\n\ne_theo_v = (1j*np.sqrt(3)*e*gamma) / ((2 * pi)**(3/2) * epsilon_0 * c *r_p) *\\\n (wl_c / (2 * wl)) * (gamma * theta) * np.sqrt(1 + gt_sqr) * kv(1/3, xi)\n\nint_theo = (4 * pi) / (mu_0 * c * wl*1e-9 * h * e) \\\n * 1e-15 * (np.abs(e_theo_h)**2 + np.abs(e_theo_v)**2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The final plot compares simulated and theoretical results. The curve exhibits\nthe typical broadband emission of dipole radiation, with the critical \nwavelength dividing the spectrum in two regions of equal radiated power \n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fig, ax = plt.subplots()\nax.plot(wl, spectrum[\"data\"], label=\"sim\")\nax.plot(wl, int_theo, label=\"theo\", linestyle=\"--\")\nax.axvline(wl_c, label=\"critical wl\", color=\"red\", linestyle=\"--\")\nax.set_xlabel(\"Wavelength [nm]\")\nax.set_ylabel(\"Intensity [ph / (s mm^2 nm)]\")\nax.set_xscale(\"log\")\nax.set_yscale(\"log\")\nax.grid()\nax.legend()\nplt.tight_layout()\nplt.show()" ] } ], "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 }