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

Last change on this file since 1203 was 1203, checked in by srkline, 3 years ago

Corrected attenuator table for VSANS to include the range 4.52->19. Patching of the attenuation factor is disabled since the factor is always calculated rather than read from the file.

Added a few help links in preparation for the full help file integration

Added a "super" white beam distribution definition and a single model function for testing of this new mode. Still need the normalization and mean wavelength for the distribution + a way to identify it in the file metadata.

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