128 lines
3.1 KiB
Plaintext
128 lines
3.1 KiB
Plaintext
/*******************************************************************************
|
|
*
|
|
* McStas, neutron ray-tracing package
|
|
* Copyright 1997-2002, All rights reserved
|
|
* Risoe National Laboratory, Roskilde, Denmark
|
|
* Institut Laue Langevin, Grenoble, France
|
|
*
|
|
* Component: PSD_monitor
|
|
*
|
|
* %I
|
|
* Written by: Kim Lefmann
|
|
* Date: Feb 3, 1998
|
|
* Version: $Revision$
|
|
* Origin: Risoe
|
|
* Release: McStas 1.6
|
|
*
|
|
* Hacked by to dump the total number of neutrons any dumpCount
|
|
* neutrons into a very simple one line file. This is needed to stay in control
|
|
* for virtual instruments.
|
|
*
|
|
* Mark Koennecke, June 2005
|
|
*
|
|
* Position-sensitive monitor.
|
|
*
|
|
* %D
|
|
* An (n times m) pixel PSD monitor. This component may also be used as a beam
|
|
* detector.
|
|
*
|
|
* Example: PSD_monitor(xmin=-0.1, xmax=0.1, ymin=-0.1, ymax=0.1,
|
|
nx=90, ny=90, filename="Output.psd")
|
|
*
|
|
* %P
|
|
* INPUT PARAMETERS:
|
|
*
|
|
* xmin: Lower x bound of detector opening (m)
|
|
* xmax: Upper x bound of detector opening (m)
|
|
* ymin: Lower y bound of detector opening (m)
|
|
* ymax: Upper y bound of detector opening (m)
|
|
* nx: Number of pixel columns (1)
|
|
* ny: Number of pixel rows (1)
|
|
* filename: Name of file in which to store the detector image (text)
|
|
* controlfile: A file to which the total number of neutrons detected is dumped
|
|
* any dumpCount counts.
|
|
* dumpCount: The number of counst after which a controlfile is written. A negative
|
|
* value switches the feauture off.
|
|
* OUTPUT PARAMETERS:
|
|
*
|
|
* PSD_N: Array of neutron counts
|
|
* PSD_p: Array of neutron weight counts
|
|
* PSD_p2: Array of second moments
|
|
* totalCounts: The total number of counts in the detector
|
|
* currentCount: The current counter since the last dump.
|
|
*
|
|
* %E
|
|
*******************************************************************************/
|
|
|
|
|
|
DEFINE COMPONENT PSD_monitor
|
|
DEFINITION PARAMETERS (nx=90, ny=90, filename, controlfile="mon01.dat")
|
|
SETTING PARAMETERS (xmin, xmax, ymin, ymax, int dumpCount = -1.)
|
|
OUTPUT PARAMETERS (PSD_N, PSD_p, PSD_p2, totalCount, currentCount)
|
|
STATE PARAMETERS (x,y,z,vx,vy,vz,t,s1,s2,p)
|
|
|
|
SHARE
|
|
%{
|
|
void dumpTotal(char *ffilename, long totalCounts){
|
|
FILE *fd = NULL;
|
|
|
|
fd = fopen(ffilename,"w");
|
|
if(fd != NULL){
|
|
fprintf(fd,"%ld\n",totalCounts);
|
|
fclose(fd);
|
|
}
|
|
}
|
|
%}
|
|
|
|
DECLARE
|
|
%{
|
|
long totalCount, currentCount;
|
|
double PSD_N[nx][ny];
|
|
double PSD_p[nx][ny];
|
|
double PSD_p2[nx][ny];
|
|
%}
|
|
INITIALIZE
|
|
%{
|
|
int i,j;
|
|
|
|
for (i=0; i<nx; i++)
|
|
for (j=0; j<ny; j++)
|
|
{
|
|
PSD_N[i][j] = 0;
|
|
PSD_p[i][j] = 0;
|
|
PSD_p2[i][j] = 0;
|
|
}
|
|
totalCount = 0;
|
|
currentCount = 0;
|
|
%}
|
|
TRACE
|
|
%{
|
|
int i,j;
|
|
|
|
PROP_Z0;
|
|
if (x>xmin && x<xmax && y>ymin && y<ymax)
|
|
{
|
|
i = floor((x - xmin)*nx/(xmax - xmin));
|
|
j = floor((y - ymin)*ny/(ymax - ymin));
|
|
PSD_N[i][j]++;
|
|
PSD_p[i][j] += p;
|
|
PSD_p2[i][j] += p*p;
|
|
totalCount++;
|
|
currentCount++;
|
|
if(dumpCount > 0 && currentCount > dumpCount){
|
|
dumpTotal(controlfile,totalCount);
|
|
currentCount = 0;
|
|
}
|
|
SCATTER;
|
|
}
|
|
%}
|
|
SAVE
|
|
%{
|
|
%}
|
|
|
|
MCDISPLAY
|
|
%{
|
|
%}
|
|
|
|
END
|