/*******************************************************************************
*         McStas instrument definition URL=http://www.mcstas.org
*
* Instrument: Union_NCrystal_example
*
* %Identification
* Written by: T. Kittelmann, X. X. Cai, Mads Bertelsen
* Date: 2020
* Origin: ESS
* %INSTRUMENT_SITE: NCrystal
*
* Example instrument for use of NCrystal in Union.
*
* %Description
* This instrument examplifies how NCrystal may be used in Union
* constructions. It is adopted from NCrystal_example.instr where both
* monochromator and samples are described via NCrystal_sample components. Here,
* they are both described via Union components.
*
* %Test: Detector: powder_pattern_detc_I=1.55e-10
*
* %Parameters
*
* %Link
* https://github.com/mctools/ncrystal/wiki/
*
* %End
*******************************************************************************/
DEFINE INSTRUMENT Union_NCrystal_example()

TRACE

COMPONENT init = Union_init()
AT (0,0,0) ABSOLUTE

// A complete NCrystal-backed Union material can be declared directly from its
// configuration string. Absorption is read from the same configuration.
//
COMPONENT NCrystal_mono_material = Union_NCrystal_material(
    cfg = "Ge_sg227.ncmat;dir1=@crys_hkl:5,1,1@lab:0,0,1;dir2=@crys_hkl:0,1,-1@lab:0,1,0;incoh_elas=0;inelas=0;mos=0.3deg;sans=0"
)
AT (0,0,0) ABSOLUTE

COMPONENT NCrystal_sample_material = Union_NCrystal_material(
    cfg = "Y2O3_sg206_Yttrium_Oxide.ncmat;density=0.6x",
    include_SLD = 1
)
AT (0,0,0) ABSOLUTE

COMPONENT origin = Progress_bar()
  AT (0, 0, 0) RELATIVE ABSOLUTE

COMPONENT source =   Source_div(lambda0=1.539739, dlambda=0.01, xwidth=0.001, yheight=0.001, focus_aw=1, focus_ah=1)
  AT (0, 0, 0.3) RELATIVE origin

COMPONENT mono_arm = Arm()
  AT (0, 0, 0.5) RELATIVE source ROTATED (0, 45 , 0) RELATIVE source

COMPONENT monochromator = Union_box(xwidth=0.05,yheight=0.05,zdepth=0.003, priority=1, material_string="NCrystal_mono_material", p_interact=0.2)
  AT (0, 0, 0) RELATIVE mono_arm

COMPONENT master1 = Union_master()
AT (0, 0, 0) RELATIVE mono_arm

COMPONENT mono_out = Arm()
  AT (0, 0, 0) RELATIVE mono_arm ROTATED (0, -90, 0) RELATIVE source

COMPONENT powder_sample = Union_cylinder(yheight=0.01, radius=0.01, priority=1, material_string="NCrystal_sample_material")
AT (0, 0, 0.4) RELATIVE mono_out

COMPONENT master2 = Union_master()
AT (0, 0, 0) RELATIVE powder_sample

COMPONENT powder_pattern_detc = Monitor_nD(
    options = "banana, angle limits=[10 170], bins=500",
    radius = 0.05, yheight = 0.1)
  AT (0, 0, 0) RELATIVE powder_sample

COMPONENT stop = Union_stop()
AT (0,0,0) ABSOLUTE

END
