/*******************************************************************************
* Instrument: Test_RNG_randvec_target_rect_angular
*
* %I
* Written by: Peter Willendrup
* Date: Oct 2nd, 2020
* Origin: DTU
* %INSTRUMENT_SITE: Tests_RNG
*
* Instrument to get basic test output from random number generator.
*
* %D
* Instrument to get basic test output from random number generator.
* 
* The instrument generates 2 randon numbers pr. particle using randpm1(),
* encoded into the particle x and y coordinates.
*
* For a low statistics, one may e.g. check that setting the seed gives
* varied output or fixing the seed gives fixed output·
*
* %Example: Ncount=1000000 Detector: Div_I=1
*
* %P
* Ncount:  [1] Specify statistics
* seed:    [1] Specify RNG seed
* dist:    [m] Distance between synthetic point-source and monitor
* angle: [deg] Angular focusing settin 
*
* %L
* <reference/HTML link>
*
* %E
*******************************************************************************/
DEFINE INSTRUMENT Test_RNG_randvec_target_rect_angular(Ncount=1000000,int seed=0, angle=45)

DECLARE
%{
  double p0;
  #pragma acc declare create(p0)
  double Angle;
  #pragma acc declare create(Angle)
%}

INITIALIZE
%{
  mcset_ncount(Ncount);
  if (seed) mcseed = seed;
  p0=1.0/mcget_ncount();
  #pragma acc update device(p0)
  Angle=angle;
  #pragma acc update device(Angle)
%}

TRACE

COMPONENT Arm = Arm()
  AT (0,0,0) ABSOLUTE
EXTEND %{
  randvec_target_rect_angular(&vx, &vy, &vz, NULL, 0, 0, 1, Angle*DEG2RAD, Angle*DEG2RAD, ROT_A_CURRENT_COMP);
  NORM(vx,vy,vz);
  vx *= 1000;
  vy *= 1000;
  vz *= 1000;
  p = p0;
%}

  COMPONENT Div = Divergence_monitor(xwidth=100.0, yheight=100.0, filename="rngout", maxdiv_h=1.1*(angle/2), maxdiv_v=1.1*(angle/2), nh=100,nv=100)
  AT (0,0,0.01) RELATIVE Arm

FINALLY
%{
%}

END
