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

Last change on this file since 399 was 328, checked in by ajj, 15 years ago

Rearranging files

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