1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=4.0 |
---|
4 | |
---|
5 | //*********************** |
---|
6 | // Vers. 1.2 092101 |
---|
7 | // |
---|
8 | // functions to perform either ractangular averages (similar to sector averages) |
---|
9 | // or annular averages ( fixed Q, I(angle) ) |
---|
10 | // |
---|
11 | // dispatched to this point by ExecuteProtocol() |
---|
12 | // |
---|
13 | //************************** |
---|
14 | |
---|
15 | //////////////////////////////////// |
---|
16 | // |
---|
17 | // For AVERAGE and for DRAWING |
---|
18 | // DRAWING routines only use a subset of the total list, since saving, naming, etc. don't apply |
---|
19 | // (10) possible keywords, some numerical, some string values |
---|
20 | // AVTYPE=string string from set {Circular,Annular,Rectangular,Sector,2D_ASCII,PNG_Graphic} |
---|
21 | // PHI=value azimuthal angle (-90,90) |
---|
22 | // DPHI=value +/- angular range around phi for average |
---|
23 | // WIDTH=value total width of rectangular section, in pixels |
---|
24 | // SIDE=string string from set {left,right,both} **note NOT capitalized |
---|
25 | // QCENTER=value q-value (1/A) of center of annulus for annular average |
---|
26 | // QDELTA=value total width of annulus centered at QCENTER |
---|
27 | // PLOT=string string from set {Yes,No} = truth of generating plot of averaged data |
---|
28 | // SAVE=string string from set {Yes,No} = truth of saving averaged data to disk |
---|
29 | // NAME=string string from set {Auto,Manual} = Automatic name generation or Manual(dialog) |
---|
30 | // |
---|
31 | ////////////////////////////////// |
---|
32 | |
---|
33 | |
---|
34 | //function to do average of a rectangular swath of the detector |
---|
35 | //a sector average seems to be more appropriate, but there may be some |
---|
36 | //utility in rectangular averages |
---|
37 | //the parameters in the global keyword-string must have already been set somewhere |
---|
38 | //either directly or from the protocol |
---|
39 | // |
---|
40 | // 2-D data in the folder must already be on a linear scale. The calling routine is |
---|
41 | //responsible for this - |
---|
42 | //writes out the averaged waves to the "type" data folder |
---|
43 | //data is not written to disk by this routine |
---|
44 | // |
---|
45 | Function RectangularAverageTo1D(type) |
---|
46 | String type |
---|
47 | |
---|
48 | SVAR keyListStr = root:myGlobals:Protocols:gAvgInfoStr |
---|
49 | |
---|
50 | //type is the data type to do the averaging on, and will be set as the current folder |
---|
51 | //get the current displayed data (so the correct folder is used) |
---|
52 | String destPath = "root:"+type |
---|
53 | // |
---|
54 | Variable xcenter,ycenter,x0,y0,sx,sx3,sy,sy3,dtsize,dtdist,dr,ddr |
---|
55 | Variable lambda,trans |
---|
56 | Wave reals = $(destPath + ":RealsRead") |
---|
57 | WAVE/T textread = $(destPath + ":TextRead") |
---|
58 | String fileStr = textread[3] |
---|
59 | |
---|
60 | // center of detector, for non-linear corrections |
---|
61 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
62 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
63 | |
---|
64 | xcenter = pixelsX/2 + 0.5 // == 64.5 for 128x128 Ordela |
---|
65 | ycenter = pixelsY/2 + 0.5 // == 64.5 for 128x128 Ordela |
---|
66 | |
---|
67 | // beam center, in pixels |
---|
68 | x0 = reals[16] |
---|
69 | y0 = reals[17] |
---|
70 | //detector calibration constants |
---|
71 | sx = reals[10] //mm/pixel (x) |
---|
72 | sx3 = reals[11] //nonlinear coeff |
---|
73 | sy = reals[13] //mm/pixel (y) |
---|
74 | sy3 = reals[14] //nonlinear coeff |
---|
75 | |
---|
76 | |
---|
77 | dtsize = 10*reals[20] //det size in mm |
---|
78 | dtdist = 1000*reals[18] // det distance in mm |
---|
79 | |
---|
80 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
81 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
82 | |
---|
83 | NVAR binWidth=root:myGlobals:gBinWidth |
---|
84 | dr = binWidth // annulus width set by user, default is one |
---|
85 | ddr = dr*sx //step size, in mm (this is the value to pass to the resolution calculation, not dr 18NOV03) |
---|
86 | |
---|
87 | Variable rcentr,large_num,small_num,dtdis2,nq,xoffst,dxbm,dybm,ii |
---|
88 | Variable phi_rad,dphi_rad,phi_x,phi_y |
---|
89 | Variable forward,mirror |
---|
90 | |
---|
91 | String side = StringByKey("SIDE",keyListStr,"=",";") |
---|
92 | // Print "side = ",side |
---|
93 | |
---|
94 | //convert from degrees to radians |
---|
95 | phi_rad = (Pi/180)*NumberByKey("PHI",keyListStr,"=",";") |
---|
96 | dphi_rad = (Pi/180)*NumberByKey("DPHI",keyListStr,"=",";") |
---|
97 | //create cartesian values for unit vector in phi direction |
---|
98 | phi_x = cos(phi_rad) |
---|
99 | phi_y = sin(phi_rad) |
---|
100 | |
---|
101 | //get (total) width of band |
---|
102 | Variable width = NumberByKey("WIDTH",keyListStr,"=",";") |
---|
103 | |
---|
104 | /// data wave is data in the current folder which was set at the top of the function |
---|
105 | Wave data=$(destPath + ":data") |
---|
106 | //Check for the existence of the mask, if not, make one (local to this folder) that is null |
---|
107 | |
---|
108 | if(WaveExists($"root:MSK:data") == 0) |
---|
109 | Print "There is no mask file loaded (WaveExists)- the data is not masked" |
---|
110 | Make/O/N=(pixelsX,pixelsY) $(destPath + ":mask") |
---|
111 | WAVE mask = $(destPath + ":mask") |
---|
112 | mask = 0 |
---|
113 | else |
---|
114 | Wave mask=$"root:MSK:data" |
---|
115 | Endif |
---|
116 | |
---|
117 | rcentr = 100 //pixels within rcentr of beam center are broken into 9 parts |
---|
118 | // values for error if unable to estimate value |
---|
119 | //large_num = 1e10 |
---|
120 | large_num = 1 //1e10 value (typically sig of last data point) plots poorly, arb set to 1 |
---|
121 | small_num = 1e-10 |
---|
122 | |
---|
123 | // output wave are expected to exist (?) initialized to zero, what length? |
---|
124 | // 300 points on VAX --- |
---|
125 | Variable wavePts=500 |
---|
126 | Make/O/N=(wavePts) $(destPath + ":qval"),$(destPath + ":aveint") |
---|
127 | Make/O/N=(wavePts) $(destPath + ":ncells"),$(destPath + ":dsq"),$(destPath + ":sigave") |
---|
128 | Make/O/N=(wavePts) $(destPath + ":SigmaQ"),$(destPath + ":fSubS"),$(destPath + ":QBar") |
---|
129 | WAVE qval = $(destPath + ":qval") |
---|
130 | WAVE aveint = $(destPath + ":aveint") |
---|
131 | WAVE ncells = $(destPath + ":ncells") |
---|
132 | WAVE dsq = $(destPath + ":dsq") |
---|
133 | WAVE sigave = $(destPath + ":sigave") |
---|
134 | WAVE qbar = $(destPath + ":QBar") |
---|
135 | WAVE sigmaq = $(destPath + ":SigmaQ") |
---|
136 | WAVE fsubs = $(destPath + ":fSubS") |
---|
137 | |
---|
138 | qval = 0 |
---|
139 | aveint = 0 |
---|
140 | ncells = 0 |
---|
141 | dsq = 0 |
---|
142 | sigave = 0 |
---|
143 | qbar = 0 |
---|
144 | sigmaq = 0 |
---|
145 | fsubs = 0 |
---|
146 | |
---|
147 | dtdis2 = dtdist^2 |
---|
148 | nq = 1 |
---|
149 | xoffst=0 |
---|
150 | //distance of beam center from detector center |
---|
151 | dxbm = FX(x0,sx3,xcenter,sx) |
---|
152 | dybm = FY(y0,sy3,ycenter,sy) |
---|
153 | |
---|
154 | //BEGIN AVERAGE ********** |
---|
155 | Variable xi,dxi,dx,jj,data_pixel,yj,dyj,dy,mask_val=0.1 |
---|
156 | Variable dr2,nd,fd,nd2,ll,kk,dxx,dyy,ir,dphi_p,d_per,d_pll |
---|
157 | Make/O/N=2 $(destPath + ":par") |
---|
158 | WAVE par = $(destPath + ":par") |
---|
159 | |
---|
160 | // IGOR arrays are indexed from [0][0], FORTAN from (1,1) (and the detector too) |
---|
161 | // loop index corresponds to FORTRAN (old code) |
---|
162 | // and the IGOR array indices must be adjusted (-1) to the correct address |
---|
163 | ii=1 |
---|
164 | do |
---|
165 | xi = ii |
---|
166 | dxi = FX(xi,sx3,xcenter,sx) |
---|
167 | dx = dxi-dxbm //dx and dy are in mm |
---|
168 | |
---|
169 | jj = 1 |
---|
170 | do |
---|
171 | data_pixel = data[ii-1][jj-1] //assign to local variable |
---|
172 | yj = jj |
---|
173 | dyj = FY(yj,sy3,ycenter,sy) |
---|
174 | dy = dyj - dybm |
---|
175 | if(!(mask[ii][jj])) //masked pixels = 1, skip if masked (this way works...) |
---|
176 | dr2 = (dx^2 + dy^2)^(0.5) //distance from beam center NOTE dr2 used here - dr used above |
---|
177 | if(dr2>rcentr) //keep pixel whole |
---|
178 | nd = 1 |
---|
179 | fd = 1 |
---|
180 | else //break pixel into 9 equal parts |
---|
181 | nd = 3 |
---|
182 | fd = 2 |
---|
183 | endif |
---|
184 | nd2 = nd^2 |
---|
185 | ll = 1 //"el-el" loop index |
---|
186 | do |
---|
187 | dxx = dx + (ll - fd)*sx/3 |
---|
188 | kk = 1 |
---|
189 | do |
---|
190 | dyy = dy + (kk - fd)*sy/3 |
---|
191 | //determine distance pixel is from beam center (d_pll) |
---|
192 | //and distance off-line (d_per) and if in forward direction |
---|
193 | par = 0 //initialize the wave |
---|
194 | forward = distance(dxx,dyy,phi_x,phi_y,par) |
---|
195 | d_per = par[0] |
---|
196 | d_pll = par[1] |
---|
197 | //check whether pixel lies within width band |
---|
198 | if(d_per <= (0.5*width*ddr)) |
---|
199 | //check if pixel lies within allowed sector(s) |
---|
200 | if(cmpstr(side,"both")==0) //both sectors |
---|
201 | //increment |
---|
202 | nq = IncrementPixel_Rec(data_pixel,ddr,d_pll,aveint,dsq,ncells,nq,nd2) |
---|
203 | else |
---|
204 | if(cmpstr(side,"right")==0) //forward sector only |
---|
205 | if(forward) |
---|
206 | //increment |
---|
207 | nq = IncrementPixel_Rec(data_pixel,ddr,d_pll,aveint,dsq,ncells,nq,nd2) |
---|
208 | Endif |
---|
209 | else //mirror sector only |
---|
210 | if(!forward) |
---|
211 | //increment |
---|
212 | nq = IncrementPixel_Rec(data_pixel,ddr,d_pll,aveint,dsq,ncells,nq,nd2) |
---|
213 | Endif |
---|
214 | Endif |
---|
215 | Endif //allowable sectors |
---|
216 | Endif //check if in band |
---|
217 | kk+=1 |
---|
218 | while(kk<=nd) |
---|
219 | ll += 1 |
---|
220 | while(ll<=nd) |
---|
221 | Endif //masked pixel check |
---|
222 | jj += 1 |
---|
223 | while (jj<=pixelsY) |
---|
224 | ii += 1 |
---|
225 | while(ii<=pixelsX) //end of the averaging |
---|
226 | |
---|
227 | //compute q-values and errors |
---|
228 | Variable ntotal,rr,theta,avesq,aveisq,var |
---|
229 | |
---|
230 | lambda = reals[26] |
---|
231 | ntotal = 0 |
---|
232 | kk = 1 |
---|
233 | do |
---|
234 | rr = (2*kk-1)*ddr/2 |
---|
235 | theta = 0.5*atan(rr/dtdist) |
---|
236 | qval[kk-1] = (4*Pi/lambda)*sin(theta) |
---|
237 | if(ncells[kk-1] == 0) |
---|
238 | //no pixels in annuli, data unknown |
---|
239 | aveint[kk-1] = 0 |
---|
240 | sigave[kk-1] = large_num |
---|
241 | else |
---|
242 | if(ncells[kk-1] <= 1) |
---|
243 | //need more than one pixel to determine error |
---|
244 | aveint[kk-1] = aveint[kk-1]/ncells[kk-1] |
---|
245 | sigave[kk-1] = large_num |
---|
246 | else |
---|
247 | //assume that the intensity in each pixel in annuli is normally |
---|
248 | // distributed about mean... |
---|
249 | aveint[kk-1] = aveint[kk-1]/ncells[kk-1] |
---|
250 | avesq = aveint[kk-1]^2 |
---|
251 | aveisq = dsq[kk-1]/ncells[kk-1] |
---|
252 | var = aveisq-avesq |
---|
253 | if(var<=0) |
---|
254 | sigave[kk-1] = small_num |
---|
255 | else |
---|
256 | sigave[kk-1] = sqrt(var/(ncells[kk-1] - 1)) |
---|
257 | endif |
---|
258 | endif |
---|
259 | endif |
---|
260 | ntotal += ncells[kk-1] |
---|
261 | kk+=1 |
---|
262 | while(kk<=nq) |
---|
263 | |
---|
264 | //Print "NQ = ",nq |
---|
265 | // data waves were defined as 200 points (=wavePts), but now have less than that (nq) points |
---|
266 | // use DeletePoints to remove junk from end of waves |
---|
267 | //WaveStats would be a more foolproof implementation, to get the # points in the wave |
---|
268 | Variable startElement,numElements |
---|
269 | startElement = nq |
---|
270 | numElements = wavePts - startElement |
---|
271 | DeletePoints startElement,numElements, qval,aveint,ncells,dsq,sigave |
---|
272 | |
---|
273 | //////////////end of VAX sector_ave() |
---|
274 | |
---|
275 | //angle dependent transmission correction |
---|
276 | Variable uval,arg,cos_th |
---|
277 | lambda = reals[26] |
---|
278 | trans = reals[4] |
---|
279 | |
---|
280 | ////this section is the trans_correct() VAX routine |
---|
281 | if(trans<0.1) |
---|
282 | Print "***transmission is less than 0.1*** and is a significant correction" |
---|
283 | endif |
---|
284 | if(trans==0) |
---|
285 | Print "***transmission is ZERO*** and has been reset to 1.0 for the averaging calculation" |
---|
286 | trans = 1 |
---|
287 | endif |
---|
288 | //optical thickness |
---|
289 | uval = -ln(trans) |
---|
290 | //apply correction to aveint[] |
---|
291 | //index from zero here, since only working with IGOR waves |
---|
292 | ii=0 |
---|
293 | do |
---|
294 | theta = 2*asin(lambda*qval[ii]/(4*pi)) |
---|
295 | cos_th = cos(theta) |
---|
296 | arg = (1-cos_th)/cos_th |
---|
297 | if((uval<0.01) || (cos_th>0.99)) //OR |
---|
298 | //small arg, approx correction |
---|
299 | aveint[ii] /= 1-0.5*uval*arg |
---|
300 | else |
---|
301 | //large arg, exact correction |
---|
302 | aveint[ii] /= (1-exp(-uval*arg))/(uval*arg) |
---|
303 | endif |
---|
304 | ii+=1 |
---|
305 | while(ii<nq) |
---|
306 | //end of transmission/pathlength correction |
---|
307 | |
---|
308 | // *************************************************************** |
---|
309 | // |
---|
310 | // Do the extra 3 columns of resolution calculations starting here. |
---|
311 | // |
---|
312 | // *************************************************************** |
---|
313 | |
---|
314 | Variable L2 = reals[18] |
---|
315 | Variable BS = reals[21] |
---|
316 | Variable S1 = reals[23] |
---|
317 | Variable S2 = reals[24] |
---|
318 | Variable L1 = reals[25] |
---|
319 | lambda = reals[26] |
---|
320 | Variable lambdaWidth = reals[27] |
---|
321 | String detStr=textRead[9] |
---|
322 | |
---|
323 | //Two parameters DDET and APOFF are instrument dependent. Determine |
---|
324 | //these from the instrument name in the header. |
---|
325 | //From conversation with JB on 01.06.99 these are the current |
---|
326 | //good values |
---|
327 | |
---|
328 | Variable DDet, apOff=0.0 |
---|
329 | DDet = DetectorPixelResolution(fileStr,detStr) //needs detector type and beamline |
---|
330 | |
---|
331 | |
---|
332 | //Width of annulus used for the average is gotten from the |
---|
333 | //input dialog before. This also must be passed to the resol |
---|
334 | //calculator. Currently the default is dr=1 so just keeping that. |
---|
335 | |
---|
336 | //Go from 0 to nq doing the calc for all three values at |
---|
337 | //every Q value |
---|
338 | |
---|
339 | ii=0 |
---|
340 | |
---|
341 | Variable ret1,ret2,ret3 |
---|
342 | do |
---|
343 | getResolution(qval[ii],lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,ddr,ret1,ret2,ret3) |
---|
344 | sigmaq[ii] = ret1 |
---|
345 | qbar[ii] = ret2 |
---|
346 | fsubs[ii] = ret3 |
---|
347 | ii+=1 |
---|
348 | while(ii<nq) |
---|
349 | |
---|
350 | DeletePoints startElement,numElements, sigmaq, qbar, fsubs |
---|
351 | |
---|
352 | // *************************************************************** |
---|
353 | // |
---|
354 | // End of resolution calculations |
---|
355 | // |
---|
356 | // *************************************************************** |
---|
357 | |
---|
358 | Avg_1D_Graph(aveint,qval,sigave) |
---|
359 | |
---|
360 | //get rid of the default mask, if one was created (it is in the current folder) |
---|
361 | //don't just kill "mask" since it might be pointing to the one in the MSK folder |
---|
362 | Killwaves/Z $(destPath+":mask") |
---|
363 | |
---|
364 | KillWaves/Z $(destPath+":par") //parameter wave used in function distance() |
---|
365 | |
---|
366 | //return to root folder (redundant) |
---|
367 | SetDataFolder root: |
---|
368 | |
---|
369 | Return 0 |
---|
370 | End |
---|
371 | |
---|
372 | //returns nq, new number of q-values |
---|
373 | //arrays aveint,dsq,ncells are also changed by this function |
---|
374 | // |
---|
375 | Function IncrementPixel_Rec(dataPixel,ddr,d_pll,aveint,dsq,ncells,nq,nd2) |
---|
376 | Variable dataPixel,ddr,d_pll |
---|
377 | Wave aveint,dsq,ncells |
---|
378 | Variable nq,nd2 |
---|
379 | |
---|
380 | Variable ir |
---|
381 | |
---|
382 | ir = trunc(abs(d_pll)/ddr)+1 |
---|
383 | if (ir>nq) |
---|
384 | nq = ir //resets maximum number of q-values |
---|
385 | endif |
---|
386 | aveint[ir-1] += dataPixel/nd2 //ir-1 must be used, since ir is physical |
---|
387 | dsq[ir-1] += dataPixel*dataPixel/nd2 |
---|
388 | ncells[ir-1] += 1/nd2 |
---|
389 | |
---|
390 | Return nq |
---|
391 | End |
---|
392 | |
---|
393 | //function determines disatnce in mm that pixel is from line |
---|
394 | //intersecting cetner of detector and direction phi |
---|
395 | //at chosen azimuthal angle phi -> [cos(phi),sin(phi0] = [phi_x,phi_y] |
---|
396 | //distance is always positive |
---|
397 | // |
---|
398 | // distances are returned in a wave |
---|
399 | // forward (truth) is the function return value |
---|
400 | // |
---|
401 | Function distance(dxx,dyy,phi_x,phi_y,par) |
---|
402 | Variable dxx,dyy,phi_x,phi_y |
---|
403 | Wave par //par[0] = d_per |
---|
404 | //par[1] = d_pll , both are returned values |
---|
405 | |
---|
406 | Variable val,rr,dot_prod,forward,d_per,d_pll,dphi_pixel |
---|
407 | |
---|
408 | rr = sqrt(dxx^2 + dyy^2) |
---|
409 | dot_prod = (dxx*phi_x + dyy*phi_y)/rr |
---|
410 | if(dot_prod >= 0) |
---|
411 | forward = 1 |
---|
412 | else |
---|
413 | forward = 0 |
---|
414 | Endif |
---|
415 | //? correct for roundoff error? - is this necessary in IGOR, w/ double precision? |
---|
416 | if(dot_prod > 1) |
---|
417 | dot_prod =1 |
---|
418 | Endif |
---|
419 | if(dot_prod < -1) |
---|
420 | dot_prod = -1 |
---|
421 | Endif |
---|
422 | dphi_pixel = acos(dot_prod) |
---|
423 | |
---|
424 | //distance (in mm) that pixel is from line (perpendicular) |
---|
425 | d_per = sin(dphi_pixel)*rr |
---|
426 | //distance (in mm) that pixel projected onto line is from beam center (parallel) |
---|
427 | d_pll = cos(dphi_pixel)*rr |
---|
428 | |
---|
429 | //assign to wave for return |
---|
430 | par[0] = d_per |
---|
431 | par[1] = d_pll |
---|
432 | |
---|
433 | return (forward) |
---|
434 | |
---|
435 | End |
---|
436 | |
---|
437 | //performs an average around an annulus of specified width, centered on a |
---|
438 | //specified q-value (Intensity vs. angle) |
---|
439 | //the parameters in the global keyword-string must have already been set somewhere |
---|
440 | //either directly or from the protocol |
---|
441 | // |
---|
442 | //the input (data in the "type" folder) must be on linear scale - the calling routine is |
---|
443 | //responsible for this |
---|
444 | //averaged data is written to the data folder and plotted. data is not written |
---|
445 | //to disk from this routine. |
---|
446 | // |
---|
447 | Function AnnularAverageTo1D(type) |
---|
448 | String type |
---|
449 | |
---|
450 | SVAR keyListStr = root:myGlobals:Protocols:gAvgInfoStr |
---|
451 | |
---|
452 | //type is the data type to do the averaging on, and will be set as the current folder |
---|
453 | //get the current displayed data (so the correct folder is used) |
---|
454 | String destPath = "root:"+type |
---|
455 | |
---|
456 | Variable xcenter,ycenter,x0,y0,sx,sx3,sy,sy3,dtsize,dtdist |
---|
457 | Variable rcentr,large_num,small_num,dtdis2,nq,xoffst,xbm,ybm,ii |
---|
458 | Variable rc,delr,rlo,rhi,dphi,nphi,dr |
---|
459 | Variable lambda,trans |
---|
460 | Wave reals = $(destPath + ":RealsRead") |
---|
461 | |
---|
462 | // center of detector, for non-linear corrections |
---|
463 | NVAR pixelsX = root:myGlobals:gNPixelsX |
---|
464 | NVAR pixelsY = root:myGlobals:gNPixelsY |
---|
465 | |
---|
466 | xcenter = pixelsX/2 + 0.5 // == 64.5 for 128x128 Ordela |
---|
467 | ycenter = pixelsY/2 + 0.5 // == 64.5 for 128x128 Ordela |
---|
468 | |
---|
469 | // beam center, in pixels |
---|
470 | x0 = reals[16] |
---|
471 | y0 = reals[17] |
---|
472 | //detector calibration constants |
---|
473 | sx = reals[10] //mm/pixel (x) |
---|
474 | sx3 = reals[11] //nonlinear coeff |
---|
475 | sy = reals[13] //mm/pixel (y) |
---|
476 | sy3 = reals[14] //nonlinear coeff |
---|
477 | |
---|
478 | dtsize = 10*reals[20] //det size in mm |
---|
479 | dtdist = 1000*reals[18] // det distance in mm |
---|
480 | lambda = reals[26] |
---|
481 | |
---|
482 | Variable qc = NumberByKey("QCENTER",keyListStr,"=",";") |
---|
483 | Variable nw = NumberByKey("QDELTA",keyListStr,"=",";") |
---|
484 | |
---|
485 | dr = 1 //minimum annulus width, keep this fixed at one |
---|
486 | NVAR numPhiSteps = root:myGlobals:gNPhiSteps |
---|
487 | nphi = numPhiSteps //number of anular sectors is set by users |
---|
488 | |
---|
489 | rc = 2*dtdist*asin(qc*lambda/4/Pi) //in mm |
---|
490 | delr = nw*sx/2 |
---|
491 | rlo = rc-delr |
---|
492 | rhi = rc + delr |
---|
493 | dphi = 360/nphi |
---|
494 | |
---|
495 | /// data wave is data in the current folder which was set at the top of the function |
---|
496 | Wave data=$(destPath + ":data") |
---|
497 | //Check for the existence of the mask, if not, make one (local to this folder) that is null |
---|
498 | |
---|
499 | if(WaveExists($"root:MSK:data") == 0) |
---|
500 | Print "There is no mask file loaded (WaveExists)- the data is not masked" |
---|
501 | Make/O/N=(pixelsX,pixelsY) $(destPath + ":mask") |
---|
502 | WAVE mask = $(destPath + ":mask") |
---|
503 | mask = 0 |
---|
504 | else |
---|
505 | Wave mask=$"root:MSK:data" |
---|
506 | Endif |
---|
507 | |
---|
508 | rcentr = 150 //pixels within rcentr of beam center are broken into 9 parts |
---|
509 | // values for error if unable to estimate value |
---|
510 | //large_num = 1e10 |
---|
511 | large_num = 1 //1e10 value (typically sig of last data point) plots poorly, arb set to 1 |
---|
512 | small_num = 1e-10 |
---|
513 | |
---|
514 | // output wave are expected to exist (?) initialized to zero, what length? |
---|
515 | // 300 points on VAX --- |
---|
516 | Variable wavePts=500 |
---|
517 | Make/O/N=(wavePts) $(destPath + ":phival"),$(destPath + ":aveint") |
---|
518 | Make/O/N=(wavePts) $(destPath + ":ncells"),$(destPath + ":sig"),$(destPath + ":sigave") |
---|
519 | WAVE phival = $(destPath + ":phival") |
---|
520 | WAVE aveint = $(destPath + ":aveint") |
---|
521 | WAVE ncells = $(destPath + ":ncells") |
---|
522 | WAVE sig = $(destPath + ":sig") |
---|
523 | WAVE sigave = $(destPath + ":sigave") |
---|
524 | |
---|
525 | phival = 0 |
---|
526 | aveint = 0 |
---|
527 | ncells = 0 |
---|
528 | sig = 0 |
---|
529 | sigave = 0 |
---|
530 | |
---|
531 | dtdis2 = dtdist^2 |
---|
532 | nq = 1 |
---|
533 | xoffst=0 |
---|
534 | //distance of beam center from detector center |
---|
535 | xbm = FX(x0,sx3,xcenter,sx) |
---|
536 | ybm = FY(y0,sy3,ycenter,sy) |
---|
537 | |
---|
538 | //BEGIN AVERAGE ********** |
---|
539 | Variable xi,xd,x,y,yd,yj,nd,fd,nd2,iphi,ntotal,var |
---|
540 | Variable jj,data_pixel,xx,yy,ll,kk,rij,phiij,avesq,aveisq |
---|
541 | |
---|
542 | // IGOR arrays are indexed from [0][0], FORTAN from (1,1) (and the detector too) |
---|
543 | // loop index corresponds to FORTRAN (old code) |
---|
544 | // and the IGOR array indices must be adjusted (-1) to the correct address |
---|
545 | ntotal = 0 |
---|
546 | ii=1 |
---|
547 | do |
---|
548 | xi = ii |
---|
549 | xd = FX(xi,sx3,xcenter,sx) |
---|
550 | x = xoffst + xd -xbm //x and y are in mm |
---|
551 | |
---|
552 | jj = 1 |
---|
553 | do |
---|
554 | data_pixel = data[ii-1][jj-1] //assign to local variable |
---|
555 | yj = jj |
---|
556 | yd = FY(yj,sy3,ycenter,sy) |
---|
557 | y = yd - ybm |
---|
558 | if(!(mask[ii-1][jj-1])) //masked pixels = 1, skip if masked (this way works...) |
---|
559 | nd = 1 |
---|
560 | fd = 1 |
---|
561 | if( (abs(x) > rcentr) || (abs(y) > rcentr)) //break pixel into 9 equal parts |
---|
562 | nd = 3 |
---|
563 | fd = 2 |
---|
564 | Endif |
---|
565 | nd2 = nd^2 |
---|
566 | ll = 1 //"el-el" loop index |
---|
567 | do |
---|
568 | xx = x + (ll - fd)*sx/3 |
---|
569 | kk = 1 |
---|
570 | do |
---|
571 | yy = y + (kk - fd)*sy/3 |
---|
572 | //test to see if center of pixel (i,j) lies in annulus |
---|
573 | rij = sqrt(x*x + y*y)/dr + 1.001 |
---|
574 | //check whether pixel lies within width band |
---|
575 | if((rij > rlo) && (rij < rhi)) |
---|
576 | //in the annulus, do something |
---|
577 | if (yy >= 0) |
---|
578 | //phiij is in degrees |
---|
579 | phiij = atan2(yy,xx)*180/Pi //0 to 180 deg |
---|
580 | else |
---|
581 | phiij = 360 + atan2(yy,xx)*180/Pi //180 to 360 deg |
---|
582 | Endif |
---|
583 | if (phiij > (360-0.5*dphi)) |
---|
584 | phiij -= 360 |
---|
585 | Endif |
---|
586 | iphi = trunc(phiij/dphi + 1.501) |
---|
587 | aveint[iphi-1] += 9*data_pixel/nd2 |
---|
588 | sig[iphi-1] += 9*data_pixel*data_pixel/nd2 |
---|
589 | ncells[iphi-1] += 9/nd2 |
---|
590 | ntotal += 9/nd2 |
---|
591 | Endif //check if in annulus |
---|
592 | kk+=1 |
---|
593 | while(kk<=nd) |
---|
594 | ll += 1 |
---|
595 | while(ll<=nd) |
---|
596 | Endif //masked pixel check |
---|
597 | jj += 1 |
---|
598 | while (jj<=pixelsY) |
---|
599 | ii += 1 |
---|
600 | while(ii<=pixelsX) //end of the averaging |
---|
601 | |
---|
602 | //compute phi-values and errors |
---|
603 | |
---|
604 | ntotal /=9 |
---|
605 | |
---|
606 | kk = 1 |
---|
607 | do |
---|
608 | phival[kk-1] = dphi*(kk-1) |
---|
609 | if(ncells[kk-1] != 0) |
---|
610 | aveint[kk-1] = aveint[kk-1]/ncells[kk-1] |
---|
611 | avesq = aveint[kk-1]*aveint[kk-1] |
---|
612 | aveisq = sig[kk-1]/ncells[kk-1] |
---|
613 | var = aveisq - avesq |
---|
614 | if (var <=0 ) |
---|
615 | sig[kk-1] = 0 |
---|
616 | sigave[kk-1] = 0 |
---|
617 | ncells[kk-1] /=9 |
---|
618 | else |
---|
619 | if(ncells[kk-1] > 9) |
---|
620 | sigave[kk-1] = sqrt(9*var/(ncells[kk-1]-9)) |
---|
621 | sig[kk-1] = sqrt( abs(aveint[kk-1])/(ncells[kk-1]/9) ) |
---|
622 | ncells[kk-1] /=9 |
---|
623 | else |
---|
624 | sig[kk-1] = 0 |
---|
625 | sigave[kk-1] = 0 |
---|
626 | ncells[kk-1] /=9 |
---|
627 | Endif |
---|
628 | Endif |
---|
629 | Endif |
---|
630 | kk+=1 |
---|
631 | while(kk<=nphi) |
---|
632 | |
---|
633 | // data waves were defined as 200 points (=wavePts), but now have less than that (nphi) points |
---|
634 | // use DeletePoints to remove junk from end of waves |
---|
635 | Variable startElement,numElements |
---|
636 | startElement = nphi |
---|
637 | numElements = wavePts - startElement |
---|
638 | DeletePoints startElement,numElements, phival,aveint,ncells,sig,sigave |
---|
639 | |
---|
640 | //////////////end of VAX Phibin.for |
---|
641 | |
---|
642 | //angle dependent transmission correction is not done in phiave |
---|
643 | Ann_1D_Graph(aveint,phival,sigave) |
---|
644 | |
---|
645 | //get rid of the default mask, if one was created (it is in the current folder) |
---|
646 | //don't just kill "mask" since it might be pointing to the one in the MSK folder |
---|
647 | Killwaves/z $(destPath+":mask") |
---|
648 | |
---|
649 | //return to root folder (redundant) |
---|
650 | SetDataFolder root: |
---|
651 | |
---|
652 | Return 0 |
---|
653 | End |
---|