/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2008, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Component: Beamstop
*
* %ID
*
* Written by: Peter Willendrup
* Date: November 2008
* Origin: Risoe
*
* Box-shaped absorbing slab.
*
* %D
* Infinitely absorbing slab of material.
*
* Example: Absorber(xmin=-0.01, xmax=0.01, ymin=-0.05, ymax=0.05, zmin=-0.2, zmax=0)
*
* %P
* INPUT PARAMETERS
*
* xmin: [m]  Lower x bound 
* xmax: [m]  Upper x bound 
* ymin: [m]  Lower y bound 
* ymax: [m]  Upper y bound 
* zmin: [m]  Lower z bound 
* zmax: [m]  Upper z bound 
*
* %END
*******************************************************************************/

DEFINE COMPONENT Absorber
DEFINITION PARAMETERS ()
SETTING PARAMETERS (xmin=0, xmax=0, ymin=0, ymax=0, zmin=0, zmax=0)
OUTPUT PARAMETERS()

DECLARE
%{
  double xw;
  double yh;
  double zt;
  double xm;
  double ym;
  double zm;
%}

INITIALIZE
%{
  xw = xmax-xmin;
  yh = ymax-ymin;
  zt = zmax-zmin;
  xm = (xmax+xmin)/2;
  ym = (ymax+ymin)/2;
  zm = (zmax+zmin)/2;
  if (xw == 0 || yh == 0 || zt == 0)
    { fprintf(stderr,"Absorber: %s: Error: Slab volume is zero!\n", NAME_CURRENT_COMP); exit(-1); }
%}

TRACE
%{
  double t0,t1,xp,yp,zp;
  xp = x - xm;
  yp = y - ym;
  zp = z - zm;
  if (box_intersect(&t0, &t1, xp, yp, zp, vx, vy, vz, xw, yh, zt)) {
    if (t1>=0) {
      PROP_DT((t1+t0)/2);
      SCATTER;
      ABSORB;
    }
  }
%}

MCDISPLAY
%{
  
  box(xm, ym, zm, xw, yh, zt);
%}

END
