source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Utilities_Comparisons.ipf @ 1098

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

renamed white beam smearing models so they would be grouped together on the file list.

Re-worked the logic and flow of the averaging/plotting/saving steps of the reduction protocol so that it would flow cleanly and leave room for changes for the multitude of different collimation conditions. The averaging routines are now aware of the collimation conditions so that the appropriate resolution can be calculated. The collimation string is also written out to the averaged data file as element[9] of the protocol. The hope is that one could key on this collimation string to decide how to proceed with the analysis.

File size: 9.3 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4//
5//
6// utility procedures for comparing values in files to ensure that certain operations
7// such as transmssion, adding raw files, etc. can be properly completed
8//
9//
10// basic results are that:
11//  matching = 1 = true = OK
12//  no match = 0 = false = NOT OK
13//
14// V_CloseEnough tolerance is an absolute value
15// so passing 0.01*val_1 = 1% tolerance, as long as val_1 can't be zero
16//
17//
18
19
20// Function to test if two raw data files were collected at identical conditions.
21// this function does as many test as I can think of to compare the conditions.
22//
23// A test like this is to be used before two raw data files can be added together.
24//
25// TODO:
26// long list of points that need to match up to be sure that the conditions are all the same
27//
28//
29// depending on how long these checks take, may want a way to bypass this with a flag
30//
31// if any of the match conditions fail, exit immediately
32//
33//
34Function V_RawFilesMatch(fname1,fname2)
35        String fname1,fname2
36
37        Variable ii
38        String detStr
39       
40// collimation conditions       
41// wavelength   
42        if(!V_FP_Value_Match(V_getWavelength,fname1,fname2))
43                return(0)       //no match
44        endif
45       
46// wavelength spread
47        if(!V_FP_Value_Match(V_getWavelength_spread,fname1,fname2))
48                return(0)       //no match
49        endif
50
51// monochromator type   
52        if(!V_String_Value_Match(V_getMonochromatorType,fname1,fname2))
53                return(0)
54        endif
55       
56// number of guides     (or narrow_slit, etc.)
57        if(!V_String_Value_Match(V_getNumberOfGuides,fname1,fname2))
58                return(0)
59        endif
60       
61       
62//// detector conditions
63//// loop over all of the detectors
64
65// detector distance and offset
66// I DON'T need to check all of the distances, just three will do
67        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"FL"))
68                return(0)       //no match
69        endif
70
71        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"ML"))
72                return(0)       //no match
73        endif
74       
75        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"B"))
76                return(0)       //no match
77        endif
78       
79       
80// I DO need to check all of the offset values
81        //// only return value for B and L/R detectors. everything else returns zero
82        //Function V_getDet_LateralOffset(fname,detStr)
83        //
84        //// only return values for T/B. everything else returns zero
85        //Function V_getDet_VerticalOffset(fname,detStr)
86        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
87                detStr = StringFromList(ii, ksDetectorListAll, ";")
88                if(!V_FP2_Value_Match(V_getDet_LateralOffset,fname1,fname2,detStr))
89                        return(0)       //no match
90                endif
91                if(!V_FP2_Value_Match(V_getDet_VerticalOffset,fname1,fname2,detStr))
92                        return(0)       //no match
93                endif
94        endfor
95       
96
97// messy - if the shape=circle, then look at size
98// but if shape=rectangle, look at height and width
99// source aperture shape, size
100        if(!V_String_Value_Match(V_getSourceAp_shape,fname1,fname2))
101                return(0)
102        endif
103// sample aperture shape, size
104        if(!V_String_Value_Match(V_getSampleAp2_shape,fname1,fname2))
105                return(0)
106        endif
107
108        return(1)               // passed all of the tests, OK, it's a match
109End
110
111
112// given an open beam file, to identify the allowable transmission measurements,
113// the conditions to meet are:
114//
115// wavelength
116// wavelength spread
117// detector distance(s)
118// detector offset(s) (this ensures that the same panel is catching the direct beam)
119//
120// ? do I need to check beam stop locations ?
121//
122Function V_Trans_Match_Open(fname1,fname2)
123        String fname1,fname2
124
125        Variable ii
126        String detStr
127       
128// collimation conditions       
129// wavelength   
130        if(!V_FP_Value_Match(V_getWavelength,fname1,fname2))
131                return(0)       //no match
132        endif
133       
134// wavelength spread
135        if(!V_FP_Value_Match(V_getWavelength_spread,fname1,fname2))
136                return(0)       //no match
137        endif
138
139//// monochromator type
140//      if(!V_String_Value_Match(V_getMonochromatorType,fname1,fname2))
141//              return(0)
142//      endif
143//     
144//// number of guides   (or narrow_slit, etc.)
145//      if(!V_String_Value_Match(V_getNumberOfGuides,fname1,fname2))
146//              return(0)
147//      endif
148       
149       
150//// detector conditions
151//// loop over all of the detectors
152
153// detector distance and offset
154// I DON'T need to check all of the distances, just three will do
155        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"FL"))
156                return(0)       //no match
157        endif
158
159        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"ML"))
160                return(0)       //no match
161        endif
162       
163        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"B"))
164                return(0)       //no match
165        endif
166       
167       
168// I DO need to check all of the offset values
169        //// only return value for B and L/R detectors. everything else returns zero
170        //Function V_getDet_LateralOffset(fname,detStr)
171        //
172        //// only return values for T/B. everything else returns zero
173        //Function V_getDet_VerticalOffset(fname,detStr)
174        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
175                detStr = StringFromList(ii, ksDetectorListAll, ";")
176                if(!V_FP2_Value_Match(V_getDet_LateralOffset,fname1,fname2,detStr))
177                        return(0)       //no match
178                endif
179                if(!V_FP2_Value_Match(V_getDet_VerticalOffset,fname1,fname2,detStr))
180                        return(0)       //no match
181                endif
182        endfor
183
184        return(1)               // passed all of the tests, OK, it's a match
185End
186
187
188// given a transmission file, identify the possible scattering files:
189//
190// first, the group ID must match
191// then, as far as configurations:
192//
193// need to match
194// wavelength
195// wavelength spread
196// (I think that is all - since the transmission is only dependent on these values)
197//
198Function V_Scatter_Match_Trans(fname1,fname2)
199        String fname1,fname2
200
201        Variable ii
202        String detStr
203       
204// collimation conditions       
205// wavelength   
206        if(!V_FP_Value_Match(V_getWavelength,fname1,fname2))
207                return(0)       //no match
208        endif
209       
210// wavelength spread
211        if(!V_FP_Value_Match(V_getWavelength_spread,fname1,fname2))
212                return(0)       //no match
213        endif
214
215//// monochromator type
216//      if(!V_String_Value_Match(V_getMonochromatorType,fname1,fname2))
217//              return(0)
218//      endif
219//     
220//// number of guides   (or narrow_slit, etc.)
221//      if(!V_String_Value_Match(V_getNumberOfGuides,fname1,fname2))
222//              return(0)
223//      endif
224       
225       
226////// detector conditions
227////// loop over all of the detectors
228//
229//// detector distance and offset
230//// I DON'T need to check all of the distances, just three will do
231//      if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"FL"))
232//              return(0)       //no match
233//      endif
234//
235//      if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"ML"))
236//              return(0)       //no match
237//      endif
238//     
239//      if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"B"))
240//              return(0)       //no match
241//      endif
242//     
243//     
244//// I DO need to check all of the offset values
245//      //// only return value for B and L/R detectors. everything else returns zero
246//      //Function V_getDet_LateralOffset(fname,detStr)
247//      //
248//      //// only return values for T/B. everything else returns zero
249//      //Function V_getDet_VerticalOffset(fname,detStr)
250//      for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
251//              detStr = StringFromList(ii, ksDetectorListAll, ";")
252//              if(!V_FP2_Value_Match(V_getDet_LateralOffset,fname1,fname2,detStr))
253//                      return(0)       //no match
254//              endif
255//              if(!V_FP2_Value_Match(V_getDet_VerticalOffset,fname1,fname2,detStr))
256//                      return(0)       //no match
257//              endif
258//      endfor
259
260        return(1)               // passed all of the tests, OK, it's a match
261End
262
263
264
265
266
267Function V_String_Value_Match(func,fname1,fname2)
268        FUNCREF proto_V_get_STR func
269        String fname1,fname2
270       
271        Variable match=0
272        String val1,val2
273        val1 = func(fname1)
274        val2 = func(fname2)
275       
276//      Print val1
277        match = (cmpstr(val1,val2) == 0)                // match = 1 if the strings match, 0 if they don't match
278//      print match
279       
280        return(match)
281End
282
283
284Function V_FP_Value_Match(func,fname1,fname2)
285        FUNCREF proto_V_get_FP func
286        String fname1,fname2
287       
288        Variable match=0
289        Variable val1,val2,tol
290        val1 = func(fname1)
291        val2 = func(fname2)
292       
293        if(val1 == 0 && val2 == 0)
294                return(1)               // a match
295        endif
296
297        if(val1 != 0)
298                tol = abs(0.01 * val1)
299        else
300                tol = abs(0.01 * val2)
301        endif
302       
303//      match = V_CloseEnough(val1,val2,0.01*val1)
304        match = V_CloseEnough(val1,val2,tol)
305       
306        return(match)
307End
308
309// when a detector string is needed
310Function V_FP2_Value_Match(func,fname1,fname2,detStr)
311        FUNCREF proto_V_get_FP2 func
312        String fname1,fname2,detStr
313       
314        Variable match=0
315        Variable val1,val2,tol
316        val1 = func(fname1,detStr)
317        val2 = func(fname2,detStr)
318       
319        if(val1 == 0 && val2 == 0)
320                return(1)               // a match
321        endif
322       
323        if(val1 != 0)
324                tol = abs(0.01 * val1)
325        else
326                tol = abs(0.01 * val2)
327        endif
328       
329        match = V_CloseEnough(val1,val2,tol)
330       
331        return(match)
332End
333
334
335// parse through conditions in the data file to generate a string
336// that represents the collimation condition so that the proper resolution
337// can be calculated during the averaging step
338//
339// possible values are:
340//
341// pinhole
342// pinhole_whiteBeam
343// narrowSlit
344// narrowSlit_whiteBeam
345// convergingPinholes
346//
347// graphite at this point is treated as pinhole, until I find evidence otherwise.
348//
349//
350Function/S V_IdentifyCollimation(fname)
351        String fname
352       
353        String collimationStr=""
354        String status="",guides=""
355        variable wb_in=0,slit=0
356       
357        status = V_getConvPinholeStatus(fname)
358        if(cmpstr(status,"IN") == 0)
359                return("convergingPinholes")
360        endif
361
362        status = V_getWhiteBeamStatus(fname)
363        if(cmpstr(status,"IN") == 0)
364                wb_in = 1
365        endif   
366       
367        guides = V_getNumberOfGuides(fname)
368        if(cmpstr(guides,"NARROW_SLITS") == 0)
369                slit = 1
370        endif
371       
372        if(wb_in == 1 && slit == 1)
373                return("narrowSlit_whiteBeam")
374        endif
375       
376        if(wb_in == 1 && slit == 0)
377                return("pinhole_whiteBeam")
378        endif
379       
380        if(wb_in == 0 && slit == 1)
381                return("narrowSlit")
382        endif
383       
384        if(wb_in == 0 && slit == 0)
385                return("pinhole")
386        endif
387       
388        // this is an error condition = null string     
389        return(collimationStr)
390End
391
392
393
Note: See TracBrowser for help on using the repository browser.