/*******************************************************************************
* Instrument: Test_RNG_randtriangle
*
* %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: PSD_I=1.0
*
* %P
* Ncount: [1] Specify statistics
* seed:   [1] Specify RNG seed
*
* %L
* <reference/HTML link>
*
* %E
*******************************************************************************/
DEFINE INSTRUMENT Test_RNG_randtriangle(Ncount=1000000,int seed=0)

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

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

TRACE

COMPONENT Arm = Arm()
  AT (0,0,0) ABSOLUTE
EXTEND %{
  // position x in one of 100 bins
  x = 0.9*randtriangle();
  y = 0.9*randtriangle();
  p = p0;
  vz=1000;
%}

COMPONENT PSD = PSD_monitor(xwidth=2.0, yheight=2.0, filename="rngout", nx=1000, ny=1000)
  AT (0,0,0) ABSOLUTE

FINALLY
%{
%}

END
