Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename module and update mirrors (gh issue #98). #102

Merged
merged 2 commits into from
Dec 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions s2e/prop/exfel_spb_day1_beamline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Module holding the SPB/SFX beamline (nanofocus, KB mirrors) at European XFEL.

import wpg.optical_elements
from wpg.optical_elements import Use_PP
from opd import defineOPD
import numpy as np
import os


def get_beamline():
""" Setup and return the WPG.Beamline object representing the SPB/SFX nanofocus beamline (KB mirrors).

:return: beamline (type wpg.Beamline)
"""

### Geometry ###
src_to_hom1 = 257.8 # Distance source to HOM 1 [m]
src_to_hom2 = 267.8 # Distance source to HOM 2 [m]
src_to_crl = 887.8 # Distance source to CRL [m]
src_to_exp = 920.42 # Distance source to experiment [m]

#Incidence angle at HOM
theta_om = 3.6e-3 # [rad]

om_mirror_length = 0.8 # [m]
om_clear_ap = om_mirror_length*theta_om


#define the beamline:
beamline = Beamline()
zoom=1

# Define HOM1 = Aperture + Wavefront distortion.
aperture_x_to_y_ratio = 1
hom1_aperture = Aperture(shape='r',ap_or_ob='a',Dx=om_clear_ap,Dy=om_clear_ap/aperture_x_to_y_ratio)

# Append to beamline.
beamline.append( hom1_aperture, Use_PP(semi_analytical_treatment=0, zoom=zoom, sampling=zoom) )

# Free space propagation from hom1 to hom2
hom1_to_hom2_drift = Drift(src_to_hom2 - src_to_hom1)
beamline.append( hom1_to_hom2_drift, Use_PP(semi_analytical_treatment=0))

# Define HOM2.
zoom = 1.0
hom2_aperture = Aperture('r','a', om_clear_ap, om_clear_ap/aperture_x_to_y_ratio)
beamline.append( hom2_aperture, Use_PP(semi_analytical_treatment=0, zoom=zoom, sampling=zoom))

#drift to CRL aperture
hom2_to_crl_drift = Drift( src_to_crl - src_to_hom2 )
beamline.append( hom2_to_crl_drift, Use_PP(semi_analytical_treatment=1))

# Circular Aperture before CRL.
crl_front_aperture_diameter = 2.8e-3
crl_front_aperture = Aperture('c','a', crl_front_aperture_diameter, crl_front_aperture_diameter)

### Define CRL
crl_focussing_plane = 3 # Both horizontal and vertical.
crl_delta = 4.8308e-06 # Refractive index decrement (n = 1- delta - i*beta) @ 8.4 keV
crl_attenuation_length = 6.053e-3 # Attenuation length [m], Henke data.
crl_shape = 1 # Parabolic lenses
crl_aperture = 3.0e-3 # [m]
crl_curvature_radius = 5.8e-3 # [m]
crl_number_of_lenses = 19
crl_wall_thickness = 8.0e-5 # Thickness
crl_center_horizontal_coordinate = 0.0
crl_center_vertical_coordinate = 0.0
crl_initial_photon_energy = 8.48e3 # [eV]
crl_final_photon_energy = 8.52e3 # [eV]

crl = CRL( _foc_plane=crl_focussing_plane,
_delta=crl_delta,
_atten_len=crl_attenuation_length,
_shape=crl_shape,
_apert_h=crl_aperture,
_apert_v=crl_aperture,
_r_min=crl_curvature_radius,
_n=crl_number_of_lenses,
_wall_thick=crl_wall_thickness,
_xc=crl_center_horizontal_coordinate,
_yc=crl_center_vertical_coordinate,
_void_cen_rad=None,
_e_start=crl_initial_photon_energy,
_e_fin=crl_final_photon_energy,
)

zoom = 0.6
beamline.append( crl_front_aperture, Use_PP(semi_analytical_treatment=0, zoom=zoom, sampling=zoom/0.1) )
beamline.append( crl, Use_PP(semi_analytical_treatment=0, zoom=1, sampling=1) )

# Drift to focus aperture
crl_to_exp_drift = Drift( src_to_exp - src_to_crl )
beamline.append( crl_to_exp_drift, Use_PP(semi_analytical_treatment=1, zoom=1, sampling=1) )

return beamline




99 changes: 99 additions & 0 deletions s2e/prop/exfel_spb_kb_beamline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Module holding WPG beamlines at European XFEL.

import wpg.optical_elements
from wpg.optical_elements import Use_PP
from opd import defineOPD
import numpy as np
import os


def get_beamline():
""" Setup and return the WPG.Beamline object representing the SPB/SFX nanofocus beamline (KB mirrors).

:return: beamline (type wpg.Beamline)
"""

# Distances
distance0 = 246.5
distance1 = 683.5
distance = distance0 + distance1

# Focal lengths.
f_hfm = 3.0 # nominal focal length for HFM KB
f_vfm = 1.9 # nominal focal length for VFM KB
distance_hfm_vfm = f_hfm - f_vfm
distance_foc = 1. /(1./f_vfm + 1. / (distance + distance_hfm_vfm))

# Mirror incidence angles
theta_om = 3.5e-3 # offset mirrors incidence angle
theta_kb = 3.5e-3 # KB mirrors incidence angle

# Mirror lengths
om_mirror_length = 0.8; om_clear_ap = om_mirror_length*theta_om
kb_mirror_length = 0.9; kb_clear_ap = kb_mirror_length*theta_kb

# Drifts.
drift0 = wpg.optical_elements.Drift(distance0)
drift1 = wpg.optical_elements.Drift(distance1)
drift_in_kb = wpg.optical_elements.Drift(distance_hfm_vfm)
drift_to_foc = wpg.optical_elements.Drift(distance_foc)

# Mirror apertures.
ap0 = wpg.optical_elements.Aperture('r','a', 120.e-6, 120.e-6)
ap1 = wpg.optical_elements.Aperture('r','a', om_clear_ap, 2*om_clear_ap)
ap_kb = wpg.optical_elements.Aperture('r','a', kb_clear_ap, kb_clear_ap)

# Mirror definitions.
hfm = wpg.optical_elements.Mirror_elliptical(
orient='x',
p=distance,
q=(distance_hfm_vfm+distance_foc),
thetaE=theta_kb,
theta0=theta_kb,
length=0.9
)
vfm = wpg.optical_elements.Mirror_elliptical(
orient='y',
p=(distance+distance_hfm_vfm),
q=distance_foc,
thetaE=theta_kb,
theta0=theta_kb,
length=0.9
)


# Wavefront distortions due to mirror profile
wf_dist_om = wpg.optical_elements.WF_dist(1500, 100, om_clear_ap, 2*om_clear_ap)
defineOPD(wf_dist_om, os.path.join('data_common','mirror2.dat'), 2, '\t', 'x',
theta_kb, scale=2)

wf_dist_hfm = wpg.optical_elements.WF_dist(1500, 100, kb_clear_ap, kb_clear_ap)
defineOPD(wf_dist_hfm, os.path.join(mirror_data_dir,'mirror1.dat'), 2, '\t', 'x',
theta_kb, scale=2, stretching=kb_mirror_length/0.8)

wf_dist_vfm = wpg.optical_elements.WF_dist(1100, 1500, kb_clear_ap, kb_clear_ap)
defineOPD(wf_dist_vfm, os.path.join(mirror_data_dir,'mirror2.dat'), 2, ' ', 'y',
theta_kb, scale=2, stretching=kb_mirror_length/0.8)


# Assemble the beamline with PP parameters.
bl0 = wpg.Beamline()
bl0.append(ap0, Use_PP(semi_analytical_treatment=0,
zoom=14.4,
sampling=1/1.6))
bl0.append(drift0,Use_PP(semi_analytical_treatment=0))
bl0.append(ap1, Use_PP(zoom=0.8))
#bl0.append(ap1, Use_PP(zoom=1.6, sampling=1/1.5))
bl0.append(wf_dist_om, Use_PP())
bl0.append(drift1, Use_PP(semi_analytical_treatment=1))
bl0.append(ap_kb, Use_PP(zoom = 6.4, sampling = 1/16.))
#bl0.append(ap_kb, Use_PP(zoom=5.4, sampling=1/6.4))
bl0.append(hfm, Use_PP())
bl0.append(wf_dist_hfm, Use_PP())
bl0.append(drift_in_kb, Use_PP(semi_analytical_treatment=1))
bl0.append(vfm, Use_PP())
bl0.append(wf_dist_vfm, Use_PP())
bl0.append(drift_to_foc, Use_PP(semi_analytical_treatment=1))

# All done, return.
return bl0
110 changes: 0 additions & 110 deletions s2e/prop/my_s2e_beamline.py

This file was deleted.

1 change: 1 addition & 0 deletions s2e/prop/my_s2e_beamline.py
29 changes: 29 additions & 0 deletions s2e/prop/opd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from wpg.useful_code.srwutils import AuxTransmAddSurfHeightProfileScaled as profile_tool
import numpy as np


def defineOPD(opTrErMirr,
mdatafile,
ncol,
delim,
orient,
theta,
scale=1.,
stretching=1.):
"""
Define optical path difference (OPD) from mirror profile

:param opTrErMirr: The struct with wave front distortions from
mirror susrface errors
:param mdatafile: An ascii file with mirror profile data
:param ncol: Number of columns in the mirror profile file
:param delim: Delimiter between numbers in an row, can be space (' '), tab '\t', etc.
:param orient: Mirror orientation, 'x' (horizontal) or 'y' (vertical)
:param theta: Mirror incidence angle
:param scale: Scaling factor for the mirror profile height errors
:param stretching: Scaling factor for the mirror profile x-axis (a hack, should be removed ASAP)
"""

heightProfData = np.loadtxt(mdatafile).T
heightProfData[0, :] = heightProfData[0, :] * stretching
profile_tool(opTrErMirr, heightProfData, orient, theta, scale)
Loading