source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Marquee_Operations.ipf @ 1032

Last change on this file since 1032 was 1032, checked in by srkline, 6 years ago

made the file selections in the test protocol panel to be popup menus with the filtered files for each step. popping now selects the file. Still a work in progress.

File size: 6.6 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5// TODO:
6// x- get BoxSum Operational, for rudimentary Transmission calculations and ABS scale
7// x- need to be able to identify the detector panel from the Marquee selection
8// x- then do the count in (unscaled) coordinates of the actual data array
9//
10//
11// -- still many operations in (SANS)Marquee.ipf that will be useful to implement:
12//
13// -- writing the box coordinates and the counts (and error) to the data file
14// -- determining the beam center (centroid) of the selection + writing this to the file
15//  -- a box sum over a range of files (with a plot)
16// -- box sum over annular regions
17// -- box sum over arcs
18// --  saving Graphics image
19// -- histogram of the counts
20//
21//
22//
23
24
25
26
27//
28//function will print marquee coordinates in axis terms, not detector terms
29//
30// will also calculate the sum in the box, and the error, and print it out
31//
32Function V_PrintMarqueeCoords() :  GraphMarquee
33        GetMarquee left,bottom
34        if(V_flag == 0)
35                Print "There is no Marquee"
36        else
37                Variable count,x1,x2,y1,y2,ct_err
38                x1 = V_left
39                x2 = V_right
40                y1 = V_bottom
41                y2 = V_top
42                printf "marquee left in bottom axis terms: %g\r",round(V_left)
43                printf "marquee right in bottom axis terms: %g\r",round(V_right)
44                printf "marquee bottom in left axis terms: %g\r",round(V_bottom)
45                printf "marquee top in left axis terms: %g\r",round(V_top)
46//              printf "**note that you must add 1 to each axis coordinate to get detector coordinates\r"
47               
48                // NOTE:
49                // this function MODIFIES x and y values on return, converting them to panel coordinates
50                // detector panel is identified from the (left,top) coordinate (x1,y2)
51                String detStr = V_FindDetStrFromLoc(x1,x2,y1,y2)               
52//              Printf "Detector = %s\r",detStr
53
54//
55                SVAR gCurDispType = root:Packages:NIST:VSANS:Globals:gCurDispType       
56                // this function will modify the x and y values (passed by reference) as needed to keep on the panel
57                V_KeepSelectionInBounds(x1,x2,y1,y2,detStr,gCurDispType)
58                Print x1,x2,y1,y2
59
60
61                count = V_SumCountsInBox(x1,x2,y1,y2,ct_err,gCurDispType,detStr)
62               
63                Print "counts = ",count
64                Print "err/counts = ",ct_err/count
65
66        endif
67End
68
69
70// NOTE:
71// this function MODIFIES x and y values on return, converting them to panel coordinates
72// detector panel is identified from the (left,top) coordinate (x1,y2)
73Function/S V_FindDetStrFromLoc(x1,x2,y1,y2)
74        Variable &x1,&x2,&y1,&y2
75       
76        // which images are here?
77        String detStr="",imStr,carriageStr
78        String currentImageRef,activeSubwindow,imageList
79        Variable ii,nIm,testX,testY,tab
80       
81        // which tab is selected? -this is the main graph panel (subwindow may not be the active one!)
82        ControlInfo/W=VSANS_Data tab0
83        tab = V_Value
84        if(tab == 0)
85                activeSubwindow = "VSANS_Data#det_panelsF"
86        elseif (tab == 1)
87                activeSubwindow = "VSANS_Data#det_panelsM"
88        else
89                activeSubwindow = "VSANS_Data#det_panelsB"
90        endif
91       
92        imageList = ImageNameList(activeSubwindow,";") 
93
94        nIm = ItemsInList(imageList,";")
95        if(nIm==0)
96                return("")              //problem, get out
97        endif
98
99        // images were added in the order TBLR, so look back through in the order RLBT, checking each to see if
100        // the xy value is found on that (scaled) array
101                               
102        // loop backwards through the list of panels (may only be one if on the back)
103        for(ii=nIm-1;ii>=0;ii-=1)
104                Wave w = ImageNameToWaveRef(activeSubwindow,StringFromList(ii, imageList,";"))
105               
106                // which, if any image is the mouse xy location on?
107                // use a multidemensional equivalent to x2pnt: (ScaledDimPos - DimOffset(waveName, dim))/DimDelta(waveName,dim)
108
109               
110                testX = ScaleToIndex(w,x1,0)
111                testY = ScaleToIndex(w,y2,1)
112               
113                if( (testX >= 0 && testX < DimSize(w,0)) && (testY >= 0 && testY < DimSize(w,1)) )
114                        // we're in-bounds on this wave
115                       
116                        // deduce the detector panel
117                        currentImageRef = StringFromList(ii, imageList,";")     //the image instance ##
118                        // string is "data", or "data#2" etc. - so this returns "", "1", "2", or "3"
119                        imStr = StringFromList(1, currentImageRef,"#")         
120                        carriageStr = activeSubWindow[strlen(activeSubWindow)-1]
121                       
122                        if(cmpstr(carriageStr,"B")==0)
123                                detStr = carriageStr
124                        else
125                                if(strlen(imStr)==0)
126                                        imStr = "9"                     // a dummy value so I can replace it later
127                                endif
128                                detStr = carriageStr+imStr              // "F2" or something similar
129                                detStr = ReplaceString("9", detStr, "T")        // ASSUMPTION :::: instances 0123 correspond to TBLR
130                                detStr = ReplaceString("1", detStr, "B")        // ASSUMPTION :::: this is the order that the panels
131                                detStr = ReplaceString("2", detStr, "L")        // ASSUMPTION :::: are ALWAYS added to the graph
132                                detStr = ReplaceString("3", detStr, "R")        // ASSUMPTION ::::
133                        endif
134                       
135                        Printf "Detector panel %s=(%d,%d)\r",detStr,testX,testY
136                       
137                        x1 = ScaleToIndex(w,x1,0)               // get all four marquee values to pass back to the calling function
138                        x2 = ScaleToIndex(w,x2,0)               // converted into detector coordinates
139                        y1 = ScaleToIndex(w,y1,1)
140                        y2 = ScaleToIndex(w,y2,1)
141                       
142                       
143                        ii = -1         //look no further, set ii to bad value to exit the for loop
144
145                endif
146               
147        endfor
148       
149        return(detStr)
150       
151End
152
153//testing function only, not called anywhere
154Function V_testKeepInBounds(x1,x2,y1,y2,detStr,folderStr)
155        Variable x1,x2,y1,y2
156        String detStr,folderStr
157       
158        V_KeepSelectionInBounds(x1,x2,y1,y2,detStr,folderStr)
159        Print x1,x2,y1,y2
160        return(0)
161End
162
163// for the given detector
164Function V_KeepSelectionInBounds(x1,x2,y1,y2,detStr,folderStr)
165        Variable &x1,&x2,&y1,&y2
166        String detStr,folderStr
167       
168        Variable pixelsX = V_getDet_pixel_num_x(folderStr,detStr)
169        Variable pixelsY = V_getDet_pixel_num_y(folderStr,detStr)
170
171        //keep selection in-bounds
172        x1 = (round(x1) >= 0) ? round(x1) : 0
173        x2 = (round(x2) <= (pixelsX-1)) ? round(x2) : (pixelsX-1)
174        y1 = (round(y1) >= 0) ? round(y1) : 0
175        y2 = (round(y2) <= (pixelsY-1)) ? round(y2) : (pixelsY-1)
176       
177        return(0)
178End
179
180
181
182//sums the data counts in the box specified by (x1,y1) to (x2,y2)
183//assuming that x1<x2, and y1<y2
184//the x,y values must also be in array coordinates[0] NOT scaled detector coords.
185//
186// accepts arbitrary detector coordinates. calling function is responsible for
187// keeping selection in bounds
188//
189Function V_SumCountsInBox(x1,x2,y1,y2,ct_err,type,detStr)
190        Variable x1,x2,y1,y2,&ct_err
191        String type,detStr
192       
193        Variable counts = 0,ii,jj,err2_sum
194       
195// get the waves of the data and the data_err
196        Wave w = V_getDetectorDataW(type,detStr)
197        Wave data_err = V_getDetectorDataErrW(type,detStr)
198
199                       
200        err2_sum = 0            // running total of the squared error
201        ii=x1
202        jj=y1
203        do
204                do
205                        counts += w[ii][jj]
206                        err2_sum += data_err[ii][jj]*data_err[ii][jj]
207                        jj+=1
208                while(jj<=y2)
209                jj=y1
210                ii+=1
211        while(ii<=x2)
212       
213        err2_sum = sqrt(err2_sum)
214        ct_err = err2_sum
215       
216//      Print "error = ",ct_err
217//      Print "error/counts = ",ct_err/counts
218       
219        Return (counts)
220End
Note: See TracBrowser for help on using the repository browser.