/*******************************************************************************
*         McXtrace instrument definition URL=http://www.mcxtrace.org
*
* Instrument: ESRF_BM29
*
* %Identification
* Written by: Martin Cramer Pedersen (mcpe@nbi.dk)
* Date: October 28th, 2021
* Version: $Revision$
* Origin: KU-Science
* Release: McXtrace 1.0
* %INSTRUMENT_SITE: ESRF
*
* A simple BM29 model at ESRF.
*
* %Description
* Toy model used for testing various sample components for solution-SAXS 
* mimicking the geometry of the BM29 beamline at ESRF:
* https://www.esrf.fr/home/UsersAndScience/Experiments/MX/About_our_beamlines/bm29/beamline-specifications.html
* 
* Note that this model does not include much of the beamline optics, instead it emulates their effect
* by settgin relevant beam parameters from a model source.
*
* %Example: ESRF_BM29.instr Lambda=1 Detector: QMonitor_I=5.2e-12 
*
* %Parameters
* DistanceFromSourceToFirstPinhole: [m]    Distance to first pinhole from source.
* DistanceFromSourceToSecondPinhole: [m]   Distance to second pinhole - used for focussing rays.
* DistanceFromSecondPinholeToSample: [m]   Collimation length.
* DistanceFromSampleToDetector: [m]        Sample-detector-distance.
* RadiusOfDetector: [m]                   Radius of the circular detector.
* Lambda: [AA]                             Wavelength of the rays emitted from source.
* DLambda: []                              Relative deviation of wavelength of the rays emitted from source.
*
* %End
*******************************************************************************/

DEFINE INSTRUMENT ESRF_BM29(
	DistanceFromSourceToFirstPinhole = 31.4,
	DistanceFromSourceToSecondPinhole = 42.5,
	DistanceFromSecondPinholeToSample = 0.1,
	DistanceFromSampleToDetector = 2.43,
	RadiusOfDetector = 0.18,
	Lambda = 1.00,
	DLambda = 0.01
)


DECLARE
%{
%}


INITIALIZE
%{
%}


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


COMPONENT Source = Source_flat(
	xwidth = 0.001,
	yheight = 0.001,
	dist = DistanceFromSourceToSecondPinhole, 
	focus_yh = 0.0007, 
	focus_xw = 0.0007,
	lambda0 = Lambda, 
	dlambda = DLambda * Lambda
)
AT (0, 0, 0) RELATIVE Origin


COMPONENT FirstPinhole = Slit(
	xwidth = 0.0007,
	yheight = 0.0007
)
AT (0, 0, DistanceFromSourceToFirstPinhole) RELATIVE Source


COMPONENT SecondPinhole = Slit(
	xwidth = 0.0007,
	yheight = 0.0007
)
AT (0, 0, DistanceFromSourceToSecondPinhole) RELATIVE Source


COMPONENT Sample = SAXSSpheres(
	xwidth = 0.01,
	yheight = 0.01, 
	zdepth = 0.01,
	R = 50.0,
	SampleToDetectorDistance = DistanceFromSampleToDetector,
	DetectorRadius = RadiusOfDetector
)
AT(0, 0, DistanceFromSampleToDetector) RELATIVE SecondPinhole


COMPONENT Beamstop = Beamstop(
	radius = 0.001
)
AT (0, 0, DistanceFromSampleToDetector - 0.000001) RELATIVE Sample


COMPONENT QMonitor = SAXSQMonitor(
	RadiusDetector = RadiusOfDetector,
	DistanceFromSample = DistanceFromSampleToDetector,
	LambdaMin = Lambda,
	Lambda0 = Lambda,
	NumberOfBins = 1000	
)
AT (0, 0, 0.000001) RELATIVE Beamstop


FINALLY
%{
%}

END

