/*******************************************************************************
*         McXtrace instrument definition URL=http://www.mcxtrace.org
*
* Instrument: Test_Saxs_spheres 
*
* %Identification
* Written by: Your name (email)
* Date: Current Date
* Origin: Your institution
* Release: McXtrace 1.0
* Version: 0.2
* %INSTRUMENT_SITE: Tests_samples
*
* Test instrument for the Saxs_spheres sample component.
*
* Simply a model source illuminating a Saxs_spheres sample. 
* The spheres are nominally made from Be in non-absorbing solution. 
*
* %Example: Test_Saxs_spheres.instr -n1e6 RR=20 Detector: detector2_I=5.0956e-16 
*
* %Parameters
* RR: [AA] Radius of the dilute hard spheres. 
*
* %End
*******************************************************************************/

/* Change name of instrument and input parameters with default values */
DEFINE INSTRUMENT Test_Saxs_spheres(RR=100)

/* 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 an xray source !    */
/* Progress_bar is an Arm displaying simulation progress.               */
COMPONENT Origin = Progress_bar()
  AT (0,0,0) ABSOLUTE

COMPONENT src = Source_flat(
    yheight = 1e-3, xwidth = 1e-3, dist = 10, focus_xw = 1e-3,
    focus_yh = 1e-3, E0 = 12, dE = 1)
  AT (0, 0, 0) RELATIVE Origin

COMPONENT psd0 = PSD_monitor(
    nx = 100, ny = 100, filename = "psd0", xwidth = 2e-3,
    yheight = 2e-3)
  AT (0, 0, 1e-9) RELATIVE src

COMPONENT sample = Saxs_spheres(
    R = RR, Phi = 0.1, Delta_rho = 1.6,
    yheight = 1e-3, radius = 0.25e-3, focus_xw = 1,
    focus_yh = 1, sphere_mtrl="Be.txt")
  AT (0, 0, 10) RELATIVE PREVIOUS
EXTEND
%{
  if(!SCATTERED) ABSORB;
%}

COMPONENT psd4pi = PSD_monitor_4PI(
    nx = 180, ny = 180, filename = "psd4pi", radius = 0.1,
    restore_xray = 1)
  AT (0, 0, 0) RELATIVE sample


COMPONENT detector = PSD_monitor(
    nx=200, ny=200, xwidth=0.1, yheight=0.1, filename="psd1",restore_xray=1
)
AT(0,0,0.1) RELATIVE sample

COMPONENT detector2 = PSD_monitor(
    nx=200, ny=200, xwidth=2e-3, yheight=2e-3, filename="psd2",restore_xray=1
)
AT(0,0,0.1) RELATIVE sample

/* 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


