/*******************************************************************************
* Instrument: ESS_butterfly_MCPL_test
*
* %I
* Written by: Peter Willendrup <pkwi@fysik.dtu.dk>
* Date: 2017-04
* Origin: DTU
* %INSTRUMENT_SITE: Tools
*
* Flexible histogramming instrument file for processing MCPL input files using Monitor_nD
*
* %D
* Flexible histogramming instrument file for processing MCPL input files using Monitor_nD.
*
* Example1: Multiple 1D histograms of position, velocity, divergence, time and wavelength, use
* NDoptions=1 defines options="previous, multiple, auto, x, y, z, vx, vy, vz, hdiv, vdiv, tof, lambda"
*
* Example2: 2D x-y plot of beam cross section:
* NDoptions=2 defines options="previous, auto, x, y"
*
* Example3: 2D TOF-lambda plot of beam:
* NDoptions=3 defines options="previous, auto, tof, lambda"
*
* %P
* MCPLfile:  [str] Defines the MCPL input file to process
* NDoptions: [int] Defines what Monitor_nD measures, see example list
*
* %L
* <reference/HTML link>
* MCPL website at <a href="https://mctools.github.io/mcpl/">https://mctools.github.io/mcpl/</a>
* %E
*******************************************************************************/
DEFINE INSTRUMENT MCPL2hist(string MCPLfile="my.mcpl.gz", int NDoptions=1)

DECLARE
%{
  char monopts[128];
%}

INITIALIZE
%{
  if (NDoptions == 1) {
    sprintf(monopts,"previous, multiple, auto, x, y, z, vx, vy, vz, hdiv, vdiv, tof, lambda");
  } else if (NDoptions == 2) {
    sprintf(monopts,"previous, auto, x, y");
  } else if (NDoptions == 3) {
    sprintf(monopts,"previous, auto, tof, lambda");
  } else {
    printf("\n%s: Warning: NDoptions=%i is undefined. Your MonitorND will likely give no output.\n\n", NAME_INSTRUMENT, NDoptions);
  }
  printf("\n%s: Running with Monitor_nD options \"%s\"\n\n", NAME_INSTRUMENT, monopts);
%}

TRACE

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

/* read neutrons from an mcpl file*/

COMPONENT MCPLinput = MCPL_input(filename=MCPLfile,verbose=1)
AT(0,0,0) RELATIVE PREVIOUS

COMPONENT MonND1 = Monitor_nD(options=monopts)
AT (0,0,0) RELATIVE PREVIOUS

FINALLY
%{
%}

END
