source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Transmission.ipf @ 1094

Last change on this file since 1094 was 1094, checked in by srkline, 5 years ago

corrected issues with transmission calculation where the popup menu of sample files was limited in number. this limitation has been removed.

fixed the re-calculation of transmission when the same value is to be patched to multiple sample files with the same group ID. now the transmission is calculated once, for the first file in the popup and the values are simply written to the remaining files.

when the box for the open beam is defined, the panel where it is located is written to the file in a new field under /reduction. it is later recalled in the transmission panel.

Defined a "Reference" beam center position for each carriage as the RIGHT panel center. then all other panel centers (L, T, B) can be derived from this value. if the beam center is measured on the Left panel, it is converted to "right" coordinates before reporting.

File size: 21.3 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5
6// TODO
7// x- 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// -- this still seems to be very awkward to use. Come up with something better
14//
15// -- need more checks - be sure that the files match
16// -- SDD, wavelength, beam on proper panel, etc.
17//
18// -- need popups (transmission, open) to respond to popup changes and
19//   update their fields, since they may be auto-located incorrectly.
20//
21// to patch the box coordinates
22// err = V_writeBoxCoordinates(fname,V_List2NumWave(str,";","inW"))
23
24
25
26//
27Function V_InitTransmissionPanel()
28       
29        DoWindow/F V_TransmissionPanel
30        if(V_Flag == 0)
31                V_InitTransPanelGlobals()
32                Execute "V_TransmissionPanel()"
33        endif
34End
35
36Function V_InitTransPanelGlobals()
37
38// root:Packages:NIST:VSANS:Globals:Transmission
39        NewDataFolder/O/S root:Packages:NIST:VSANS:Globals:Transmission
40        Variable/G gSamGrpID,gTrnGrpID,gTrans,gTransErr
41        String/G gSamLabel="file label",gTransLabel="file label",gEmptyLabel="file label"
42        String/G gEmptyBoxCoord="1;2;3;4;",gEmptyPanel="ENTER PANEL"
43        String/G gSamMatchList = "_none_"
44
45
46        SetDataFolder root:
47        return(0)
48End
49
50Window V_TransmissionPanel() : Panel
51        PauseUpdate; Silent 1           // building window...
52        NewPanel /W=(1496,366,1974,990) /K=1
53        ModifyPanel cbRGB=(32896,16448,0,19621)
54        DoWindow/C V_TransmissionPanel
55
56//      ShowTools/A
57        PopupMenu popup_0,pos={16.00,359.00},size={104.00,23.00},fstyle=1,fsize=12,proc=V_TSamFilePopMenuProc,title="Sample"
58        PopupMenu popup_0,mode=1,popvalue="_none_",value= #"root:Packages:NIST:VSANS:Globals:Transmission:gSamMatchList "
59        PopupMenu popup_1,pos={12.00,229.00},size={195.00,23.00},fstyle=1,fsize=12,proc=V_TTransmFilePopMenuProc,title="Transmission"
60        PopupMenu popup_1,mode=1,popvalue="sans3584.nxs.ngv",value= V_getFilePurposeList("TRANSMISSION",0)
61        PopupMenu popup_2,pos={17.00,79.00},size={188.00,23.00},fstyle=1,fsize=12,proc=V_TEmpBeamPopMenuProc,title="Open Beam"
62        PopupMenu popup_2,mode=1,popvalue="sans3584.nxs.ngv",value= V_getFileIntentList("OPEN BEAM",0)
63        Button button_0,pos={34.00,499.00},size={100.00,20.00},proc=V_CalcTransmButtonProc,title="Calculate"
64        Button button_2,pos={349.00,13.00},size={30.00,20.00},proc=V_HelpTransmButtonProc,title="?"
65        Button button_3,pos={410.00,13.00},size={50.00,20.00},proc=V_DoneTransmButtonProc,title="Done"
66        Button button_4,pos={164.00,500.00},size={150.00,20.00},proc=V_CalcTransmListButtonProc,title="Calculate All In Popup"
67        SetVariable setvar_0,pos={18.00,390.00},size={300.00,14.00},title="Label:"
68        SetVariable setvar_0,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gSamLabel
69        SetVariable setvar_1,pos={18.00,417.00},size={300.00,14.00},title="Group ID:"
70        SetVariable setvar_1,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gSamGrpID
71        SetVariable setvar_2,pos={15.00,257.00},size={300.00,14.00},title="Label:"
72        SetVariable setvar_2,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gTransLabel
73        SetVariable setvar_3,pos={14.00,283.00},size={300.00,14.00},title="Group ID:"
74        SetVariable setvar_3,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gTrnGrpID
75        SetVariable setvar_4,pos={18.00,108.00},size={300.00,14.00},title="Label:"
76        SetVariable setvar_4,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gEmptyLabel
77        SetVariable setvar_5,pos={18.00,132.00},size={300.00,14.00},title="XY Box:"
78        SetVariable setvar_5,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gEmptyBoxCoord
79        SetVariable setvar_6,pos={18.00,157.00},size={300.00,14.00},fstyle=1,fsize=12,title="Panel:"
80        SetVariable setvar_6,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gEmptyPanel
81        SetVariable setvar_7,pos={18.00,442.00},size={300.00,14.00},title="Transmission:"
82        SetVariable setvar_7,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gTrans
83        SetVariable setvar_8,pos={18.00,467.00},size={300.00,14.00},title="Error:"
84        SetVariable setvar_8,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gTransErr
85EndMacro
86
87
88//Window V_TransmissionPanel() : Panel
89//      PauseUpdate; Silent 1           // building window...
90//      NewPanel /W=(1286,328,1764,952)
91//      ModifyPanel cbRGB=(32896,16448,0,19621)
92//      DoWindow/C V_TransmissionPanel
93//
94////    ShowTools/A
95//      PopupMenu popup_0,pos={19.00,55.00},size={86.00,23.00},proc=V_TSamFilePopMenuProc,title="Sample"
96////    PopupMenu popup_0,mode=1,value= V_getFilePurposeList("SCATTERING",0)//+V_getFileIntentList("EMPTY CELL",0)
97//      PopupMenu popup_0,mode=1,value=root:Packages:NIST:VSANS:Globals:Transmission:gSamMatchList
98//      PopupMenu popup_1,pos={102,248},size={72.00,23.00},proc=V_TTransmFilePopMenuProc,title="Transmission"
99//      PopupMenu popup_1,mode=1,value= V_getFilePurposeList("TRANSMISSION",0)
100//      PopupMenu popup_2,pos={164,353},size={72.00,23.00},proc=V_TEmpBeamPopMenuProc,title="Open Beam"
101////    PopupMenu popup_2,mode=1,value= V_getFileIntentList("EMPTY BEAM",0)
102//      PopupMenu popup_2,mode=1,value= V_getFileIntentList("OPEN BEAM",0)
103//      Button button_0,pos={37,193},size={100.00,20.00},proc=V_CalcTransmButtonProc,title="Calculate"
104////    Button button_1,pos={23.00,491.00},size={100.00,20.00},proc=V_WriteTransmButtonProc,title="Write"
105//      Button button_2,pos={349.00,13.00},size={30.00,20.00},proc=V_HelpTransmButtonProc,title="?"
106//      Button button_3,pos={410.00,13.00},size={50.00,20.00},proc=V_DoneTransmButtonProc,title="Done"
107//      SetVariable setvar_0,pos={21.00,86.00},size={300.00,14.00},title="Label:"
108//      SetVariable setvar_0,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gSamLabel
109//      SetVariable setvar_1,pos={21.00,113.00},size={300.00,14.00},title="Group ID:"
110//      SetVariable setvar_1,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gSamGrpID
111//      SetVariable setvar_2,pos={105,276.00},size={300.00,14.00},title="Label:"
112//      SetVariable setvar_2,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gTransLabel
113//      SetVariable setvar_3,pos={104,302},size={300.00,14.00},title="Group ID:"
114//      SetVariable setvar_3,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gTrnGrpID
115//      SetVariable setvar_4,pos={165,382},size={300.00,14.00},title="Label:"
116//      SetVariable setvar_4,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gEmptyLabel
117//      SetVariable setvar_5,pos={165,406},size={300.00,14.00},title="XY Box:"
118//      SetVariable setvar_5,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gEmptyBoxCoord
119//      SetVariable setvar_6,pos={165,431},size={300.00,14.00},title="Panel:"
120//      SetVariable setvar_6,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gEmptyPanel
121//      SetVariable setvar_7,pos={21,138},size={300.00,14.00},title="Transmission:"
122//      SetVariable setvar_7,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gTrans
123//      SetVariable setvar_8,pos={21,163},size={300.00,14.00},title="Error:"
124//      SetVariable setvar_8,limits={-inf,inf,0},value= root:Packages:NIST:VSANS:Globals:Transmission:gTransErr
125//EndMacro
126
127// TODO
128// -- fill in the details
129// -- currently, I pick these from the Catalog, for speed
130// -- ? is the catalog current?
131// -- T error is not part of the Catalog - is that OK?
132//
133// when the SAM file menu is popped:
134//  fill in the fields:
135// x- label
136// x- group id
137// x- transmission
138// -- T error
139//
140Function V_TSamFilePopMenuProc(pa) : PopupMenuControl
141        STRUCT WMPopupAction &pa
142
143
144// **** TODO
145// short-circuit the switch, and simply report the values
146// -- the TransFile popup now drives the panel
147                SVAR gSamLabel = root:Packages:NIST:VSANS:Globals:Transmission:gSamLabel
148                gSamLabel = V_getSampleDescription(pa.popStr)
149                NVAR gSamGrpID = root:Packages:NIST:VSANS:Globals:Transmission:gSamGrpID
150                gSamGrpID = V_getSample_GroupID(pa.popStr)
151                NVAR gTrans = root:Packages:NIST:VSANS:Globals:Transmission:gTrans
152                gTrans = V_getSampleTransmission(pa.popStr)
153                NVAR gTransErr = root:Packages:NIST:VSANS:Globals:Transmission:gTransErr
154                gTransErr = V_getSampleTransError(pa.popStr)
155
156        return(0)       
157       
158//      switch( pa.eventCode )
159//              case 2: // mouse up
160//                      Variable popNum = pa.popNum
161//                      String popStr = pa.popStr
162//                     
163//                      Variable ii,np
164//                     
165//                      WAVE/T fileNameW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames
166//                      WAVE/T labelW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Labels
167//                      WAVE groupIDW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Group_ID
168//                      WAVE transmW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Transmission
169//                      WAVE/T intentW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent
170//                     
171//                      // TODO
172//                      // I don't have a wave for the transmission error value, so it's not displayed here
173//                      // -- do I read it in, or just ignore it...     
174//                      np = numpnts(labelW)            //fileNameW is LONGER - so don't use numpnts(fileWave)
175//                      for(ii=0;ii<np;ii+=1)
176//                              if(cmpstr(fileNameW[ii],popStr)==0)
177//                             
178//                                      SetVariable setvar_0,value=labelW[ii]
179//                                      SetVariable setvar_1,value=groupIDW[ii]
180//                                      SetVariable setvar_7,value=transmW[ii]
181//                                      break           //found, get out
182//                              endif           
183//                      endfor
184//             
185//              // loop back through to find the transmission file with the matching group id
186//              // TODO x- set the popup string to the matching name on exit
187//                      Variable targetID = groupIDW[ii]
188////                    String list = V_getFilePurposeList("TRANSMISSION",0)
189//                      String list = V_getFileIntentPurposeList("SAMPLE","TRANSMISSION",0)
190//                     
191//                      WAVE/T purposeW = root:Packages:NIST:VSANS:CatVSHeaderInfo:Purpose
192//                      for(ii=0;ii<np;ii+=1)
193//                              if(cmpstr(purposeW[ii],"TRANSMISSION")==0 && cmpstr(intentW[ii],"SAMPLE")==0 && groupIDW[ii] == targetID)
194//                                      Print "transmission file match at ",filenameW[ii]
195//                                      SetVariable setvar_2,value=labelW[ii]
196//                                      SetVariable setvar_3,value=groupIDW[ii]
197//                                      PopupMenu popup_1,mode=WhichListItem(fileNameW[ii], list )+1,popValue=fileNameW[ii]
198//                                      break
199//                              endif           
200//                      endfor
201//
202//              // now loop back through to find the empty beam file
203//              // TODO
204//              // x- fill in the XY box
205//              // x-  Detector Panel field is hard-wired for "B"
206//              // -- do I use "EMPTY BEAM", "OPEN BEAM" or both?? I think "OPEN BEAM" is what NICE will use in a drop-down menu
207//              //     
208////                    list = V_getFileIntentList("EMPTY BEAM",0)
209//                      list = V_getFileIntentList("OPEN BEAM",0)
210//                     
211//                      for(ii=0;ii<np;ii+=1)
212//                              if(cmpstr(intentW[ii],"OPEN BEAM")==0)
213//                                      Print "Open beam match at ",filenameW[ii]
214//                                      SetVariable setvar_4,value=labelW[ii]
215//                                      PopupMenu popup_2,mode=WhichListItem(fileNameW[ii], list )+1,popValue=fileNameW[ii]
216//                                     
217////                                    SetVariable setvar_6,value =_STR:"ML"
218//
219//                                      WAVE boxCoord = V_getBoxCoordinates(filenameW[ii])
220//                                      Print boxCoord
221//                                      SetVariable setvar_5,value=_STR:V_NumWave2List(boxCoord,";")
222//
223//                                     
224//                                      break
225//                              endif           
226//                      endfor
227//                                                             
228//                      break
229//              case -1: // control being killed
230//                      break
231//      endswitch
232
233        return 0
234End
235
236// TODO
237//
238// Given the group ID of the sample, try to locate a (the) matching transmission file
239// by locating a matching ID in the list of transmission (intent) files
240//
241// then pop the menu
242//
243//
244Function V_TTransmFilePopMenuProc(pa) : PopupMenuControl
245        STRUCT WMPopupAction &pa
246
247        switch( pa.eventCode )
248                case 2: // mouse up
249                        Variable popNum = pa.popNum
250                        String popStr = pa.popStr
251                       
252                        SVAR gTransLabel = root:Packages:NIST:VSANS:Globals:Transmission:gTransLabel
253                        gTransLabel = V_getSampleDescription(popStr)
254                        NVAR gTrnGrpID = root:Packages:NIST:VSANS:Globals:Transmission:gTrnGrpID
255                        gTrnGrpID = V_getSample_GroupID(popStr)                 
256                       
257                        SVAR gSamMatchList = root:Packages:NIST:VSANS:Globals:Transmission:gSamMatchList
258                        String quote = "\""
259                        gSamMatchList = quote + V_getFileIntentPurposeIDList("SAMPLE","SCATTERING",gTrnGrpID,0) + quote
260                        // this resets a global string, since I can't pass a parameter (only constants) in value=fn()           
261//                      PopupMenu popup_0,mode=1,value=#gSamMatchList
262                        PopupMenu popup_0,mode=1,value=V_getSamListForPopup()
263                       
264                        break
265                case -1: // control being killed
266                        break
267        endswitch
268
269        return 0
270End
271
272Function/S V_getSamListForPopup()
273
274//      String quote = "\""
275        NVAR gTrnGrpID = root:Packages:NIST:VSANS:Globals:Transmission:gTrnGrpID
276
277        return(V_getFileIntentPurposeIDList("SAMPLE","SCATTERING",gTrnGrpID,0))
278End
279
280Function V_TEmpBeamPopMenuProc(pa) : PopupMenuControl
281        STRUCT WMPopupAction &pa
282
283        switch( pa.eventCode )
284                case 2: // mouse up
285                        Variable popNum = pa.popNum
286                        String popStr = pa.popStr
287                       
288                        Print "empty beam match at ",popStr
289                        SetVariable setvar_4,value=_STR:V_getSampleDescription(popStr)
290                       
291
292                        WAVE boxCoord = V_getBoxCoordinates(popStr)
293                        Print boxCoord
294                        SetVariable setvar_5,value=_STR:V_NumWave2List(boxCoord,";")
295                       
296                        String detStr = V_getReduction_BoxPanel(popStr)
297                        SetVariable setvar_6,value =_STR:detStr
298                       
299                        break
300                case -1: // control being killed
301                        break
302        endswitch
303
304        return 0
305End
306
307
308// NOTE: DIV is not needed for the transmission calculation, since it's a ratio
309// and the DIV simply drops out. (DIV is needed for ABS scaling calculation of Kappa, since
310// that is not a ratio)
311//
312// TODO
313// -- figure out which detector corrections are necessary to do on loading
314// data for calculation. Then set/reset preferences accordingly
315// (see V_isoCorrectButtonProc() for example of how to do this)
316//
317//  -- DIV (turn off)
318// -- NonLinear (turn off ?)
319// -- solid angle (turn off ?)
320// -- dead time (keep on?)
321//
322// -- once calculated, update the Transmission panel
323// -- update the data file
324// -- update the CATALOG (and/or delete the RawVSANS to force a re-read)
325//
326Function V_CalcTransmButtonProc(ba) : ButtonControl
327        STRUCT WMButtonAction &ba
328
329        switch( ba.eventCode )
330                case 2: // mouse up
331                        // click code here
332
333                        String SamFile,TransFile,EmptyFile
334
335                        ControlInfo/W=V_TransmissionPanel popup_0
336                        SamFile = S_Value
337
338                        ControlInfo/W=V_TransmissionPanel popup_1
339                        TransFile = S_Value             
340               
341                        ControlInfo/W=V_TransmissionPanel popup_2
342                        EmptyFile = S_Value
343               
344                        V_CalcOneTransmission(SamFile,TransFile,EmptyFile)                     
345
346                       
347                        // done
348                        break
349                case -1: // control being killed
350                        break
351        endswitch
352
353
354        return 0
355End
356
357Function V_CalcTransmListButtonProc(ba) : ButtonControl
358        STRUCT WMButtonAction &ba
359
360        switch( ba.eventCode )
361                case 2: // mouse up
362                        // click code here
363
364                        SVAR gSamMatchList = root:Packages:NIST:VSANS:Globals:Transmission:gSamMatchList
365
366                        String SamFile,TransFile,EmptyFile
367
368                        ControlInfo/W=V_TransmissionPanel popup_1
369                        TransFile = S_Value             
370               
371                        ControlInfo/W=V_TransmissionPanel popup_2
372                        EmptyFile = S_Value
373               
374                        // gSamMatchStr has " at each end. remove these
375                        String list
376                        list = gSamMatchList
377                        list = list[1,strlen(list)-1]
378                        list = list[0,strlen(list)-2]
379                       
380                        Variable num,ii
381                        num = ItemsInList(list, ";")
382                        for(ii=0;ii<num;ii+=1)
383                                SamFile = StringFromList(ii, list, ";")
384                               
385                                if(ii==0)
386                                        // calculate the transmission for the first file
387                                        V_CalcOneTransmission(SamFile,TransFile,EmptyFile)     
388                                else
389                                        // then just write in the values (globals) that V_CalcOne determined
390                                        NVAR gTrans = root:Packages:NIST:VSANS:Globals:Transmission:gTrans
391                                        NVAR gTransErr = root:Packages:NIST:VSANS:Globals:Transmission:gTransErr
392                                       
393                                        // write both out to the sample *scattering* file on disk
394                                        V_writeSampleTransmission(SamFile,gTrans)
395                                        V_writeSampleTransError(SamFile,gTransErr)     
396
397                                endif           
398                        endfor
399                       
400                        Print "Done Processing Transmission List"
401
402                        // done
403                        break
404                case -1: // control being killed
405                        break
406        endswitch
407
408
409        return 0
410End
411
412
413
414Function V_CalcOneTransmission(SamFileName,TransFileName,EmptyFileName)                 
415        String SamFileName,TransFileName,EmptyFileName
416
417                Variable trans,trans_err
418                Variable emptyCts,empty_ct_err,samCts,sam_ct_err
419                String detStr
420               
421               
422                // save preferences for file loading
423                Variable savDivPref,savSAPref
424                NVAR gDoDIVCor = root:Packages:NIST:VSANS:Globals:gDoDIVCor
425                savDivPref = gDoDIVCor
426                NVAR gDoSolidAngleCor = root:Packages:NIST:VSANS:Globals:gDoSolidAngleCor
427                savSAPref = gDoSolidAngleCor
428               
429                // set local preferences
430                gDoDIVCor = 0
431                gDoSolidAngleCor = 0
432               
433                // check for sample transmission + error
434                // if present -- exit
435               
436                trans = V_getSampleTransmission(samfileName)
437                trans_err = V_getSampleTransError(samfileName)
438//                      // TODO
439//                      // -- this criteria is rather crude. think it through better
440//                      // -- or should I simply let it overwrite? What is the harm in that?
441//                      if(trans != 0 && trans < 1 && trans_err != 0)
442//                              Printf "Sample transmission, error = %g +/- %g   already exists, nothing calculated\r",trans,trans_err
443//                              break
444//                      endif
445               
446        // for empty beam               
447                emptyCts = V_getBoxCounts(emptyFileName)
448                empty_ct_err = V_getBoxCountsError(emptyFileName)
449                WAVE xyBoxW = V_getBoxCoordinates(emptyFileName)
450                // TODO
451                // x- need to get the panel string for the sum.
452                // x- the detector string is currently hard-wired
453                SVAR gEmptyPanel = root:Packages:NIST:VSANS:Globals:Transmission:gEmptyPanel
454                detStr = gEmptyPanel
455
456               
457                // check for box count + error values
458                // if present, proceed
459                // TODO
460                // -- this criteria is rather crude. think it through better
461                if(emptyCts > 1 && empty_ct_err != 0)
462                        Printf "Empty beam box counts, error = %g +/- %g   already exists, box counts not re-calculated\r",emptyCts,empty_ct_err
463                       
464                else
465                        // else the counts have not been determined
466                        // read in the data file
467                        V_LoadAndPlotRAW_wName(emptyFileName)
468                        // convert raw->SAM
469                        V_Raw_to_work("SAM")
470                        V_UpdateDisplayInformation("SAM")       
471                       
472                        // and determine box sum and error
473                        // store these locally
474                        emptyCts = V_SumCountsInBox(xyBoxW[0],xyBoxW[1],xyBoxW[2],xyBoxW[3],empty_ct_err,"SAM",detStr)
475       
476                        Print "empty counts = ",emptyCts
477                        Print "empty err/counts = ",empty_ct_err/emptyCts
478                       
479                        // TODO
480                        // write these back to the file
481                        // (write locally?)
482                       
483                endif
484
485        // for Sample Transmission File
486               
487                // check for box count + error values
488                samCts = V_getBoxCounts(TransFileName)
489                sam_ct_err = V_getBoxCountsError(TransFileName)
490                // if present, proceed
491                // TODO
492                // -- this criteria is rather crude. think it through better
493                if(samCts > 1 && sam_ct_err != 0)
494                        Printf "Sam Trans box counts, error = %g +/- %g   already exists, nothing calculated\r",samCts,sam_ct_err
495                       
496                else
497                        // else
498                        // read in the data file
499                        V_LoadAndPlotRAW_wName(TransFileName)
500                        // convert raw->SAM
501                        V_Raw_to_work("SAM")
502                        V_UpdateDisplayInformation("SAM")       
503                       
504                        // get the box coordinates
505                        // and determine box sum and error
506                       
507                        // store these locally
508                        samCts = V_SumCountsInBox(xyBoxW[0],xyBoxW[1],xyBoxW[2],xyBoxW[3],sam_ct_err,"SAM",detStr)
509       
510                        Print "sam counts = ",samCts
511                        Print "sam err/counts = ",sam_ct_err/samCts
512                       
513                        // TODO
514                        // write these back to the file
515                        // (write locally?)     
516                endif
517               
518        //then calculate the transmission
519                Variable empAttenFactor,emp_atten_err,samAttenFactor,sam_atten_err,attenRatio
520               
521                // get the attenuation factor for the empty beam
522                empAttenFactor = V_getAttenuator_transmission(emptyFileName)
523                emp_atten_err = V_getAttenuator_trans_err(emptyFileName)
524                // get the attenuation factor for the sample transmission
525                samAttenFactor = V_getAttenuator_transmission(TransFileName)
526                sam_atten_err = V_getAttenuator_trans_err(TransFileName)       
527                AttenRatio = empAttenFactor/samAttenFactor             
528                // calculate the transmission
529                // calculate the transmission error
530                trans = samCts/emptyCts * AttenRatio
531                                       
532                // squared, relative error
533                if(AttenRatio == 1)
534                        trans_err = (sam_ct_err/samCts)^2 + (empty_ct_err/emptyCts)^2           //same atten, att_err drops out
535                else
536                        trans_err = (sam_ct_err/samCts)^2 + (empty_ct_err/emptyCts)^2 + (sam_atten_err/samAttenFactor)^2 + (emp_atten_err/empAttenFactor)^2
537                endif
538                trans_err = sqrt(trans_err)
539                trans_err *= trans              // now, one std deviation
540               
541                //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity
542                If(attenRatio==1)
543                        Printf "%s\t\tTrans Counts = %g\tTrans = %g +/- %g\r",SamFileName, samCts,trans,trans_err
544                else
545                        Printf "%s\t\tTrans Counts = %g\tTrans = %g +/- %g\tAttenuatorRatio = %g\r",SamFileName, samCts,trans,trans_err,attenRatio
546                endif
547               
548                // write both out to the sample *scattering* file on disk
549                V_writeSampleTransmission(SamFileName,trans)
550                V_writeSampleTransError(SamFileName,trans_err) 
551               
552                // (DONE)
553                // x- update the value displayed in the panel
554                // (NO) update the local value in the file catalog
555                // x- delete the file from RawVSANS to force a re-read?
556                NVAR gTrans = root:Packages:NIST:VSANS:Globals:Transmission:gTrans
557                gTrans = trans
558                NVAR gTransErr = root:Packages:NIST:VSANS:Globals:Transmission:gTransErr
559                gTransErr = trans_err
560
561                V_KillNamedDataFolder(V_RemoveDotExtension(samFileName))
562
563        // restore preferences on exit
564        gDoDIVCor = savDivPref
565        gDoSolidAngleCor = savSAPref
566
567        return(0)                       
568
569End
570
571
572
573
574
575
576
577Function V_WriteTransmButtonProc(ba) : ButtonControl
578        STRUCT WMButtonAction &ba
579
580        switch( ba.eventCode )
581                case 2: // mouse up
582                        // click code here
583                        break
584                case -1: // control being killed
585                        break
586        endswitch
587
588        return 0
589End
590
591Function V_HelpTransmButtonProc(ba) : ButtonControl
592        STRUCT WMButtonAction &ba
593
594        switch( ba.eventCode )
595                case 2: // mouse up
596                        // click code here
597                       
598                        DoAlert 0,"Transmission Help not written yet"
599                       
600                        break
601                case -1: // control being killed
602                        break
603        endswitch
604
605        return 0
606End
607
608Function V_DoneTransmButtonProc(ba) : ButtonControl
609        STRUCT WMButtonAction &ba
610
611        switch( ba.eventCode )
612                case 2: // mouse up
613                        // click code here
614                        DoWindow/K V_TransmissionPanel
615                        break
616                case -1: // control being killed
617                        break
618        endswitch
619
620        return 0
621End
622
Note: See TracBrowser for help on using the repository browser.