/*******************************************************************************
*         McStas instrument definition URL=http://www.mcstas.org
*
* Instrument: Test_Collimator_Radial
*
* %Identification
* Written by: E. Farhi [farhi@ill.fr]
* Date: Sept 1st, 2008
* Origin: ILL
* %INSTRUMENT_SITE: Tests_optics
*
* Cross comparison of radial collimator components
*
* %Description
* Cross comparison of radial collimator components, using McStas and
* contributed components. It shows that all implementations are equivalent.
* The Exact_radial_coll contributed component also takes into account the absorbing
* blade thickness between slits, which decreases slightly intensity.
*
* %Example: Collimator=1 Detector: BananaTheta_I=1.52649e-08
* %Example: Collimator=2 Detector: BananaTheta_I=1.41509e-08
* %Example: Collimator=3 Detector: BananaTheta_I=1.581e-08
*
* %Parameters
* Collimator: [1]  Choice of radial collimator component to test, with 1=Collimator_Radial, 2=Collimator_ROC, 3=Exact_radial_coll.
* Powder: [string] Reflection list for powder-sample
*
* %End
*******************************************************************************/
DEFINE INSTRUMENT Test_Collimator_Radial(int Collimator=1, string Powder="Na2Ca3Al2F14.laz")

INITIALIZE
%{
  printf("\nTest_Collimator_Radial: ");
  switch (Collimator) {
  case 1:
    printf("Using Collimator_Radial\n"); break;
  case 2:
    printf("Using Collimator_ROC\n"); break;
  case 3:
    printf("Using Exact_radial_coll\n"); break;
  }
%}

TRACE

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

COMPONENT Source = Source_gen(
   focus_xw = 0.006, focus_yh = 0.01, lambda0 = 1.5, dlambda = 0.01,
   yheight = 0.05, xwidth = 0.05)
  AT (0, 0, 0) RELATIVE PREVIOUS

COMPONENT Monitor1_xt = Monitor_nD(
    options = "x y", xwidth = 0.05, yheight = 0.05)
  AT (0, 0, 1) RELATIVE PREVIOUS

COMPONENT Sample = PowderN(
  reflections = Powder, radius = 0.0030,
  p_transmit=0.1, p_inc=0.05,
  yheight = 0.01, d_phi=RAD2DEG*atan2(0.09,1.5))
AT (0, 0, 0.1) RELATIVE PREVIOUS
EXTEND %{
  if (!SCATTERED) ABSORB;
%}

COMPONENT BananaThetaIn = Monitor_nD(
  options = "banana, angle limits=[2 160], bins=1280", restore_neutron=1,
  radius = 0.3, yheight = 0.09)
AT (0, 0, 0) RELATIVE Sample

COMPONENT collimador_rad = Collimator_radial(
  nslit=ceil((130-2)/0.42),
  radius=0.324, length=0.419-0.324, yheight=0.09,
  theta_min=-160, theta_max=160, roc=0)
  WHEN (Collimator==1)
AT (0, 0, 0) RELATIVE Sample

COMPONENT collimador_d20 = Collimator_ROC(
  ROC_pitch=0.42, ROC_ri=0.324, ROC_ro=0.419, ROC_h=0.09,
  ROC_ttmin=-160, ROC_ttmax=160, ROC_sign=-1)
  WHEN (Collimator==2)
AT (0, 0, 0) RELATIVE Sample

COMPONENT collimador_contrib = Exact_radial_coll(
  nslit=ceil(130-2/0.42), radius=0.324, length=0.419-0.324, h_in=0.09, h_out=0.09,
  theta_min=-160, theta_max=160)
  WHEN (Collimator==3)
AT (0, 0, 0) RELATIVE Sample

/* perfect detector: 1D(theta). Se ha modificado los limites. Originalm ~ [-4 -130]*/
COMPONENT BananaTheta = Monitor_nD(
  options = "banana, angle limits=[2 160], bins=1280",
  radius = 1.5, yheight = 0.09)
AT (0, 0, 0) RELATIVE Sample

END
