1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*******************************************************************************
*
* McXtrace, x-ray tracing package
* Copyright, All rights reserved
* DTU Physics, Kgs. Lyngby, Denmark
* Synchrotron SOLEIL, Saint-Aubin, France
*
* Component: E_monitor
*
* %Identification
* Written by: Erik Knudsen
* Based on neutron component written by Kristian Nielsen and Kim Lefmann
*
* Date: June 22, 2009
* Origin: Risoe
* Release: McXtrace 0.1
*
* Energy-sensitive monitor.
*
* %Description
* A square single monitor that measures the energy of the incoming x-rays.
*
* Example: E_monitor(xwidth=0.1, yheight=0.1,
* Emin=1, Emax=50, nE=20, filename="Output.nrj")
*
* %Parameters
* INPUT PARAMETERS:
*
* xwidth: [m] Width of detector.
* yheight: [m] Height of detector.
* Emin: [keV] Minimum energy to detect.
* Emax: [keV] Maximum energy to detect.
* nE: [m] Number of energy channels.
* filename: [str] Name of file in which to store the detector image.
* restore_xray: [0/1] If set, the monitor does not influence the x-ray state.
*
* CALCULATED PARAMETERS:
*
* E_N: Array of x-ray counts
* E_p: Array of x-ray weight counts
* E_p2: Array of second moments
*
* %End
*******************************************************************************/
DEFINE COMPONENT E_monitor
SETTING PARAMETERS (nE=20, string filename=0,
xwidth=0.1, yheight=0.1, Emin, Emax, restore_xray=0)
DECLARE
%{
DArray1d E_N;
DArray1d E_p;
DArray1d E_p2;
double xmin;
double xmax;
double ymin;
double ymax;
%}
INITIALIZE
%{
int i;
xmax = xwidth/2; xmin = -xmax;
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);
// Use instance name for monitor output if no input was given
if (!strcmp(filename,"\0")) sprintf(filename,"%s",NAME_CURRENT_COMP);
%}
TRACE
%{
int i;
double E;
PROP_Z0;
if (x>xmin && x<xmax && y>ymin && y<ymax)
{
E = K2E*sqrt(kx*kx + ky*ky + kz*kz);
i = floor((E-Emin)*nE/(Emax-Emin));
if(i >= 0 && i < nE)
{
#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] + p*p;
SCATTER;
}
}
if (restore_xray) {
RESTORE_XRAY(INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
}
%}
SAVE
%{
DETECTOR_OUT_1D(
"Energy monitor",
"Energy [keV]",
"Intensity",
"E", Emin, Emax, nE,
&E_N[0],&E_p[0],&E_p2[0],
filename);
%}
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
|