/*******************************************************************************
*         McXtrace instrument definition URL=http://www.mcxtrace.org
*
* Instrument: JJ_SAXS (rename also the example and DEFINE lines below)
*
* %Identification
* Written by: Erik Knudsen (erkn@risoe.dtu.dk)
* Date: September 24th, 2009
* Origin: Ris&oslash; DTU, (Finnair flight AY67 to Hong Kong)
* Release: McXtrace
* Version: 0.1_alpha
* %INSTRUMENT_SITE: SAXSLAB
*
* Crude model of a laboratory SAXS-instrument mimicking the type sold by SAXSlab/JJ-Xray Systems.
*
* %Description
* This is a very sketchy model of a SAXS-system, related to the old design of JJ X-ray systems. 
* It has been superseeded by the SAXS_saxslab model. 
* Limitations include:
* - Focusing only in 1 direction.
* - iNo reflectivity coating is implemented.
*
* %Parameters
* pin2_pos: [m] distance between 1st and 2nd pinhole in beam tube
* pin3_pos: [m] distance between 2nd and 3rd pinhole in beam tube
* optic_L:  [m] length of the focusing optic
* sample_pos:[m] distance from 3rd pinhole to sample
* detector_pos: [m] distance from 3rd pinhole to detector 
*
* %Example: pin2_pos=0.2 pin3_pos=0.4 optic_L=0.1 sample_pos=0.2 detector_pos=2 Detector: psd1_I=7.8629e-05 
*
* %End
*******************************************************************************/

DEFINE INSTRUMENT JJ_SAXS(pin2_pos=0.2, pin3_pos=0.4, optic_L=0.1, sample_pos=0.2, detector_pos=2)

DECLARE
%{
%}

INITIALIZE
%{
%}

TRACE

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

COMPONENT apparent_source=Source_flat(
    xwidth=8e-3,yheight=.04e-3,dist=0.1,focus_yh=0.001,focus_xw=0.01,lambda0=1.54,dlambda=0.1
)
AT (0,0,0) RELATIVE PREVIOUS

COMPONENT psd00=PSD_monitor(
    filename="psd00.dat",xwidth=0.2,yheight=0.2,restore_xray=1
)
  AT(0,0,0.0999) RELATIVE PREVIOUS

  COMPONENT optic_arm=Arm()
AT(0,0,0.1) RELATIVE apparent_source
ROTATED(0,0,-90) RELATIVE apparent_source

COMPONENT optic=Mirror_curved(
        radius=20,length=0.2, coating="", R0=1)
AT(0,0,0) RELATIVE optic_arm
ROTATED(0,2.75,0) RELATIVE optic_arm
EXTEND
%{
  if (!SCATTERED) ABSORB;
%}

COMPONENT beam_tube_axis=Arm()
AT(0,0,0.1) RELATIVE apparent_source
ROTATED (5.5,0,0) RELATIVE Origin

COMPONENT pinhole1=Slit(xwidth=0.1,yheight=0.1)
  AT(0,0,0.15) RELATIVE beam_tube_axis

COMPONENT psd01=PSD_monitor(
    filename="psd01.dat",xwidth=0.2,yheight=0.2,restore_xray=1
)
  AT(0,0,1e-3) RELATIVE PREVIOUS

COMPONENT pinhole2=Slit(xwidth=0.1,yheight=0.1)
  AT(0,0,pin2_pos) RELATIVE beam_tube_axis

/*COMPONENT psd02=PSD_monitor(
    filename="psd02.dat",xwidth=0.2,yheight=0.2
)
AT (0,0,1e-3) RELATIVE PREVIOUS 
*/
COMPONENT pinhole3=Slit(xwidth=0.1,yheight=0.1)
  AT(0,0,pin3_pos) RELATIVE beam_tube_axis
COMPONENT psd03=PSD_monitor(
    filename="psd02.dat",xwidth=0.2,yheight=0.2
)
AT (0,0,1e-3) RELATIVE PREVIOUS 

COMPONENT psd1=PSD_monitor(
    filename="psd1.dat",xwidth=0.4,yheight=0.4
)
AT (0,0,2) RELATIVE psd03 

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


