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

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

many minor changes after real VSANS data collected.

additional procedures added to allow easy correction of the incorrect header information from NICE.

Most notable addition is the pinhole resolution added to the calculation and the I(q) output. White beam is also treated (incorrectly) as a gaussian distrivution, but the results of smeared fitting look to be quite good.

Trimming and sorting routines are now (pinhole) resolution aware.

File identification routines have been updated to use the proper definitions of "purpose" and "intent". Both fields are now in the catalog, to allow for better sorting.

File size: 9.1 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// x- determining the beam center (centroid) of the selection
15//  -- writing beam center (centroid) to the file?
16//  -- a box sum over a range of files (with a plot)
17// -- box sum over annular regions
18// -- box sum over arcs
19// --  saving Graphics image
20// -- histogram of the counts
21//
22//
23//
24
25
26
27
28//
29//function will print marquee coordinates in axis terms, not detector terms
30//
31// will also calculate the sum in the box, and the error, and print it out
32//
33Function V_PrintMarqueeCoords() :  GraphMarquee
34        GetMarquee left,bottom
35        if(V_flag == 0)
36                Print "There is no Marquee"
37        else
38                Variable count,x1,x2,y1,y2,ct_err
39                x1 = V_left
40                x2 = V_right
41                y1 = V_bottom
42                y2 = V_top
43                printf "marquee left in bottom axis terms: %g\r",round(V_left)
44                printf "marquee right in bottom axis terms: %g\r",round(V_right)
45                printf "marquee bottom in left axis terms: %g\r",round(V_bottom)
46                printf "marquee top in left axis terms: %g\r",round(V_top)
47//              printf "**note that you must add 1 to each axis coordinate to get detector coordinates\r"
48               
49                // NOTE:
50                // this function MODIFIES x and y values on return, converting them to panel coordinates
51                // detector panel is identified from the (left,top) coordinate (x1,y2)
52                String detStr = V_FindDetStrFromLoc(x1,x2,y1,y2)               
53//              Printf "Detector = %s\r",detStr
54
55//
56                SVAR gCurDispType = root:Packages:NIST:VSANS:Globals:gCurDispType       
57                // this function will modify the x and y values (passed by reference) as needed to keep on the panel
58                V_KeepSelectionInBounds(x1,x2,y1,y2,detStr,gCurDispType)
59                Printf "%d;%d;%d;%d;\r",x1,x2,y1,y2
60
61
62                count = V_SumCountsInBox(x1,x2,y1,y2,ct_err,gCurDispType,detStr)
63               
64                Print "counts = ",count
65                Print "err/counts = ",ct_err/count
66
67        endif
68End
69
70
71// NOTE:
72// this function MODIFIES x and y values on return, converting them to panel coordinates
73// detector panel is identified from the (left,top) coordinate (x1,y2)
74Function/S V_FindDetStrFromLoc(x1,x2,y1,y2)
75        Variable &x1,&x2,&y1,&y2
76       
77        // which images are here?
78        String detStr="",imStr,carriageStr
79        String currentImageRef,activeSubwindow,imageList
80        Variable ii,nIm,testX,testY,tab
81       
82        // which tab is selected? -this is the main graph panel (subwindow may not be the active one!)
83        ControlInfo/W=VSANS_Data tab0
84        tab = V_Value
85        if(tab == 0)
86                activeSubwindow = "VSANS_Data#det_panelsF"
87        elseif (tab == 1)
88                activeSubwindow = "VSANS_Data#det_panelsM"
89        else
90                activeSubwindow = "VSANS_Data#det_panelsB"
91        endif
92       
93        imageList = ImageNameList(activeSubwindow,";") 
94
95        nIm = ItemsInList(imageList,";")
96        if(nIm==0)
97                return("")              //problem, get out
98        endif
99
100        // images were added in the order TBLR, so look back through in the order RLBT, checking each to see if
101        // the xy value is found on that (scaled) array
102                               
103        // loop backwards through the list of panels (may only be one if on the back)
104        for(ii=nIm-1;ii>=0;ii-=1)
105                Wave w = ImageNameToWaveRef(activeSubwindow,StringFromList(ii, imageList,";"))
106               
107                // which, if any image is the mouse xy location on?
108                // use a multidemensional equivalent to x2pnt: (ScaledDimPos - DimOffset(waveName, dim))/DimDelta(waveName,dim)
109
110               
111                testX = ScaleToIndex(w,x1,0)
112                testY = ScaleToIndex(w,y2,1)
113               
114                if( (testX >= 0 && testX < DimSize(w,0)) && (testY >= 0 && testY < DimSize(w,1)) )
115                        // we're in-bounds on this wave
116                       
117                        // deduce the detector panel
118                        currentImageRef = StringFromList(ii, imageList,";")     //the image instance ##
119                        // string is "data", or "data#2" etc. - so this returns "", "1", "2", or "3"
120                        imStr = StringFromList(1, currentImageRef,"#")         
121                        carriageStr = activeSubWindow[strlen(activeSubWindow)-1]
122                       
123                        if(cmpstr(carriageStr,"B")==0)
124                                detStr = carriageStr
125                        else
126                                if(strlen(imStr)==0)
127                                        imStr = "9"                     // a dummy value so I can replace it later
128                                endif
129                                detStr = carriageStr+imStr              // "F2" or something similar
130                                detStr = ReplaceString("9", detStr, "T")        // ASSUMPTION :::: instances 0123 correspond to TBLR
131                                detStr = ReplaceString("1", detStr, "B")        // ASSUMPTION :::: this is the order that the panels
132                                detStr = ReplaceString("2", detStr, "L")        // ASSUMPTION :::: are ALWAYS added to the graph
133                                detStr = ReplaceString("3", detStr, "R")        // ASSUMPTION ::::
134                        endif
135                       
136                        Printf "Detector panel %s=(%d,%d)\r",detStr,testX,testY
137                       
138                        x1 = ScaleToIndex(w,x1,0)               // get all four marquee values to pass back to the calling function
139                        x2 = ScaleToIndex(w,x2,0)               // converted into detector coordinates
140                        y1 = ScaleToIndex(w,y1,1)
141                        y2 = ScaleToIndex(w,y2,1)
142                       
143                       
144                        ii = -1         //look no further, set ii to bad value to exit the for loop
145
146                endif
147               
148        endfor
149       
150        return(detStr)
151       
152End
153
154//testing function only, not called anywhere
155Function V_testKeepInBounds(x1,x2,y1,y2,detStr,folderStr)
156        Variable x1,x2,y1,y2
157        String detStr,folderStr
158       
159        V_KeepSelectionInBounds(x1,x2,y1,y2,detStr,folderStr)
160        Print x1,x2,y1,y2
161        return(0)
162End
163
164// for the given detector
165Function V_KeepSelectionInBounds(x1,x2,y1,y2,detStr,folderStr)
166        Variable &x1,&x2,&y1,&y2
167        String detStr,folderStr
168       
169        Variable pixelsX = V_getDet_pixel_num_x(folderStr,detStr)
170        Variable pixelsY = V_getDet_pixel_num_y(folderStr,detStr)
171
172        //keep selection in-bounds
173        x1 = (round(x1) >= 0) ? round(x1) : 0
174        x2 = (round(x2) <= (pixelsX-1)) ? round(x2) : (pixelsX-1)
175        y1 = (round(y1) >= 0) ? round(y1) : 0
176        y2 = (round(y2) <= (pixelsY-1)) ? round(y2) : (pixelsY-1)
177       
178        return(0)
179End
180
181
182
183//sums the data counts in the box specified by (x1,y1) to (x2,y2)
184//assuming that x1<x2, and y1<y2
185//the x,y values must also be in array coordinates[0] NOT scaled detector coords.
186//
187// accepts arbitrary detector coordinates. calling function is responsible for
188// keeping selection in bounds
189//
190Function V_SumCountsInBox(x1,x2,y1,y2,ct_err,type,detStr)
191        Variable x1,x2,y1,y2,&ct_err
192        String type,detStr
193       
194        Variable counts = 0,ii,jj,err2_sum
195       
196// get the waves of the data and the data_err
197        Wave w = V_getDetectorDataW(type,detStr)
198        Wave data_err = V_getDetectorDataErrW(type,detStr)
199
200                       
201        err2_sum = 0            // running total of the squared error
202        ii=x1
203        jj=y1
204        do
205                do
206                        counts += w[ii][jj]
207                        err2_sum += data_err[ii][jj]*data_err[ii][jj]
208                        jj+=1
209                while(jj<=y2)
210                jj=y1
211                ii+=1
212        while(ii<=x2)
213       
214        err2_sum = sqrt(err2_sum)
215        ct_err = err2_sum
216       
217//      Print "error = ",ct_err
218//      Print "error/counts = ",ct_err/counts
219       
220        Return (counts)
221End
222
223
224Function V_FindCentroid() :  GraphMarquee
225
226//      //get the current displayed data (so the correct folder is used)
227//      SVAR cur_folder=root:myGlobals:gDataDisplayType
228//      String dest = "root:Packages:NIST:" + cur_folder
229       
230        Variable xzsum,yzsum,zsum,xctr,yctr
231        Variable left,right,bottom,top,ii,jj,counts
232        Variable x_mm_sum,y_mm_sum,x_mm,y_mm
233
234       
235        GetMarquee left,bottom
236        if(V_flag == 0)
237                Print "There is no Marquee"
238        else
239                left = round(V_left)            //get integer values for selection limits
240                right = round(V_right)
241                top = round(V_top)
242                bottom = round(V_bottom)
243
244                // NOTE:
245                // this function MODIFIES x and y values on return, converting them to panel coordinates
246                // detector panel is identified from the (left,top) coordinate (x1,y2)
247                String detStr = V_FindDetStrFromLoc(left,right,bottom,top)             
248        //      Printf "Detector = %s\r",detStr
249       
250        //
251                SVAR gCurDispType = root:Packages:NIST:VSANS:Globals:gCurDispType       
252                // this function will modify the x and y values (passed by reference) as needed to keep on the panel
253                V_KeepSelectionInBounds(left,right,bottom,top,detStr,gCurDispType)
254                Print left,right,bottom,top
255                       
256               
257                // selection valid now, calculate beamcenter
258                // get the waves of the data and the data_err
259                Wave data = V_getDetectorDataW(gCurDispType,detStr)
260                Wave data_err = V_getDetectorDataErrW(gCurDispType,detStr)
261               
262                // get the real-space information
263                String destPath = "root:Packages:NIST:VSANS:"+gCurDispType
264                Wave data_realDistX = $(destPath + ":entry:instrument:detector_"+detStr+":data_realDistX")
265                Wave data_realDistY = $(destPath + ":entry:instrument:detector_"+detStr+":data_realDistY")
266       
267                xzsum = 0
268                yzsum = 0
269                zsum = 0
270                x_mm_sum = 0
271                y_mm_sum = 0
272               
273                // count over rectangular selection, doing each row, L-R, bottom to top
274                ii = bottom -1
275                do
276                        ii +=1
277                        jj = left-1
278                        do
279                                jj += 1
280                                counts = data[jj][ii]
281                                xzsum += jj*counts
282                                yzsum += ii*counts
283                                zsum += counts
284                               
285                                x_mm_sum += data_realDistX[jj][ii]*counts
286                                y_mm_sum += data_realDistY[jj][ii]*counts
287                        while(jj<right)
288                while(ii<top)
289               
290                xctr = xzsum/zsum
291                yctr = yzsum/zsum
292               
293                x_mm = x_mm_sum/zsum
294                y_mm = y_mm_sum/zsum
295                // add 1 to each to get to detector coordinates (1,128)
296                // rather than the data array which is [0,127]
297//              xctr+=1
298//              yctr+=1
299               
300                Print "X-center (in array coordinates 0->n-1 ) = ",xctr
301                Print "Y-center (in array coordinates 0->n-1 ) = ",yctr
302               
303                Print "X-center (cm) = ",x_mm/10
304                Print "Y-center (cm) = ",y_mm/10
305        endif
306       
307        //back to root folder (redundant)
308        SetDataFolder root:
309       
310End
Note: See TracBrowser for help on using the repository browser.