/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2023, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Instrument: templateSasView
*
* %Identification
* Written by: Torben Nielsen 
* Origin: DTU Physics / ESS DMSC
* 
*
* %INSTRUMENT_SITE: Templates
*
* Test instrument for some SasView_model components. No guide / velocity selector
* etc.
*
* %Description
*
* Very simple test instrument for the SasView_model component
*
* %Example: model_index=1 Ncount=1e6 par1=4 par2=1 par3=40 par4=20 par5=400 Detector: detector_I=5e6
* %Example: model_index=3 Ncount=1e6 par1=220 par2=0.06 par3=40 par4=4 par5=1 Detector: detector_I=3.3e4
* %Example: model_index=47 Ncount=1e6 par1=4 par2=2 par3=35 par4=75 par5=400 Detector: detector_I=2.5e6
*
* %Parameters
* lambda: [AA]   Mean wavelength of neutrons
* dlambda: [AA]  Wavelength spread of neutrons
* 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
*
* %Link
* %End
*******************************************************************************/
DEFINE INSTRUMENT templateSasView(lambda=6, dlambda=0.05, model_index=47, par1=0, par2=0, par3=0, par4=0, par5=0, par6=0, par7=0, par8=0, Ncount=0)

DECLARE %{
%}

INITIALIZE %{

  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_simple(
    radius = 0.02, dist = 3, focus_xw = 0.01, focus_yh = 0.01,
    lambda0 = lambda, dlambda = dlambda, flux = 1e8)
  AT (0, 0, 0) RELATIVE arm

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

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

SPLIT COMPONENT sample = Arm()
  AT (0, 0, 0.2) 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", xmin = -0.3,
    xmax = 0.3, ymin = -0.3, ymax = 0.3)
  AT (0, 0, 3) RELATIVE sample

COMPONENT Ldetector = L_monitor(
    nL = 1000, filename = "Edet.dat", xmin = -0.3,
    xmax = 0.3, ymin = -0.3, ymax = 0.3, Lmin = 5.5,
    Lmax = 6.5)
  AT (0, 0, 3.01) RELATIVE sample

COMPONENT PSDrad = PSD_monitor_rad(
    filename = "psd2.dat", filename_av = "psd2_av.dat", rmax = 0.3)
  AT (0, 0, 3.02) RELATIVE sample

END
