/*******************************************************************************
*         McStas instrument definition URL=http://www.mcstas.org
*
* Instrument: Samples_Incoherent
*
* %Identification
* Written by: Peter Willendrup, Erik Knudsen, Aziz Aziz Daoud-aladine
* Date: August 14th, 2007
* Origin: RISOE
* %INSTRUMENT_SITE: Tests_samples
*
* This instrument allows to compare incoherent scattering from different McStas
* sample components.
*
* %Description
* This instrument allows to compare incoherent scattering from different McStas
* sample components:
*
* * PowderN
* Single_crystal
* Isotropic_sqw
* Incoherent
*
* Examples:
*
* Compare incoherent scattering from all sample comps, beamstop in place.
*
* mcrun Samples_Incoherent -d Some_directory -N5 SAMPLE=1,5 STOP=1
*
* Compare incoherent scattering and direct beam attenuation for PowderN, Single_crystal
* and Isotroic_sqw:
*
* mcrun Samples_Incoherent -d Some_other_directory -N4 SAMPLE=2,5 STOP=0
*
* Have a closer look of direct beam attentuation for PowderN, Single_crystal
* and Isotroic_sqw (has the side-effect that back-scattered neutrons are absorbed):
*
* mcrun Samples_Incoherent -d Some_third_directory -N4 SAMPLE=2,5 STOP=0 DB=1
*
* The sample type selection is:
*   box:      1=Vanadium
*             2=PowderN
*             3=Single_Crystal
*             4=Isotropic_Sqw
*             5=Incoherent
*            10=Isotropic_Sqw with V.lau
*   cube.off: 6=PowderN,
*             7=Single_Crystal
*             8=Isotropic_Sqw
*             9=Incoherent
*
* %Example: SAMPLE=1 STOP=1 Detector: PSD_Sphere_4pi_I=1.2321e+06
* %Example: SAMPLE=2 STOP=1 Detector: PSD_Sphere_4pi_I=1.2324e+06
* %Example: SAMPLE=3 STOP=1 Detector: PSD_Sphere_4pi_I=1.3196e+06
* %Example: SAMPLE=4 STOP=1 Detector: PSD_Sphere_4pi_I=1.3246e+06
* %Example: SAMPLE=5 STOP=1 Detector: PSD_Sphere_4pi_I=1.3252e+06
* %Example: SAMPLE=6 STOP=1 -n 1e5 Detector: PSD_Sphere_4pi_I=1.2324e+06
* %Example: SAMPLE=7 STOP=1 -n 1e5 Detector: PSD_Sphere_4pi_I=1.3225e+06
* %Example: SAMPLE=8 STOP=1 -n 1e5 Detector: PSD_Sphere_4pi_I=1.3233e+06
* %Example: SAMPLE=9 STOP=1 -n 1e5 Detector: PSD_Sphere_4pi_I=1.3239e+06
* %Example: SAMPLE=10 STOP=1 -n 1e5 Detector: PSD_Sphere_4pi_I=1.28905e+06
*
* %Parameters
* L_min: [AA]         Minimum wavelength of neutrons
* L_max: [AA]         Maximum wavelength of neutrons
* STOP: [1]           Beamstop inserted? (Needed in case of comparison between V and SX/sqw).
* DB: [1]             Direct Beam monitor inserted? (Side-effect: absorbs 'backscattered' neutrons).
* Order: [1]          Maximum order of multiple scattering in SX/sqw
* INC: [barns]        Incoherent scattering cross section
* ABS: [barns]        Absorption cross section
* ISISFACE: [string]  ISIS moderator face to look at
* SAMPLE: [ ]         Sample choice, 1:Incoherent, 2:PowderN, 3:Single_crystal, 4:Isotropic_Sqw, 5:Incoherent with multiple scattering, 6:PowderN with OFF geometry, 7:Single_crystal with OFF geometry, 8:Isotropic_Sqw with OFF geometry, 9:Incoherent with OFF geometry, 10:Isotropic_Sqw with .laz input
*
* %Link
* Validation of Single_crystal is now in progress!
*
* %End
*******************************************************************************/
DEFINE INSTRUMENT Samples_Incoherent(L_min=0.5, L_max=7, int SAMPLE=1, STOP=0, Order=0, INC=5.08, ABS=5.08, DB=0, string ISISFACE="hydrogen")
DEPENDENCY " -DUSE_OFF "

DECLARE %{
  double e_min,e_max;
%}

INITIALIZE %{
   e_min=81.799/L_max/L_max;
   e_max=81.799/L_min/L_min;
%}

TRACE

COMPONENT Source = ISIS_moderator(
	Face = ISISFACE, Emin = e_min, Emax = e_max, dist = 8.299, focus_xw = 0.005,
	focus_yh = 0.005, xwidth = .12, yheight = .115, CAngle = 0,
	SAC = 1)
  AT (0, 0, 0) ABSOLUTE

COMPONENT Coord = Progress_bar()
   AT (0.0,0.0,8.3000) RELATIVE Source

/* set of samples *************************************************************/

COMPONENT Vsample = Incoherent(sigma_abs=ABS, sigma_inc=INC,
  xwidth=0.005, yheight=0.005, zdepth=0.005)
WHEN (SAMPLE==1) AT (0, 0, 0) RELATIVE Coord

COMPONENT PowN = PowderN(reflections="", d_phi=0, Vc = 13.827, p_transmit = 0.5, p_inc = 0.5,
  sigma_abs=ABS, sigma_inc=INC,
  xwidth=0.005, yheight=0.005, zdepth=0.005)
WHEN (SAMPLE==2) AT (0, 0, 0) RELATIVE Coord

COMPONENT SX = Single_crystal(reflections="", order=Order, ax=3.0282, by=3.0282, cz=3.0282/2,
  sigma_abs=ABS, sigma_inc=INC, barns=1,
  xwidth=0.005, yheight=0.005, zdepth=0.005)
WHEN (SAMPLE==3) AT (0, 0, 0) RELATIVE Coord

COMPONENT Sqw = Isotropic_Sqw(rho=1/13.827, order=Order,
  sigma_abs=ABS, sigma_inc=INC, sigma_coh=0,
  xwidth=0.005, yheight=0.005, zdepth=0.005)
WHEN (SAMPLE==4) AT (0,0,0) RELATIVE Coord

COMPONENT IncS = Incoherent(order=Order,
  sigma_abs=ABS, sigma_inc=INC,
  xwidth=0.005, yheight=0.005, zdepth=0.005)
WHEN (SAMPLE==5) AT (0, 0, 0) RELATIVE Coord

/* set of samples with OFF geometry *******************************************/

COMPONENT PowNg = PowderN(reflections="", d_phi=0, Vc = 13.827, p_transmit = 0.5, p_inc = 0.5,
  sigma_abs=ABS, sigma_inc=INC,
  geometry="cube.off", xwidth=0.005)
WHEN (SAMPLE==6) AT (0, 0, 0) RELATIVE Coord

COMPONENT SXg = Single_crystal(reflections="", order=Order, ax=3.0282, by=3.0282, cz=3.0282/2,
  sigma_abs=ABS, sigma_inc=INC, barns=1,
  geometry="cube.off", xwidth=0.005)
WHEN (SAMPLE==7) AT (0, 0, 0) RELATIVE Coord

COMPONENT Sqwg = Isotropic_Sqw(rho=1/13.827, order=Order,
  sigma_abs=ABS, sigma_inc=INC, sigma_coh=0,
  geometry="cube.off", xwidth=0.005)
WHEN (SAMPLE==8) AT (0,0,0) RELATIVE Coord

COMPONENT IncSg=Incoherent(order=Order,
  sigma_abs=ABS, sigma_inc=INC,
  geometry="cube.off", xwidth=0.005)
WHEN (SAMPLE==9) AT (0, 0, 0) RELATIVE Coord

/* other Sqw tests *************************************************************/

COMPONENT SqwV= Isotropic_Sqw(Sqw_coh="V.lau",
  xwidth=0.005, yheight=0.005, zdepth=0.005)
WHEN (SAMPLE==10) AT (0,0,0) RELATIVE Coord

/* end of samples *************************************************************/

COMPONENT Dirbeam = PSD_monitor(nx=128,ny=128,filename="beamstopPSD",xwidth=0.01,yheight=0.01)
WHEN (DB) AT (0,0,0.039) RELATIVE Sqw

COMPONENT Stop = Beamstop(radius=0.005)
WHEN (STOP==1) AT (0,0,0.04) RELATIVE Sqw

COMPONENT Tof_Sphere_4pi = Monitor_nD(
    options = "sphere abs lambda, limits=[0.38,7.13], bins=2000, file=TOF", xwidth = 0.1)
  AT (0, 0, 0) RELATIVE Coord

COMPONENT PSD_Sphere_4pi = PSD_monitor_4PI(radius=0.051, nx=180, ny=180, filename="PSD")
  AT (0, 0, 0) RELATIVE Coord

COMPONENT Coord3 = Arm()
   AT (0.0,0.0,8.3000) RELATIVE Source
EXTEND %{
  p=1;
%}

COMPONENT Sphere_4pi = PSD_monitor_4PI(radius=0.052, nx=180, ny=180, filename="Events")
  AT (0, 0, 0) RELATIVE Coord

END
