Exemplo n.º 1
0
def example_screen(do_plot=True):

    #
    # collimated source
    #
    src = SourceGaussian.initialize_collimated_source(number_of_rays=10000,
                                                      sigmaX=1e-6,
                                                      sigmaZ=1e-6)

    beam = src.get_beam()

    print(beam.info())

    #
    # screen definition
    #

    screen1 = S4ScreenElement(optical_element=S4Screen(),
                              coordinates=ElementCoordinates(p=100.0, q=0.0))

    print(screen1.info())

    beam2, tmp = screen1.trace_beam(beam)

    #
    if do_plot:
        plotxy(beam2, 1, 3, nbins=100, title="SCREEN")
Exemplo n.º 2
0
def example_point_source():

    a = SourceGaussian.initialize_point_source(
        number_of_rays=10000,
        sigmaXprime=3e-6,
        sigmaZprime=1e-6,
        real_space_center=[0.0, 0.0, 0.0],
        direction_space_center=[0.0, 0.0])
    print(a.info())

    x, y, z = a.get_arrays_real_space()
    print("x.shape:", x.shape)
    print("y.shape:", y.shape)
    print("z.shape:", z.shape)

    xp, zp = a.get_arrays_direction_space()
    print("xp.shape:", xp.shape)
    print("zp.shape:", zp.shape)

    VP = a.get_volume_divergences()
    print("VP", VP.shape, VP.size)

    Vx = a.get_volume_real_space()
    print("Vx: ", Vx.shape)

    V = a.get_volume()
    print("V: ", V.shape)

    beam = a.get_beam()

    plotxy(beam, 4, 6, title="point source")
Exemplo n.º 3
0
def example_double_gaussian():
    #
    #
    a = SourceGaussian.initialize_from_keywords(
        number_of_rays=10000,
        sigmaX=2.0e-6,
        sigmaY=1.0e-3,
        sigmaZ=1.0e-6,
        sigmaXprime=3e-6,
        sigmaZprime=3e-6,
        real_space_center=[0.0, 0.0, 0.0],
        direction_space_center=[0.0, 0.0])

    print(a.info())

    beam = a.get_beam()
    plot_scatter(beam.get_column(2),
                 beam.get_column(1),
                 title="double Gaussian",
                 xtitle="col 2",
                 ytitle="col 1")
    plot_scatter(beam.get_column(1),
                 beam.get_column(3),
                 title="double Gaussian",
                 xtitle="col 1",
                 ytitle="col 3")
    plot_scatter(beam.get_column(4),
                 beam.get_column(6),
                 title="double Gaussian",
                 xtitle="col 4",
                 ytitle="col 6")
    print(beam.info())

    print(isinstance(a, SourceGaussian))
Exemplo n.º 4
0
def example_beam_stopper(do_plot=True):

    src = SourceGaussian.initialize_collimated_source(number_of_rays=10000,
                                                      sigmaX=1e-6,
                                                      sigmaZ=1e-6)
    beam = src.get_beam()

    #
    # slit definition
    #
    boundary_shape = Ellipse(-1e-6, 1e-6, -0.5e-6, 0.5e-6)
    coordinates = ElementCoordinates(p=100.0, q=0.0)
    optical_element = S4Screen(name="slit1",
                               boundary_shape=boundary_shape,
                               i_abs=False,
                               i_stop=True,
                               thick=0.0,
                               file_abs="")

    screen1 = S4ScreenElement(optical_element=optical_element,
                              coordinates=coordinates)

    print(screen1.info())

    #
    # trace
    #

    beam2, tmp = screen1.trace_beam(beam)

    #
    if do_plot:
        plotxy(beam2, 1, 3, nbins=100, title="BEAM STOPPER", nolost=True)
Exemplo n.º 5
0
def example_branch_3(surface_shape_file, do_plot=True):
    #
    # source
    #
    # beam0 = Beam.initialize_as_pencil(N=500)
    source = SourceGaussian.initialize_from_keywords(
        number_of_rays=100000,
        sigmaX=0.0,
        sigmaY=0.0,
        sigmaZ=0.0,
        sigmaXprime=1e-4,
        sigmaZprime=1e-4,
    )
    beam0 = Beam()
    beam0.genSource(source)
    print(beam0.info())

    if do_plot:
        plotxy(beam0, 4, 6, title="Image 0", nbins=201)

    #
    # syned definitopns
    #

    # boundaries
    rlen1 = 0.6
    rlen2 = 0.6
    rwidx1 = 0.05
    rwidx2 = 0.05

    #
    # shadow definitions
    #
    mirror1 = S4SurfaceDataMirrorElement(optical_element=S4SurfaceDataMirror(
        name="M1",
        surface_data_file=surface_shape_file,
        boundary_shape=Rectangle(x_left=-rwidx2,
                                 x_right=rwidx1,
                                 y_bottom=-rlen2,
                                 y_top=rlen1)),
                                         coordinates=ElementCoordinates(
                                             p=100.0,
                                             q=1000.0,
                                             angle_radial=numpy.radians(88.8)))
    print(mirror1.info())

    #
    # run
    #
    beam1, mirr1 = mirror1.trace_beam(beam0)
    print(mirr1.info())

    #
    # check
    #

    if do_plot:
        plotxy(beam1, 1, 3, title="Image 1", nbins=101, nolost=1)
        plotxy(mirr1, 2, 1, title="Footprint 1", nbins=101, nolost=1)
Exemplo n.º 6
0
    def get_beam_in_gaussian_approximation(self, NRAYS=1000, SEED=12345):
        emin, emax, npoints = self.get_magnetic_structure().get_energy_box()

        if self.get_magnetic_structure().get_flag_emittance():
            sigma_x, sigdi_x, sigma_z, sigdi_z = self.get_electron_beam(
            ).get_sigmas_all()
            Sx, Sz, Spx, Spz = self.get_undulator_photon_beam_sizes_by_convolution(
                sigma_x=sigma_x,
                sigma_z=sigma_z,
                sigdi_x=sigdi_x,
                sigdi_z=sigdi_z,
                undulator_E0=0.5 * (emin + emax),
                undulator_length=self.get_magnetic_structure().length(),
            )
            a = SourceGaussian.initialize_from_keywords(
                number_of_rays=NRAYS,
                sigmaX=Sx,
                sigmaY=0,
                sigmaZ=Sz,
                sigmaXprime=Spx,
                sigmaZprime=Spz,
                real_space_center=[0.0, 0.0, 0.0],
                direction_space_center=[0.0, 0.0])
        else:
            s, sp = self.get_undulator_photon_beam_sizes(
                undulator_E0=0.5 * (emin + emax),
                undulator_length=self.get_magnetic_structure().length(),
            )
            a = SourceGaussian.initialize_from_keywords(
                number_of_rays=NRAYS,
                sigmaX=s,
                sigmaY=0,
                sigmaZ=s,
                sigmaXprime=sp,
                sigmaZprime=sp,
                real_space_center=[0.0, 0.0, 0.0],
                direction_space_center=[0.0, 0.0])

        print(a.info())
        beam = a.get_beam()
        if emax != emin:
            e = numpy.random.random(NRAYS) * (emax - emin) + emin
            beam.set_photon_energy_eV(e)

        return beam
Exemplo n.º 7
0
def example_branch_2(do_plot=True):
    source = SourceGaussian.initialize_from_keywords(
        number_of_rays=100000,
        sigmaX=0.0,
        sigmaY=0.0,
        sigmaZ=0.0,
        sigmaXprime=1e-6,
        sigmaZprime=1e-6,
    )
    beam0 = Beam()
    beam0.genSource(source)
    print(beam0.info())

    if do_plot:
        plotxy(beam0, 4, 6, title="Image 0", nbins=201)

    #
    # syned definitopns
    #

    # boundaries
    boundary_shape = None  #Rectangle(x_left=-rwidx2,x_right=rwidx1,y_bottom=-rlen2,y_top=rlen1)

    #
    # shadow definitions
    #
    mirror1 = S4ToroidalMirrorElement(optical_element=S4ToroidalMirror(
        name="M1",
        surface_calculation=SurfaceCalculation.EXTERNAL,
        min_radius=0.157068,
        maj_radius=358.124803 - 0.157068,
        boundary_shape=boundary_shape),
                                      coordinates=ElementCoordinates(
                                          p=10.0,
                                          q=6.0,
                                          angle_radial=numpy.radians(88.8)))

    print(mirror1.info())

    #
    # run
    #
    beam1, mirr1 = mirror1.trace_beam(beam0)
    print(mirr1.info())

    #
    # check
    #

    if do_plot:
        plotxy(beam1, 1, 3, title="Image 1", nbins=101, nolost=1)
        plotxy(mirr1, 2, 1, title="Footprint 1", nbins=101, nolost=1)
Exemplo n.º 8
0
def lens_with_divergent_beam(do_plot=True):



    src = SourceGaussian.initialize_from_keywords(number_of_rays=100000,
                                                  sigmaX=     20e-6/2.35,sigmaZ=     10e-6/2.35,
                                                  sigmaXprime=50e-6/2.35,sigmaZprime=10e-6/2.35)

    beam = src.get_beam()

    SX, SZ = (1e6*beam.get_standard_deviation(1),1e6*beam.get_standard_deviation(3))

    if do_plot:
        plotxy(beam,4,6,nbins=100,title="SOURCE DIVERGENCES")

    beam_tmp = beam.duplicate()
    beam_tmp.retrace(100.0)
    if do_plot:
        plotxy(beam_tmp,1,3,nbins=100,title="SOURCE AFTER 10m")


    #
    # lens definition
    #

    p = 10.0
    q = 10.0
    F = 1.0 / (1/p + 1/q)

    lens1e = S4IdealLensElement(optical_element=S4IdealLens(name="Undefined", focal_x=F, focal_y=F),
                                coordinates=ElementCoordinates(p=p, q=q))

    print(lens1e.info())
    beam2, tmp = lens1e.trace_beam(beam)


    X = beam2.get_column(1)
    Y = beam2.get_column(3)
    print("X: ",X.min(),X.max(),X.std())
    print("Y: ",Y.min(),Y.max(),Y.std())


    if do_plot:
        plotxy(beam2,1,3,nbins=100,title="FOCAL PLANE",xrange=[-5e-5,5e-5],yrange=[-5e-5,5e-5])

    FX, FZ = (1e6*beam2.get_standard_deviation(1),1e6*beam2.get_standard_deviation(3))
    print("Source dimensions (rms): %f %f um"%(SX,SZ))
    print("Focal dimensions (rms): %f %f um"%(FX,FZ))
    print("Demagnification: H:%g V:%g (theoretical: %g) "%(SX/FX,SZ/FZ,p/q))
Exemplo n.º 9
0
def lens_with_collimated_beam(do_plot=True):

    #
    # collimated source
    #
    src = SourceGaussian.initialize_collimated_source(number_of_rays=10000,sigmaX=1e-6,sigmaZ=1e-6)




    beam = src.get_beam()

    print(beam.info())
    SX, SZ = (1e6*beam.get_standard_deviation(1),1e6*beam.get_standard_deviation(3))

    if do_plot:
        plotxy(beam,1,3,nbins=100,title="SOURCE")
        # histo1(beam, 1, nbins=100)

    #
    # lens definition
    #



    lens1e = S4IdealLensElement(optical_element=S4IdealLens(name="Undefined", focal_x=10.0, focal_y=10.0),
                                coordinates=ElementCoordinates(p=100.0, q=10.0))


    print(lens1e.info())

    #
    # trace
    #

    beam2, tmp = lens1e.trace_beam(beam)

    #
    if do_plot:
        plotxy(beam2,1,3,nbins=100,title="FOCAL PLANE")

    FX, FZ = (1e6*beam2.get_standard_deviation(1),1e6*beam2.get_standard_deviation(3))
    print("Source dimensions: %f %f um"%(SX,SZ))
    print("Focal dimensions: %f %f um"%(FX,FZ))
    print("Demagnification: %g %g"%(SX/FX,SX/FZ))
Exemplo n.º 10
0
def example_filter(do_plot=True):

    src = SourceGaussian.initialize_collimated_source(number_of_rays=10000,
                                                      sigmaX=1e-6,
                                                      sigmaZ=1e-6)
    beam = src.get_beam()

    #
    # slit definition
    #

    from shadow4.physical_models.prerefl.prerefl import PreRefl
    PreRefl.prerefl(interactive=False,
                    SYMBOL="Be",
                    DENSITY=1.848,
                    FILE="Be.dat",
                    E_MIN=100.0,
                    E_MAX=20000.0,
                    E_STEP=100.0)

    optical_element = S4Screen(name="filter1",
                               boundary_shape=None,
                               i_abs=True,
                               i_stop=False,
                               thick=10e-6,
                               file_abs="Be.dat")
    coordinates = ElementCoordinates(p=100.0, q=0.0)
    filter1 = S4ScreenElement(optical_element=optical_element,
                              coordinates=coordinates)

    print(filter1.info())

    #
    # trace
    #

    beam2, tmp = filter1.trace_beam(beam)

    #
    if do_plot:
        plotxy(beam2, 1, 3, nbins=100, title="FILTER", nolost=True)

    print("Intensity: ", beam2.intensity())
Exemplo n.º 11
0
def example_collimated_source():
    #
    a = SourceGaussian.initialize_collimated_source(
        number_of_rays=10000,
        sigmaX=1.0,
        sigmaY=0.0,
        sigmaZ=1.0,
        real_space_center=[0.0, 0.0, 0.0],
        direction_space_center=[0.0, 0.0])

    print(a.info())
    beam = a.get_beam()

    plotxy(beam, 1, 3, title="collimated source")

    plot_scatter(beam.get_column(1),
                 beam.get_column(3),
                 xtitle="col 1",
                 ytitle="col 3",
                 title="collimated source")
    print(beam.info())
Exemplo n.º 12
0
def example_holed_filter(do_plot=True):

    src = SourceGaussian.initialize_collimated_source(number_of_rays=10000,
                                                      sigmaX=1e-6,
                                                      sigmaZ=1e-6)
    beam = src.get_beam()

    #
    # slit definition
    #
    boundary_shape = Rectangle(x_left=-0.5e-6,
                               x_right=0.5e-6,
                               y_bottom=-0.5e-6,
                               y_top=0.5e-6)

    optical_element = S4Screen(name="filter1",
                               boundary_shape=boundary_shape,
                               i_abs=True,
                               i_stop=True,
                               thick=10e-6,
                               file_abs="Be.dat")

    coordinates = ElementCoordinates(p=100.0, q=0.0)
    filter1 = S4ScreenElement(optical_element=optical_element,
                              coordinates=coordinates)

    print(filter1.info())

    #
    # trace
    #

    beam2, tmp = filter1.trace_beam(beam)

    #
    if do_plot:
        plotxy(beam2, 1, 3, nbins=100, title="HOLED FILTER", nolost=True)
Exemplo n.º 13
0
def example_branch_5(surface_type, do_plot=True):
    #
    # source
    #
    source = SourceGaussian.initialize_from_keywords(
        number_of_rays=100000,
        sigmaX=0.0,
        sigmaY=0.0,
        sigmaZ=0.0,
        sigmaXprime=1e-6,
        sigmaZprime=1e-6,
    )
    beam0 = Beam()
    beam0.genSource(source)
    # print(beam0.info())

    #
    # syned definitopns
    #
    # boundaries
    boundary_shape = None

    coordinates_syned = ElementCoordinates(p=10.0,
                                           q=10.0,
                                           angle_radial=numpy.radians(88.8))

    # surface shape

    if surface_type == "plane":
        mirror1 = S4PlaneMirrorElement(optical_element=S4PlaneMirror(
            name="M1", boundary_shape=boundary_shape),
                                       coordinates=coordinates_syned)
    elif surface_type == "sphere":
        mirror1 = S4SphereMirrorElement(optical_element=S4SphereMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=False,
            surface_calculation=SurfaceCalculation.INTERNAL,
            p_focus=10.0,
            q_focus=10.0,
            grazing_angle=numpy.radians(90.0 - 88.8)),
                                        coordinates=coordinates_syned)
    elif surface_type == "spherical_cylinder_tangential":
        mirror1 = S4SphereMirrorElement(optical_element=S4SphereMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=True,
            cylinder_direction=Direction.TANGENTIAL,
            surface_calculation=SurfaceCalculation.INTERNAL,
            p_focus=10.0,
            q_focus=10.0,
            grazing_angle=numpy.radians(90.0 - 88.8)),
                                        coordinates=coordinates_syned)
    elif surface_type == "spherical_cylinder_sagittal":
        mirror1 = S4SphereMirrorElement(optical_element=S4SphereMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=True,
            cylinder_direction=Direction.SAGITTAL,
            surface_calculation=SurfaceCalculation.INTERNAL,
            p_focus=10.0,
            q_focus=10.0,
            grazing_angle=numpy.radians(90.0 - 88.8)),
                                        coordinates=coordinates_syned)
    elif surface_type == "ellipsoid":
        mirror1 = S4EllipsoidMirrorElement(optical_element=S4EllipsoidMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=False,
            surface_calculation=SurfaceCalculation.INTERNAL,
            p_focus=20.0,
            q_focus=10.0,
            grazing_angle=0.003),
                                           coordinates=coordinates_syned)
    elif surface_type == "elliptical_cylinder":
        mirror1 = S4EllipsoidMirrorElement(optical_element=S4EllipsoidMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=True,
            cylinder_direction=Direction.TANGENTIAL,
            surface_calculation=SurfaceCalculation.INTERNAL,
            p_focus=20.0,
            q_focus=10.0,
            grazing_angle=0.003),
                                           coordinates=coordinates_syned)
    elif surface_type == "hyperboloid":
        mirror1 = S4HyperboloidMirrorElement(
            optical_element=S4HyperboloidMirror(
                name="M1",
                boundary_shape=boundary_shape,
                is_cylinder=False,
                surface_calculation=SurfaceCalculation.INTERNAL,
                p_focus=20.0,
                q_focus=10.0,
                grazing_angle=0.003),
            coordinates=coordinates_syned)
    elif surface_type == "hyperbolic_cylinder":
        mirror1 = S4HyperboloidMirrorElement(
            optical_element=S4HyperboloidMirror(
                name="M1",
                boundary_shape=boundary_shape,
                is_cylinder=True,
                cylinder_direction=Direction.TANGENTIAL,
                surface_calculation=SurfaceCalculation.INTERNAL,
                p_focus=20.0,
                q_focus=10.0,
                grazing_angle=0.003),
            coordinates=coordinates_syned)
    elif surface_type == "paraboloid":
        mirror1 = S4ParaboloidMirrorElement(optical_element=S4ParaboloidMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=False,
            surface_calculation=SurfaceCalculation.INTERNAL,
            at_infinity=Side.SOURCE,
            p_focus=20.0,
            q_focus=10.0,
            grazing_angle=0.003),
                                            coordinates=coordinates_syned)
    elif surface_type == "parabolic_cylinder":
        mirror1 = S4ParaboloidMirrorElement(optical_element=S4ParaboloidMirror(
            name="M1",
            boundary_shape=boundary_shape,
            is_cylinder=True,
            cylinder_direction=Direction.TANGENTIAL,
            surface_calculation=SurfaceCalculation.INTERNAL,
            at_infinity=Side.SOURCE,
            p_focus=20.0,
            q_focus=10.0,
            grazing_angle=0.003),
                                            coordinates=coordinates_syned)
    elif surface_type == "conic":
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            boundary_shape=boundary_shape,
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ]),
                                       coordinates=coordinates_syned)
    else:
        raise Exception("undefined surface shape")

    #
    # run
    #
    print(mirror1.info())
    beam1, mirr1 = mirror1.trace_beam(beam0)

    #
    # check
    #

    if do_plot:
        plotxy(beam1, 1, 3, nbins=101, nolost=1, title=surface_type)
Exemplo n.º 14
0
def example_branch_1(do_plot=True):
    #
    # source
    #
    source = SourceGaussian.initialize_from_keywords(
        number_of_rays=100000,
        sigmaX=0.0,
        sigmaY=0.0,
        sigmaZ=0.0,
        sigmaXprime=1e-6,
        sigmaZprime=1e-6,
    )
    beam0 = Beam()
    beam0.genSource(source)
    print(beam0.info())

    if do_plot:
        plotxy(beam0, 4, 6, title="Image 0", nbins=201)

    #
    # syned definitopns
    #

    # surface shape

    # boundaries
    # boundary_shape = None
    rlen1 = 5e-05
    rlen2 = 5e-05
    rwidx1 = 2e-05
    rwidx2 = 2e-05
    boundary_shape = Rectangle(x_left=-rwidx2,
                               x_right=rwidx1,
                               y_bottom=-rlen2,
                               y_top=rlen1)
    # boundary_shape = Rectangle(x_left=-1e-05, x_right=2e-05, y_bottom=-5e-04, y_top=7e-04)
    # boundary_shape = Ellipse(a_axis_min=-rwidx2/2, a_axis_max=rwidx2/2, b_axis_min=-rlen2/2, b_axis_max=rlen2/2)
    # boundary_shape = Ellipse(a_axis_min=-0e-05, a_axis_max=1e-05, b_axis_min=-1.5e-05, b_axis_max=2.5e-05)
    # boundary_shape = Ellipse(a_axis_min=0, a_axis_max=1e-05, b_axis_min=-0.0005, b_axis_max=0)

    # rlen1 = -2.5e-05
    # rlen2 = 5e-05
    # rwidx1 = 1e-05
    # rwidx2 = 2e-05
    #
    # boundary_shape = TwoEllipses(
    #     a1_axis_min=-rwidx1 / 2, a1_axis_max=rwidx1 / 2, b1_axis_min=-rlen1 / 2, b1_axis_max=rlen1 / 2,
    #     a2_axis_min=-rwidx2 / 2, a2_axis_max=rwidx2 / 2, b2_axis_min=-rlen2 / 2, b2_axis_max=rlen2 / 2)

    coordinates_syned = ElementCoordinates(p=10.0,
                                           q=6.0,
                                           angle_radial=numpy.radians(88.8))

    #
    # shadow definitions
    #
    mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
        name="M1",
        conic_coefficients=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0],
        boundary_shape=boundary_shape),
                                   coordinates=coordinates_syned)

    print(mirror1.info())

    #
    # run
    #
    beam1, mirr1 = mirror1.trace_beam(beam_in=beam0)
    print(mirr1.info())

    #
    # check
    #

    if do_plot:
        plotxy(beam1, 1, 3, title="Image 1", nbins=101, nolost=1)
        plotxy(mirr1, 2, 1, title="Footprint 1", nbins=101, nolost=1)

    #
    # M2
    #

    mirror2 = S4ConicMirrorElement(optical_element=S4ConicMirror(
        conic_coefficients=[0, 0, 0, 0, 0, 0, 0, 0, -1, 0],
        boundary_shape=Rectangle(-100e-6, 100e-6, -150e-6, 150e-6)),
                                   coordinates=ElementCoordinates(
                                       p=10.0,
                                       q=100.0,
                                       angle_radial=(0.5 * numpy.pi - 0.003)))

    print(mirror2.info())
    #
    #
    if do_plot:
        beam2, mirr2 = mirror2.trace_beam(beam1)
        plotxy(beam2, 1, 3, title="Image 2", nbins=101, nolost=1)
        plotxy(mirr2, 2, 1, title="Footprint 2", nbins=101, nolost=1)
Exemplo n.º 15
0
def example_branch_4(do_plot=True, f_refl=0):

    #
    # source
    #
    # beam0 = Beam.initialize_as_pencil(N=500)
    source = SourceGaussian.initialize_from_keywords(
        number_of_rays=100000,
        sigmaX=0.0,
        sigmaY=0.0,
        sigmaZ=0.0,
        sigmaXprime=1e-6,
        sigmaZprime=1e-6,
    )
    beam0 = Beam()
    numpy.random.seed(123456)
    beam0.genSource(source)
    beam0.set_photon_wavelength(5e-10)
    print(beam0.info())

    if do_plot:
        plotxy(beam0, 4, 6, title="Image 0", nbins=201)

    #
    # syned definitopns
    #

    # surface shape
    # boundaries
    rlen1 = 5e-05
    rlen2 = 5e-05
    rwidx1 = 2e-05
    rwidx2 = 2e-05

    boundary_shape = Rectangle(x_left=-rwidx2,
                               x_right=rwidx1,
                               y_bottom=-rlen2,
                               y_top=rlen1)

    coordinates_syned = ElementCoordinates(p=10.0,
                                           q=6.0,
                                           angle_radial=numpy.radians(88.8))

    #
    # shadow definitions
    #
    if f_refl == 0:  # prerefl

        PreRefl.prerefl(interactive=False,
                        SYMBOL="SiC",
                        DENSITY=3.217,
                        FILE="SiC.dat",
                        E_MIN=100.0,
                        E_MAX=20000.0,
                        E_STEP=100.0)
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ],
            boundary_shape=boundary_shape,
            f_reflec=1,
            f_refl=f_refl,
            file_refl="SiC.dat"),
                                       coordinates=coordinates_syned)
    elif f_refl == 1:  # refraction index
        import xraylib
        refraction_index = xraylib.Refractive_Index("SiC", 2.4797, 3.217)
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ],
            boundary_shape=boundary_shape,
            f_reflec=1,
            f_refl=f_refl,
            file_refl="",
            refraction_index=refraction_index),
                                       coordinates=coordinates_syned)
    elif f_refl == 2:  # user file: 1D  vs angle
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ],
            boundary_shape=boundary_shape,
            f_reflec=1,
            f_refl=f_refl,
            file_refl="../../oasys_workspaces/xoppy_f1f2_139980555361648.dat"),
                                       coordinates=coordinates_syned)
    elif f_refl == 3:  # user file 1D vs energy
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ],
            boundary_shape=boundary_shape,
            f_reflec=1,
            f_refl=f_refl,
            file_refl="../../oasys_workspaces/xoppy_f1f2_139981943656272.dat"),
                                       coordinates=coordinates_syned)
    elif f_refl == 4:  # user file
        mirror1 = S4ConicMirrorElement(optical_element=S4ConicMirror(
            name="M1",
            conic_coefficients=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0
            ],
            boundary_shape=boundary_shape,
            f_reflec=1,
            f_refl=f_refl,
            file_refl="../../oasys_workspaces/xoppy_f1f2_139980938100080.dat"),
                                       coordinates=coordinates_syned)

    print(mirror1.info())

    #
    # run
    #
    beam1, mirr1 = mirror1.trace_beam(beam0)
    print(mirr1.info())

    #
    # check
    #

    if do_plot:
        plotxy(beam1, 1, 3, title="Image 1", nbins=101, nolost=1)
        plotxy(mirr1, 2, 1, title="Footprint 1", nbins=101, nolost=1)
Exemplo n.º 16
0
def lens_id16ni(do_plot=True):

    #
    # source
    #
    ESRF =  {'sigmaX':387.8,"sigmaZ":3.5,"sigmaX'":10.3,"sigmaZ'":1.2}
    EBS =  {'sigmaX':27.2, "sigmaZ":3.4,"sigmaX'":5.2,"sigmaZ'":1.4}
    m = EBS

    photon_energy = 17000.0
    undulator_length = 1.4

    sr,srp = get_sigmas_radiation(photon_energy,undulator_length)
    print("radiation sigmas: ",sr,srp)

    demagX = [2.42,2899]
    demagZ = 1849

    #
    f2dot35 = 2*numpy.sqrt(2*numpy.log(2))
    sx,sz,sxp,szp = m['sigmaX'],m['sigmaZ'],m["sigmaX'"],m["sigmaZ'"]

    Sx  = 1e-6 * numpy.sqrt( sx**2 + sr**2)
    Sz  = 1e-6 * numpy.sqrt( sz**2 + sr**2)
    Sxp = 1e-6 * numpy.sqrt( sxp**2 + srp**2)
    Szp = 1e-6 * numpy.sqrt( szp**2 + srp**2)

    print("Gaussian source dimensions (rms) x z x' z'",1e6*Sx,1e6*Sz,1e6*Sxp,1e6*Szp)
    print("Gaussian source dimensions (FWHM) x z x' z'",f2dot35*1e6*Sx,f2dot35*1e6*Sz,f2dot35*1e6*Sxp,f2dot35*1e6*Szp)

    src = SourceGaussian.initialize_from_keywords(number_of_rays=500000,
                                                  sigmaX=Sx,sigmaZ=Sz,
                                                  sigmaXprime=Sxp,sigmaZprime=Szp)

    beam = src.get_beam()
    SX, SZ = (1e6*beam.get_standard_deviation(1),1e6*beam.get_standard_deviation(3))

    if do_plot:
        plotxy(beam,1,3,nbins=100,title="SOURCE")

    #
    # multilayer
    #
    p = 28.3
    q = 11.70
    F = 1/(1/p+1/q)


    lens1e = S4IdealLensElement(optical_element=S4IdealLens(name="ML", focal_x=F, focal_y=0),
                                coordinates=ElementCoordinates(p=p, q=q))

    beam, tmp = lens1e.trace_beam(beam)


    FX, FZ = (1e6*beam.get_standard_deviation(1),1e6*beam.get_standard_deviation(3))
    print("----------------- Secondary source---------------------")
    print("Source dimensions (rms): %f %f um"%(SX,SZ))
    print("Focal dimensions (rms): %f %f um"%(FX,FZ))
    print("Focal dimensions (2.35*rms): %f %f um"%(f2dot35*FX,f2dot35*FZ))
    print("Demagnification: H:%g V:%g (theoretical: %g) "%(SX/FX,SZ/FZ,p/q))


    # first KB mirror
    p = 144.90
    q = 0.025
    F = 1.0/(1/184.90+1/0.10)

    lens2e = S4IdealLensElement(optical_element=S4IdealLens(name="KBV", focal_x=0, focal_y=F),
                                coordinates=ElementCoordinates(p=p, q=q))


    print(lens2e.info())
    beam, tmp = lens2e.trace_beam(beam)



    # second KB mirror
    p = 0.025
    q = 0.05
    F = 1.0/(1/144.95+1/0.05)

    lens3e = S4IdealLensElement(optical_element=S4IdealLens(name="KBH", focal_x=F, focal_y=0),
                                coordinates=ElementCoordinates(p=p, q=q))

    print(lens3e.info())
    beam, tmp = lens3e.trace_beam(beam)


    #
    #
    #
    # beam3 = Beam3.initialize_from_shadow4_beam(beam)
    if do_plot:
        tkt = plotxy(beam,1,3,nbins=300,xrange=[-0.0000005,0.0000005],yrange=[-0.0000005,0.0000005],title="FOCAL PLANE")

        print(tkt['fwhm_h'],tkt['fwhm_v'])

    FX, FZ = (1e6*beam.get_standard_deviation(1),1e6*beam.get_standard_deviation(3))
    print("----------------- Focal position ---------------------")
    print("Source dimensions (rms): %f %f um"%(SX,SZ))
    print("Source dimensions (2.35*rms): %f %f um"%(f2dot35*SX,f2dot35*SZ))
    print("Focal dimensions (rms): %f %f um"%(FX,FZ))
    print("Focal dimensions (2.35*rms): %f %f um"%(f2dot35*FX,f2dot35*FZ))
    if do_plot: print("Focal dimensions (FWHM HISTO): %f %f nm"%(1e9*tkt['fwhm_h'],1e9*tkt['fwhm_v']))
    print("Demagnification (StDev) H:%g V:%g (theoretical: %g,%g) "%(SX/FX,SZ/FZ,demagX[0]*demagX[1],demagZ))
    if do_plot: print("Demagnification:(HISTO) H:%g V:%g (theoretical: %g,%g) "%(f2dot35*SX/(f2dot35*1e6*tkt['fwhm_h']),SZ/(1e6*tkt['fwhm_v']),demagX[0]*demagX[1],demagZ))
Exemplo n.º 17
0
    from shadow4.beamline.optical_elements.mirrors.s4_toroidal_mirror import S4ToroidalMirror, S4ToroidalMirrorElement
    from shadow4.beamline.optical_elements.mirrors.s4_sphere_mirror import S4SphereMirror, S4SphereMirrorElement
    from shadow4.beamline.s4_optical_element import SurfaceCalculation
    from shadow4.beamline.optical_elements.mirrors.s4_surface_data_mirror import S4SurfaceDataMirror, \
        S4SurfaceDataMirrorElement

    from shadow4.syned.shape import Rectangle, Direction, Side  # TODO from syned.beamline.shape
    from srxraylib.plot.gol import set_qt

    set_qt()
    do_plot = True

    source = SourceGaussian.initialize_from_keywords(number_of_rays=10000,
                                                     sigmaX=0.0,
                                                     sigmaY=0.0,
                                                     sigmaZ=0.0,
                                                     sigmaXprime=1e-6,
                                                     sigmaZprime=1e-6, )
    beam0 = Beam()
    beam0.genSource(source)
    print(beam0.info())

    if do_plot:
        plotxy(beam0, 4, 6, title="Image 0", nbins=201)

    rlen1 = 0.6
    rlen2 = 0.6
    rwidx1 = 0.05
    rwidx2 = 0.05

    base_element = S4ToroidalMirror(name="M1b",
Exemplo n.º 18
0

if __name__ == "__main__":

    from shadow4.sources.source_geometrical.source_gaussian import SourceGaussian
    from shadow4.beam.beam import Beam
    from shadow4.tools.graphics import plotxy

    #
    # source
    #
    src = SourceGaussian.initialize_from_keywords(
        number_of_rays=10000,
        sigmaX=1.0e-6,
        sigmaY=0.0,
        sigmaZ=1.0e-6,
        sigmaXprime=0.0002,
        sigmaZprime=0.0002,
        real_space_center=[0.0, 0.0, 0.0],
        direction_space_center=[0.0, 0.0])
    beam = Beam()

    beam.genSource(src)
    beam.set_photon_energy_eV(1000.0)

    print(beam.info())

    # plotxy(Beam3.initialize_from_shadow4_beam(beam),1,3,nbins=100,title="SOURCE")

    #
    # grating