source: sans/Dev/trunk/NCNR_User_Procedures/USANS/COR_Graph.ipf @ 404

Last change on this file since 404 was 404, checked in by ajj, 14 years ago

Refactoring USANS functions to use root:Packages:NIST:USANS as their base to comply with canSAS proposal.

  • Property eol-style set to native
  • Property svn:executable set to *
File size: 16.3 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma Version=2.20
3#pragma IgorVersion=6.0
4
5////////////////////////////
6// 101001 Vers. 1
7//
8// procedures to plot the sma, emp, and cor data
9// - user interaction is through control bar on COR_Graph
10// - provides user with feedback about peak angle, transmissions
11// - asks for information about BKG and EMP levels
12// - asks for sample thickness
13// - interactively selects range of data to save (and type)
14// - dispatches to routines to determine transmissions and correct the data
15// - dispatches to save routines
16//
17/////////////////////////////
18
19
20//plot all that is available in the root:Graph folder
21// no distinction as to what the status of the data really is
22// "Clr" buttons on the USANS_Panel will clear the graph..
23//
24Function DoCORGraph()
25
26        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
27       
28        DoWindow/F COR_Graph
29        if(V_flag==0)
30                //draw the blank window and the control bar
31                Display /W=(5,42,450,500) /K=1
32                DoWindow/C COR_Graph
33                ControlBar 100
34                SetVariable gTransWide,pos={210,12},size={135,15},title="Trans - Wide",format="%5.4f"
35                SetVariable gTransWide,help={"Average counts on transmssion detector at wide angles"}
36                SetVariable gTransWide,limits={0,1,0.001},value= $(USANSFolder+":Globals:MainPanel:gTransWide")
37                SetVariable gTransRock,pos={210,27},size={135,15},title="Trans - Rock",format="%5.4f"
38                SetVariable gTransRock,help={"Transmission counts at the zero-angle peak"}
39                SetVariable gTransRock,limits={0,1,0.001},value= $(USANSFolder+":Globals:MainPanel:gTransRock")
40                SetVariable gEmpCts,pos={210,42},size={135,15},title="EMP Level",format="%7.4f"
41                SetVariable gEmpCts,limits={-Inf,Inf,0.1},value= $(USANSFolder+":Globals:MainPanel:gEmpCts")
42                SetVariable gEmpCts,help={"High q limit of empty cell scattering normalized to 1.0e6 monitor counts"}
43                SetVariable gBkgCts,pos={210,57},size={135,15},title="BKG Level",format="%7.4f"
44                SetVariable gBkgCts,limits={-Inf,Inf,0.1},value= $(USANSFolder+":Globals:MainPanel:gBkgCts")
45                SetVariable gBkgCts,help={"Background scattering level normalized to 1.0e6 monitor counts"}
46                SetVariable gThick,pos={210,72},size={135,15},title="SAM Thick(cm)",format="%5.4f"
47                SetVariable gThick,help={"Thickness of the sample in centimeters"}
48                SetVariable gThick,limits={0,5,0.01},value= $(USANSFolder+":Globals:MainPanel:gThick")
49                Button UpdateButton,pos={115,19},size={88,20},proc=UpdateButtonProc,title="Update Trans"
50                Button UpdateButton,help={"Updates both the wide and rocking transmission values based on the raw data files"}
51                Button CorrectButton,pos={115,53},size={88,20},proc=CorrectButtonProc,title="Correct Data"
52                Button CorrectButton,help={"Corrects the sample data by subtracting empty cell and backgrond scattering"}
53                Button SaveDataButton,pos={355,3},size={85,20},proc=SaveButtonProc,title="Save Data..."
54                Button SaveDataButton,help={"Saves the selected data type to disk in ASCII format"}
55                CheckBox useCrsrCheck,pos={360,27},size={119,14},proc=UseCrsrCheckProc,title="Use Cursors?"
56                CheckBox useCrsrCheck,value= 0
57                CheckBox useCrsrCheck,help={"Adds cursors to the datset to select the range of data points to save"}
58                CheckBox CORCheck,pos={380,44},size={40,14},title="COR",value=1,proc=TypeToggleCheckProc,mode=1
59                CheckBox CORCheck,help={"Selects COR data as the saved type"}
60                CheckBox SAMCheck,pos={380,60},size={40,14},title="SAM",value=0,proc=TypeToggleCheckProc,mode=1
61                CheckBox SAMCheck,help={"Selects SAM data s the saved type"}
62                CheckBox EMPCheck,pos={380,76},size={40,14},title="EMP",value= 0,proc=TypeToggleCheckProc,mode=1
63                CheckBox EMPCheck,help={"Selects EMP data as the saved type"}
64                Button qpkButton,pos={12,61},size={90,20},proc=QpkButtonProc,title="Change Qpk"
65                Button qpkButton,help={"Use this to override the automatically determined peak locations in SAM or EMP datasets"}
66                ValDisplay valdispSAM,pos={10,15},size={100,14},title="Qpk SAM",format="%1.3f"
67                ValDisplay valdispSAM,limits={0,0,0},barmisc={0,1000},value=QpkFromNote("SAM")
68                ValDisplay valdispSAM,help={"Displays the peak angle the raw SAM data, determined automatically"}
69                ValDisplay valdispEMP,pos={10,36},size={100,14},title="Qpk EMP",format="%1.3f"
70                ValDisplay valdispEMP,limits={0,0,0},barmisc={0,1000},value=QpkFromNote("EMP")
71                ValDisplay valdispEMP,help={"Displays the peak angle the raw EMP data, determined automatically"}
72       
73                Legend
74        Endif
75        // add each data type to the graph, if possible (each checks on its own)
76        //SAM
77        GraphSAM()
78        //EMP
79        GraphEMP()
80        //COR
81        GraphCOR()
82        //EMP and BKG levels
83        GraphEMPBKGLevels()
84       
85        ControlUpdate/A/W=COR_Graph
86       
87        ModifyGraph log(left)=1,mirror=2,grid=1,standoff=0
88        ModifyGraph tickUnit=1
89        Label left "(Counts/sec)/(MON*10\\S6\\M)"
90        Label bottom "q (A\\S-1\\M)"
91       
92        return(0)
93End
94
95// add SAM data to the graph if it exists and is not already on the graph
96//
97Function GraphSAM()
98
99        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
100
101        //is it already on the graph?
102        SetDataFolder $(USANSFolder+":Graph")
103        String list=""
104        list = Wavelist("DetCts_SAM*",";","WIN:COR_Graph")
105        if(strlen(list)!=0)
106                //Print "SAM already on graph"
107                return(0)
108        Endif
109        //append the data if it exists
110        If(waveExists($"DetCts_SAM")==1)
111                DoWindow/F COR_Graph
112                AppendToGraph DetCts_SAM vs Qvals_SAM
113                ModifyGraph rgb(DetCts_SAM)=(1,12815,52428)
114                ModifyGraph mode(DetCts_SAM)=3,marker(DetCts_SAM)=19,msize(DetCts_SAM)=2
115                ModifyGraph tickUnit=1
116                ErrorBars DetCts_SAM Y,wave=(ErrDetCts_SAM,ErrDetCts_SAM)
117        endif
118        SetDataFolder root:
119End
120
121// add EMP data to the graph if it exists and is not already on the graph
122//
123Function GraphEMP()
124
125        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
126
127        SetDataFolder $(USANSFolder+":Graph")
128        String list=""
129        list = Wavelist("DetCts_EMP*",";","WIN:COR_Graph")
130        if(strlen(list)!=0)
131        //      Print "EMP already on graph"
132                return(0)
133        Endif
134        //append the data if it exists
135        If(waveExists($"DetCts_EMP")==1)
136                DoWindow/F COR_Graph
137                AppendToGraph DetCts_EMP vs Qvals_EMP
138                ModifyGraph msize(DetCts_EMP)=2,rgb(DetCts_EMP)=(1,39321,19939)
139                ModifyGraph mode(DetCts_EMP)=3,marker(DetCts_EMP)=19
140                ModifyGraph tickUnit=1
141                ErrorBars DetCts_EMP Y,wave=(ErrDetCts_EMP,ErrDetCts_EMP)
142        endif
143        SetDataFolder root:
144        return(0)
145End
146
147// add COR data to the graph if it exists and is not already on the graph
148//
149Function GraphCOR()
150        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
151
152        SetDataFolder $(USANSFolder+":Graph")
153       
154        String list=""
155        list = Wavelist("DetCts_COR*",";","WIN:COR_Graph")
156        if(strlen(list)!=0)
157        //      Print "COR already on graph"
158                return(0)
159        Endif
160        //append the data if it exists
161        If(waveExists($"DetCts_COR")==1)
162                DoWindow/F COR_Graph
163                AppendToGraph DetCts_COR vs Qvals_COR
164                ModifyGraph msize(DetCts_COR)=2,rgb(DetCts_COR)=(52428,34958,1)
165                ModifyGraph mode(DetCts_COR)=3,marker(DetCts_COR)=19
166                ModifyGraph tickUnit=1
167                ErrorBars DetCts_COR Y,wave=(ErrDetCts_COR,ErrDetCts_COR)
168        endif
169
170        SetDataFolder root:
171        return(0)
172End
173
174// add horizoontal lines for the background and empty cell levels
175Function GraphEMPBKGLevels()
176
177        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
178
179        //if the data is on the graph, remove them and replot, to properly reset the scale
180        DoUpdate
181        String list = TraceNameList("COR_Graph",";",1)
182        //Print list
183        DoWindow/F COR_Graph
184        if(stringmatch(list,"*empLevel*")==1)
185                //remove
186                RemoveFromGraph empLevel,bkgLevel
187        Endif
188        DoUpdate
189        AppendToGraph $(USANSFolder+":EMP:EMPLevel"),$(USANSFolder+":BKG:BKGLevel")
190        ModifyGraph rgb(empLevel)=(0,0,0),lsize(bkgLevel)=2,rgb(bkgLevel)=(52428,1,1)
191        ModifyGraph lsize(empLevel)=2,offset={0,0}
192        ModifyGraph tickUnit=1
193        GetAxis/W=COR_Graph/Q bottom
194        SetScale/I x V_min,V_max,"",$(USANSFolder+":EMP:EMPLevel"),$(USANSFolder+":BKG:BKGLevel")
195        return(0)
196End
197
198// polls the control bar for proper selections of SavePath
199// checks for selected dataset from radio buttons
200// obtains the poin numbers from the cursors, if selected
201// dispatches to save routine
202//
203Function SaveButtonProc(ctrlName) : ButtonControl
204        String ctrlName
205
206        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
207       
208        PathInfo/S savePathName
209        if(V_Flag==0)
210                DoAlert 0,"Pick a \"SavePath...\"\rNo data file has been written"
211                return(1)
212        Endif
213       
214        String type=""
215        Variable useCrsrs=0,ptA=0,ptB=0
216       
217        //check for data save type (controlled by radio buttons)
218        NVAR gRadioVal=$(USANSFolder+":Globals:MainPanel:gTypeCheck")           //1=COR,2=SAM,3=EMP
219        switch(gRadioVal)
220                case 1: //COR
221                        type="COR"
222                        break                           
223                case 2: //SAM
224                        type="SAM"
225                        break
226                case 3: //EMP
227                        type="EMP"
228                        break   
229                default:
230                        DoAlert 0,"No Radio button selected\rNo data file written"
231                        return(1)
232        endswitch
233       
234        //check for data save between cursors
235        ControlInfo UseCrsrCheck
236        useCrsrs = V_Value              //1 if checked
237        //if so, read off the point range (cursors should be on the same wave as the save type)
238        if(useCrsrs)
239                Wave xwave=$(USANSFolder+":Graph:Qvals_"+type)
240                ptA=x2pnt(xwave,xcsr(A))
241                ptB=x2pnt(xwave,xcsr(B))
242                if(ptA>ptB)
243                        ptA=x2pnt(xwave,xcsr(B))
244                        ptB=x2pnt(xwave,xcsr(A))
245                endif
246                ptA=trunc(ptA)  //make sure it's integer
247                ptB=trunc(ptB)
248                //Print ptA,ptB
249        endif
250       
251        //fill in the blanks and dispatch to save routine
252        WriteUSANSWaves(type,"",ptA,ptB,1)
253       
254        return(0)
255End
256
257//show/hide cursors depending on the checkbox selection
258//put cursors on the selected save data type
259Function UseCrsrCheckProc(ctrlName,checked) : CheckBoxControl
260        String ctrlName
261        Variable checked
262       
263        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
264       
265        NVAR gRadioVal=$(USANSFolder+":Globals:MainPanel:gTypeCheck")           //1=COR,2=SAM,3=EMP
266        String type=""
267        switch(gRadioVal)
268                case 1: //COR
269                        type="COR"
270                        break                           
271                case 2: //SAM
272                        type="SAM"
273                        break
274                case 3: //EMP
275                        type="EMP"
276                        break   
277                default:
278                        DoAlert 0,"No Radio button selected\rCan't place cursors"
279                        return(1)
280        endswitch
281        if(checked)
282                //show info and cursors, if the wave in on the graph
283                String str,yname
284                str=TraceNameList("", ";", 1)
285                yname="DetCts_"+type
286                Variable ok=WhichListItem(yname, str,";",0)
287                if(ok != -1)
288                        Wave ywave=$(USANSFolder+":Graph:DetCts_"+type)
289                        Showinfo/W=COR_Graph
290                        Cursor/A=1/P/S=1 A,$yname,0
291                        Cursor/A=0/P/S=1 B,$yname,numpnts(ywave)-1
292                else
293                        //trace is not on graph
294                        CheckBox $ctrlName, value=0             //not checked
295                        HideInfo/W=COR_Graph
296                        Cursor/K A
297                        Cursor/K B
298                        DoAlert 0,type+" data is not on the graph"
299                endif
300        else
301                //hide info and cursors, if there are any displayed
302                HideInfo/W=COR_Graph
303                Cursor/K A
304                Cursor/K B
305        endif
306        DoUpdate
307End
308
309//radio button control of save type
310//sets global, so buttons don't need to be polled
311Function TypeToggleCheckProc(ctrlName,checked) : CheckBoxControl
312        String ctrlName
313        Variable checked
314
315        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
316
317        NVAR gRadioVal=$(USANSFolder+":Globals:MainPanel:gTypeCheck")
318       
319        strswitch(ctrlName)
320                case "CORCheck":
321                        gRadioVal=1
322                        break
323                case "SAMCheck":
324                        gRadioVal=2
325                        break
326                case "EMPCheck":
327                        gRadioVal=3
328                        break
329        endswitch
330        CheckBox CORCheck,value= (gRadioVal==1)
331        CheckBox SAMCheck,value= (gRadioVal==2)
332        CheckBox EMPCheck,value= (gRadioVal==3)
333       
334        //move the cursors to the correct trace on the graph
335        ControlInfo useCrsrCheck
336        checked=V_Value
337        UseCrsrCheckProc("useCrsrCheck",V_Value)
338End
339
340//updates the trans values and the bkg/empty values on the graph, if necessary
341//calculate the T_Wide and T_Rock from the wave notes
342// if there is an error in the wave notes, "NaN" will typically be returned
343//
344Function UpdateButtonProc(ctrlName) : ButtonControl
345        String ctrlName
346
347        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
348       
349        Wave samCts=$(USANSFolder+":SAM:DetCts")
350        Wave empCts=$(USANSFolder+":EMP:DetCts")
351        if((WaveExists(samCts)==0) || (WaveExists(empCts)==0))
352                Variable/G $(USANSFolder+":Globals:MainPanel:gTransWide")=NaN           //error
353                Variable/G $(USANSFolder+":Globals:MainPanel:gTransRock")=NaN
354                return(1)
355        Endif
356        //get the wave notes, and the transCt values
357        String samNote=note(samCts),empNote=note(empCts)
358        Variable samWide,empWide,samRock,empRock
359        samWide = NumberByKey("TWIDE",samNote,":",";")
360        empWide = NumberByKey("TWIDE",empNote,":",";")
361        samRock = NumberByKey("PEAKVAL",samNote,":",";")
362        empRock = NumberByKey("PEAKVAL",empNote,":",";")
363        Variable/G $(USANSFolder+":Globals:MainPanel:gTransWide")=samWide/empWide
364        Variable/G $(USANSFolder+":Globals:MainPanel:gTransRock")=samRock/empRock
365       
366        return(0)
367End
368
369// dispatches to the function to perform the data correction
370//
371Function CorrectButtonProc(ctrlName) : ButtonControl
372        String ctrlName
373       
374        DoCorrectData()
375        return(0)
376End
377
378//button to present a simple input dialog to ask the user for the data type
379// (either SAM or EMP) and the new value of the peak angle to use.
380//
381// rarely needed, but sometimes the data can fool IGOR, and no peak can be found
382// in some cases, data may not cover the primary beam. In both of these cases it
383// is necessary to manually override the peak angle
384//
385// calls RePlotWithUserAngle to "re-do" everything
386//
387Function QpkButtonProc(ctrlName) : ButtonControl
388        String ctrlName
389       
390        Variable newPkAngle=0
391        String dataSet="SAM;EMP;",type=""
392       
393        Prompt type,"Select Data Set",popup,dataSet
394        Prompt newPkAngle, "Enter new peak ANGLE, in Degrees"
395        DoPrompt "Override the peak angle",type,newPkAngle
396        //Print newPkAngle,type
397        if(V_Flag==1)           //user cancel, exit
398                return(1)
399        endif
400        //with the new information (type and angle) re-do the whole mess
401        //...as if the "plot" button was hit, except that the angle is known...
402       
403        RePlotWithUserAngle(type,newPkAngle)
404End
405
406//returns the peak location found (and used) for zero angle
407//displayed on the COR_Graph
408Function QpkFromNote(type)
409        String type
410
411        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
412               
413        Wave/Z detCts=$(USANSFolder+":Graph:DetCts_"+type)
414        if(!WaveExists(detCts))
415                return(NaN)
416        Endif
417        String str=note(detcts)
418        Variable val
419       
420        val=NumberByKey("PEAKANG", str,":",";")
421        return(val)
422End
423
424//nearly identical to PlotSelectedSAMButtonProc
425// - re-loads the data and goes through all the steps as it they were new datsets
426// - DOES NOT try to find the peak angle, instead uses the input zeroAngle
427// - replaces the PEAKANG:value with the input zeroAngle
428// updates the plot with the corrected angle
429//
430Function RePlotWithUserAngle(type,zeroAngle)
431        String type
432        Variable zeroAngle
433
434        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
435       
436        //SETS the wave note with the PEAKANG value
437       
438        //loads each of the data files
439        //normalizes each file to countrate immediately
440        //appends them to the individual waves in "SAM" folder
441        //sorts by angle
442        //converts to Q-values USING SUPPLIED ANGLE
443        //
444        //get selected files from listbox (everything)
445        //use the listBox wave directly
446       
447        Wave/T listW=$(USANSFolder+":Globals:MainPanel:"+type+"Wave")
448        Variable ii,num=numpnts(listW)
449        String fname="",fpath=""
450        PathInfo bt5PathName
451        fpath = S_Path
452       
453        //load, normalize, and append
454        //loop over the number of items in the list
455        for(ii=0;ii<num;ii+=1)
456                fname = fpath + listw[ii]
457                LoadBT5File(fname,"SWAP")       //overwrite what's in the SWAP folder
458                Convert2Countrate("SWAP")
459                if(ii==0)       //first time, overwrite
460                        NewDataWaves("SWAP",type)
461                else            //append to waves in TYPE folder
462                        AppendDataWaves("SWAP",type)
463                endif
464        endfor
465        //sort after all loaded
466        DoAngleSort(type)
467       
468        //find the peak and convert to Q-values
469        //Variable zeroAngle = FindZeroAngle("SAM")
470        //if(zeroAngle == -9999)
471                //DoAlert 0,"Couldn't find a peak - using zero as zero angle"
472        //      zeroAngle = 0
473        //Endif
474       
475        //find the peak value at the supplied angle, rather than automatic...
476        Wave tmpangle = $(USANSFolder+":"+type+":Angle")
477        Wave tmpdetCts = $(USANSFolder+":"+type+":DetCts")
478        Variable pkHt=0
479        pkHt = interp(zeroAngle,tmpangle,tmpdetcts)
480        String str=""
481        str=note(tmpDetCts)
482        str = ReplaceNumberByKey("PEAKANG",str,zeroAngle,":",";")
483        str = ReplaceNumberByKey("PEAKVAL",str,pkHt,":",";")
484        Note/K tmpDetCts
485        Note tmpdetCts,str
486       
487        ConvertAngle2Qvals(type,zeroAngle)
488        //find the Trans Cts for T_Wide
489        FindTWideCts(type)
490        //
491        //copy the data to plot to the root:Graph directory, and give clear names
492        if(WaveExists($(USANSFolder+":"+type+":Qvals")))
493                Duplicate/O $(USANSFolder+":"+type+":Qvals"),$(USANSFolder+":Graph:Qvals_"+type)
494        Endif
495        Duplicate/O $(USANSFolder+":"+type+":Angle"),$(USANSFolder+":Graph:Angle_"+type)
496        Duplicate/O $(USANSFolder+":"+type+":DetCts"),$(USANSFolder+":Graph:DetCts_"+type)
497        Duplicate/O $(USANSFolder+":"+type+":ErrDetCts"),$(USANSFolder+":Graph:ErrDetCts_"+type)
498       
499        //now plot the data (or just bring the graph to the front)
500        DoCORGraph()
501       
502        //update the valDisplays
503        ControlUpdate/A/W=COR_Graph             //overkill, does them all
504End
Note: See TracBrowser for help on using the repository browser.