File: TOF_PSD_monitor_rad.comp

package info (click to toggle)
mccode 3.5.19%2Bds5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,113,256 kB
  • sloc: ansic: 40,697; python: 25,137; yacc: 8,438; sh: 5,405; javascript: 4,596; lex: 1,632; cpp: 742; perl: 296; lisp: 273; makefile: 226; fortran: 132
file content (158 lines) | stat: -rw-r--r-- 4,219 bytes parent folder | download
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
/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright 1997-2002, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Component: TOF_PSD_monitor_rad
*
* %Identification
* Written by: Kim Lefmann
* Modified from: PSD_monitor_rad by Henrich Frielinghaus, FZJuelich
* Date:       March 2012
* Origin:     UCPH
* Modified by:
*
* Position-sensitive TOF monitor with radially averaging.
*
* %D
* TOF monitor that performs radial averaging.
* Comment: The intensity is given as two 2D files:
*          1) a radial sum vs. TOF
*          2) a radial average (i.e. intensity per area) vs. TOF
*
* Example: TOF_PSD_monitor_rad(rmax=0.2, nr=100, filename="Output.psd", filename_av="Output_av.psd")
*
* %P
* INPUT PARAMETERS:
*
* rmax: [m]              Outer radius of detector
* nr: [1]                Number of concentric circles
* filename: [string]     Name of file in which to store the detector image
* filename_av: [string]  Name of file in which to store the averaged detector image
* nt: [1]                Number of time bins
* tmin: [mu-s]           Beginning of time window
* tmax: [mu-s]           End of time window
* nowritefile: [1]      If set, monitor will skip writing to disk
*
* CALCULATED PARAMETERS:
*
* PSDr_N: []             Array of neutron counts
* PSDr_p: []             Array of neutron weight counts
* PSDr_p2: []            Array of second moments
* PSDr_av_N: []          Array of neutron counts, averaged
* PSDr_av_p: []          Array of neutron weight counts, averaged
* PSDr_av_p2: []         Array of second moments, averaged
*
* %E
*******************************************************************************/

DEFINE COMPONENT TOF_PSD_monitor_rad

SETTING PARAMETERS (int nr=100, int nt=100, int nowritefile=0,
  string filename=0, string filename_av=0, rmax=0.2, tmin, tmax, int restore_neutron=0)


DECLARE
%{
  double tt_0;
  double tt_1;

  DArray2d TOFPSDr_N;
  DArray2d TOFPSDr_p;
  DArray2d TOFPSDr_p2;
  DArray2d TOFPSDr_av_p;
  DArray2d TOFPSDr_av_p2;
%}

INITIALIZE
%{
  TOFPSDr_N = create_darr2d(nt, nr);
  TOFPSDr_p = create_darr2d(nt, nr);
  TOFPSDr_p2 = create_darr2d(nt, nr);
  TOFPSDr_av_p = create_darr2d(nt, nr);
  TOFPSDr_av_p2 = create_darr2d(nt, nr);

  tt_0=tmin*1e-6;
  tt_1=tmax*1e-6;

  // Use instance name for monitor output if no input was given
  if (!strcmp(filename,"\0")) sprintf(filename,"%s",NAME_CURRENT_COMP);

  // Use instance name for monitor output if no input was given
  if (!strcmp(filename_av,"\0")) sprintf(filename_av,"%s%s",NAME_CURRENT_COMP,"_avg");
%}

TRACE
%{
  int i,j;
  double dt,radpos;

  PROP_Z0;

  radpos = sqrt(x*x+y*y);
  i = floor((t-tt_0)*nt/(tt_1-tt_0));              /* Bin number */
  j = floor(nr*radpos/rmax);

  if (radpos < rmax && i>=0 && i < nt)
  {
    double p2 = p*p;
    #pragma acc atomic
    TOFPSDr_N[i][j] = TOFPSDr_N[i][j]+1;
    #pragma acc atomic
    TOFPSDr_p[i][j] = TOFPSDr_p[i][j]+p;
    #pragma acc atomic
    TOFPSDr_p2[i][j] = TOFPSDr_p2[i][j]+p2;
    SCATTER;
  }

  if (restore_neutron) {
    RESTORE_NEUTRON(INDEX_CURRENT_COMP, x, y, z, vx, vy, vz, t, sx, sy, sz, p);
  }
%}

SAVE
%{
if (!nowritefile) {
  int i, j;
  for(i=0; i<nt; i++)
    for(j=0; j<nr; j++) {
      TOFPSDr_av_p[i][j]  = TOFPSDr_p[i][j]  / (PI*rmax*rmax/(nr*nr)*(2*j+1.0));
      TOFPSDr_av_p2[i][j] = TOFPSDr_p2[i][j]
        / (PI*rmax*rmax/(nr*nr)*(2*j+1.0)) / (PI*rmax*rmax/(nr*nr)*(2*j+1.0));
    }
  DETECTOR_OUT_2D(
    "TOF PSD monitor radial sum",
    "Time-of-flight [\\gms]",
    "Radius [m]",
    tmin, tmax, 0, rmax,
    nt, nr,
    &TOFPSDr_N[0][0],&TOFPSDr_p[0][0],&TOFPSDr_p2[0][0],
    filename);
  DETECTOR_OUT_2D(
    "TOF PSD monitor radial average",
    "Time-of-flight [\\gms]",
    "Radius [m]",
    tmin, tmax, 0, rmax,
    nt, nr,
    &TOFPSDr_N[0][0],&TOFPSDr_av_p[0][0],&TOFPSDr_av_p2[0][0],
    filename_av);
}
%}

FINALLY
%{
  destroy_darr2d(TOFPSDr_N);
  destroy_darr2d(TOFPSDr_p);
  destroy_darr2d(TOFPSDr_p2);
  destroy_darr2d(TOFPSDr_av_p);
  destroy_darr2d(TOFPSDr_av_p2);
%}

MCDISPLAY
%{
  circle("xy",0,0,0,rmax);
%}

END