/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2008, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Instrument: templateSANS
*
* %Identification
* Written by: <a href="mailto:kim.lefmann@risoe.dk">Kim Lefmann</a>
* Date: 19th Dec 2003.
* Origin: <a href="http://www.risoe.dk">Risoe</a>
* %INSTRUMENT_SITE: Mantid
*
* Test instrument for the Sans_spheres component. No guide / velocity selector
* etc. Will be developed further at later time.
*
* %Description
* Very simple test instrument for the Sans_spheres componen
*
* Modified to show a proof of concept method for storing a 'Mantid friendly' type of NeXus file.
*
* Needed steps:
* 1) Compile your instrument with NeXus library support
* 2) Generate an IDF using mcdisplay templateSANS_Mantid --format=Mantid -n0
* 3) mcrun templateSANS_Mantid -n1e6 --format=NeXus
*
* %Example: lambda=6 Detector: PSDrad_I=7.55196e+06
* %Example: lambda=6 --format=NeXus Detector: PSDrad_I=7.55196e+06
*
* %Parameters
* lambda: [AA]          Mean wavelength of neutrons
* dlambda: [AA]         Wavelength spread of neutrons
* r: [AA]               Radius of scattering hard spheres
* PHI: [1]              Particle volume fraction
* Delta_Rho: [fm/AA^3]  Excess scattering length density
* sigma_abs: [barns]    Absorption cross section at 2200 m/s
*
* %Link
*
* %End
*******************************************************************************/
DEFINE INSTRUMENT templateSANS_Mantid(lambda=6, dlambda=0.05, r=150, PHI=1e-3, Delta_Rho=0.6, sigma_abs=0.0)
DEPENDENCY " @NEXUSFLAGS@ "

DECLARE %{
%}

INITIALIZE %{
%}

TRACE

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

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

COMPONENT sourceMantid = Source_simple(
    radius = 0.02, dist = 3, focus_xw = 0.01, focus_yh = 0.01,
    lambda0 = lambda, dlambda = dlambda, flux = 1e16)
  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

COMPONENT LdetectorPRE = L_monitor(
    nL = 1000, filename = "Edet0.dat", xmin = -0.3,
    xmax = 0.3, ymin = -0.3, ymax = 0.3, Lmin = 5.5,
    Lmax = 6.5)
AT (0,0,0.05) RELATIVE coll2


SPLIT COMPONENT sampleMantid = Sans_spheres(
  R=r, Phi=PHI, Delta_rho=Delta_Rho, sigma_abs=sigma_abs,
  xwidth=0.01, yheight=0.01, zdepth=0.005)
   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 sampleMantid

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 sampleMantid


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

COMPONENT nD_Mantid_1 = Monitor_nD(
    options ="mantid square x limits=[-0.3 0.3] bins=128 y limits=[-0.3 0.3] bins=128, neutron pixel min=0 t, list all neutrons",
    xmin = -0.3,
    xmax = 0.3,
    ymin = -0.3,
    ymax = 0.3,
    restore_neutron = 1,
    filename = "bank01_events.dat")
  AT (0, 0, 3.2) RELATIVE sampleMantid

END
