/******************************************************************************* * * McStas, neutron ray-tracing package * Copyright 1997-2002, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Component: TOFlog_monitor.comp * * %I * Written by: Kim Lefmann * Date: October 2000 * Origin: Risoe * * Rectangular Time-of-flight monitor with logarithmic time binning. * * %D * * A rectangular time-of-flight monitor with logarithmic time binning. * (The neutron intensity is NOT given logarithmically) * * %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 * tmin: [mus] Lower bound for time bins * tmax: [mus] Higher bound for time bins * ndec: [1] Number of time bins per decade * filename: [string] Name of file in which to store the detector image * restore_neutron: [1] If set, the monitor does not influence the neutron state * nowritefile: [1] If set, monitor will skip writing to disk * * OUTPUT PARAMETERS: * * TOF_N: [] Array of neutron counts * TOF_p: [] Array of neutron weight counts * TOF_p2: [] Array of second moments * * %E *******************************************************************************/ DEFINE COMPONENT TOFlog_monitor DEFINITION PARAMETERS (tmin, tmax, ndec=10) SETTING PARAMETERS (string filename=0, xmin=-0.05, xmax=0.05, ymin=-0.05, ymax=0.05, xwidth=0, yheight=0, restore_neutron=0, int nowritefile=0) OUTPUT PARAMETERS (TOF_N, TOF_p, TOF_p2) /* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */ DECLARE %{ #define LARGENUMBER 10000 int nchan; double TOF_N[LARGENUMBER]; double TOF_p[LARGENUMBER]; double TOF_p2[LARGENUMBER]; %} INITIALIZE %{ int i; if (xwidth > 0) { xmax = xwidth/2; xmin = -xmax; } if (yheight > 0) { ymax = yheight/2; ymin = -ymax; } if ((xmin >= xmax) || (ymin >= ymax)) { printf("TOFlog_mon: %s: Null detection area !\n" "ERROR (xwidth,yheight,xmin,xmax,ymin,ymax). Exiting", NAME_CURRENT_COMP); exit(-1); } nchan=(int)ceil(ndec*log(tmax/tmin)/log(10.0)); if (nchan>LARGENUMBER) printf("FATAL ERROR, too many time channels \n"); for (i=0; ixmin && xymin && y= 0 && i < nchan) { TOF_N[i]++; TOF_p[i] += p; TOF_p2[i] += p*p; } } if (restore_neutron) { RESTORE_NEUTRON(INDEX_CURRENT_COMP, x, y, z, vx, vy, vz, t, sx, sy, sz, p); } %} SAVE %{ if (!nowritefile) { DETECTOR_OUT_1D( "Time-of-flight monitor", "Log(Time-of-flight [\\gms])", "Intensity", "t", log(tmin)/log(10.0), log(tmax)/log(10.0), nchan, &TOF_N[0],&TOF_p[0],&TOF_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