/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2008, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Instrument: incoherent_validation
*
* %Identification
* Written by: Mads Bertelsen
* Date: May 2016
* Origin: Johns Hopkins University, Baltimore
* %INSTRUMENT_SITE: Union_validation
*
* %Description
* Validation of Union components against incoherent scattering component
*
* %Example: comp_select=1 sample_radius=0.01 sample_height=0.01 pack=1 sigma_inc_vanadium=5.08 sigma_abs_vanadium=5.08 Vc_vanadium=13.827 geometry_interact=0.5 Detector: Detector: PSD_transmission_I=19084.8
* %Example: comp_select=1 sample_radius=0.01 sample_height=0.01 pack=1 sigma_inc_vanadium=5.08 sigma_abs_vanadium=5.08 Vc_vanadium=13.827 geometry_interact=0.5 Detector: Detector: PSDlin_scattering_I=1.10444
* %Example: comp_select=1 sample_radius=0.01 sample_height=0.01 pack=1 sigma_inc_vanadium=5.08 sigma_abs_vanadium=5.08 Vc_vanadium=13.827 geometry_interact=0.5 Detector: Detector: PSDlin_scattering_2_I=1.54102
*
* %Parameters
* comp_select:             [] 1: Union components, 2: Incoherent
* sample_radius:          [m] Radius of sample   
* sample_height:          [m] Height of sample     
* pack:                   [ ] Packing factor         
* sigma_inc_vanadium: [barns] Incoherent cross-section
* sigma_abs_vanadium: [barns] Absorption cross-section
* Vc_vanadium:         [AA^3] Unit cell volume
* geometry_interact:      [ ] p_interact for the Union sample
*
*
* %End
*******************************************************************************/

DEFINE INSTRUMENT Incoherent_validation(
  int comp_select=1, sample_radius=0.01, sample_height=0.01,
  pack=1, sigma_inc_vanadium=5.08, sigma_abs_vanadium=5.08,
  Vc_vanadium=13.827,geometry_interact=0.5)

DECLARE
%{
%}

TRACE

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

COMPONENT Vanadium_incoherent = Incoherent_process(sigma=sigma_inc_vanadium,packing_factor=pack,unit_cell_volume=Vc_vanadium)
AT (0,0,0) ABSOLUTE

COMPONENT Vanadium = Union_make_material(my_absorption=100*sigma_abs_vanadium/Vc_vanadium*pack,process_string="Vanadium_incoherent")
AT (0,0,0) ABSOLUTE

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

COMPONENT source = Source_div(
        xwidth=0.0005, yheight=0.0005,focus_aw=2, focus_ah=1.5,
        E0 = 10, dE = 0, flux=1E10)
  AT (0,0,0) RELATIVE a1 ROTATED (0,0,0) RELATIVE a1

COMPONENT sample_position = Arm()
AT (0,0,1) RELATIVE a1
ROTATED (0,0,0) RELATIVE a1


COMPONENT cylinder_sample_union = Union_cylinder(radius=sample_radius, yheight=sample_height, priority=1, material_string="Vanadium",p_interact = geometry_interact)
WHEN(comp_select == 1)
AT (0,0,0) RELATIVE sample_position
ROTATED (0,0,0) RELATIVE sample_position


COMPONENT test_sample = Union_master()
WHEN(comp_select == 1)
AT(0,0,1) RELATIVE a1

COMPONENT cylinder_sample_incoherent = Incoherent(radius=sample_radius, yheight=sample_height, pack=pack, p_interact=0.8, f_QE=0, gamma=0, sigma_abs=sigma_abs_vanadium, sigma_inc=sigma_inc_vanadium, Vc=Vc_vanadium, concentric=0, order=0)
WHEN(comp_select == 2)
AT (0,0,0) RELATIVE sample_position
ROTATED (0,0,0) RELATIVE sample_position

COMPONENT m4pi = PSD_monitor_4PI(radius=1, nx=180, ny=180, filename="4Pi_events.dat",restore_neutron=1)
  AT (0, 0, 0) RELATIVE sample_position

COMPONENT Banana_monitor = Monitor_nD(radius=1, yheight=0.1, options="banana, theta limits=[20,170], bins=200",filename="banana.dat",restore_neutron=1)
AT (0,0,0) RELATIVE sample_position
ROTATED (0,0,0) RELATIVE sample_position

COMPONENT PSDlin_transmission = PSDlin_monitor(xwidth=0.1, yheight=0.01, nbins=100, filename="Output_transmission_lin.psd",restore_neutron = 1)
AT (0,0,0.5) RELATIVE sample_position

COMPONENT PSD_transmission = PSD_monitor(xmin=-0.05,xmax=0.05,ymin=-0.05,ymax=0.05, nx=100, ny=100, filename="Output_transmission.psd",restore_neutron = 1)
AT (0,0,0.5) RELATIVE sample_position

COMPONENT scattering_arm = Arm()
AT (0,0,0) RELATIVE sample_position
ROTATED (0,25,0) RELATIVE sample_position

COMPONENT PSDlin_scattering = PSDlin_monitor(xwidth=0.1, yheight=0.05, nbins=100, filename="Output_scattering.psd",restore_neutron = 1)
AT (0,0,0.5) RELATIVE scattering_arm

COMPONENT scattering_arm_2 = Arm()
AT (0,0,0) RELATIVE sample_position
ROTATED (45,-35,0) RELATIVE sample_position

COMPONENT PSDlin_scattering_2 = PSDlin_monitor(xwidth=0.1, yheight=0.05, nbins=100, filename="Output_scattering_2.psd",restore_neutron = 1)
AT (0,0,0.5) RELATIVE scattering_arm_2

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

END
