/*******************************************************************************
*
* 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_demos
*
* %Description
*  Powder in Al can
*
* Example: Detector: Banana_monitor_I=9.84391e-09
*
* %Parameters
* material_data_file: [string] Name of data file for powder sample
* E0: [meV] Source mean energy
* dE: [meV] Source energy spread
* sample_radius: [m] Sample radius
* sample_height: [m] Sample height
* pack: [1] Packing factor, 1 is full density
* sigma_inc: [barns] Incoherent cross section for powder sample
* sigma_abs: [barns] Absorption cross section for powder sample
* Vc: [AA] Unit cell volume for powder sample
* geometry_interact: [1] Fraction of beam to interact with geometry
* incoherent_fraction: [1] Fraction of scattered events that select the powder process
*
* %End
*******************************************************************************/

DEFINE INSTRUMENT Tagging_demo(string material_data_file="Cu.laz",E0=100,dE=2,sample_radius=0.01,sample_height=0.01,pack=1,sigma_inc=2.2,sigma_abs=15.12,Vc=47.22,geometry_interact=0.5,incoherent_fraction=0.2)

DECLARE
%{
%}

TRACE

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

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

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

COMPONENT Cu_incoherent_process = Incoherent_process(sigma=sigma_inc,packing_factor=pack,unit_cell_volume=Vc,interact_fraction=incoherent_fraction)
AT (0,0,0) ABSOLUTE

// d_phi is a focusing option in the Powder process
COMPONENT Cu_powder_process = Powder_process(reflections=material_data_file,d_phi=15)
AT (0,0,0) ABSOLUTE

COMPONENT Cu_powder = Union_make_material(my_absorption=100*sigma_abs/Vc*pack,process_string="Cu_incoherent_process,Cu_powder_process")
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=1.5, focus_ah=1.5,
        E0 = E0, dE = dE)
  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 powder_container = Union_cylinder(radius=sample_radius*1.2, yheight=sample_height*1.1, priority=1, material_string="Al", p_interact=0.2)
AT (0,0,0) RELATIVE sample_position
ROTATED (0,0,0) RELATIVE sample_position

COMPONENT powder_inside_container = Union_cylinder(radius=sample_radius, yheight=sample_height, priority=2, material_string="Cu_powder", p_interact = geometry_interact)
AT (0,0,0) RELATIVE sample_position
ROTATED (0,0,0) RELATIVE sample_position

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

COMPONENT detector_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=500",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
