/******************************************************************************* * * McXtrace, X-ray tracing package * Copyright (C), All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Component: PSD_monitor_coh * * %I * Written by: Erik Knudsen * Date: March 13, 2010 * Origin: Risoe * Release: McXtrace 0.1 * * Position-sensitive monitor with phase intergration. * * %D * An (n times m) pixel PSD monitor taking phase into account. * As the i:th ray hits a pixel (j,k) in the monitor the intensity in that * pixel will be updated as a complex sum, i.e. $P_i = P_\left\{i-1\right\} + p_i exp\left\{-\phi_i\right\}$. * * By setting ratio<1 the effective pixel area becomes a * fraction of the ideal (which is to divide the xwidth and yheight intervals into nx and ny abutting * subintervals). This reduces the monitor effective area by ratio^2. * If the centering flag is set - the monitor will treat all rays as if they hit a pixel * center. This behaves as if ratio -> 0, but at no cost in statistics. * * Example: PSD_monitor_coh(xmin=-0.1, xmax=0.1, ymin=-0.1, ymax=0.1, nx=90, ny=90, filename="Output.psd") * * %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. * nx: [m] Number of pixel columns. * ny: [m] Number of pixel rows. * filename: [m] Name of file in which to store the detector images (the suffixes .abs and .arg will be added). * restore_xray: If set, the monitor does not influence the xray state. * ratio [ ] ratio between pixel area and effective pixel area. * centering [ ] Treat all rays as if they hit the center of the pixel. * nowritefile:  If set, monitor will skip writing to disk * * OUTPUT PARAMETERS: * * PSD_N: Array of xray event counts. * PSD_phi: Array of xray complex weight counts (the argument consituttes the phase). * PSD_p2: Array of second ms. * * %E *******************************************************************************/ DEFINE COMPONENT PSD_monitor_coh DEFINITION PARAMETERS () SETTING PARAMETERS (int nx=90, int ny=90, string filename="", restore_xray=0, xmin=-0.05, xmax=0.05, ymin=-0.05, ymax=0.05, xwidth=0, yheight=0, ratio=1, int centering=1, int nowritefile=0) OUTPUT PARAMETERS () /*STATE PARAMETERS (x,y,z,kx,ky,kz,phi,Ex,Ey,Ez,p)*/ SHARE %{ #include %} DECLARE %{ DArray2d PSD_N; DArray2d PSD_p2; DArray2d PSD_phi_real; DArray2d PSD_phi_imag; %} INITIALIZE %{ int i,j; if (xwidth > 0) { xmax = xwidth/2; xmin = -xmax; } if (yheight > 0) { ymax = yheight/2; ymin = -ymax; } if ((xmin >= xmax) || (ymin >= ymax)) { fprintf(stderr,"ERROR (%s): Null detection area! Aborting.\n",NAME_CURRENT_COMP); exit(-1); } PSD_N = create_darr2d(nx,ny); PSD_p2 = create_darr2d(nx,ny); PSD_phi_real = create_darr2d(nx,ny); PSD_phi_imag = create_darr2d(nx,ny); %} TRACE %{ int i,j; double k,x_o,y_o,z_o; double p2; double complex dphi; double dphi_r,dphi_i; x_o=x;y_o=y;z_o=z; k=sqrt(kx*kx+ky*ky+kz*kz); PROP_Z0; if (x>xmin && xymin && y