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

Last change on this file since 1130 was 1117, checked in by srkline, 4 years ago

extensive changes to accomodate 1x1 binning of the HighRes? detector. It is implemented as a global flag. Currently only 4x4 and 1x1 are allowed. 1x1 has never been tested in reality, only simulated data - so my assumed dimensions may not be correct. look for TODOHIGHRES in the file for places that may need to be updated for different file dimensions. Testing of the simulated data is proving to be excruciatingly slow, but passable for a test. Speed optimization will be needed if this is the final solution. Memory management will also be an issue since every "copy" of the highRes matrix is enormous. Carry as few of these around as possible in the future to keep the experiment size to something reasonable.

File size: 11.7 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// SEP 2018 -- increased the tolerance to 2%, since I was getting false differences
18// especially for the lateral offset after switching from trans->scatter configs. Panel
19// was returning to postion, but within 2% (since the value was near zero)
20//
21
22
23// Function to test if two raw data files were collected at identical conditions.
24// this function does as many test as I can think of to compare the conditions.
25//
26// A test like this is to be used before two raw data files can be added together.
27//
28// TODO:
29// long list of points that need to match up to be sure that the conditions are all the same
30//
31//
32// depending on how long these checks take, may want a way to bypass this with a flag
33//
34// if any of the match conditions fail, exit immediately
35//
36//
37Function V_RawFilesMatchConfig(fname1,fname2)
38        String fname1,fname2
39
40        Variable ii
41        String detStr
42       
43// collimation conditions       
44// wavelength   
45        if(!V_FP_Value_Match(V_getWavelength,fname1,fname2))
46                return(0)       //no match
47        endif
48       
49// wavelength spread
50        if(!V_FP_Value_Match(V_getWavelength_spread,fname1,fname2))
51                return(0)       //no match
52        endif
53
54// monochromator type   
55        if(!V_String_Value_Match(V_getMonochromatorType,fname1,fname2))
56                return(0)
57        endif
58       
59// number of guides     (or narrow_slit, etc.)
60        if(!V_String_Value_Match(V_getNumberOfGuides,fname1,fname2))
61                return(0)
62        endif
63       
64       
65//// detector conditions
66//// loop over all of the detectors
67
68// detector distance and offset
69// I DON'T need to check all of the distances, just three will do
70        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"FL"))
71                return(0)       //no match
72        endif
73
74        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"ML"))
75                return(0)       //no match
76        endif
77       
78        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"B"))
79                return(0)       //no match
80        endif
81       
82       
83// I DO need to check all of the offset values
84        //// only return value for B and L/R detectors. everything else returns zero
85        //Function V_getDet_LateralOffset(fname,detStr)
86        //
87        //// only return values for T/B. everything else returns zero
88        //Function V_getDet_VerticalOffset(fname,detStr)
89        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
90                detStr = StringFromList(ii, ksDetectorListAll, ";")
91                if(!V_FP2_Value_Match(V_getDet_LateralOffset,fname1,fname2,detStr))
92                        return(0)       //no match
93                endif
94                if(!V_FP2_Value_Match(V_getDet_VerticalOffset,fname1,fname2,detStr))
95                        return(0)       //no match
96                endif
97        endfor
98       
99
100// messy - if the shape=circle, then look at size
101// but if shape=rectangle, look at height and width
102// source aperture shape, size
103        if(!V_String_Value_Match(V_getSourceAp_shape,fname1,fname2))
104                return(0)
105        endif
106// sample aperture shape, size
107        if(!V_String_Value_Match(V_getSampleAp2_shape,fname1,fname2))
108                return(0)
109        endif
110
111        return(1)               // passed all of the tests, OK, it's a match
112End
113
114
115// given an open beam file, to identify the allowable transmission measurements,
116// the conditions to meet are:
117//
118// wavelength
119// wavelength spread
120// detector distance(s)
121// detector offset(s) (this ensures that the same panel is catching the direct beam)
122//
123// ? do I need to check beam stop locations ?
124//
125Function V_Trans_Match_Open(fname1,fname2)
126        String fname1,fname2
127
128        Variable ii
129        String detStr
130       
131// collimation conditions       
132// wavelength   
133        if(!V_FP_Value_Match(V_getWavelength,fname1,fname2))
134                return(0)       //no match
135        endif
136       
137// wavelength spread
138        if(!V_FP_Value_Match(V_getWavelength_spread,fname1,fname2))
139                return(0)       //no match
140        endif
141
142//// monochromator type
143//      if(!V_String_Value_Match(V_getMonochromatorType,fname1,fname2))
144//              return(0)
145//      endif
146//     
147//// number of guides   (or narrow_slit, etc.)
148//      if(!V_String_Value_Match(V_getNumberOfGuides,fname1,fname2))
149//              return(0)
150//      endif
151       
152       
153//// detector conditions
154//// loop over all of the detectors
155
156// detector distance and offset
157// I DON'T need to check all of the distances, just three will do
158        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"FL"))
159                return(0)       //no match
160        endif
161
162        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"ML"))
163                return(0)       //no match
164        endif
165       
166        if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"B"))
167                return(0)       //no match
168        endif
169       
170       
171//// ???Do I need to check all of the offset values
172//      //// only return value for B and L/R detectors. everything else returns zero
173//      //Function V_getDet_LateralOffset(fname,detStr)
174//      //
175//      //// only return values for T/B. everything else returns zero
176//      //Function V_getDet_VerticalOffset(fname,detStr)
177//      for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
178//              detStr = StringFromList(ii, ksDetectorListAll, ";")
179//              if(!V_FP2_Value_Match(V_getDet_LateralOffset,fname1,fname2,detStr))
180//                      return(0)       //no match
181//              endif
182//              if(!V_FP2_Value_Match(V_getDet_VerticalOffset,fname1,fname2,detStr))
183//                      return(0)       //no match
184//              endif
185//      endfor
186
187// only check the panel position for the actual panel used for the open beam measurement
188        detStr = V_getReduction_BoxPanel(fname1)
189        if(!V_FP2_Value_Match(V_getDet_LateralOffset,fname1,fname2,detStr))
190                return(0)       //no match
191        endif
192
193        return(1)               // passed all of the tests, OK, it's a match
194End
195
196
197// given a transmission file, identify the possible scattering files:
198//
199// first, the group ID must match
200// then, as far as configurations:
201//
202// need to match
203// wavelength
204// wavelength spread
205// (I think that is all - since the transmission is only dependent on these values)
206//
207Function V_Scatter_Match_Trans(fname1,fname2)
208        String fname1,fname2
209
210        Variable ii
211        String detStr
212       
213// collimation conditions       
214// wavelength   
215        if(!V_FP_Value_Match(V_getWavelength,fname1,fname2))
216                return(0)       //no match
217        endif
218       
219// wavelength spread
220        if(!V_FP_Value_Match(V_getWavelength_spread,fname1,fname2))
221                return(0)       //no match
222        endif
223
224//// monochromator type
225//      if(!V_String_Value_Match(V_getMonochromatorType,fname1,fname2))
226//              return(0)
227//      endif
228//     
229//// number of guides   (or narrow_slit, etc.)
230//      if(!V_String_Value_Match(V_getNumberOfGuides,fname1,fname2))
231//              return(0)
232//      endif
233       
234       
235////// detector conditions
236////// loop over all of the detectors
237//
238//// detector distance and offset
239//// I DON'T need to check all of the distances, just three will do
240//      if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"FL"))
241//              return(0)       //no match
242//      endif
243//
244//      if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"ML"))
245//              return(0)       //no match
246//      endif
247//     
248//      if(!V_FP2_Value_Match(V_getDet_NominalDistance,fname1,fname2,"B"))
249//              return(0)       //no match
250//      endif
251//     
252//     
253//// I DO need to check all of the offset values
254//      //// only return value for B and L/R detectors. everything else returns zero
255//      //Function V_getDet_LateralOffset(fname,detStr)
256//      //
257//      //// only return values for T/B. everything else returns zero
258//      //Function V_getDet_VerticalOffset(fname,detStr)
259//      for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
260//              detStr = StringFromList(ii, ksDetectorListAll, ";")
261//              if(!V_FP2_Value_Match(V_getDet_LateralOffset,fname1,fname2,detStr))
262//                      return(0)       //no match
263//              endif
264//              if(!V_FP2_Value_Match(V_getDet_VerticalOffset,fname1,fname2,detStr))
265//                      return(0)       //no match
266//              endif
267//      endfor
268
269        return(1)               // passed all of the tests, OK, it's a match
270End
271
272
273
274
275
276Function V_String_Value_Match(func,fname1,fname2)
277        FUNCREF proto_V_get_STR func
278        String fname1,fname2
279       
280        Variable match=0
281        String val1,val2
282        val1 = func(fname1)
283        val2 = func(fname2)
284       
285//      Print val1
286        match = (cmpstr(val1,val2) == 0)                // match = 1 if the strings match, 0 if they don't match
287//      print match
288       
289        return(match)
290End
291
292
293Function V_FP_Value_Match(func,fname1,fname2)
294        FUNCREF proto_V_get_FP func
295        String fname1,fname2
296       
297        Variable match=0
298        Variable val1,val2,tol
299        val1 = func(fname1)
300        val2 = func(fname2)
301       
302        if(val1 == 0 && val2 == 0)
303                return(1)               // a match
304        endif
305
306        if(val1 != 0)
307                tol = abs(0.02 * val1)
308        else
309                tol = abs(0.02 * val2)
310        endif
311       
312//      match = V_CloseEnough(val1,val2,0.01*val1)
313        match = V_CloseEnough(val1,val2,tol)
314       
315        return(match)
316End
317
318// when a detector string is needed
319Function V_FP2_Value_Match(func,fname1,fname2,detStr)
320        FUNCREF proto_V_get_FP2 func
321        String fname1,fname2,detStr
322       
323        Variable match=0
324        Variable val1,val2,tol
325        val1 = func(fname1,detStr)
326        val2 = func(fname2,detStr)
327       
328        if(val1 == 0 && val2 == 0)
329                return(1)               // a match
330        endif
331       
332        if(val1 != 0)
333                tol = abs(0.02 * val1)
334        else
335                tol = abs(0.02 * val2)
336        endif
337       
338        match = V_CloseEnough(val1,val2,tol)
339       
340        return(match)
341End
342
343
344// parse through conditions in the data file to generate a string
345// that represents the collimation condition so that the proper resolution
346// can be calculated during the averaging step
347//
348// possible values are:
349//
350// pinhole
351// pinhole_whiteBeam
352// narrowSlit
353// narrowSlit_whiteBeam
354// convergingPinholes
355//
356// graphite at this point is treated as pinhole, until I find evidence otherwise.
357//
358//
359Function/S V_IdentifyCollimation(fname)
360        String fname
361       
362        String collimationStr=""
363        String status="",guides=""
364        variable wb_in=0,slit=0
365       
366        guides = V_getNumberOfGuides(fname)
367        if(cmpstr(guides,"CONV_BEAMS") == 0)
368                return("convergingPinholes")
369        endif
370
371// TODO: as of 6/2018 with the converging pinholes IN, status is "out"
372//      status = V_getConvPinholeStatus(fname)
373//      if(cmpstr(status,"IN") == 0)
374//              return("convergingPinholes")
375//      endif
376
377        status = V_getWhiteBeamStatus(fname)
378        if(cmpstr(status,"IN") == 0)
379                wb_in = 1
380        endif   
381       
382        guides = V_getNumberOfGuides(fname)
383        if(cmpstr(guides,"NARROW_SLITS") == 0)
384                slit = 1
385        endif
386       
387        if(wb_in == 1 && slit == 1)
388                return("narrowSlit_whiteBeam")
389        endif
390       
391        if(wb_in == 1 && slit == 0)
392                return("pinhole_whiteBeam")
393        endif
394       
395        if(wb_in == 0 && slit == 1)
396                return("narrowSlit")
397        endif
398       
399        if(wb_in == 0 && slit == 0)
400                return("pinhole")
401        endif
402       
403        // this is an error condition = null string     
404        return(collimationStr)
405End
406
407
408// TODO -- this may not correctly mimic the enumerated type of the file
409//  but I need to fudge this somehow
410//
411// returns null string if the type cannot be deduced, calling procedure is responsible
412//  for properly handling this error condition
413//
414Function/S V_DeduceMonochromatorType(fname)
415        String fname
416       
417        String typeStr=""
418
419        if(cmpstr(V_getVelSelStatus(fname),"IN") == 0)
420                typeStr = "velocity_selector"
421        endif
422       
423        if(cmpstr(V_getWhiteBeamStatus(fname),"IN") == 0)
424                typeStr = "white_beam"
425        endif
426       
427        if(cmpstr(V_getCrystalStatus(fname),"IN") == 0)
428                typeStr = "crystal"
429        endif   
430       
431        return(typeStr)
432End
433
434
435// returns the beamstop diameter [mm]
436// if there is no beamtop in front of the specified detector, return 0.01mm
437//
438Function V_DeduceBeamstopDiameter(folderStr,detStr)
439        String folderStr,detStr
440       
441        Variable BS, dummyVal,num
442        dummyVal = 0.01         //[mm]
443       
444        if(cmpstr("F",detStr[0]) == 0)
445                // front carriage has no beamstops
446                return(dummyVal)
447        endif
448       
449        if(cmpstr("M",detStr[0]) == 0)
450                // middle carriage (2)
451                num = V_getBeamStopC2num_beamstops(folderStr)
452                if(num)
453                        BS = V_getBeamStopC2_size(folderStr)
454                else
455                        //num = 0, no beamstops in the middle.
456                        return(dummyVal)
457                endif
458        endif
459
460        if(cmpstr("B",detStr[0]) == 0)
461                // back (3)
462                num = V_getBeamStopC3num_beamstops(folderStr)
463                if(num)
464                        BS = V_getBeamStopC3_size(folderStr)
465                else
466                        //num = 0, no beamstops on the back
467                        return(dummyVal)
468                endif
469        endif   
470       
471        return(BS)
472end
473
474
475
476//
477// tests if two values are close enough to each other
478// very useful since ICE came to be
479//
480// tol is an absolute value (since input v1 or v2 may be zero, can't reliably
481// use a percentage
482Function V_CloseEnough(v1,v2,tol)
483        Variable v1, v2, tol
484
485        if(abs(v1-v2) < tol)
486                return(1)
487        else
488                return(0)
489        endif
490End
491
Note: See TracBrowser for help on using the repository browser.