/*******************************************************************************
*
* McXtrace, xray-tracing package
*         Copyright (C) 1997-2008, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Instrument: Template_SasView
*
* %Identification
* Written by: Torben Nielsen 
* Modified by: Erik b knudsen
* Date: Jan 2017.
* Origin: DTU Physics / ESS DMSC
* Release: 1.5
* 
* %INSTRUMENT_SITE: Tests_samples
*
* Test instrument for the SasView_model component. No optics.
* etc. 
*
*
* %Description
*
* Very simple test instrument for 3 examples from the suite of SasView_ components
*
* %Example: model_index=1 Ncount=1e5 par1=4 par2=1 par3=40 par4=20 par5=400 Detector: detector_I=605
* %Example: model_index=3 Ncount=1e5 par1=220 par2=0.06 par3=40 par4=4 par5=1 Detector: detector_I=4.2
* %Example: model_index=47 Ncount=1e5 par1=4 par2=2 par3=35 par4=75 par5=400 Detector: detector_I=297
*
* %Parameters
* lambda: [AA]   Mean wavelength of X-rays
* dlambda: [AA]  Wavelength spread of X-rays
* model_index: [ ] SASmodels model index (see SasView_model.comp mcdoc page)
* par1: [ ] Slot 1 in SASmodel parameter vector
* par2: [ ] Slot 2 in SASmodel parameter vector
* par3: [ ] Slot 3 in SASmodel parameter vector
* par4: [ ] Slot 4 in SASmodel parameter vector
* par5: [ ] Slot 5 in SASmodel parameter vector
* par6: [ ] Slot 6 in SASmodel parameter vector
* par7: [ ] Slot 7 in SASmodel parameter vector
* par8: [ ] Slot 8 in SASmodel parameter vector
* Ncount:[1] Override the number of rays to simulate.
*
* %Link
* %End
*******************************************************************************/
DEFINE INSTRUMENT Template_SasView(lambda=1.54, dlambda=0.05, model_index=10, par1=0, par2=0, par3=0, par4=0, par5=0, par6=0, par7=0, par8=0, Ncount=0)

DECLARE %{
  double modelpars[8];
%}

INITIALIZE %{
  modelpars[0]=par1;
  modelpars[1]=par2;
  modelpars[2]=par3;
  modelpars[3]=par4;
  modelpars[4]=par5;
  modelpars[5]=par6;
  modelpars[6]=par7;
  modelpars[7]=par8;

  if (Ncount>0)
    mcset_ncount(Ncount);

%}

TRACE

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

COMPONENT arm = Arm(
    )
  AT (0, 0, 0) ABSOLUTE

COMPONENT source = Source_flat (
    radius = 0.0005, dist = 3, focus_xw = .5e-3, focus_yh = .5e-3,
    lambda0 = lambda, dlambda = dlambda, flux = 1e8)
  AT (0, 0, 0) RELATIVE arm

COMPONENT coll1 = Slit(
    radius = 0.0005)
  AT (0, 0, 3) RELATIVE arm

COMPONENT coll2 = Slit(
    radius = 0.0005)
  AT (0, 0, 6) RELATIVE arm

// Example sphere
SPLIT COMPONENT sample = Arm()
  AT (0, 0, 0) RELATIVE coll2

COMPONENT sample1= SasView_barbell(model_scale=1,model_abs=0.0,
				   sld=par1,sld_solvent=par2,radius_bell=par3,radius=par4,length=par5,
				      xwidth=0.01, yheight=0.01, zdepth=0.005,focus_xw=0.6, focus_yh=0.6, target_index=1)
WHEN (model_index==1) AT (0,0,0.2) RELATIVE coll2
EXTEND %{
  if (!SCATTERED) ABSORB;
%}

COMPONENT sample3= SasView_bcc_paracrystal(model_scale=1,model_abs=0.0,
					   dnn=par1, d_factor=par2, radius=par3, sld=par4, sld_solvent=par5,
				      xwidth=0.01, yheight=0.01, zdepth=0.005,focus_xw=0.6, focus_yh=0.6, target_index=1)
WHEN (model_index==3) AT (0,0,0.2) RELATIVE coll2
EXTEND %{
  if (!SCATTERED) ABSORB;
%}

COMPONENT sample47= SasView_parallelepiped(model_scale=1,model_abs=0.0,
				      sld=par1,sld_solvent=par2,length_a=par3,length_b=par4,length_c=par5,
				      xwidth=0.01, yheight=0.01, zdepth=0.005,focus_xw=0.6, focus_yh=0.6, target_index=1)
WHEN (model_index==47) AT (0,0,0.2) RELATIVE coll2
EXTEND %{
  if (!SCATTERED) ABSORB;
%}

COMPONENT detector = PSD_monitor(
    nx = 128, ny = 128, filename = "PSD.dat", xwidth = 0.6, yheight=0.6)
  AT (0, 0, 3) RELATIVE sample

COMPONENT Ldetector = L_monitor(
    nL = 1000, filename = "Edet.dat", xwidth = 0.6, yheight=0.6, Lmin = 0.5,
    Lmax = 2.5)
  AT (0, 0, 3.01) RELATIVE sample

COMPONENT PSDrad = PSD_monitor(
        filename = "psd2.dat",  radius = 0.3)
  AT (0, 0, 3.02) RELATIVE sample

END

