/******************************************************************************* * * 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 * Version: $Revision$ * Origin: Risoe * * 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 (nx=90, ny=90) SETTING PARAMETERS (string filename=0, 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 (PSD_N, PSD_p2,PSD_phi) /*STATE PARAMETERS (x,y,z,kx,ky,kz,phi,Ex,Ey,Ez,p)*/ DECLARE %{ #include double **PSD_N; double complex **PSD_phi; double **PSD_p2; %} INITIALIZE %{ int i,j; double *p1,*p2; double complex *p3; 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); } p1=calloc(nx*ny,sizeof(double)); p2=calloc(nx*ny,sizeof(double)); p3=calloc(nx*ny,sizeof(double complex)); PSD_N=calloc(nx,sizeof(double *)); PSD_p2=calloc(nx,sizeof(double *)); PSD_phi=calloc(nx,sizeof(double complex *)); for (i=0; ixmin && xymin && y