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
|
/*******************************************************************************
*
* McXtrace, x-ray tracing package
* Copyright, All rights reserved
* DTU Physics, Kgs. Lyngby, Denmark
* Synchrotron SOLEIL, Saint-Aubin, France
*
* Component: W_PSD_monitor
*
* %Identification
* Written by: Erik Knudsen
* Date: June 22, 2009
* Origin: Risoe
* Release: McXtrace 0.1
*
* Position-sensitive wattage monitor.
*
* %Description
* Based on neutron PSD component written by Kim Lefmann
* An n times m pixel PSD wattage monitor. This component may also be used as a beam
* detector.
*
* Example: W_psd_monitor(xwidth=0.1, yheight=0.1,
* nx=90, ny=90, filename="Output.psd")
*
* %Parameters
* INPUT PARAMETERS:
*
* xwidth: [m] Width of detector.
* yheight: [m] Height of detector.
* nx: [1] Number of pixel columns
* ny: [1] Number of pixel rows
* filename: [str] Name of file in which to store the detector image
* restore_xray: [1] If set, the monitor does not influence the xray state
*
* CALCULATED PARAMETERS:
*
* PSD_N: Array of xray counts
* PSD_W: Array of xray weight counts
* PSD_W2: Array of second moments
*
* %End
*******************************************************************************/
DEFINE COMPONENT W_psd_monitor
SETTING PARAMETERS (int nx=90, int ny=90, string filename=0, int restore_xray=0, xwidth=0.1, yheight=0.1)
DECLARE
%{
DArray2d PSD_N;
DArray2d PSD_W;
DArray2d PSD_W2;
double xmin;
double xmax;
double ymin;
double ymax;
%}
INITIALIZE
%{
int i,j;
xmax = xwidth/2; xmin = -xmax;
ymax = yheight/2; ymin = -ymax;
if ((xmin >= xmax) || (ymin >= ymax)) {
printf("PSD_monitor: %s: Null detection area !\n"
"ERROR (xwidth,yheight,xmin,xmax,ymin,ymax). Exiting",
NAME_CURRENT_COMP);
exit(0);
}
PSD_N = create_darr2d(nx, ny);
PSD_W = create_darr2d(nx, ny);
PSD_W2 = create_darr2d(nx, ny);
// Use instance name for monitor output if no input was given
if (!strcmp(filename,"\0")) sprintf(filename,"%s",NAME_CURRENT_COMP);
%}
TRACE
%{
int i,j;
double W1,W2;
PROP_Z0;
if (x>xmin && x<xmax && y>ymin && y<ymax)
{
i = floor((x - xmin)*nx/(xmax - xmin));
j = floor((y - ymin)*ny/(ymax - ymin));
double k=sqrt(scalar_prod(kx,ky,kz,kx,ky,kz));
#pragma acc atomic
PSD_N[i][j] += 1;
W1=p*k*K2E*1.6022e-16;
#pragma acc atomic
PSD_W[i][j] += W1;
W2=(p*k*K2E*1.6022e-16)*(p*k*K2E*1.6022e-16);
#pragma acc atomic
PSD_W2[i][j] += W2;
SCATTER;
}
if (restore_xray) {
RESTORE_XRAY(INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
}
%}
SAVE
%{
DETECTOR_OUT_2D(
"W_psd_monitor",
"X position [m]",
"Y position [m]",
xmin, xmax, ymin, ymax,
nx, ny,
&PSD_N[0][0],&PSD_W[0][0],&PSD_W2[0][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
|