/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2008, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Instrument: Unit_test_abs_logger_1D_space_tof_to_lambda
*
* %Identification
* Written by: Mads Bertelsen
* Date: June 2020
* Origin: ESS
* %INSTRUMENT_SITE: Tests_union
*
* Test of abs_logger_1D_space_tof_to_lambda that calculates wavelength from tof
*
* %Description
* This component works as other absorption loggers, but converts the tof and
* position data to wavelength, which is then compared to the actual wavelength
* calculated from the neutron state. The neutron position used to calculate
* the wavelength is pixelated while the time of flight is continous. The
* distance from source to sample is an input parameter, and the distance from
* sample to a detector pixel is calculated using the reference component position
* which should be specified with a relative component index. This test checks
* both the standard view with measured and true wavelength on each axis, and the
* relative where they have been normalized and a value of 1 is expected.
*
* %Example: Detector: abs_logger_1D_space_tof_to_lambda_I=9.82157e-12
* %Example: Detector: abs_logger_1D_space_tof_to_lambda_relative_I=1.02297e-11
*
* %End
*******************************************************************************/

DEFINE INSTRUMENT Unit_test_abs_logger_1D_space_tof_to_lambda()

DECLARE
%{
%}

INITIALIZE
%{
%}

TRACE

COMPONENT init = Union_init()
AT (0,0,0) ABSOLUTE

COMPONENT incoherent = Incoherent_process(sigma=0.2, packing_factor=1, unit_cell_volume=66.4)
AT (0,0,0) ABSOLUTE

COMPONENT powder = Powder_process(reflections="Cu2MnAl.laz")
AT (0,0,0) ABSOLUTE

COMPONENT material = Union_make_material(my_absorption=4.0,
    process_string="incoherent,powder")
AT (0,0,0) ABSOLUTE

COMPONENT Origin = Progress_bar()
  AT (0,0,0) ABSOLUTE

COMPONENT source = Source_div(
        xwidth=0.02, yheight=0.002,
        focus_aw=0.01, focus_ah=0.01,
        lambda0=5, dlambda=3)
AT (0,0,0) RELATIVE Origin

COMPONENT geometry_center = Arm()
AT (0,0,10.0) RELATIVE source

COMPONENT sphere = Union_sphere(radius=0.02, priority=6, material_string="material")
AT (0,0,0) RELATIVE geometry_center

COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material")
AT (-0.03,0,-0.01) RELATIVE geometry_center

COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material")
AT (0.03,0,0.02) RELATIVE geometry_center

COMPONENT cylinder = Union_cylinder(radius=0.02, yheight=0.8, priority=7, material_string="material")
AT (-1.0,0,0.0) RELATIVE geometry_center

COMPONENT abs_logger_1D_space_tof_to_lambda = Union_abs_logger_1D_space_tof_to_lambda(
    yheight=0.8, yn=100,
    target_geometry="cylinder",
    ref_component=-5,
    source_sample_dist=10.0,
    lambda_min=2.0, lambda_max=8.0, lambda_bins=200,
    filename="Union_abs_logger_1D_space_tof_to_lambda.dat")
AT (0,0,0) RELATIVE cylinder

COMPONENT abs_logger_1D_space_tof_to_lambda_relative = Union_abs_logger_1D_space_tof_to_lambda(
    yheight=0.8, yn=100,
    target_geometry="cylinder",
    ref_component=-6,
    source_sample_dist=10.0,
    lambda_min=2.0, lambda_max=8.0, lambda_bins=200,
    filename="Union_abs_logger_1D_space_tof_to_lambda_relative.dat",
    relative_measured=1, relative_min=0.95, relative_max=1.05, relative_bins=100)
AT (0,0,0) RELATIVE cylinder

COMPONENT master = Union_master()
AT(0,0,0) RELATIVE geometry_center

COMPONENT transmission = PSD_monitor(
    xwidth=0.1, yheight=0.08, nx=200, ny=200,
    filename="PSD.dat", restore_neutron=1)
AT (0,0,1) RELATIVE geometry_center


COMPONENT stop = Union_stop()
AT (0,0,0) ABSOLUTE

END
