/*******************************************************************************
*         McStas instrument definition URL=http://www.mcstas.org
*
* Instrument: Tomography
*
* %Identification
* Written by: Peter Willendrup, based on work by Reynald ARNERIN
* Date: June 20th, 2008
* Origin: Risoe
* %INSTRUMENT_SITE: Templates
*
* Instrument to study tomographic imaging by means of the feature of OFF shape samples.
*
* %Description
* Instrument to study tomographic imaging by means of the feature of OFF shape samples.
*
* Example: mcrun Tomography.instr offfile=bunny.off -n1e4 -N18 omega=0,340 -d TomoScan
* (Note that to achieve proper statistics for tomographic reconstruction, MUCH higher ncounts
*  are needed)
*
* Use the provided Matlab tomo_recon.m function (requires imaging toolbox, PGPLOT output data
* and a Unix/Mac) in the tools/matlab folder to reconstruct a 3D volume of the object. Use e.g. 
* isosurface to do thresholding for extraction of the object surface.
*
* %Example: omega=0 Detector: monitor_I=2.23492e-09
*
* %Parameters
* geometry: [string]  Name of the OFF file describing the sample shape
* omega: [deg]        Sample rotation around y
* sigma_abs: [barn]   Sample absorption xs
* frac_scatt: [1]     Fraction of neutrons to scatter in the sample
* div_v: [deg]        Source vertical divergence (angular height)
* div_h: [deg]        Source horisontal divergence (angular width)
* source_w: [m]       Source width
* source_h: [m]       Source height
* det_w: [m]          Detector width
* det_h: [m]          Detector height
* opts: [string]      Monitor_nD options string
*
* %Link
* http://shape.cs.princeton.edu/benchmark/documentation/off_format.html
*
* %End
*******************************************************************************/
DEFINE INSTRUMENT Tomography(string geometry="socket.off", omega=0, sigma_abs=100, frac_scatt=0, div_v=1e-4, div_h=1e-4, source_w=0.4, source_h=0.2, det_w=0.4, det_h=0.2, string opts="x bins=80 y bins=40")
DEPENDENCY " -DUSE_OFF "

TRACE

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

COMPONENT source = Source_div(xwidth = source_w, yheight = source_h, focus_aw=div_h, focus_ah=div_v, E0=14, dE=.5)
AT (0, 0, 0) RELATIVE Origin 

COMPONENT samplearm = Arm()
AT (0,0,1+0) RELATIVE Origin
ROTATED (0,omega,0) RELATIVE Origin

COMPONENT sample=Incoherent(p_interact = frac_scatt, geometry = geometry, yheight=0.1, sigma_abs=sigma_abs, focus_xw=det_w, focus_yh=det_h, target_index=1)
AT (0,0,0) RELATIVE samplearm 

COMPONENT monitor = Monitor_nD(xwidth=det_w,yheight=det_h,options=opts)
AT (0, 0, 2) RELATIVE source

END

