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

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

more changes to VCALC functionality and bug fixes for VCALC

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