/*******************************************************************************
*         McStas instrument definition URL=http://www.mcstas.org
*
* Instrument: Test_PowderN_Res
*
* %Identification
* Written by: Peter Willendrup
* Date: 20160309
* Origin: DTU
* %INSTRUMENT_SITE: Tests_samples
*
* Idealized powder diffractometer, to illustrate the difference between 'banana,theta' and 'banana,divergence' in Monitor_nD.
*
* %Description
* Idealized powder diffractometer, to illustrate the difference between 'banana,theta' and 'banana,divergence' in Monitor_nD. Includes a Na2Ca3Al2F14 powder sample.
*
* The beam from the source is very low-divergent, to allow studying effects at the sample "only".
*
* By default, absorption in the sample is effectively suppressed.
*
* Example: Lambda0=2.5667 dLambda=0.01 radius=0.001,0.021 TT=71.8 D_PHI=6 SPLITS=117 Distance=30 sig_abs=1e-09 -N21
* %Example: Lambda0=2.5667 dLambda=0.01 radius=0.01 TT=71.8 D_PHI=6 SPLITS=117 Distance=30 sig_abs=1e-09 Detector: DetectorSmall_I=288.57
*
* %Parameters
* Lambda0: [AA]     Central wavelength of the source
* dLambda: [AA]     Width of wavelength band from the source
* radius: [m]       Radius of cylindrical powder sample
* TT: [deg]         Two-theta (scattering angle) of small banana detectors
* D_PHI: [deg]      d_phi focusing around detector "plane" in degrees
* SPLITS: [1]       SPLIT statistics booster at sample position
* Distance: [m]     Distance between source and sample
* sig_abs: [barns]  Absorption cross-section in the sample
*
* %Link
* A reference/HTML link for more information
*
* %End
*******************************************************************************/
DEFINE INSTRUMENT Test_PowderN_Res(Lambda0=2.5667,dLambda=0.01,radius=0.01,TT=72,D_PHI=6, SPLITS=117,Distance=30,sig_abs=1e-9)

/* The DECLARE section allows us to declare variables or  small      */
/* functions in C syntax. These may be used in the whole instrument. */
DECLARE
%{
%}

/* The INITIALIZE section is executed when the simulation starts     */
/* (C code). You may use them as component parameter values.         */
INITIALIZE
%{
%}

/* Here comes the TRACE section, where the actual      */
/* instrument is defined as a sequence of components.  */
TRACE

/* The Arm() class component defines reference points and orientations  */
/* in 3D space. Every component instance must have a unique name. Here, */
/* Origin is used. This Arm() component is set to define the origin of  */
/* our global coordinate system (AT (0,0,0) ABSOLUTE). It may be used   */
/* for further RELATIVE reference, Other useful keywords are : ROTATED  */
/* EXTEND GROUP PREVIOUS. Also think about adding a neutron source !    */
/* Progress_bar is an Arm displaying simulation progress.               */
COMPONENT Origin = Progress_bar()
  AT (0,0,0) ABSOLUTE


COMPONENT Source = Source_div(
    xwidth = 2.01*radius, yheight = 0.1, focus_aw = 1e-3,
    focus_ah = 1e-3, lambda0 = Lambda0, dlambda = dLambda, flux = 1e16)
  AT (0, 0, 0) RELATIVE PREVIOUS

// COMPONENT Source = Source_simple(
//     radius = 0.1, dist = 10, focus_xw = 2.1*radius, focus_yh = 0.1,
//     lambda0 = Lambda0, dlambda = dLambda, flux = 1e16, gauss = 1,
//     dist=Distance)
//   AT (0, 0, 0) RELATIVE PREVIOUS

COMPONENT SampleSlit = Slit (xwidth=2.1*radius,yheight=0.1)
AT (0,0,0.89*Distance) RELATIVE PREVIOUS

SPLIT SPLITS COMPONENT Sample = PowderN(
    reflections = "Na2Ca3Al2F14.laz", radius = radius,
    yheight = 0.1,d_phi=D_PHI,sigma_abs=sig_abs)
  AT (0, 0, Distance) RELATIVE Source
EXTEND %{
  if(!SCATTERED) ABSORB;
%}

COMPONENT Detector = Monitor_nD(
  xwidth=3.0, yheight=0.09, filename="detector.dat", min=19.9, max=99.9, bins=400, restore_neutron=1,
  options="banana, theta")
AT (0,0,0) RELATIVE Sample

COMPONENT DetectorSmall = Monitor_nD(
  xwidth=3.001, yheight=0.09, filename="detectorsmall.dat", min=TT-2, max=TT+2, bins=41,restore_neutron=1,
  options="banana, theta")
AT (0,0,0) RELATIVE Sample

COMPONENT DetectorSmallDiv = Monitor_nD(
  xwidth=3.001, yheight=0.09, filename="detectorsmall2.dat", min=TT-2, max=TT+2, bins=41,restore_neutron=1,
  options="banana, divergence")
AT (0,0,0) RELATIVE Sample

COMPONENT TwoTheta = Arm(
    )
  AT (0, 0, 0) RELATIVE Sample
  ROTATED (0, TT, 0) RELATIVE Sample


/* COMPONENT PSD = PSD_monitor(
    filename = "smallPSD", xwidth = 0.001, yheight = 0.1)
  AT (0, 0, 1.51) RELATIVE PREVIOUS */


/* This section is executed when the simulation ends (C code). Other    */
/* optional sections are : SAVE                                         */
FINALLY
%{
%}
/* The END token marks the instrument definition end */
END



