/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2008, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Instrument: test
*
* %Identification
* Written by: Mads Bertelsen
* Date: September 2015
* Origin: University of Copenhagen
* %INSTRUMENT_SITE: Union_demos
*
* %Description
* Demonstration of Union components, here 4 different powder samoples in a
*  weird sample holder contained in a cryostat is simulated.
* This instrument file produces an absorption image of the setup.
*
*
* %Example: stick_displacement=0 Detector: screen_I=0.0111929
*
* %Parameters
* stick_displacement: [m] height displacement of sample stick
*
* %End
*******************************************************************************/

DEFINE INSTRUMENT Union_demonstration_absorption_image(stick_displacement=0)

DECLARE
%{
%}

TRACE

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

// Material definitions here use automatic linking, meaning that all processes
//  preceding each make_material component is included in that material.

// P0
COMPONENT Al_incoherent = Incoherent_process(sigma=4*0.0082,packing_factor=1,unit_cell_volume=66.4) //,interact_fraction=0.8)
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

// Cu definition
// 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=100*4*3.78/47.22)
AT (0,0,0) ABSOLUTE

// Ag Au mix definition
// P0
COMPONENT Ag_incoherent = Incoherent_process(sigma=4*0.58,packing_factor=1,unit_cell_volume=68.22,packing_factor=0.5)
AT (0,0,0) ABSOLUTE

// P1
COMPONENT Ag_Powder = Powder_process(reflections="Ag.laz",packing_factor=0.5)
AT (0,0,0) ABSOLUTE

// P2
COMPONENT Au_incoherent = Incoherent_process(sigma=4*0.43,packing_factor=1,unit_cell_volume=67.87,packing_factor=0.5)
AT (0,0,0) ABSOLUTE

// P3
COMPONENT Au_Powder = Powder_process(reflections="Au.laz",packing_factor=0.5)
AT (0,0,0) ABSOLUTE

COMPONENT Au_Ag_mix = Union_make_material(my_absorption=0.5*100*4*3.78/68.22+0.5*100*4*98.65/67.87)
AT (0,0,0) ABSOLUTE

// Cd definition
// P0
COMPONENT Cd_incoherent = Incoherent_process(sigma=2*3.46,packing_factor=1,unit_cell_volume=43.11)
AT (0,0,0) ABSOLUTE

// P1
COMPONENT Cd_Powder = Powder_process(reflections="Cd.laz")
AT (0,0,0) ABSOLUTE

COMPONENT Cd = Union_make_material(my_absorption=100*2*2520/43.11)
AT (0,0,0) ABSOLUTE

// Cs definition
// P0
COMPONENT Cs_incoherent = Incoherent_process(sigma=2*0.55,packing_factor=1,unit_cell_volume=47.22)
AT (0,0,0) ABSOLUTE

// P1
COMPONENT Cs_Powder = Powder_process(reflections="Cs.laz")
AT (0,0,0) ABSOLUTE

COMPONENT Cs = Union_make_material(my_absorption=100*2*3.78/47.22)
AT (0,0,0) ABSOLUTE



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

COMPONENT source = Source_div(
        xwidth=0.45, yheight=1.1,focus_aw=0.1, focus_ah=0.1,
        E0 = 10,
        dE = 0)
  AT (0,0.35,0) RELATIVE a1
  ROTATED (0,0,0) RELATIVE a1


// Sample position
COMPONENT beam_center = Arm()
AT (0,0,1.4) RELATIVE a1
ROTATED (0,0,0) RELATIVE a1


COMPONENT drum_center = Arm()
AT (0,0.38,0) RELATIVE beam_center
ROTATED (0,0,0) RELATIVE beam_center

// V1
COMPONENT cryostat_mountin_plate = Union_cylinder(radius=0.12,yheight=0.01,priority=7,material_string="Al")
AT (0,-0.103,0) RELATIVE beam_center
ROTATED (0,0,0) RELATIVE beam_center

// V2
COMPONENT cryostat_drum_walls = Union_cylinder(radius=0.2,yheight=0.57,priority=8,material_string="Al")
AT (0,0,0) RELATIVE drum_center
ROTATED (0,0,0) RELATIVE drum_center

// V3
COMPONENT cryostat_drum_vacuum = Union_cylinder(radius=0.19,yheight=0.55,priority=9,material_string="Vacuum")
AT (0,0,0) RELATIVE drum_center
ROTATED (0,0,0) RELATIVE drum_center

// V4
COMPONENT outer_cryostat_wall = Union_cylinder(radius=0.1,yheight=0.2,priority=10,material_string="Al",p_interact=0.2)
AT (0,0,0) RELATIVE beam_center
ROTATED (0,0,0) RELATIVE beam_center

// V5
COMPONENT outer_cryostat_vacuum = Union_cylinder(radius=0.09,yheight=0.2,priority=11,material_string="Vacuum")
AT (0,0.01,0) RELATIVE beam_center
ROTATED (0,0,0) RELATIVE beam_center

// V6
COMPONENT inner_cryostat_wall = Union_cylinder(radius=0.06,yheight=0.16,priority=12,material_string="Al",p_interact=0.2)
AT (0,0.01,0) RELATIVE beam_center
ROTATED (0,0,0) RELATIVE beam_center

// V7
COMPONENT inner_cryostat_vacuum = Union_cylinder(radius=0.05,yheight=0.15,priority=13,material_string="Vacuum")
AT (0,0.01,0) RELATIVE beam_center
ROTATED (0,0,0) RELATIVE beam_center

// V8
COMPONENT sample_stick_walls = Union_cylinder(radius=0.04,yheight=0.605,priority=14,material_string="Al")
AT (0,0.39,0) RELATIVE beam_center
ROTATED (0,0,0) RELATIVE beam_center

// V9
COMPONENT sample_stick_vacuum = Union_cylinder(radius=0.035,yheight=0.64,priority=15,material_string="Vacuum")
AT (0,0.4,0) RELATIVE beam_center
ROTATED (0,0,0) RELATIVE beam_center


COMPONENT sample_rod_bottom = Arm()
AT (0,0.05+stick_displacement,0) RELATIVE beam_center
ROTATED (0,85,0) RELATIVE beam_center

// V10
COMPONENT sample_rod = Union_cylinder(radius=0.0075,yheight=0.7,priority=25,material_string="Al")
AT (0,0.35,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V11
COMPONENT sample_rod_collar_1 = Union_cylinder(radius=0.034,yheight=0.02,priority=17,material_string="Al")
AT (0,0.048,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V12
COMPONENT sample_rod_collar_2 = Union_cylinder(radius=0.034,yheight=0.02,priority=18,material_string="Al")
AT (0,0.14,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V13
COMPONENT sample_rod_collar_3 = Union_cylinder(radius=0.034,yheight=0.02,priority=19,material_string="Al")
AT (0,0.34,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V14
COMPONENT sample_rod_collar_4 = Union_cylinder(radius=0.034,yheight=0.02,priority=20,material_string="Al")
AT (0,0.635,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V15
COMPONENT sample_rod_collar_1_vacuum = Union_cylinder(radius=0.03,yheight=0.016,priority=21,material_string="Vacuum")
AT (0,0.048-0.005,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V16
COMPONENT sample_rod_collar_2_vacuum = Union_cylinder(radius=0.03,yheight=0.016,priority=22,material_string="Vacuum")
AT (0,0.14-0.005,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V17
COMPONENT sample_rod_collar_3_vacuum = Union_cylinder(radius=0.03,yheight=0.016,priority=23,material_string="Vacuum")
AT (0,0.34-0.005,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V18
COMPONENT sample_rod_collar_4_vacuum = Union_cylinder(radius=0.03,yheight=0.016,priority=24,material_string="Vacuum")
AT (0,0.635-0.005,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V19
COMPONENT sample_holder1 = Union_box(xwidth=0.01,yheight=0.05,zdepth=0.004,priority=35,material_string="Al",p_interact=0.3)
AT (0,0,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V20
COMPONENT sample_holder2 = Union_box(xwidth=0.0099,yheight=0.004,zdepth=0.03/0.85,priority=51,material_string="Al",p_interact=0.3)
AT (0,-0.03,0.03*0.35+0.004) RELATIVE sample_rod_bottom
ROTATED (25,0,0) RELATIVE sample_rod_bottom

// V21
COMPONENT sample_holder3 = Union_box(xwidth=0.0098,yheight=0.004,zdepth=0.03/0.85,priority=52,material_string="Al",p_interact=0.3)
AT (0,-0.03,-0.03*0.35-0.004) RELATIVE sample_rod_bottom
ROTATED (-25,0,0) RELATIVE sample_rod_bottom

// V22
COMPONENT sample_holder4 = Union_box(xwidth=0.01,yheight=0.07,zdepth=0.004,priority=53,material_string="Al",p_interact=0.3)
AT (0,-0.03-0.035-0.005,0.03) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V23
COMPONENT sample_holder5 = Union_box(xwidth=0.01,yheight=0.07,zdepth=0.004,priority=54,material_string="Al",p_interact=0.3)
AT (0,-0.03-0.035-0.005,-0.03) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V24
COMPONENT sample_holder_bottom = Union_box(xwidth=0.0098,yheight=0.004,zdepth=0.058,priority=42,material_string="Al",p_interact=0.3)
AT (0,-0.03-0.067-0.007,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V25
COMPONENT sample_holder_top_shelf = Union_box(xwidth=0.0098,yheight=0.004,zdepth=0.058,priority=43,material_string="Al",p_interact=0.3)
AT (0,-0.045+0.003,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V26
COMPONENT sample_holder_middle_shelf = Union_box(xwidth=0.0098,yheight=0.004,zdepth=0.058,priority=44,material_string="Al",p_interact=0.3)
AT (0,-0.072,0) RELATIVE sample_rod_bottom
ROTATED (0,0,0) RELATIVE sample_rod_bottom

// V27
COMPONENT sample_1 = Union_cylinder(radius=0.0045,yheight=0.02,priority=63,material_string="Cu",p_interact=0.6)
AT (0,-0.002-0.01-0.003,0.015) RELATIVE sample_holder_top_shelf
ROTATED (0,0,0) RELATIVE sample_holder_top_shelf

// V28
COMPONENT sample_1_container = Union_cylinder(radius=0.0052,yheight=0.023,priority=62,material_string="Al",p_interact=0.3)
AT (0,0,0) RELATIVE sample_1
ROTATED (0,0,0) RELATIVE sample_1

// V29
COMPONENT sample_1_container_rim = Union_cylinder(radius=0.007,yheight=0.002,priority=61,material_string="Al",p_interact=0.3)
AT (0,0.023*0.5,0) RELATIVE sample_1
ROTATED (0,0,0) RELATIVE sample_1

// V30
COMPONENT sample_2 = Union_cylinder(radius=0.0045,yheight=0.02,priority=73,material_string="Au_Ag_mix",p_interact=0.6)
AT (0,-0.002-0.01-0.003,-0.015) RELATIVE sample_holder_top_shelf
ROTATED (0,0,0) RELATIVE sample_holder_top_shelf

// V31
COMPONENT sample_2_container = Union_cylinder(radius=0.0052,yheight=0.023,priority=72,material_string="Al",p_interact=0.3)
AT (0,0,0) RELATIVE sample_2
ROTATED (0,0,0) RELATIVE sample_2

// V32
COMPONENT sample_2_container_rim = Union_cylinder(radius=0.007,yheight=0.002,priority=71,material_string="Al",p_interact=0.3)
AT (0,0.023*0.5,0) RELATIVE sample_2
ROTATED (0,0,0) RELATIVE sample_2

// V33
COMPONENT sample_3 = Union_cylinder(radius=0.0045,yheight=0.02,priority=83,material_string="Cd",p_interact=0.6)
AT (0,-0.002-0.01-0.003,0.015) RELATIVE sample_holder_middle_shelf
ROTATED (0,0,0) RELATIVE sample_holder_middle_shelf

// V34
COMPONENT sample_3_container = Union_cylinder(radius=0.0052,yheight=0.023,priority=82,material_string="Al",p_interact=0.3)
AT (0,0,0) RELATIVE sample_3
ROTATED (0,0,0) RELATIVE sample_3

// V35
COMPONENT sample_3_container_rim = Union_cylinder(radius=0.007,yheight=0.002,priority=81,material_string="Al",p_interact=0.3)
AT (0,0.023*0.5,0) RELATIVE sample_3
ROTATED (0,0,0) RELATIVE sample_3

// V36
COMPONENT sample_4 = Union_cylinder(radius=0.0045,yheight=0.02,priority=93,material_string="Cs",p_interact=0.6)
AT (0,-0.002-0.01-0.003,-0.015) RELATIVE sample_holder_middle_shelf
ROTATED (0,0,0) RELATIVE sample_holder_middle_shelf

// V37
COMPONENT sample_4_container = Union_cylinder(radius=0.0052,yheight=0.023,priority=92,material_string="Al",p_interact=0.3)
AT (0,0,0) RELATIVE sample_4
ROTATED (0,0,0) RELATIVE sample_4

// V38
COMPONENT sample_4_container_rim = Union_cylinder(radius=0.007,yheight=0.002,priority=91,material_string="Al",p_interact=0.3)
AT (0,0.023*0.5,0) RELATIVE sample_4
ROTATED (0,0,0) RELATIVE sample_4

COMPONENT test_sample = Union_master()
AT(0,0,0) RELATIVE beam_center
ROTATED(0,30,20) RELATIVE beam_center

COMPONENT screen = PSD_monitor(xwidth=0.45,ymin=-0.15,ymax=0.85,nx=500,ny=1200,filename="absoprtion_picture.dat",restore_neutron=1)
  AT (0,0,2) RELATIVE a1

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


END
