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

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

updates to:
how the DIV file is generated. Options for normalization are transparent choices now. Normalizing individually is the correct option to use, others are for testing.

updated what files can be displayed for drawing a mask

updated how the beam stop in place is deciphered

updated which raw data corrections are shown and allowed to be turned on/off on the VSANS preferences.

File size: 13.4 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="",typeStr=""
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        guides = V_getNumberOfGuides(fname)
383        if(cmpstr(guides,"NARROW_SLITS") == 0)
384                slit = 1
385        endif
386       
387// TODO: still not the correct way to identify the super white beam condition
388        typeStr = V_getMonochromatorType(fname)
389        if(cmpstr(typeStr,"super_white_beam")==0)
390                if(slit == 1)
391                        return("narrowSlit_super_white_beam")
392                else
393                        return("pinhole_super_white_beam")
394                endif
395        endif
396
397
398// TODO: as of 6/2018 with the converging pinholes IN, status is "out"
399//      status = V_getConvPinholeStatus(fname)
400//      if(cmpstr(status,"IN") == 0)
401//              return("convergingPinholes")
402//      endif
403
404        status = V_getWhiteBeamStatus(fname)
405        if(cmpstr(status,"IN") == 0)
406                wb_in = 1
407        endif   
408       
409
410       
411        if(wb_in == 1 && slit == 1)
412                return("narrowSlit_whiteBeam")
413        endif
414       
415        if(wb_in == 1 && slit == 0)
416                return("pinhole_whiteBeam")
417        endif
418       
419        if(wb_in == 0 && slit == 1)
420                return("narrowSlit")
421        endif
422       
423        if(wb_in == 0 && slit == 0)
424                return("pinhole")
425        endif
426       
427        // this is an error condition = null string     
428        return(collimationStr)
429End
430
431
432// TODO -- this may not correctly mimic the enumerated type of the file
433//  but I need to fudge this somehow
434//
435// returns null string if the type cannot be deduced, calling procedure is responsible
436//  for properly handling this error condition
437//
438Function/S V_IdentifyMonochromatorType(fname)
439        String fname
440       
441        String typeStr=""
442
443// TODO: if super_white_beam, this needs to be patched in the header
444//     
445        typeStr = V_getMonochromatorType(fname)
446        if(cmpstr(typeStr,"super_white_beam")==0)
447                return(typeStr)
448        endif
449       
450       
451        if(cmpstr(V_getVelSelStatus(fname),"IN") == 0)
452                typeStr = "velocity_selector"
453        endif
454       
455        if(cmpstr(V_getWhiteBeamStatus(fname),"IN") == 0)
456                typeStr = "white_beam"
457        endif
458       
459        if(cmpstr(V_getCrystalStatus(fname),"IN") == 0)
460                typeStr = "crystal"
461        endif   
462
463
464       
465        return(typeStr)
466End
467
468
469// returns the beamstop diameter [mm]
470//
471// checks the field num_beamstops. if this is 0, then there is no beam stop in place
472//      if there is no beamtop in front of the specified detector, return 0.01mm
473//
474// if the number is non-zero, then for the middle carriage, return the BS size, which
475//  will always be the diameter, since there are only circular beamstops present.
476//
477// TODO
478//  -- for the back carriage, the numbered beam stops are:
479// (1) = 6 mm x 300 mm (RECTANGLE)
480// (2) = 12 mm diameter (CIRCLE)
481// (3) = 12 mm x 300 mm (RECTANGLE)
482//
483//              -- currently this returns the diameter of the beam stop for # 2
484//    and the width ONLY if #1 or #3 (both are 300 mm high)
485//
486Function V_IdentifyBeamstopDiameter(folderStr,detStr)
487        String folderStr,detStr
488       
489        Variable BS, dummyVal,num
490        dummyVal = 0.01         //[mm]
491       
492        if(cmpstr("F",detStr[0]) == 0)
493                // front carriage has no beamstops
494                return(dummyVal)
495        endif
496       
497        if(cmpstr("M",detStr[0]) == 0)
498                // middle carriage (2)
499                num = V_getBeamStopC2num_beamstops(folderStr)
500                if(num)
501                        BS = V_getBeamStopC2_size(folderStr)
502                else
503                        //num = 0, no beamstops in the middle.
504                        return(dummyVal)
505                endif
506        endif
507
508        if(cmpstr("B",detStr[0]) == 0)
509                // back (3)
510                num = V_getBeamStopC3num_beamstops(folderStr)
511                if(num==0)
512                        return(dummyVal)
513                endif
514               
515                if(num==2)
516                        //2 = circular beamstop
517                        BS = V_getBeamStopC3_size(folderStr)
518                else
519                        //1 or 3, these are rectangular -- return the width, since the height of both is 300 mm
520                        return(V_getBeamStopC3_width(folderStr))
521                endif
522        endif   
523       
524        return(BS)
525end
526
527
528
529//
530// tests if two values are close enough to each other
531// very useful since ICE came to be
532//
533// tol is an absolute value (since input v1 or v2 may be zero, can't reliably
534// use a percentage
535Function V_CloseEnough(v1,v2,tol)
536        Variable v1, v2, tol
537
538        if(abs(v1-v2) < tol)
539                return(1)
540        else
541                return(0)
542        endif
543End
544
Note: See TracBrowser for help on using the repository browser.