/******************************************************************************* * * McXtrace, X-ray tracing package * Copyright, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * University of Copenhagen, Copenhagen, Denmark * * Component: Chopper_simple * * %I * * Written by; Erik Knudsen * Date: August 2011 * Origin: Risoe * * Ideal chopper * * %D * Ideal model of a chopper situated at Z=0. If a photon arrives at the chopper plane * at a time of t = [t0 +-n*T: t0 +-n*T +tau], where T is the period of the chopper, t0 the initial delay * and tau the opening time of the chopper, it is left untouched - otherwise it is ABSORBed. * If on a continous source the isfirst parameter may be used. In this case the photon time is _defined_ * by the chopper. In other words no photons are absorbed, the photon time is merely sampled within the chopper window. * t_rise is the rise-time of the chopper opening giving a trapezoidal shape. * Limitations: this component does not take chopper geometry into account. If isfirst only samples in the first chopper opening window. * * * %P * Input parameters: * t0: [s] Initial delay of the opening time * T: [s] Period of the chopper * tau: [s] Opening time of the chopper * t_rise: [s] Rise time of the chopper pulse. * xwidth:[m] height of the chopper opening * yheight:[m] width of the chopeper opening * isfirst: [ ] is the chopper the first chopper on a continous source. * tjit: [ ] Timing jitter in terms of the opening time tau. For each ray the opening window will be shifted by a random amount within t=[-tjit*.5*tau,tjit*.5*tau] * * %E *******************************************************************************/ DEFINE COMPONENT Chopper_simple DEFINITION PARAMETERS () SETTING PARAMETERS (t0=0,T=1,tau=0.1,xwidth=0.1,yheight=0.1,isfirst=0,t_rise=0, tjit=0) OUTPUT PARAMETERS ( ) /*X-ray PARAMETERS (x,y,z,kx,ky,kz,phi,t,Ex,Ey,Ez,p)*/ INITIALIZE %{ if (T<=0 || tau<=0){ fprintf(stderr,"Error: (%s): Periodm T=%g <=0 or opening time, tau=%g <=0\n",NAME_CURRENT_COMP,T,tau); exit(-1); } if(xwidth<=0 || yheight<=0){ fprintf(stderr,"Error: (%s): Opening area (xwidth x yheight) = (%g x %g) <=0\n",NAME_CURRENT_COMP,xwidth,yheight); exit(-1); } %} TRACE %{ double tjitter=0; PROP_Z0; if(tjit) tjitter = (rand01()-0.5)*tau*tjit; if ( fabs(x)tau ){ p*=(1-t_rise)/t_rise; } t+=t0; } }else{ int n=(int) floor((t-t0)/T); if(t-(t0+n*T+tjitter)>tau){ ABSORB; } } }else{ ABSORB; } %} MCDISPLAY %{ /*chopper is symbolically shown as a disc chopper, although it is not*/ rectangle("xy",0,0,0,xwidth,yheight); double delta,radius; delta=2*yheight; radius=sqrt(xwidth*xwidth/4+delta*delta); circle("xy",0,-(delta-yheight/2.0),0,radius); %} END