/******************************************************************************* * * McXtrace, X-ray tracing package * Copyright (C), All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * Copenhagen Univeristy, Copenhagen, Denmark * * Component: Phi_monitor * * %I * Written by: Erik B Knudsen * * Date: June, 2019 * Version: $Revision$ * Origin: DTU Physics * * Phase-sensitive monitor. * * %D * A square single monitor that measures the phase of the incoming x-rays. The phase is measured * mod 2*pi in the range 0 to 2*pi. * * Example: Phi_monitor(xmin=-0.1, xmax=0.1, ymin=-0.1, ymax=0.1,nPhi=20, filename="Output.dat") * * %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. * Phimin: [1] Minimum phase to detect. * Phimax: [1] Maximum phase to detect * nPhi: [1] Number of phase bins * filename: [1] Name of file in which to store the data * restore_xray: [1] If set, the monitor does not influence the xray state * nowritefile: [1] If set, monitor will skip writing to disk * * OUTPUT PARAMETERS: * * Phi_N: Array of x.ray counts * Phi_p: Array of x-ray weight counts * Phi_p2: Array of second moments * * %E *******************************************************************************/ DEFINE COMPONENT Phi_monitor DEFINITION PARAMETERS (nPhi=20, string filename=0) SETTING PARAMETERS (xmin=-0.05, xmax=0.05, ymin=-0.05, ymax=0.05, xwidth=0, yheight=0, Phimin=0, Phimax=2*M_PI, restore_xray=0, int nowritefile=0) OUTPUT PARAMETERS (Phi_N, Phi_p, Phi_p2) /* X-ray parameters: (x,y,z,kx,ky,kz,phi,t,Ex,Ey,Ez,p) */ DECLARE %{ double Phi_N[nPhi]; double Phi_p[nPhi], Phi_p2[nPhi]; %} INITIALIZE %{ int i; 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); } if (Phimin<0){ fprintf(stderr,"WARNING (%s): Lower bound <0. Phase is in the interval [0,2*pi].\n",NAME_CURRENT_COMP); } if (Phimax<0){ fprintf(stderr,"WARNING (%s): Upper bound > 2*pi. Phase is in the interval [0,2*pi].\n",NAME_CURRENT_COMP); } for (i=0; ixmin && xymin && y= 0 && i < nPhi) { Phi_N[i]++; Phi_p[i] += p; Phi_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 %{ if(!nowritefile){ DETECTOR_OUT_1D( "Phase monitor", "Phase [ ]", "Intensity", "Phi", Phimin, Phimax, nPhi, &Phi_N[0],&Phi_p[0],&Phi_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