/******************************************************************************* * * McStas, neutron ray-tracing package * Copyright (C) 1997-2006, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Component: TOF2E_monitor * * %I * Written by: Kim Lefmann and Helmuth Schoeber * Date: Sept. 13, 2006 * Origin: Risoe * * TOF-sensitive monitor, converting to energy * * %D * A square single monitor that measures the energy of the incoming neutrons * from their time-of-flight * * Example: TOF2E_monitor(xmin=-0.1, xmax=0.1, ymin=-0.1, ymax=0.1, Emin=1, Emax=50, nE=20, filename="Output.nrj", L_flight=20, T_zero=0) * * %P * INPUT PARAMETERS: * * xmin: [m] Lower x bound of detector opening * xmax: [m] Upper x bound of detector opening * ymin: [m] Lower y bound of detector opening * ymax: [m] Upper y bound of detector opening * xwidth: [m] Width of detector. Overrides xmin, xmax * yheight: [m] Height of detector. Overrides ymin, ymax * Emin: [meV] Minimum energy to detect * Emax: [meV] Maximum energy to detect * nE: [1] Number of energy channels * filename: [string] Name of file in which to store the detector image * T_zero: [s] Zero point in time * L_flight: [m] flight length user in conversion * restore_neutron: [1] If set, the monitor does not influence the neutron state * nowritefile: [1] If set, monitor will skip writing to disk * * OUTPUT PARAMETERS: * * E_N: [] Array of neutron counts * E_p: [] Array of neutron weight counts * E_p2: [] Array of second moments * S_p: [] Sum of neutron weight counts * S_pE: [] Sum of weighted energies * S_pE2: [] Sum of weighted energy squared * * %E *******************************************************************************/ DEFINE COMPONENT TOF2E_monitor DEFINITION PARAMETERS () SETTING PARAMETERS (nE=20, string filename=0, int nowritefile=0, xmin=-0.05, xmax=0.05, ymin=-0.05, ymax=0.05, xwidth=0, yheight=0, Emin, Emax, T_zero, L_flight, restore_neutron=0) OUTPUT PARAMETERS () /* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */ DECLARE %{ DArray1d E_N; DArray1d E_p; DArray1d E_p2; double S_p; double S_pE; double S_pE2; %} INITIALIZE %{ int i; if (xwidth > 0) { xmax = xwidth/2; xmin = -xmax; } if (yheight > 0) { ymax = yheight/2; ymin = -ymax; } if ((xmin >= xmax) || (ymin >= ymax)) { printf("E_monitor: %s: Null detection area !\n" "ERROR (xwidth,yheight,xmin,xmax,ymin,ymax). Exiting", NAME_CURRENT_COMP); exit(0); } E_N = create_darr1d(nE); E_p = create_darr1d(nE); E_p2 = create_darr1d(nE); for (i=0; ixmin && xymin && y= 0 && i < nE) { double p2 = p*p; #pragma acc atomic E_N[i] = E_N[i]+1; #pragma acc atomic E_p[i] = E_p[i]+p; #pragma acc atomic E_p2[i] = E_p2[i]+p2; SCATTER; } } if (restore_neutron) { RESTORE_NEUTRON(INDEX_CURRENT_COMP, x, y, z, vx, vy, vz, t, sx, sy, sz, p); } %} SAVE %{ if (!nowritefile) { DETECTOR_OUT_1D( "TOF-to-Energy monitor", "Energy [meV]", "Intensity", "E", Emin, Emax, nE, &E_N[0],&E_p[0],&E_p2[0], filename); if (S_p) printf(" : %g meV , E-width : %g meV \n", S_pE/S_p,sqrt(S_pE2/S_p - S_pE*S_pE/(S_p*S_p)) ); } %} FINALLY %{ destroy_darr1d(E_N); destroy_darr1d(E_p); destroy_darr1d(E_p2); %} MCDISPLAY %{ multiline(5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin, (double)ymin, 0.0); %} END