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

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

fixed a few bugs in the transmission panel.

added patching operation for dead time of the back panel

File size: 9.6 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//// ???Do I 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// only check the panel position for the actual panel used for the open beam measurement
185        detStr = V_getReduction_BoxPanel(fname1)
186        if(!V_FP2_Value_Match(V_getDet_LateralOffset,fname1,fname2,detStr))
187                return(0)       //no match
188        endif
189
190        return(1)               // passed all of the tests, OK, it's a match
191End
192
193
194// given a transmission file, identify the possible scattering files:
195//
196// first, the group ID must match
197// then, as far as configurations:
198//
199// need to match
200// wavelength
201// wavelength spread
202// (I think that is all - since the transmission is only dependent on these values)
203//
204Function V_Scatter_Match_Trans(fname1,fname2)
205        String fname1,fname2
206
207        Variable ii
208        String detStr
209       
210// collimation conditions       
211// wavelength   
212        if(!V_FP_Value_Match(V_getWavelength,fname1,fname2))
213                return(0)       //no match
214        endif
215       
216// wavelength spread
217        if(!V_FP_Value_Match(V_getWavelength_spread,fname1,fname2))
218                return(0)       //no match
219        endif
220
221//// monochromator type
222//      if(!V_String_Value_Match(V_getMonochromatorType,fname1,fname2))
223//              return(0)
224//      endif
225//     
226//// number of guides   (or narrow_slit, etc.)
227//      if(!V_String_Value_Match(V_getNumberOfGuides,fname1,fname2))
228//              return(0)
229//      endif
230       
231       
232////// detector conditions
233////// loop over all of the detectors
234//
235//// detector distance and offset
236//// I DON'T need to check all of the distances, just three will do
237//      if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"FL"))
238//              return(0)       //no match
239//      endif
240//
241//      if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"ML"))
242//              return(0)       //no match
243//      endif
244//     
245//      if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"B"))
246//              return(0)       //no match
247//      endif
248//     
249//     
250//// I DO need to check all of the offset values
251//      //// only return value for B and L/R detectors. everything else returns zero
252//      //Function V_getDet_LateralOffset(fname,detStr)
253//      //
254//      //// only return values for T/B. everything else returns zero
255//      //Function V_getDet_VerticalOffset(fname,detStr)
256//      for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
257//              detStr = StringFromList(ii, ksDetectorListAll, ";")
258//              if(!V_FP2_Value_Match(V_getDet_LateralOffset,fname1,fname2,detStr))
259//                      return(0)       //no match
260//              endif
261//              if(!V_FP2_Value_Match(V_getDet_VerticalOffset,fname1,fname2,detStr))
262//                      return(0)       //no match
263//              endif
264//      endfor
265
266        return(1)               // passed all of the tests, OK, it's a match
267End
268
269
270
271
272
273Function V_String_Value_Match(func,fname1,fname2)
274        FUNCREF proto_V_get_STR func
275        String fname1,fname2
276       
277        Variable match=0
278        String val1,val2
279        val1 = func(fname1)
280        val2 = func(fname2)
281       
282//      Print val1
283        match = (cmpstr(val1,val2) == 0)                // match = 1 if the strings match, 0 if they don't match
284//      print match
285       
286        return(match)
287End
288
289
290Function V_FP_Value_Match(func,fname1,fname2)
291        FUNCREF proto_V_get_FP func
292        String fname1,fname2
293       
294        Variable match=0
295        Variable val1,val2,tol
296        val1 = func(fname1)
297        val2 = func(fname2)
298       
299        if(val1 == 0 && val2 == 0)
300                return(1)               // a match
301        endif
302
303        if(val1 != 0)
304                tol = abs(0.01 * val1)
305        else
306                tol = abs(0.01 * val2)
307        endif
308       
309//      match = V_CloseEnough(val1,val2,0.01*val1)
310        match = V_CloseEnough(val1,val2,tol)
311       
312        return(match)
313End
314
315// when a detector string is needed
316Function V_FP2_Value_Match(func,fname1,fname2,detStr)
317        FUNCREF proto_V_get_FP2 func
318        String fname1,fname2,detStr
319       
320        Variable match=0
321        Variable val1,val2,tol
322        val1 = func(fname1,detStr)
323        val2 = func(fname2,detStr)
324       
325        if(val1 == 0 && val2 == 0)
326                return(1)               // a match
327        endif
328       
329        if(val1 != 0)
330                tol = abs(0.01 * val1)
331        else
332                tol = abs(0.01 * val2)
333        endif
334       
335        match = V_CloseEnough(val1,val2,tol)
336       
337        return(match)
338End
339
340
341// parse through conditions in the data file to generate a string
342// that represents the collimation condition so that the proper resolution
343// can be calculated during the averaging step
344//
345// possible values are:
346//
347// pinhole
348// pinhole_whiteBeam
349// narrowSlit
350// narrowSlit_whiteBeam
351// convergingPinholes
352//
353// graphite at this point is treated as pinhole, until I find evidence otherwise.
354//
355//
356Function/S V_IdentifyCollimation(fname)
357        String fname
358       
359        String collimationStr=""
360        String status="",guides=""
361        variable wb_in=0,slit=0
362       
363        status = V_getConvPinholeStatus(fname)
364        if(cmpstr(status,"IN") == 0)
365                return("convergingPinholes")
366        endif
367
368        status = V_getWhiteBeamStatus(fname)
369        if(cmpstr(status,"IN") == 0)
370                wb_in = 1
371        endif   
372       
373        guides = V_getNumberOfGuides(fname)
374        if(cmpstr(guides,"NARROW_SLITS") == 0)
375                slit = 1
376        endif
377       
378        if(wb_in == 1 && slit == 1)
379                return("narrowSlit_whiteBeam")
380        endif
381       
382        if(wb_in == 1 && slit == 0)
383                return("pinhole_whiteBeam")
384        endif
385       
386        if(wb_in == 0 && slit == 1)
387                return("narrowSlit")
388        endif
389       
390        if(wb_in == 0 && slit == 0)
391                return("pinhole")
392        endif
393       
394        // this is an error condition = null string     
395        return(collimationStr)
396End
397
398
399
Note: See TracBrowser for help on using the repository browser.