/*******************************************************************************
*         McStas instrument definition URL=http://www.mcstas.org
*
* Instrument: Union_NCrystal_mix_example
*
* %Identification
* Written by: T. Kittelmann, X. X. Cai, Mads Bertelsen
* Date: 2020
* Origin: ESS
* %INSTRUMENT_SITE: NCrystal
*
* Example instrument for use of NCrystal_sample as well as 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,
* the monochromator is described via a Union components, but the sample is still
* an NCrystal_sample component.
*
* %Test: Detector: powder_pattern_detc_I=1.53e-10
*
* %Parameters
*
* %Link
* https://github.com/mctools/ncrystal/wiki/
*
* %End
*******************************************************************************/
DEFINE INSTRUMENT Union_NCrystal_mix_example()

TRACE

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

// Keep the explicit process-plus-material form when combining NCrystal with
// other Union processes. The sample below uses the convenience material API.
//
// ncrystal_mcstasunion NCrystal_mono_material 'Ge_sg227.ncmat;mos=0.3deg;comp=bragg;dir1=@crys_hkl:5,1,1@lab:0,0,1;dir2=@crys_hkl:0,1,-1@lab:0,1,0'
//
COMPONENT NCrystal_mono_material_ncrystal_proc = NCrystal_process(
    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_mono_material = Union_make_material(
    process_string = "NCrystal_mono_material_ncrystal_proc",
    my_absorption = 9.72016247573315
)
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")
  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 NCrystal_sample_material = Union_NCrystal_material(
    cfg="Y2O3_sg206_Yttrium_Oxide.ncmat;density=0.6x")
AT (0,0,0) ABSOLUTE

/* Make a cylindrical sample of loosely packed Y2O3 powder. */
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
