/*******************************************************************************
*         McXtrace instrument definition URL=http://www.mcxtrace.org
*
* Instrument: Test_Mirror_toroid
*
* %Identification
* Written by: Erik B Knudsen (erkn@fysik.dtu.dk)
* Date: Jul 16
* Origin: DTU Physics
* Version: 1.0
* %INSTRUMENT_SITE: Tests_optics
*
* Unit test instrument to check that Mirrror_toroid is working
*
* %Description
* A mere unit test instrument. Also includes a perfectly flat Mirror as reference.
*
* %Example: Test_Mirror_toroid.instr gamma=5 Detector: psd3_I=7.21499e-08
*
* %Parameters		
* gamma: [deg] Nominal glancing angle of mirror
* Tor: [0/1]   Uses a toroidal mirror (1) or a flat mirror (0).
*
* %End
*******************************************************************************/

/* Change name of instrument and input parameters with default values */
DEFINE INSTRUMENT Test_Mirror_toroid(gamma=5, Tor=1)

/* 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(
        radius = 1e-3, dist = 2, focus_xw = .5e-2, focus_yh = 1e-3, E0=12.5, dE=1, gauss=1)
  AT (0, 0, 0) RELATIVE Origin

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

COMPONENT mt = Mirror_toroid(
   radius=0.1, radius_o=20, xwidth=5e-2, zdepth=2e-1,R0=1
)
WHEN (Tor) AT(0,0,2) RELATIVE Origin
ROTATED (-gamma, 0, 0) RELATIVE Origin

COMPONENT mt2 = Mirror(
   xwidth=5e-2, zdepth=2e-1,R0=1 
)
WHEN (!Tor) AT(0,0,2) RELATIVE Origin
ROTATED (-gamma, 0, 0) RELATIVE Origin

COMPONENT a1 = Arm()
AT(0,0,0) RELATIVE mt
ROTATED (-gamma,0,0) RELATIVE mt

COMPONENT psd1 = COPY(psd0)(filename="psd1")
AT(0,0,1.001e-2) RELATIVE PREVIOUS


COMPONENT psd2 = COPY(psd0)(xwidth=2e-2, filename="psd2")
AT(0,0,1) RELATIVE PREVIOUS

COMPONENT psd3 = COPY(psd2)(filename="psd3")
AT(0,0,1) 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

