/*****************************************************************************
*         McStas instrument definition URL=http://www.mcstas.org
*
* Instrument: Test_Pol_Set
*
* %Identification
* Written by: Peter Christiansen
* Date: July 2006
* Origin: RISOE
* %INSTRUMENT_SITE: Tests_polarization
*
* Tests Set_pol, Incoherent, and pol monitors.
*
* %Description
*
* First check is that the randmly generated spin gives uniform (flat)
* distributions on all 3 pol monitor.
* Second check is that when the polarisation is hardcoded to (0, 1, 0)
* after Incoherent it is (0, -1/3, 0).
*
* %Example: Test_Pol_Set.instr Detector: polMonitor3_I=-0.333333
*
* %Parameters
*
* %Link
*
* %End
*******************************************************************************/

/* Change name of instrument and input parameters with default values */
DEFINE INSTRUMENT Test_Pol_Set()

/* 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_simple(
    radius = 0.01, dist = 1.0, focus_xw = 0.01, focus_yh = 0.01, lambda0 = 5,
    dlambda = 1, flux = 1)
  AT (0, 0, 0) RELATIVE Origin

COMPONENT polSetter1 = Set_pol(randomOn=1)
  AT (0,0,0) RELATIVE Origin

COMPONENT polMonitor1x =
Pol_monitor(xwidth=0.1, yheight=0.1,
	    mx=1, my=0, mz=0)
     AT (0, 0, 0.2) RELATIVE Origin

COMPONENT polMonitor1y =
Pol_monitor(xwidth=0.1, yheight=0.1,
	    mx=0, my=1, mz=0)
     AT (0, 0, 0.25) RELATIVE Origin

COMPONENT polMonitor1z =
Pol_monitor(xwidth=0.1, yheight=0.1,
	    mx=0, my=0, mz=1)
     AT (0, 0, 0.3) RELATIVE Origin

COMPONENT polSetter2 =
Set_pol(py=1)
     AT (0, 0, 0.5) RELATIVE Origin

COMPONENT polMonitor2 =
Pol_monitor(xwidth=0.1, yheight=0.1,
	    my=1)
     AT (0, 0, 0.75) RELATIVE Origin

COMPONENT armTarget = Arm()
  AT (0,0,1) RELATIVE Origin

COMPONENT vsample =
Incoherent(radius = 0.01, yheight = 0.1, sigma_abs = 0,
	 target_x=1.0, target_y=0, target_z=0,
	 focus_xw=0.01, focus_yh=0.01)
     AT (0, 0, 0) RELATIVE armTarget

COMPONENT armMonitor = Arm()
  AT (0,0,0) RELATIVE armTarget
  ROTATED (0, 90, 0) RELATIVE armTarget

COMPONENT polMonitor3 =
Pol_monitor(xwidth=0.1, yheight=0.1,
	    my=1)
     AT (0, 0, 0.25) RELATIVE armMonitor

FINALLY
%{
%}
/* The END token marks the instrument definition end */
END
