def build_beamline(nrays=raycing.nrays): fixedExit = 15. beamLine = raycing.BeamLine(azimuth=0, height=0) rs.GeometricSource( beamLine, 'GeometricSource', (0, 0, -fixedExit), nrays=nrays, dx=5., dy=0, dz=5., dxprime=0., dzprime=0., distE='flat', energies=eLimits, polarization='horizontal') p = 20000. si111 = rm.CrystalSi(hkl=(1, 1, 1), tK=-171+273.15) beamLine.dcm = roe.DCM(beamLine, 'DCM', (0, p - 2000, -fixedExit), surface=('Si111',), material=(si111,)) beamLine.dcm.bragg = math.asin(rm.ch / (2 * si111.d * E0)) beamLine.dcm.cryst2perpTransl = fixedExit/2./math.cos(beamLine.dcm.bragg) beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', (0, p - 1000, 0)) beamLine.qwp = roe.LauePlate(beamLine, 'QWP', (0, p, 0), material=(crystalDiamond,)) beamLine.qwp.pitch = theta0 + math.pi/2 q = 50. beamLine.fsm2 = rsc.Screen(beamLine, 'FSM2', (0, p + q, 0)) return beamLine
def build_beamline(nrays=1e5): beamLine = raycing.BeamLine(height=0) # rs.GeometricSource(beamLine, 'GeometricSource', (0, 0, 0), # nrays=nrays, dx=0, dz=0, distxprime='flat', dxprime=1e-4, # distzprime='flat', dzprime=1e-4, # distE='flat', energies=(E0-dE, E0+dE), polarization='horizontal') rs.GeometricSource( beamLine, 'GeometricSource', (0, 0, 0), nrays=nrays, distx='annulus', dx=(0, 1), dxprime=0, dzprime=0, distE='flat', energies=(E0-dE, E0+dE), polarization='horizontal') beamLine.fsm1 = rsc.Screen(beamLine, 'DiamondFSM1', (0., p-100, 0.)) siCryst = rm.CrystalSi(hkl=(1, 1, 1), geom='Bragg-Fresnel') pitch = \ siCryst.get_Bragg_angle(E0) - siCryst.get_dtheta_symmetric_Bragg(E0) # pitch = np.pi/2 f = 0, p * np.cos(pitch), p * np.sin(pitch) beamLine.fzp = roe.GeneralFZPin0YZ( beamLine, 'FZP', [0., p, 0.], pitch=pitch, material=siCryst, f1='inf', f2=f, E=E0, N=340) beamLine.fzp.order = 1 beamLine.fsm2 = rsc.Screen(beamLine, 'DiamondFSM2', [0, 0, 0], z=(0, -np.sin(2*pitch), np.cos(2*pitch))) if showIn3D: beamLine.fsm2RelPos = [p] else: beamLine.fsm2RelPos = np.linspace(0, p, 21) return beamLine
def compare_dTheta(): """A comparison subroutine used in the module test suit.""" def for_one_material(mat, ref1, title): fig = plt.figure(figsize=(8, 6), dpi=100) ax = fig.add_subplot(111) ax.set_xlabel(r'$\theta_{B}-\alpha$, deg') ax.set_ylabel(r'$\delta\theta$, deg') fig.suptitle(title, fontsize=16) thetaB = np.degrees(mat.get_Bragg_angle(E[0])) calc_dt_new = np.degrees( np.abs(mat.get_dtheta(E, np.radians(alpha)))) p2, = ax.semilogy( alpha+thetaB, calc_dt_new, '-b', label=r'with curvature') calc_dt_reg = np.degrees( np.abs(mat.get_dtheta_regular(E, np.radians(alpha)))) p3, = ax.semilogy( alpha+thetaB, calc_dt_reg, '-r', label=r'without curvature') ax.legend(loc=0) ax.set_xlim(0, 90) ax.set_ylim(6e-5, 0.3) fname = title fig.savefig(fname + '.png') E = np.ones(500) * 10000. alpha = np.linspace(-90., 90., 500) mat = rm.CrystalSi(tK=80) titleStr = u'Deviation from the Bragg angle, Si(111), {0:d}keV'.format( int(E[0]/1000)) for_one_material(mat, None, titleStr)
def build_beamline(nrays=raycing.nrays): fixedExit = 15. beamLine = raycing.BeamLine(azimuth=0, height=0) hDiv = 1.5e-3 vDiv = 2.5e-4 beamLine.source = rs.GeometricSource(beamLine, 'GeometricSource', (0, 0, 0), nrays=nrays, dx=0.1, dy=0, dz=2., dxprime=hDiv / 2, dzprime=0, distE='flat', energies=eLimits, polarization='horizontal') beamLine.feMovableMask = ra.RectangularAperture( beamLine, 'FEMovableMask', [0, 10000, 0], ('left', 'top', 'right', 'bottom'), [-10, 3., 10, -3.]) beamLine.feMovableMask.set_divergence( beamLine.source, [-hDiv / 2, vDiv / 2, hDiv / 2, -vDiv / 2]) yDCM = 21000. si111 = rm.CrystalSi(hkl=(1, 1, 1), tK=-171 + 273.15) beamLine.dcm = roe.DCM(beamLine, 'DCM', (0, yDCM, 0), surface=('Si111', ), material=(si111, )) beamLine.dcm.bragg = math.asin(rm.ch / (2 * si111.d * E0)) beamLine.dcm.cryst2perpTransl = fixedExit / 2. / math.cos( beamLine.dcm.bragg) beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', (0, yDCM + 700, 0)) yVFM = 24000. beamLine.vfm = roe.ToroidMirror(beamLine, 'VFM', (0, yVFM, fixedExit), pitch=4.0e-3) beamLine.vfm.R = yVFM / beamLine.vfm.pitch beamLine.vfm.r = 2. / 3. * yVFM * beamLine.vfm.pitch yFlatMirror = yVFM + 2000. zFlatMirror = (yFlatMirror - yVFM) * 2. * beamLine.vfm.pitch + fixedExit beamLine.vdm = roe.OE(beamLine, 'FlatMirror', (0, yFlatMirror, zFlatMirror), pitch=-beamLine.vfm.pitch, positionRoll=math.pi) ySample = 1.5 * yVFM yQWP = ySample - 3000. beamLine.qwp = roe.OE(beamLine, 'QWP', (0, yQWP, zFlatMirror), roll=math.pi / 4, material=(crystalDiamond, )) beamLine.qwp.pitch = theta0 beamLine.fsm2 = rsc.Screen(beamLine, 'FSM2', (0, ySample, zFlatMirror)) return beamLine
def __init__(self, hkl=[1, 1, 1], tempC=-140, gap=5): if isinstance(hkl, str): hkl = [int(i) for i in hkl] cryst_name = f"Si{hkl[0]}{hkl[1]}{hkl[2]}" self.name = cryst_name self.temperature = 273.15 + tempC self.gap = gap self.cryst = rmats.CrystalSi(hkl=hkl, name=cryst_name, tK=self.temperature) self.dcm = roes.DCM(name=r"DCM", material=self.cryst, material2=self.cryst, cryst2perpTransl=gap)
def plot_compare(): fig1 = plt.figure(1, figsize=(7, 5)) ax = plt.subplot(111, label='1') ax.set_xlabel(u'energy (keV)') ax.set_ylabel(u'flux (a.u.)') cwd = os.getcwd() pickleName = os.path.join(cwd, 'taper_1TotalFlux.pickle') with open(pickleName, 'rb') as f: _f, binEdges, total1D = pickle.load(f) dE = binEdges[1] - binEdges[0] E = binEdges[:-1] + dE / 2. ax.plot(E, total1D / max(total1D), 'r', label='calculated by xrt', lw=2) try: e, f = np.loadtxt('fluxUndulator1DtaperP06.dc0', skiprows=10, usecols=[0, 1], unpack=True) ax.plot(e * 1e-3, f / max(f), 'b', label='calculated by Spectra', lw=2) except: # analysis:ignore pass # e, f = np.loadtxt('yaup-0.out', skiprows=32, usecols=[0, 1], unpack=True) # ax.plot(e*1e-3, f/max(f), 'g', label='calculated by YAUP/XOP', lw=2) theta, fl = np.loadtxt("thetaexafssc1an_zn_hgap_00002r2.fio.gz", skiprows=113, usecols=(0, 5), unpack=True) si_1 = rm.CrystalSi(hkl=(1, 1, 1), tK=77) E = rm.ch / (2 * si_1.d * np.sin(np.radians(theta))) ax.plot(E * 1e-3, fl / max(fl), 'k', lw=2, label='measured @ Petra3') # ax2.set_xlim(0, None) # ax2.set_ylim(1.400, 1.600) ax.legend(loc='lower center') fig1.savefig('compareTaper.png') plt.show()
sys.path.append(os.path.join('..', '..')) # analysis:ignore import xrt.backends.raycing.sources as rsources import xrt.backends.raycing.screens as rscreens import xrt.backends.raycing.materials as rmats import xrt.backends.raycing.oes as roes # import xrt.backends.raycing.apertures as rapts import xrt.backends.raycing.run as rrun import xrt.backends.raycing as raycing import xrt.plotter as xrtplot import xrt.runner as xrtrun Emin, Emax = 8998, 9002 crystalSi01 = rmats.CrystalSi(t=0.1, hkl=[1, 1, 1], useTT=True, calcBorrmann=True, geom=r"Laue reflected") def build_beamline(): beamLine = raycing.BeamLine() beamLine.geometricSource01 = rsources.GeometricSource( bl=beamLine, name=None, center=[0, 0, 0], nrays=1000, distE=r"flat", dx=0.001, dz=0.001,
import numpy as np import sys sys.path.append( r"/reg/neh/home/apra/.conda/envs/myenv/lib/python2.7/site-packages") import xrt.backends.raycing.sources as rsources import xrt.backends.raycing.screens as rscreens import xrt.backends.raycing.materials as rmats import xrt.backends.raycing.oes as roes import xrt.backends.raycing.apertures as rapts import xrt.backends.raycing.run as rrun import xrt.backends.raycing as raycing import xrt.plotter as xrtplot import xrt.runner as xrtrun crystalSi01 = rmats.CrystalSi(name=None) def build_beamline(): HOMS = raycing.BeamLine() HOMS.Source = rsources.GeometricSource(bl=HOMS, name=None, center=[0, 0, 0], dx=0.1, dz=0.1, dxprime=0.0000005, dzprime=0.0000005) HOMS.P1H = rscreens.Screen(bl=HOMS, name=None, center=[0, 89894, 0])
__date__ = "08 Mar 2016" import os, sys sys.path.append(os.path.join('..', '..', '..')) # analysis:ignore import numpy as np import xrt.plotter as xrtp import xrt.runner as xrtr import xrt.backends.raycing.materials as rm from BalderBL import build_beamline, align_beamline stripe = 'Si' E0 = 9000 dE = 4 si111_1 = rm.CrystalSi(hkl=(1, 1, 1), tK=-171 + 273.15) si111_2 = rm.CrystalSi(hkl=(1, 1, 1), tK=-140 + 273.15) si311_1 = rm.CrystalSi(hkl=(3, 1, 1), tK=-171 + 273.15) si311_2 = rm.CrystalSi(hkl=(3, 1, 1), tK=-140 + 273.15) def define_plots(): plots = [] plot = xrtp.XYCPlot('beamFSMDCM', (1, ), xaxis=xrtp.XYCAxis(r'$x$', 'mm'), yaxis=xrtp.XYCAxis(r'$z$', 'mm'), caxis=xrtp.XYCAxis('energy', 'eV'), title='DCM') plot.xaxis.limits = [-7., 7.] plot.yaxis.limits = [38.1 - 7., 38.1 + 7.]
def build_beamline(nrays=raycing.nrays, eMinRays=550, eMaxRays=30550): x0, y0 = -30095.04, -30102.65 # straight section center xFar, yFar = -59999.67, -198.017 height = 1400. azimuth = np.arctan2(xFar - x0, yFar - y0) stripeSi = rm.Material('Si', rho=2.33) stripeRh = rm.Material('Rh', rho=12.41) stripePt = rm.Material('Pt', rho=21.45) si111_1 = rm.CrystalSi(hkl=(1, 1, 1), tK=-171+273.15) si311_1 = rm.CrystalSi(hkl=(3, 1, 1), tK=-171+273.15) si111_2 = rm.CrystalSi(hkl=(1, 1, 1), tK=-140+273.15) si311_2 = rm.CrystalSi(hkl=(3, 1, 1), tK=-140+273.15) filterDiamond = rm.Material('C', rho=3.52, kind='plate') beamLine = raycing.BeamLine(azimuth=azimuth, height=height) wigglerToStraightSection = 645.0 xWiggler = x0 + wigglerToStraightSection * beamLine.sinAzimuth yWiggler = y0 + wigglerToStraightSection * beamLine.cosAzimuth rs.Wiggler(beamLine, name='MPW80', center=( xWiggler, yWiggler, height), nrays=nrays, period=80., K=13, n=12, eE=3., eI=0.4, eSigmaX=200, eSigmaZ=15, eEpsilonX=4.3, eEpsilonZ=0.043, eMin=eMinRays, eMax=eMaxRays, xPrimeMax=1.5, zPrimeMax=0.25) # rs.GeometricSource(beamLine, 'Source', (xWiggler, yWiggler, height), # nrays=nrays, distE='flat', energies=(2000, 25000), # polarization='horizontal') sampleToStraightSection = 36554.1 beamLine.xSample = x0 + sampleToStraightSection * beamLine.sinAzimuth beamLine.ySample = y0 + sampleToStraightSection * beamLine.cosAzimuth beamLine.feFixedMask = ra.RectangularAperture( beamLine, 'FEFixedMask', (-36876.69, -23321.01, height), ('left', 'right', 'bottom', 'top'), [-8.3, 8.3, -2.35, 2.35]) beamLine.fePhotonShutter = ra.RectangularAperture( beamLine, 'FEPhotonShutter', (-37133.37, -23064.33, height), ('left', 'right', 'bottom', 'top'), [-10.5, 10.5, -8.0, 8.0], alarmLevel=0.) beamLine.feMovableMaskLT = ra.RectangularAperture( beamLine, 'FEMovableMaskLT', (-38979.62, -21218.07, height), ('left', 'top'), [-10, 3.], alarmLevel=0.5) beamLine.feMovableMaskRB = ra.RectangularAperture( beamLine, 'FEMovableMaskRB', (-39262.47, -20935.23, height), ('right', 'bottom'), [10, -3.], alarmLevel=0.5) beamLine.filter1 = roe.Plate( beamLine, 'Filter1', (-42740.918, -17456.772, height), pitch=np.pi/2, limPhysX=(-20., 20.), limPhysY=(-9., 9.), surface=('diamond 90 $\mu$m',), material=(filterDiamond,), t=0.09, targetOpenCL=targetOpenCL, alarmLevel=0.) beamLine.fsm1 = rsc.Screen( beamLine, 'DiamondFSM1', (-42920.68, -17277.01, height), compressX=1./2.44) beamLine.vcm = roe.VCM( beamLine, 'VCM', [-43819.49, -16378.20, height], surface=('Rh', 'Si', 'Pt'), material=(stripeRh, stripeSi, stripePt), limPhysX=(-53., 53.), limPhysY=(-655., 655.), limOptX=((-47., -15.5, 16.), (-16., 15.5, 47.)), limOptY=((-650., -655., -650.), (650., 655., 650.)), R=5.0e6, jack1=[-43328.05, -16869.64, 973.0732], jack2=[-44403.38, -15964.02, 973.0732], jack3=[-44233.68, -15794.31, 973.0732], tx1=[0.0, -695.], tx2=[0.0, 705.75], targetOpenCL=targetOpenCL, alarmLevel=0.) beamLine.fsm2 = rsc.Screen( beamLine, 'NormalFSM2', (-44745.34, -15452.36, height), compressX=1./2.44) beamLine.dcm = roe.DCMOnTripodWithOneXStage( beamLine, 'DCM', [-45342.09, -14855.6, 1415.], surface=('Si311', 'Si111'), material=(si311_1, si111_1), material2=(si311_2, si111_2), limPhysX=((-51.1, 6.1), (-6.1, 51.1)), limPhysY=(-30., 30.), cryst2perpTransl=20., cryst2longTransl=95., limPhysX2=((8.6, -48.6), (48.6, -8.6)), limPhysY2=(-90., 90.), jack1=[-45052.88, -15079.04, 702.4973], jack2=[-44987.82, -14490.02, 702.4973], jack3=[-45576.85, -14555.08, 702.4973], targetOpenCL=targetOpenCL, alarmLevel=0.) beamLine.fsm3 = rsc.Screen( beamLine, 'DiamondFSM3', (-46625.89, -13571.81, height), compressX=1./2.44) beamLine.BSBlock = ra.RectangularAperture( beamLine, 'BSBlock', (-45988.52, -14209.17, height), ('bottom',), (22,), alarmLevel=0.) beamLine.slitAfterDCM_LR = ra.RectangularAperture( beamLine, 'SlitAfterDCM_LR', (-46095.65, -14102.04, height), ('left', 'right'), [-25.0, 25.0], alarmLevel=0.5) beamLine.slitAfterDCM_BT = ra.RectangularAperture( beamLine, 'SlitAfterDCM_BT', (-46107.67, -14090.02, height), ('bottom', 'top'), [27.0, 77.0], alarmLevel=0.5) foilsZActuatorOffset = 0 beamLine.xbpm4foils = ra.SetOfRectangularAperturesOnZActuator( beamLine, 'XBPM4foils', (-46137.73, -14059.97, height), (u'Cu5µm', u'Al7µm', u'Al0.8µm', 'top-edge'), (1344.607 + foilsZActuatorOffset, 1366.607 + foilsZActuatorOffset, 1388.607 + foilsZActuatorOffset, 1400. + foilsZActuatorOffset), (45, 45, 45), (8, 8, 8), alarmLevel=0.) beamLine.vfm = roe.DualVFM( beamLine, 'VFM', [-47491.364, -12706.324, 1449.53], surface=('Rh', 'Pt'), material=(stripeRh, stripePt), limPhysX=(-56., 56.), limPhysY=(-714., 714.), limOptX=((1., -46.), (46., -4.)), limOptY=((-712., -712.), (712., 712.)), positionRoll=np.pi, R=5.0e6, r1=70., xCylinder1=23.5, hCylinder1=3.7035, r2=35.98, xCylinder2=-25.0, hCylinder2=6.9504, jack1=[-46987.20, -13210.49, 1272.88], jack2=[-48062.53, -12304.87, 1272.88], jack3=[-47892.83, -12135.16, 1272.88], tx1=[0.0, -713.], tx2=[0.0, 687.75], targetOpenCL=targetOpenCL, alarmLevel=0.2) beamLine.fsm4 = rsc.Screen( beamLine, 'DiamondFSM4', (-48350.17, -11847.53, height), compressX=1./2.44) beamLine.ohPSFront = ra.RectangularAperture( beamLine, 'OH-PS-FrontCollimator', (-48592.22, -11605.47, height), ('left', 'right', 'bottom', 'top'), (-23., 23., 30.48, 79.92), alarmLevel=0.2) beamLine.ohPSBack = ra.RectangularAperture( beamLine, 'OH-PS-BackCollimator', (-48708.19, -11489.51, height), ('left', 'right', 'bottom', 'top'), (-23., 23., 31.1, 81.1), alarmLevel=0.) beamLine.eh100To40Flange = ra.RoundAperture( beamLine, 'eh100To40Flange', [-53420.63, -6777.058, height], 19., alarmLevel=0.) eh100To40FlangeToslit = 1159. slitX = beamLine.eh100To40Flange.center[0] +\ eh100To40FlangeToslit * np.sin(azimuth) slitY = beamLine.eh100To40Flange.center[1] +\ eh100To40FlangeToslit * np.cos(azimuth) beamLine.slitEH = ra.RectangularAperture( beamLine, 'slitEH', (slitX, slitY, height), ('left', 'right', 'bottom', 'top'), [-5, 5, -2.5, 2.5], alarmLevel=0.5) beamLine.fsmAtSample = rsc.Screen( beamLine, 'FocusAtSample', (beamLine.xSample, beamLine.ySample, height)) return beamLine
# -*- coding: utf-8 -*- __author__ = "Konstantin Klementiev, Roman Chernikov" __date__ = "22 Feb 2016" import numpy as np import matplotlib.pyplot as plt # path to xrt: import os, sys; sys.path.append(os.path.join('..', '..', '..')) # analysis:ignore import xrt.backends.raycing.materials as rm crystal = rm.CrystalSi(hkl=(1, 1, 1), tK=80) E = 9000 alpha = np.linspace(-12, 90, 1001) # degrees thetaB = np.degrees(crystal.get_Bragg_angle(E)) dtheta0 = np.degrees(np.abs(crystal.get_dtheta_regular(E, np.radians(alpha)))) plt.semilogy(alpha+thetaB, dtheta0, '-r', label=r'without curvature') dtheta1 = np.degrees(np.abs(crystal.get_dtheta(E, np.radians(alpha)))) plt.semilogy(alpha+thetaB, dtheta1, '-b', label=r'with curvature') plt.gca().set_xlabel(r'$\theta_{B}-\alpha$ (deg)') plt.gca().set_ylabel(r'$\delta\theta$ (deg)') plt.gca().set_xlim(0, 90) plt.gca().set_ylim(6e-5, 1) plt.gcf().suptitle('Deviation from the Bragg angle, Si(111), {0:.0f}keV'. format(E/1000), fontsize=16) plt.legend() plt.show()
# -*- coding: utf-8 -*- __author__ = "Konstantin Klementiev, Roman Chernikov" __date__ = "22 Jan 2016" import numpy as np import matplotlib.pyplot as plt # path to xrt: import os, sys sys.path.append(os.path.join('..', '..', '..')) # analysis:ignore import xrt.backends.raycing.materials as rm crystal = rm.CrystalSi(hkl=(1, 1, 1)) E = 9000 dtheta = np.linspace(-20, 80, 501) theta = crystal.get_Bragg_angle(E) + dtheta * 1e-6 curS, curP = crystal.get_amplitude(E, np.sin(theta)) print(crystal.get_a()) print(crystal.get_F_chi(E, 0.5 / crystal.d)) print( u'Darwin width at E={0:.0f} eV is {1:.5f} µrad for s-polarization'.format( E, crystal.get_Darwin_width(E) * 1e6)) plt.plot(dtheta, abs(curS)**2, 'r', dtheta, abs(curP)**2, 'b') plt.gca().set_xlabel(u'$\\theta - \\theta_{B}$ (µrad)') plt.gca().set_ylabel(r'reflectivity') plt.show()
import numpy as np from scipy import optimize from matplotlib import pyplot as plt import os, sys sys.path.append(os.path.join('..', '..', '..')) # analysis:ignore import xrt.backends.raycing.sources as rsources import xrt.backends.raycing.screens as rscreens import xrt.backends.raycing.materials as rmats import xrt.backends.raycing.oes as roes import xrt.backends.raycing.apertures as rapts import xrt.backends.raycing.run as rrun import xrt.backends.raycing as raycing import xrt.plotter as xrtplot import xrt.runner as xrtrun Si111 = rmats.CrystalSi(hkl=[1, 1, 1], name=r"Si111") minimizationArray = [] counter = [0] def build_beamline(): beamLine = raycing.BeamLine(alignE=10000) beamLine.Wiggler = rsources.Wiggler(bl=beamLine, name=r"Flat-Top Wiggler", center=[0, 0, 0], nrays=500000, eE=2.9, eI=0.25, eEpsilonX=18.1,
def build_beamline(nrays=raycing.nrays, hkl=(1, 1, 1), stripe='Si', eMinRays=None, eMaxRays=None): filterDiamond = rm.Material('C', rho=3.52, kind='plate') if stripe.startswith('S'): materialVCM = stripeSi materialVFM = stripeSiO2 elif stripe.startswith('I'): materialVCM = stripeIr materialVFM = stripeIr else: raise ('Don' 't know the mirror material') si_1 = rm.CrystalSi(hkl=hkl, tK=-171 + 273.15) si_2 = rm.CrystalSi(hkl=hkl, tK=-140 + 273.15) height = 0 beamLine = raycing.BeamLine(azimuth=0, height=height) wigglerToStraightSection = 0 xWiggler = wigglerToStraightSection * beamLine.sinAzimuth yWiggler = wigglerToStraightSection * beamLine.cosAzimuth if eMinRays is None: eMinRays = 50. if eMaxRays is None: eMaxRays = 60050. # rs.WigglerWS( # beamLine, name='SoleilW50', center=(xWiggler, yWiggler, height), # nrays=nrays, period=50., K=8.446, n=39, eE=3., eI=0.5, # eSigmaX=48.66, eSigmaZ=6.197, eEpsilonX=0.263, eEpsilonZ=0.008, # eMin=50, eMax=60050, eMinRays=eMinRays, eMaxRays=eMaxRays, eN=2000, # xPrimeMax=0.22, zPrimeMax=0.06, nx=40, nz=10) rs.Wiggler(beamLine, name='SoleilW50', center=(xWiggler, yWiggler, height), nrays=nrays, period=50., K=8.446, n=39, eE=3., eI=0.5, eSigmaX=48.66, eSigmaZ=6.197, eEpsilonX=0.263, eEpsilonZ=0.008, eMin=eMinRays, eMax=eMaxRays, xPrimeMax=0.22, zPrimeMax=0.06) beamLine.fsm0 = rsc.Screen(beamLine, 'FSM0', (0, 15000, height)) beamLine.feFixedMask = ra.RectangularAperture( beamLine, 'FEFixedMask', (0, 15750, height), ('left', 'right', 'bottom', 'top'), [-3.15, 3.15, -0.7875, 0.7875]) beamLine.fsmFE = rsc.Screen(beamLine, 'FSM-FE', (0, 16000, height)) beamLine.filter1 = roe.Plate(beamLine, 'Filter1', (0, 23620, height), pitch=math.pi / 2, limPhysX=(-9., 9.), limPhysY=(-4., 4.), surface='diamond 60 $\mu$m', material=filterDiamond, t=0.06, alarmLevel=0.) if stripe.startswith('I'): beamLine.filter2 = roe.Plate(beamLine, 'Filter2', (0, 23720, height), pitch=math.pi / 2, limPhysX=(-9., 9.), limPhysY=(-4., 4.), surface='diamond 0.4 mm', material=filterDiamond, t=0.4, alarmLevel=0.) beamLine.vcm = roe.SimpleVCM(beamLine, 'VCM', [0, 25290, height], surface=('Si', ), material=(materialVCM, ), limPhysX=(-15., 15.), limPhysY=(-680., 680.), limOptX=(-6, 6), limOptY=(-670., 670.), R=5.0e6, pitch=2e-3, alarmLevel=0.) beamLine.fsmVCM = rsc.Screen(beamLine, 'FSM-VCM', (0, 26300, height)) beamLine.dcm = roe.DCM(beamLine, 'DCM', [0, 27060, height], surface=('Si111', ), material=(si_1, ), material2=(si_2, ), alpha=np.radians(0), limPhysX=(-10, 10), limPhysY=(-30, 30), cryst2perpTransl=20, cryst2longTransl=65, limPhysX2=(-10, 10), limPhysY2=(-90, 90), alarmLevel=0.) beamLine.BSBlock = ra.RectangularAperture(beamLine, 'BSBlock', (0, 29100, height), ('bottom', ), (22, ), alarmLevel=0.) beamLine.slitAfterDCM = ra.RectangularAperture( beamLine, 'SlitAfterDCM', (0, 29200, height), ('left', 'right', 'bottom', 'top'), [-7, 7, -2, 2], alarmLevel=0.5) beamLine.fsmDCM = rsc.Screen(beamLine, 'FSM-DCM', (0, 29400, height)) beamLine.vfm = roe.SimpleVFM(beamLine, 'VFM', [0, 30575, height], surface=('SiO2', ), material=(materialVFM, ), limPhysX=(-20., 20.), limPhysY=(-700., 700.), limOptX=(-10, 10), limOptY=(-700, 700), positionRoll=math.pi, R=5.0e6, r=40.77, alarmLevel=0.2) beamLine.slitAfterVFM = ra.RectangularAperture( beamLine, 'SlitAfterVFM', (0, 31720, height), ('left', 'right', 'bottom', 'top'), [-7, 7, -2, 2], alarmLevel=0.5) beamLine.fsmVFM = rsc.Screen(beamLine, 'FSM-VFM', (0, 32000, height)) beamLine.ohPS = ra.RectangularAperture(beamLine, 'OH-PS', (0, 32070, height), ('left', 'right', 'bottom', 'top'), (-20, 20, 25, 55), alarmLevel=0.2) beamLine.slitEH = ra.RectangularAperture( beamLine, 'slitEH', (0, 43000, height), ('left', 'right', 'bottom', 'top'), [-20, 20, -7, 7], alarmLevel=0.5) beamLine.fsmSample = rsc.Screen(beamLine, 'FSM-Sample', (0, 45863, height)) return beamLine
# -*- coding: utf-8 -*- __author__ = "Konstantin Klementiev, Roman Chernikov" __date__ = "08 Jul 2016" import numpy as np from scipy.interpolate import UnivariateSpline import matplotlib.pyplot as plt # path to xrt: import os, sys sys.path.append(os.path.join('..', '..', '..')) # analysis:ignore import xrt.backends.raycing.materials as rm crystal, E = rm.CrystalSi(hkl=(1, 1, 1)), 8040 dtheta = np.linspace(-30, 90, 601) dt = dtheta[1] - dtheta[0] theta = crystal.get_Bragg_angle(E) + dtheta * 1e-6 refl = np.abs(crystal.get_amplitude(E, np.sin(theta))[0])**2 # s-polarization spline = UnivariateSpline(dtheta, refl - refl.max() / 2, s=0) r11, r12 = spline.roots() # find the roots rc = np.convolve(refl, refl, 'same') / (refl.sum() * dt) * dt spline = UnivariateSpline(dtheta, rc - rc.max() / 2, s=0) r21, r22 = spline.roots() # find the roots plt.plot(dtheta, refl, 'r', label=u'one crystal\nFWHM = {0:.1f} µrad'.format( crystal.get_Darwin_width(E) * 1e6)) plt.axvspan(r11, r12, facecolor='r', alpha=0.05) plt.plot(dtheta, rc,
if geom.startswith('Bragg'): n = (0, 0, 1) # outward surface normal else: n = (0, -1, 0) # outward surface normal hn = (0, np.sin(alpha), np.cos(alpha)) # outward Bragg normal gamma0 = sum(i*j for i, j in zip(n, s0)) gammah = sum(i*j for i, j in zip(n, sh)) hns0 = sum(i*j for i, j in zip(hn, s0)) return gamma0, gammah, hns0 #crystalType = 'Si' crystalType = 'Ge' hkl = (1, 1, 1) if crystalType == 'Si': crystal = rm.CrystalSi(hkl=hkl) elif crystalType == 'Ge': crystal = rm.CrystalDiamond(hkl=hkl, d=5.657, elements='Ge') E = 8900 dtheta = np.linspace(-20, 80, 501) #dtheta = np.linspace(-100, 300, 501) theta = crystal.get_Bragg_angle(E) + dtheta*1e-6 asymmDeg = 0. # Degrees g0, gh, hs0 = calc_vectors(theta, asymmDeg, 'Bragg') curS, curP = crystal.get_amplitude(E, g0, gh, hs0) #curS, curP = crystal.get_amplitude(E, np.sin(theta)) #print(crystal.get_a()) print(crystal.get_F_chi(E, 0.5/crystal.d)) print(u'Darwin width at E={0:.0f} eV is {1:.5f} µrad for s-polarization'.
import numpy as np sys.path.append(r"C:\Ray-tracing") import xrt.backends.raycing.sources as rsources import xrt.backends.raycing.screens as rscreens import xrt.backends.raycing.materials as rmats import xrt.backends.raycing.oes as roes import xrt.backends.raycing.run as rrun import xrt.backends.raycing as raycing import xrt.plotter as xrtplot import xrt.runner as xrtrun Ec = 2840 nrays = 1e6 crystalSi = rmats.CrystalSi(geom="Bragg") #crystalSi = rmats.CrystalSi(geom="Laue", t=0.1) alpha = -0.35 if crystalSi.geom.startswith("Laue"): alpha += np.pi / 2 def build_beamline(): beamLine = raycing.BeamLine() beamLine.source = rsources.GeometricSource( beamLine, center=[0, 0, 0], dx=2, dz=1, dxprime=25e-06,
# -*- coding: utf-8 -*- __author__ = "Konstantin Klementiev, Roman Chernikov" __date__ = "08 Jul 2016" import numpy as np from scipy.interpolate import UnivariateSpline import matplotlib.pyplot as plt # path to xrt: import os, sys sys.path.append(os.path.join('..', '..', '..')) # analysis:ignore import xrt.backends.raycing.materials as rm crystal, E = rm.CrystalSi(hkl=(1, 1, 1)), 9000 dtheta = np.linspace(-30, 85, 601) dt = dtheta[1] - dtheta[0] theta = crystal.get_Bragg_angle(E) + dtheta * 1e-6 refl = np.abs(crystal.get_amplitude(E, np.sin(theta))[0])**2 # s-polarization rc = np.convolve(refl, refl, 'same') / (refl.sum() * dt) * dt spline = UnivariateSpline(dtheta, rc - rc.max() / 2, s=0) r1, r2 = spline.roots() # find the roots plt.plot(dtheta, refl, 'r', label=u'one crystal\nFWHM = {0:.1f} µrad'.format( crystal.get_Darwin_width(E) * 1e6)) plt.plot(dtheta, rc, 'b', label=u'two crystal\n(convolution)' u'\nFWHM = {0:.1f} µrad'.format(r2 - r1)) plt.gca().set_xlabel(u'$\\theta - \\theta_{B}$ (µrad)')
'dz': FWHM_z / 1000 / 2.634, # mm 'dxprime': 0.03 / 1e6, # rad 'dzprime': 0.03 / 1e6, # rad 'distE': 'flat', # lines, normal, flat 'energies': [E0 - dE, E0 + dE], 'polarization': 'h' # 'polarization': 'v' } angle = 0 Si_kwargs = { 'hkl': [3, 3, 3], # 'tK': 300 # [K] 'tK': 120 # [K] } Si_crystal = rm.CrystalSi(**Si_kwargs) Si_theta = Si_crystal.get_Bragg_angle(E0) n = np.array([0, np.cos(angle), np.sin(angle)]) center = [0, 0, 0] pitch = Si_theta crystal0_kwargs = { 'name': 'crystal0', 'center': center, 'pitch': 'auto', 'positionRoll': 0, 'material': Si_crystal, 'alpha': 0 } angle = angle + (2 * Si_theta - 2 * Si_crystal.get_dtheta(E0, 0))
#Materials and crystal planes import sys # sys.path.append(r'C:\Users\espov\Documents\Python\xrt') sys.path.append('/mnt/c/Users/espov/Documents/Python/xrt') import xrt.backends.raycing.materials as rmats matRh = rmats.Material(elements=r"Rh", kind=r"mirror", rho=12.41, table=r"Chantler", name=None) Si111_300K = rmats.CrystalSi(tK=300.0, name=None) Si111_125K = rmats.CrystalSi(tK=125.0, name=None) Si555_300K = rmats.CrystalSi(tK=300.0, hkl=[5, 5, 5], name=None) Quartz102_300K = rmats.CrystalFromCell( name=r"alphaQuartz", hkl=[1, 0, 2], a=4.91304, c=5.40463, gamma=120, atoms=[14, 14, 14, 8, 8, 8, 8, 8, 8], atomsXYZ=[[0.4697, 0.0, 0.0], [-0.4697, -0.4697, 0.3333333333333333], [0.0, 0.4697, 0.6666666666666666], [0.4125, 0.2662, 0.1188], [-0.1463, -0.4125, 0.4521], [-0.2662, 0.1463, -0.2145], [0.1463, -0.2662, -0.1188], [-0.4125, -0.1463, 0.2145], [0.2662, 0.4125, 0.5479]],
from __future__ import absolute_import # needed for Py2 __author__ = "Konstantin Klementiev" __date__ = "22 Jul 2021" # !!! SEE CODERULES.TXT !!! # path to xrt: import sys sys.path.append(r'c:\Ray-tracing') # analysis:ignore import xrt.backends.raycing.materials as rm crystalSi111 = rm.CrystalSi(hkl=(1, 1, 1)) crystalSi311 = rm.CrystalSi(hkl=(3, 1, 1)) crystals = dict(Si111=crystalSi111, Si311=crystalSi311) refl, rc = dict(), dict() for cryst in crystals: refl[cryst] = None rc[cryst] = None
prefix = '02_bentLaueDCM' energies = [9e3, 1.6e4, 2.5e4, 3.6e4] radii = [1e3, 5e3, 25e3, 125e3, np.inf] dEOverE = [1.6e-1, 3e-2, 8e-3, 2.4e-3, 8e-4] # @ radii ddEOverE = [1, 1.25, 2.5, 3.] # @ energies dthetaMax = [8., 2., 0.4, 0.4, 0.4] # mrad, @ radii ddthetaMax = [1., 0.5, 0.25, 0.125] # @ energies #polarization = ['hor', 'vert', '+45', '-45', 'right', 'left', None] polarization = 'hor', nThetas = 51 #crystalDiamond = rm.CrystalDiamond((1,1,1), 2.0592872, elements='C', si111 = rm.CrystalSi(hkl=(1, 1, 1), geom='Laue', t=0.2) fixedExit = 51. pLaueDCM = 1000. qLaueDCM = 100. def build_beamline(nrays=1e5): beamLine = raycing.BeamLine(height=0) rs.GeometricSource(beamLine, 'GeometricSource', nrays=nrays, dx=3., dz=3., dxprime=1.6e-4, distzprime=None) beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', (0, pLaueDCM - 100, 0))
# -*- coding: utf-8 -*- """ Created on Thu Jun 19 15:15:38 2014 @author: konkle """ import os, sys sys.path.append(os.path.join('..', '..')) # analysis:ignore import xrt.backends.raycing.materials as rm xtalSi = rm.CrystalSi(hkl=(1, 1, 1), tK=300, rho=2.3296) xtalSiGeneral = rm.CrystalFromCell('silicon', (1, 1, 1), a=5.4311946, atoms=['Si'] * 8, atomsXYZ=[[0.0, 0.0, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0], [.25, .25, .25], [.25, .75, .75], [.75, .25, .75], [.75, .75, .25]]) E0 = 4000. xtal = xtalSi print(xtal.get_structure_factor(E0, 0.5 / xtal.d)) xtal = xtalSiGeneral print(xtal.get_structure_factor(E0, 0.5 / xtal.d))
def mono_kwargs(E0, dE, hkl, miscut, crystal_pitch_corr=[0, 0, 0, 0], withLens=True, screens=None): FWHM_x = 1000 FWHM_z = 300 screens_kwargs = [] # SOURCE d_source = 200 source_kwargs = { 'name': 'source', 'center': [0, -d_source, 0], 'nrays': 1e5, 'dx': FWHM_x / 1000 / 2.634, # mm 'dz': FWHM_z / 1000 / 2.634, # mm 'dxprime': 0.03 / 1e6, # rad 'dzprime': 0.03 / 1e6, # rad 'distE': 'flat', # lines, normal, flat 'energies': [E0 - dE, E0 + dE], # 'polarization': 'h' 'polarization': 'v' } angle = 0 # CRYSTAL 0 Si_kwargs = { 'hkl': hkl, # 'tK': 300 # [K] 'tK': 120 # [K] } Si_crystal = rm.CrystalSi(**Si_kwargs) Si_tth = 2 * Si_crystal.get_Bragg_angle(E0) n = np.array([0, np.cos(angle), np.sin(angle)]) center = [0, 0, 0] crystal0_kwargs = { 'name': 'crystal0', 'center': center, 'pitch': 'auto', 'positionRoll': 0, 'material': Si_crystal, 'alpha': 0 } if (screens is None) or ('crystal0' in screens): screens_kwargs.append({ 'name': 's_crystal0', 'center': center, 'z': get_perpendicular_vector(n) }) angle = angle + (Si_tth - 2 * Si_crystal.get_dtheta(E0, 0) + crystal_pitch_corr[0]) # CRYSTAL 1 center = crystal0_kwargs['center'] + \ np.array([0, np.cos(angle), np.sin(angle)])*200 crystal1_kwargs = { 'name': 'crystal1', 'center': center, 'pitch': 'auto', 'positionRoll': np.pi, 'material': Si_crystal, 'alpha': miscut } if (screens is None) or ('crystal1' in screens): screens_kwargs.append({ 'name': 's_crystal1', 'center': center, 'z': get_perpendicular_vector(n) }) angle = angle - (Si_tth - 2 * Si_crystal.get_dtheta(E0, miscut) + crystal_pitch_corr[1]) # CRL 1 mBeryllium = rm.Material('Be', rho=1.848, kind='lens') q = 10000 # mm zmax = 0.2 n = np.array([0, np.cos(angle), np.sin(angle)]) center = crystal1_kwargs['center'] + n * q crl1_kwargs = { 'name': 'crl1', 'center': center, 'material': mBeryllium, 'zmax': zmax, 'nCRL': (q, E0), } if (screens is None) or ('crl1' in screens): screens_kwargs.append({ 'name': 's_crl1', 'center': center, 'z': get_perpendicular_vector(n) }) angle = angle + 0 # SLITS n = np.array([0, np.cos(angle), np.sin(angle)]) center = crl1_kwargs['center'] + n * q slit_kwargs = { 'name': 'slits', 'center': center, 'kind': ['left', 'right', 'bottom', 'top'], # 'opening': [-5, 5, -.0035, .0035] 'opening': [-5, 5, -5, 5] } if (screens is None) or ('slits' in screens): screens_kwargs.append({ 'name': 's_slits', 'center': center, 'z': get_perpendicular_vector(n) }) angle = angle + 0 # CRL 2 n = np.array([0, np.cos(angle), np.sin(angle)]) center = slit_kwargs['center'] + n * q crl2_kwargs = { 'name': 'crl2', 'center': center, 'material': mBeryllium, 'zmax': zmax, 'nCRL': (q, E0), } if (screens is None) or ('crl2' in screens): screens_kwargs.append({ 'name': 's_crl2', 'center': center, 'z': get_perpendicular_vector(n) }) angle = angle + 0 # CRYSTAL 2 n = np.array([0, np.cos(angle), np.sin(angle)]) center = crl2_kwargs['center'] + n * (q - 200) crystal2_kwargs = { 'name': 'crystal2', 'center': center, 'pitch': 'auto', 'positionRoll': np.pi, 'material': Si_crystal, 'alpha': 0 } if (screens is None) or ('crystal2' in screens): screens_kwargs.append({ 'name': 's_crystal2', 'center': center, 'z': get_perpendicular_vector(n) }) angle = angle - (Si_tth - 2 * Si_crystal.get_dtheta(E0, 0) + crystal_pitch_corr[2]) # CRYSTAL 3 n = np.array([0, np.cos(angle), np.sin(angle)]) center = crystal2_kwargs['center'] + n * 200 crystal3_kwargs = { 'name': 'crystal3', 'center': center, 'pitch': 'auto', 'positionRoll': 0, 'material': Si_crystal, 'alpha': -miscut } if (screens is None) or ('crystal3' in screens): screens_kwargs.append({ 'name': 's_crystal3', 'center': center, 'z': get_perpendicular_vector(n) }) angle = angle + (Si_tth - 2 * Si_crystal.get_dtheta(E0, -miscut) + crystal_pitch_corr[3]) # DETECTOR n = np.array([0, np.cos(angle), np.sin(angle)]) center = crystal3_kwargs['center'] + n * 300 screens_kwargs.append({ 'name': 'detector', 'center': center, 'z': get_perpendicular_vector(n) }) if withLens is True: oes_kwargs = [source_kwargs, crystal0_kwargs, crystal1_kwargs, crl1_kwargs, \ slit_kwargs, crl2_kwargs, crystal2_kwargs, crystal3_kwargs] else: oes_kwargs = [source_kwargs, crystal0_kwargs, crystal1_kwargs, \ slit_kwargs, crystal2_kwargs, crystal3_kwargs] screens_kwargs.pop(2) screens_kwargs.pop(3) return oes_kwargs, screens_kwargs
def run_tests(): """The body of the module test suit. Uncomment the tests you want.""" #Compare the calculated rocking curves of Si crystals with those calculated by #XCrystal and XInpro (parts of XOP): compare_rocking_curves('111') # compare_rocking_curves('333') # compare_rocking_curves('111', t=0.007) # t is thickness in mm # compare_rocking_curves('333', t=0.007) # compare_rocking_curves('111', t=0.100) # compare_rocking_curves('333', t=0.100) compare_rocking_curves('111', t=0.007, geom='Bragg transmitted') # compare_rocking_curves('333', t=0.007, geom='Bragg transmitted') # compare_rocking_curves('111', t=0.100, geom='Bragg transmitted') # compare_rocking_curves('333', t=0.100, geom='Bragg transmitted') # compare_rocking_curves('111', t=0.007, geom='Laue reflected') # compare_rocking_curves('333', t=0.007, geom='Laue reflected') # compare_rocking_curves('111', t=0.100, geom='Laue reflected') # compare_rocking_curves('333', t=0.100, geom='Laue reflected') # compare_rocking_curves('111', t=0.007, geom='Laue transmitted') # compare_rocking_curves('333', t=0.007, geom='Laue transmitted') # compare_rocking_curves('111', t=0.100, geom='Laue transmitted') # compare_rocking_curves('333', t=0.100, geom='Laue transmitted') # Compare rocking curves for bent Si crystals with those calculated by #XCrystal_Bent (Takagi-Taupin): compare_rocking_curves_bent('111', t=1.0, geom='Laue reflected', Rcurvmm=np.inf, alphas=[30]) # compare_rocking_curves_bent('333', t=1.0, geom='Laue reflected', # Rcurvmm=np.inf, alphas=[30]) # compare_rocking_curves_bent('111', t=1.0, geom='Laue reflected', # Rcurvmm=50*1e3, # alphas=[-60, -45, -30, -15, 0, 15, 30, 45, 60]) # compare_rocking_curves_bent('333', t=1.0, geom='Laue reflected', # Rcurvmm=50*1e3, # alphas=[-60, -45, -30, -15, 0, 15, 30, 45, 60]) #check that Bragg transmitted and Laue transmitted give the same results if the #beam path is equal: beamPath = 0.1 # mm compare_Bragg_Laue('111', beamPath=beamPath) compare_Bragg_Laue('333', beamPath=beamPath) #Compare the calculated reflectivities of Si, Pt, SiO_2 with those by Xf1f2 #(part of XOP): compare_reflectivity() compare_reflectivity_coated() #Compare the calculated reflectivities of W slab with those by Mlayer #(part of XOP): compare_reflectivity_slab() #Compare the calculated reflectivities of W slab with those by Mlayer #(part of XOP): # compare_reflectivity_multilayer() compare_reflectivity_multilayer_interdiffusion() # compare_dTheta() #Compare the calculated absorption coefficient with that by XCrossSec #(part of XOP): compare_absorption_coeff() #Compare the calculated transmittivity with that by XPower #(part of XOP): compare_transmittivity() #Play with Si crystal: crystalSi = rm.CrystalSi(hkl=(1, 1, 1), tK=100.) print(2 * crystalSi.get_a()/math.sqrt(3.)) # 2dSi111 print('Si111 d-spacing = {0:.6f}'.format(crystalSi.d)) print(crystalSi.get_Bragg_offset(8600, 8979)) crystalDiamond = rm.CrystalDiamond((1, 1, 1), 2.0592872, elements='C') E = 9000. print(u'Darwin width at E={0:.0f} eV is {1:.5f} µrad for s-polarization'. format(E, crystalDiamond.get_Darwin_width(E) * 1e6)) print(u'Darwin width at E={0:.0f} eV is {1:.5f} µrad for p-polarization'. format(E, crystalDiamond.get_Darwin_width(E, polarization='p')*1e6)) plt.show() print("finished")