source: sans/USANSReduction/trunk/Put in User Procedures Folder/USANS Procedures v2.20/COR_Graph.ipf @ 51

Last change on this file since 51 was 35, checked in by ajj, 16 years ago

Set pragma = 2.20 and required version >= 2.20 for includes in USANS_Includes.ipf

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