/*******************************************************************************
*         McXtrace instrument definition URL=http://www.mcxtrace.org
*
* Instrument: NSLS2_CHX
*
* %Identification
* Written by: Jana Baltser
* Date: March 2011
* Origin: NBI, BNL
* Release: McXtrace 1.0
* Version: 0.2
* %INSTRUMENT_SITE: NSLS2
*
* Coherent hard x-ray beamline @ NSLS II
* 
* %Description
* This is a lay-out of the coherent hard x-ray (CHX) beamline at NSLS-II.
* Since the ray-tracing method doesn't allow to account for partial coherence of the
* undulator source, the best approximation was to use the gaussian photon beam and to neglect
* diffraction effects on apertures.
* The choice of the source sizes along with angular divergence corresponds to the situation of 
* high emittance (e=0.99nm). 
*
* %Example: NSLS2_CHX -n1e6 L=33.5 L2=35.3 L3=44 Energy=10 Detector: Det_ff_I=2.82787e+16 
*
* %Parameters
* L: [m] Distance from the source to the SS1, secondary source aperture.
* L2: [m] Position of the CRL.
* L3: [m] Position of the Kinoform lens.
* Energy: [keV] primary energy used at the beamline.
*
* %End
*******************************************************************************/

DEFINE INSTRUMENT NSLS2_CHX(L=33.5,L2=35.3,L3=44,Energy=10)

DECLARE
%{
	const double source_h=43e-6;
	const double source_v=7e-6;
	const double div_h=22e-6;
	const double div_v=8.8e-6;
	
	const double slit_x=44e-6;
	const double slit_y=1e-3;
%}

INITIALIZE
%{
%}

TRACE

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

COMPONENT Source = Source_gaussian(sig_x=source_h,sig_y=source_v,sigPr_x=div_h,sigPr_y=div_v,E0=Energy,dE=0,dist=L,flux=4e18)
AT (0, 0, 0) RELATIVE Origin

   
COMPONENT Det=PSD_monitor(filename="psd.dat",xwidth=5e-3,yheight=5e-3,restore_xray=1,nx=200,ny=200)
AT (0,0,L) RELATIVE Origin

COMPONENT Slit=Slit(xwidth=slit_x,yheight=slit_y)
AT (0,0,10e-4) RELATIVE PREVIOUS

COMPONENT Det1=PSD_monitor(filename="psd1.dat",xwidth=.4e-3,yheight=2e-3,restore_xray=1,nx=200,ny=200)
AT (0,0,L2-1e-3) RELATIVE Origin
  
COMPONENT CRL=Lens_parab_Cyl(r=.5e-3,yheight=1e-3,xwidth=1e-3,d=.05e-3,N=9, material_datafile="Be.txt")
AT (0,0,L2) RELATIVE Origin

COMPONENT Det_f=PSD_monitor(filename="psd_f.dat",xwidth=.4e-3,yheight=.4e-3, restore_xray=1, nx=200, ny=200)
AT (0,0,43.98) RELATIVE Origin

COMPONENT Kinoform=Lens_parab_Cyl(r=.5e-3,yheight=1.3e-3,xwidth=1.3e-3,d=.1e-3,N=21, material_datafile="Be.txt")
AT (0,0,L3) RELATIVE Origin
ROTATED (0,0 ,90) RELATIVE Origin

COMPONENT Det_ff=PSD_monitor(filename="psd_ff.dat",xwidth=.08e-3,yheight=.08e-3, restore_xray=1, nx=200, ny=200)
AT (0,0,48.5) RELATIVE Origin

END
