Source code for pysrw.emitters

"""Radiating objects."""

import numpy as np

from . import srwlib
from . import configuration

[docs] class PointSource(srwlib.SRWLPtSrc):
[docs] def __init__(self, xPos=0, yPos=0, zPos=0, flux=1e10, pol="H"): """Fully coherent point source. Args: xPos (optional): the x point source position. Defaults to 0. yPos (optional): the y point source position. Defaults to 0. zPos (optional): the z point source position. Defaults to 0. flux (optional): photon flux in ph/(s0.1%BW). pol: one of 'H', 'V' or 'radial' polarization. """ pol = {"H": 1, "V": 2, "radial":7}[pol] super().__init__(_x=xPos, _y=yPos, _z=zPos, _flux=flux, _polar=pol)
[docs] class GaussianBeam(srwlib.SRWLGsnBm):
[docs] def __init__(self, xPos=0, yPos=0, zPos=0, xAngle=0, yAngle=0, xSigma=100e-6, ySigma=100e-6, pol="H"): """Fully coherent Gaussian beam. Args: xPos (optional): the x waist position. Defaults to 0. yPos (optional): the y waist position. Defaults to 0. zPos (optional): the z waist position. Defaults to 0. xAngle (optional): the horizontal tilt angle. Defaults to 0. yAngle (optional): the vertical tilt angle. Defaults to 0. xSigma (optional): the horizontal waist size. Defaults to 100e-6. ySigma (optional): the vertical waist size. Defaults to 100e-6. pol: one of 'H' or 'V' polarization. """ _pol = {"H": 1, "V": 2}[pol] super().__init__(_x=xPos, _y=yPos, _z=zPos, _xp=xAngle, _yp=yAngle, _sigX=xSigma, _sigY=ySigma, _polar=_pol)
[docs] class Particle(srwlib.SRWLParticle):
[docs] def __init__(self, energy, xPos, yPos, zPos, xAngle=0, yAngle=0): """Charged ultrarelativistic particle. Particle positions and angles are referred to the start of the computation, :math:`c \cdot t=0`. Args: energy: particle energy in Gev. xPos: particle x position. yPos: particle y position. zPos: particle z position. xAngle (optional): horizontal tilt angle. Defaults to 0. yAngle (optional): vertical tilt angle. Defaults to 0. """ self.xPos = xPos self.yPos = yPos self.zPos = zPos self.xAngle = xAngle self.yAngle = yAngle self.energy = energy self.gamma = energy * np.abs(configuration.CONFIG.PART_CHARGE) / \ configuration.CONFIG.PART_MASS super().__init__(_x=xPos, _y=yPos, _z=zPos, _xp=xAngle, _yp=yAngle, _gamma=self.gamma)
[docs] class ParticleBeam(srwlib.SRWLPartBeam):
[docs] def __init__(self, energy, xPos, yPos, zPos, xAngle=0, yAngle=0, xSigma=0, ySigma=0, xDiv=0, yDiv=0, dEoverE=0, current=1): """Ultrarelativistic beam. All quantities are referred to the start of the computation, i.e. for c*t=0. Args: energy: particle energy in Gev. xPos: particle x position. yPos: particle y position. zPos: particle z position. xAngle (optional): horizontal tilt angle. Defaults to 0. yAngle (optional): vertical tilt angle. Defaults to 0. xSigma (optional): horizontal beam size. Defaults to 0. ySigma (optional): vertical beam size. Defaults to 0. xDiv (optional): horizontal beam divergence. Defaults to 0. yDiv (optional): vertical beam divergence. Defaults to 0. dEoverE (optional): energy spread. Defaults to 0. """ # TODO test the second order momenta effect # store the nominal particle which represents the equivalent filament # (i.e. zero emittance) beam self.nominalParticle = Particle(energy, xPos, yPos, zPos, xAngle, yAngle) self.xSigma = xSigma self.ySigma = ySigma self.xDiv = xDiv self.yDiv = yDiv self.gamma = self.nominalParticle.gamma # alias # second order momenta (look at SRWLPartBeam for details) self.secondMomenta = srwlib.array("d", [xSigma**2, 0, xDiv**2, ySigma**2, 0, yDiv**2, 0, 0, 0, 0, dEoverE**2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) super().__init__(_Iavg=current, _partStatMom1=self.nominalParticle, _arStatMom2=self.secondMomenta)