source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/VC_UtilityProcedures.ipf @ 1133

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

many changes to the VCALC procedures to add in the hard/soft shadowing to the calculation, visualization of the shadowed regions, and the actual q-values. Added a separate panel to view the shadowed regions.

simpe fix to the real time routine to allow easy updating of both the raw 2D data and 1-D average

update to the USANS package to handle the new NICE generated data where the data is collected in terms of q-values rather than angle. On startup asks user which style of data they have. Sets a preference that can be un-checked if you have old-style ICP data. (there is nothing in the data file that I can key on).

File size: 47.8 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2
3////////////////////////
4//
5//
6// a bunch of utility procedures to access information from the VCALC panel and to access
7// constants based in which of the detectors I'm trying to work with. Saves a lot of repetitive switches
8//
9// start the function names with VCALC_ to avoid the eventual conflicts with the file loading utilities
10// for reduction of real VSANS data
11//
12//
13// -- add more of these procedures as more items are added to the panel
14//
15////////////////////////
16
17
18//  Values from the VCALC panel
19
20
21
22
23// returns the panel separation [cm]
24Function VCALC_getPanelTranslation(type)
25        String type
26       
27        Variable sep
28       
29        strswitch(type)
30                case "FL":
31                        ControlInfo/W=VCALC VCALCCtrl_2a
32                        sep = V_Value
33                        break
34                case "FR":
35                        ControlInfo/W=VCALC VCALCCtrl_2aa
36                        sep = V_Value
37                        break
38                case "FT":
39                        ControlInfo/W=VCALC VCALCCtrl_2b
40                        sep = V_Value   
41                        break
42                case "FB":
43                        ControlInfo/W=VCALC VCALCCtrl_2bb
44                        sep = V_Value   
45                        break
46
47                case "ML":
48                        ControlInfo/W=VCALC VCALCCtrl_3a
49                        sep = V_Value
50                        break
51                case "MR":
52                        ControlInfo/W=VCALC VCALCCtrl_3aa
53                        sep = V_Value
54                        break
55                case "MT":
56                        ControlInfo/W=VCALC VCALCCtrl_3b
57                        sep = V_Value
58                        break   
59                case "MB":
60                        ControlInfo/W=VCALC VCALCCtrl_3bb
61                        sep = V_Value
62                        break   
63                                               
64                case "B":               
65                        sep = 0
66                        break
67                       
68                default:
69                        Print "Error -- type not found in        VCALC_getPanelSeparation(type)"                                       
70                        sep = NaN               //no match for type             
71        endswitch
72       
73        return(sep)
74end
75
76
77
78// returns the (mean) wavelength from the panel -- value is angstroms
79Function VCALC_getWavelength()
80       
81        ControlInfo/W=VCALC VCALCCtrl_0b
82
83        return(V_Value)
84end
85
86// returns the wavelength spread from the panel -- value is fraction
87Function VCALC_getWavelengthSpread()
88       
89        ControlInfo/W=VCALC VCALCCtrl_0d
90
91        return(str2num(S_Value))
92end
93
94// returns the number of neutrons on the sample
95Function VCALC_getImon()
96       
97        ControlInfo/W=VCALC VCALCCtrl_5a
98
99        return(V_Value)
100end
101
102// returns the model function to use
103Function/S VCALC_getModelFunctionStr()
104       
105        ControlInfo/W=VCALC VCALCCtrl_5b
106
107        return(S_Value)
108end
109
110
111
112/// NVARs set in VCALC space (not necessarily matching the true instrument values)
113// -- these all set to the proper data folder, then BACK TO ROOT:
114
115
116// return the pixel X size, in [cm]
117Function VCALC_getPixSizeX(type)
118        String type
119
120        Variable pixSizeX = V_getDet_x_pixel_size("VCALC",type)
121
122        return(pixSizeX)
123end
124
125// return the pixel Y size, in [cm]
126Function VCALC_getPixSizeY(type)
127        String type
128
129        Variable pixSizeY = V_getDet_y_pixel_size("VCALC",type)
130       
131        return(pixSizeY)
132end
133
134
135// return the number of pixels in x-dimension
136Function VCALC_get_nPix_X(type)
137        String type
138
139        Variable nPix = V_getDet_pixel_num_x("VCALC",type)
140       
141        return(nPix)
142end
143
144// return the number of pixels in y-dimension
145Function VCALC_get_nPix_Y(type)
146        String type
147
148        Variable nPix = V_getDet_pixel_num_y("VCALC",type)
149
150        return(nPix)
151end
152
153
154
155// SDD offset of the top/bottom panels
156// value returned is in [cm]
157//
158Function VCALC_getTopBottomSDDSetback(type)
159        String type
160
161        SetDataFolder root:Packages:NIST:VSANS:VCALC
162       
163        strswitch(type)
164                case "FL":
165                case "FR":
166                        SetDataFolder root:
167                        return(0)               
168                        break           //already zero, do nothing
169                case "FT":
170                case "FB":             
171                        NVAR sdd_setback = gFront_SDDsetback    //T/B are 41 cm farther back
172                        break
173                       
174                case "ML":
175                case "MR":
176                        SetDataFolder root:
177                        return(0)
178                        break           //already zero, do nothing
179                case "MT":
180                case "MB":
181                        NVAR sdd_setback = gMiddle_SDDsetback   //T/B are 41 cm farther back
182                        break   
183                                               
184                case "B":
185                case "B ":
186                        SetDataFolder root:
187                        return(0)
188                        break           //already zero, do nothing
189                       
190                default:
191                        Print "Error -- type not found in        VCALC_getTopBottomSDDSetback(type)"                                   
192                        sdd_setback = 0         //no match for type             
193        endswitch
194
195        SetDataFolder root:
196               
197        return(sdd_setback)     
198End
199
200
201
202//////////////////////////////////
203//
204// Actions for the VCALC controls
205//
206//////////////////////////////////
207
208// get the sourceAperture_to_GateValve distance from the table
209//
210// correct for the sampleAperture_to_GateValve distance
211//
212// return the SourceAp to SampleAp Distance in [cm]
213Function VC_calcSSD()
214
215        Variable ng,ssd,samAp_to_GV
216        ControlInfo/W=VCALC VCALCCtrl_0a
217        ng = V_Value
218
219        ControlInfo/W=VCALC VCALCCtrl_1d
220        samAp_to_GV = V_Value           // [cm]
221       
222        switch(ng)
223                case 0:
224                                ssd = 2441
225                        break
226                case 1:
227                                ssd = 2157
228                        break
229                case 2:
230                                ssd = 1976
231                        break
232                case 3:
233                                ssd = 1782
234                        break                   
235                case 4:
236                                ssd = 1582
237                        break                   
238                case 5:
239                                ssd = 1381
240                        break                   
241                case 6:
242                                ssd = 1181
243                        break                   
244                case 7:
245                                ssd = 980
246                        break                   
247                case 8:
248                                ssd = 780
249                        break                   
250                case 9:
251                                ssd = 579
252                        break                   
253                default:
254                        Print "Error - using default SSD value"
255                        ssd = 2441
256        endswitch
257        ssd -= samAp_to_GV
258       
259//      print "SSD (cm) = ",ssd
260        return(ssd)
261End
262
263
264// read the number of guides from the slider
265// return the Source aperture diameter [cm]
266// TODO - needs a case statement since a1 can depend on Ng
267Function VC_sourceApertureDiam()
268
269        Variable ng,a1
270        ControlInfo/W=VCALC VCALCCtrl_0a
271        ng = V_Value
272
273        ControlInfo/W=VCALC VCALCCtrl_0f
274        String apStr = S_Value
275       
276
277        if(ng > 0)     
278                a1 = 6          // 60 mm diameter
279        else
280                sscanf apStr, "%g cm", a1
281        endif
282
283//      Print "Source Ap diam (cm) = ",a1
284        return(a1)
285End
286
287// reports tha value in [cm]
288Function VC_sampleApertureDiam()
289
290        ControlInfo/W=VCALC VCALCCtrl_1c
291        Variable val = str2num(S_Value)
292
293        return(val)
294End
295
296
297///////////////////
298//
299// Presets
300//
301///////////////////
302
303
304// for Front+Middle Only
305// x F SDD=120
306// x (L=-20, R=20) (T=4, B=-4)
307//
308// x M SDD = 1900
309// x (L=0, R=0)
310//
311// x Velocity selector
312// x Ng = 0
313// x Lam = 8
314// x delLam = 0.12
315// source ap = ? (circular)
316//
317// ignore back detector
318// x set plot type to F2-M2xTB-B
319//
320//
321Function VC_Preset_FrontMiddle_Ng0()
322
323// set preference to ignore back detector
324        NVAR gIgnoreB = root:Packages:NIST:VSANS:Globals:gIgnoreDetB
325        gIgnoreB = 1
326       
327        // front carriage
328        SetVariable VCALCCtrl_2a,value=_NUM:-10         //Left offset
329        SetVariable VCALCCtrl_2aa,value=_NUM:10         //Right offset
330        SetVariable VCALCCtrl_2b,value=_NUM:4                   //Top offset
331        SetVariable VCALCCtrl_2bb,value=_NUM:-4         //Bottom offset
332
333        SetVariable VCALCCtrl_2d,value=_NUM:400         //SDD
334
335        // middle carriage
336        SetVariable VCALCCtrl_3a,value=_NUM:-10         //Left offset
337        SetVariable VCALCCtrl_3aa,value=_NUM:-10                //Right offset
338        SetVariable VCALCCtrl_3b,value=_NUM:4                   //Top offset (doesn't matter)
339        SetVariable VCALCCtrl_3bb,value=_NUM:-4         //Bottom offset (doesn't matter)
340
341        SetVariable VCALCCtrl_3d,value=_NUM:1900                //SDD
342       
343       
344        // monochromator
345        PopupMenu VCALCCtrl_0c,mode=1,popvalue="Velocity Selector"
346       
347        // wavelength spread
348        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
349        DLStr = "0.12;"
350//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
351        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12"
352       
353        // wavelength
354        SetVariable VCALCCtrl_0b,value=_NUM:6
355
356        //number of guides
357//      Slider VCALCCtrl_0a,value= 0
358        V_GuideSliderProc("VCALCCtrl_0a",0,1)           //Set Ng=0, resets the aperture string to the new string
359        Slider VCALCCtrl_0a,value=0
360
361       
362// source aperture (+new string)
363        PopupMenu VCALCCtrl_0f,mode=3           //set the 3.0 cm aperture
364       
365// binning mode
366        PopupMenu popup_b,mode=1,popValue="F2-M2xTB-B"
367
368
369        return(0)
370End
371
372
373Function VC_Preset_FrontMiddle_Ng2()
374
375        // front carriage
376        SetVariable VCALCCtrl_2a,value=_NUM:-10         //Left offset
377        SetVariable VCALCCtrl_2aa,value=_NUM:10         //Right offset
378        SetVariable VCALCCtrl_2b,value=_NUM:4                   //Top offset
379        SetVariable VCALCCtrl_2bb,value=_NUM:-4         //Bottom offset
380
381        SetVariable VCALCCtrl_2d,value=_NUM:350         //SDD
382
383        // middle carriage
384        SetVariable VCALCCtrl_3a,value=_NUM:-10         //Left offset
385        SetVariable VCALCCtrl_3aa,value=_NUM:-10                //Right offset
386        SetVariable VCALCCtrl_3b,value=_NUM:4                   //Top offset (doesn't matter)
387        SetVariable VCALCCtrl_3bb,value=_NUM:-4         //Bottom offset (doesn't matter)
388
389        SetVariable VCALCCtrl_3d,value=_NUM:1600                //SDD
390       
391       
392        // monochromator
393        PopupMenu VCALCCtrl_0c,mode=1,popvalue="Velocity Selector"
394       
395        // wavelength spread
396        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
397        DLStr = "0.12;"
398//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
399        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12"
400       
401        // wavelength
402        SetVariable VCALCCtrl_0b,value=_NUM:6
403
404        //number of guides
405//      Slider VCALCCtrl_0a,value= 0
406        V_GuideSliderProc("VCALCCtrl_0a",2,1)           //Set Ng=2, resets the aperture string to the new string
407        Slider VCALCCtrl_0a,value=2
408       
409// source aperture (+new string)
410        PopupMenu VCALCCtrl_0f,mode=1           //6.0 cm aperture
411       
412
413// binning mode
414        PopupMenu popup_b,mode=1,popValue="F2-M2xTB-B"
415
416
417        return(0)
418End
419
420Function VC_Preset_FrontMiddle_Ng7()
421
422        // front carriage
423        SetVariable VCALCCtrl_2a,value=_NUM:-10         //Left offset
424        SetVariable VCALCCtrl_2aa,value=_NUM:10         //Right offset
425        SetVariable VCALCCtrl_2b,value=_NUM:4                   //Top offset
426        SetVariable VCALCCtrl_2bb,value=_NUM:-4         //Bottom offset
427
428        SetVariable VCALCCtrl_2d,value=_NUM:230         //SDD
429
430        // middle carriage
431        SetVariable VCALCCtrl_3a,value=_NUM:-10         //Left offset
432        SetVariable VCALCCtrl_3aa,value=_NUM:-10                //Right offset
433        SetVariable VCALCCtrl_3b,value=_NUM:4                   //Top offset (doesn't matter)
434        SetVariable VCALCCtrl_3bb,value=_NUM:-4         //Bottom offset (doesn't matter)
435
436        SetVariable VCALCCtrl_3d,value=_NUM:1100                //SDD
437       
438       
439        // monochromator
440        PopupMenu VCALCCtrl_0c,mode=1,popvalue="Velocity Selector"
441       
442        // wavelength spread
443        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
444        DLStr = "0.12;"
445//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
446        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12"
447       
448        // wavelength
449        SetVariable VCALCCtrl_0b,value=_NUM:6
450
451        //number of guides
452//      Slider VCALCCtrl_0a,value= 0
453        V_GuideSliderProc("VCALCCtrl_0a",7,1)           //Set Ng=7, resets the aperture string to the new string
454        Slider VCALCCtrl_0a,value=7
455
456// source aperture (+new string)
457        PopupMenu VCALCCtrl_0f,mode=1           //6.0 cm aperture
458
459
460// binning mode
461        PopupMenu popup_b,mode=1,popValue="F2-M2xTB-B"
462
463
464        return(0)
465End
466
467Function VC_Preset_FrontMiddle_Ng9()
468
469        // front carriage
470        SetVariable VCALCCtrl_2a,value=_NUM:-10         //Left offset
471        SetVariable VCALCCtrl_2aa,value=_NUM:10         //Right offset
472        SetVariable VCALCCtrl_2b,value=_NUM:4                   //Top offset
473        SetVariable VCALCCtrl_2bb,value=_NUM:-4         //Bottom offset
474
475        SetVariable VCALCCtrl_2d,value=_NUM:100         //SDD
476
477        // middle carriage
478        SetVariable VCALCCtrl_3a,value=_NUM:-10         //Left offset
479        SetVariable VCALCCtrl_3aa,value=_NUM:-10                //Right offset
480        SetVariable VCALCCtrl_3b,value=_NUM:4                   //Top offset (doesn't matter)
481        SetVariable VCALCCtrl_3bb,value=_NUM:-4         //Bottom offset (doesn't matter)
482
483        SetVariable VCALCCtrl_3d,value=_NUM:450         //SDD
484       
485       
486       
487        // monochromator
488        PopupMenu VCALCCtrl_0c,mode=1,popvalue="Velocity Selector"
489       
490        // wavelength spread
491        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
492        DLStr = "0.12;"
493//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
494        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12"
495       
496        // wavelength
497        SetVariable VCALCCtrl_0b,value=_NUM:6
498
499        //number of guides
500//      Slider VCALCCtrl_0a,value= 0
501        V_GuideSliderProc("VCALCCtrl_0a",9,1)           //Set Ng=9, resets the aperture string to the new string
502        Slider VCALCCtrl_0a,value=9
503
504// source aperture (+new string)
505        PopupMenu VCALCCtrl_0f,mode=1           //6.0 cm aperture
506
507
508// binning mode
509        PopupMenu popup_b,mode=1,popValue="F2-M2xTB-B"
510
511
512        return(0)
513End
514
515
516
517
518// White beam preset
519// - set monochromator (this sets lam, delLam)
520// - disregard the back detector (set as front/middle)
521//
522Function VC_Preset_WhiteBeam()
523
524        // monochromator
525        PopupMenu VCALCCtrl_0c,mode=1,popvalue="White Beam"
526       
527        // wavelength spread
528        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
529        DLStr = "0.40;"
530//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.40",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
531        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.40"
532
533// wavelength
534        SetVariable VCALCCtrl_0b,value=_NUM:5.3//,disable=0     ,noedit=0       // allow user editing again
535
536        // adjust the front carriage
537        SetVariable VCALCCtrl_2a,value=_NUM:-20         //Left offset
538        SetVariable VCALCCtrl_2aa,value=_NUM:20         //Right offset
539        SetVariable VCALCCtrl_2b,value=_NUM:8                   //Top offset
540        SetVariable VCALCCtrl_2bb,value=_NUM:-8         //Bottom offset
541
542        SetVariable VCALCCtrl_2d,value=_NUM:120         //SDD
543
544        // middle carriage
545        SetVariable VCALCCtrl_3a,value=_NUM:-15         //Left offset
546        SetVariable VCALCCtrl_3aa,value=_NUM:15         //Right offset
547        SetVariable VCALCCtrl_3b,value=_NUM:15                  //Top offset (doesn't matter)
548        SetVariable VCALCCtrl_3bb,value=_NUM:-15                //Bottom offset (doesn't matter)
549
550        SetVariable VCALCCtrl_3d,value=_NUM:1900                //SDD
551       
552// binning mode
553        PopupMenu popup_b,mode=1,popValue="F4-M4-B"
554
555// set preference to USE back detector
556        NVAR gIgnoreB = root:Packages:NIST:VSANS:Globals:gIgnoreDetB
557        gIgnoreB = 0
558       
559                       
560        return(0)
561end
562
563
564// Graphite - high resolution beam preset
565// - set monochromator (this sets lam, delLam)
566// - uses the back detector (set as front/middle)
567//
568Function VC_Preset_GraphiteMono()
569
570        // front carriage
571        SetVariable VCALCCtrl_2a,value=_NUM:-20         //Left offset
572        SetVariable VCALCCtrl_2aa,value=_NUM:20         //Right offset
573        SetVariable VCALCCtrl_2b,value=_NUM:4                   //Top offset
574        SetVariable VCALCCtrl_2bb,value=_NUM:-4         //Bottom offset
575
576        SetVariable VCALCCtrl_2d,value=_NUM:120         //SDD
577
578        // middle carriage
579        SetVariable VCALCCtrl_3a,value=_NUM:-8          //Left offset
580        SetVariable VCALCCtrl_3aa,value=_NUM:08 //Right offset
581        SetVariable VCALCCtrl_3b,value=_NUM:18                  //Top offset (doesn't matter)
582        SetVariable VCALCCtrl_3bb,value=_NUM:-18                //Bottom offset (doesn't matter)
583
584        SetVariable VCALCCtrl_3d,value=_NUM:1500                //SDD
585
586        // back carriage       
587        SetVariable VCALCCtrl_4b,value=_NUM:2300                //SDD
588       
589        // monochromator
590        PopupMenu VCALCCtrl_0c,mode=1,popvalue="Graphite"
591       
592        // wavelength spread
593        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
594        DLStr = "0.01;"
595//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
596        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.01"
597       
598        // wavelength
599        SetVariable VCALCCtrl_0b,value=_NUM:4.75//,disable=0    ,noedit=0       // allow user editing again
600
601        //number of guides
602        Slider VCALCCtrl_0a,value= 0
603
604
605// binning mode
606        PopupMenu popup_b,mode=1,popValue="F4-M4-B"
607
608        return(0)
609end
610
611// calculates L2, the sample aperture to detector distance
612Function VC_calc_L2(detStr)
613        String detStr
614
615        Variable a2_to_GV,sam_to_GV,sdd,l2
616        sdd = VC_getSDD(detStr)                 //sample pos to detector
617        ControlInfo/W=VCALC VCALCCtrl_1d
618        a2_to_GV = V_Value
619        ControlInfo/W=VCALC VCALCCtrl_1e
620        sam_to_GV = V_Value
621        l2 = sdd - sam_to_GV + a2_to_GV
622       
623        return(l2)
624End
625
626//
627//direction = one of "vertical;horizontal;maximum;"
628// all of this is bypassed if the lenses are in
629//
630// carrNum = 1,2,3 for F,M,B
631//
632// returns a value in [cm]
633Function VC_beamDiameter(direction,detStr)
634        String direction
635        String detStr
636
637//      NVAR lens = root:Packages:NIST:SAS:gUsingLenses
638//      if(lens)
639//              return sourceApertureDiam()
640//      endif
641       
642        Variable l1,l2,l2Diff
643        Variable d1,d2,bh,bv,bm,umbra,a1,a2
644        Variable lambda,lambda_width,bs_factor
645   
646// TODO: proper value for bs_factor
647        bs_factor = 1.05
648       
649        l1 = VC_calcSSD()
650        lambda = VCALC_getWavelength()
651        lambda_width = VCALC_getWavelengthSpread()
652       
653       
654        Variable a2_to_GV,sam_to_GV,sdd
655        sdd = VC_getSDD(detStr)                 //sample pos to detector
656        ControlInfo/W=VCALC VCALCCtrl_1d
657        a2_to_GV = V_Value
658        ControlInfo/W=VCALC VCALCCtrl_1e
659        sam_to_GV = V_Value
660        l2 = sdd - sam_to_GV + a2_to_GV
661   
662   
663    // TODO verify that these values are in cm
664        a1 = VC_sourceApertureDiam()
665   
666        // sample aperture diam [cm]
667        ControlInfo/W=VCALC VCALCCtrl_1c
668        a2 = V_Value
669   
670    d1 = a1*l2/l1
671    d2 = a2*(l1+l2)/l1
672    bh = d1+d2          //beam size in horizontal direction
673    umbra = abs(d1-d2)
674    //vertical spreading due to gravity
675    bv = bh + 1.25e-8*(l1+l2)*l2*lambda*lambda*lambda_width
676    bm = (bs_factor*bh > bv) ? bs_factor*bh : bv //use the larger of horiz*safety or vertical
677   
678    strswitch(direction)        // string switch
679        case "vertical":                // execute if case matches expression
680                return(bv)
681                break                                           // exit from switch
682        case "horizontal":              // execute if case matches expression
683                return(bh)
684                break
685        case "maximum":         // execute if case matches expression
686                return(bm)
687                break
688        default:                                                        // optional default expression executed
689                return(bm)                                              // when no case matches
690    endswitch
691   
692    return(0)
693   
694End
695
696// 1=front
697// 2=middle
698// 3=back
699// return value is in cm
700// actual Sample position to detector distance is reported
701// Top/Bottom setback is included
702Function VC_getSDD(detStr)
703        String detStr
704       
705        Variable sdd
706
707        strswitch(detstr)
708                case "B":
709                case "B ":
710                        ControlInfo/W=VCALC VCALCCtrl_4b
711                        break
712                case "ML":
713                case "MR":
714                case "MT":
715                case "MB":
716                        ControlInfo/W=VCALC VCALCCtrl_3d
717                        break
718                case "FL":
719                case "FR":
720                case "FT":
721                case "FB":
722                        ControlInfo/W=VCALC VCALCCtrl_2d
723                        break           
724                default:
725                        Print "no case matched in VC_getSDD()"
726        endswitch
727
728        // this is gate valve to detector distance
729        sdd = V_Value
730       
731        sdd += VCALC_getTopBottomSDDSetback(detStr)
732       
733        // VCALCCtrl_1e is Sample Pos to Gate Valve (cm)
734        ControlInfo/W=VCALC VCALCCtrl_1e
735        sdd += V_Value
736       
737        return(sdd)
738end
739       
740
741// TODO
742// -- verify all of the numbers, constants, and "empirical" transmission corrections
743// --
744//
745Function V_beamIntensity()
746
747        Variable as,solid_angle,l1,d2_phi
748        Variable a1,a2,retVal
749        Variable ng
750        Variable lambda_t
751        Variable lambda,phi_0
752        Variable lambda_width
753        Variable guide_loss,t_guide,t_filter,t_total,t_special
754
755        NVAR gBeamInten = root:Packages:NIST:VSANS:VCALC:gBeamIntensity
756 
757// TODO
758// -- verify these numbers
759        lambda_t = 6.20
760        phi_0 = 1.82e13
761        guide_loss = 0.97
762        t_special = 1
763
764        ControlInfo/W=VCALC VCALCCtrl_0a
765        ng = V_Value
766 
767        lambda = VCALC_getWavelength()
768        lambda_width = VCALC_getWavelengthSpread()
769        l1 = VC_calcSSD()
770   
771    // TODO verify that these values are in cm
772        a1 = VC_sourceApertureDiam()
773   
774        // sample aperture diam [cm]
775        a2 = VC_sampleApertureDiam()
776   
777//      alpha = (a1+a2)/(2*l1)  //angular divergence of beam
778//      f = l_gap*alpha/(2*guide_width)
779//      t4 = (1-f)*(1-f)
780//      t6 = 1 - lambda*(b-(ng/8)*(b-c))                //experimental correction factor
781
782        t_guide = exp(ng*ln(guide_loss))        // trans losses of guides in pre-sample flight
783        t_filter = exp(-0.371 - 0.0305*lambda - 0.00352*lambda*lambda)
784        t_total = t_special*t_guide*t_filter
785
786   
787        as = pi/4*a2*a2         //area of sample in the beam
788        d2_phi = phi_0/(2*pi)
789        d2_phi *= exp(4*ln(lambda_t/lambda))
790        d2_phi *= exp(-1*(lambda_t*lambda_t/lambda/lambda))
791
792        solid_angle = pi/4* (a1/l1)*(a1/l1)
793
794        retVal = as * d2_phi * lambda_width * solid_angle * t_total
795
796        // set the global for display
797        gBeamInten = retVal
798       
799        return (retVal)
800end
801
802//
803Function VC_figureOfMerit()
804
805        Variable bi = V_beamIntensity()
806        Variable lambda = VCALC_getWavelength()
807       
808   return (lambda*lambda*bi)
809End
810
811// return a beamstop diameter (cm) larger than maximum beam dimension
812Function VC_beamstopDiam(detStr)
813        String detStr
814       
815        Variable bm=0
816        Variable bs=0.0
817   Variable yesLens=0
818   
819        if(yesLens)
820                //bm = sourceApertureDiam()             //ideal result, not needed
821                bs = 1                                                          //force the diameter to 1"
822        else
823                bm = VC_beamDiameter("maximum",detStr)
824                do
825                bs += 1
826           while ( (bs*2.54 < bm) || (bs > 30.0))                       //30 = ridiculous limit to avoid inf loop
827        endif
828
829        return (bs*2.54)                //return diameter in cm, not inches for txt
830End
831
832// multiply the appropriate IQ data by the beamstop shadow factor for display
833//
834Function V_IQ_BeamstopShadow()
835
836        String popStr
837        Variable binType
838       
839        ControlInfo/W=VCALC popup_b
840        popStr = S_Value       
841
842        binType = V_BinTypeStr2Num(popStr)     
843       
844        String folderStr = "root:Packages:NIST:VSANS:VCALC:"
845       
846
847        String extStr =""
848       
849        switch(binType)
850                case 1:
851                        extStr = ksBinType1             
852
853                        break
854                case 2:
855                        extStr = ksBinType2             
856
857                        break
858                case 3:
859                        extStr = ksBinType3     
860                       
861                        break
862                case 4:                         /// this is for a tall, narrow slit mode       
863                        extStr = ksBinType4
864
865                        break
866                case 5:
867                        extStr = ksBinType5     
868               
869                        break
870                case 6:
871                        extStr = ksBinType6     
872               
873                        break
874                case 7:
875                        extStr = ksBinType7     
876               
877                        break
878                       
879                default:
880                        Abort "Binning mode not found in V_IQ_BeamstopShadow"// when no case matches   
881        endswitch
882
883// TODO:
884// -- I had to put a lot of conditions on when not to try to apply the shadow factor
885// to avoid errors when iq had no points in the wave, or incorrectly applying the beamstop to the back panel.
886       
887        Variable ii
888        String ext
889//      loop over all of the types of data
890        for(ii=0;ii<ItemsInList(extStr);ii+=1)
891                ext = StringFromList(ii, extStr, ";")
892                Wave iq = $(folderStr+"iBin_qxqy_"+ext)
893                Wave/Z fs = $(folderStr+"fSubS_qxqy_"+ext)
894                if(WaveExists(fs) && numpnts(iq) > 0 && cmpstr(ext,"B") != 0)
895                        iq = (fs < 0.1) ? iq*0.1 : iq*fs
896                endif
897        endfor 
898       
899        return(0)
900end
901
902
903
904//
905// instead of setting some of the data to NaN to exclude it, draw a proper mask to be used
906// during the I(q) averaging
907//
908// use both the "hard" and "soft" shadowing
909// -- chooses the more "conservative" of the shadowing values (soft value at short SDD + T/B)
910//
911// the MSK data will be in its ususal location from the initialization.
912//
913// FL shadows FT, FB, ML
914// FR shadows FT, FB, MR
915// FT shadows ML, MR, MT
916// FB shadows ML, MR, MB
917// ML shadows MT, MB, B
918// MR shadows MT, MB, B
919// MT shadows B
920// MB shadows B
921//
922Function VC_DrawVCALCMask()
923
924        VC_DrawVCALCMask_FL()
925        VC_DrawVCALCMask_FR()
926        VC_DrawVCALCMask_FT()
927        VC_DrawVCALCMask_FB()
928       
929        VC_DrawVCALCMask_ML()
930        VC_DrawVCALCMask_MR()
931        VC_DrawVCALCMask_MT()
932        VC_DrawVCALCMask_MB()
933       
934        return(0)
935end
936
937// FL shadows FT, FB, ML
938Function VC_DrawVCALCMask_FL()
939       
940        Variable pixSizeX,pixSizeY,nPix,nt
941
942        Variable offset,offset_ML,L2_F,L2_M,delta_L,delta_S,D2
943        Variable delta_Xh,delta_Xs,delta_X_pix,delta
944        String type,target
945
946// FL shadows FT,FB,ML
947        type = "FL"
948
949        // lateral offset of FL
950        offset = VCALC_getPanelTranslation(type)
951        // sample aperture diam [cm]
952        D2 = VC_sampleApertureDiam()
953        // sdd F         [cm] = sample aperture to detector
954        L2_F = VC_calc_L2(type)
955        // depth of electronics (L/R panels)
956        delta_L = 33            //[cm]
957        // offset of 80/20 frame
958        delta_S = 2.5           //[cm]
959       
960       
961        // sdd of FT, or FB, or ML
962/////
963        target = "FT"
964        L2_M = VC_calc_L2(target)
965        // mask data
966        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
967
968// extent of shadow in [cm] (starting point of shadow from center of beam)
969// hard
970        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
971// soft
972        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
973
974        //use the smaller shadow value (this means closer to the center, a larger shadow)
975        delta = min(delta_Xh,delta_Xs)
976
977// how many detector tubes to mask?
978        pixSizeX = VCALC_getPixSizeX(target)
979        pixSizeY = VCALC_getPixSizeY(target)
980
981        //since "target" is FT, use x-position
982        // at what "pixel" does the shadow start?
983        delta_X_pix = trunc(delta/pixSizeX)             //pixels from the center
984        nPix = VCALC_get_nPix_X(target)
985
986        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the FT panel
987                nt = trunc(nPix/2) - delta_x_pix
988                mask[0,nt][] = 1
989        endif
990       
991/////
992        target = "FB"
993        L2_M = VC_calc_L2(target)
994        // mask data
995        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
996
997// extent of shadow in [cm] (starting point of shadow from center of beam)
998// hard
999        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1000// soft
1001        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1002
1003        //use the smaller shadow value
1004        delta = min(delta_Xh,delta_Xs)
1005       
1006// how many detector tubes to mask?
1007        pixSizeX = VCALC_getPixSizeX(target)
1008        pixSizeY = VCALC_getPixSizeY(target)
1009
1010        //since "target" is FB, use x-position
1011        // at what "pixel" does the shadow start?
1012        delta_X_pix = trunc(delta/pixSizeX)
1013        nPix = VCALC_get_nPix_X(target)
1014
1015        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the FB panel
1016                nt = trunc(nPix/2) - delta_x_pix
1017                mask[0,nt][] = 1
1018        endif
1019
1020///
1021// for ML, there can also be lateral offset of the ML panel
1022        target = "ML"
1023
1024        L2_M = VC_calc_L2(target)
1025        // mask data
1026        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1027
1028// extent of shadow in [cm] (starting point of shadow from center of beam)
1029// hard
1030        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1031// soft
1032        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1033
1034        //use the smaller shadow value
1035        delta = min(delta_Xh,delta_Xs)
1036//      delta = delta_Xh
1037       
1038// how many detector tubes to mask?
1039        pixSizeX = VCALC_getPixSizeX(target)
1040        pixSizeY = VCALC_getPixSizeY(target)
1041
1042// offset of ML, in "pixels"
1043        offset_ML = VCALC_getPanelTranslation(target)/pixSizeX          //[cm]
1044        offset_ML = -trunc(offset_ML)
1045        //since "target" is ML, use x-position
1046        // at what "pixel" does the shadow start?
1047        delta_X_pix = trunc(delta/pixSizeX)
1048        nPix = VCALC_get_nPix_X(target)
1049       
1050        //is the delta_x_pix still on the left edge of ML?
1051        if(delta_x_pix < 0)             //entire panel is shadowed
1052                nt = nPix-1
1053                mask[0,nt][] = 1
1054        else
1055                if(delta_X_pix < nPix + offset_ML)
1056                        nt = nPix + offset_ML - delta_x_pix
1057                        mask[0,nt][] = 1
1058                endif
1059        endif
1060       
1061        return(0)
1062end
1063
1064// FR shadows FT, FB, MR
1065Function VC_DrawVCALCMask_FR()
1066       
1067        Variable pixSizeX,pixSizeY,nPix,nt
1068
1069        Variable offset,offset_MR,L2_F,L2_M,delta_L,delta_S,D2
1070        Variable delta_Xh,delta_Xs,delta_X_pix,delta
1071        String type,target
1072
1073// FR shadows FT, FB, MR
1074        type = "FR"
1075
1076        // lateral offset of FR
1077        offset = VCALC_getPanelTranslation(type)
1078        // sample aperture diam [cm]
1079        D2 = VC_sampleApertureDiam()
1080        // sdd F         [cm] = sample aperture to detector
1081        L2_F = VC_calc_L2(type)
1082        // depth of electronics (L/R panels)
1083        delta_L = 33            //[cm]
1084        // offset of 80/20 frame
1085        delta_S = 2.5           //[cm]
1086       
1087       
1088        // sdd of FT, or FB, or MR
1089/////
1090        target = "FT"
1091        L2_M = VC_calc_L2(target)
1092        // mask data
1093        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1094
1095// extent of shadow in [cm] (starting point of shadow from center of beam)
1096// hard
1097        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1098// soft
1099        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1100
1101        //use the smaller shadow value (this means closer to the center, a larger shadow)
1102        delta = min(delta_Xh,delta_Xs)
1103
1104// how many detector tubes to mask?
1105        pixSizeX = VCALC_getPixSizeX(target)
1106        pixSizeY = VCALC_getPixSizeY(target)
1107
1108        //since "target" is FT, use x-position
1109        // at what "pixel" does the shadow start?
1110        delta_X_pix = trunc(delta/pixSizeX)
1111        nPix = VCALC_get_nPix_X(target)
1112
1113        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the FT panel
1114                nt = trunc(nPix/2) - delta_x_pix
1115                mask[nPix-nt,nPix-1][] = 1
1116        endif
1117       
1118/////
1119        target = "FB"
1120        L2_M = VC_calc_L2(target)
1121        // mask data
1122        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1123
1124// extent of shadow in [cm] (starting point of shadow from center of beam)
1125// hard
1126        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1127// soft
1128        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1129
1130        //use the smaller shadow value
1131        delta = min(delta_Xh,delta_Xs)
1132       
1133// how many detector tubes to mask?
1134        pixSizeX = VCALC_getPixSizeX(target)
1135        pixSizeY = VCALC_getPixSizeY(target)
1136
1137        //since "target" is FB, use x-position
1138        // at what "pixel" does the shadow start?
1139        delta_X_pix = trunc(delta/pixSizeX)
1140        nPix = VCALC_get_nPix_X(target)
1141
1142        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the FB panel
1143                nt = trunc(nPix/2) - delta_x_pix
1144                mask[nPix-nt,nPix-1][] = 1
1145        endif
1146
1147///
1148// for MR, there can also be lateral offset of the panel
1149        target = "MR"
1150
1151        L2_M = VC_calc_L2(target)
1152        // mask data
1153        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1154
1155// extent of shadow in [cm] (starting point of shadow from center of beam)
1156// hard
1157        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1158// soft
1159        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1160
1161        //use the smaller shadow value
1162        delta = min(delta_Xh,delta_Xs)
1163       
1164// how many detector tubes to mask?
1165        pixSizeX = VCALC_getPixSizeX(target)
1166        pixSizeY = VCALC_getPixSizeY(target)
1167
1168// offset of MR, in "pixels"
1169        offset_MR = VCALC_getPanelTranslation(target)/pixSizeX          //[cm]
1170        offset_MR = trunc(offset_MR)
1171        //since "target" is ML, use x-position
1172        // at what "pixel" does the shadow start?
1173        nPix = VCALC_get_nPix_X(target)
1174       
1175        delta_X_pix = trunc(delta/pixSizeX)
1176       
1177        //is the delta_x_pix still on the right edge of MR?
1178        if(delta_x_pix < 0)             //entire panel is shadowed
1179                nt = nPix-1
1180                mask[0,nt][] = 1
1181        else
1182                if(delta_X_pix < nPix + offset_MR)
1183                        nt = nPix + offset_MR - delta_x_pix
1184                        mask[nPix-nt,nPix-1][] = 1
1185                endif
1186        endif
1187               
1188        return(0)
1189end
1190
1191// FT shadows ML, MR, MT
1192Function VC_DrawVCALCMask_FT()
1193       
1194        Variable pixSizeX,pixSizeY,nPix,nt
1195
1196        Variable offset,offset_MT,L2_F,L2_M,delta_L,delta_S,D2
1197        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1198        String type,target
1199
1200// FT shadows ML, MR, MT
1201        type = "FT"
1202
1203        //  offset of FT
1204        offset = VCALC_getPanelTranslation(type)
1205        // sample aperture diam [cm]
1206        D2 = VC_sampleApertureDiam()
1207        // sdd F         [cm] = sample aperture to detector
1208        L2_F = VC_calc_L2(type)
1209        // depth of electronics (T/B panels)
1210        delta_L = 61            //[cm]
1211        // offset of 80/20 frame
1212        delta_S = 2.5           //[cm]
1213       
1214       
1215        // sdd of ML, or MR, or MT
1216/////
1217        target = "ML"
1218        L2_M = VC_calc_L2(target)
1219        // mask data
1220        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1221
1222// extent of shadow in [cm] (starting point of shadow from center of beam)
1223// hard
1224        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1225// soft
1226        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1227
1228        //use the smaller shadow value (this means closer to the center, a larger shadow)
1229        delta = min(delta_Xh,delta_Xs)
1230
1231// how many detector tubes to mask?
1232        pixSizeX = VCALC_getPixSizeX(target)
1233        pixSizeY = VCALC_getPixSizeY(target)
1234
1235        //since "target" is ML, use Y-position
1236        // at what "pixel" does the shadow start?
1237        delta_Y_pix = trunc(delta/pixSizeY)
1238        nPix = VCALC_get_nPix_Y(target)
1239
1240        if(delta_y_pix < trunc(nPix/2))
1241                nt = trunc(nPix/2) - delta_y_pix
1242                mask[][nPix-nt,nPix-1] = 1
1243        endif
1244
1245/////
1246        target = "MR"
1247        L2_M = VC_calc_L2(target)
1248        // mask data
1249        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1250
1251// extent of shadow in [cm] (starting point of shadow from center of beam)
1252// hard
1253        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1254// soft
1255        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1256
1257        //use the smaller shadow value
1258        delta = min(delta_Xh,delta_Xs)
1259
1260       
1261// how many detector tubes to mask?
1262        pixSizeX = VCALC_getPixSizeX(target)
1263        pixSizeY = VCALC_getPixSizeY(target)
1264
1265        //since "target" is MR, use y-position
1266        // at what "pixel" does the shadow start?
1267        delta_y_pix = trunc(delta/pixSizey)
1268        nPix = VCALC_get_nPix_Y(target)
1269
1270        if(delta_y_pix < trunc(nPix/2))
1271                nt = trunc(nPix/2) - delta_y_pix
1272                mask[][nPix-nt,nPix-1] = 1
1273        endif
1274       
1275///
1276// for MT, there can also be lateral offset of the MT panel
1277        target = "MT"
1278
1279        L2_M = VC_calc_L2(target)
1280        // mask data
1281        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1282
1283// extent of shadow in [cm] (starting point of shadow from center of beam)
1284// hard
1285        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1286// soft
1287        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1288
1289        //use the smaller shadow value
1290        delta = min(delta_Xh,delta_Xs)
1291       
1292// how many detector tubes to mask?
1293        pixSizeX = VCALC_getPixSizeX(target)
1294        pixSizeY = VCALC_getPixSizeY(target)
1295
1296// offset of MT, in "pixels" -in Y-direction
1297        offset_MT = VCALC_getPanelTranslation(target)/pixSizeY          //[cm]
1298        offset_MT = trunc(offset_MT)
1299        //since "target" is MT, use y-position
1300        // at what "pixel" does the shadow start?
1301        delta_Y_pix = trunc(delta/pixSizeY)
1302        nPix = VCALC_get_nPix_Y(target)
1303
1304        if(delta_Y_pix < nPix + offset_MT)
1305                nt = nPix + offset_MT - delta_y_pix
1306                mask[][nPix-nt,nPix-1] = 1
1307        endif
1308       
1309       
1310        return(0)
1311end
1312
1313// FB shadows ML, MR, MB
1314Function VC_DrawVCALCMask_FB()
1315       
1316        Variable pixSizeX,pixSizeY,nPix,nt
1317
1318        Variable offset,offset_MB,L2_F,L2_M,delta_L,delta_S,D2
1319        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1320        String type,target
1321
1322// FB shadows ML, MR, MB
1323        type = "FB"
1324
1325        //  offset of FB
1326        offset = VCALC_getPanelTranslation(type)
1327       
1328        // sample aperture diam [cm]
1329        D2 = VC_sampleApertureDiam()
1330        // sdd F         [cm] = sample aperture to detector
1331        L2_F = VC_calc_L2(type)
1332        // depth of electronics (T/B panels)
1333        delta_L = 61            //[cm]
1334        // offset of 80/20 frame
1335        delta_S = 2.5           //[cm]
1336       
1337       
1338        // sdd of ML, or MR, or MB
1339/////
1340        target = "ML"
1341        L2_M = VC_calc_L2(target)
1342        // mask data
1343        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1344
1345// extent of shadow in [cm] (starting point of shadow from center of beam)
1346// hard
1347        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1348// soft
1349        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1350
1351        //use the smaller shadow value (this means closer to the center, a larger shadow)
1352        delta = min(delta_Xh,delta_Xs)
1353
1354       
1355// how many detector tubes to mask?
1356        pixSizeX = VCALC_getPixSizeX(target)
1357        pixSizeY = VCALC_getPixSizeY(target)
1358
1359        //since "target" is ML, use Y-position
1360        // at what "pixel" does the shadow start?
1361        delta_Y_pix = trunc(delta/pixSizeY)
1362        nPix = VCALC_get_nPix_Y(target)
1363
1364        if(delta_y_pix < trunc(nPix/2))
1365                nt = trunc(nPix/2) - delta_y_pix
1366                mask[][0,nt] = 1
1367        endif
1368       
1369/////
1370        target = "MR"
1371        L2_M = VC_calc_L2(target)
1372        // mask data
1373        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1374
1375// extent of shadow in [cm] (starting point of shadow from center of beam)
1376// hard
1377        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1378// soft
1379        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1380
1381        //use the smaller shadow value
1382        delta = min(delta_Xh,delta_Xs)
1383       
1384// how many detector tubes to mask?
1385        pixSizeX = VCALC_getPixSizeX(target)
1386        pixSizeY = VCALC_getPixSizeY(target)
1387
1388        //since "target" is MR, use y-position
1389        // at what "pixel" does the shadow start?
1390        delta_y_pix = trunc(delta/pixSizeY)
1391        nPix = VCALC_get_nPix_Y(target)
1392
1393        if(delta_y_pix < trunc(nPix/2))
1394                nt = trunc(nPix/2) - delta_y_pix
1395                mask[][0,nt] = 1
1396        endif
1397       
1398///
1399// for MB, there can also be lateral offset of the MT panel
1400        target = "MB"
1401
1402        L2_M = VC_calc_L2(target)
1403        // mask data
1404        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1405
1406// extent of shadow in [cm] (starting point of shadow from center of beam)
1407// hard
1408        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1409// soft
1410        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1411
1412        //use the smaller shadow value
1413        delta = min(delta_Xh,delta_Xs)
1414       
1415// how many detector tubes to mask?
1416        pixSizeX = VCALC_getPixSizeX(target)
1417        pixSizeY = VCALC_getPixSizeY(target)
1418
1419// offset of MT, in "pixels" -in Y-direction
1420        offset_MB = VCALC_getPanelTranslation(target)/pixSizeY          //[cm]
1421        offset_MB = -trunc(offset_MB)
1422        //since "target" is MT, use y-position
1423        // at what "pixel" does the shadow start?
1424        delta_Y_pix = trunc(delta/pixSizeY)
1425        nPix = VCALC_get_nPix_Y(target)
1426
1427        if(delta_Y_pix < nPix + offset_MB)
1428                nt = nPix + offset_MB - delta_y_pix
1429                mask[][0,nt] = 1
1430        endif
1431       
1432
1433        return(0)
1434end
1435
1436// ML shadows MT, MB, B
1437Function VC_DrawVCALCMask_ML()
1438       
1439        Variable pixSizeX,pixSizeY,nPix,nt
1440
1441        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1442        Variable delta_Xh,delta_Xs,delta_X_pix,delta
1443        String type,target
1444
1445// ML shadows MT, MB, B
1446        type = "ML"
1447
1448        // lateral offset of ML
1449        offset = VCALC_getPanelTranslation(type)
1450        // sample aperture diam [cm]
1451        D2 = VC_sampleApertureDiam()
1452        // sdd F         [cm] = sample aperture to detector
1453        L2_F = VC_calc_L2(type)
1454        // depth of electronics (L/R panels)
1455        delta_L = 33            //[cm]
1456        // offset of 80/20 frame
1457        delta_S = 2.5           //[cm]
1458       
1459       
1460        // sdd of MT, or MB, or B
1461/////
1462        target = "MT"
1463        L2_M = VC_calc_L2(target)
1464        // mask data
1465        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1466
1467// extent of shadow in [cm] (starting point of shadow from center of beam)
1468// hard
1469        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1470// soft
1471        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1472
1473        //use the smaller shadow value (this means closer to the center, a larger shadow)
1474        delta = min(delta_Xh,delta_Xs)
1475
1476// how many detector tubes to mask?
1477        pixSizeX = VCALC_getPixSizeX(target)
1478        pixSizeY = VCALC_getPixSizeY(target)
1479
1480        //since "target" is FT, use x-position
1481        // at what "pixel" does the shadow start?
1482        delta_X_pix = trunc(delta/pixSizeX)             //pixels from the center
1483        nPix = VCALC_get_nPix_X(target)
1484
1485        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the FT panel
1486                nt = trunc(nPix/2) - delta_x_pix
1487                mask[0,nt][] = 1
1488        endif
1489       
1490/////
1491        target = "MB"
1492        L2_M = VC_calc_L2(target)
1493        // mask data
1494        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1495
1496// extent of shadow in [cm] (starting point of shadow from center of beam)
1497// hard
1498        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1499// soft
1500        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1501
1502        //use the smaller shadow value
1503        delta = min(delta_Xh,delta_Xs)
1504       
1505// how many detector tubes to mask?
1506        pixSizeX = VCALC_getPixSizeX(target)
1507        pixSizeY = VCALC_getPixSizeY(target)
1508
1509        //since "target" is MB, use x-position
1510        // at what "pixel" does the shadow start?
1511        delta_X_pix = trunc(delta/pixSizeX)
1512        nPix = VCALC_get_nPix_X(target)
1513
1514        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the MB panel
1515                nt = trunc(nPix/2) - delta_x_pix
1516                mask[0,nt][] = 1
1517        endif
1518
1519///
1520// for B, there can also be lateral offset of the B panel
1521        target = "B"
1522
1523        L2_M = VC_calc_L2(target)
1524        // mask data
1525        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1526
1527// extent of shadow in [cm] (starting point of shadow from center of beam)
1528// hard
1529        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1530// soft
1531        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1532
1533        //use the smaller shadow value
1534        delta = min(delta_Xh,delta_Xs)
1535//      delta = delta_Xh
1536       
1537// how many detector tubes to mask?
1538        pixSizeX = VCALC_getPixSizeX(target)
1539        pixSizeY = VCALC_getPixSizeY(target)
1540
1541// offset of B, in "pixels"
1542        offset_B = VCALC_getPanelTranslation(target)/pixSizeX           //[cm]
1543        offset_B = -trunc(offset_B)
1544        //since "target" is B, use x-position
1545        // at what "pixel" does the shadow start?
1546        delta_X_pix = trunc(delta/pixSizeX)
1547        nPix = VCALC_get_nPix_X(target)
1548       
1549        //is the delta_x_pix still on the left edge of B?
1550        if(delta_x_pix < 0)             //entire panel is shadowed
1551                nt = nPix-1
1552                mask[0,nt][] = 1
1553        else
1554                if(delta_X_pix < nPix + offset_B)
1555                        nt = nPix + offset_B - delta_x_pix
1556                        mask[0,nt][] = 1
1557                endif
1558        endif
1559       
1560        return(0)
1561end
1562
1563// MR shadows MT, MB, B
1564Function VC_DrawVCALCMask_MR()
1565       
1566        Variable pixSizeX,pixSizeY,nPix,nt
1567
1568        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1569        Variable delta_Xh,delta_Xs,delta_X_pix,delta
1570        String type,target
1571
1572// MR shadows MT, MB, B
1573        type = "MR"
1574
1575        // lateral offset of FR
1576        offset = VCALC_getPanelTranslation(type)
1577        // sample aperture diam [cm]
1578        D2 = VC_sampleApertureDiam()
1579        // sdd F         [cm] = sample aperture to detector
1580        L2_F = VC_calc_L2(type)
1581        // depth of electronics (L/R panels)
1582        delta_L = 33            //[cm]
1583        // offset of 80/20 frame
1584        delta_S = 2.5           //[cm]
1585       
1586       
1587        // sdd of MT, or MB, or B
1588/////
1589        target = "MT"
1590        L2_M = VC_calc_L2(target)
1591        // mask data
1592        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1593
1594// extent of shadow in [cm] (starting point of shadow from center of beam)
1595// hard
1596        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1597// soft
1598        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1599
1600        //use the smaller shadow value (this means closer to the center, a larger shadow)
1601        delta = min(delta_Xh,delta_Xs)
1602
1603// how many detector tubes to mask?
1604        pixSizeX = VCALC_getPixSizeX(target)
1605        pixSizeY = VCALC_getPixSizeY(target)
1606
1607        //since "target" is MT, use x-position
1608        // at what "pixel" does the shadow start?
1609        delta_X_pix = trunc(delta/pixSizeX)
1610        nPix = VCALC_get_nPix_X(target)
1611
1612        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the MT panel
1613                nt = trunc(nPix/2) - delta_x_pix
1614                mask[nPix-nt,nPix-1][] = 1
1615        endif
1616       
1617/////
1618        target = "MB"
1619        L2_M = VC_calc_L2(target)
1620        // mask data
1621        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1622
1623// extent of shadow in [cm] (starting point of shadow from center of beam)
1624// hard
1625        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1626// soft
1627        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1628
1629        //use the smaller shadow value
1630        delta = min(delta_Xh,delta_Xs)
1631       
1632// how many detector tubes to mask?
1633        pixSizeX = VCALC_getPixSizeX(target)
1634        pixSizeY = VCALC_getPixSizeY(target)
1635
1636        //since "target" is FB, use x-position
1637        // at what "pixel" does the shadow start?
1638        delta_X_pix = trunc(delta/pixSizeX)
1639        nPix = VCALC_get_nPix_X(target)
1640
1641        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the MB panel
1642                nt = trunc(nPix/2) - delta_x_pix
1643                mask[nPix-nt,nPix-1][] = 1
1644        endif
1645
1646///
1647// for B, there can also be lateral offset of the panel
1648        target = "B"
1649
1650        L2_M = VC_calc_L2(target)
1651        // mask data
1652        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1653
1654// extent of shadow in [cm] (starting point of shadow from center of beam)
1655// hard
1656        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1657// soft
1658        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1659
1660        //use the smaller shadow value
1661        delta = min(delta_Xh,delta_Xs)
1662       
1663// how many detector tubes to mask?
1664        pixSizeX = VCALC_getPixSizeX(target)
1665        pixSizeY = VCALC_getPixSizeY(target)
1666
1667// offset of B, in "pixels"
1668        offset_B = VCALC_getPanelTranslation(target)/pixSizeX           //[cm]
1669        offset_B = trunc(offset_B)
1670        //since "target" is B, use x-position
1671        // at what "pixel" does the shadow start?
1672        nPix = VCALC_get_nPix_X(target)
1673       
1674        delta_X_pix = trunc(delta/pixSizeX)
1675       
1676        //is the delta_x_pix still on the right edge of B?
1677        if(delta_x_pix < 0)             //entire panel is shadowed
1678                nt = nPix-1
1679                mask[0,nt][] = 1
1680        else
1681                if(delta_X_pix < nPix + offset_B)
1682                        nt = nPix + offset_B - delta_x_pix
1683                        mask[nPix-nt,nPix-1][] = 1
1684                endif
1685        endif
1686       
1687        return(0)
1688end
1689
1690
1691// MT shadows B
1692Function VC_DrawVCALCMask_MT()
1693       
1694        Variable pixSizeX,pixSizeY,nPix,nt
1695
1696        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1697        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1698        String type,target
1699
1700// MT shadows B
1701        type = "MT"
1702
1703        //  offset of MT
1704        offset = VCALC_getPanelTranslation(type)
1705        // sample aperture diam [cm]
1706        D2 = VC_sampleApertureDiam()
1707        // sdd F         [cm] = sample aperture to detector
1708        L2_F = VC_calc_L2(type)
1709        // depth of electronics (T/B panels)
1710        delta_L = 61            //[cm]
1711        // offset of 80/20 frame
1712        delta_S = 2.5           //[cm]
1713       
1714       
1715        // sdd of ML, or MR, or MT
1716///////
1717//      target = "ML"
1718//      L2_M = VC_calc_L2(target)
1719//      // mask data
1720//      Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1721//
1722//// extent of shadow in [cm] (starting point of shadow from center of beam)
1723//// hard
1724//      delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1725//// soft
1726//      delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1727//
1728//      //use the smaller shadow value (this means closer to the center, a larger shadow)
1729//      delta = min(delta_Xh,delta_Xs)
1730//
1731//// how many detector tubes to mask?
1732//      pixSizeX = VCALC_getPixSizeX(target)
1733//      pixSizeY = VCALC_getPixSizeY(target)
1734//
1735//      //since "target" is ML, use Y-position
1736//      // at what "pixel" does the shadow start?
1737//      delta_Y_pix = trunc(delta/pixSizeY)
1738//      nPix = VCALC_get_nPix_Y(target)
1739//
1740//      if(delta_y_pix < trunc(nPix/2))
1741//              nt = trunc(nPix/2) - delta_y_pix
1742//              mask[][nPix-nt,nPix-1] = 1
1743//      endif
1744
1745/////
1746//      target = "MR"
1747//      L2_M = VC_calc_L2(target)
1748//      // mask data
1749//      Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1750//
1751//// extent of shadow in [cm] (starting point of shadow from center of beam)
1752//// hard
1753//      delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1754//// soft
1755//      delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1756//
1757//      //use the smaller shadow value
1758//      delta = min(delta_Xh,delta_Xs)
1759//
1760//     
1761//// how many detector tubes to mask?
1762//      pixSizeX = VCALC_getPixSizeX(target)
1763//      pixSizeY = VCALC_getPixSizeY(target)
1764//
1765//      //since "target" is MR, use y-position
1766//      // at what "pixel" does the shadow start?
1767//      delta_y_pix = trunc(delta/pixSizey)
1768//      nPix = VCALC_get_nPix_Y(target)
1769//
1770//      if(delta_y_pix < trunc(nPix/2))
1771//              nt = trunc(nPix/2) - delta_y_pix
1772//              mask[][nPix-nt,nPix-1] = 1
1773//      endif
1774       
1775///
1776// for B, there can also be lateral offset of the B panel
1777        target = "B"
1778
1779        L2_M = VC_calc_L2(target)
1780        // mask data
1781        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1782
1783// extent of shadow in [cm] (starting point of shadow from center of beam)
1784// hard
1785        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1786// soft
1787        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1788
1789        //use the smaller shadow value
1790        delta = min(delta_Xh,delta_Xs)
1791       
1792// how many detector tubes to mask?
1793        pixSizeX = VCALC_getPixSizeX(target)
1794        pixSizeY = VCALC_getPixSizeY(target)
1795
1796// offset of B, in "pixels" -in Y-direction
1797        offset_B = VCALC_getPanelTranslation(target)/pixSizeY           //[cm]
1798        offset_B = trunc(offset_B)
1799        //since "target" is B, use y-position
1800        // at what "pixel" does the shadow start?
1801        delta_Y_pix = trunc(delta/pixSizeY)
1802        nPix = VCALC_get_nPix_Y(target)
1803
1804        if(delta_y_pix < trunc(nPix/2))
1805                nt = trunc(nPix/2) - delta_y_pix
1806                mask[][nPix-nt,nPix-1] = 1
1807        endif
1808       
1809        return(0)
1810end
1811
1812// MB shadows B
1813Function VC_DrawVCALCMask_MB()
1814       
1815        Variable pixSizeX,pixSizeY,nPix,nt
1816
1817        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1818        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1819        String type,target
1820
1821// MB shadows B
1822        type = "MB"
1823
1824        //  offset of MB
1825        offset = VCALC_getPanelTranslation(type)
1826       
1827        // sample aperture diam [cm]
1828        D2 = VC_sampleApertureDiam()
1829        // sdd F         [cm] = sample aperture to detector
1830        L2_F = VC_calc_L2(type)
1831        // depth of electronics (T/B panels)
1832        delta_L = 61            //[cm]
1833        // offset of 80/20 frame
1834        delta_S = 2.5           //[cm]
1835       
1836       
1837        // sdd of ML, or MR, or MB
1838/////
1839//      target = "ML"
1840//      L2_M = VC_calc_L2(target)
1841//      // mask data
1842//      Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1843//
1844//// extent of shadow in [cm] (starting point of shadow from center of beam)
1845//// hard
1846//      delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1847//// soft
1848//      delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1849//
1850//      //use the smaller shadow value (this means closer to the center, a larger shadow)
1851//      delta = min(delta_Xh,delta_Xs)
1852//
1853//     
1854//// how many detector tubes to mask?
1855//      pixSizeX = VCALC_getPixSizeX(target)
1856//      pixSizeY = VCALC_getPixSizeY(target)
1857//
1858//      //since "target" is ML, use Y-position
1859//      // at what "pixel" does the shadow start?
1860//      delta_Y_pix = trunc(delta/pixSizeY)
1861//      nPix = VCALC_get_nPix_Y(target)
1862//
1863//      if(delta_y_pix < trunc(nPix/2))
1864//              nt = trunc(nPix/2) - delta_y_pix
1865//              mask[][0,nt] = 1
1866//      endif
1867       
1868/////
1869//      target = "MR"
1870//      L2_M = VC_calc_L2(target)
1871//      // mask data
1872//      Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1873//
1874//// extent of shadow in [cm] (starting point of shadow from center of beam)
1875//// hard
1876//      delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1877//// soft
1878//      delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1879//
1880//      //use the smaller shadow value
1881//      delta = min(delta_Xh,delta_Xs)
1882//     
1883//// how many detector tubes to mask?
1884//      pixSizeX = VCALC_getPixSizeX(target)
1885//      pixSizeY = VCALC_getPixSizeY(target)
1886//
1887//      //since "target" is MR, use y-position
1888//      // at what "pixel" does the shadow start?
1889//      delta_y_pix = trunc(delta/pixSizeY)
1890//      nPix = VCALC_get_nPix_Y(target)
1891//
1892//      if(delta_y_pix < trunc(nPix/2))
1893//              nt = trunc(nPix/2) - delta_y_pix
1894//              mask[][0,nt] = 1
1895//      endif
1896       
1897///
1898// for B, there can also be lateral offset of the B panel
1899        target = "B"
1900
1901        L2_M = VC_calc_L2(target)
1902        // mask data
1903        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1904
1905// extent of shadow in [cm] (starting point of shadow from center of beam)
1906// hard
1907        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1908// soft
1909        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1910
1911        //use the smaller shadow value
1912        delta = min(delta_Xh,delta_Xs)
1913       
1914// how many detector tubes to mask?
1915        pixSizeX = VCALC_getPixSizeX(target)
1916        pixSizeY = VCALC_getPixSizeY(target)
1917
1918// offset of B, in "pixels" -in Y-direction
1919        offset_B = VCALC_getPanelTranslation(target)/pixSizeY           //[cm]
1920        offset_B = -trunc(offset_B)
1921        //since "target" is MT, use y-position
1922        // at what "pixel" does the shadow start?
1923        delta_Y_pix = trunc(delta/pixSizeY)
1924        nPix = VCALC_get_nPix_Y(target)
1925
1926        if(delta_y_pix < trunc(nPix/2))
1927                nt = trunc(nPix/2) - delta_y_pix
1928                mask[][0,nt] = 1
1929        endif
1930
1931        return(0)
1932end
1933
1934
1935
1936
1937//
1938// resets the mask to 0 = (use all)
1939//
1940Function VC_ResetVCALCMask()
1941
1942        Variable ii
1943        String detStr
1944       
1945        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
1946                detStr = StringFromList(ii, ksDetectorListAll, ";")
1947                Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+detStr+":data")
1948                mask = 0       
1949        endfor
1950       
1951        return(0)
1952end
1953
1954
Note: See TracBrowser for help on using the repository browser.