1 | #pragma TextEncoding = "MacRoman" |
---|
2 | #pragma rtGlobals=3 // Use modern global access method and strict wave access. |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | // TODO |
---|
7 | // -- initialization |
---|
8 | // x- link to main panel |
---|
9 | // |
---|
10 | // ?? redesign the panel based on the CATALOG? |
---|
11 | // -- refresh the catalog, then work with those waves? |
---|
12 | // |
---|
13 | |
---|
14 | // TODO |
---|
15 | // -- currently, the initialization does nothing. |
---|
16 | Function V_InitTransmissionPanel() |
---|
17 | |
---|
18 | Execute "V_TransmissionPanel()" |
---|
19 | |
---|
20 | End |
---|
21 | |
---|
22 | |
---|
23 | Window V_TransmissionPanel() : Panel |
---|
24 | PauseUpdate; Silent 1 // building window... |
---|
25 | NewPanel /W=(1286,328,1764,952) |
---|
26 | ModifyPanel cbRGB=(32896,16448,0,19621) |
---|
27 | DoWindow/C V_TransmissionPanel |
---|
28 | |
---|
29 | // ShowTools/A |
---|
30 | PopupMenu popup_0,pos={19.00,55.00},size={86.00,23.00},proc=V_TSamFilePopMenuProc,title="Sample" |
---|
31 | PopupMenu popup_0,mode=1,value= V_getFileIntentList("SAMPLE",0)+V_getFileIntentList("EMPTY CELL",0) |
---|
32 | PopupMenu popup_1,pos={102,248},size={72.00,23.00},proc=V_TTransmFilePopMenuProc,title="Transmission" |
---|
33 | PopupMenu popup_1,mode=1,value= V_getFileIntentList("TRANSMISSION",0) |
---|
34 | PopupMenu popup_2,pos={164,353},size={72.00,23.00},proc=V_TEmpBeamPopMenuProc,title="Empty Beam" |
---|
35 | PopupMenu popup_2,mode=1,value= V_getFileIntentList("EMPTY BEAM",0) |
---|
36 | Button button_0,pos={37,193},size={100.00,20.00},proc=V_CalcTransmButtonProc,title="Calculate" |
---|
37 | // Button button_1,pos={23.00,491.00},size={100.00,20.00},proc=V_WriteTransmButtonProc,title="Write" |
---|
38 | Button button_2,pos={349.00,13.00},size={30.00,20.00},proc=V_HelpTransmButtonProc,title="?" |
---|
39 | Button button_3,pos={410.00,13.00},size={50.00,20.00},proc=V_DoneTransmButtonProc,title="Done" |
---|
40 | SetVariable setvar_0,pos={21.00,86.00},size={300.00,14.00},title="Label:" |
---|
41 | SetVariable setvar_0,limits={-inf,inf,0},value= _STR:"file label" |
---|
42 | SetVariable setvar_1,pos={21.00,113.00},size={300.00,14.00},title="Group ID:" |
---|
43 | SetVariable setvar_1,limits={-inf,inf,0},value= VSANS_RED_VERSION |
---|
44 | SetVariable setvar_2,pos={105,276.00},size={300.00,14.00},title="Label:" |
---|
45 | SetVariable setvar_2,limits={-inf,inf,0},value= _STR:"file label" |
---|
46 | SetVariable setvar_3,pos={104,302},size={300.00,14.00},title="Group ID:" |
---|
47 | SetVariable setvar_3,limits={-inf,inf,0},value= VSANS_RED_VERSION |
---|
48 | SetVariable setvar_4,pos={165,382},size={300.00,14.00},title="Label:" |
---|
49 | SetVariable setvar_4,limits={-inf,inf,0},value= _STR:"file label" |
---|
50 | SetVariable setvar_5,pos={165,406},size={300.00,14.00},title="XY Box:" |
---|
51 | SetVariable setvar_5,limits={-inf,inf,0},value= _STR:"dummy" |
---|
52 | SetVariable setvar_6,pos={165,431},size={300.00,14.00},title="Panel:" |
---|
53 | SetVariable setvar_6,limits={-inf,inf,0},value= _STR:"dummy" |
---|
54 | SetVariable setvar_7,pos={21,138},size={300.00,14.00},title="Transmission:" |
---|
55 | SetVariable setvar_7,limits={-inf,inf,0},value= VSANS_RED_VERSION |
---|
56 | SetVariable setvar_8,pos={21,163},size={300.00,14.00},title="Error:" |
---|
57 | SetVariable setvar_8,limits={-inf,inf,0},value= VSANS_RED_VERSION |
---|
58 | EndMacro |
---|
59 | |
---|
60 | // TODO |
---|
61 | // -- fill in the details |
---|
62 | // -- currently, I pick these from the Catalog, for speed |
---|
63 | // -- ? is the catalog current? |
---|
64 | // -- T error is not part of the Catalog - is that OK? |
---|
65 | // |
---|
66 | // when the SAM file menu is popped: |
---|
67 | // fill in the fields: |
---|
68 | // x- label |
---|
69 | // x- group id |
---|
70 | // x- transmission |
---|
71 | // -- T error |
---|
72 | // |
---|
73 | Function V_TSamFilePopMenuProc(pa) : PopupMenuControl |
---|
74 | STRUCT WMPopupAction &pa |
---|
75 | |
---|
76 | switch( pa.eventCode ) |
---|
77 | case 2: // mouse up |
---|
78 | Variable popNum = pa.popNum |
---|
79 | String popStr = pa.popStr |
---|
80 | |
---|
81 | Variable ii,np |
---|
82 | |
---|
83 | WAVE/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames |
---|
84 | WAVE/T labelW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Labels |
---|
85 | WAVE groupIDW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Group_ID |
---|
86 | WAVE transmW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Transmission |
---|
87 | |
---|
88 | // TODO |
---|
89 | // I don't have a wave for the transmission error value, so it's not displayed here |
---|
90 | // -- do I read it in, or just ignore it... |
---|
91 | np = numpnts(labelW) //fileNameW is LONGER - so don't use numpnts(fileWave) |
---|
92 | for(ii=0;ii<np;ii+=1) |
---|
93 | if(cmpstr(fileNameW[ii],popStr)==0) |
---|
94 | |
---|
95 | SetVariable setvar_0,value=labelW[ii] |
---|
96 | SetVariable setvar_1,value=groupIDW[ii] |
---|
97 | SetVariable setvar_7,value=transmW[ii] |
---|
98 | break //found, get out |
---|
99 | endif |
---|
100 | endfor |
---|
101 | |
---|
102 | // loop back through to find the transmission file with the matching group id |
---|
103 | // TODO x- set the popup string to the matching name on exit |
---|
104 | Variable targetID = groupIDW[ii] |
---|
105 | String list = V_getFileIntentList("TRANSMISSION",0) |
---|
106 | WAVE/T intentW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent |
---|
107 | for(ii=0;ii<np;ii+=1) |
---|
108 | if(cmpstr(intentW[ii],"TRANSMISSION")==0 && groupIDW[ii] == targetID) |
---|
109 | Print "transmission file match at ",filenameW[ii] |
---|
110 | SetVariable setvar_2,value=labelW[ii] |
---|
111 | SetVariable setvar_3,value=groupIDW[ii] |
---|
112 | PopupMenu popup_1,mode=WhichListItem(fileNameW[ii], list )+1 |
---|
113 | break |
---|
114 | endif |
---|
115 | endfor |
---|
116 | |
---|
117 | // now loop back through to find the empty beam file |
---|
118 | // TODO |
---|
119 | // x- fill in the XY box |
---|
120 | // -- Detector Panel field is hard-wired for "B" |
---|
121 | // |
---|
122 | WAVE/T intentW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent |
---|
123 | list = V_getFileIntentList("EMPTY BEAM",0) |
---|
124 | |
---|
125 | for(ii=0;ii<np;ii+=1) |
---|
126 | if(cmpstr(intentW[ii],"EMPTY BEAM")==0) |
---|
127 | Print "empty beam match at ",filenameW[ii] |
---|
128 | SetVariable setvar_4,value=labelW[ii] |
---|
129 | PopupMenu popup_2,mode=WhichListItem(fileNameW[ii], list )+1 |
---|
130 | |
---|
131 | SetVariable setvar_6,value =_STR:"B" |
---|
132 | |
---|
133 | WAVE boxCoord = V_getBoxCoordinates(filenameW[ii]) |
---|
134 | Print boxCoord |
---|
135 | SetVariable setvar_5,value=_STR:V_NumWave2List(boxCoord,";") |
---|
136 | |
---|
137 | |
---|
138 | break |
---|
139 | endif |
---|
140 | endfor |
---|
141 | |
---|
142 | break |
---|
143 | case -1: // control being killed |
---|
144 | break |
---|
145 | endswitch |
---|
146 | |
---|
147 | return 0 |
---|
148 | End |
---|
149 | |
---|
150 | // TODO |
---|
151 | // |
---|
152 | // Given the group ID of the sample, try to locate a (the) matching transmission file |
---|
153 | // by locating a matching ID in the list of transmission (intent) files |
---|
154 | // |
---|
155 | // then pop the menu |
---|
156 | // |
---|
157 | // |
---|
158 | Function V_TTransmFilePopMenuProc(pa) : PopupMenuControl |
---|
159 | STRUCT WMPopupAction &pa |
---|
160 | |
---|
161 | switch( pa.eventCode ) |
---|
162 | case 2: // mouse up |
---|
163 | Variable popNum = pa.popNum |
---|
164 | String popStr = pa.popStr |
---|
165 | |
---|
166 | |
---|
167 | |
---|
168 | break |
---|
169 | case -1: // control being killed |
---|
170 | break |
---|
171 | endswitch |
---|
172 | |
---|
173 | return 0 |
---|
174 | End |
---|
175 | |
---|
176 | |
---|
177 | Function V_TEmpBeamPopMenuProc(pa) : PopupMenuControl |
---|
178 | STRUCT WMPopupAction &pa |
---|
179 | |
---|
180 | switch( pa.eventCode ) |
---|
181 | case 2: // mouse up |
---|
182 | Variable popNum = pa.popNum |
---|
183 | String popStr = pa.popStr |
---|
184 | break |
---|
185 | case -1: // control being killed |
---|
186 | break |
---|
187 | endswitch |
---|
188 | |
---|
189 | return 0 |
---|
190 | End |
---|
191 | |
---|
192 | |
---|
193 | // NOTE: DIV is not needed for the transmission calculation, since it's a ratio |
---|
194 | // and the DIV simply drops out. (DIV is needed for ABS scaling calculation of Kappa, since |
---|
195 | // that is not a ratio) |
---|
196 | // |
---|
197 | // TODO |
---|
198 | // -- figure out which detector corrections are necessary to do on loading |
---|
199 | // data for calculation. Then set/reset preferences accordingly |
---|
200 | // (see V_isoCorrectButtonProc() for example of how to do this) |
---|
201 | // |
---|
202 | // -- DIV (turn off) |
---|
203 | // -- NonLinear (turn off ?) |
---|
204 | // -- solid angle (turn off ?) |
---|
205 | // -- dead time (keep on?) |
---|
206 | // |
---|
207 | // -- once calculated, update the Transmission panel |
---|
208 | // -- update the data file |
---|
209 | // -- update the CATALOG (and/or delete the RawVSANS to force a re-read) |
---|
210 | // |
---|
211 | Function V_CalcTransmButtonProc(ba) : ButtonControl |
---|
212 | STRUCT WMButtonAction &ba |
---|
213 | |
---|
214 | switch( ba.eventCode ) |
---|
215 | case 2: // mouse up |
---|
216 | // click code here |
---|
217 | |
---|
218 | Variable trans,trans_err |
---|
219 | Variable emptyCts,empty_ct_err,samCts,sam_ct_err |
---|
220 | String fileName,samFileName,emptyFileName |
---|
221 | String detStr |
---|
222 | |
---|
223 | |
---|
224 | // save preferences for file loading |
---|
225 | Variable savDivPref,savSAPref |
---|
226 | NVAR gDoDIVCor = root:Packages:NIST:VSANS:Globals:gDoDIVCor |
---|
227 | savDivPref = gDoDIVCor |
---|
228 | NVAR gDoSolidAngleCor = root:Packages:NIST:VSANS:Globals:gDoSolidAngleCor |
---|
229 | savSAPref = gDoSolidAngleCor |
---|
230 | |
---|
231 | // set local preferences |
---|
232 | gDoDIVCor = 0 |
---|
233 | gDoSolidAngleCor = 0 |
---|
234 | |
---|
235 | // check for sample transmission + error |
---|
236 | // if present -- exit |
---|
237 | ControlInfo/W=V_TransmissionPanel popup_0 |
---|
238 | fileName = S_Value |
---|
239 | trans = V_getSampleTransmission(fileName) |
---|
240 | trans_err = V_getSampleTransError(fileName) |
---|
241 | // // TODO |
---|
242 | // // -- this criteria is rather crude. think it through better |
---|
243 | // // -- or should I simply let it overwrite? What is the harm in that? |
---|
244 | // if(trans != 0 && trans < 1 && trans_err != 0) |
---|
245 | // Printf "Sample transmission, error = %g +/- %g already exists, nothing calculated\r",trans,trans_err |
---|
246 | // break |
---|
247 | // endif |
---|
248 | |
---|
249 | // for empty beam |
---|
250 | |
---|
251 | ControlInfo/W=V_TransmissionPanel popup_2 |
---|
252 | emptyFileName = S_Value |
---|
253 | |
---|
254 | emptyCts = V_getBoxCounts(emptyFileName) |
---|
255 | empty_ct_err = V_getBoxCountsError(emptyFileName) |
---|
256 | WAVE xyBoxW = V_getBoxCoordinates(emptyFileName) |
---|
257 | // TODO |
---|
258 | // -- need to get the panel string for the sum. |
---|
259 | // -- the detector string is currently hard-wired |
---|
260 | detStr = "B" |
---|
261 | |
---|
262 | // check for box count + error values |
---|
263 | // if present, proceed |
---|
264 | // TODO |
---|
265 | // -- this criteria is rather crude. think it through better |
---|
266 | if(emptyCts > 1 && empty_ct_err != 0) |
---|
267 | Printf "Empty beam box counts, error = %g +/- %g already exists, box counts not re-calculated\r",emptyCts,empty_ct_err |
---|
268 | |
---|
269 | else |
---|
270 | // else the counts have not been determined |
---|
271 | // read in the data file |
---|
272 | V_LoadAndPlotRAW_wName(emptyFileName) |
---|
273 | // convert raw->SAM |
---|
274 | V_Raw_to_work("SAM") |
---|
275 | V_UpdateDisplayInformation("SAM") |
---|
276 | |
---|
277 | // and determine box sum and error |
---|
278 | // store these locally |
---|
279 | emptyCts = V_SumCountsInBox(xyBoxW[0],xyBoxW[1],xyBoxW[2],xyBoxW[3],empty_ct_err,"SAM",detStr) |
---|
280 | |
---|
281 | Print "empty counts = ",emptyCts |
---|
282 | Print "empty err/counts = ",empty_ct_err/emptyCts |
---|
283 | |
---|
284 | // TODO |
---|
285 | // write these back to the file |
---|
286 | // (write locally?) |
---|
287 | |
---|
288 | endif |
---|
289 | |
---|
290 | // for Sample Transmission File |
---|
291 | |
---|
292 | ControlInfo/W=V_TransmissionPanel popup_1 |
---|
293 | samFileName = S_Value |
---|
294 | // check for box count + error values |
---|
295 | samCts = V_getBoxCounts(samFileName) |
---|
296 | sam_ct_err = V_getBoxCountsError(samFileName) |
---|
297 | // if present, proceed |
---|
298 | // TODO |
---|
299 | // -- this criteria is rather crude. think it through better |
---|
300 | if(samCts > 1 && sam_ct_err != 0) |
---|
301 | Printf "Sam Trans box counts, error = %g +/- %g already exists, nothing calculated\r",samCts,sam_ct_err |
---|
302 | |
---|
303 | else |
---|
304 | // else |
---|
305 | // read in the data file |
---|
306 | V_LoadAndPlotRAW_wName(samFileName) |
---|
307 | // convert raw->SAM |
---|
308 | V_Raw_to_work("SAM") |
---|
309 | V_UpdateDisplayInformation("SAM") |
---|
310 | |
---|
311 | // get the box coordinates |
---|
312 | // and determine box sum and error |
---|
313 | |
---|
314 | // store these locally |
---|
315 | samCts = V_SumCountsInBox(xyBoxW[0],xyBoxW[1],xyBoxW[2],xyBoxW[3],sam_ct_err,"SAM",detStr) |
---|
316 | |
---|
317 | Print "sam counts = ",samCts |
---|
318 | Print "sam err/counts = ",sam_ct_err/samCts |
---|
319 | |
---|
320 | // TODO |
---|
321 | // write these back to the file |
---|
322 | // (write locally?) |
---|
323 | endif |
---|
324 | |
---|
325 | //then calculate the transmission |
---|
326 | Variable empAttenFactor,emp_atten_err,samAttenFactor,sam_atten_err,attenRatio |
---|
327 | |
---|
328 | // get the attenuation factor for the empty beam |
---|
329 | empAttenFactor = V_getAttenuator_transmission(emptyFileName) |
---|
330 | emp_atten_err = V_getAttenuator_trans_err(emptyFileName) |
---|
331 | // get the attenuation factor for the sample transmission |
---|
332 | samAttenFactor = V_getAttenuator_transmission(samFileName) |
---|
333 | sam_atten_err = V_getAttenuator_trans_err(samFileName) |
---|
334 | AttenRatio = empAttenFactor/samAttenFactor |
---|
335 | // calculate the transmission |
---|
336 | // calculate the transmission error |
---|
337 | trans = samCts/emptyCts * AttenRatio |
---|
338 | |
---|
339 | // squared, relative error |
---|
340 | if(AttenRatio == 1) |
---|
341 | trans_err = (sam_ct_err/samCts)^2 + (empty_ct_err/emptyCts)^2 //same atten, att_err drops out |
---|
342 | else |
---|
343 | trans_err = (sam_ct_err/samCts)^2 + (empty_ct_err/emptyCts)^2 + (sam_atten_err/samAttenFactor)^2 + (emp_atten_err/empAttenFactor)^2 |
---|
344 | endif |
---|
345 | trans_err = sqrt(trans_err) |
---|
346 | trans_err *= trans // now, one std deviation |
---|
347 | |
---|
348 | //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity |
---|
349 | If(attenRatio==1) |
---|
350 | Printf "%s\t\tTrans Counts = %g\tTrans = %g +/- %g\r",fileName, samCts,trans,trans_err |
---|
351 | else |
---|
352 | Printf "%s\t\tTrans Counts = %g\tTrans = %g +/- %g\tAttenuatorRatio = %g\r",fileName, samCts,trans,trans_err,attenRatio |
---|
353 | endif |
---|
354 | |
---|
355 | // write both out to the sample *scattering* file on disk |
---|
356 | V_writeSampleTransmission(fileName,trans) |
---|
357 | V_writeSampleTransError(fileName,trans_err) |
---|
358 | |
---|
359 | // TODO |
---|
360 | // -- update the value displayed in the panel |
---|
361 | // -- update the local value in the file catalog |
---|
362 | // -- delete the file from RawVSANS to force a re-read? |
---|
363 | // SetVariable setvar_7,value= trans |
---|
364 | // SetVariable setvar_8,value= trans_err |
---|
365 | // DoUpdate/W=V_TransmissionPanel |
---|
366 | |
---|
367 | |
---|
368 | // done |
---|
369 | break |
---|
370 | case -1: // control being killed |
---|
371 | break |
---|
372 | endswitch |
---|
373 | |
---|
374 | // restore preferences on exit |
---|
375 | gDoDIVCor = savDivPref |
---|
376 | gDoSolidAngleCor = savSAPref |
---|
377 | |
---|
378 | |
---|
379 | return 0 |
---|
380 | End |
---|
381 | |
---|
382 | Function V_WriteTransmButtonProc(ba) : ButtonControl |
---|
383 | STRUCT WMButtonAction &ba |
---|
384 | |
---|
385 | switch( ba.eventCode ) |
---|
386 | case 2: // mouse up |
---|
387 | // click code here |
---|
388 | break |
---|
389 | case -1: // control being killed |
---|
390 | break |
---|
391 | endswitch |
---|
392 | |
---|
393 | return 0 |
---|
394 | End |
---|
395 | |
---|
396 | Function V_HelpTransmButtonProc(ba) : ButtonControl |
---|
397 | STRUCT WMButtonAction &ba |
---|
398 | |
---|
399 | switch( ba.eventCode ) |
---|
400 | case 2: // mouse up |
---|
401 | // click code here |
---|
402 | |
---|
403 | DoAlert 0,"Transmission Help not written yet" |
---|
404 | |
---|
405 | break |
---|
406 | case -1: // control being killed |
---|
407 | break |
---|
408 | endswitch |
---|
409 | |
---|
410 | return 0 |
---|
411 | End |
---|
412 | |
---|
413 | Function V_DoneTransmButtonProc(ba) : ButtonControl |
---|
414 | STRUCT WMButtonAction &ba |
---|
415 | |
---|
416 | switch( ba.eventCode ) |
---|
417 | case 2: // mouse up |
---|
418 | // click code here |
---|
419 | DoWindow/K V_TransmissionPanel |
---|
420 | break |
---|
421 | case -1: // control being killed |
---|
422 | break |
---|
423 | endswitch |
---|
424 | |
---|
425 | return 0 |
---|
426 | End |
---|
427 | |
---|