1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/*******************************************************************************
*
* McStas, neutron ray-tracing package
* Copyright 1997-2002, All rights reserved
* Risoe National Laboratory, Roskilde, Denmark
* Institut Laue Langevin, Grenoble, France
*
* Component: NPI_tof_theta_monitor
*
* %I
* Written by: Kim Lefmann
* Date: October 2000
* Version: $Revision: 1.1 $
* Origin: Risoe
* Release: McStas 1.6
* Modified by: Kim Lefmann, October 9, 2001
* Modified by: J Navrátil (NPI Řež), December 10, 2015
*
* Cylindrical (2pi) PSD Time-of-flight monitor.
*
* %D
* Derived from TOF_cylPSD_monitor.
* Code is extended by the option allowing to define range of scattering angles, therefore creating only a part of the cylinder surface.
* The plot is transposed when compared to TOF_cylPSD_monitor: scattering angles are on the horizontal axis.
*
*
* Example: TOF_cylPSD_monitor_NPI(nt = 1024, nphi = 960, filename = "Output.dat",
* radius = 2, yheight = 1.0, tmin = 3e4, tmax = 12e4, amin = 75, amax = 105, restore_neutron = 1)
*
* %P
* INPUT PARAMETERS:
*
* Inherited from NPI_tof_theta_monitor:
* radius: Cylinder radius (m)
* yheight: Cylinder height (m)
* nt: Number of time bins (1)
* tmin: Beginning of time window (mu-s)
* tmax: End of time window (mu-s)
* nphi: Number of angular bins (deg)
* amin: minimum angle to detect (deg)
* amax: maximum angle to detect (deg)
* filename: Name of file in which to store the detector image (text)
* restore_neutron: If set, the monitor does not influence the neutron state (1)
*
* Newly added
* amin: [deg] minimum of scattering angle to be detected
* amax: [deg] maximum of scattering angle to be detected
*
* CALCULATED PARAMETERS:
*
* TOF_N: Array of neutron counts
* TOF_p: Array of neutron weight counts
* TOF_p2: Array of second moments
*
* %E
*******************************************************************************/
DEFINE COMPONENT NPI_tof_theta_monitor
SETTING PARAMETERS (string filename=0, radius=1, yheight=0.3, tmin, tmax, amin, amax, restore_neutron=1, verbose=0, int nt=128, int na=90)
/* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */
SHARE
%{
%}
DECLARE
%{
DArray2d TOF_N;
DArray2d TOF_p;
DArray2d TOF_p2;
double th2_min;
double th2_max;
double dth;
double dtof;
double tt_0;
double tt_1;
%}
INITIALIZE
%{
th2_min = amin*DEG2RAD;
th2_max = amax*DEG2RAD;
dth=(th2_max-th2_min)/na;
tt_0=tmin*1e-6;
tt_1=tmax*1e-6;
dtof=(tt_1-tt_0)/nt;
TOF_N = create_darr2d(na, nt);
TOF_p = create_darr2d(na, nt);
TOF_p2 = create_darr2d(na, nt);
if (verbose) {
printf("%s: range 2theta=(%g,%g), time(%g,%g)\n",NAME_CURRENT_COMP,amin,amax,tmin/1000,tmax/1000);
}
// Use instance name for monitor output if no input was given
if (!strcmp(filename,"\0")) sprintf(filename,"%s",NAME_CURRENT_COMP);
%}
TRACE
%{
int i,j;
double t0,t1,theta2;
double cos2;
int cross=cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, radius, yheight);
/* don't allow intersections with top/bottom cylinder walls
only neutrons from inside are allowed
*/
if ( (cross!=1) || (t0>0) || (t1<0) ) {
p=0;
} else {
PROP_DT(t1);
/* Calculate pixel */
if (fabs(y)<(0.5*yheight)) {
cos2=z/sqrt(radius*radius+y*y);
theta2=acos(cos2);
if (theta2>th2_min && theta2< th2_max) {
i = (int)floor((theta2-th2_min)/dth+0.5);
j = (int)floor((t-tt_0)/dtof+0.5);
if ( j>=0 && j<nt && i>=0 && i<na ) {
double p2=p*p;
#pragma acc atomic
TOF_N[i][j] = TOF_N[i][j] + 1;
#pragma acc atomic
TOF_p[i][j] = TOF_p[i][j] + p;
#pragma acc atomic
TOF_p2[i][j] = TOF_p2[i][j] + p2;
} else {
}
}
}
}
if (restore_neutron) {
RESTORE_NEUTRON(INDEX_CURRENT_COMP, x, y, z, vx, vy, vz, t, sx, sy, sz, p);
}
%}
SAVE
%{
DETECTOR_OUT_2D(
"Cylindrical monitor ToF x 2theta",
"Scattering angle [deg]",
"Time-of-flight [\\gms]",
amin, amax, tmin, tmax,
na, nt,
&TOF_N[0][0],&TOF_p[0][0],&TOF_p2[0][0],
filename);
%}
FINALLY
%{
destroy_darr2d(TOF_N);
destroy_darr2d(TOF_p);
destroy_darr2d(TOF_p2);
%}
MCDISPLAY
%{
magnify("y");
circle("xz", 0,0,0,radius);
%}
END
|