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

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

updating the IgorVersion? pragma to v7.0 for all files to be consistent.

File size: 61.9 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2#pragma IgorVersion = 7.00
3
4////////////////////////
5//
6//
7// a bunch of utility procedures to access information from the VCALC panel and to access
8// constants based in which of the detectors I'm trying to work with. Saves a lot of repetitive switches
9//
10// start the function names with VCALC_ to avoid the eventual conflicts with the file loading utilities
11// for reduction of real VSANS data
12//
13//
14// -- add more of these procedures as more items are added to the panel
15//
16////////////////////////
17
18
19//  Values from the VCALC panel
20
21
22
23
24// returns the panel translation [cm]
25Function VCALC_getPanelTranslation(type)
26        String type
27       
28        Variable sep
29       
30        strswitch(type)
31                case "FL":
32                        ControlInfo/W=VCALC VCALCCtrl_2a
33                        sep = V_Value
34                        break
35                case "FR":
36                        ControlInfo/W=VCALC VCALCCtrl_2aa
37                        sep = V_Value
38                        break
39                case "FT":
40                        ControlInfo/W=VCALC VCALCCtrl_2b
41                        sep = V_Value   
42                        break
43                case "FB":
44                        ControlInfo/W=VCALC VCALCCtrl_2bb
45                        sep = V_Value   
46                        break
47
48                case "ML":
49                        ControlInfo/W=VCALC VCALCCtrl_3a
50                        sep = V_Value
51                        break
52                case "MR":
53                        ControlInfo/W=VCALC VCALCCtrl_3aa
54                        sep = V_Value
55                        break
56                case "MT":
57                        ControlInfo/W=VCALC VCALCCtrl_3b
58                        sep = V_Value
59                        break   
60                case "MB":
61                        ControlInfo/W=VCALC VCALCCtrl_3bb
62                        sep = V_Value
63                        break   
64                                               
65                case "B":               
66                        sep = 0
67                        break
68                       
69                default:
70                        Print "Error -- type not found in        VCALC_getPanelSeparation(type)"                                       
71                        sep = NaN               //no match for type             
72        endswitch
73       
74        return(sep)
75end
76
77
78
79// returns the (mean) wavelength from the panel -- value is angstroms
80Function VCALC_getWavelength()
81       
82        ControlInfo/W=VCALC VCALCCtrl_0b
83
84        return(V_Value)
85end
86
87// returns the wavelength spread from the panel -- value is fraction
88Function VCALC_getWavelengthSpread()
89       
90        ControlInfo/W=VCALC VCALCCtrl_0d
91
92        return(str2num(S_Value))
93end
94
95// returns the number of neutrons on the sample
96Function VCALC_getImon()
97       
98        ControlInfo/W=VCALC VCALCCtrl_5a
99
100        return(V_Value)
101end
102
103// returns the model function to use
104Function/S VCALC_getModelFunctionStr()
105       
106        ControlInfo/W=VCALC VCALCCtrl_5b
107
108        return(S_Value)
109end
110
111
112
113/// NVARs set in VCALC space (not necessarily matching the true instrument values)
114// -- these all set to the proper data folder, then BACK TO ROOT:
115
116
117// return the pixel X size, in [cm]
118Function VCALC_getPixSizeX(type)
119        String type
120
121        Variable pixSizeX = V_getDet_x_pixel_size("VCALC",type)
122
123        return(pixSizeX)
124end
125
126// return the pixel Y size, in [cm]
127Function VCALC_getPixSizeY(type)
128        String type
129
130        Variable pixSizeY = V_getDet_y_pixel_size("VCALC",type)
131       
132        return(pixSizeY)
133end
134
135
136// return the number of pixels in x-dimension
137Function VCALC_get_nPix_X(type)
138        String type
139
140        Variable nPix = V_getDet_pixel_num_x("VCALC",type)
141       
142        return(nPix)
143end
144
145// return the number of pixels in y-dimension
146Function VCALC_get_nPix_Y(type)
147        String type
148
149        Variable nPix = V_getDet_pixel_num_y("VCALC",type)
150
151        return(nPix)
152end
153
154
155
156// SDD offset of the top/bottom panels
157// value returned is in [cm]
158//
159Function VCALC_getTopBottomSDDSetback(type)
160        String type
161
162        SetDataFolder root:Packages:NIST:VSANS:VCALC
163       
164        strswitch(type)
165                case "FL":
166                case "FR":
167                        SetDataFolder root:
168                        return(0)               
169                        break           //already zero, do nothing
170                case "FT":
171                case "FB":             
172                        NVAR sdd_setback = gFront_SDDsetback    //T/B are 41 cm farther back
173                        break
174                       
175                case "ML":
176                case "MR":
177                        SetDataFolder root:
178                        return(0)
179                        break           //already zero, do nothing
180                case "MT":
181                case "MB":
182                        NVAR sdd_setback = gMiddle_SDDsetback   //T/B are 41 cm farther back
183                        break   
184                                               
185                case "B":
186                case "B ":
187                        SetDataFolder root:
188                        return(0)
189                        break           //already zero, do nothing
190                       
191                default:
192                        Print "Error -- type not found in        VCALC_getTopBottomSDDSetback(type)"                                   
193                        sdd_setback = 0         //no match for type             
194        endswitch
195
196        SetDataFolder root:
197               
198        return(sdd_setback)     
199End
200
201
202Function VC_getNumGuides()
203
204        Variable ng
205        ControlInfo/W=VCALC VCALCCtrl_0a
206        ng = V_Value
207        return(ng)
208End
209//////////////////////////////////
210//
211// Actions for the VCALC controls
212//
213//////////////////////////////////
214
215// get the sourceAperture_to_GateValve distance from the table
216//
217// correct for the sampleAperture_to_GateValve distance
218//
219// return the SourceAp to SampleAp Distance in [cm]
220Function VC_calcSSD()
221
222        Variable ng,ssd,samAp_to_GV
223        ControlInfo/W=VCALC VCALCCtrl_0a
224        ng = V_Value
225
226        ControlInfo/W=VCALC VCALCCtrl_1d
227        samAp_to_GV = V_Value           // [cm]
228       
229        switch(ng)
230                case 0:
231                                ssd = 2441
232                        break
233                case 1:
234                                ssd = 2157
235                        break
236                case 2:
237                                ssd = 1976
238                        break
239                case 3:
240                                ssd = 1782
241                        break                   
242                case 4:
243                                ssd = 1582
244                        break                   
245                case 5:
246                                ssd = 1381
247                        break                   
248                case 6:
249                                ssd = 1181
250                        break                   
251                case 7:
252                                ssd = 980
253                        break                   
254                case 8:
255                                ssd = 780
256                        break                   
257                case 9:
258                                ssd = 579
259                        break                   
260                default:
261                        Print "Error - using default SSD value"
262                        ssd = 2441
263        endswitch
264        ssd -= samAp_to_GV
265       
266//      print "SSD (cm) = ",ssd
267        return(ssd)
268End
269
270
271// read the number of guides from the slider
272// return the Source aperture diameter [cm]
273// TODO - needs a case statement since a1 can depend on Ng
274Function VC_sourceApertureDiam()
275
276        Variable ng,a1
277        ControlInfo/W=VCALC VCALCCtrl_0a
278        ng = V_Value
279
280        ControlInfo/W=VCALC VCALCCtrl_0f
281        String apStr = S_Value
282       
283
284        if(ng > 0)     
285                a1 = 6          // 60 mm diameter
286        else
287                sscanf apStr, "%g cm", a1
288        endif
289
290//      Print "Source Ap diam (cm) = ",a1
291        return(a1)
292End
293
294// reports tha value in [cm]
295Function VC_sampleApertureDiam()
296
297        ControlInfo/W=VCALC VCALCCtrl_1c
298        Variable val = str2num(S_Value)
299
300        return(val)
301End
302
303
304///////////////////
305//
306// Presets
307//
308///////////////////
309
310
311// for Front+Middle Only
312// x F SDD=120
313// x (L=-20, R=20) (T=4, B=-4)
314//
315// x M SDD = 1900
316// x (L=0, R=0)
317//
318// x Velocity selector
319// x Ng = 0
320// x Lam = 8
321// x delLam = 0.12
322// source ap = ? (circular)
323//
324// ignore back detector
325// x set plot type to F2-M2xTB-B
326//
327//
328Function VC_Preset_FrontMiddle_Ng0()
329
330// set preference to ignore back detector
331        NVAR gIgnoreB = root:Packages:NIST:VSANS:Globals:gIgnoreDetB
332        gIgnoreB = 1
333       
334        // front carriage
335        SetVariable VCALCCtrl_2a,value=_NUM:-10         //Left offset
336        SetVariable VCALCCtrl_2aa,value=_NUM:10         //Right offset
337        SetVariable VCALCCtrl_2b,value=_NUM:4                   //Top offset
338        SetVariable VCALCCtrl_2bb,value=_NUM:-4         //Bottom offset
339
340        SetVariable VCALCCtrl_2d,value=_NUM:400         //SDD
341
342        // middle carriage
343        SetVariable VCALCCtrl_3a,value=_NUM:-10         //Left offset
344        SetVariable VCALCCtrl_3aa,value=_NUM:-10                //Right offset
345        SetVariable VCALCCtrl_3b,value=_NUM:4                   //Top offset (doesn't matter)
346        SetVariable VCALCCtrl_3bb,value=_NUM:-4         //Bottom offset (doesn't matter)
347
348        SetVariable VCALCCtrl_3d,value=_NUM:1900                //SDD
349       
350       
351        // monochromator
352        PopupMenu VCALCCtrl_0c,mode=1,popvalue="Velocity Selector"
353       
354        // wavelength spread
355        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
356        DLStr = "0.12;"
357//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
358        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12"
359       
360        // wavelength
361        SetVariable VCALCCtrl_0b,value=_NUM:6
362
363        //number of guides
364//      Slider VCALCCtrl_0a,value= 0
365        V_GuideSliderProc("VCALCCtrl_0a",0,1)           //Set Ng=0, resets the aperture string to the new string
366        Slider VCALCCtrl_0a,value=0
367
368       
369// source aperture (+new string)
370        PopupMenu VCALCCtrl_0f,mode=3           //set the 3.0 cm aperture
371       
372// binning mode
373        PopupMenu popup_b,mode=1,popValue="F2-M2xTB-B"
374
375
376        return(0)
377End
378
379
380Function VC_Preset_FrontMiddle_Ng2()
381
382        // front carriage
383        SetVariable VCALCCtrl_2a,value=_NUM:-10         //Left offset
384        SetVariable VCALCCtrl_2aa,value=_NUM:10         //Right offset
385        SetVariable VCALCCtrl_2b,value=_NUM:4                   //Top offset
386        SetVariable VCALCCtrl_2bb,value=_NUM:-4         //Bottom offset
387
388        SetVariable VCALCCtrl_2d,value=_NUM:350         //SDD
389
390        // middle carriage
391        SetVariable VCALCCtrl_3a,value=_NUM:-10         //Left offset
392        SetVariable VCALCCtrl_3aa,value=_NUM:-10                //Right offset
393        SetVariable VCALCCtrl_3b,value=_NUM:4                   //Top offset (doesn't matter)
394        SetVariable VCALCCtrl_3bb,value=_NUM:-4         //Bottom offset (doesn't matter)
395
396        SetVariable VCALCCtrl_3d,value=_NUM:1600                //SDD
397       
398       
399        // monochromator
400        PopupMenu VCALCCtrl_0c,mode=1,popvalue="Velocity Selector"
401       
402        // wavelength spread
403        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
404        DLStr = "0.12;"
405//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
406        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12"
407       
408        // wavelength
409        SetVariable VCALCCtrl_0b,value=_NUM:6
410
411        //number of guides
412//      Slider VCALCCtrl_0a,value= 0
413        V_GuideSliderProc("VCALCCtrl_0a",2,1)           //Set Ng=2, resets the aperture string to the new string
414        Slider VCALCCtrl_0a,value=2
415       
416// source aperture (+new string)
417        PopupMenu VCALCCtrl_0f,mode=1           //6.0 cm aperture
418       
419
420// binning mode
421        PopupMenu popup_b,mode=1,popValue="F2-M2xTB-B"
422
423
424        return(0)
425End
426
427Function VC_Preset_FrontMiddle_Ng7()
428
429        // front carriage
430        SetVariable VCALCCtrl_2a,value=_NUM:-10         //Left offset
431        SetVariable VCALCCtrl_2aa,value=_NUM:10         //Right offset
432        SetVariable VCALCCtrl_2b,value=_NUM:4                   //Top offset
433        SetVariable VCALCCtrl_2bb,value=_NUM:-4         //Bottom offset
434
435        SetVariable VCALCCtrl_2d,value=_NUM:230         //SDD
436
437        // middle carriage
438        SetVariable VCALCCtrl_3a,value=_NUM:-10         //Left offset
439        SetVariable VCALCCtrl_3aa,value=_NUM:-10                //Right offset
440        SetVariable VCALCCtrl_3b,value=_NUM:4                   //Top offset (doesn't matter)
441        SetVariable VCALCCtrl_3bb,value=_NUM:-4         //Bottom offset (doesn't matter)
442
443        SetVariable VCALCCtrl_3d,value=_NUM:1100                //SDD
444       
445       
446        // monochromator
447        PopupMenu VCALCCtrl_0c,mode=1,popvalue="Velocity Selector"
448       
449        // wavelength spread
450        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
451        DLStr = "0.12;"
452//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
453        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12"
454       
455        // wavelength
456        SetVariable VCALCCtrl_0b,value=_NUM:6
457
458        //number of guides
459//      Slider VCALCCtrl_0a,value= 0
460        V_GuideSliderProc("VCALCCtrl_0a",7,1)           //Set Ng=7, resets the aperture string to the new string
461        Slider VCALCCtrl_0a,value=7
462
463// source aperture (+new string)
464        PopupMenu VCALCCtrl_0f,mode=1           //6.0 cm aperture
465
466
467// binning mode
468        PopupMenu popup_b,mode=1,popValue="F2-M2xTB-B"
469
470
471        return(0)
472End
473
474Function VC_Preset_FrontMiddle_Ng9()
475
476        // front carriage
477        SetVariable VCALCCtrl_2a,value=_NUM:-10         //Left offset
478        SetVariable VCALCCtrl_2aa,value=_NUM:10         //Right offset
479        SetVariable VCALCCtrl_2b,value=_NUM:4                   //Top offset
480        SetVariable VCALCCtrl_2bb,value=_NUM:-4         //Bottom offset
481
482        SetVariable VCALCCtrl_2d,value=_NUM:100         //SDD
483
484        // middle carriage
485        SetVariable VCALCCtrl_3a,value=_NUM:-10         //Left offset
486        SetVariable VCALCCtrl_3aa,value=_NUM:-10                //Right offset
487        SetVariable VCALCCtrl_3b,value=_NUM:4                   //Top offset (doesn't matter)
488        SetVariable VCALCCtrl_3bb,value=_NUM:-4         //Bottom offset (doesn't matter)
489
490        SetVariable VCALCCtrl_3d,value=_NUM:450         //SDD
491       
492       
493       
494        // monochromator
495        PopupMenu VCALCCtrl_0c,mode=1,popvalue="Velocity Selector"
496       
497        // wavelength spread
498        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
499        DLStr = "0.12;"
500//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
501        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12"
502       
503        // wavelength
504        SetVariable VCALCCtrl_0b,value=_NUM:6
505
506        //number of guides
507//      Slider VCALCCtrl_0a,value= 0
508        V_GuideSliderProc("VCALCCtrl_0a",9,1)           //Set Ng=9, resets the aperture string to the new string
509        Slider VCALCCtrl_0a,value=9
510
511// source aperture (+new string)
512        PopupMenu VCALCCtrl_0f,mode=1           //6.0 cm aperture
513
514
515// binning mode
516        PopupMenu popup_b,mode=1,popValue="F2-M2xTB-B"
517
518
519        return(0)
520End
521
522
523
524
525// White beam preset
526// - set monochromator (this sets lam, delLam)
527// - disregard the back detector (set as front/middle)
528//
529Function VC_Preset_WhiteBeam()
530
531        // monochromator
532        PopupMenu VCALCCtrl_0c,mode=1,popvalue="White Beam"
533       
534        // wavelength spread
535        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
536        DLStr = "0.40;"
537//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.40",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
538        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.40"
539
540// wavelength
541        SetVariable VCALCCtrl_0b,value=_NUM:5.3//,disable=0     ,noedit=0       // allow user editing again
542
543        // adjust the front carriage
544        SetVariable VCALCCtrl_2a,value=_NUM:-20         //Left offset
545        SetVariable VCALCCtrl_2aa,value=_NUM:20         //Right offset
546        SetVariable VCALCCtrl_2b,value=_NUM:8                   //Top offset
547        SetVariable VCALCCtrl_2bb,value=_NUM:-8         //Bottom offset
548
549        SetVariable VCALCCtrl_2d,value=_NUM:120         //SDD
550
551        // middle carriage
552        SetVariable VCALCCtrl_3a,value=_NUM:-15         //Left offset
553        SetVariable VCALCCtrl_3aa,value=_NUM:15         //Right offset
554        SetVariable VCALCCtrl_3b,value=_NUM:15                  //Top offset (doesn't matter)
555        SetVariable VCALCCtrl_3bb,value=_NUM:-15                //Bottom offset (doesn't matter)
556
557        SetVariable VCALCCtrl_3d,value=_NUM:1900                //SDD
558       
559// binning mode
560        PopupMenu popup_b,mode=1,popValue="F4-M4-B"
561
562// set preference to USE back detector
563        NVAR gIgnoreB = root:Packages:NIST:VSANS:Globals:gIgnoreDetB
564        gIgnoreB = 0
565       
566                       
567        return(0)
568end
569
570
571// Graphite - high resolution beam preset
572// - set monochromator (this sets lam, delLam)
573// - uses the back detector (set as front/middle)
574//
575Function VC_Preset_GraphiteMono()
576
577        // front carriage
578        SetVariable VCALCCtrl_2a,value=_NUM:-20         //Left offset
579        SetVariable VCALCCtrl_2aa,value=_NUM:20         //Right offset
580        SetVariable VCALCCtrl_2b,value=_NUM:4                   //Top offset
581        SetVariable VCALCCtrl_2bb,value=_NUM:-4         //Bottom offset
582
583        SetVariable VCALCCtrl_2d,value=_NUM:120         //SDD
584
585        // middle carriage
586        SetVariable VCALCCtrl_3a,value=_NUM:-8          //Left offset
587        SetVariable VCALCCtrl_3aa,value=_NUM:08 //Right offset
588        SetVariable VCALCCtrl_3b,value=_NUM:18                  //Top offset (doesn't matter)
589        SetVariable VCALCCtrl_3bb,value=_NUM:-18                //Bottom offset (doesn't matter)
590
591        SetVariable VCALCCtrl_3d,value=_NUM:1500                //SDD
592
593        // back carriage       
594        SetVariable VCALCCtrl_4b,value=_NUM:2300                //SDD
595       
596        // monochromator
597        PopupMenu VCALCCtrl_0c,mode=1,popvalue="Graphite"
598       
599        // wavelength spread
600        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
601        DLStr = "0.01;"
602//      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
603        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.01"
604       
605        // wavelength
606        SetVariable VCALCCtrl_0b,value=_NUM:4.75//,disable=0    ,noedit=0       // allow user editing again
607
608        //number of guides
609        Slider VCALCCtrl_0a,value= 0
610
611
612// binning mode
613        PopupMenu popup_b,mode=1,popValue="F4-M4-B"
614
615        return(0)
616end
617
618// calculates L2, the sample aperture to detector distance
619Function VC_calc_L2(detStr)
620        String detStr
621
622        Variable a2_to_GV,sam_to_GV,sdd,l2
623        sdd = VC_getSDD(detStr)                 //sample pos to detector
624        ControlInfo/W=VCALC VCALCCtrl_1d
625        a2_to_GV = V_Value
626        ControlInfo/W=VCALC VCALCCtrl_1e
627        sam_to_GV = V_Value
628        l2 = sdd - sam_to_GV + a2_to_GV
629       
630        return(l2)
631End
632
633//
634//direction = one of "vertical;horizontal;maximum;"
635// all of this is bypassed if the lenses are in
636//
637// carrNum = 1,2,3 for F,M,B
638//
639// returns a value in [cm]
640Function VC_beamDiameter(direction,detStr)
641        String direction
642        String detStr
643
644//      NVAR lens = root:Packages:NIST:SAS:gUsingLenses
645//      if(lens)
646//              return sourceApertureDiam()
647//      endif
648       
649        Variable l1,l2,l2Diff
650        Variable d1,d2,bh,bv,bm,umbra,a1,a2
651        Variable lambda,lambda_width,bs_factor
652   
653// TODO: proper value for bs_factor
654        bs_factor = 1.05
655       
656        l1 = VC_calcSSD()
657        lambda = VCALC_getWavelength()
658        lambda_width = VCALC_getWavelengthSpread()
659       
660       
661        Variable a2_to_GV,sam_to_GV,sdd
662        sdd = VC_getSDD(detStr)                 //sample pos to detector
663        ControlInfo/W=VCALC VCALCCtrl_1d
664        a2_to_GV = V_Value
665        ControlInfo/W=VCALC VCALCCtrl_1e
666        sam_to_GV = V_Value
667        l2 = sdd - sam_to_GV + a2_to_GV
668   
669   
670    // TODO verify that these values are in cm
671        a1 = VC_sourceApertureDiam()
672   
673        // sample aperture diam [cm]
674        ControlInfo/W=VCALC VCALCCtrl_1c
675        a2 = V_Value
676   
677    d1 = a1*l2/l1
678    d2 = a2*(l1+l2)/l1
679    bh = d1+d2          //beam size in horizontal direction
680    umbra = abs(d1-d2)
681    //vertical spreading due to gravity
682    bv = bh + 1.25e-8*(l1+l2)*l2*lambda*lambda*lambda_width
683    bm = (bs_factor*bh > bv) ? bs_factor*bh : bv //use the larger of horiz*safety or vertical
684   
685    strswitch(direction)        // string switch
686        case "vertical":                // execute if case matches expression
687                return(bv)
688                break                                           // exit from switch
689        case "horizontal":              // execute if case matches expression
690                return(bh)
691                break
692        case "maximum":         // execute if case matches expression
693                return(bm)
694                break
695        default:                                                        // optional default expression executed
696                return(bm)                                              // when no case matches
697    endswitch
698   
699    return(0)
700   
701End
702
703// 1=front
704// 2=middle
705// 3=back
706// return value is in cm
707// actual Sample position to detector distance is reported
708// Top/Bottom setback is included
709Function VC_getSDD(detStr)
710        String detStr
711       
712        Variable sdd
713
714        strswitch(detstr)
715                case "B":
716                case "B ":
717                        ControlInfo/W=VCALC VCALCCtrl_4b
718                        break
719                case "ML":
720                case "MR":
721                case "MT":
722                case "MB":
723                        ControlInfo/W=VCALC VCALCCtrl_3d
724                        break
725                case "FL":
726                case "FR":
727                case "FT":
728                case "FB":
729                        ControlInfo/W=VCALC VCALCCtrl_2d
730                        break           
731                default:
732                        Print "no case matched in VC_getSDD()"
733        endswitch
734
735        // this is gate valve to detector distance
736        sdd = V_Value
737       
738        sdd += VCALC_getTopBottomSDDSetback(detStr)
739       
740        // VCALCCtrl_1e is Sample Pos to Gate Valve (cm)
741        ControlInfo/W=VCALC VCALCCtrl_1e
742        sdd += V_Value
743       
744        return(sdd)
745end
746
747
748
749Function V_sampleToGateValve()
750        // VCALCCtrl_1e is Sample Pos to Gate Valve (cm)
751        ControlInfo/W=VCALC VCALCCtrl_1e
752        return(V_Value)
753end
754
755
756Function V_sampleApertureToGateValve()
757        // VCALCCtrl_1d is Sample Aperture to Gate Valve (cm)
758        ControlInfo/W=VCALC VCALCCtrl_1d
759        return(V_Value)
760end
761
762
763
764// 1=front
765// 2=middle
766// 3=back
767// return value is in cm
768// gate valve to detector (= nominal distance) is reported
769// Top/Bottom setback is NOT included
770Function VC_getGateValveToDetDist(detStr)
771        String detStr
772       
773        Variable sdd
774
775        strswitch(detstr)
776                case "B":
777                case "B ":
778                        ControlInfo/W=VCALC VCALCCtrl_4b
779                        break
780                case "ML":
781                case "MR":
782                case "MT":
783                case "MB":
784                        ControlInfo/W=VCALC VCALCCtrl_3d
785                        break
786                case "FL":
787                case "FR":
788                case "FT":
789                case "FB":
790                        ControlInfo/W=VCALC VCALCCtrl_2d
791                        break           
792                default:
793                        Print "no case matched in VC_getSDD()"
794        endswitch
795
796        // this is gate valve to detector distance
797        sdd = V_Value
798       
799        return(sdd)
800end     
801
802// TODO
803// -- verify all of the numbers, constants, and "empirical" transmission corrections
804// --
805//
806Function V_beamIntensity()
807
808        Variable as,solid_angle,l1,d2_phi
809        Variable a1,a2,retVal
810        Variable ng
811        Variable lambda_t
812        Variable lambda,phi_0
813        Variable lambda_width
814        Variable guide_loss,t_guide,t_filter,t_total,t_special
815
816        NVAR gBeamInten = root:Packages:NIST:VSANS:VCALC:gBeamIntensity
817 
818// TODO
819// -- verify these numbers
820        lambda_t = 6.20
821        phi_0 = 1.82e13
822        guide_loss = 0.97
823        t_special = 1
824
825        ControlInfo/W=VCALC VCALCCtrl_0a
826        ng = V_Value
827 
828        lambda = VCALC_getWavelength()
829        lambda_width = VCALC_getWavelengthSpread()
830        l1 = VC_calcSSD()
831   
832    // TODO verify that these values are in cm
833        a1 = VC_sourceApertureDiam()
834   
835        // sample aperture diam [cm]
836        a2 = VC_sampleApertureDiam()
837   
838//      alpha = (a1+a2)/(2*l1)  //angular divergence of beam
839//      f = l_gap*alpha/(2*guide_width)
840//      t4 = (1-f)*(1-f)
841//      t6 = 1 - lambda*(b-(ng/8)*(b-c))                //experimental correction factor
842
843        t_guide = exp(ng*ln(guide_loss))        // trans losses of guides in pre-sample flight
844        t_filter = exp(-0.371 - 0.0305*lambda - 0.00352*lambda*lambda)
845        t_total = t_special*t_guide*t_filter
846
847   
848        as = pi/4*a2*a2         //area of sample in the beam
849        d2_phi = phi_0/(2*pi)
850        d2_phi *= exp(4*ln(lambda_t/lambda))
851        d2_phi *= exp(-1*(lambda_t*lambda_t/lambda/lambda))
852
853        solid_angle = pi/4* (a1/l1)*(a1/l1)
854
855        retVal = as * d2_phi * lambda_width * solid_angle * t_total
856
857        // set the global for display
858        gBeamInten = retVal
859       
860        return (retVal)
861end
862
863//
864Function VC_figureOfMerit()
865
866        Variable bi = V_beamIntensity()
867        Variable lambda = VCALC_getWavelength()
868       
869   return (lambda*lambda*bi)
870End
871
872// return a beamstop diameter (cm) larger than maximum beam dimension
873Function VC_beamstopDiam(detStr)
874        String detStr
875       
876        Variable bm=0
877        Variable bs=0.0
878   Variable yesLens=0
879   
880        if(yesLens)
881                //bm = sourceApertureDiam()             //ideal result, not needed
882                bs = 1                                                          //force the diameter to 1"
883        else
884                bm = VC_beamDiameter("maximum",detStr)
885                do
886                bs += 1
887           while ( (bs*2.54 < bm) || (bs > 30.0))                       //30 = ridiculous limit to avoid inf loop
888        endif
889
890        return (bs*2.54)                //return diameter in cm, not inches for txt
891End
892
893// multiply the appropriate IQ data by the beamstop shadow factor for display
894//
895Function V_IQ_BeamstopShadow()
896
897        String popStr
898        Variable binType
899       
900        ControlInfo/W=VCALC popup_b
901        popStr = S_Value       
902
903        binType = V_BinTypeStr2Num(popStr)     
904       
905        String folderStr = "root:Packages:NIST:VSANS:VCALC:"
906       
907
908        String extStr =""
909       
910        switch(binType)
911                case 1:
912                        extStr = ksBinType1             
913
914                        break
915                case 2:
916                        extStr = ksBinType2             
917
918                        break
919                case 3:
920                        extStr = ksBinType3     
921                       
922                        break
923                case 4:                         /// this is for a tall, narrow slit mode       
924                        extStr = ksBinType4
925
926                        break
927                case 5:
928                        extStr = ksBinType5     
929               
930                        break
931                case 6:
932                        extStr = ksBinType6     
933               
934                        break
935                case 7:
936                        extStr = ksBinType7     
937               
938                        break
939                       
940                default:
941                        Abort "Binning mode not found in V_IQ_BeamstopShadow"// when no case matches   
942        endswitch
943
944// TODO:
945// -- I had to put a lot of conditions on when not to try to apply the shadow factor
946// to avoid errors when iq had no points in the wave, or incorrectly applying the beamstop to the back panel.
947       
948        Variable ii
949        String ext
950//      loop over all of the types of data
951        for(ii=0;ii<ItemsInList(extStr);ii+=1)
952                ext = StringFromList(ii, extStr, ";")
953                Wave iq = $(folderStr+"iBin_qxqy_"+ext)
954                Wave/Z fs = $(folderStr+"fSubS_qxqy_"+ext)
955                if(WaveExists(fs) && numpnts(iq) > 0 && cmpstr(ext,"B") != 0)
956                        iq = (fs < 0.1) ? iq*0.1 : iq*fs
957                endif
958        endfor 
959       
960        return(0)
961end
962
963
964
965//
966// instead of setting some of the data to NaN to exclude it, draw a proper mask to be used
967// during the I(q) averaging
968//
969// use both the "hard" and "soft" shadowing
970// -- chooses the more "conservative" of the shadowing values (soft value at short SDD + T/B)
971//
972// the MSK data will be in its ususal location from the initialization.
973//
974// FL shadows FT, FB, ML
975// FR shadows FT, FB, MR
976// FT shadows ML, MR, MT
977// FB shadows ML, MR, MB
978// ML shadows MT, MB, B
979// MR shadows MT, MB, B
980// MT shadows B
981// MB shadows B
982//
983Function VC_DrawVCALCMask()
984
985        VC_DrawVCALCMask_FL()
986        VC_DrawVCALCMask_FR()
987        VC_DrawVCALCMask_FT()
988        VC_DrawVCALCMask_FB()
989       
990        VC_DrawVCALCMask_ML()
991        VC_DrawVCALCMask_MR()
992        VC_DrawVCALCMask_MT()
993        VC_DrawVCALCMask_MB()
994       
995        return(0)
996end
997
998// FL shadows FT, FB, ML
999Function VC_DrawVCALCMask_FL()
1000       
1001        Variable pixSizeX,pixSizeY,nPix,nt
1002
1003        Variable offset,offset_ML,L2_F,L2_M,delta_L,delta_S,D2
1004        Variable delta_Xh,delta_Xs,delta_X_pix,delta
1005        String type,target
1006
1007// FL shadows FT,FB,ML
1008        type = "FL"
1009
1010        // lateral offset of FL
1011        offset = VCALC_getPanelTranslation(type)
1012        // sample aperture diam [cm]
1013        D2 = VC_sampleApertureDiam()
1014        // sdd F         [cm] = sample aperture to detector
1015        L2_F = VC_calc_L2(type)
1016        // depth of electronics (L/R panels)
1017        delta_L = 33            //[cm]
1018        // offset of 80/20 frame
1019        delta_S = 2.5           //[cm]
1020       
1021       
1022        // sdd of FT, or FB, or ML
1023/////
1024        target = "FT"
1025        L2_M = VC_calc_L2(target)
1026        // mask data
1027        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1028
1029// extent of shadow in [cm] (starting point of shadow from center of beam)
1030// hard
1031        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1032// soft
1033        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1034
1035        //use the smaller shadow value (this means closer to the center, a larger shadow)
1036        delta = min(delta_Xh,delta_Xs)
1037
1038// how many detector tubes to mask?
1039        pixSizeX = VCALC_getPixSizeX(target)
1040        pixSizeY = VCALC_getPixSizeY(target)
1041
1042        //since "target" is FT, use x-position
1043        // at what "pixel" does the shadow start?
1044        delta_X_pix = trunc(delta/pixSizeX)             //pixels from the center
1045        nPix = VCALC_get_nPix_X(target)
1046
1047        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the FT panel
1048                nt = trunc(nPix/2) - delta_x_pix
1049                mask[0,nt][] = 1
1050        endif
1051       
1052/////
1053        target = "FB"
1054        L2_M = VC_calc_L2(target)
1055        // mask data
1056        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1057
1058// extent of shadow in [cm] (starting point of shadow from center of beam)
1059// hard
1060        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1061// soft
1062        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1063
1064        //use the smaller shadow value
1065        delta = min(delta_Xh,delta_Xs)
1066       
1067// how many detector tubes to mask?
1068        pixSizeX = VCALC_getPixSizeX(target)
1069        pixSizeY = VCALC_getPixSizeY(target)
1070
1071        //since "target" is FB, use x-position
1072        // at what "pixel" does the shadow start?
1073        delta_X_pix = trunc(delta/pixSizeX)
1074        nPix = VCALC_get_nPix_X(target)
1075
1076        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the FB panel
1077                nt = trunc(nPix/2) - delta_x_pix
1078                mask[0,nt][] = 1
1079        endif
1080
1081///
1082// for ML, there can also be lateral offset of the ML panel
1083        target = "ML"
1084
1085        L2_M = VC_calc_L2(target)
1086        // mask data
1087        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1088
1089// extent of shadow in [cm] (starting point of shadow from center of beam)
1090// hard
1091        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1092// soft
1093        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1094
1095        //use the smaller shadow value
1096        delta = min(delta_Xh,delta_Xs)
1097//      delta = delta_Xh
1098       
1099// how many detector tubes to mask?
1100        pixSizeX = VCALC_getPixSizeX(target)
1101        pixSizeY = VCALC_getPixSizeY(target)
1102
1103// offset of ML, in "pixels"
1104        offset_ML = VCALC_getPanelTranslation(target)/pixSizeX          //[cm]
1105        offset_ML = -trunc(offset_ML)
1106        //since "target" is ML, use x-position
1107        // at what "pixel" does the shadow start?
1108        delta_X_pix = trunc(delta/pixSizeX)
1109        nPix = VCALC_get_nPix_X(target)
1110       
1111        //is the delta_x_pix still on the left edge of ML?
1112        if(delta_x_pix < 0)             //entire panel is shadowed
1113                nt = nPix-1
1114                mask[0,nt][] = 1
1115        else
1116                if(delta_X_pix < nPix + offset_ML)
1117                        nt = nPix + offset_ML - delta_x_pix
1118                        mask[0,nt][] = 1
1119                endif
1120        endif
1121       
1122        return(0)
1123end
1124
1125// FR shadows FT, FB, MR
1126Function VC_DrawVCALCMask_FR()
1127       
1128        Variable pixSizeX,pixSizeY,nPix,nt
1129
1130        Variable offset,offset_MR,L2_F,L2_M,delta_L,delta_S,D2
1131        Variable delta_Xh,delta_Xs,delta_X_pix,delta
1132        String type,target
1133
1134// FR shadows FT, FB, MR
1135        type = "FR"
1136
1137        // lateral offset of FR
1138        offset = VCALC_getPanelTranslation(type)
1139        // sample aperture diam [cm]
1140        D2 = VC_sampleApertureDiam()
1141        // sdd F         [cm] = sample aperture to detector
1142        L2_F = VC_calc_L2(type)
1143        // depth of electronics (L/R panels)
1144        delta_L = 33            //[cm]
1145        // offset of 80/20 frame
1146        delta_S = 2.5           //[cm]
1147       
1148       
1149        // sdd of FT, or FB, or MR
1150/////
1151        target = "FT"
1152        L2_M = VC_calc_L2(target)
1153        // mask data
1154        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1155
1156// extent of shadow in [cm] (starting point of shadow from center of beam)
1157// hard
1158        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1159// soft
1160        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1161
1162        //use the smaller shadow value (this means closer to the center, a larger shadow)
1163        delta = min(delta_Xh,delta_Xs)
1164
1165// how many detector tubes to mask?
1166        pixSizeX = VCALC_getPixSizeX(target)
1167        pixSizeY = VCALC_getPixSizeY(target)
1168
1169        //since "target" is FT, use x-position
1170        // at what "pixel" does the shadow start?
1171        delta_X_pix = trunc(delta/pixSizeX)
1172        nPix = VCALC_get_nPix_X(target)
1173
1174        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the FT panel
1175                nt = trunc(nPix/2) - delta_x_pix
1176                mask[nPix-nt,nPix-1][] = 1
1177        endif
1178       
1179/////
1180        target = "FB"
1181        L2_M = VC_calc_L2(target)
1182        // mask data
1183        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1184
1185// extent of shadow in [cm] (starting point of shadow from center of beam)
1186// hard
1187        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1188// soft
1189        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1190
1191        //use the smaller shadow value
1192        delta = min(delta_Xh,delta_Xs)
1193       
1194// how many detector tubes to mask?
1195        pixSizeX = VCALC_getPixSizeX(target)
1196        pixSizeY = VCALC_getPixSizeY(target)
1197
1198        //since "target" is FB, use x-position
1199        // at what "pixel" does the shadow start?
1200        delta_X_pix = trunc(delta/pixSizeX)
1201        nPix = VCALC_get_nPix_X(target)
1202
1203        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the FB panel
1204                nt = trunc(nPix/2) - delta_x_pix
1205                mask[nPix-nt,nPix-1][] = 1
1206        endif
1207
1208///
1209// for MR, there can also be lateral offset of the panel
1210        target = "MR"
1211
1212        L2_M = VC_calc_L2(target)
1213        // mask data
1214        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1215
1216// extent of shadow in [cm] (starting point of shadow from center of beam)
1217// hard
1218        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1219// soft
1220        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1221
1222        //use the smaller shadow value
1223        delta = min(delta_Xh,delta_Xs)
1224       
1225// how many detector tubes to mask?
1226        pixSizeX = VCALC_getPixSizeX(target)
1227        pixSizeY = VCALC_getPixSizeY(target)
1228
1229// offset of MR, in "pixels"
1230        offset_MR = VCALC_getPanelTranslation(target)/pixSizeX          //[cm]
1231        offset_MR = trunc(offset_MR)
1232        //since "target" is ML, use x-position
1233        // at what "pixel" does the shadow start?
1234        nPix = VCALC_get_nPix_X(target)
1235       
1236        delta_X_pix = trunc(delta/pixSizeX)
1237       
1238        //is the delta_x_pix still on the right edge of MR?
1239        if(delta_x_pix < 0)             //entire panel is shadowed
1240                nt = nPix-1
1241                mask[0,nt][] = 1
1242        else
1243                if(delta_X_pix < nPix + offset_MR)
1244                        nt = nPix + offset_MR - delta_x_pix
1245                        mask[nPix-nt,nPix-1][] = 1
1246                endif
1247        endif
1248               
1249        return(0)
1250end
1251
1252// FT shadows ML, MR, MT
1253Function VC_DrawVCALCMask_FT()
1254       
1255        Variable pixSizeX,pixSizeY,nPix,nt
1256
1257        Variable offset,offset_MT,L2_F,L2_M,delta_L,delta_S,D2
1258        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1259        String type,target
1260
1261// FT shadows ML, MR, MT
1262        type = "FT"
1263
1264        //  offset of FT
1265        offset = VCALC_getPanelTranslation(type)
1266        // sample aperture diam [cm]
1267        D2 = VC_sampleApertureDiam()
1268        // sdd F         [cm] = sample aperture to detector
1269        L2_F = VC_calc_L2(type)
1270        // depth of electronics (T/B panels)
1271        delta_L = 61            //[cm]
1272        // offset of 80/20 frame
1273        delta_S = 2.5           //[cm]
1274       
1275       
1276        // sdd of ML, or MR, or MT
1277/////
1278        target = "ML"
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 (this means closer to the center, a larger shadow)
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        //since "target" is ML, use Y-position
1297        // at what "pixel" does the shadow start?
1298        delta_Y_pix = trunc(delta/pixSizeY)
1299        nPix = VCALC_get_nPix_Y(target)
1300
1301        if(delta_y_pix < trunc(nPix/2))
1302                nt = trunc(nPix/2) - delta_y_pix
1303                mask[][nPix-nt,nPix-1] = 1
1304        endif
1305
1306/////
1307        target = "MR"
1308        L2_M = VC_calc_L2(target)
1309        // mask data
1310        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1311
1312// extent of shadow in [cm] (starting point of shadow from center of beam)
1313// hard
1314        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1315// soft
1316        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1317
1318        //use the smaller shadow value
1319        delta = min(delta_Xh,delta_Xs)
1320
1321       
1322// how many detector tubes to mask?
1323        pixSizeX = VCALC_getPixSizeX(target)
1324        pixSizeY = VCALC_getPixSizeY(target)
1325
1326        //since "target" is MR, use y-position
1327        // at what "pixel" does the shadow start?
1328        delta_y_pix = trunc(delta/pixSizey)
1329        nPix = VCALC_get_nPix_Y(target)
1330
1331        if(delta_y_pix < trunc(nPix/2))
1332                nt = trunc(nPix/2) - delta_y_pix
1333                mask[][nPix-nt,nPix-1] = 1
1334        endif
1335       
1336///
1337// for MT, there can also be lateral offset of the MT panel
1338        target = "MT"
1339
1340        L2_M = VC_calc_L2(target)
1341        // mask data
1342        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1343
1344// extent of shadow in [cm] (starting point of shadow from center of beam)
1345// hard
1346        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1347// soft
1348        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1349
1350        //use the smaller shadow value
1351        delta = min(delta_Xh,delta_Xs)
1352       
1353// how many detector tubes to mask?
1354        pixSizeX = VCALC_getPixSizeX(target)
1355        pixSizeY = VCALC_getPixSizeY(target)
1356
1357// offset of MT, in "pixels" -in Y-direction
1358        offset_MT = VCALC_getPanelTranslation(target)/pixSizeY          //[cm]
1359        offset_MT = trunc(offset_MT)
1360        //since "target" is MT, use y-position
1361        // at what "pixel" does the shadow start?
1362        delta_Y_pix = trunc(delta/pixSizeY)
1363        nPix = VCALC_get_nPix_Y(target)
1364
1365        if(delta_Y_pix < nPix + offset_MT)
1366                nt = nPix + offset_MT - delta_y_pix
1367                mask[][nPix-nt,nPix-1] = 1
1368        endif
1369       
1370       
1371        return(0)
1372end
1373
1374// FB shadows ML, MR, MB
1375Function VC_DrawVCALCMask_FB()
1376       
1377        Variable pixSizeX,pixSizeY,nPix,nt
1378
1379        Variable offset,offset_MB,L2_F,L2_M,delta_L,delta_S,D2
1380        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1381        String type,target
1382
1383// FB shadows ML, MR, MB
1384        type = "FB"
1385
1386        //  offset of FB
1387        offset = VCALC_getPanelTranslation(type)
1388       
1389        // sample aperture diam [cm]
1390        D2 = VC_sampleApertureDiam()
1391        // sdd F         [cm] = sample aperture to detector
1392        L2_F = VC_calc_L2(type)
1393        // depth of electronics (T/B panels)
1394        delta_L = 61            //[cm]
1395        // offset of 80/20 frame
1396        delta_S = 2.5           //[cm]
1397       
1398       
1399        // sdd of ML, or MR, or MB
1400/////
1401        target = "ML"
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 (this means closer to the center, a larger shadow)
1413        delta = min(delta_Xh,delta_Xs)
1414
1415       
1416// how many detector tubes to mask?
1417        pixSizeX = VCALC_getPixSizeX(target)
1418        pixSizeY = VCALC_getPixSizeY(target)
1419
1420        //since "target" is ML, use Y-position
1421        // at what "pixel" does the shadow start?
1422        delta_Y_pix = trunc(delta/pixSizeY)
1423        nPix = VCALC_get_nPix_Y(target)
1424
1425        if(delta_y_pix < trunc(nPix/2))
1426                nt = trunc(nPix/2) - delta_y_pix
1427                mask[][0,nt] = 1
1428        endif
1429       
1430/////
1431        target = "MR"
1432        L2_M = VC_calc_L2(target)
1433        // mask data
1434        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1435
1436// extent of shadow in [cm] (starting point of shadow from center of beam)
1437// hard
1438        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1439// soft
1440        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1441
1442        //use the smaller shadow value
1443        delta = min(delta_Xh,delta_Xs)
1444       
1445// how many detector tubes to mask?
1446        pixSizeX = VCALC_getPixSizeX(target)
1447        pixSizeY = VCALC_getPixSizeY(target)
1448
1449        //since "target" is MR, use y-position
1450        // at what "pixel" does the shadow start?
1451        delta_y_pix = trunc(delta/pixSizeY)
1452        nPix = VCALC_get_nPix_Y(target)
1453
1454        if(delta_y_pix < trunc(nPix/2))
1455                nt = trunc(nPix/2) - delta_y_pix
1456                mask[][0,nt] = 1
1457        endif
1458       
1459///
1460// for MB, there can also be lateral offset of the MT panel
1461        target = "MB"
1462
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
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// offset of MT, in "pixels" -in Y-direction
1481        offset_MB = VCALC_getPanelTranslation(target)/pixSizeY          //[cm]
1482        offset_MB = -trunc(offset_MB)
1483        //since "target" is MT, use y-position
1484        // at what "pixel" does the shadow start?
1485        delta_Y_pix = trunc(delta/pixSizeY)
1486        nPix = VCALC_get_nPix_Y(target)
1487
1488        if(delta_Y_pix < nPix + offset_MB)
1489                nt = nPix + offset_MB - delta_y_pix
1490                mask[][0,nt] = 1
1491        endif
1492       
1493
1494        return(0)
1495end
1496
1497// ML shadows MT, MB, B
1498Function VC_DrawVCALCMask_ML()
1499       
1500        Variable pixSizeX,pixSizeY,nPix,nt
1501
1502        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1503        Variable delta_Xh,delta_Xs,delta_X_pix,delta
1504        String type,target
1505
1506// ML shadows MT, MB, B
1507        type = "ML"
1508
1509        // lateral offset of ML
1510        offset = VCALC_getPanelTranslation(type)
1511        // sample aperture diam [cm]
1512        D2 = VC_sampleApertureDiam()
1513        // sdd F         [cm] = sample aperture to detector
1514        L2_F = VC_calc_L2(type)
1515        // depth of electronics (L/R panels)
1516        delta_L = 33            //[cm]
1517        // offset of 80/20 frame
1518        delta_S = 2.5           //[cm]
1519       
1520       
1521        // sdd of MT, or MB, or B
1522/////
1523        target = "MT"
1524        L2_M = VC_calc_L2(target)
1525        // mask data
1526        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1527
1528// extent of shadow in [cm] (starting point of shadow from center of beam)
1529// hard
1530        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1531// soft
1532        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1533
1534        //use the smaller shadow value (this means closer to the center, a larger shadow)
1535        delta = min(delta_Xh,delta_Xs)
1536
1537// how many detector tubes to mask?
1538        pixSizeX = VCALC_getPixSizeX(target)
1539        pixSizeY = VCALC_getPixSizeY(target)
1540
1541        //since "target" is FT, use x-position
1542        // at what "pixel" does the shadow start?
1543        delta_X_pix = trunc(delta/pixSizeX)             //pixels from the center
1544        nPix = VCALC_get_nPix_X(target)
1545
1546        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the FT panel
1547                nt = trunc(nPix/2) - delta_x_pix
1548                mask[0,nt][] = 1
1549        endif
1550       
1551/////
1552        target = "MB"
1553        L2_M = VC_calc_L2(target)
1554        // mask data
1555        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1556
1557// extent of shadow in [cm] (starting point of shadow from center of beam)
1558// hard
1559        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1560// soft
1561        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1562
1563        //use the smaller shadow value
1564        delta = min(delta_Xh,delta_Xs)
1565       
1566// how many detector tubes to mask?
1567        pixSizeX = VCALC_getPixSizeX(target)
1568        pixSizeY = VCALC_getPixSizeY(target)
1569
1570        //since "target" is MB, use x-position
1571        // at what "pixel" does the shadow start?
1572        delta_X_pix = trunc(delta/pixSizeX)
1573        nPix = VCALC_get_nPix_X(target)
1574
1575        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the MB panel
1576                nt = trunc(nPix/2) - delta_x_pix
1577                mask[0,nt][] = 1
1578        endif
1579
1580///
1581// for B, there can also be lateral offset of the B panel
1582        target = "B"
1583
1584        L2_M = VC_calc_L2(target)
1585        // mask data
1586        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1587
1588// extent of shadow in [cm] (starting point of shadow from center of beam)
1589// hard
1590        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1591// soft
1592        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1593
1594        //use the smaller shadow value
1595        delta = min(delta_Xh,delta_Xs)
1596//      delta = delta_Xh
1597       
1598// how many detector tubes to mask?
1599        pixSizeX = VCALC_getPixSizeX(target)
1600        pixSizeY = VCALC_getPixSizeY(target)
1601
1602// offset of B, in "pixels"
1603        offset_B = VCALC_getPanelTranslation(target)/pixSizeX           //[cm]
1604        offset_B = -trunc(offset_B)
1605        //since "target" is B, use x-position
1606        // at what "pixel" does the shadow start?
1607        delta_X_pix = trunc(delta/pixSizeX)
1608        nPix = VCALC_get_nPix_X(target)
1609       
1610        //is the delta_x_pix still on the left edge of B?
1611        if(delta_x_pix < 0)             //entire panel is shadowed
1612                nt = nPix-1
1613                mask[0,nt][] = 1
1614        else
1615                if(delta_X_pix < nPix + offset_B)
1616                        nt = nPix + offset_B - delta_x_pix
1617                        mask[0,nt][] = 1
1618                endif
1619        endif
1620       
1621        return(0)
1622end
1623
1624// MR shadows MT, MB, B
1625Function VC_DrawVCALCMask_MR()
1626       
1627        Variable pixSizeX,pixSizeY,nPix,nt
1628
1629        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1630        Variable delta_Xh,delta_Xs,delta_X_pix,delta
1631        String type,target
1632
1633// MR shadows MT, MB, B
1634        type = "MR"
1635
1636        // lateral offset of FR
1637        offset = VCALC_getPanelTranslation(type)
1638        // sample aperture diam [cm]
1639        D2 = VC_sampleApertureDiam()
1640        // sdd F         [cm] = sample aperture to detector
1641        L2_F = VC_calc_L2(type)
1642        // depth of electronics (L/R panels)
1643        delta_L = 33            //[cm]
1644        // offset of 80/20 frame
1645        delta_S = 2.5           //[cm]
1646       
1647       
1648        // sdd of MT, or MB, or B
1649/////
1650        target = "MT"
1651        L2_M = VC_calc_L2(target)
1652        // mask data
1653        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1654
1655// extent of shadow in [cm] (starting point of shadow from center of beam)
1656// hard
1657        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1658// soft
1659        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1660
1661        //use the smaller shadow value (this means closer to the center, a larger shadow)
1662        delta = min(delta_Xh,delta_Xs)
1663
1664// how many detector tubes to mask?
1665        pixSizeX = VCALC_getPixSizeX(target)
1666        pixSizeY = VCALC_getPixSizeY(target)
1667
1668        //since "target" is MT, use x-position
1669        // at what "pixel" does the shadow start?
1670        delta_X_pix = trunc(delta/pixSizeX)
1671        nPix = VCALC_get_nPix_X(target)
1672
1673        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the MT panel
1674                nt = trunc(nPix/2) - delta_x_pix
1675                mask[nPix-nt,nPix-1][] = 1
1676        endif
1677       
1678/////
1679        target = "MB"
1680        L2_M = VC_calc_L2(target)
1681        // mask data
1682        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1683
1684// extent of shadow in [cm] (starting point of shadow from center of beam)
1685// hard
1686        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1687// soft
1688        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1689
1690        //use the smaller shadow value
1691        delta = min(delta_Xh,delta_Xs)
1692       
1693// how many detector tubes to mask?
1694        pixSizeX = VCALC_getPixSizeX(target)
1695        pixSizeY = VCALC_getPixSizeY(target)
1696
1697        //since "target" is FB, use x-position
1698        // at what "pixel" does the shadow start?
1699        delta_X_pix = trunc(delta/pixSizeX)
1700        nPix = VCALC_get_nPix_X(target)
1701
1702        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the MB panel
1703                nt = trunc(nPix/2) - delta_x_pix
1704                mask[nPix-nt,nPix-1][] = 1
1705        endif
1706
1707///
1708// for B, there can also be lateral offset of the panel
1709        target = "B"
1710
1711        L2_M = VC_calc_L2(target)
1712        // mask data
1713        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1714
1715// extent of shadow in [cm] (starting point of shadow from center of beam)
1716// hard
1717        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1718// soft
1719        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1720
1721        //use the smaller shadow value
1722        delta = min(delta_Xh,delta_Xs)
1723       
1724// how many detector tubes to mask?
1725        pixSizeX = VCALC_getPixSizeX(target)
1726        pixSizeY = VCALC_getPixSizeY(target)
1727
1728// offset of B, in "pixels"
1729        offset_B = VCALC_getPanelTranslation(target)/pixSizeX           //[cm]
1730        offset_B = trunc(offset_B)
1731        //since "target" is B, use x-position
1732        // at what "pixel" does the shadow start?
1733        nPix = VCALC_get_nPix_X(target)
1734       
1735        delta_X_pix = trunc(delta/pixSizeX)
1736       
1737        //is the delta_x_pix still on the right edge of B?
1738        if(delta_x_pix < 0)             //entire panel is shadowed
1739                nt = nPix-1
1740                mask[0,nt][] = 1
1741        else
1742                if(delta_X_pix < nPix + offset_B)
1743                        nt = nPix + offset_B - delta_x_pix
1744                        mask[nPix-nt,nPix-1][] = 1
1745                endif
1746        endif
1747       
1748        return(0)
1749end
1750
1751
1752// MT shadows B
1753Function VC_DrawVCALCMask_MT()
1754       
1755        Variable pixSizeX,pixSizeY,nPix,nt
1756
1757        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1758        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1759        String type,target
1760
1761// MT shadows B
1762        type = "MT"
1763
1764        //  offset of MT
1765        offset = VCALC_getPanelTranslation(type)
1766        // sample aperture diam [cm]
1767        D2 = VC_sampleApertureDiam()
1768        // sdd F         [cm] = sample aperture to detector
1769        L2_F = VC_calc_L2(type)
1770        // depth of electronics (T/B panels)
1771        delta_L = 61            //[cm]
1772        // offset of 80/20 frame
1773        delta_S = 2.5           //[cm]
1774       
1775       
1776        // sdd of ML, or MR, or MT
1777///////
1778//      target = "ML"
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 (this means closer to the center, a larger shadow)
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//      //since "target" is ML, use Y-position
1797//      // at what "pixel" does the shadow start?
1798//      delta_Y_pix = trunc(delta/pixSizeY)
1799//      nPix = VCALC_get_nPix_Y(target)
1800//
1801//      if(delta_y_pix < trunc(nPix/2))
1802//              nt = trunc(nPix/2) - delta_y_pix
1803//              mask[][nPix-nt,nPix-1] = 1
1804//      endif
1805
1806/////
1807//      target = "MR"
1808//      L2_M = VC_calc_L2(target)
1809//      // mask data
1810//      Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1811//
1812//// extent of shadow in [cm] (starting point of shadow from center of beam)
1813//// hard
1814//      delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1815//// soft
1816//      delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1817//
1818//      //use the smaller shadow value
1819//      delta = min(delta_Xh,delta_Xs)
1820//
1821//     
1822//// how many detector tubes to mask?
1823//      pixSizeX = VCALC_getPixSizeX(target)
1824//      pixSizeY = VCALC_getPixSizeY(target)
1825//
1826//      //since "target" is MR, use y-position
1827//      // at what "pixel" does the shadow start?
1828//      delta_y_pix = trunc(delta/pixSizey)
1829//      nPix = VCALC_get_nPix_Y(target)
1830//
1831//      if(delta_y_pix < trunc(nPix/2))
1832//              nt = trunc(nPix/2) - delta_y_pix
1833//              mask[][nPix-nt,nPix-1] = 1
1834//      endif
1835       
1836///
1837// for B, there can also be lateral offset of the B panel
1838        target = "B"
1839
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
1851        delta = min(delta_Xh,delta_Xs)
1852       
1853// how many detector tubes to mask?
1854        pixSizeX = VCALC_getPixSizeX(target)
1855        pixSizeY = VCALC_getPixSizeY(target)
1856
1857// offset of B, in "pixels" -in Y-direction
1858        offset_B = VCALC_getPanelTranslation(target)/pixSizeY           //[cm]
1859        offset_B = trunc(offset_B)
1860        //since "target" is B, use y-position
1861        // at what "pixel" does the shadow start?
1862        delta_Y_pix = trunc(delta/pixSizeY)
1863        nPix = VCALC_get_nPix_Y(target)
1864
1865        if(delta_y_pix < trunc(nPix/2))
1866                nt = trunc(nPix/2) - delta_y_pix
1867                mask[][nPix-nt,nPix-1] = 1
1868        endif
1869       
1870        return(0)
1871end
1872
1873// MB shadows B
1874Function VC_DrawVCALCMask_MB()
1875       
1876        Variable pixSizeX,pixSizeY,nPix,nt
1877
1878        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1879        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1880        String type,target
1881
1882// MB shadows B
1883        type = "MB"
1884
1885        //  offset of MB
1886        offset = VCALC_getPanelTranslation(type)
1887       
1888        // sample aperture diam [cm]
1889        D2 = VC_sampleApertureDiam()
1890        // sdd F         [cm] = sample aperture to detector
1891        L2_F = VC_calc_L2(type)
1892        // depth of electronics (T/B panels)
1893        delta_L = 61            //[cm]
1894        // offset of 80/20 frame
1895        delta_S = 2.5           //[cm]
1896       
1897       
1898        // sdd of ML, or MR, or MB
1899/////
1900//      target = "ML"
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 (this means closer to the center, a larger shadow)
1912//      delta = min(delta_Xh,delta_Xs)
1913//
1914//     
1915//// how many detector tubes to mask?
1916//      pixSizeX = VCALC_getPixSizeX(target)
1917//      pixSizeY = VCALC_getPixSizeY(target)
1918//
1919//      //since "target" is ML, use Y-position
1920//      // at what "pixel" does the shadow start?
1921//      delta_Y_pix = trunc(delta/pixSizeY)
1922//      nPix = VCALC_get_nPix_Y(target)
1923//
1924//      if(delta_y_pix < trunc(nPix/2))
1925//              nt = trunc(nPix/2) - delta_y_pix
1926//              mask[][0,nt] = 1
1927//      endif
1928       
1929/////
1930//      target = "MR"
1931//      L2_M = VC_calc_L2(target)
1932//      // mask data
1933//      Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1934//
1935//// extent of shadow in [cm] (starting point of shadow from center of beam)
1936//// hard
1937//      delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1938//// soft
1939//      delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1940//
1941//      //use the smaller shadow value
1942//      delta = min(delta_Xh,delta_Xs)
1943//     
1944//// how many detector tubes to mask?
1945//      pixSizeX = VCALC_getPixSizeX(target)
1946//      pixSizeY = VCALC_getPixSizeY(target)
1947//
1948//      //since "target" is MR, use y-position
1949//      // at what "pixel" does the shadow start?
1950//      delta_y_pix = trunc(delta/pixSizeY)
1951//      nPix = VCALC_get_nPix_Y(target)
1952//
1953//      if(delta_y_pix < trunc(nPix/2))
1954//              nt = trunc(nPix/2) - delta_y_pix
1955//              mask[][0,nt] = 1
1956//      endif
1957       
1958///
1959// for B, there can also be lateral offset of the B panel
1960        target = "B"
1961
1962        L2_M = VC_calc_L2(target)
1963        // mask data
1964        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1965
1966// extent of shadow in [cm] (starting point of shadow from center of beam)
1967// hard
1968        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1969// soft
1970        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1971
1972        //use the smaller shadow value
1973        delta = min(delta_Xh,delta_Xs)
1974       
1975// how many detector tubes to mask?
1976        pixSizeX = VCALC_getPixSizeX(target)
1977        pixSizeY = VCALC_getPixSizeY(target)
1978
1979// offset of B, in "pixels" -in Y-direction
1980        offset_B = VCALC_getPanelTranslation(target)/pixSizeY           //[cm]
1981        offset_B = -trunc(offset_B)
1982        //since "target" is MT, use y-position
1983        // at what "pixel" does the shadow start?
1984        delta_Y_pix = trunc(delta/pixSizeY)
1985        nPix = VCALC_get_nPix_Y(target)
1986
1987        if(delta_y_pix < trunc(nPix/2))
1988                nt = trunc(nPix/2) - delta_y_pix
1989                mask[][0,nt] = 1
1990        endif
1991
1992        return(0)
1993end
1994
1995
1996
1997
1998//
1999// resets the mask to 0 = (use all)
2000//
2001Function VC_ResetVCALCMask()
2002
2003        Variable ii
2004        String detStr
2005       
2006        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
2007                detStr = StringFromList(ii, ksDetectorListAll, ";")
2008                Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+detStr+":data")
2009                mask = 0       
2010        endfor
2011       
2012        return(0)
2013end
2014
2015Function/S V_SetConfigurationText()
2016
2017        String str="",temp
2018
2019//      SetDataFolder root:Packages:NIST:SAS
2020//     
2021//      NVAR numberOfGuides=gNg
2022//      NVAR gTable=gTable              //2=chamber, 1=table
2023//      NVAR wavelength=gLambda
2024//      NVAR lambdaWidth=gDeltaLambda
2025////    NVAR instrument = instrument
2026//      NVAR L2diff = L2diff
2027//   NVAR lens = root:Packages:NIST:SAS:gUsingLenses
2028//      SVAR/Z aStr = root:Packages:NIST:gAngstStr
2029//      SVAR selInstr = root:Packages:NIST:SAS:gInstStr
2030
2031        NVAR min_f = root:Packages:NIST:VSANS:VCALC:gQmin_F
2032        NVAR max_f = root:Packages:NIST:VSANS:VCALC:gQmax_F
2033        NVAR min_m = root:Packages:NIST:VSANS:VCALC:gQmin_M
2034        NVAR max_m = root:Packages:NIST:VSANS:VCALC:gQmax_M
2035        NVAR min_b = root:Packages:NIST:VSANS:VCALC:gQmin_B
2036        NVAR max_b = root:Packages:NIST:VSANS:VCALC:gQmax_B
2037       
2038        String aStr = "A"
2039       
2040        sprintf temp,"Source Aperture Diameter =\t\t%6.2f cm\r",VC_sourceApertureDiam()
2041        str += temp
2042        sprintf temp,"Source to Sample =\t\t\t\t%6.0f cm\r",VC_calcSSD()
2043        str += temp
2044//      sprintf temp,"Sample Position to Detector =\t%6.0f cm\r",VC_getSDD("ML")
2045//      str += temp
2046        sprintf temp,"Beam diameter (Mid) =\t\t\t%6.2f cm\r",VC_beamDiameter("maximum","ML")
2047        str += temp
2048        sprintf temp,"Beamstop diameter =\t\t\t\t%6.2f inches\r",VC_beamstopDiam("ML")/2.54
2049        str += temp
2050        sprintf temp,"Back: Min -> Max Q-value =\t\t\t%6.4f -> %6.4f 1/%s \r",min_b,max_b,aStr
2051        str += temp
2052        sprintf temp,"Middle: Min -> Max Q-value =\t\t%6.4f -> %6.4f 1/%s \r",min_m,max_m,aStr
2053        str += temp
2054        sprintf temp,"Front: Min -> Max Q-value =\t\t%6.4f -> %6.4f 1/%s \r",min_f,max_f,aStr
2055        str += temp
2056        sprintf temp,"Beam Intensity =\t\t\t\t%.0f counts/s\r",V_beamIntensity()
2057        str += temp
2058        sprintf temp,"Figure of Merit =\t\t\t\t%3.3g %s^2/s\r",VC_figureOfMerit(),aStr
2059        str += temp
2060//      sprintf temp,"Attenuator transmission =\t\t%3.3g = Atten # %d\r"//,attenuatorTransmission(),attenuatorNumber()
2061//      str += temp
2062////   
2063//      // add text of the user-edited values
2064//      //
2065        sprintf temp,"***************** %s *** %s *****************\r","VSANS","VSANS"
2066        str += temp
2067        sprintf temp,"Sample Aperture Diameter =\t\t\t\t%.2f cm\r",VC_sampleApertureDiam()
2068        str += temp
2069        sprintf temp,"Number of Guides =\t\t\t\t\t\t%d \r", VC_getNumGuides()
2070        str += temp
2071        sprintf temp,"Back: Sample Position to Detector =\t\t\t%.1f cm\r", VC_getSDD("B")
2072        str += temp
2073        sprintf temp,"Middle: Sample Position to Detector =\t\t%.1f cm\r", VC_getSDD("ML")
2074        str += temp
2075        sprintf temp,"\tOffsets (L,R) (T,B) = (%.2f, %.2f) (%.2f, %.2f) cm\r", VCALC_getPanelTranslation("ML"),VCALC_getPanelTranslation("MR"),VCALC_getPanelTranslation("MT"),VCALC_getPanelTranslation("MB")
2076        str += temp
2077        sprintf temp,"Front: Sample Position to Detector =\t\t\t%.1f cm\r", VC_getSDD("FL")
2078        str += temp
2079        sprintf temp,"\tOffsets (L,R) (T,B) = (%.2f, %.2f) (%.2f, %.2f) cm\r", VCALC_getPanelTranslation("FL"),VCALC_getPanelTranslation("FR"),VCALC_getPanelTranslation("FT"),VCALC_getPanelTranslation("FB")
2080        str += temp
2081//      if(gTable==1)
2082//              sprintf temp,"Sample Position is \t\t\t\t\t\tHuber\r"
2083//      else
2084//              sprintf temp,"Sample Position is \t\t\t\t\t\tChamber\r"
2085//      endif
2086//      str += temp
2087//      sprintf temp,"Detector Offset =\t\t\t\t\t\t%.1f cm\r", detectorOffset()
2088//      str += temp
2089        sprintf temp,"Neutron Wavelength =\t\t\t\t\t%.2f %s\r", VCALC_getWavelength(),aStr
2090        str += temp
2091        sprintf temp,"Wavelength Spread, FWHM =\t\t\t\t%.3f\r", VCALC_getWavelengthSpread()
2092        str += temp
2093//      sprintf temp,"Sample Aperture to Sample Position =\t%.2f cm\r", L2Diff
2094//      str += temp
2095//      if(lens==1)
2096//              sprintf temp,"Lenses are IN\r"
2097//      else
2098//              sprintf temp,"Lenses are OUT\r"
2099//      endif
2100//      str += temp
2101       
2102   setDataFolder root:
2103   return str                   
2104End
2105
2106//Write String representing NICE VSANS configuration
2107Function/S V_SetNICEConfigText()
2108       
2109        string temp_s
2110
2111        String titleStr
2112        String keyStr,keyStrEnd
2113        String valueStr,valueStrEnd
2114        String closingStr
2115        String nameStr,valStr,str
2116
2117        keyStr = "        {\r          \"key\": {\r            \"class\": \"java.lang.String\",\r            \"value\": \""
2118        keyStrEnd = "\"\r          },\r"
2119
2120        valueStr = "          \"value\": {\r            \"class\": \"java.lang.String\",\r            \"value\": \""
2121        valueStrEnd = "\"\r          }\r        },\r"
2122
2123        closingStr = "\"\r          }\r        }\r      ]\r    }\r  }\r]\r"
2124
2125        str = "Dummy filler"
2126
2127        titleStr = "VCALC Configuration"
2128
2129        temp_s = ""
2130
2131        temp_s = "[\r  {\r    \"key\": {\r      \"class\": \"java.lang.String\",\r"
2132        temp_s += "      \"value\": \""+titleStr+"\"\r    },\r"
2133        temp_s += "    \"value\": {\r      \"class\": \"java.util.HashMap\",\r      \"value\": [\r"
2134       
2135//front
2136        nameStr = "frontTrans.primaryNode"
2137        valStr = num2Str(VC_getGateValveToDetDist("FL")) + "cm"         //nominal distance, any panel will do
2138        temp_s += keyStr + nameStr + keyStrEnd
2139        temp_s += valueStr + valStr + valueStrEnd
2140       
2141        nameStr = "carriage.frontRight"
2142        valStr = num2Str(VCALC_getPanelTranslation("FR")) + "cm"                //no space before unit
2143        temp_s += keyStr + nameStr + keyStrEnd
2144        temp_s += valueStr + valStr + valueStrEnd
2145       
2146        nameStr = "carriage.frontLeft"
2147        valStr = num2Str(VCALC_getPanelTranslation("FL")) + "cm"                //no space before unit
2148        temp_s += keyStr + nameStr + keyStrEnd
2149        temp_s += valueStr + valStr + valueStrEnd       
2150               
2151        nameStr = "carriage.frontTop"
2152        valStr = num2Str(VCALC_getPanelTranslation("FT")) + "cm"                //no space before unit
2153        temp_s += keyStr + nameStr + keyStrEnd
2154        temp_s += valueStr + valStr + valueStrEnd
2155
2156        nameStr = "carriage.frontBottom"
2157        valStr = num2Str(VCALC_getPanelTranslation("FB")) + "cm"                //no space before unit
2158        temp_s += keyStr + nameStr + keyStrEnd
2159        temp_s += valueStr + valStr + valueStrEnd
2160
2161        nameStr = "frontRightAreaDetector.beamCenterX"
2162        valStr = num2Str(V_getDet_beam_center_x("VCALC","FR")) + "cm"
2163        temp_s += keyStr + nameStr + keyStrEnd
2164        temp_s += valueStr + valStr + valueStrEnd
2165               
2166        nameStr = "frontRightAreaDetector.beamCenterY"
2167        valStr = num2Str(V_getDet_beam_center_y("VCALC","FR")) + "cm"
2168        temp_s += keyStr + nameStr + keyStrEnd
2169        temp_s += valueStr + valStr + valueStrEnd
2170
2171        nameStr = "frontLeftAreaDetector.beamCenterX"
2172        valStr = num2Str(V_getDet_beam_center_x("VCALC","FL")) + "cm"
2173        temp_s += keyStr + nameStr + keyStrEnd
2174        temp_s += valueStr + valStr + valueStrEnd
2175       
2176        nameStr = "frontLeftAreaDetector.beamCenterY"
2177        valStr = num2Str(V_getDet_beam_center_y("VCALC","FL")) + "cm"
2178        temp_s += keyStr + nameStr + keyStrEnd
2179        temp_s += valueStr + valStr + valueStrEnd
2180
2181        nameStr = "frontTopAreaDetector.beamCenterX"
2182        valStr = num2Str(V_getDet_beam_center_x("VCALC","FT")) + "cm"
2183        temp_s += keyStr + nameStr + keyStrEnd
2184        temp_s += valueStr + valStr + valueStrEnd
2185
2186        nameStr = "frontTopAreaDetector.beamCenterY"
2187        valStr = num2Str(V_getDet_beam_center_y("VCALC","FT")) + "cm"
2188        temp_s += keyStr + nameStr + keyStrEnd
2189        temp_s += valueStr + valStr + valueStrEnd
2190
2191        nameStr = "frontBottomAreaDetector.beamCenterX"
2192        valStr = num2Str(V_getDet_beam_center_x("VCALC","FB")) + "cm"
2193        temp_s += keyStr + nameStr + keyStrEnd
2194        temp_s += valueStr + valStr + valueStrEnd
2195
2196        nameStr = "frontBottomAreaDetector.beamCenterY"
2197        valStr = num2Str(V_getDet_beam_center_y("VCALC","FB")) + "cm"
2198        temp_s += keyStr + nameStr + keyStrEnd
2199        temp_s += valueStr + valStr + valueStrEnd
2200       
2201
2202       
2203// middle               
2204        nameStr = "middleTrans.primaryNode"
2205        valStr = num2Str(VC_getGateValveToDetDist("ML")) + "cm"         //nominal distance, any panel will do
2206        temp_s += keyStr + nameStr + keyStrEnd
2207        temp_s += valueStr + valStr + valueStrEnd
2208
2209        nameStr = "carriage.middleRight"
2210        valStr = num2Str(VCALC_getPanelTranslation("MR")) + "cm"                //no space before unit
2211        temp_s += keyStr + nameStr + keyStrEnd
2212        temp_s += valueStr + valStr + valueStrEnd
2213
2214        nameStr = "carriage.middleLeft"
2215        valStr = num2Str(VCALC_getPanelTranslation("ML")) + "cm"                //no space before unit
2216        temp_s += keyStr + nameStr + keyStrEnd
2217        temp_s += valueStr + valStr + valueStrEnd
2218
2219        nameStr = "carriage.middleTop"
2220        valStr = num2Str(VCALC_getPanelTranslation("MT")) + "cm"                //no space before unit
2221        temp_s += keyStr + nameStr + keyStrEnd
2222        temp_s += valueStr + valStr + valueStrEnd
2223
2224        nameStr = "carriage.middleBottom"
2225        valStr = num2Str(VCALC_getPanelTranslation("MB")) + "cm"                //no space before unit
2226        temp_s += keyStr + nameStr + keyStrEnd
2227        temp_s += valueStr + valStr + valueStrEnd
2228
2229        nameStr = "middleRightAreaDetector.beamCenterX"
2230        valStr = num2Str(V_getDet_beam_center_x("VCALC","MR")) + "cm"
2231        temp_s += keyStr + nameStr + keyStrEnd
2232        temp_s += valueStr + valStr + valueStrEnd
2233
2234        nameStr = "middleRightAreaDetector.beamCenterY"
2235        valStr = num2Str(V_getDet_beam_center_y("VCALC","MR")) + "cm"
2236        temp_s += keyStr + nameStr + keyStrEnd
2237        temp_s += valueStr + valStr + valueStrEnd
2238       
2239        nameStr = "middleLeftAreaDetector.beamCenterX"
2240        valStr = num2Str(V_getDet_beam_center_x("VCALC","ML")) + "cm"
2241        temp_s += keyStr + nameStr + keyStrEnd
2242        temp_s += valueStr + valStr + valueStrEnd               
2243
2244        nameStr = "middleLeftAreaDetector.beamCenterY"
2245        valStr = num2Str(V_getDet_beam_center_y("VCALC","ML")) + "cm"
2246        temp_s += keyStr + nameStr + keyStrEnd
2247        temp_s += valueStr + valStr + valueStrEnd
2248               
2249        nameStr = "middleTopAreaDetector.beamCenterX"
2250        valStr = num2Str(V_getDet_beam_center_x("VCALC","MT")) + "cm"
2251        temp_s += keyStr + nameStr + keyStrEnd
2252        temp_s += valueStr + valStr + valueStrEnd
2253
2254        nameStr = "middleTopAreaDetector.beamCenterY"
2255        valStr = num2Str(V_getDet_beam_center_y("VCALC","MT")) + "cm"
2256        temp_s += keyStr + nameStr + keyStrEnd
2257        temp_s += valueStr + valStr + valueStrEnd
2258
2259        nameStr = "middleBottomAreaDetector.beamCenterX"
2260        valStr = num2Str(V_getDet_beam_center_x("VCALC","MB")) + "cm"
2261        temp_s += keyStr + nameStr + keyStrEnd
2262        temp_s += valueStr + valStr + valueStrEnd
2263
2264        nameStr = "middleBottomAreaDetector.beamCenterY"
2265        valStr = num2Str(V_getDet_beam_center_y("VCALC","MB")) + "cm"
2266        temp_s += keyStr + nameStr + keyStrEnd
2267        temp_s += valueStr + valStr + valueStrEnd
2268
2269        nameStr = "C2BeamStop.beamStop"
2270        valStr = num2Str(1)
2271        temp_s += keyStr + nameStr + keyStrEnd
2272        temp_s += valueStr + valStr + valueStrEnd
2273
2274        nameStr = "C2BeamStopY.softPosition"
2275        valStr = num2Str(0) + "cm"              //no space before unit
2276        temp_s += keyStr + nameStr + keyStrEnd
2277        temp_s += valueStr + valStr + valueStrEnd
2278       
2279        nameStr = "C2BeamStopX.X"
2280        valStr = num2Str(0) + "cm"              //no space before unit
2281        temp_s += keyStr + nameStr + keyStrEnd
2282        temp_s += valueStr + valStr + valueStrEnd
2283
2284
2285// back
2286        nameStr = "rearTrans.primaryNode"
2287        valStr = num2Str(VC_getGateValveToDetDist("B")) + "cm"          //nominal distance, any panel will do
2288        temp_s += keyStr + nameStr + keyStrEnd
2289        temp_s += valueStr + valStr + valueStrEnd
2290
2291        nameStr = "C3DetectorOffset.softPosition"
2292        valStr = num2Str(0) + "cm"              //no space before unit
2293        temp_s += keyStr + nameStr + keyStrEnd
2294        temp_s += valueStr + valStr + valueStrEnd
2295
2296        nameStr = "rearAreaDetector.beamCenterX"
2297        valStr = num2Str(V_getDet_beam_center_x_pix("VCALC","B"))
2298        temp_s += keyStr + nameStr + keyStrEnd
2299        temp_s += valueStr + valStr + valueStrEnd
2300
2301        nameStr = "rearAreaDetector.beamCenterY"
2302        valStr = num2Str(V_getDet_beam_center_y_pix("VCALC","B"))
2303        temp_s += keyStr + nameStr + keyStrEnd
2304        temp_s += valueStr + valStr + valueStrEnd
2305       
2306        nameStr = "C3BeamStop.beamStop"
2307        valStr = num2Str(0)
2308        temp_s += keyStr + nameStr + keyStrEnd
2309        temp_s += valueStr + valStr + valueStrEnd
2310
2311        nameStr = "C3BeamStopY.softPosition"
2312        valStr = num2Str(0) + "cm"              //no space before unit
2313        temp_s += keyStr + nameStr + keyStrEnd
2314        temp_s += valueStr + valStr + valueStrEnd
2315
2316        nameStr = "C3BeamStopX.X"
2317        valStr = num2Str(0) + "cm"              //no space before unit
2318        temp_s += keyStr + nameStr + keyStrEnd
2319        temp_s += valueStr + valStr + valueStrEnd
2320
2321
2322
2323//geometry, guides, beam...
2324
2325        nameStr = "guide.guide"
2326        valStr = num2Str(VC_getNumGuides())
2327        temp_s += keyStr + nameStr + keyStrEnd
2328        temp_s += valueStr + valStr + valueStrEnd
2329       
2330        nameStr = "guide.sampleAperture"
2331        valStr = num2Str(VC_sampleApertureDiam()) + "cm"                //no space before unit
2332        temp_s += keyStr + nameStr + keyStrEnd
2333        temp_s += valueStr + valStr + valueStrEnd
2334
2335        nameStr = "guide.sourceAperture"
2336        valStr = num2Str(VC_sourceApertureDiam()) + "cm"                //no space before unit
2337        temp_s += keyStr + nameStr + keyStrEnd
2338        temp_s += valueStr + valStr + valueStrEnd
2339       
2340        nameStr = "geometry.externalSampleApertureShape"
2341        valStr = "CIRCLE"
2342        temp_s += keyStr + nameStr + keyStrEnd
2343        temp_s += valueStr + valStr + valueStrEnd
2344
2345        nameStr = "geometry.externalSampleAperture"
2346        valStr = num2Str(VC_sampleApertureDiam()) + "cm"                //no space before unit
2347        temp_s += keyStr + nameStr + keyStrEnd
2348        temp_s += valueStr + valStr + valueStrEnd
2349
2350        nameStr = "geometry.samplePositionOffset"
2351        valStr = num2Str(V_sampleToGateValve()) + "cm"          //no space before unit
2352        temp_s += keyStr + nameStr + keyStrEnd
2353        temp_s += valueStr + valStr + valueStrEnd
2354       
2355        nameStr = "geometry.sampleApertureOffset"
2356        valStr = num2Str(V_sampleApertureToGateValve()) + "cm"          //no space before unit
2357        temp_s += keyStr + nameStr + keyStrEnd
2358        temp_s += valueStr + valStr + valueStrEnd
2359       
2360        nameStr = "attenuator.attenuator"
2361        valStr = num2Str(0)
2362        temp_s += keyStr + nameStr + keyStrEnd
2363        temp_s += valueStr + valStr + valueStrEnd
2364
2365        nameStr = "wavelength.wavelength"
2366        valStr = num2Str(VCALC_getWavelength()) + "A"           //no space before unit
2367        temp_s += keyStr + nameStr + keyStrEnd
2368        temp_s += valueStr + valStr + valueStrEnd
2369       
2370        nameStr = "wavelengthSpread.wavelengthSpread"
2371        valStr = num2Str(VCALC_getWavelengthSpread())
2372// last one has a different ending sequence     
2373        temp_s += keyStr + nameStr + keyStrEnd
2374        temp_s += valueStr + valStr + closingStr
2375               
2376        return temp_s
2377end
2378
Note: See TracBrowser for help on using the repository browser.