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

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

adding marquee operations to do a simple box sum, for manual calculation of transmission

Error in LamellarParacrystalline? model has been fixed.

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