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

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

minor changes - can't find the diff command in TortoiseSVN...

File size: 62.1 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        sdd += VCALC_getTopBottomSDDSetback(detStr)             //returns zero for L/R
625        ControlInfo/W=VCALC VCALCCtrl_1d
626        a2_to_GV = V_Value
627        ControlInfo/W=VCALC VCALCCtrl_1e
628        sam_to_GV = V_Value
629        l2 = sdd - sam_to_GV + a2_to_GV
630       
631        return(l2)
632End
633
634//
635//direction = one of "vertical;horizontal;maximum;"
636// all of this is bypassed if the lenses are in
637//
638// carrNum = 1,2,3 for F,M,B
639//
640// returns a value in [cm]
641Function VC_beamDiameter(direction,detStr)
642        String direction
643        String detStr
644
645//      NVAR lens = root:Packages:NIST:SAS:gUsingLenses
646//      if(lens)
647//              return sourceApertureDiam()
648//      endif
649       
650        Variable l1,l2,l2Diff
651        Variable d1,d2,bh,bv,bm,umbra,a1,a2
652        Variable lambda,lambda_width,bs_factor
653   
654// TODO: proper value for bs_factor
655        bs_factor = 1.05
656       
657        l1 = VC_calcSSD()
658        lambda = VCALC_getWavelength()
659        lambda_width = VCALC_getWavelengthSpread()
660       
661       
662        Variable a2_to_GV,sam_to_GV,sdd
663        sdd = VC_getSDD(detStr)                 //sample pos to detector
664        sdd += VCALC_getTopBottomSDDSetback(detStr)             //returns zero for L/R
665        ControlInfo/W=VCALC VCALCCtrl_1d
666        a2_to_GV = V_Value
667        ControlInfo/W=VCALC VCALCCtrl_1e
668        sam_to_GV = V_Value
669        l2 = sdd - sam_to_GV + a2_to_GV
670   
671   
672    // TODO verify that these values are in cm
673        a1 = VC_sourceApertureDiam()
674   
675        // sample aperture diam [cm]
676        ControlInfo/W=VCALC VCALCCtrl_1c
677        a2 = V_Value
678   
679    d1 = a1*l2/l1
680    d2 = a2*(l1+l2)/l1
681    bh = d1+d2          //beam size in horizontal direction
682    umbra = abs(d1-d2)
683    //vertical spreading due to gravity
684    bv = bh + 1.25e-8*(l1+l2)*l2*lambda*lambda*lambda_width
685    bm = (bs_factor*bh > bv) ? bs_factor*bh : bv //use the larger of horiz*safety or vertical
686   
687    strswitch(direction)        // string switch
688        case "vertical":                // execute if case matches expression
689                return(bv)
690                break                                           // exit from switch
691        case "horizontal":              // execute if case matches expression
692                return(bh)
693                break
694        case "maximum":         // execute if case matches expression
695                return(bm)
696                break
697        default:                                                        // optional default expression executed
698                return(bm)                                              // when no case matches
699    endswitch
700   
701    return(0)
702   
703End
704
705// 1=front
706// 2=middle
707// 3=back
708// return value is in cm
709// actual Sample position to detector distance is reported
710// Top/Bottom setback is included
711Function VC_getSDD(detStr)
712        String detStr
713       
714        Variable sdd
715
716        strswitch(detstr)
717                case "B":
718                case "B ":
719                        ControlInfo/W=VCALC VCALCCtrl_4b
720                        break
721                case "ML":
722                case "MR":
723                case "MT":
724                case "MB":
725                        ControlInfo/W=VCALC VCALCCtrl_3d
726                        break
727                case "FL":
728                case "FR":
729                case "FT":
730                case "FB":
731                        ControlInfo/W=VCALC VCALCCtrl_2d
732                        break           
733                default:
734                        Print "no case matched in VC_getSDD()"
735        endswitch
736
737        // this is gate valve to detector distance
738        sdd = V_Value
739       
740        // MAR 2020 -- don't add in the setback, ask for it when needed
741//      sdd += VCALC_getTopBottomSDDSetback(detStr)
742       
743        // VCALCCtrl_1e is Sample Pos to Gate Valve (cm)
744        ControlInfo/W=VCALC VCALCCtrl_1e
745        sdd += V_Value
746       
747        return(sdd)
748end
749
750
751
752Function V_sampleToGateValve()
753        // VCALCCtrl_1e is Sample Pos to Gate Valve (cm)
754        ControlInfo/W=VCALC VCALCCtrl_1e
755        return(V_Value)
756end
757
758
759Function V_sampleApertureToGateValve()
760        // VCALCCtrl_1d is Sample Aperture to Gate Valve (cm)
761        ControlInfo/W=VCALC VCALCCtrl_1d
762        return(V_Value)
763end
764
765
766
767// 1=front
768// 2=middle
769// 3=back
770// return value is in cm
771// gate valve to detector (= nominal distance) is reported
772// Top/Bottom setback is NOT included
773Function VC_getGateValveToDetDist(detStr)
774        String detStr
775       
776        Variable sdd
777
778        strswitch(detstr)
779                case "B":
780                case "B ":
781                        ControlInfo/W=VCALC VCALCCtrl_4b
782                        break
783                case "ML":
784                case "MR":
785                case "MT":
786                case "MB":
787                        ControlInfo/W=VCALC VCALCCtrl_3d
788                        break
789                case "FL":
790                case "FR":
791                case "FT":
792                case "FB":
793                        ControlInfo/W=VCALC VCALCCtrl_2d
794                        break           
795                default:
796                        Print "no case matched in VC_getGateValveToDetDistance()"
797        endswitch
798
799        // this is gate valve to detector distance
800        sdd = V_Value
801       
802        return(sdd)
803end     
804
805// TODO
806// -- verify all of the numbers, constants, and "empirical" transmission corrections
807// --
808//
809Function V_beamIntensity()
810
811        Variable as,solid_angle,l1,d2_phi
812        Variable a1,a2,retVal
813        Variable ng
814        Variable lambda_t
815        Variable lambda,phi_0
816        Variable lambda_width
817        Variable guide_loss,t_guide,t_filter,t_total,t_special
818
819        NVAR gBeamInten = root:Packages:NIST:VSANS:VCALC:gBeamIntensity
820 
821// TODO
822// -- verify these numbers
823        lambda_t = 6.20
824        phi_0 = 1.82e13
825        guide_loss = 0.97
826        t_special = 1
827
828        ControlInfo/W=VCALC VCALCCtrl_0a
829        ng = V_Value
830 
831        lambda = VCALC_getWavelength()
832        lambda_width = VCALC_getWavelengthSpread()
833        l1 = VC_calcSSD()
834   
835    // TODO verify that these values are in cm
836        a1 = VC_sourceApertureDiam()
837   
838        // sample aperture diam [cm]
839        a2 = VC_sampleApertureDiam()
840   
841//      alpha = (a1+a2)/(2*l1)  //angular divergence of beam
842//      f = l_gap*alpha/(2*guide_width)
843//      t4 = (1-f)*(1-f)
844//      t6 = 1 - lambda*(b-(ng/8)*(b-c))                //experimental correction factor
845
846        t_guide = exp(ng*ln(guide_loss))        // trans losses of guides in pre-sample flight
847        t_filter = exp(-0.371 - 0.0305*lambda - 0.00352*lambda*lambda)
848        t_total = t_special*t_guide*t_filter
849
850   
851        as = pi/4*a2*a2         //area of sample in the beam
852        d2_phi = phi_0/(2*pi)
853        d2_phi *= exp(4*ln(lambda_t/lambda))
854        d2_phi *= exp(-1*(lambda_t*lambda_t/lambda/lambda))
855
856        solid_angle = pi/4* (a1/l1)*(a1/l1)
857
858        retVal = as * d2_phi * lambda_width * solid_angle * t_total
859
860        // set the global for display
861        gBeamInten = retVal
862       
863        return (retVal)
864end
865
866//
867Function VC_figureOfMerit()
868
869        Variable bi = V_beamIntensity()
870        Variable lambda = VCALC_getWavelength()
871       
872   return (lambda*lambda*bi)
873End
874
875// return a beamstop diameter (cm) larger than maximum beam dimension
876Function VC_beamstopDiam(detStr)
877        String detStr
878       
879        Variable bm=0
880        Variable bs=0.0
881   Variable yesLens=0
882   
883        if(yesLens)
884                //bm = sourceApertureDiam()             //ideal result, not needed
885                bs = 1                                                          //force the diameter to 1"
886        else
887                bm = VC_beamDiameter("maximum",detStr)
888                do
889                bs += 1
890           while ( (bs*2.54 < bm) || (bs > 30.0))                       //30 = ridiculous limit to avoid inf loop
891        endif
892
893        return (bs*2.54)                //return diameter in cm, not inches for txt
894End
895
896// multiply the appropriate IQ data by the beamstop shadow factor for display
897//
898Function V_IQ_BeamstopShadow()
899
900        String popStr
901        Variable binType
902       
903        ControlInfo/W=VCALC popup_b
904        popStr = S_Value       
905
906        binType = V_BinTypeStr2Num(popStr)     
907       
908        String folderStr = "root:Packages:NIST:VSANS:VCALC:"
909       
910
911        String extStr =""
912       
913        switch(binType)
914                case 1:
915                        extStr = ksBinType1             
916
917                        break
918                case 2:
919                        extStr = ksBinType2             
920
921                        break
922                case 3:
923                        extStr = ksBinType3     
924                       
925                        break
926                case 4:                         /// this is for a tall, narrow slit mode       
927                        extStr = ksBinType4
928
929                        break
930                case 5:
931                        extStr = ksBinType5     
932               
933                        break
934                case 6:
935                        extStr = ksBinType6     
936               
937                        break
938                case 7:
939                        extStr = ksBinType7     
940               
941                        break
942                       
943                default:
944                        Abort "Binning mode not found in V_IQ_BeamstopShadow"// when no case matches   
945        endswitch
946
947// TODO:
948// -- I had to put a lot of conditions on when not to try to apply the shadow factor
949// to avoid errors when iq had no points in the wave, or incorrectly applying the beamstop to the back panel.
950       
951        Variable ii
952        String ext
953//      loop over all of the types of data
954        for(ii=0;ii<ItemsInList(extStr);ii+=1)
955                ext = StringFromList(ii, extStr, ";")
956                Wave iq = $(folderStr+"iBin_qxqy_"+ext)
957                Wave/Z fs = $(folderStr+"fSubS_qxqy_"+ext)
958                if(WaveExists(fs) && numpnts(iq) > 0 && cmpstr(ext,"B") != 0)
959                        iq = (fs < 0.1) ? iq*0.1 : iq*fs
960                endif
961        endfor 
962       
963        return(0)
964end
965
966
967
968//
969// instead of setting some of the data to NaN to exclude it, draw a proper mask to be used
970// during the I(q) averaging
971//
972// use both the "hard" and "soft" shadowing
973// -- chooses the more "conservative" of the shadowing values (soft value at short SDD + T/B)
974//
975// the MSK data will be in its ususal location from the initialization.
976//
977// FL shadows FT, FB, ML
978// FR shadows FT, FB, MR
979// FT shadows ML, MR, MT
980// FB shadows ML, MR, MB
981// ML shadows MT, MB, B
982// MR shadows MT, MB, B
983// MT shadows B
984// MB shadows B
985//
986Function VC_DrawVCALCMask()
987
988        VC_DrawVCALCMask_FL()
989        VC_DrawVCALCMask_FR()
990        VC_DrawVCALCMask_FT()
991        VC_DrawVCALCMask_FB()
992       
993        VC_DrawVCALCMask_ML()
994        VC_DrawVCALCMask_MR()
995        VC_DrawVCALCMask_MT()
996        VC_DrawVCALCMask_MB()
997       
998        return(0)
999end
1000
1001// FL shadows FT, FB, ML
1002Function VC_DrawVCALCMask_FL()
1003       
1004        Variable pixSizeX,pixSizeY,nPix,nt
1005
1006        Variable offset,offset_ML,L2_F,L2_M,delta_L,delta_S,D2
1007        Variable delta_Xh,delta_Xs,delta_X_pix,delta
1008        String type,target
1009
1010// FL shadows FT,FB,ML
1011        type = "FL"
1012
1013        // lateral offset of FL
1014        offset = VCALC_getPanelTranslation(type)
1015        // sample aperture diam [cm]
1016        D2 = VC_sampleApertureDiam()
1017        // sdd F         [cm] = sample aperture to detector
1018        L2_F = VC_calc_L2(type)
1019        // depth of electronics (L/R panels)
1020        delta_L = 33            //[cm]
1021        // offset of 80/20 frame
1022        delta_S = 2.5           //[cm]
1023       
1024       
1025        // sdd of FT, or FB, or ML
1026/////
1027        target = "FT"
1028        L2_M = VC_calc_L2(target)
1029        // mask data
1030        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1031
1032// extent of shadow in [cm] (starting point of shadow from center of beam)
1033// hard
1034        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1035// soft
1036        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1037
1038        //use the smaller shadow value (this means closer to the center, a larger shadow)
1039        delta = min(delta_Xh,delta_Xs)
1040
1041// how many detector tubes to mask?
1042        pixSizeX = VCALC_getPixSizeX(target)
1043        pixSizeY = VCALC_getPixSizeY(target)
1044
1045        //since "target" is FT, use x-position
1046        // at what "pixel" does the shadow start?
1047        delta_X_pix = trunc(delta/pixSizeX)             //pixels from the center
1048        nPix = VCALC_get_nPix_X(target)
1049
1050        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the FT panel
1051                nt = trunc(nPix/2) - delta_x_pix
1052                mask[0,nt][] = 1
1053        endif
1054       
1055/////
1056        target = "FB"
1057        L2_M = VC_calc_L2(target)
1058        // mask data
1059        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1060
1061// extent of shadow in [cm] (starting point of shadow from center of beam)
1062// hard
1063        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1064// soft
1065        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1066
1067        //use the smaller shadow value
1068        delta = min(delta_Xh,delta_Xs)
1069       
1070// how many detector tubes to mask?
1071        pixSizeX = VCALC_getPixSizeX(target)
1072        pixSizeY = VCALC_getPixSizeY(target)
1073
1074        //since "target" is FB, use x-position
1075        // at what "pixel" does the shadow start?
1076        delta_X_pix = trunc(delta/pixSizeX)
1077        nPix = VCALC_get_nPix_X(target)
1078
1079        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the FB panel
1080                nt = trunc(nPix/2) - delta_x_pix
1081                mask[0,nt][] = 1
1082        endif
1083
1084///
1085// for ML, there can also be lateral offset of the ML panel
1086        target = "ML"
1087
1088        L2_M = VC_calc_L2(target)
1089        // mask data
1090        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1091
1092// extent of shadow in [cm] (starting point of shadow from center of beam)
1093// hard
1094        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1095// soft
1096        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1097
1098        //use the smaller shadow value
1099        delta = min(delta_Xh,delta_Xs)
1100//      delta = delta_Xh
1101       
1102// how many detector tubes to mask?
1103        pixSizeX = VCALC_getPixSizeX(target)
1104        pixSizeY = VCALC_getPixSizeY(target)
1105
1106// offset of ML, in "pixels"
1107        offset_ML = VCALC_getPanelTranslation(target)/pixSizeX          //[cm]
1108        offset_ML = -trunc(offset_ML)
1109        //since "target" is ML, use x-position
1110        // at what "pixel" does the shadow start?
1111        delta_X_pix = trunc(delta/pixSizeX)
1112        nPix = VCALC_get_nPix_X(target)
1113       
1114        //is the delta_x_pix still on the left edge of ML?
1115        if(delta_x_pix < 0)             //entire panel is shadowed
1116                nt = nPix-1
1117                mask[0,nt][] = 1
1118        else
1119                if(delta_X_pix < nPix + offset_ML)
1120                        nt = nPix + offset_ML - delta_x_pix
1121                        mask[0,nt][] = 1
1122                endif
1123        endif
1124       
1125        return(0)
1126end
1127
1128// FR shadows FT, FB, MR
1129Function VC_DrawVCALCMask_FR()
1130       
1131        Variable pixSizeX,pixSizeY,nPix,nt
1132
1133        Variable offset,offset_MR,L2_F,L2_M,delta_L,delta_S,D2
1134        Variable delta_Xh,delta_Xs,delta_X_pix,delta
1135        String type,target
1136
1137// FR shadows FT, FB, MR
1138        type = "FR"
1139
1140        // lateral offset of FR
1141        offset = VCALC_getPanelTranslation(type)
1142        // sample aperture diam [cm]
1143        D2 = VC_sampleApertureDiam()
1144        // sdd F         [cm] = sample aperture to detector
1145        L2_F = VC_calc_L2(type)
1146        // depth of electronics (L/R panels)
1147        delta_L = 33            //[cm]
1148        // offset of 80/20 frame
1149        delta_S = 2.5           //[cm]
1150       
1151       
1152        // sdd of FT, or FB, or MR
1153/////
1154        target = "FT"
1155        L2_M = VC_calc_L2(target)
1156        // mask data
1157        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1158
1159// extent of shadow in [cm] (starting point of shadow from center of beam)
1160// hard
1161        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1162// soft
1163        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1164
1165        //use the smaller shadow value (this means closer to the center, a larger shadow)
1166        delta = min(delta_Xh,delta_Xs)
1167
1168// how many detector tubes to mask?
1169        pixSizeX = VCALC_getPixSizeX(target)
1170        pixSizeY = VCALC_getPixSizeY(target)
1171
1172        //since "target" is FT, use x-position
1173        // at what "pixel" does the shadow start?
1174        delta_X_pix = trunc(delta/pixSizeX)
1175        nPix = VCALC_get_nPix_X(target)
1176
1177        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the FT panel
1178                nt = trunc(nPix/2) - delta_x_pix
1179                mask[nPix-nt,nPix-1][] = 1
1180        endif
1181       
1182/////
1183        target = "FB"
1184        L2_M = VC_calc_L2(target)
1185        // mask data
1186        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1187
1188// extent of shadow in [cm] (starting point of shadow from center of beam)
1189// hard
1190        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1191// soft
1192        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1193
1194        //use the smaller shadow value
1195        delta = min(delta_Xh,delta_Xs)
1196       
1197// how many detector tubes to mask?
1198        pixSizeX = VCALC_getPixSizeX(target)
1199        pixSizeY = VCALC_getPixSizeY(target)
1200
1201        //since "target" is FB, use x-position
1202        // at what "pixel" does the shadow start?
1203        delta_X_pix = trunc(delta/pixSizeX)
1204        nPix = VCALC_get_nPix_X(target)
1205
1206        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the FB panel
1207                nt = trunc(nPix/2) - delta_x_pix
1208                mask[nPix-nt,nPix-1][] = 1
1209        endif
1210
1211///
1212// for MR, there can also be lateral offset of the panel
1213        target = "MR"
1214
1215        L2_M = VC_calc_L2(target)
1216        // mask data
1217        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1218
1219// extent of shadow in [cm] (starting point of shadow from center of beam)
1220// hard
1221        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1222// soft
1223        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1224
1225        //use the smaller shadow value
1226        delta = min(delta_Xh,delta_Xs)
1227       
1228// how many detector tubes to mask?
1229        pixSizeX = VCALC_getPixSizeX(target)
1230        pixSizeY = VCALC_getPixSizeY(target)
1231
1232// offset of MR, in "pixels"
1233        offset_MR = VCALC_getPanelTranslation(target)/pixSizeX          //[cm]
1234        offset_MR = trunc(offset_MR)
1235        //since "target" is ML, use x-position
1236        // at what "pixel" does the shadow start?
1237        nPix = VCALC_get_nPix_X(target)
1238       
1239        delta_X_pix = trunc(delta/pixSizeX)
1240       
1241        //is the delta_x_pix still on the right edge of MR?
1242        if(delta_x_pix < 0)             //entire panel is shadowed
1243                nt = nPix-1
1244                mask[0,nt][] = 1
1245        else
1246                if(delta_X_pix < nPix + offset_MR)
1247                        nt = nPix + offset_MR - delta_x_pix
1248                        mask[nPix-nt,nPix-1][] = 1
1249                endif
1250        endif
1251               
1252        return(0)
1253end
1254
1255// FT shadows ML, MR, MT
1256Function VC_DrawVCALCMask_FT()
1257       
1258        Variable pixSizeX,pixSizeY,nPix,nt
1259
1260        Variable offset,offset_MT,L2_F,L2_M,delta_L,delta_S,D2
1261        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1262        String type,target
1263
1264// FT shadows ML, MR, MT
1265        type = "FT"
1266
1267        //  offset of FT
1268        offset = VCALC_getPanelTranslation(type)
1269        // sample aperture diam [cm]
1270        D2 = VC_sampleApertureDiam()
1271        // sdd F         [cm] = sample aperture to detector
1272        L2_F = VC_calc_L2(type)
1273        // depth of electronics (T/B panels)
1274        delta_L = 61            //[cm]
1275        // offset of 80/20 frame
1276        delta_S = 2.5           //[cm]
1277       
1278       
1279        // sdd of ML, or MR, or MT
1280/////
1281        target = "ML"
1282        L2_M = VC_calc_L2(target)
1283        // mask data
1284        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1285
1286// extent of shadow in [cm] (starting point of shadow from center of beam)
1287// hard
1288        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1289// soft
1290        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1291
1292        //use the smaller shadow value (this means closer to the center, a larger shadow)
1293        delta = min(delta_Xh,delta_Xs)
1294
1295// how many detector tubes to mask?
1296        pixSizeX = VCALC_getPixSizeX(target)
1297        pixSizeY = VCALC_getPixSizeY(target)
1298
1299        //since "target" is ML, use Y-position
1300        // at what "pixel" does the shadow start?
1301        delta_Y_pix = trunc(delta/pixSizeY)
1302        nPix = VCALC_get_nPix_Y(target)
1303
1304        if(delta_y_pix < trunc(nPix/2))
1305                nt = trunc(nPix/2) - delta_y_pix
1306                mask[][nPix-nt,nPix-1] = 1
1307        endif
1308
1309/////
1310        target = "MR"
1311        L2_M = VC_calc_L2(target)
1312        // mask data
1313        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1314
1315// extent of shadow in [cm] (starting point of shadow from center of beam)
1316// hard
1317        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1318// soft
1319        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1320
1321        //use the smaller shadow value
1322        delta = min(delta_Xh,delta_Xs)
1323
1324       
1325// how many detector tubes to mask?
1326        pixSizeX = VCALC_getPixSizeX(target)
1327        pixSizeY = VCALC_getPixSizeY(target)
1328
1329        //since "target" is MR, use y-position
1330        // at what "pixel" does the shadow start?
1331        delta_y_pix = trunc(delta/pixSizey)
1332        nPix = VCALC_get_nPix_Y(target)
1333
1334        if(delta_y_pix < trunc(nPix/2))
1335                nt = trunc(nPix/2) - delta_y_pix
1336                mask[][nPix-nt,nPix-1] = 1
1337        endif
1338       
1339///
1340// for MT, there can also be lateral offset of the MT panel
1341        target = "MT"
1342
1343        L2_M = VC_calc_L2(target)
1344        // mask data
1345        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1346
1347// extent of shadow in [cm] (starting point of shadow from center of beam)
1348// hard
1349        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1350// soft
1351        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1352
1353        //use the smaller shadow value
1354        delta = min(delta_Xh,delta_Xs)
1355       
1356// how many detector tubes to mask?
1357        pixSizeX = VCALC_getPixSizeX(target)
1358        pixSizeY = VCALC_getPixSizeY(target)
1359
1360// offset of MT, in "pixels" -in Y-direction
1361        offset_MT = VCALC_getPanelTranslation(target)/pixSizeY          //[cm]
1362        offset_MT = trunc(offset_MT)
1363        //since "target" is MT, use y-position
1364        // at what "pixel" does the shadow start?
1365        delta_Y_pix = trunc(delta/pixSizeY)
1366        nPix = VCALC_get_nPix_Y(target)
1367
1368        if(delta_Y_pix < nPix + offset_MT)
1369                nt = nPix + offset_MT - delta_y_pix
1370                mask[][nPix-nt,nPix-1] = 1
1371        endif
1372       
1373       
1374        return(0)
1375end
1376
1377// FB shadows ML, MR, MB
1378Function VC_DrawVCALCMask_FB()
1379       
1380        Variable pixSizeX,pixSizeY,nPix,nt
1381
1382        Variable offset,offset_MB,L2_F,L2_M,delta_L,delta_S,D2
1383        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1384        String type,target
1385
1386// FB shadows ML, MR, MB
1387        type = "FB"
1388
1389        //  offset of FB
1390        offset = VCALC_getPanelTranslation(type)
1391       
1392        // sample aperture diam [cm]
1393        D2 = VC_sampleApertureDiam()
1394        // sdd F         [cm] = sample aperture to detector
1395        L2_F = VC_calc_L2(type)
1396        // depth of electronics (T/B panels)
1397        delta_L = 61            //[cm]
1398        // offset of 80/20 frame
1399        delta_S = 2.5           //[cm]
1400       
1401       
1402        // sdd of ML, or MR, or MB
1403/////
1404        target = "ML"
1405        L2_M = VC_calc_L2(target)
1406        // mask data
1407        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1408
1409// extent of shadow in [cm] (starting point of shadow from center of beam)
1410// hard
1411        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1412// soft
1413        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1414
1415        //use the smaller shadow value (this means closer to the center, a larger shadow)
1416        delta = min(delta_Xh,delta_Xs)
1417
1418       
1419// how many detector tubes to mask?
1420        pixSizeX = VCALC_getPixSizeX(target)
1421        pixSizeY = VCALC_getPixSizeY(target)
1422
1423        //since "target" is ML, use Y-position
1424        // at what "pixel" does the shadow start?
1425        delta_Y_pix = trunc(delta/pixSizeY)
1426        nPix = VCALC_get_nPix_Y(target)
1427
1428        if(delta_y_pix < trunc(nPix/2))
1429                nt = trunc(nPix/2) - delta_y_pix
1430                mask[][0,nt] = 1
1431        endif
1432       
1433/////
1434        target = "MR"
1435        L2_M = VC_calc_L2(target)
1436        // mask data
1437        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1438
1439// extent of shadow in [cm] (starting point of shadow from center of beam)
1440// hard
1441        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1442// soft
1443        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1444
1445        //use the smaller shadow value
1446        delta = min(delta_Xh,delta_Xs)
1447       
1448// how many detector tubes to mask?
1449        pixSizeX = VCALC_getPixSizeX(target)
1450        pixSizeY = VCALC_getPixSizeY(target)
1451
1452        //since "target" is MR, use y-position
1453        // at what "pixel" does the shadow start?
1454        delta_y_pix = trunc(delta/pixSizeY)
1455        nPix = VCALC_get_nPix_Y(target)
1456
1457        if(delta_y_pix < trunc(nPix/2))
1458                nt = trunc(nPix/2) - delta_y_pix
1459                mask[][0,nt] = 1
1460        endif
1461       
1462///
1463// for MB, there can also be lateral offset of the MT panel
1464        target = "MB"
1465
1466        L2_M = VC_calc_L2(target)
1467        // mask data
1468        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1469
1470// extent of shadow in [cm] (starting point of shadow from center of beam)
1471// hard
1472        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1473// soft
1474        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1475
1476        //use the smaller shadow value
1477        delta = min(delta_Xh,delta_Xs)
1478       
1479// how many detector tubes to mask?
1480        pixSizeX = VCALC_getPixSizeX(target)
1481        pixSizeY = VCALC_getPixSizeY(target)
1482
1483// offset of MT, in "pixels" -in Y-direction
1484        offset_MB = VCALC_getPanelTranslation(target)/pixSizeY          //[cm]
1485        offset_MB = -trunc(offset_MB)
1486        //since "target" is MT, use y-position
1487        // at what "pixel" does the shadow start?
1488        delta_Y_pix = trunc(delta/pixSizeY)
1489        nPix = VCALC_get_nPix_Y(target)
1490
1491        if(delta_Y_pix < nPix + offset_MB)
1492                nt = nPix + offset_MB - delta_y_pix
1493                mask[][0,nt] = 1
1494        endif
1495       
1496
1497        return(0)
1498end
1499
1500// ML shadows MT, MB, B
1501Function VC_DrawVCALCMask_ML()
1502       
1503        Variable pixSizeX,pixSizeY,nPix,nt
1504
1505        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1506        Variable delta_Xh,delta_Xs,delta_X_pix,delta
1507        String type,target
1508
1509// ML shadows MT, MB, B
1510        type = "ML"
1511
1512        // lateral offset of ML
1513        offset = VCALC_getPanelTranslation(type)
1514        // sample aperture diam [cm]
1515        D2 = VC_sampleApertureDiam()
1516        // sdd F         [cm] = sample aperture to detector
1517        L2_F = VC_calc_L2(type)
1518        // depth of electronics (L/R panels)
1519        delta_L = 33            //[cm]
1520        // offset of 80/20 frame
1521        delta_S = 2.5           //[cm]
1522       
1523       
1524        // sdd of MT, or MB, or B
1525/////
1526        target = "MT"
1527        L2_M = VC_calc_L2(target)
1528        // mask data
1529        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1530
1531// extent of shadow in [cm] (starting point of shadow from center of beam)
1532// hard
1533        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1534// soft
1535        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1536
1537        //use the smaller shadow value (this means closer to the center, a larger shadow)
1538        delta = min(delta_Xh,delta_Xs)
1539
1540// how many detector tubes to mask?
1541        pixSizeX = VCALC_getPixSizeX(target)
1542        pixSizeY = VCALC_getPixSizeY(target)
1543
1544        //since "target" is FT, use x-position
1545        // at what "pixel" does the shadow start?
1546        delta_X_pix = trunc(delta/pixSizeX)             //pixels from the center
1547        nPix = VCALC_get_nPix_X(target)
1548
1549        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the FT panel
1550                nt = trunc(nPix/2) - delta_x_pix
1551                mask[0,nt][] = 1
1552        endif
1553       
1554/////
1555        target = "MB"
1556        L2_M = VC_calc_L2(target)
1557        // mask data
1558        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1559
1560// extent of shadow in [cm] (starting point of shadow from center of beam)
1561// hard
1562        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1563// soft
1564        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1565
1566        //use the smaller shadow value
1567        delta = min(delta_Xh,delta_Xs)
1568       
1569// how many detector tubes to mask?
1570        pixSizeX = VCALC_getPixSizeX(target)
1571        pixSizeY = VCALC_getPixSizeY(target)
1572
1573        //since "target" is MB, use x-position
1574        // at what "pixel" does the shadow start?
1575        delta_X_pix = trunc(delta/pixSizeX)
1576        nPix = VCALC_get_nPix_X(target)
1577
1578        if(delta_x_pix < trunc(nPix/2) )                        //still on the left side of the MB panel
1579                nt = trunc(nPix/2) - delta_x_pix
1580                mask[0,nt][] = 1
1581        endif
1582
1583///
1584// for B, there can also be lateral offset of the B panel
1585        target = "B"
1586
1587        L2_M = VC_calc_L2(target)
1588        // mask data
1589        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1590
1591// extent of shadow in [cm] (starting point of shadow from center of beam)
1592// hard
1593        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1594// soft
1595        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1596
1597        //use the smaller shadow value
1598        delta = min(delta_Xh,delta_Xs)
1599//      delta = delta_Xh
1600       
1601// how many detector tubes to mask?
1602        pixSizeX = VCALC_getPixSizeX(target)
1603        pixSizeY = VCALC_getPixSizeY(target)
1604
1605// offset of B, in "pixels"
1606        offset_B = VCALC_getPanelTranslation(target)/pixSizeX           //[cm]
1607        offset_B = -trunc(offset_B)
1608        //since "target" is B, use x-position
1609        // at what "pixel" does the shadow start?
1610        delta_X_pix = trunc(delta/pixSizeX)
1611        nPix = VCALC_get_nPix_X(target)
1612       
1613        //is the delta_x_pix still on the left edge of B?
1614        if(delta_x_pix < 0)             //entire panel is shadowed
1615                nt = nPix-1
1616                mask[0,nt][] = 1
1617        else
1618                if(delta_X_pix < nPix + offset_B)
1619                        nt = nPix + offset_B - delta_x_pix
1620                        mask[0,nt][] = 1
1621                endif
1622        endif
1623       
1624        return(0)
1625end
1626
1627// MR shadows MT, MB, B
1628Function VC_DrawVCALCMask_MR()
1629       
1630        Variable pixSizeX,pixSizeY,nPix,nt
1631
1632        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1633        Variable delta_Xh,delta_Xs,delta_X_pix,delta
1634        String type,target
1635
1636// MR shadows MT, MB, B
1637        type = "MR"
1638
1639        // lateral offset of FR
1640        offset = VCALC_getPanelTranslation(type)
1641        // sample aperture diam [cm]
1642        D2 = VC_sampleApertureDiam()
1643        // sdd F         [cm] = sample aperture to detector
1644        L2_F = VC_calc_L2(type)
1645        // depth of electronics (L/R panels)
1646        delta_L = 33            //[cm]
1647        // offset of 80/20 frame
1648        delta_S = 2.5           //[cm]
1649       
1650       
1651        // sdd of MT, or MB, or B
1652/////
1653        target = "MT"
1654        L2_M = VC_calc_L2(target)
1655        // mask data
1656        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1657
1658// extent of shadow in [cm] (starting point of shadow from center of beam)
1659// hard
1660        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1661// soft
1662        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1663
1664        //use the smaller shadow value (this means closer to the center, a larger shadow)
1665        delta = min(delta_Xh,delta_Xs)
1666
1667// how many detector tubes to mask?
1668        pixSizeX = VCALC_getPixSizeX(target)
1669        pixSizeY = VCALC_getPixSizeY(target)
1670
1671        //since "target" is MT, use x-position
1672        // at what "pixel" does the shadow start?
1673        delta_X_pix = trunc(delta/pixSizeX)
1674        nPix = VCALC_get_nPix_X(target)
1675
1676        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the MT panel
1677                nt = trunc(nPix/2) - delta_x_pix
1678                mask[nPix-nt,nPix-1][] = 1
1679        endif
1680       
1681/////
1682        target = "MB"
1683        L2_M = VC_calc_L2(target)
1684        // mask data
1685        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1686
1687// extent of shadow in [cm] (starting point of shadow from center of beam)
1688// hard
1689        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1690// soft
1691        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1692
1693        //use the smaller shadow value
1694        delta = min(delta_Xh,delta_Xs)
1695       
1696// how many detector tubes to mask?
1697        pixSizeX = VCALC_getPixSizeX(target)
1698        pixSizeY = VCALC_getPixSizeY(target)
1699
1700        //since "target" is FB, use x-position
1701        // at what "pixel" does the shadow start?
1702        delta_X_pix = trunc(delta/pixSizeX)
1703        nPix = VCALC_get_nPix_X(target)
1704
1705        if(delta_x_pix < trunc(nPix/2) )                        //still on the right side of the MB panel
1706                nt = trunc(nPix/2) - delta_x_pix
1707                mask[nPix-nt,nPix-1][] = 1
1708        endif
1709
1710///
1711// for B, there can also be lateral offset of the panel
1712        target = "B"
1713
1714        L2_M = VC_calc_L2(target)
1715        // mask data
1716        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1717
1718// extent of shadow in [cm] (starting point of shadow from center of beam)
1719// hard
1720        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1721// soft
1722        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1723
1724        //use the smaller shadow value
1725        delta = min(delta_Xh,delta_Xs)
1726       
1727// how many detector tubes to mask?
1728        pixSizeX = VCALC_getPixSizeX(target)
1729        pixSizeY = VCALC_getPixSizeY(target)
1730
1731// offset of B, in "pixels"
1732        offset_B = VCALC_getPanelTranslation(target)/pixSizeX           //[cm]
1733        offset_B = trunc(offset_B)
1734        //since "target" is B, use x-position
1735        // at what "pixel" does the shadow start?
1736        nPix = VCALC_get_nPix_X(target)
1737       
1738        delta_X_pix = trunc(delta/pixSizeX)
1739       
1740        //is the delta_x_pix still on the right edge of B?
1741        if(delta_x_pix < 0)             //entire panel is shadowed
1742                nt = nPix-1
1743                mask[0,nt][] = 1
1744        else
1745                if(delta_X_pix < nPix + offset_B)
1746                        nt = nPix + offset_B - delta_x_pix
1747                        mask[nPix-nt,nPix-1][] = 1
1748                endif
1749        endif
1750       
1751        return(0)
1752end
1753
1754
1755// MT shadows B
1756Function VC_DrawVCALCMask_MT()
1757       
1758        Variable pixSizeX,pixSizeY,nPix,nt
1759
1760        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1761        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1762        String type,target
1763
1764// MT shadows B
1765        type = "MT"
1766
1767        //  offset of MT
1768        offset = VCALC_getPanelTranslation(type)
1769        // sample aperture diam [cm]
1770        D2 = VC_sampleApertureDiam()
1771        // sdd F         [cm] = sample aperture to detector
1772        L2_F = VC_calc_L2(type)
1773        // depth of electronics (T/B panels)
1774        delta_L = 61            //[cm]
1775        // offset of 80/20 frame
1776        delta_S = 2.5           //[cm]
1777       
1778       
1779        // sdd of ML, or MR, or MT
1780///////
1781//      target = "ML"
1782//      L2_M = VC_calc_L2(target)
1783//      // mask data
1784//      Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1785//
1786//// extent of shadow in [cm] (starting point of shadow from center of beam)
1787//// hard
1788//      delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1789//// soft
1790//      delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1791//
1792//      //use the smaller shadow value (this means closer to the center, a larger shadow)
1793//      delta = min(delta_Xh,delta_Xs)
1794//
1795//// how many detector tubes to mask?
1796//      pixSizeX = VCALC_getPixSizeX(target)
1797//      pixSizeY = VCALC_getPixSizeY(target)
1798//
1799//      //since "target" is ML, use Y-position
1800//      // at what "pixel" does the shadow start?
1801//      delta_Y_pix = trunc(delta/pixSizeY)
1802//      nPix = VCALC_get_nPix_Y(target)
1803//
1804//      if(delta_y_pix < trunc(nPix/2))
1805//              nt = trunc(nPix/2) - delta_y_pix
1806//              mask[][nPix-nt,nPix-1] = 1
1807//      endif
1808
1809/////
1810//      target = "MR"
1811//      L2_M = VC_calc_L2(target)
1812//      // mask data
1813//      Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1814//
1815//// extent of shadow in [cm] (starting point of shadow from center of beam)
1816//// hard
1817//      delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1818//// soft
1819//      delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1820//
1821//      //use the smaller shadow value
1822//      delta = min(delta_Xh,delta_Xs)
1823//
1824//     
1825//// how many detector tubes to mask?
1826//      pixSizeX = VCALC_getPixSizeX(target)
1827//      pixSizeY = VCALC_getPixSizeY(target)
1828//
1829//      //since "target" is MR, use y-position
1830//      // at what "pixel" does the shadow start?
1831//      delta_y_pix = trunc(delta/pixSizey)
1832//      nPix = VCALC_get_nPix_Y(target)
1833//
1834//      if(delta_y_pix < trunc(nPix/2))
1835//              nt = trunc(nPix/2) - delta_y_pix
1836//              mask[][nPix-nt,nPix-1] = 1
1837//      endif
1838       
1839///
1840// for B, there can also be lateral offset of the B panel
1841        target = "B"
1842
1843        L2_M = VC_calc_L2(target)
1844        // mask data
1845        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1846
1847// extent of shadow in [cm] (starting point of shadow from center of beam)
1848// hard
1849        delta_Xh = D2/2 + (offset - D2/2)*(L2_M/L2_F)
1850// soft
1851        delta_Xs = D2/2 + (offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1852
1853        //use the smaller shadow value
1854        delta = min(delta_Xh,delta_Xs)
1855       
1856// how many detector tubes to mask?
1857        pixSizeX = VCALC_getPixSizeX(target)
1858        pixSizeY = VCALC_getPixSizeY(target)
1859
1860// offset of B, in "pixels" -in Y-direction
1861        offset_B = VCALC_getPanelTranslation(target)/pixSizeY           //[cm]
1862        offset_B = trunc(offset_B)
1863        //since "target" is B, use y-position
1864        // at what "pixel" does the shadow start?
1865        delta_Y_pix = trunc(delta/pixSizeY)
1866        nPix = VCALC_get_nPix_Y(target)
1867
1868        if(delta_y_pix < trunc(nPix/2))
1869                nt = trunc(nPix/2) - delta_y_pix
1870                mask[][nPix-nt,nPix-1] = 1
1871        endif
1872       
1873        return(0)
1874end
1875
1876// MB shadows B
1877Function VC_DrawVCALCMask_MB()
1878       
1879        Variable pixSizeX,pixSizeY,nPix,nt
1880
1881        Variable offset,offset_B,L2_F,L2_M,delta_L,delta_S,D2
1882        Variable delta_Xh,delta_Xs,delta_Y_pix,delta
1883        String type,target
1884
1885// MB shadows B
1886        type = "MB"
1887
1888        //  offset of MB
1889        offset = VCALC_getPanelTranslation(type)
1890       
1891        // sample aperture diam [cm]
1892        D2 = VC_sampleApertureDiam()
1893        // sdd F         [cm] = sample aperture to detector
1894        L2_F = VC_calc_L2(type)
1895        // depth of electronics (T/B panels)
1896        delta_L = 61            //[cm]
1897        // offset of 80/20 frame
1898        delta_S = 2.5           //[cm]
1899       
1900       
1901        // sdd of ML, or MR, or MB
1902/////
1903//      target = "ML"
1904//      L2_M = VC_calc_L2(target)
1905//      // mask data
1906//      Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1907//
1908//// extent of shadow in [cm] (starting point of shadow from center of beam)
1909//// hard
1910//      delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1911//// soft
1912//      delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1913//
1914//      //use the smaller shadow value (this means closer to the center, a larger shadow)
1915//      delta = min(delta_Xh,delta_Xs)
1916//
1917//     
1918//// how many detector tubes to mask?
1919//      pixSizeX = VCALC_getPixSizeX(target)
1920//      pixSizeY = VCALC_getPixSizeY(target)
1921//
1922//      //since "target" is ML, use Y-position
1923//      // at what "pixel" does the shadow start?
1924//      delta_Y_pix = trunc(delta/pixSizeY)
1925//      nPix = VCALC_get_nPix_Y(target)
1926//
1927//      if(delta_y_pix < trunc(nPix/2))
1928//              nt = trunc(nPix/2) - delta_y_pix
1929//              mask[][0,nt] = 1
1930//      endif
1931       
1932/////
1933//      target = "MR"
1934//      L2_M = VC_calc_L2(target)
1935//      // mask data
1936//      Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1937//
1938//// extent of shadow in [cm] (starting point of shadow from center of beam)
1939//// hard
1940//      delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1941//// soft
1942//      delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1943//
1944//      //use the smaller shadow value
1945//      delta = min(delta_Xh,delta_Xs)
1946//     
1947//// how many detector tubes to mask?
1948//      pixSizeX = VCALC_getPixSizeX(target)
1949//      pixSizeY = VCALC_getPixSizeY(target)
1950//
1951//      //since "target" is MR, use y-position
1952//      // at what "pixel" does the shadow start?
1953//      delta_y_pix = trunc(delta/pixSizeY)
1954//      nPix = VCALC_get_nPix_Y(target)
1955//
1956//      if(delta_y_pix < trunc(nPix/2))
1957//              nt = trunc(nPix/2) - delta_y_pix
1958//              mask[][0,nt] = 1
1959//      endif
1960       
1961///
1962// for B, there can also be lateral offset of the B panel
1963        target = "B"
1964
1965        L2_M = VC_calc_L2(target)
1966        // mask data
1967        Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+target+":data")
1968
1969// extent of shadow in [cm] (starting point of shadow from center of beam)
1970// hard
1971        delta_Xh = D2/2 + (-offset - D2/2)*(L2_M/L2_F)
1972// soft
1973        delta_Xs = D2/2 + (-offset + delta_S - D2/2)*(L2_M/(L2_F+delta_L))
1974
1975        //use the smaller shadow value
1976        delta = min(delta_Xh,delta_Xs)
1977       
1978// how many detector tubes to mask?
1979        pixSizeX = VCALC_getPixSizeX(target)
1980        pixSizeY = VCALC_getPixSizeY(target)
1981
1982// offset of B, in "pixels" -in Y-direction
1983        offset_B = VCALC_getPanelTranslation(target)/pixSizeY           //[cm]
1984        offset_B = -trunc(offset_B)
1985        //since "target" is MT, use y-position
1986        // at what "pixel" does the shadow start?
1987        delta_Y_pix = trunc(delta/pixSizeY)
1988        nPix = VCALC_get_nPix_Y(target)
1989
1990        if(delta_y_pix < trunc(nPix/2))
1991                nt = trunc(nPix/2) - delta_y_pix
1992                mask[][0,nt] = 1
1993        endif
1994
1995        return(0)
1996end
1997
1998
1999
2000
2001//
2002// resets the mask to 0 = (use all)
2003//
2004Function VC_ResetVCALCMask()
2005
2006        Variable ii
2007        String detStr
2008       
2009        for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1)
2010                detStr = StringFromList(ii, ksDetectorListAll, ";")
2011                Wave mask = $("root:Packages:NIST:VSANS:MSK:entry:instrument:detector_"+detStr+":data")
2012                mask = 0       
2013        endfor
2014       
2015        return(0)
2016end
2017
2018Function/S V_SetConfigurationText()
2019
2020        String str="",temp
2021
2022//      SetDataFolder root:Packages:NIST:SAS
2023//     
2024//      NVAR numberOfGuides=gNg
2025//      NVAR gTable=gTable              //2=chamber, 1=table
2026//      NVAR wavelength=gLambda
2027//      NVAR lambdaWidth=gDeltaLambda
2028////    NVAR instrument = instrument
2029//      NVAR L2diff = L2diff
2030//   NVAR lens = root:Packages:NIST:SAS:gUsingLenses
2031//      SVAR/Z aStr = root:Packages:NIST:gAngstStr
2032//      SVAR selInstr = root:Packages:NIST:SAS:gInstStr
2033
2034        NVAR min_f = root:Packages:NIST:VSANS:VCALC:gQmin_F
2035        NVAR max_f = root:Packages:NIST:VSANS:VCALC:gQmax_F
2036        NVAR min_m = root:Packages:NIST:VSANS:VCALC:gQmin_M
2037        NVAR max_m = root:Packages:NIST:VSANS:VCALC:gQmax_M
2038        NVAR min_b = root:Packages:NIST:VSANS:VCALC:gQmin_B
2039        NVAR max_b = root:Packages:NIST:VSANS:VCALC:gQmax_B
2040       
2041        String aStr = "A"
2042       
2043        sprintf temp,"Source Aperture Diameter =\t\t%6.2f cm\r",VC_sourceApertureDiam()
2044        str += temp
2045        sprintf temp,"Source to Sample =\t\t\t\t%6.0f cm\r",VC_calcSSD()
2046        str += temp
2047//      sprintf temp,"Sample Position to Detector =\t%6.0f cm\r",VC_getSDD("ML")
2048//      str += temp
2049        sprintf temp,"Beam diameter (Mid) =\t\t\t%6.2f cm\r",VC_beamDiameter("maximum","ML")
2050        str += temp
2051        sprintf temp,"Beamstop diameter =\t\t\t\t%6.2f inches\r",VC_beamstopDiam("ML")/2.54
2052        str += temp
2053        sprintf temp,"Back: Min -> Max Q-value =\t\t\t%6.4f -> %6.4f 1/%s \r",min_b,max_b,aStr
2054        str += temp
2055        sprintf temp,"Middle: Min -> Max Q-value =\t\t%6.4f -> %6.4f 1/%s \r",min_m,max_m,aStr
2056        str += temp
2057        sprintf temp,"Front: Min -> Max Q-value =\t\t%6.4f -> %6.4f 1/%s \r",min_f,max_f,aStr
2058        str += temp
2059        sprintf temp,"Beam Intensity =\t\t\t\t%.0f counts/s\r",V_beamIntensity()
2060        str += temp
2061        sprintf temp,"Figure of Merit =\t\t\t\t%3.3g %s^2/s\r",VC_figureOfMerit(),aStr
2062        str += temp
2063//      sprintf temp,"Attenuator transmission =\t\t%3.3g = Atten # %d\r"//,attenuatorTransmission(),attenuatorNumber()
2064//      str += temp
2065////   
2066//      // add text of the user-edited values
2067//      //
2068        sprintf temp,"***************** %s *** %s *****************\r","VSANS","VSANS"
2069        str += temp
2070        sprintf temp,"Sample Aperture Diameter =\t\t\t\t%.2f cm\r",VC_sampleApertureDiam()
2071        str += temp
2072        sprintf temp,"Number of Guides =\t\t\t\t\t\t%d \r", VC_getNumGuides()
2073        str += temp
2074        sprintf temp,"Back: Sample Position to Detector =\t\t\t%.1f cm\r", VC_getSDD("B")
2075        str += temp
2076        sprintf temp,"Middle: Sample Position to Detector =\t\t%.1f cm\r", VC_getSDD("ML")
2077        str += temp
2078        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")
2079        str += temp
2080        sprintf temp,"Front: Sample Position to Detector =\t\t\t%.1f cm\r", VC_getSDD("FL")
2081        str += temp
2082        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")
2083        str += temp
2084//      if(gTable==1)
2085//              sprintf temp,"Sample Position is \t\t\t\t\t\tHuber\r"
2086//      else
2087//              sprintf temp,"Sample Position is \t\t\t\t\t\tChamber\r"
2088//      endif
2089//      str += temp
2090//      sprintf temp,"Detector Offset =\t\t\t\t\t\t%.1f cm\r", detectorOffset()
2091//      str += temp
2092        sprintf temp,"Neutron Wavelength =\t\t\t\t\t%.2f %s\r", VCALC_getWavelength(),aStr
2093        str += temp
2094        sprintf temp,"Wavelength Spread, FWHM =\t\t\t\t%.3f\r", VCALC_getWavelengthSpread()
2095        str += temp
2096//      sprintf temp,"Sample Aperture to Sample Position =\t%.2f cm\r", L2Diff
2097//      str += temp
2098//      if(lens==1)
2099//              sprintf temp,"Lenses are IN\r"
2100//      else
2101//              sprintf temp,"Lenses are OUT\r"
2102//      endif
2103//      str += temp
2104       
2105   setDataFolder root:
2106   return str                   
2107End
2108
2109//Write String representing NICE VSANS configuration
2110Function/S V_SetNICEConfigText()
2111       
2112        string temp_s
2113
2114        String titleStr
2115        String keyStr,keyStrEnd
2116        String valueStr,valueStrEnd
2117        String closingStr
2118        String nameStr,valStr,str
2119
2120        keyStr = "        {\r          \"key\": {\r            \"class\": \"java.lang.String\",\r            \"value\": \""
2121        keyStrEnd = "\"\r          },\r"
2122
2123        valueStr = "          \"value\": {\r            \"class\": \"java.lang.String\",\r            \"value\": \""
2124        valueStrEnd = "\"\r          }\r        },\r"
2125
2126        closingStr = "\"\r          }\r        }\r      ]\r    }\r  }\r]\r"
2127
2128        str = "Dummy filler"
2129
2130        titleStr = "VCALC Configuration"
2131
2132        temp_s = ""
2133
2134        temp_s = "[\r  {\r    \"key\": {\r      \"class\": \"java.lang.String\",\r"
2135        temp_s += "      \"value\": \""+titleStr+"\"\r    },\r"
2136        temp_s += "    \"value\": {\r      \"class\": \"java.util.HashMap\",\r      \"value\": [\r"
2137       
2138//front
2139        nameStr = "frontTrans.primaryNode"
2140        valStr = num2Str(VC_getGateValveToDetDist("FL")) + "cm"         //nominal distance, any panel will do
2141        temp_s += keyStr + nameStr + keyStrEnd
2142        temp_s += valueStr + valStr + valueStrEnd
2143       
2144        nameStr = "carriage.frontRight"
2145        valStr = num2Str(VCALC_getPanelTranslation("FR")) + "cm"                //no space before unit
2146        temp_s += keyStr + nameStr + keyStrEnd
2147        temp_s += valueStr + valStr + valueStrEnd
2148       
2149        nameStr = "carriage.frontLeft"
2150        valStr = num2Str(VCALC_getPanelTranslation("FL")) + "cm"                //no space before unit
2151        temp_s += keyStr + nameStr + keyStrEnd
2152        temp_s += valueStr + valStr + valueStrEnd       
2153               
2154        nameStr = "carriage.frontTop"
2155        valStr = num2Str(VCALC_getPanelTranslation("FT")) + "cm"                //no space before unit
2156        temp_s += keyStr + nameStr + keyStrEnd
2157        temp_s += valueStr + valStr + valueStrEnd
2158
2159        nameStr = "carriage.frontBottom"
2160        valStr = num2Str(VCALC_getPanelTranslation("FB")) + "cm"                //no space before unit
2161        temp_s += keyStr + nameStr + keyStrEnd
2162        temp_s += valueStr + valStr + valueStrEnd
2163
2164        nameStr = "frontRightAreaDetector.beamCenterX"
2165        valStr = num2Str(V_getDet_beam_center_x("VCALC","FR")) + "cm"
2166        temp_s += keyStr + nameStr + keyStrEnd
2167        temp_s += valueStr + valStr + valueStrEnd
2168               
2169        nameStr = "frontRightAreaDetector.beamCenterY"
2170        valStr = num2Str(V_getDet_beam_center_y("VCALC","FR")) + "cm"
2171        temp_s += keyStr + nameStr + keyStrEnd
2172        temp_s += valueStr + valStr + valueStrEnd
2173
2174        nameStr = "frontLeftAreaDetector.beamCenterX"
2175        valStr = num2Str(V_getDet_beam_center_x("VCALC","FL")) + "cm"
2176        temp_s += keyStr + nameStr + keyStrEnd
2177        temp_s += valueStr + valStr + valueStrEnd
2178       
2179        nameStr = "frontLeftAreaDetector.beamCenterY"
2180        valStr = num2Str(V_getDet_beam_center_y("VCALC","FL")) + "cm"
2181        temp_s += keyStr + nameStr + keyStrEnd
2182        temp_s += valueStr + valStr + valueStrEnd
2183
2184        nameStr = "frontTopAreaDetector.beamCenterX"
2185        valStr = num2Str(V_getDet_beam_center_x("VCALC","FT")) + "cm"
2186        temp_s += keyStr + nameStr + keyStrEnd
2187        temp_s += valueStr + valStr + valueStrEnd
2188
2189        nameStr = "frontTopAreaDetector.beamCenterY"
2190        valStr = num2Str(V_getDet_beam_center_y("VCALC","FT")) + "cm"
2191        temp_s += keyStr + nameStr + keyStrEnd
2192        temp_s += valueStr + valStr + valueStrEnd
2193
2194        nameStr = "frontBottomAreaDetector.beamCenterX"
2195        valStr = num2Str(V_getDet_beam_center_x("VCALC","FB")) + "cm"
2196        temp_s += keyStr + nameStr + keyStrEnd
2197        temp_s += valueStr + valStr + valueStrEnd
2198
2199        nameStr = "frontBottomAreaDetector.beamCenterY"
2200        valStr = num2Str(V_getDet_beam_center_y("VCALC","FB")) + "cm"
2201        temp_s += keyStr + nameStr + keyStrEnd
2202        temp_s += valueStr + valStr + valueStrEnd
2203       
2204
2205       
2206// middle               
2207        nameStr = "middleTrans.primaryNode"
2208        valStr = num2Str(VC_getGateValveToDetDist("ML")) + "cm"         //nominal distance, any panel will do
2209        temp_s += keyStr + nameStr + keyStrEnd
2210        temp_s += valueStr + valStr + valueStrEnd
2211
2212        nameStr = "carriage.middleRight"
2213        valStr = num2Str(VCALC_getPanelTranslation("MR")) + "cm"                //no space before unit
2214        temp_s += keyStr + nameStr + keyStrEnd
2215        temp_s += valueStr + valStr + valueStrEnd
2216
2217        nameStr = "carriage.middleLeft"
2218        valStr = num2Str(VCALC_getPanelTranslation("ML")) + "cm"                //no space before unit
2219        temp_s += keyStr + nameStr + keyStrEnd
2220        temp_s += valueStr + valStr + valueStrEnd
2221
2222        nameStr = "carriage.middleTop"
2223        valStr = num2Str(VCALC_getPanelTranslation("MT")) + "cm"                //no space before unit
2224        temp_s += keyStr + nameStr + keyStrEnd
2225        temp_s += valueStr + valStr + valueStrEnd
2226
2227        nameStr = "carriage.middleBottom"
2228        valStr = num2Str(VCALC_getPanelTranslation("MB")) + "cm"                //no space before unit
2229        temp_s += keyStr + nameStr + keyStrEnd
2230        temp_s += valueStr + valStr + valueStrEnd
2231
2232        nameStr = "middleRightAreaDetector.beamCenterX"
2233        valStr = num2Str(V_getDet_beam_center_x("VCALC","MR")) + "cm"
2234        temp_s += keyStr + nameStr + keyStrEnd
2235        temp_s += valueStr + valStr + valueStrEnd
2236
2237        nameStr = "middleRightAreaDetector.beamCenterY"
2238        valStr = num2Str(V_getDet_beam_center_y("VCALC","MR")) + "cm"
2239        temp_s += keyStr + nameStr + keyStrEnd
2240        temp_s += valueStr + valStr + valueStrEnd
2241       
2242        nameStr = "middleLeftAreaDetector.beamCenterX"
2243        valStr = num2Str(V_getDet_beam_center_x("VCALC","ML")) + "cm"
2244        temp_s += keyStr + nameStr + keyStrEnd
2245        temp_s += valueStr + valStr + valueStrEnd               
2246
2247        nameStr = "middleLeftAreaDetector.beamCenterY"
2248        valStr = num2Str(V_getDet_beam_center_y("VCALC","ML")) + "cm"
2249        temp_s += keyStr + nameStr + keyStrEnd
2250        temp_s += valueStr + valStr + valueStrEnd
2251               
2252        nameStr = "middleTopAreaDetector.beamCenterX"
2253        valStr = num2Str(V_getDet_beam_center_x("VCALC","MT")) + "cm"
2254        temp_s += keyStr + nameStr + keyStrEnd
2255        temp_s += valueStr + valStr + valueStrEnd
2256
2257        nameStr = "middleTopAreaDetector.beamCenterY"
2258        valStr = num2Str(V_getDet_beam_center_y("VCALC","MT")) + "cm"
2259        temp_s += keyStr + nameStr + keyStrEnd
2260        temp_s += valueStr + valStr + valueStrEnd
2261
2262        nameStr = "middleBottomAreaDetector.beamCenterX"
2263        valStr = num2Str(V_getDet_beam_center_x("VCALC","MB")) + "cm"
2264        temp_s += keyStr + nameStr + keyStrEnd
2265        temp_s += valueStr + valStr + valueStrEnd
2266
2267        nameStr = "middleBottomAreaDetector.beamCenterY"
2268        valStr = num2Str(V_getDet_beam_center_y("VCALC","MB")) + "cm"
2269        temp_s += keyStr + nameStr + keyStrEnd
2270        temp_s += valueStr + valStr + valueStrEnd
2271
2272        nameStr = "C2BeamStop.beamStop"
2273        valStr = num2Str(1)
2274        temp_s += keyStr + nameStr + keyStrEnd
2275        temp_s += valueStr + valStr + valueStrEnd
2276
2277        nameStr = "C2BeamStopY.softPosition"
2278        valStr = num2Str(0) + "cm"              //no space before unit
2279        temp_s += keyStr + nameStr + keyStrEnd
2280        temp_s += valueStr + valStr + valueStrEnd
2281       
2282        nameStr = "C2BeamStopX.X"
2283        valStr = num2Str(0) + "cm"              //no space before unit
2284        temp_s += keyStr + nameStr + keyStrEnd
2285        temp_s += valueStr + valStr + valueStrEnd
2286
2287
2288// back
2289        nameStr = "rearTrans.primaryNode"
2290        valStr = num2Str(VC_getGateValveToDetDist("B")) + "cm"          //nominal distance, any panel will do
2291        temp_s += keyStr + nameStr + keyStrEnd
2292        temp_s += valueStr + valStr + valueStrEnd
2293
2294        nameStr = "C3DetectorOffset.softPosition"
2295        valStr = num2Str(0) + "cm"              //no space before unit
2296        temp_s += keyStr + nameStr + keyStrEnd
2297        temp_s += valueStr + valStr + valueStrEnd
2298
2299        nameStr = "rearAreaDetector.beamCenterX"
2300        valStr = num2Str(V_getDet_beam_center_x_pix("VCALC","B"))
2301        temp_s += keyStr + nameStr + keyStrEnd
2302        temp_s += valueStr + valStr + valueStrEnd
2303
2304        nameStr = "rearAreaDetector.beamCenterY"
2305        valStr = num2Str(V_getDet_beam_center_y_pix("VCALC","B"))
2306        temp_s += keyStr + nameStr + keyStrEnd
2307        temp_s += valueStr + valStr + valueStrEnd
2308       
2309        nameStr = "C3BeamStop.beamStop"
2310        valStr = num2Str(0)
2311        temp_s += keyStr + nameStr + keyStrEnd
2312        temp_s += valueStr + valStr + valueStrEnd
2313
2314        nameStr = "C3BeamStopY.softPosition"
2315        valStr = num2Str(0) + "cm"              //no space before unit
2316        temp_s += keyStr + nameStr + keyStrEnd
2317        temp_s += valueStr + valStr + valueStrEnd
2318
2319        nameStr = "C3BeamStopX.X"
2320        valStr = num2Str(0) + "cm"              //no space before unit
2321        temp_s += keyStr + nameStr + keyStrEnd
2322        temp_s += valueStr + valStr + valueStrEnd
2323
2324
2325
2326//geometry, guides, beam...
2327
2328        nameStr = "guide.guide"
2329        valStr = num2Str(VC_getNumGuides())
2330        temp_s += keyStr + nameStr + keyStrEnd
2331        temp_s += valueStr + valStr + valueStrEnd
2332       
2333        nameStr = "guide.sampleAperture"
2334        valStr = num2Str(VC_sampleApertureDiam()) + "cm"                //no space before unit
2335        temp_s += keyStr + nameStr + keyStrEnd
2336        temp_s += valueStr + valStr + valueStrEnd
2337
2338        nameStr = "guide.sourceAperture"
2339        valStr = num2Str(VC_sourceApertureDiam()) + "cm"                //no space before unit
2340        temp_s += keyStr + nameStr + keyStrEnd
2341        temp_s += valueStr + valStr + valueStrEnd
2342       
2343        nameStr = "geometry.externalSampleApertureShape"
2344        valStr = "CIRCLE"
2345        temp_s += keyStr + nameStr + keyStrEnd
2346        temp_s += valueStr + valStr + valueStrEnd
2347
2348        nameStr = "geometry.externalSampleAperture"
2349        valStr = num2Str(VC_sampleApertureDiam()) + "cm"                //no space before unit
2350        temp_s += keyStr + nameStr + keyStrEnd
2351        temp_s += valueStr + valStr + valueStrEnd
2352
2353        nameStr = "geometry.samplePositionOffset"
2354        valStr = num2Str(V_sampleToGateValve()) + "cm"          //no space before unit
2355        temp_s += keyStr + nameStr + keyStrEnd
2356        temp_s += valueStr + valStr + valueStrEnd
2357       
2358        nameStr = "geometry.sampleApertureOffset"
2359        valStr = num2Str(V_sampleApertureToGateValve()) + "cm"          //no space before unit
2360        temp_s += keyStr + nameStr + keyStrEnd
2361        temp_s += valueStr + valStr + valueStrEnd
2362       
2363        nameStr = "attenuator.attenuator"
2364        valStr = num2Str(0)
2365        temp_s += keyStr + nameStr + keyStrEnd
2366        temp_s += valueStr + valStr + valueStrEnd
2367
2368        nameStr = "wavelength.wavelength"
2369        valStr = num2Str(VCALC_getWavelength()) + "A"           //no space before unit
2370        temp_s += keyStr + nameStr + keyStrEnd
2371        temp_s += valueStr + valStr + valueStrEnd
2372       
2373        nameStr = "wavelengthSpread.wavelengthSpread"
2374        valStr = num2Str(VCALC_getWavelengthSpread())
2375// last one has a different ending sequence     
2376        temp_s += keyStr + nameStr + keyStrEnd
2377        temp_s += valueStr + valStr + closingStr
2378               
2379        return temp_s
2380end
2381
Note: See TracBrowser for help on using the repository browser.