/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2008, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Instrument: SANS_KWS2_AnySample
*
* %I
* Written by: Henrich Frielinghaus
* Date:       Sept 2004
* Origin:     FZ-Juelich/FRJ-2/IFF/KWS-2
* %INSTRUMENT_SITE: FZ_Juelich
*
* KWS2 SANS instrument at FZ-Juelich. 2 detectors. 4 available sample models.
*
* %D
*
* KWS2 SANS instrument at FZ-Juelich. Custom sample (None, Guinier, Debye or Any).
* Sample is at 40 m from source. 2 detectors.
*
* %Example: lambda=7 sample=0 Detector: detector_I=3450
* %Example: lambda=7 sample=1 Detector: detector_I=1182
* %Example: lambda=7 sample=2 Detector: detector_I=1751
* %Example: lambda=7 sample=3 Detector: detector_I=1249
*
* %P
* lambda: [AA] Mean wavelength of neutrons
* dlambda: [AA]  Wavelength spread of neutrons
* sample: [int] type of sample, as 0=None, 1='AnySample', 2='Debye' or 3='Guinier'
* Clen: [m] distance to collimation in 0-20. Sample is at 40 m from source
* Dlen: [m] distance from sample to detector
* NGblen: [m] collimation width/height
* FLUX: [n/s/cm2/st] incoming neutron flux
*
* %E
*******************************************************************************/

DEFINE INSTRUMENT SANS_KWS2_AnySample(lambda=7.0, dlambda=0.7, FLUX=1e8, NGblen=0.05, int sample=0, Clen = 10.0, Dlen = 10.0)

INITIALIZE
%{
  char sample_str[32];
  switch (sample) {
  case 1:
    strcpy(sample_str, "AnySample"); break;
  case 2:
    strcpy(sample_str, "Debye"); break;
  case 3:
    strcpy(sample_str, "Guinier"); break;
  default:
    strcpy(sample_str, "None"); break;
  }

  printf("SANS_KWS2_AnySample: sample is selected as %s\n", sample_str);
%}

TRACE

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


COMPONENT source = Source_simple(
    radius = 1.414*NGblen, focus_xw = NGblen, focus_yh = NGblen,
    lambda0 = lambda, dlambda = dlambda, flux = FLUX)
  AT (0, 0, 0) RELATIVE origin


COMPONENT guide = Guide(w1=NGblen, h1=NGblen, w2=NGblen, h2=NGblen, l=20.0,
                        R0=0.99, Qc=0.0219, alpha=6.07, m=2, W=0.003)
  AT (0, 0, Clen) RELATIVE source


COMPONENT Cguide= Guide(w1=NGblen, h1=NGblen, w2=NGblen, h2=NGblen, l=20.0-Clen,
                        R0=0.99, Qc=0.0219, alpha=6.07, m=2, W=0.003)
  AT (0, 0, 20) RELATIVE guide


COMPONENT SmpAp = Slit(xwidth=0.01, yheight=0.01)
  AT (0, 0, 19.95) RELATIVE Cguide

/* set of sample selected from instrument parameters */
COMPONENT sample = Arm()
   AT (0,0, 20.00) RELATIVE Cguide

COMPONENT sampleAS = SANS_AnySamp(transm=0.5, Rg=300, qmax=0.031416,
                               xwidth=0.02, yheight=0.02, zdepth=0.001)
   WHEN (sample == 1)
   AT (0,0,0) RELATIVE sample

COMPONENT sampleDS = SANS_DebyeS(transm=0.5, qDS=0.022,
                               xwidth=0.02, yheight=0.02, zdepth=0.001)
   WHEN (sample == 2)
   AT (0,0,0) RELATIVE sample

COMPONENT sampleGu = SANS_Guinier(transm=0.5, Rg=300, qmax=0.031416,
                               xwidth=0.02, yheight=0.02, zdepth=0.001)
   WHEN (sample == 3)
   AT (0,0,0) RELATIVE sample

/*COMPONENT Lmon = L_monitor(
    nL = 1000, filename = "Lmon.dat",    xwidth = 1.5*NGblen, yheight = 1.5*NGblen, Lmin = 4.5, Lmax = 12.5)
  AT (0, 0, Dlen-0.05) RELATIVE sample
*/

Component Bstop = Beamstop(xwidth=1.5*NGblen, yheight = 1.5*NGblen)
WHEN (sample)
  AT (0, 0, Dlen-0.005) RELATIVE sample

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

COMPONENT detector2 = PSD_monitor_rad(rmax=0.35, nr=500, filename="PSDr.dat", filename_av="PSDr_av.dat")
  AT (0, 0, 0.01) RELATIVE detector

END
