/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2008, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Instrument: Union_conditional_test
*
* %Identification
* Written by: Mads Bertelsen
* Date: September 2015
* Origin: University of Copenhagen
* %INSTRUMENT_SITE: Union_demos
*
*
* %Description
* Use of all conditional components
*
* %Example: dummy=1 Detector: detector_scat_I=40.2053
* Example: dummy=1 Detector: test_logger_2D_space_zx_con_time_I=76662.3
* Example: dummy=1 Detector: test_logger_2D_space_zx_con_PSD_I=387.97
*
* %Parameters
* dummy: [ ] Dummy input parameter
* 
* %End
*******************************************************************************/

DEFINE INSTRUMENT Union_conditional_test(dummy=1)

DECLARE
%{
%}

TRACE

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

COMPONENT Vanadium_incoherent = Incoherent_process(sigma=2*5.08,packing_factor=1,unit_cell_volume=27.66)
AT (0,0,0) ABSOLUTE

COMPONENT Vanadium = Union_make_material(my_absorption=2*5.08*100/27.66,process_string="Vanadium_incoherent")
AT (0,0,0) ABSOLUTE

// P0
COMPONENT Al_incoherent = Incoherent_process(sigma=4*0.0082,packing_factor=1,unit_cell_volume=66.4)
AT (0,0,0) ABSOLUTE

// P1
COMPONENT Al_Powder = Powder_process(reflections="Al.laz")
AT (0,0,0) ABSOLUTE

COMPONENT Al = Union_make_material(my_absorption=100*4*0.231/66.4)
AT (0,0,0) ABSOLUTE

// P0
COMPONENT Cu_incoherent = Incoherent_process(sigma=4*0.55,packing_factor=1,unit_cell_volume=47.22)
AT (0,0,0) ABSOLUTE

// P1
COMPONENT Cu_Powder = Powder_process(reflections="Cu.laz")
AT (0,0,0) ABSOLUTE

COMPONENT Cu = Union_make_material(my_absorption=5*100*4*3.78/47.22)
AT (0,0,0) ABSOLUTE

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

COMPONENT source = Source_div(
        xwidth=0.09, yheight=0.15,focus_aw=0.01, focus_ah=0.01,
        E0 = 5,
        dE = 0, flux = 1E12)
  AT (0,0,0) RELATIVE a1 ROTATED (0,0,0) RELATIVE a1

COMPONENT sample_pos = Arm()
AT (0,0,0.3) RELATIVE source

COMPONENT cryostat_wall = Union_cylinder(
 radius=0.07,yheight=0.32,priority=10,material_string="Al",p_interact=0.2)
AT (0,0,0) RELATIVE sample_pos
ROTATED (0,0,0) RELATIVE sample_pos

COMPONENT cryostat_wall_vacuum = Union_cylinder(
 radius=0.068,yheight=0.318,priority=11,material_string="Vacuum")
AT (0,0,0) RELATIVE sample_pos
ROTATED (0,0,0) RELATIVE sample_pos

COMPONENT sample_sphere = Union_sphere(
 radius=0.031,priority=20,material_string="Cu")
AT (0.01,0,0) RELATIVE sample_pos
ROTATED (0,0,0) RELATIVE sample_pos

COMPONENT sample_box = Union_box(
 xwidth=0.021, yheight=0.018, zdepth=0.1, priority=21, material_string="Vanadium")
AT (-0.01,0,0) RELATIVE sample_pos
ROTATED (34,17,0) RELATIVE sample_pos

COMPONENT sample_cone = Union_cone(
 radius_top=0.031, radius_bottom=0.005, yheight=0.04, priority=22, material_string="Cu")
AT (0.02,-0.03,0) RELATIVE sample_pos
ROTATED (0,0,20) RELATIVE sample_pos

COMPONENT test_logger_1D = Union_logger_1D(
  variable="time", min_value=1E-4, max_value=8E-4, n1=200, filename="logger_1D.dat"
)
AT (0,0,0) RELATIVE sample_pos
ROTATED (0,0,0) RELATIVE sample_pos

COMPONENT test_logger_2D_space_zx = Union_logger_2D_space(
  D_direction_1 = "z", D1_min=-0.1, D1_max=0.1, n1=200,
  D_direction_2 = "x", D2_min=-0.1, D2_max=0.1, n2=200,
  filename="logger_2D_space_zx.dat"
)
AT (0,0,0) RELATIVE sample_pos
ROTATED (0,0,0) RELATIVE sample_pos

COMPONENT test_logger_2D_space_zy = Union_logger_2D_space(
  D_direction_1 = "z", D1_min=-0.1, D1_max=0.1, n1=200,
  D_direction_2 = "y", D2_min=-0.1, D2_max=0.1, n2=200,
  filename="logger_2D_space_zy.dat"
)
AT (0,0,0) RELATIVE sample_pos
ROTATED (0,0,0) RELATIVE sample_pos

COMPONENT scat_direction = Arm()
AT (0,0,0) RELATIVE sample_pos
ROTATED (0,34,0) RELATIVE sample_pos

COMPONENT test_logger_2D_space_zx_con_time = Union_logger_2D_space(
  D_direction_1 = "z", D1_min=-0.1, D1_max=0.1, n1=200,
  D_direction_2 = "x", D2_min=-0.1, D2_max=0.1, n2=200,
  filename="logger_2D_space_zx_con_time.dat"
)
AT (0,0,0) RELATIVE sample_pos
ROTATED (0,0,0) RELATIVE sample_pos

COMPONENT test_conditional_standard = Union_conditional_standard(
    target_loggers="test_logger_2D_space_zx_con_time",
    time_min = 4E-4, time_max = 5E-4)
AT (0,0,0) RELATIVE sample_pos

COMPONENT test_logger_2D_space_zx_con_PSD = Union_logger_2D_space(
  D_direction_1 = "z", D1_min=-0.1, D1_max=0.1, n1=200,
  D_direction_2 = "x", D2_min=-0.1, D2_max=0.1, n2=200,
  filename="logger_2D_space_zx_con_PSD.dat"
)
AT (0,0,0) RELATIVE sample_pos
ROTATED (0,0,0) RELATIVE sample_pos

COMPONENT test_conditional_PSD = Union_conditional_PSD(
    target_loggers="test_logger_2D_space_zx_con_PSD",
    xwidth=0.085, yheight=0.15)
AT (0,0,0.5) RELATIVE scat_direction

COMPONENT sample = Union_master()
AT(0,0,0) RELATIVE sample_pos
ROTATED(0,0,0) RELATIVE sample_pos

COMPONENT detector = PSD_monitor(xwidth=0.085, yheight=0.15, nx=200, ny=200, filename="PSD.dat", restore_neutron=1)
AT (0,0,0.3) RELATIVE sample_pos
ROTATED (0,0,0) RELATIVE sample_pos

COMPONENT detector_scat = PSD_monitor(xwidth=0.085, yheight=0.15, nx=200, ny=200, filename="PSD_scat.dat", restore_neutron=1)
AT (0,0,0.5) RELATIVE scat_direction
ROTATED (0,0,0) RELATIVE scat_direction

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


END
