source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/VC_VCALCPanel_MockUp.ipf @ 1130

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

more bug fixes for the VCALC functionality

File size: 46.8 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3//
4//
5// mockup of the panel for VCALC
6//
7// -- all is housed in the folder:
8//      NewDataFolder/O root:Packages:NIST:VSANS:VCALC
9//
10// -- Put all of the constants to define the instrument plus all of the VCALC stuff
11//
12// anticipating that at the same level as VCALC will be all of the reduction folders
13// in a similar way as for SANS reduction
14//
15//
16
17
18Proc VCALC_Panel()
19        DoWindow/F VCALC
20        if(V_flag==0)
21       
22                //initialize space = folders, parameters, instrument constants, etc.
23                VC_Initialize_Space()
24               
25                //open the panel
26                DrawVCALC_Panel()
27               
28                // two graphs with the ray-tracing side/top views
29                SetupSideView()
30                SetupTopView()
31               
32                // a front view of the panels
33                FrontView_1x()
34               
35                // TODO: fake a "click" on the front SDD to force (almost)everything to update
36                // including the I(q) graph
37                FakeFrontMiddleSDDClick()
38
39        endif
40End
41
42Function FakeFrontMiddleSDDClick()
43       
44        STRUCT WMSetVariableAction sva
45        sva.eventCode = 3
46//      sva.dval = 0.3
47
48        VC_BDet_SDD_SetVarProc(sva)             
49        VC_MDet_SDD_SetVarProc(sva)
50        VC_FDet_SDD_SetVarProc(sva)
51
52        return(0)
53end
54
55
56Proc DrawVCALC_Panel()
57        PauseUpdate; Silent 1           // building window...
58        NewPanel /W=(34,44,1274,699)/N=VCALC/K=1
59        ModifyPanel cbRGB=(49151,60031,65535)
60//      ShowTools/A
61        SetDrawLayer UserBack
62       
63// always visible stuff, not on any tab
64       
65        GroupBox group0,pos={10,10},size={440,125},title="Setup"
66        TabControl Vtab,labelBack=(45000,61000,58000),pos={14,150},size={430,200},tabLabel(0)="Collim"
67        TabControl Vtab,tabLabel(1)="Sample",tabLabel(2)="Front Det",tabLabel(3)="Mid Det"
68        TabControl Vtab,tabLabel(4)="Back Det",tabLabel(5)="Simul",value= 0,proc=VCALCTabProc
69        GroupBox group1,pos={460,10},size={762,635},title="Detector Panel Positions + Data"
70
71        PopupMenu popup_a,pos={50,40},size={142,20},title="Presets"
72        PopupMenu popup_a,mode=1,popvalue="F+M Ng0 Low Q",value= root:Packages:NIST:VSANS:VCALC:gPresetPopStr
73        PopupMenu popup_a,proc=VC_PresetConfigPopup
74
75        PopupMenu popup_b,pos={670,311},size={142,20},title="Binning type",proc=VC_RebinIQ_PopProc
76        PopupMenu popup_b,mode=1,value= root:Packages:NIST:VSANS:VCALC:gBinTypeStr
77        SetVariable setVar_b,pos={476,313},size={120,15},title="axis Q",proc=Front2DQ_Range_SetVarProc
78        SetVariable setVar_b,limits={0.02,1,0.02},value=_NUM:0.3
79        CheckBox check_0a title="Log?",size={60,20},pos={619,313},proc=Front2DQ_Log_CheckProc
80               
81        SetVariable setVar_a,pos={476,26},size={120,15},title="axis degrees",proc=FrontView_Range_SetVarProc
82        SetVariable setVar_a,limits={0.3,30,0.2},value=_NUM:20
83
84        ValDisplay valDisp_a,pos={50,380},size={150,15},title="Beam Intensity",value=root:Packages:NIST:VSANS:VCALC:gBeamIntensity
85
86        ValDisplay valDisp_b,pos={50,410},size={150,15},title="Q min (Front) (1/A)",value=root:Packages:NIST:VSANS:VCALC:gQmin_F
87        ValDisplay valDisp_c,pos={250,410},size={150,15},title="Q max (Front) (1/A)",value=root:Packages:NIST:VSANS:VCALC:gQmax_F
88        ValDisplay valDisp_d,pos={50,440},size={150,15},title="Q min (Mid) (1/A)",value=root:Packages:NIST:VSANS:VCALC:gQmin_M
89        ValDisplay valDisp_e,pos={250,440},size={150,15},title="Q max (Mid) (1/A)",value=root:Packages:NIST:VSANS:VCALC:gQmax_M
90        ValDisplay valDisp_f,pos={50,470},size={150,15},title="Q min (Back) (1/A)",value=root:Packages:NIST:VSANS:VCALC:gQmin_B
91        ValDisplay valDisp_g,pos={250,470},size={150,15},title="Q max (Back) (1/A)",value=root:Packages:NIST:VSANS:VCALC:gQmax_B
92        ValDisplay valDisp_h,pos={50,500},size={200,15},title="Beam Diam (middle) (cm)",value=root:Packages:NIST:VSANS:VCALC:gBeamDiam
93        ValDisplay valDisp_i,pos={50,530},size={200,15},title="Beam Stop Diam (middle) (in)",value=root:Packages:NIST:VSANS:VCALC:gBeamStopDiam
94        ValDisplay valDisp_j,pos={50,560},size={200,15},title="Real Q min (1/A)",value=root:Packages:NIST:VSANS:VCALC:gRealQMin
95
96
97
98        // for panels (in degrees)     
99        Display/W=(476,45,757,303)/HOST=# root:Packages:NIST:VSANS:VCALC:fv_degY vs root:Packages:NIST:VSANS:VCALC:fv_degX
100        RenameWindow #,FrontView
101        ModifyGraph mode=2              // mode = 2 = dots
102        ModifyGraph marker=19
103        ModifyGraph rgb=(0,0,0)
104        ModifyGraph tick=2,mirror=1
105        Label left "degrees"
106        Label bottom "degrees" 
107        SetActiveSubwindow ##
108
109
110        // for side view
111        Display/W=(842,25,1200,170)/HOST=# root:Packages:NIST:VSANS:VCALC:fv_degY vs root:Packages:NIST:VSANS:VCALC:fv_degX
112        RenameWindow #,SideView
113        ModifyGraph mode=2              // mode = 2 = dots
114        ModifyGraph marker=19
115        ModifyGraph rgb=(0,0,0)
116        ModifyGraph tick=2,mirror=1
117        Label left "Vertical position (cm)"
118        Label bottom "SDD (cm)"
119        SetActiveSubwindow ##   
120       
121        // for top view
122        Display/W=(842,180,1200,325)/HOST=# root:Packages:NIST:VSANS:VCALC:fv_degY vs root:Packages:NIST:VSANS:VCALC:fv_degX
123        RenameWindow #,TopView
124        ModifyGraph mode=2              // mode = 2 = dots
125        ModifyGraph marker=19
126        ModifyGraph rgb=(0,0,0)
127        ModifyGraph tick=2,mirror=1
128        Label left "Horizontal position (cm)"
129        Label bottom "SDD (cm)"
130        SetActiveSubwindow ##   
131
132        // for panels (as 2D Q)
133        Display/W=(475,332,814,631)/HOST=# root:Packages:NIST:VSANS:VCALC:fv_degY vs root:Packages:NIST:VSANS:VCALC:fv_degX
134        RenameWindow #,Panels_Q
135        ModifyGraph mode=2              // mode = 2 = dots
136        ModifyGraph tick=2,mirror=1,grid=2,standoff=0
137        ModifyGraph width={Aspect,1},height={Aspect,1},gbRGB=(56797,56797,56797)
138        SetAxis left -0.2,0.2
139        SetAxis bottom -0.2,0.2
140        Label left "Qy"
141        Label bottom "Qx"       
142        SetActiveSubwindow ##
143
144
145
146        // for averaged I(Q)
147        Display/W=(842,334,1204,629)/HOST=# //root:Packages:NIST:VCALC:fv_degY vs root:Packages:NIST:VSANS:VCALC:fv_degX
148        RenameWindow #,Panels_IQ
149//      ModifyGraph mode=2              // mode = 2 = dots
150        ModifyGraph tick=2,mirror=1,grid=2
151//      Label left "Intensity"
152//      Label bottom "Q"       
153        SetActiveSubwindow ##
154
155
156       
157// all controls are named VCALCCtrl_NA where N is the tab number and A is the letter indexing items on tab
158
159       
160// tab(0), collimation - initially visible
161        Slider VCALCCtrl_0a,pos={223,324-50},size={200,45},limits={0,9,1},value= 1,vert= 0,proc=V_GuideSliderProc
162        SetVariable VCALCCtrl_0b,pos={25,294-50},size={120,15},title="wavelength"
163        SetVariable VCALCCtrl_0b,limits={4,20,1},value=_NUM:8,proc=VC_Lambda_SetVarProc
164        PopupMenu VCALCCtrl_0c,pos={26,257-50},size={150,20},title="monochromator"
165        PopupMenu VCALCCtrl_0c,mode=1,popvalue="Velocity Selector",value= root:Packages:NIST:VSANS:VCALC:gMonochromatorType
166        PopupMenu VCALCCtrl_0c,proc=VC_MonochromSelectPopup
167        PopupMenu VCALCCtrl_0d,pos={26,321-50},size={115,20},title="delta lambda"
168        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
169        PopupMenu VCALCCtrl_0d,proc=VC_DeltaLamSelectPopup
170        PopupMenu VCALCCtrl_0e,pos={291,262-50},size={132,20},title="source shape"
171        PopupMenu VCALCCtrl_0e,mode=1,popvalue="circular",value= root:Packages:NIST:VSANS:VCALC:gSourceShape
172        PopupMenu VCALCCtrl_0e,proc=VC_SourceApShapeSelectPopup
173        PopupMenu VCALCCtrl_0f,pos={283,293-50},size={141,20},title="source aperture"
174        PopupMenu VCALCCtrl_0f,mode=1,popvalue="6.0 cm",value= root:Packages:NIST:VSANS:VCALC:gSourceDiam
175        PopupMenu VCALCCtrl_0f,proc=VC_SourceAperDiamSelectPopup
176
177
178// tab(1) - Sample conditions, initially not visible
179        PopupMenu VCALCCtrl_1a,pos={38,250-50},size={142,20},title="table location",disable=1
180        PopupMenu VCALCCtrl_1a,mode=1,popvalue="Changer",value= root:Packages:NIST:VSANS:VCALC:gTableLocation
181        PopupMenu VCALCCtrl_1b,pos={270,250-50},size={115,20},title="Aperture Shape",disable=1
182        PopupMenu VCALCCtrl_1b,mode=1,popvalue="circular",value= root:Packages:NIST:VSANS:VCALC:gSampleApertureShape
183        PopupMenu VCALCCtrl_1c,pos={270,310-50},size={132,20},title="Aperture Diam (cm)",disable=1
184        PopupMenu VCALCCtrl_1c,mode=1,popvalue="1.27",value= root:Packages:NIST:VSANS:VCALC:gSampleApertureDiam
185        SetVariable VCALCCtrl_1d,pos={25,280-50},size={200,15},title="Sample Aperture to Gate Valve (cm)"
186        SetVariable VCALCCtrl_1d,limits={4,40,0.1},value=_NUM:22,proc=VC_A2_to_GV_SetVarProc,disable=1
187        SetVariable VCALCCtrl_1e,pos={25,310-50},size={200,15},title="Sample Pos to Gate Valve (cm)"
188        SetVariable VCALCCtrl_1e,limits={4,40,0.1},value=_NUM:11,proc=VC_Sam_to_GV_SetVarProc,disable=1
189
190// tab(2) - Front detector panels, initially not visible
191        SetVariable VCALCCtrl_2a,pos={30,260-50},size={150,15},title="LEFT Offset (cm)",proc=VC_FDet_LR_SetVarProc
192        SetVariable VCALCCtrl_2a,limits={-20,19,0.1},disable=1,value=_NUM:-10
193        SetVariable VCALCCtrl_2aa,pos={30,290-50},size={150,15},title="RIGHT Offset (cm)",proc=VC_FDet_LR_SetVarProc
194        SetVariable VCALCCtrl_2aa,limits={-19,20,0.1},disable=1,value=_NUM:10
195       
196        SetVariable VCALCCtrl_2b,pos={30,330-50},size={150,15},title="TOP Offset (cm)",proc=VC_FDet_LR_SetVarProc
197        SetVariable VCALCCtrl_2b,limits={0,18,0.1},disable=1,value=_NUM:10
198        SetVariable VCALCCtrl_2bb,pos={30,360-50},size={150,15},title="BOTTOM Offset (cm)",proc=VC_FDet_LR_SetVarProc
199        SetVariable VCALCCtrl_2bb,limits={-18,0,0.1},disable=1,value=_NUM:-10
200       
201        SetVariable VCALCCtrl_2d,pos={205,260-50},size={230,15},title="Gate Valve to Detector Distance (cm)",proc=VC_FDet_SDD_SetVarProc
202        SetVariable VCALCCtrl_2d,limits={70,800,1},disable=1    ,value=_NUM:150
203       
204
205// tab(3) - Middle detector panels, initially not visible
206        SetVariable VCALCCtrl_3a,pos={30,260-50},size={150,15},title="LEFT Offset (cm)",proc=VC_MDet_LR_SetVarProc
207        SetVariable VCALCCtrl_3a,limits={-20,19,0.1},disable=1,value=_NUM:-7
208        SetVariable VCALCCtrl_3aa,pos={30,290-50},size={150,15},title="RIGHT Offset (cm)",proc=VC_MDet_LR_SetVarProc
209        SetVariable VCALCCtrl_3aa,limits={-19,20,0.1},disable=1,value=_NUM:7
210               
211        SetVariable VCALCCtrl_3b,pos={30,330-50},size={150,15},title="TOP Offset (cm)",proc=VC_MDet_LR_SetVarProc
212        SetVariable VCALCCtrl_3b,limits={0,18,0.1},disable=1,value=_NUM:14
213        SetVariable VCALCCtrl_3bb,pos={30,360-50},size={150,15},title="BOTTOM Offset (cm)",proc=VC_MDet_LR_SetVarProc
214        SetVariable VCALCCtrl_3bb,limits={-18,0,0.1},disable=1,value=_NUM:-14
215
216        SetVariable VCALCCtrl_3d,pos={205,260-50},size={230,15},title="Gate Valve to Detector Distance (cm)",proc=VC_MDet_SDD_SetVarProc
217        SetVariable VCALCCtrl_3d,limits={250,2000,1},disable=1,value=_NUM:1000
218
219       
220// tab(4) - Back detector panel
221        SetVariable VCALCCtrl_4a,pos={188,290-50},size={150,15},title="Lateral Offset (cm)"
222        SetVariable VCALCCtrl_4a,limits={0,20,0.1},disable=1,value=_NUM:0
223        SetVariable VCALCCtrl_4b,pos={188,260-50},size={230,15},title="Gate Valve to Detector Distance (cm)",proc=VC_BDet_SDD_SetVarProc
224        SetVariable VCALCCtrl_4b,limits={2000,2500,1},disable=1,value=_NUM:2200
225//      PopupMenu VCALCCtrl_4c,pos={40,260},size={180,20},title="Detector type",disable=1
226//      PopupMenu VCALCCtrl_4c,mode=1,popvalue="2D",value= root:Packages:NIST:VSANS:VCALC:gBackDetType
227
228// tab(5) - Simulation setup
229        SetVariable VCALCCtrl_5a,pos={40,290-50},size={200,15},title="Neutrons on Sample (imon)"
230        SetVariable VCALCCtrl_5a,limits={1e7,1e15,1e7},disable=1,value=_NUM:1e11,proc=VC_SimImon_SetVarProc
231        PopupMenu VCALCCtrl_5b,pos={40,260-50},size={180,20},title="Model Function",disable=1
232        PopupMenu VCALCCtrl_5b,mode=1,popvalue="Debye",value= root:Packages:NIST:VSANS:VCALC:gModelFunctionType,proc=VC_SimModelFunc_PopProc
233       
234End
235
236//
237//  recalculates the detector panels, doesn't adjust the views
238//
239Function Recalculate_AllDetectors()
240
241// calculates Q for each panel
242// and fills 2D panels with model data
243        fPlotBackPanels()
244        fPlotMiddlePanels()
245        fPlotFrontPanels()
246
247        String popStr
248        String collimationStr = "pinhole"
249        ControlInfo/W=VCALC popup_b
250        popStr = S_Value                //
251        V_QBinAllPanels_Circular("VCALC",V_BinTypeStr2Num(popStr),collimationStr)
252
253
254        // plot the results (1D)
255        String type = "VCALC"
256        String str,winStr="VCALC#Panels_IQ",workTypeStr
257        workTypeStr = "root:Packages:NIST:VSANS:"+type
258       
259        sprintf str,"(\"%s\",%d,\"%s\")",workTypeStr,V_BinTypeStr2Num(popStr),winStr
260        Execute ("V_Back_IQ_Graph"+str)
261               
262        Execute ("V_Middle_IQ_Graph"+str)
263       
264        Execute ("V_Front_IQ_Graph"+str)
265
266
267
268
269       
270        V_beamIntensity()
271       
272//      Print "Beam diam (middle) = ",VC_beamDiameter("horizontal",2)           //middle carriage
273       
274        // fill in the Qmin and Qmax values
275        V_QMinMax_Back()
276        V_QMinMax_Middle()
277        V_QMinMax_Front()
278       
279        //calculate beam diameter and beamstop size
280        V_BeamDiamDisplay("maximum", "MR")      //TODO -- hard-wired here for the Middle carriage (and in the SetVar label)
281        V_BeamStopDiamDisplay("MR")
282       
283        //calculate the "real" QMin with the beamstop
284        V_QMin_withBeamStop("MR")               //TODO -- hard-wired here as the middle carriage and MR panel
285       
286        // multiply the averaged data by the shadow factor to simulate a beamstop
287        V_IQ_BeamstopShadow()
288       
289        return(0)
290End
291
292
293
294// function to control the drawing of controls in the TabControl on the main panel
295// Naming scheme for the controls MUST be strictly adhered to... else controls will
296// appear in odd places...
297// all controls are named VCALCCtrl_NA where N is the tab number and A is the letter denoting
298// the controls position on that particular tab.
299// in this way, they will always be drawn correctly..
300//
301//
302// -- this will need to be modified to allow for the graph to be drawn of the detector bank positions
303//     if that is individual to each tab - or if it's  always visible - that's still to be decided.
304//
305//
306Function VCALCTabProc(name,tab)
307        String name
308        Variable tab
309       
310//      Print "name,number",name,tab
311        String ctrlList = ControlNameList("",";"),item="",nameStr=""
312        Variable num = ItemsinList(ctrlList,";"),ii,onTab
313        for(ii=0;ii<num;ii+=1)
314                //items all start w/"VCALCCtrl_", 10 characters
315                item=StringFromList(ii, ctrlList ,";")
316                nameStr=item[0,9]
317                if(cmpstr(nameStr,"VCALCCtrl_")==0)
318                        onTab = str2num(item[10])                       //[10] is a number
319                        ControlInfo $item
320                        switch(abs(V_flag))     
321                                case 1:
322                                        Button $item,disable=(tab!=onTab)
323                                        break
324                                case 2:
325                                        CheckBox $item,disable=(tab!=onTab)
326                                        break
327                                case 3:
328                                        PopupMenu $item,disable=(tab!=onTab)
329                                        break
330                                case 4:
331                                        ValDisplay $item,disable=(tab!=onTab)
332                                        break
333                                case 5:
334                                        SetVariable $item,disable=(tab!=onTab)
335                                        break
336                                case 7:
337                                        Slider $item,disable=(tab!=onTab)
338                                        break
339                                case 9:
340                                        GroupBox $item,disable=(tab!=onTab)
341                                        break
342                                case 10:       
343                                        TitleBox $item,disable=(tab!=onTab)
344                                        break
345                                // add more items to the switch if different control types are used
346                        endswitch
347                endif
348        endfor
349       
350        return(0)
351End
352
353
354
355// TODO
356//changing the number of guides changes the SSD
357// the source aperture popup may need to be updated
358//
359Function V_GuideSliderProc(ctrlName,sliderValue,event)
360        String ctrlName
361        Variable sliderValue
362        Variable event  // bit field: bit 0: value set, 1: mouse down, 2: mouse up, 3: mouse moved
363       
364        Variable recalc=0
365        SVAR apStr = root:Packages:NIST:VSANS:VCALC:gSourceDiam
366       
367        if(event %& 0x1)        // bit 0, value set
368                if(cmpstr(ctrlName,"") != 0)            //here by direct action, so do LensCheck and recalculate
369//                      recalc=1
370//                      LensCheckProc("",2)             //make sure lenses are deselected
371                endif
372//              sourceToSampleDist()            //updates the SSD global and wave
373                //change the sourceAp popup, SDD range, etc
374                switch(sliderValue)
375                        case 0:
376//                              ControlInfo/W=SASCALC popup0
377//                              mode=V_value
378                                apStr = "0.75 cm;1.5 cm;3.0 cm;"
379                                break
380                        default:
381                                apStr = "6 cm;"
382                endswitch
383                ControlUpdate/W=VCALC VCALCCtrl_0f
384//              UpdateControls()                                // the Ng global is actually set inside this function
385                Recalculate_AllDetectors()
386        endif
387        return 0
388End
389
390
391
392
393
394Function Front2DQ_Log_CheckProc(cba) : CheckBoxControl
395        STRUCT WMCheckboxAction &cba
396
397        switch( cba.eventCode )
398                case 2: // mouse up
399                        Variable checked = cba.checked
400                       
401                        Execute "FrontPanels_AsQ()"
402                        Execute "MiddlePanels_AsQ()"
403                        Execute "BackPanels_AsQ()"
404                       
405                        break
406                case -1: // control being killed
407                        break
408        endswitch
409
410        return 0
411End
412
413
414
415Function VC_SourceAperDiamSelectPopup(pa) : PopupMenuControl
416        STRUCT WMPopupAction &pa
417
418        switch( pa.eventCode )
419                case 2: // mouse up
420                        Variable popNum = pa.popNum
421                        String popStr = pa.popStr
422                       
423                        Print "Not filled in yet"
424                       
425                        // a recalculation is needed after the change
426                        //Recalculate_AllDetectors()
427                                       
428                        break
429                case -1: // control being killed
430                        break
431        endswitch
432
433        return 0
434End
435
436Function VC_SourceApShapeSelectPopup(pa) : PopupMenuControl
437        STRUCT WMPopupAction &pa
438
439        switch( pa.eventCode )
440                case 2: // mouse up
441                        Variable popNum = pa.popNum
442                        String popStr = pa.popStr
443                       
444                        Print "Not filled in yet"
445
446                        // a recalculation is needed after the change
447                        //Recalculate_AllDetectors()
448                                                                       
449                        break
450                case -1: // control being killed
451                        break
452        endswitch
453
454        return 0
455End
456
457Function VC_DeltaLamSelectPopup(pa) : PopupMenuControl
458        STRUCT WMPopupAction &pa
459
460        switch( pa.eventCode )
461                case 2: // mouse up
462                        Variable popNum = pa.popNum
463                        String popStr = pa.popStr
464                       
465                        // a recalculation is needed after the change
466                        Recalculate_AllDetectors()
467                                                                       
468                        break
469                case -1: // control being killed
470                        break
471        endswitch
472
473        return 0
474End
475
476// change the choices for deltaLam based on the
477// type of monochromator selected
478//
479// some cases force a change of the wavelength
480//
481// then recalculate
482Function VC_MonochromSelectPopup(pa) : PopupMenuControl
483        STRUCT WMPopupAction &pa
484
485        switch( pa.eventCode )
486                case 2: // mouse up
487                        Variable popNum = pa.popNum
488                        String popStr = pa.popStr
489                       
490                        SVAR DLStr = root:Packages:NIST:VSANS:VCALC:gDeltaLambda
491                       
492                        strswitch(popStr)
493                                case "Velocity Selector":
494                                        DLStr = "0.12;"
495//                                      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
496                                        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.12"
497                                       
498                                        SetVariable VCALCCtrl_0b,disable=0,noedit=0             // allow user editing again
499
500                                        break
501                                case "Graphite":
502                                        DLStr = "0.01;"
503//                                      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.01",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
504                                        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.01"
505                                       
506                                        SetVariable VCALCCtrl_0b,value=_NUM:4.75,disable=2              // wavelength
507                                        break
508                                case "White Beam":
509                                        DLStr = "0.40;"
510//                                      PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.40",value= root:Packages:NIST:VSANS:VCALC:gDeltaLambda
511                                        PopupMenu VCALCCtrl_0d,mode=1,popvalue="0.40"
512
513                                        SetVariable VCALCCtrl_0b,value=_NUM:5.3,disable=2               //wavelength
514                                        break           
515                                default:
516                                        Print "Error--No match in VC_MonochromSelectPopup"
517                                        return(0)
518                        endswitch
519                       
520
521                        // a recalculation is needed after the change
522                        Recalculate_AllDetectors()
523                                                               
524                        break
525                case -1: // control being killed
526                        break
527        endswitch
528
529        return 0
530End
531
532//
533//
534// "F+M Ng0 Low Q;F+M Ng2 Mid Q;F+M Ng7 Mid Q;F+M Ng9 High Q;Converging Pinholes;Narrow Slit;White Beam;Graphite;Polarizer;"
535//
536Function VC_PresetConfigPopup(pa) : PopupMenuControl
537        STRUCT WMPopupAction &pa
538
539        switch( pa.eventCode )
540                case 2: // mouse up
541                        Variable popNum = pa.popNum
542                        String popStr = pa.popStr
543                       
544                        String BinStr = "F2-M2xTB-B"
545               
546                        strswitch(popStr)
547                                case "F+M Ng0 Low Q":
548                                        VC_Preset_FrontMiddle_Ng0()
549                                        break
550                                case "F+M Ng2 Mid Q":
551                                        VC_Preset_FrontMiddle_Ng2()
552                                        break
553                                case "F+M Ng7 Mid Q":
554                                        VC_Preset_FrontMiddle_Ng7()
555                                        break
556                                case "F+M Ng9 High Q":
557                                        VC_Preset_FrontMiddle_Ng9()
558                                        break
559                                       
560                                case "White Beam":
561                                        VC_Preset_WhiteBeam()
562                                        break   
563                                case "Graphite":
564                                        VC_Preset_GraphiteMono()
565                                        break
566                                case "Narrow Slit":
567                                       
568                                        break
569                                case "Converging Pinholes":
570                                       
571                                        break
572                                case "Polarizer":
573                                       
574                                        break
575                                       
576                                default:
577                                        Print "Error--No match in VC_PresetConfigPopup"
578                                        return(0)
579                        endswitch
580                       
581                        // update the views
582                        VC_UpdateViews()
583                       
584                        // a recalculation is needed after the change
585                        // this re-bins the data too
586                        Recalculate_AllDetectors()
587                       
588                        // re-bin the data?
589//                      VC_RebinIQ_PopProc("",0,binStr)
590                                       
591                        break
592                case -1: // control being killed
593                        break
594        endswitch
595
596        return 0
597End
598
599
600
601
602
603//
604// recalculate the detectors with a preset model function
605//
606Function VC_SimModelFunc_PopProc(ctrlName,popNum,popStr) : PopupMenuControl
607        String ctrlName
608        Variable popNum // which item is currently selected (1-based)
609        String popStr           // contents of current popup item as string
610
611        Recalculate_AllDetectors()
612       
613        return(0)       
614End
615
616
617//
618// recalculate the I(q) binning. no need to adjust model function or views
619// just rebin
620//
621// this is for the VCALC 1-D plot subwindow only. so it is set up to
622// operate on that window - but uses the same binning and plotting routines
623// as the regualr VSANS data display
624//
625Function VC_RebinIQ_PopProc(ctrlName,popNum,popStr) : PopupMenuControl
626        String ctrlName
627        Variable popNum // which item is currently selected (1-based)
628        String popStr           // contents of current popup item as string
629
630
631        String type = "VCALC"
632        String str,winStr="VCALC#Panels_IQ",workTypeStr
633        workTypeStr = "root:Packages:NIST:VSANS:"+type
634       
635        String collimationStr = "pinhole"               //TODO: fill this in from the VCALC panel
636       
637// dispatch based on the string, not on the number of selection in the pop string
638        V_QBinAllPanels_Circular(type,V_BinTypeStr2Num(popStr),collimationStr)
639       
640        sprintf str,"(\"%s\",%d,\"%s\")",workTypeStr,V_BinTypeStr2Num(popStr),winStr
641
642        Execute ("V_Back_IQ_Graph"+str)
643        Execute ("V_Middle_IQ_Graph"+str)
644        Execute ("V_Front_IQ_Graph"+str)
645
646// OLD - do not use
647//      // do the q-binning for front panels to get I(Q)
648//      Execute "BinAllFrontPanels()"
649//      Execute "Front_IQ_Graph()"
650//
651//      // do the q-binning for middle panels to get I(Q)
652//      Execute "BinAllMiddlePanels()"
653//      Execute "Middle_IQ_Graph()"
654//     
655//      // do the q-binning for the back panel to get I(Q)
656//      Execute "BinAllBackPanels()"
657//      Execute "Back_IQ_Graph()"
658//     
659        return(0)       
660End
661
662
663//
664// setVar for the distance from Sample Position to Gave Valve
665//
666Function VC_Sam_to_GV_SetVarProc(sva) : SetVariableControl
667        STRUCT WMSetVariableAction &sva
668
669        switch( sva.eventCode )
670                case 1: // mouse up
671                case 2: // Enter key
672                case 3: // Live update
673                        Variable dval = sva.dval
674                        String sval = sva.sval
675                       
676//                      // don't need to recalculate the views, but need to recalculate the detectors
677
678//                      Recalculate_AllDetectors()             
679                               
680                        break
681                case -1: // control being killed
682                        break
683        endswitch
684
685        return 0
686End
687       
688
689//
690// setVar for the distance from Sample Aperture to Gave Valve
691//
692Function VC_A2_to_GV_SetVarProc(sva) : SetVariableControl
693        STRUCT WMSetVariableAction &sva
694
695        switch( sva.eventCode )
696                case 1: // mouse up
697                case 2: // Enter key
698                case 3: // Live update
699                        Variable dval = sva.dval
700                        String sval = sva.sval
701                       
702//                      // don't need to recalculate the views, but need to recalculate the detectors
703
704//                      Recalculate_AllDetectors()             
705                               
706                        break
707                case -1: // control being killed
708                        break
709        endswitch
710
711        return 0
712End
713       
714//
715// setVar for the wavelength
716//
717Function VC_Lambda_SetVarProc(sva) : SetVariableControl
718        STRUCT WMSetVariableAction &sva
719
720        switch( sva.eventCode )
721                case 1: // mouse up
722                case 2: // Enter key
723                case 3: // Live update
724                        Variable dval = sva.dval
725                        String sval = sva.sval
726                       
727//                      // don't need to recalculate the views, but need to recalculate the detectors
728
729                        Recalculate_AllDetectors()             
730                               
731                        break
732                case -1: // control being killed
733                        break
734        endswitch
735
736        return 0
737End
738
739//
740// setVar for the simulation monitor count
741//
742Function VC_SimImon_SetVarProc(sva) : SetVariableControl
743        STRUCT WMSetVariableAction &sva
744
745        switch( sva.eventCode )
746                case 1: // mouse up
747                case 2: // Enter key
748                case 3: // Live update
749                        Variable dval = sva.dval
750                        String sval = sva.sval
751
752                        Recalculate_AllDetectors()             
753                               
754                        break
755                case -1: // control being killed
756                        break
757        endswitch
758
759        return 0
760End
761
762
763// setVar for the range (in degrees) for the FrontView plot of the detectors
764//
765Function FrontView_Range_SetVarProc(sva) : SetVariableControl
766        STRUCT WMSetVariableAction &sva
767
768        switch( sva.eventCode )
769                case 1: // mouse up
770                case 2: // Enter key
771                case 3: // Live update
772                        Variable dval = sva.dval
773                        String sval = sva.sval
774                       
775                        FrontView_1x()
776                       
777                        break
778                case -1: // control being killed
779                        break
780        endswitch
781
782        return 0
783End
784
785// setVar for the range (in Q) for the FrontView plot of the detectors
786//
787// TODO: this assumes that everything (the data) is already updated - this only updates the plot range
788Function Front2DQ_Range_SetVarProc(sva) : SetVariableControl
789        STRUCT WMSetVariableAction &sva
790
791        switch( sva.eventCode )
792                case 1: // mouse up
793                case 2: // Enter key
794                case 3: // Live update
795                        Variable dval = sva.dval
796                        String sval = sva.sval
797                       
798                        SetAxis/W=VCALC#Panels_Q left -dval,dval
799                        SetAxis/W=VCALC#Panels_Q bottom -dval,dval
800                       
801//                      FrontPanels_AsQ()
802                       
803                        break
804                case -1: // control being killed
805                        break
806        endswitch
807
808        return 0
809End
810
811// SDD for the Front detector. triggers a recalculation
812// of the intensity and a redraw of the banks
813//
814Function VC_FDet_SDD_SetVarProc(sva) : SetVariableControl
815        STRUCT WMSetVariableAction &sva
816
817        switch( sva.eventCode )
818                case 1: // mouse up
819                case 2: // Enter key
820                case 3: // Live update
821                        Variable dval = sva.dval
822                        String sval = sva.sval
823                       
824//                      Variable LR_sep,TB_sep
825//                      // don't know if LR or TB called, so get the explicit values
826//                      //
827//                      ControlInfo VCALCCtrl_2a
828//                      LR_sep = V_Value
829//                      ControlInfo VCALCCtrl_2b
830//                      TB_sep = V_Value
831//                     
832//                      UpdateFrontDetector(LR_sep,TB_sep)
833                       
834                        UpdateSideView()
835                        UpdateTopView()
836                        FrontView_1x()
837                       
838                        fPlotFrontPanels()
839                       
840                        break
841                case -1: // control being killed
842                        break
843        endswitch
844
845        return 0
846End
847
848// SDD for the Middle detector. triggers a recalculation
849// of the intensity and a redraw of the banks
850//
851Function VC_MDet_SDD_SetVarProc(sva) : SetVariableControl
852        STRUCT WMSetVariableAction &sva
853
854        switch( sva.eventCode )
855                case 1: // mouse up
856                case 2: // Enter key
857                case 3: // Live update
858                        Variable dval = sva.dval
859                        String sval = sva.sval
860                       
861//                      Variable LR_sep,TB_sep
862//                      // don't know if LR or TB called, so get the explicit values
863//                      //
864//                      ControlInfo VCALCCtrl_2a
865//                      LR_sep = V_Value
866//                      ControlInfo VCALCCtrl_2b
867//                      TB_sep = V_Value
868//                     
869//                      UpdateFrontDetector(LR_sep,TB_sep)
870                       
871                        UpdateSideView()
872                        UpdateTopView()
873                        FrontView_1x()
874                       
875                        fPlotMiddlePanels()
876                       
877                        break
878                case -1: // control being killed
879                        break
880        endswitch
881
882        return 0
883End
884
885// SDD for the Back detector. triggers a recalculation
886// of the intensity and a redraw of the banks
887//
888Function VC_BDet_SDD_SetVarProc(sva) : SetVariableControl
889        STRUCT WMSetVariableAction &sva
890
891        switch( sva.eventCode )
892                case 1: // mouse up
893                case 2: // Enter key
894                case 3: // Live update
895                        Variable dval = sva.dval
896                        String sval = sva.sval
897                       
898//                      Variable LR_sep,TB_sep
899//                      // don't know if LR or TB called, so get the explicit values
900//                      //
901//                      ControlInfo VCALCCtrl_2a
902//                      LR_sep = V_Value
903//                      ControlInfo VCALCCtrl_2b
904//                      TB_sep = V_Value
905//                     
906//                      UpdateFrontDetector(LR_sep,TB_sep)
907                       
908                        UpdateSideView()
909                        UpdateTopView()
910                        FrontView_1x()
911                       
912                        fPlotBackPanels()
913                       
914                        break
915                case -1: // control being killed
916                        break
917        endswitch
918
919        return 0
920End
921
922// separation, either LR or TB of the front detector. triggers a recalculation
923// of the intensity and a redraw of the banks
924//
925Function VC_FDet_LR_SetVarProc(sva) : SetVariableControl
926        STRUCT WMSetVariableAction &sva
927
928        switch( sva.eventCode )
929                case 1: // mouse up
930                case 2: // Enter key
931                case 3: // Live update
932                        Variable dval = sva.dval
933                        String sval = sva.sval
934                       
935//                      Variable LR_sep,TB_sep
936//                      // don't know if LR or TB called, so get the explicit values
937//                      //
938//                      ControlInfo VCALCCtrl_2a
939//                      LR_sep = V_Value
940//                      ControlInfo VCALCCtrl_2b
941//                      TB_sep = V_Value
942//                     
943//                      UpdateFrontDetector(LR_sep,TB_sep)
944                       
945                        UpdateSideView()
946                        UpdateTopView()
947                        FrontView_1x()
948                       
949                        fPlotFrontPanels()
950                       
951                        break
952                case -1: // control being killed
953                        break
954        endswitch
955
956        return 0
957End
958
959
960// separation, either LR or TB of the middle detector. triggers a recalculation
961// of the intensity and a redraw of the banks
962//
963Function VC_MDet_LR_SetVarProc(sva) : SetVariableControl
964        STRUCT WMSetVariableAction &sva
965
966        switch( sva.eventCode )
967                case 1: // mouse up
968                case 2: // Enter key
969                case 3: // Live update
970                        Variable dval = sva.dval
971                        String sval = sva.sval
972                       
973//                      Variable LR_sep,TB_sep
974//                      // don't know if LR or TB called, so get the explicit values
975//                      //
976//                      ControlInfo VCALCCtrl_3a
977//                      LR_sep = V_Value
978//                      ControlInfo VCALCCtrl_3b
979//                      TB_sep = V_Value
980                       
981//                      UpdateMiddleDetector(LR_sep,TB_sep)
982                       
983                        UpdateSideView()
984                        UpdateTopView()
985                        FrontView_1x()
986                       
987                        fPlotMiddlePanels()
988                       
989                        break
990                case -1: // control being killed
991                        break
992        endswitch
993
994        return 0
995End
996
997// call to update the views (not the q-calculation, that is a separate call)
998Function VC_UpdateViews()
999
1000        UpdateSideView()
1001        UpdateTopView()
1002        FrontView_1x()
1003       
1004        return(0)
1005End
1006
1007// this all needs to be fixed and updated - not yet specific to VSANS
1008//
1009// -- all of the simulation stuff will need to be re-thought
1010// -- all of the integersRead, data, etc. will need to be re-thought...
1011// -- but the space needs to be allocated.
1012// -- parameters and constants need to be defined in their own space
1013//
1014// FEB 2016 -- changed the data folder space to mimic the HDF folder structure
1015// so that the averaging routines could be re-used (along with everything else)
1016// -- painful, but better in the long run
1017//
1018// -- I have not re-named the detector arrays to all be "data" since that is very difficult to
1019//   deal with on images. Added a global "gVCALC_Active" as a crude workaround as needed. Turn it
1020//   on when needed and then immediately off
1021//
1022Proc VC_Initialize_Space()
1023//
1024        NewDataFolder/O root:Packages
1025        NewDataFolder/O root:Packages:NIST
1026        NewDataFolder/O root:Packages:NIST:VSANS
1027        NewDataFolder/O root:Packages:NIST:VSANS:VCALC
1028        NewDataFolder/O root:Packages:NIST:VSANS:VCALC:entry
1029        NewDataFolder/O root:Packages:NIST:VSANS:VCALC:entry:instrument
1030        NewDataFolder/O root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B
1031        NewDataFolder/O root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_MB
1032        NewDataFolder/O root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_MT
1033        NewDataFolder/O root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_ML
1034        NewDataFolder/O root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_MR
1035        NewDataFolder/O root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FB
1036        NewDataFolder/O root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FT
1037        NewDataFolder/O root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FL
1038        NewDataFolder/O root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FR
1039
1040//      NewDataFolder/O root:Packages:NIST:VSANS:VCALC:Front
1041//      NewDataFolder/O root:Packages:NIST:VSANS:VCALC:Middle
1042//      NewDataFolder/O root:Packages:NIST:VSANS:VCALC:Back
1043
1044        NewDataFolder/O root:Packages:NIST:VSANS:RawVSANS
1045       
1046        Variable/G root:Packages:NIST:VSANS:VCALC:gVCALC_Active = 1
1047        Variable/G root:Packages:NIST:VSANS:VCALC:gUseNonLinearDet = 0          //if == 1, use RAW non-linear corrections
1048       
1049        SetDataFolder root:Packages:NIST:VSANS:VCALC
1050       
1051
1052///// FRONT DETECTOR BANKS
1053// dimensions for the detector banks (then get them in the drawing functions)
1054// Width and height are not part of the Nexus file definition, but are needed for VCALC drawing
1055// so keep them as variables
1056        Variable/G gFront_LR_w = 38.4           //front bank, nominal LR panel width [cm]
1057        Variable/G gFront_LR_h = 100.0
1058        Variable/G gFront_TB_w = 50.0
1059        Variable/G gFront_TB_h = 38.4
1060
1061// SDD setback of T/B (decide on units??)
1062// for the Nexus file, the detector distance should already be corrected for the "setback"
1063// of the T/B panels. keep as VCALC variable
1064        Variable/G gFront_SDDsetback = 41.0                     // [cm]
1065       
1066       
1067// detector resolution (xy for each bank!)
1068        Make/O/D/N=1 :entry:instrument:detector_FL:x_pixel_size = 0.84          // (cm)         these tubes are vertical 8.4 mm x-spacing (JGB 2/2106)
1069        Make/O/D/N=1 :entry:instrument:detector_FL:y_pixel_size = 0.8           // (cm)         //!! now 8 mm, since nPix=128, rather than 256
1070        Make/O/D/N=1 :entry:instrument:detector_FR:x_pixel_size = 0.84
1071        Make/O/D/N=1 :entry:instrument:detector_FR:y_pixel_size = 0.8
1072        //T/B
1073        Make/O/D/N=1 :entry:instrument:detector_FT:x_pixel_size = 0.4           //these tubes are horizontal
1074        Make/O/D/N=1 :entry:instrument:detector_FT:y_pixel_size = 0.84
1075        Make/O/D/N=1 :entry:instrument:detector_FB:x_pixel_size = 0.4
1076        Make/O/D/N=1 :entry:instrument:detector_FB:y_pixel_size = 0.84
1077       
1078
1079// number of pixels in each bank (this can be modified at acquisition time, so it must be adjustable here)
1080        Make/O/D/N=1 :entry:instrument:detector_FL:pixel_num_x = 48     // == number of tubes
1081        Make/O/D/N=1 :entry:instrument:detector_FL:pixel_num_y = 128    // == pixels in vertical direction (was 256, John says likely will run @ 128 9/2015)
1082        Make/O/D/N=1 :entry:instrument:detector_FR:pixel_num_x = 48     // == number of tubes
1083        Make/O/D/N=1 :entry:instrument:detector_FR:pixel_num_y = 128    // == pixels in vertical direction
1084        Make/O/D/N=1 :entry:instrument:detector_FT:pixel_num_x = 128    // == pixels in horizontal direction
1085        Make/O/D/N=1 :entry:instrument:detector_FT:pixel_num_y = 48     // == number of tubes
1086        Make/O/D/N=1 :entry:instrument:detector_FB:pixel_num_x = 128    // == pixels in horizontal direction
1087        Make/O/D/N=1 :entry:instrument:detector_FB:pixel_num_y = 48     // == number of tubes
1088
1089
1090
1091// pixel beam center - HDF style
1092        Make/O/D/N=1 :entry:instrument:detector_FL:beam_center_x = 55           // == x beam center, in pixels
1093        Make/O/D/N=1 :entry:instrument:detector_FL:beam_center_y = 64           // == y beam center, in pixels
1094        Make/O/D/N=1 :entry:instrument:detector_FR:beam_center_x = -8   
1095        Make/O/D/N=1 :entry:instrument:detector_FR:beam_center_y = 64   
1096        Make/O/D/N=1 :entry:instrument:detector_FT:beam_center_x = 64   
1097        Make/O/D/N=1 :entry:instrument:detector_FT:beam_center_y = -8   
1098        Make/O/D/N=1 :entry:instrument:detector_FB:beam_center_x = 64   
1099        Make/O/D/N=1 :entry:instrument:detector_FB:beam_center_y = 55   
1100
1101
1102
1103///// MIDDLE DETECTOR BANKS
1104// Width and height are not part of the Nexus file definition, but are needed for VCALC drawing
1105// so keep them as variables
1106        Variable/G gMiddle_LR_w = 38.4          //middle bank, nominal LR panel width (cm)
1107        Variable/G gMiddle_LR_h = 100.0
1108        Variable/G gMiddle_TB_w = 50.0
1109        Variable/G gMiddle_TB_h = 38.4
1110// SDD offset of T/B (decide on units??)
1111// for the Nexus file, the detector distance should already be corrected for the "setback"
1112// of the T/B panels. keep as VCALC variable
1113        Variable/G gMiddle_SDDsetback = 41.0                    // [cm]
1114       
1115// detector resolution (xy for each bank!)
1116        Make/O/D/N=1 :entry:instrument:detector_ML:x_pixel_size = 0.84          // (cm)         these tubes are vertical 8.4 mm x-spacing (JGB 2/2106)
1117        Make/O/D/N=1 :entry:instrument:detector_ML:y_pixel_size = 0.8           // (cm)         //!! now 8 mm, since nPix=128, rather than 256
1118        Make/O/D/N=1 :entry:instrument:detector_MR:x_pixel_size = 0.84
1119        Make/O/D/N=1 :entry:instrument:detector_MR:y_pixel_size = 0.8
1120        //T/B
1121        Make/O/D/N=1 :entry:instrument:detector_MT:x_pixel_size = 0.4           //these tubes are horizontal
1122        Make/O/D/N=1 :entry:instrument:detector_MT:y_pixel_size = 0.84
1123        Make/O/D/N=1 :entry:instrument:detector_MB:x_pixel_size = 0.4
1124        Make/O/D/N=1 :entry:instrument:detector_MB:y_pixel_size = 0.84
1125
1126
1127
1128// number of pixels in each bank (this can be modified at acquisition time, so it must be adjustable here)
1129        Make/O/D/N=1 :entry:instrument:detector_ML:pixel_num_x = 48     // == number of tubes
1130        Make/O/D/N=1 :entry:instrument:detector_ML:pixel_num_y = 128    // == pixels in vertical direction (was 256, John says likely will run @ 128 9/2015)
1131        Make/O/D/N=1 :entry:instrument:detector_MR:pixel_num_x = 48     // == number of tubes
1132        Make/O/D/N=1 :entry:instrument:detector_MR:pixel_num_y = 128    // == pixels in vertical direction
1133        Make/O/D/N=1 :entry:instrument:detector_MT:pixel_num_x = 128    // == pixels in horizontal direction
1134        Make/O/D/N=1 :entry:instrument:detector_MT:pixel_num_y = 48     // == number of tubes
1135        Make/O/D/N=1 :entry:instrument:detector_MB:pixel_num_x = 128    // == pixels in horizontal direction
1136        Make/O/D/N=1 :entry:instrument:detector_MB:pixel_num_y = 48     // == number of tubes
1137       
1138
1139
1140// pixel beam center - HDF style
1141        Make/O/D/N=1 :entry:instrument:detector_ML:beam_center_x = 55           // == x beam center, in pixels
1142        Make/O/D/N=1 :entry:instrument:detector_ML:beam_center_y = 64           // == y beam center, in pixels
1143        Make/O/D/N=1 :entry:instrument:detector_MR:beam_center_x = -8   
1144        Make/O/D/N=1 :entry:instrument:detector_MR:beam_center_y = 64   
1145        Make/O/D/N=1 :entry:instrument:detector_MT:beam_center_x = 64   
1146        Make/O/D/N=1 :entry:instrument:detector_MT:beam_center_y = -8   
1147        Make/O/D/N=1 :entry:instrument:detector_MB:beam_center_x = 64   
1148        Make/O/D/N=1 :entry:instrument:detector_MB:beam_center_y = 55   
1149
1150
1151
1152
1153//// BACK DETECTOR
1154        Variable/G gBack_w = 22.2                               //w and h for the back detector [cm]
1155        Variable/G gBack_h = 50.4
1156       
1157       
1158        // TODOHIRES -- be sure that all of this is correct, since it is hard-wired values
1159        // -- can't use a switch so I'm using an if(), where the default is 4x4 binning
1160        if(root:Packages:NIST:VSANS:Globals:gHighResBinning == 1)
1161                Make/O/D/N=1 :entry:instrument:detector_B:x_pixel_size = 0.00845                // 340 micron resolution (units of [cm] here)
1162                Make/O/D/N=1 :entry:instrument:detector_B:y_pixel_size = 0.00845               
1163       
1164                Make/O/D/N=1 :entry:instrument:detector_B:pixel_num_x = 2720            // detector pixels in x-direction
1165                Make/O/D/N=1 :entry:instrument:detector_B:pixel_num_y = 6624
1166               
1167        // pixel beam center - HDF style
1168                Make/O/D/N=1 :entry:instrument:detector_B:beam_center_x = 1360.1        // == x beam center, in pixels +0.1 so I know it's from here
1169                Make/O/D/N=1 :entry:instrument:detector_B:beam_center_y = 3312.1                // == y beam center, in pixels
1170        else
1171                Make/O/D/N=1 :entry:instrument:detector_B:x_pixel_size = 0.034          // 340 micron resolution (units of [cm] here)
1172                Make/O/D/N=1 :entry:instrument:detector_B:y_pixel_size = 0.034         
1173       
1174                Make/O/D/N=1 :entry:instrument:detector_B:pixel_num_x = 680             // detector pixels in x-direction
1175                Make/O/D/N=1 :entry:instrument:detector_B:pixel_num_y = 1656
1176               
1177        // pixel beam center - HDF style
1178                Make/O/D/N=1 :entry:instrument:detector_B:beam_center_x = 340.1 // == x beam center, in pixels +0.1 so I know it's from here
1179                Make/O/D/N=1 :entry:instrument:detector_B:beam_center_y = 828.1         // == y beam center, in pixels
1180        endif
1181
1182
1183// Generate all of the waves used for the detector and the q values
1184//
1185// TODO: the detector dimensions need to be properly defined here...
1186// FRONT
1187//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
1188
1189        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FL
1190        Make/O/D/N=(pixel_num_x[0],pixel_num_y[0]) det_FL
1191        Duplicate/O det_FL qTot_FL,qx_FL,qy_FL,qz_FL
1192
1193        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FR
1194        Make/O/D/N=(pixel_num_x[0],pixel_num_y[0]) det_FR
1195        Duplicate/O det_FR qTot_FR,qx_FR,qy_FR,qz_FR
1196
1197        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FT
1198        Make/O/D/N=(pixel_num_x[0],pixel_num_y[0]) det_FT
1199        Duplicate/O det_FT qTot_FT,qx_FT,qy_FT,qz_FT
1200       
1201        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FB
1202        Make/O/D/N=(pixel_num_x[0],pixel_num_y[0]) det_FB
1203        Duplicate/O det_FB qTot_FB,qx_FB,qy_FB,qz_FB
1204
1205
1206//MIDDLE
1207// TODO: the detector dimensions need to be properly defined here...
1208//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
1209
1210        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_ML
1211        Make/O/D/N=(pixel_num_x[0],pixel_num_y[0]) det_ML
1212        Duplicate/O det_ML qTot_ML,qx_ML,qy_ML,qz_ML
1213       
1214        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_MR
1215        Make/O/D/N=(pixel_num_x[0],pixel_num_y[0]) det_MR
1216        Duplicate/O det_MR qTot_MR,qx_MR,qy_MR,qz_MR
1217
1218        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_MT
1219        Make/O/D/N=(pixel_num_x[0],pixel_num_y[0]) det_MT
1220        Duplicate/O det_MT qTot_MT,qx_MT,qy_MT,qz_MT
1221       
1222        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_MB
1223        Make/O/D/N=(pixel_num_x[0],pixel_num_y[0]) det_MB
1224        Duplicate/O det_MB qTot_MB,qx_MB,qy_MB,qz_MB
1225
1226// BACK
1227// TODO: the detector dimensions need to be properly defined here...
1228//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Back
1229
1230        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B
1231        Make/O/D/N=(pixel_num_x[0],pixel_num_y[0]) det_B
1232        Duplicate/O det_B qTot_B,qx_B,qy_B,qz_B
1233
1234
1235////////////    FOR THE PANEL
1236
1237        SetDataFolder root:Packages:NIST:VSANS:VCALC
1238
1239        Make/O/D/N=2 fpx1,fpy1,mpx1,mpy1                // for display of the detector panels
1240        Make/O/D/N=2 fv_degX,fv_degY
1241
1242
1243// to fill in:
1244// values for always-visible items
1245        String/G gPresetPopStr = "F+M Ng0 Low Q;F+M Ng2 Mid Q;F+M Ng7 Mid Q;F+M Ng9 High Q;Converging Pinholes;Narrow Slit;White Beam;Graphite;Polarizer;"
1246        String/G gBinTypeStr = ksBinTypeStr
1247        Variable/G gBeamIntensity= 0
1248
1249        Variable/G gQmin_F,gQmax_F,gQmin_M,gQmax_M,gQmin_B,gQmax_B
1250        Variable/G gBeamDiam,gBeamStopDiam
1251        Variable/G gRealQMin
1252
1253// popup strings for each tab (then use the string in the panel)
1254// tab 0 - collimation
1255        String/G gMonochromatorType = "Velocity Selector;Graphite;White Beam;"
1256        String/G gSourceShape = "circular;rectangular;converging pinholes;"
1257        String/G gSourceDiam = "6.0 cm;"
1258        String/G gSourceDiam_0g = "0.75 cm;1.5 cm;3.0 cm;"              // values from John Mar 2018
1259        String/G gDeltaLambda = "0.12;"
1260       
1261// tab 1 - sample conditions
1262        String/G gTableLocation = "Changer;Stage;"
1263        String/G gSampleApertureShape = "circular;rectangular;converging pinholes;"
1264        String/G gSampleApertureDiam = "1.27;1.59;1.0;2.0;"
1265       
1266// tab 2
1267
1268// tab 3
1269
1270// tab 4 - back detector
1271        String/G gBackDetType = "1D;2D;"
1272
1273// tab 5
1274        String/G gModelFunctionType = "Debye;Sphere;Big Debye;Big Sphere;AgBeh;Vycor;Empty Cell;Blocked Beam;"
1275        gModelFunctionType += "Debye +;AgBeh +;Empty Cell +;"
1276
1277////////////////////
1278
1279
1280
1281// limits for detector travel? or are these limits part of the panel, hard-wired there
1282
1283
1284//      // for the panel
1285
1286        Variable/G gNg=0
1287//      Variable/G gOffset=0
1288        Variable/G gSamAp=1.27          //samAp diameter in cm
1289//      String/G gSourceApString = "1.43 cm;2.54 cm;3.81 cm;"
1290        String/G gApPopStr = "1/16\";1/8\";3/16\";1/4\";5/16\";3/8\";7/16\";1/2\";9/16\";5/8\";11/16\";3/4\";other;"
1291        Variable/G gSamApOther = 10             //non-standard aperture diameter, in mm
1292        Variable/G gUsingLenses = 0             //0=no lenses, 1=lenses(or prisms)
1293//      Variable/G gModelOffsetFactor = 1
1294//     
1295//      // for the MC simulation
1296//      Variable/G doSimulation =0              // == 1 if 1D simulated data, 0 if other from the checkbox
1297//      Variable/G gRanDateTime=datetime
1298//      Variable/G gImon = 10000
1299//      Variable/G gThick = 0.1
1300//      Variable/G gSig_incoh = 0.1
1301//      String/G gFuncStr = ""
1302//      Variable/G gR2 = 2.54/2
1303//      Variable/G gSamTrans=0.8                        //for 1D, default value
1304//      Variable/G gCntTime = 300
1305//      Variable/G gDoMonteCarlo = 0
1306//      Variable/G gUse_MC_XOP = 1                              //set to zero to use Igor code
1307//      Variable/G gBeamStopIn = 1                      //set to zero for beamstop out (transmission)
1308//      Variable/G gRawCounts = 0
1309//      Variable/G gSaveIndex = 100
1310//      String/G gSavePrefix = "SIMUL"
1311//      Variable/G gAutoSaveIndex = 100                 //a way to set the index for automated saves
1312//      String/G gAutoSaveLabel = ""                            //a way to set the "sample" label for automated saves
1313//      Make/O/D/N=10 results = 0
1314//      Make/O/T/N=10 results_desc = {"total X-section (1/cm)","SAS X-section (1/cm)","number that scatter","number that reach detector","avg # times scattered","fraction single coherent","fraction multiple coherent","fraction multiple scattered","fraction transmitted","detector counts w/beamstop"}
1315//
1316//      Variable/G g_1DTotCts = 0                       //summed counts (simulated)
1317//      Variable/G g_1DEstDetCR = 0             // estimated detector count rate
1318//      Variable/G g_1DFracScatt = 0            // fraction of beam captured on detector
1319//      Variable/G g_1DEstTrans = 0             // estimated transmission of sample
1320//      Variable/G g_1D_DoABS = 1
1321//      Variable/G g_1D_AddNoise = 1
1322//      Variable/G g_MultScattFraction=0
1323//      Variable/G g_detectorEff=0.75                   //average value for most wavelengths
1324//      Variable/G g_actSimTime = 0                             //for the save
1325//      Variable/G g_SimTimeWarn = 10                   //manually set to a very large value for scripted operation
1326//     
1327
1328//     
1329//      //for the fake dependency
1330//      Variable/G gTouched=0
1331//      Variable/G gCalculate=0
1332//      //for plotting
1333//      Variable/G gFreezeCount=1               //start the count at 1 to keep Jeff happy
1334//      Variable/G gDoTraceOffset=0             // (1==Yes, offset 2^n), 0==turn off the offset
1335
1336
1337
1338//
1339// instrument - specific dimensions
1340//
1341
1342//     
1343        Variable/G gInstrument = 6              // files (may) be tagged SA6 as the 6th SANS instrument
1344        Variable/G gS12 = 54.8
1345//      Variable/G d_det = 0.5
1346//      Variable/G a_pixel = 0.5
1347//      Variable/G del_r = 0.5
1348//      Variable/G det_width = 64.0
1349        Variable/G gLambda_t = 5.50
1350        Variable/G gL2r_lower = 132.3
1351        Variable/G gL2r_upper =  1317
1352        Variable/G gLambda_lower = 2.5
1353        Variable/G gLambda_upper = 20.0
1354        Variable/G gD_upper = 25.0
1355        Variable/G gBs_factor = 1.05
1356        Variable/G gT1 = 0.63
1357        Variable/G gT2 = 1.0
1358        Variable/G gT3 = 0.75
1359        Variable/G gL_gap = 100.0
1360        Variable/G gGuide_width = 6.0
1361        Variable/G gIdmax = 100.0
1362
1363//
1364//      //new values, from 11/2009 --- BeamFluxReport_2009.ifn
1365        Variable/G gPhi_0 = 2.42e13
1366        Variable/G gB = 0.0
1367        Variable/G gC = -0.0243
1368        Variable/G gGuide_loss = 0.924
1369//     
1370//      //fwhm values (new variables) (+3, 0, -3, calibrated 2009)
1371        Variable/G gFwhm_narrow = 0.109
1372        Variable/G gFwhm_mid = 0.125
1373        Variable/G gFwhm_wide = 0.236
1374//     
1375//      //source apertures (cm)
1376        Variable/G gA1_0_0 = 1.43
1377        Variable/G gA1_0_1 = 2.54
1378        Variable/G gA1_0_2 = 3.81
1379        Variable/G gA1_7_0 = 2.5                        // after the polarizer         
1380        Variable/G gA1_7_1 = 5.0
1381        Variable/G gA1_7_1 = 0.95               //
1382        Variable/G gA1_def = 5.00
1383//     
1384        SetDataFolder root:
1385end
1386
1387// set the global values for display
1388Function V_QMinMax_Back()
1389
1390        NVAR min_b = root:Packages:NIST:VSANS:VCALC:gQmin_B
1391        NVAR max_b = root:Packages:NIST:VSANS:VCALC:gQmax_B
1392
1393        String folderStr = "VCALC"
1394        String detStr = ""
1395
1396        String folderPath = "root:Packages:NIST:VSANS:"+folderStr
1397        String instPath = ":entry:instrument:detector_"
1398
1399        detStr = "B"
1400        WAVE qTot_B = $(folderPath+instPath+detStr+":qTot_"+detStr)
1401
1402        min_b = WaveMin(qTot_B)
1403        max_b = WaveMax(qTot_B)
1404
1405
1406        return(0)
1407end
1408
1409// set the global values for display
1410Function V_QMinMax_Middle()
1411
1412        NVAR min_m = root:Packages:NIST:VSANS:VCALC:gQmin_M
1413        NVAR max_m = root:Packages:NIST:VSANS:VCALC:gQmax_M
1414
1415        String folderStr = "VCALC"
1416        String detStr = ""
1417
1418        String folderPath = "root:Packages:NIST:VSANS:"+folderStr
1419        String instPath = ":entry:instrument:detector_"
1420
1421        detStr = "ML"
1422        WAVE qTot_ML = $(folderPath+instPath+detStr+":qTot_"+detStr)
1423
1424        detStr = "MR"
1425        WAVE qTot_MR = $(folderPath+instPath+detStr+":qTot_"+detStr)
1426
1427        detStr = "MT"
1428        WAVE qTot_MT = $(folderPath+instPath+detStr+":qTot_"+detStr)
1429
1430        detStr = "MB"
1431        WAVE qTot_MB = $(folderPath+instPath+detStr+":qTot_"+detStr)
1432
1433        min_m = min(WaveMin(qTot_ML),WaveMin(qTot_MT),WaveMin(qTot_MR),WaveMin(qTot_MB))
1434        max_m = max(WaveMax(qTot_ML),WaveMax(qTot_MT),WaveMax(qTot_MR),WaveMax(qTot_MB))
1435
1436
1437        return(0)
1438end
1439
1440// set the global values for display
1441Function V_QMinMax_Front()
1442
1443        NVAR min_f = root:Packages:NIST:VSANS:VCALC:gQmin_F
1444        NVAR max_f = root:Packages:NIST:VSANS:VCALC:gQmax_F
1445
1446        String folderStr = "VCALC"
1447        String detStr = ""
1448       
1449        String folderPath = "root:Packages:NIST:VSANS:"+folderStr
1450        String instPath = ":entry:instrument:detector_"
1451
1452        detStr = "FL"
1453        WAVE qTot_FL = $(folderPath+instPath+detStr+":qTot_"+detStr)
1454
1455        detStr = "FR"
1456        WAVE qTot_FR = $(folderPath+instPath+detStr+":qTot_"+detStr)
1457
1458        detStr = "FT"
1459        WAVE qTot_FT = $(folderPath+instPath+detStr+":qTot_"+detStr)
1460
1461        detStr = "FB"
1462        WAVE qTot_FB = $(folderPath+instPath+detStr+":qTot_"+detStr)
1463
1464        min_f = min(WaveMin(qTot_FL),WaveMin(qTot_FT),WaveMin(qTot_FR),WaveMin(qTot_FB))
1465        max_f = max(WaveMax(qTot_FL),WaveMax(qTot_FT),WaveMax(qTot_FR),WaveMax(qTot_FB))
1466
1467
1468        return(0)
1469end
1470
1471Function V_QMin_withBeamStop(detStr)
1472        String detStr
1473       
1474        NVAR val = root:Packages:NIST:VSANS:VCALC:gRealQMin
1475
1476        Variable BSDiam,SDD,two_theta,lambda,qMin
1477
1478        BSDiam = VC_beamstopDiam(detStr)
1479        SDD = VC_getSDD(detStr)
1480        lambda = VCALC_getWavelength()
1481       
1482        two_theta = atan(BSDiam/2/SDD)
1483        qMin = 4*pi/lambda*sin(two_theta/2)
1484               
1485        val = qMin
1486       
1487        return(0)
1488End
1489
1490
1491Function V_BeamDiamDisplay(direction, detStr)
1492        String direction
1493        String detStr
1494       
1495        NVAR val = root:Packages:NIST:VSANS:VCALC:gBeamDiam
1496
1497        val = VC_beamDiameter(direction, detStr)                //middle carriage, maximum extent, includes gravity
1498
1499        return(0)
1500End
1501
1502
1503// carrNum 1=front, 2=middle, 3=back
1504Function V_BeamStopDiamDisplay(detStr)
1505        String detStr
1506
1507        NVAR val = root:Packages:NIST:VSANS:VCALC:gBeamStopDiam
1508
1509        val = VC_beamstopDiam(detStr)/2.54              //return the value in inches
1510
1511        return(0)
1512End
1513       
1514               
1515       
Note: See TracBrowser for help on using the repository browser.