source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/VC_DetectorBinning_Q.ipf @ 1081

Last change on this file since 1081 was 1081, checked in by srkline, 5 years ago

additions to VCALC procedures to correctly account for panel motion (individual, not symmetric). Updated the plotting routines to all (mostly) pass through the same subroutines so that additional averaging modes will be easier to add.

File size: 53.4 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2
3
4//////////////////
5//
6// Procedures for:
7//
8//              Gathering information to calculate QxQyQz
9//              Filling the panels with Qtot, QxQyQz
10//              Filling the "data" with a model function
11//              Averaging the panels (independently) into I(Q)
12//              Plotting the 9 detector panels in 2D
13//              Plotting the 1D I(q) data depending on the panel combinations
14//
15//
16//  There are some things in the current circular averaging that don't make any sense
17//  and don't seem to really do anything at all, so i have decided to trim them out.
18//  1) subdividing pixels near the beam stop into 9 sub-pixels
19//  2) non-linear correction (only applies to Ordela)
20//
21//
22//  Do I separate out the circular, sector, rectangular, annular averaging into
23//   separate routines?
24//
25//
26//
27///////////////////
28
29
30
31
32Proc PlotFrontPanels()
33        fPlotFrontPanels()
34End
35
36//
37// Plot the front panels in 2D and 1D
38//              calcualate Q
39//              fill w/model data
40//              "shadow" the T/B detectors
41//              bin the data to I(q)
42//              draw I(q) graph
43//              draw 2D panel graph
44//
45// *** Call this function when front panels are adjusted, or wavelength, etc. changed
46//
47Function fPlotFrontPanels()
48
49        // space is allocated for all of the detectors and Q's on initialization
50        // calculate Qtot, qxqyqz arrays from geometry
51        VC_CalculateQFrontPanels()
52       
53        // fill the panels with fake sphere scattering data
54        // TODO: am I in the right data folder??
55//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
56
57        String folderStr = "VCALC"
58        String detStr = ""
59
60        String folderPath = "root:Packages:NIST:VSANS:"+folderStr
61        String instPath = ":entry:instrument:detector_"
62
63        detStr = "FL"
64        WAVE det_FL = $(folderPath+instPath+detStr+":det_"+detStr)     
65        WAVE qTot_FL = $(folderPath+instPath+detStr+":qTot_"+detStr)
66       
67        detStr = "FR"
68        WAVE det_FR = $(folderPath+instPath+detStr+":det_"+detStr)     
69        WAVE qTot_FR = $(folderPath+instPath+detStr+":qTot_"+detStr)
70//      WAVE qTot_FR = $("root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FR:qTot_FR")
71       
72        detStr = "FT"
73        WAVE det_FT = $(folderPath+instPath+detStr+":det_"+detStr)     
74        WAVE qTot_FT = $(folderPath+instPath+detStr+":qTot_"+detStr)
75       
76        detStr = "FB"
77        WAVE det_FB = $(folderPath+instPath+detStr+":det_"+detStr)     
78        WAVE qTot_FB = $(folderPath+instPath+detStr+":qTot_"+detStr)
79
80       
81       
82        FillPanel_wModelData(det_FL,qTot_FL,"FL")
83        FillPanel_wModelData(det_FR,qTot_FR,"FR")
84        FillPanel_wModelData(det_FT,qTot_FT,"FT")
85        FillPanel_wModelData(det_FB,qTot_FB,"FB")
86
87        SetDataFolder root:
88               
89        // set any "shadowed" area of the T/B detectors to NaN to get a realistic
90        // view of how much of the detectors are actually collecting data
91        // -- I can get the separation L/R from the panel - only this "open" width is visible.
92        //TODO - make this a proper shadow - TB extent of the LR panels matters too, not just the LR separation
93        VC_SetShadow_TopBottom("VCALC","FT")            // TODO: -- be sure the data folder is properly set (within the function...)
94        VC_SetShadow_TopBottom("VCALC","FB")
95       
96        // do the q-binning for each of the panels to get I(Q)
97        BinAllFrontPanels()
98
99
100        // plot the results
101        String type = "VCALC"
102        String str,winStr="VCALC#Panels_IQ",workTypeStr,popStr
103        workTypeStr = "root:Packages:NIST:VSANS:"+type
104
105        ControlInfo/W=VCALC popup_b
106        popStr = S_Value                //
107       
108        sprintf str,"(\"%s\",%d,\"%s\")",workTypeStr,V_BinTypeStr2Num(popStr),winStr
109
110        Execute ("V_Front_IQ_Graph"+str)
111               
112//      Execute "Front_IQ_Graph()"
113
114        FrontPanels_AsQ()
115       
116        return(0)
117End
118
119
120// works for Left, works for Right... works for T/B too.
121//
122// - TODO: be sure that the Q's are calculated correctly even when the beam is off of the
123//     detector, and on different sides of the detector (or T/B) - since it will be in a different
124//     relative postion to 0,0 on the detector. If the postions are symmetric, then the Q's should be identical.
125//     --- test this...
126// TODO -- be sure I'm in the right data folder. nothing is set correctly right now
127//
128// TODO: make all detector parameters global, not hard-wired
129//
130//
131// --- Panels are all allocated in the initialization. Here, only the q-values are calculated
132//     when anything changes
133//
134// TODO
135// NOTE -- this is VCALC ONLY. data is not referenced for hdf here, and data is rescaled based on VCALC assumptions
136//
137Function VC_CalculateQFrontPanels()
138
139        Variable xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,nPix_X,nPix_Y
140        Variable F_L_sep,F_R_sep,F_T_sep,F_B_sep,F_sdd_setback
141
142        String folderPath = "root:Packages:NIST:VSANS:VCALC"
143        String instPath = ":entry:instrument:detector_"
144        String detStr=""
145
146// get the values from the panel + constants   
147        F_L_sep = VCALC_getPanelTranslation("FL")
148        F_R_sep = VCALC_getPanelTranslation("FR")
149        F_T_sep = VCALC_getPanelTranslation("FT")
150        F_B_sep = VCALC_getPanelTranslation("FB")
151       
152        SDD = VCALC_getSDD("FL")                //nominal SDD [cm] - need offset for TB
153        lam = VCALC_getWavelength()
154
155//separations are in cm --
156//      F_LR_sep /= 10
157//      F_TB_sep /= 10
158// TODO - I'm treating the separation as the TOTAL width - so the difference
159//      from the "center" to the edge is 1/2 of the separation
160
161// TODO (make the N along the tube length a variable, since this can be reset @ acquisition)
162
163        F_sdd_setback = VCALC_getTopBottomSDDSetback("FT")      //T/B are 41 cm farther back  //TODO: make all detector parameters global, not hard-wired
164
165// detector data to bin
166//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
167        Wave det_FL = $(folderPath+instPath+"FL"+":det_FL")
168        Wave det_FR = $(folderPath+instPath+"FR"+":det_FR")             // these are (48,128)           (nominal, may change)
169
170        Wave det_FT = $(folderPath+instPath+"FT"+":det_FT")
171        Wave det_FB = $(folderPath+instPath+"FB"+":det_FB")             // these are (128,48)
172
173//FRONT/LEFT
174        detStr = "FL"
175        Wave qTot_FL = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
176        Wave qx_FL = $(folderPath+instPath+detStr+":qx_"+detStr)
177        Wave qy_FL = $(folderPath+instPath+detStr+":qy_"+detStr)       
178        Wave qz_FL = $(folderPath+instPath+detStr+":qz_"+detStr)       
179
180        qTot_FL = 0
181        qx_FL = 0
182        qy_FL = 0
183        qz_FL = 0       
184       
185// TODO - these are to be set from globals, not hard-wired. N and pixelSixze will be known (or pre-measured)
186// pixel sizes are in cm
187        pixSizeX = VCALC_getPixSizeX("FL")
188        pixSizeY = VCALC_getPixSizeY("FL")
189//      pixSizeX = 0.8                  // 0.8 cm/pixel along width
190//      pixSizeY = 0.4                  // approx 0.4 cm/pixel along length
191        nPix_X = VCALC_get_nPix_X("FL")
192        nPix_Y = VCALC_get_nPix_Y("FL")
193
194        if(kBCTR_CM)
195                xCtr = 0
196                yCtr = 0                        //values in cm
197        else   
198                xCtr = nPix_X-(F_L_sep/pixSizeX)                // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
199                yCtr = nPix_Y/2
200        endif
201        //put these  beam center values into the local folder
202        V_putDet_beam_center_x("VCALC","FL",xCtr)
203        V_putDet_beam_center_y("VCALC","FL",yCtr)
204       
205//      VC_Detector_2Q(det_FL,qTot_FL,qx_FL,qy_FL,qz_FL,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
206        VC_Detector_2Q_NonLin(det_FL,qTot_FL,qx_FL,qy_FL,qz_FL,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,"FL")
207        Print "xy for FL = ",xCtr,yCtr
208       
209        //set the wave scaling for the detector image so that it can be plotted in q-space
210        // TODO: this is only approximate - since the left "edge" is not the same from top to bottom, so I crudely
211        // take the middle value. At very small angles, OK, at 1m, this is a crummy approximation.
212        // since qTot is magnitude only, I need to put in the (-ve)
213        SetScale/I x WaveMin(qx_FL),WaveMax(qx_FL),"", det_FL           //this sets the left and right ends of the data scaling
214        SetScale/I y WaveMin(qy_FL),WaveMax(qy_FL),"", det_FL
215//////////////////
216
217//FRONT/RIGHT
218//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
219        detStr = "FR"
220        Wave qTot_FR = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
221        Wave qx_FR = $(folderPath+instPath+detStr+":qx_"+detStr)
222        Wave qy_FR = $(folderPath+instPath+detStr+":qy_"+detStr)       
223        Wave qz_FR = $(folderPath+instPath+detStr+":qz_"+detStr)       
224       
225        qTot_FR = 0
226        qx_FR = 0
227        qy_FR = 0
228        qz_FR = 0
229
230// TODO - these are to be set from globals, not hard-wired
231// pixel sizes are in cm
232        pixSizeX = VCALC_getPixSizeX("FR")
233        pixSizeY = VCALC_getPixSizeY("FR")
234        nPix_X = VCALC_get_nPix_X("FR")
235        nPix_Y = VCALC_get_nPix_Y("FR")
236
237        if(kBCTR_CM)
238                xCtr = 0
239                yCtr = 0                        //values in cm
240        else   
241                xCtr = -(F_R_sep/pixSizeX)-1           
242                yCtr = nPix_Y/2
243        endif
244
245        //put these  beam center values into the local folder
246        V_putDet_beam_center_x("VCALC","FR",xCtr)
247        V_putDet_beam_center_y("VCALC","FR",yCtr)       
248//      VC_Detector_2Q(det_FR,qTot_FR,qx_FR,qy_FR,qz_FR,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
249        VC_Detector_2Q_NonLin(det_FR,qTot_FR,qx_FR,qy_FR,qz_FR,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,"FR")
250
251//      Print "xy for FR = ",xCtr,yCtr
252        SetScale/I x WaveMin(qx_FR),WaveMax(qx_FR),"", det_FR           //this sets the left and right ends of the data scaling
253        SetScale/I y WaveMin(qy_FR),WaveMax(qy_FR),"", det_FR
254/////////////////
255
256//FRONT/TOP
257//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
258        detStr = "FT"
259        Wave qTot_FT = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
260        Wave qx_FT = $(folderPath+instPath+detStr+":qx_"+detStr)
261        Wave qy_FT = $(folderPath+instPath+detStr+":qy_"+detStr)       
262        Wave qz_FT = $(folderPath+instPath+detStr+":qz_"+detStr)       
263
264        qTot_FT = 0
265        qx_FT = 0
266        qy_FT = 0
267        qz_FT = 0
268
269// TODO - these are to be set from globals, not hard-wired
270// pixel sizes are in cm
271        pixSizeX = VCALC_getPixSizeX("FT")
272        pixSizeY = VCALC_getPixSizeY("FT")
273        nPix_X = VCALC_get_nPix_X("FT")
274        nPix_Y = VCALC_get_nPix_Y("FT")
275
276        if(kBCTR_CM)
277                xCtr = 0
278                yCtr = 0                        //values in cm
279        else   
280                xCtr = nPix_X/2
281                yCtr = -(F_T_sep/2/pixSizeY)-1
282        endif   
283
284                //put these  beam center values into the local folder
285        V_putDet_beam_center_x("VCALC","FT",xCtr)
286        V_putDet_beam_center_y("VCALC","FT",yCtr)
287         
288        // global sdd_offset is in (mm), convert to meters here for the Q-calculation
289//      VC_Detector_2Q(det_FT,qTot_FT,qx_FT,qy_FT,qz_FT,xCtr,yCtr,sdd+F_sdd_offset/1000,lam,pixSizeX,pixSizeY)
290        VC_Detector_2Q_NonLin(det_FT,qTot_FT,qx_FT,qy_FT,qz_FT,xCtr,yCtr,sdd+F_sdd_setback,lam,pixSizeX,pixSizeY,"FT")
291
292//      Print "xy for FT = ",xCtr,yCtr
293        SetScale/I x WaveMin(qx_FT),WaveMax(qx_FT),"", det_FT           //this sets the left and right ends of the data scaling
294        SetScale/I y WaveMin(qy_FT),WaveMax(qy_FT),"", det_FT
295//////////////////
296
297//FRONT/BOTTOM
298//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
299        detStr = "FB"
300        Wave qTot_FB = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
301        Wave qx_FB = $(folderPath+instPath+detStr+":qx_"+detStr)
302        Wave qy_FB = $(folderPath+instPath+detStr+":qy_"+detStr)       
303        Wave qz_FB = $(folderPath+instPath+detStr+":qz_"+detStr)       
304
305        qTot_FB = 0
306        qx_FB = 0
307        qy_FB = 0
308        qz_FB = 0
309
310// TODO - these are to be set from globals, not hard-wired
311// pixel sizes are in cm
312        pixSizeX = VCALC_getPixSizeX("FB")
313        pixSizeY = VCALC_getPixSizeY("FB")
314        nPix_X = VCALC_get_nPix_X("FB")
315        nPix_Y = VCALC_get_nPix_Y("FB")
316
317        if(kBCTR_CM)
318                xCtr = 0
319                yCtr = 0                        //values in cm
320        else   
321                xCtr = nPix_X/2
322                yCtr = nPix_Y+(F_B_sep/2/pixSizeY)              // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
323        endif   
324                       
325        //put these  beam center values into the local folder
326        V_putDet_beam_center_x("VCALC","FB",xCtr)
327        V_putDet_beam_center_y("VCALC","FB",yCtr)
328       
329        // global sdd_offset is in (mm), convert to meters here for the Q-calculation
330//      VC_Detector_2Q(det_FB,qTot_FB,qx_FB,qy_FB,qz_FB,xCtr,yCtr,sdd+F_sdd_offset/1000,lam,pixSizeX,pixSizeY)
331        VC_Detector_2Q_NonLin(det_FB,qTot_FB,qx_FB,qy_FB,qz_FB,xCtr,yCtr,sdd+F_sdd_setback,lam,pixSizeX,pixSizeY,"FB")
332
333//      Print "xy for FB = ",xCtr,yCtr
334        SetScale/I x WaveMin(qx_FB),WaveMax(qx_FB),"", det_FB           //this sets the left and right ends of the data scaling
335        SetScale/I y WaveMin(qy_FB),WaveMax(qy_FB),"", det_FB
336/////////////////
337
338        SetDataFolder root:
339               
340        return(0)
341End
342
343
344// TODO - this doesn't quite mask things out as they should be (too much is masked L/R of center)
345// and the outer edges of the detector are masked even if the TB panels extend past the TB of the LR panels.
346// ? skip the masking? but then I bin the detector data directly to get I(q), skipping the masked NaN values...
347//
348Function VC_SetShadow_TopBottom(folderStr,type)
349        String folderStr,type
350       
351        Variable L_sep,R_sep,nPix_L,nPix_R,xCtr,ii,jj,numCol,pixSizeX,pixSizeY,nPix_X,nPix_Y
352
353/// !! type passed in will be FT, FB, MT, MB, so I can't ask for the panel separation -- or I'll get the TB separation...
354// translation in [cm]
355        if(cmpstr("F",type[0]) == 0)            // FT or FB passed in
356                L_sep = VCALC_getPanelTranslation("FL")
357                R_sep = VCALC_getPanelTranslation("FR")
358        else
359                L_sep = VCALC_getPanelTranslation("ML")
360                R_sep = VCALC_getPanelTranslation("MR")
361        endif
362
363
364//detector data
365        Wave det = $("root:Packages:NIST:VSANS:"+folderStr+":entry:instrument:detector_"+type+":det_"+type)
366
367// TODO - these are to be set from globals, not hard-wired
368// pixel sizes are in cm for T/B detector
369// TODO - the "FT" check is hard wired for FRONT -- get rid of this...
370
371        pixSizeX = VCALC_getPixSizeX(type)
372        pixSizeY = VCALC_getPixSizeY(type)
373
374        nPix_X = VCALC_get_nPix_X(type)
375        nPix_Y = VCALC_get_nPix_Y(type)
376       
377        //TODO -- get this from a global
378        xCtr = nPix_X/2
379        nPix_L = trunc(abs(L_sep)/pixSizeX)             // approx # of pixels Left of center that are not obscured by L/R panels
380        nPix_R = trunc(abs(R_sep)/pixSizeX)             // approx # of pixels Right of center that are not obscured by L/R panels
381       
382        numCol = DimSize(det,0)         // x dim (columns)
383        for(ii=0;ii<(xCtr-nPix_L-4);ii+=1)
384                det[ii][] = NaN
385        endfor
386        for(ii=(xCtr+nPix_R+6);ii<numCol;ii+=1)
387                det[ii][] = NaN
388        endfor
389       
390        return(0)
391end
392
393
394// After the panels have been calculated and rescaled in terms of Q, and filled with simulated data
395// they can be appended to the subwindow. If they are already there, the axes and coloring
396// are rescaled as needed
397//
398Function FrontPanels_AsQ()
399
400        String frontStr = "root:Packages:NIST:VSANS:VCALC:entry:instrument:"
401//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
402        SetDataFolder $(frontStr+"detector_FB")
403        Wave det_FB = det_FB
404        SetDataFolder $(frontStr+"detector_FT")
405        Wave det_FT = det_FT
406        SetDataFolder $(frontStr+"detector_FL")
407        Wave det_FL = det_FL
408        SetDataFolder $(frontStr+"detector_FR")
409        Wave det_FR = det_FR
410       
411        CheckDisplayed /W=VCALC#Panels_Q det_FB
412        if(V_flag == 0)
413                AppendImage/W=VCALC#Panels_Q det_FB
414                ModifyImage/W=VCALC#Panels_Q det_FB ctab= {*,*,ColdWarm,0}
415                AppendImage/W=VCALC#Panels_Q det_FT
416                ModifyImage/W=VCALC#Panels_Q det_FT ctab= {*,*,ColdWarm,0}
417                AppendImage/W=VCALC#Panels_Q det_FL
418                ModifyImage/W=VCALC#Panels_Q det_FL ctab= {*,*,ColdWarm,0}
419                AppendImage/W=VCALC#Panels_Q det_FR
420                ModifyImage/W=VCALC#Panels_Q det_FR ctab= {*,*,ColdWarm,0}
421        endif
422
423        Variable dval
424        ControlInfo/W=VCALC setVar_b
425        dval = V_Value
426
427        SetAxis/W=VCALC#Panels_Q left -dval,dval
428        SetAxis/W=VCALC#Panels_Q bottom -dval,dval     
429
430        ControlInfo/W=VCALC check_0a
431// V_Value == 1 if checked
432        ModifyImage/W=VCALC#Panels_Q det_FB log=V_Value
433        ModifyImage/W=VCALC#Panels_Q det_FT log=V_Value
434        ModifyImage/W=VCALC#Panels_Q det_FL log=V_Value
435        ModifyImage/W=VCALC#Panels_Q det_FR log=V_Value
436
437
438        SetDataFolder root:
439       
440EndMacro
441
442
443
444
445
446
447//
448// these routines bin the 2D q data to 1D I(q). Currently the Qtot is magnitude only, no sign (since
449// it's being binned to I(Q), having a sign makes no sense. If you want the sign, work from qxqyqz
450//
451// first - the DeltaQ step is set as the smaller detector resolution (along tube)
452//       which is different for LR / TB geometry. This is not set in stone.
453//
454// second - each detector is binned separately
455//
456// -- like the routines in CircSectAve, start with 500 points, and trim after binning is done.
457//      you'l end up with < 200 points.
458//
459// the results are in iBin_qxqy, qBin_qxqy, and eBin_qxqy, in the folder passed
460//
461// TODO -- this is a (partial) duplicated routine... I need to
462// **** COPY the logic from V_QBinAllPanels_Circular every time I add a new bin type
463//
464// -- see also BinAllMiddlePanels()
465// -- BinAllBackPanels()
466//
467Function BinAllFrontPanels()
468
469        SetDeltaQ("VCALC","FL")
470        SetDeltaQ("VCALC","FR")
471        SetDeltaQ("VCALC","FT")
472        SetDeltaQ("VCALC","FB")
473
474        Variable binType       
475        ControlInfo/W=VCALC popup_b
476        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
477
478        String folderStr = "VCALC"
479       
480        switch(binType)
481                case 1:
482                        VC_fDoBinning_QxQy2D(folderStr,"FL")
483                        VC_fDoBinning_QxQy2D(folderStr,"FR")
484                        VC_fDoBinning_QxQy2D(folderStr,"FT")
485                        VC_fDoBinning_QxQy2D(folderStr,"FB")
486//                      VC_fDoBinning_QxQy2D(folderStr,"ML")
487//                      VC_fDoBinning_QxQy2D(folderStr,"MR")
488//                      VC_fDoBinning_QxQy2D(folderStr,"MT")
489//                      VC_fDoBinning_QxQy2D(folderStr,"MB")                   
490//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
491
492                        break
493                case 2:
494                        VC_fDoBinning_QxQy2D(folderStr,"FLR")
495                        VC_fDoBinning_QxQy2D(folderStr,"FTB")
496//                      VC_fDoBinning_QxQy2D(folderStr,"MLR")
497//                      VC_fDoBinning_QxQy2D(folderStr,"MTB")
498//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
499
500                        break
501                case 3:
502//                      VC_fDoBinning_QxQy2D(folderStr,"MLRTB")
503                        VC_fDoBinning_QxQy2D(folderStr,"FLRTB")
504//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
505                       
506                        break
507                case 4:                         /// this is for a tall, narrow slit mode       
508                        VC_fBinDetector_byRows(folderStr,"FL")
509                        VC_fBinDetector_byRows(folderStr,"FR")
510//                      VC_fBinDetector_byRows(folderStr,"ML")
511//                      VC_fBinDetector_byRows(folderStr,"MR")
512//                      VC_fBinDetector_byRows(folderStr,"B")
513
514                        break
515                case 5:
516                        VC_fDoBinning_QxQy2D(folderStr,"FTB")
517                        VC_fDoBinning_QxQy2D(folderStr,"FLR")
518//                      VC_fDoBinning_QxQy2D(folderStr,"MLRTB")
519//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
520               
521                        break
522                case 6:
523                        VC_fDoBinning_QxQy2D(folderStr,"FLRTB")
524//                      VC_fDoBinning_QxQy2D(folderStr,"MLR")
525//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
526               
527                        break
528                case 7:
529                        VC_fDoBinning_QxQy2D(folderStr,"FTB")
530                        VC_fDoBinning_QxQy2D(folderStr,"FLR")
531//                      VC_fDoBinning_QxQy2D(folderStr,"MLR")
532//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
533               
534                        break
535                       
536                default:
537                        Abort "Binning mode not found in BinAllFrontPanels "// when no case matches     
538        endswitch
539       
540
541//      if(binType == 1)
542//              VC_BinQxQy_to_1D("VCALC","FL")
543//              VC_BinQxQy_to_1D("VCALC","FR")
544//              VC_BinQxQy_to_1D("VCALC","FT")
545//              VC_BinQxQy_to_1D("VCALC","FB")
546//      endif
547//     
548//      if(binType == 2)       
549//              VC_BinQxQy_to_1D("VCALC","FLR")
550//              VC_BinQxQy_to_1D("VCALC","FTB")
551//      endif
552//
553//      if(binType == 3)
554//              VC_BinQxQy_to_1D("VCALC","FLRTB")
555//      endif
556//
557//// TODO -- this is only a temporary fix for slit mode
558//      if(binType == 4)
559//              /// this is for a tall, narrow slit mode       
560//              VC_fBinDetector_byRows("VCALC","FL")
561//              VC_fBinDetector_byRows("VCALC","FR")
562//              VC_fBinDetector_byRows("VCALC","FT")
563//              VC_fBinDetector_byRows("VCALC","FB")
564//      endif
565               
566End
567
568
569
570
571
572
573
574Proc PlotMiddlePanels()
575        fPlotMiddlePanels()
576End
577
578// to plot I(q) for the 4 Middle panels
579//
580// *** Call this function when Middle panels are adjusted, or wavelength, etc. changed
581//
582Function fPlotMiddlePanels()
583
584        // space is allocated for all of the detectors and Q's on initialization
585        // calculate Qtot, qxqyqz arrays from geometry
586        VC_CalculateQMiddlePanels()
587       
588        // fill the panels with fake sphere scattering data
589        // TODO: am I in the right data folder??
590//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
591
592        String folderStr = "VCALC"
593        String detStr = ""
594
595        String folderPath = "root:Packages:NIST:VSANS:"+folderStr
596        String instPath = ":entry:instrument:detector_"
597
598        detStr = "ML"
599        WAVE det_ML = $(folderPath+instPath+detStr+":det_"+detStr)     
600        WAVE qTot_ML = $(folderPath+instPath+detStr+":qTot_"+detStr)
601
602        detStr = "MR"
603        WAVE det_MR = $(folderPath+instPath+detStr+":det_"+detStr)     
604        WAVE qTot_MR = $(folderPath+instPath+detStr+":qTot_"+detStr)
605
606        detStr = "MT"
607        WAVE det_MT = $(folderPath+instPath+detStr+":det_"+detStr)     
608        WAVE qTot_MT = $(folderPath+instPath+detStr+":qTot_"+detStr)
609
610        detStr = "MB"
611        WAVE det_MB = $(folderPath+instPath+detStr+":det_"+detStr)     
612        WAVE qTot_MB = $(folderPath+instPath+detStr+":qTot_"+detStr)
613
614        FillPanel_wModelData(det_ML,qTot_ML,"ML")
615        FillPanel_wModelData(det_MR,qTot_MR,"MR")
616        FillPanel_wModelData(det_MT,qTot_MT,"MT")
617        FillPanel_wModelData(det_MB,qTot_MB,"MB")                       
618
619        SetDataFolder root:
620               
621        // set any "shadowed" area of the T/B detectors to NaN to get a realitic
622        // view of how much of the detectors are actually collecting data
623        // -- I can get the separation L/R from the panel - only this "open" width is visible.
624        VC_SetShadow_TopBottom("VCALC","MT")            // TODO: -- be sure the data folder is properly set (within the function...)
625        VC_SetShadow_TopBottom("VCALC","MB")
626       
627        // do the q-binning for each of the panels to get I(Q)
628        BinAllMiddlePanels()
629
630        // plot the results
631        String type = "VCALC"
632        String str,winStr="VCALC#Panels_IQ",workTypeStr,popStr
633        workTypeStr = "root:Packages:NIST:VSANS:"+type
634
635        ControlInfo/W=VCALC popup_b
636        popStr = S_Value                //
637       
638        sprintf str,"(\"%s\",%d,\"%s\")",workTypeStr,V_BinTypeStr2Num(popStr),winStr
639
640        Execute ("V_Middle_IQ_Graph"+str)
641               
642
643        // plot the results
644//      Execute "Middle_IQ_Graph()"
645
646
647        MiddlePanels_AsQ()
648       
649        return(0)
650End
651
652// works for Left, works for Right... works for T/B too.
653//
654// - TODO: be sure that the Q's are calculated correctly even when the beam is off of the
655//     detector, and on different sides of the detector (or T/B) - since it will be in a different
656//     relative postion to 0,0 on the detector. If the postions are symmetric, then the Q's should be identical.
657//     --- test this...
658// TODO -- be sure I'm in the right data folder. nothing is set correctly right now
659//
660// TODO: make all detector parameters global, not hard-wired
661//
662//
663// --- Panels are all allocated in the initialization. Here, only the q-values are calculated
664//     when anything changes
665//
666Function VC_CalculateQMiddlePanels()
667
668        Variable xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,nPix_X,nPix_Y
669        Variable M_L_sep,M_R_sep,M_T_sep,M_B_sep, M_sdd_setback
670
671
672        String folderPath = "root:Packages:NIST:VSANS:VCALC"
673        String instPath = ":entry:instrument:detector_"
674        String detStr=""
675       
676        M_L_sep = VCALC_getPanelTranslation("ML")
677        M_R_sep = VCALC_getPanelTranslation("MR")
678        M_T_sep = VCALC_getPanelTranslation("MT")
679        M_B_sep = VCALC_getPanelTranslation("MB")
680       
681        SDD = VCALC_getSDD("ML")                //nominal SDD [cm] - need offset for TB
682        lam = VCALC_getWavelength()
683
684//separations are in cm -- need to watch the units, convert to cm
685//      M_LR_sep /= 10
686//      M_TB_sep /= 10
687// TODO - I'm treating the separation as the TOTAL width - so the difference
688//      from the "center" to the edge is 1/2 of the separation
689
690// TODO (make the N along the tube length a variable, since this can be reset @ acquisition)
691        M_sdd_setback = VCALC_getTopBottomSDDSetback("MT")      //T/B are 41 cm farther back  //TODO: make all detector parameters global, not hard-wired
692
693
694//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
695        Wave det_ML = $(folderPath+instPath+"ML"+":det_ML")
696        Wave det_MR = $(folderPath+instPath+"MR"+":det_MR")             // these are (48,128)           (nominal, may change)
697
698        Wave det_MT = $(folderPath+instPath+"MT"+":det_MT")
699        Wave det_MB = $(folderPath+instPath+"MB"+":det_MB")             // these are (128,48)
700
701//Middle/LEFT
702        detStr = "ML"
703        Wave qTot_ML = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
704        Wave qx_ML = $(folderPath+instPath+detStr+":qx_"+detStr)
705        Wave qy_ML = $(folderPath+instPath+detStr+":qy_"+detStr)       
706        Wave qz_ML = $(folderPath+instPath+detStr+":qz_"+detStr)       
707       
708        qTot_ML = 0
709        qx_ML = 0
710        qy_ML = 0
711        qz_ML = 0       
712       
713// TODO - these are to be set from globals, not hard-wired. N and pixelSixze will be known (or pre-measured)
714// pixel sizes are in cm
715        pixSizeX = VCALC_getPixSizeX("ML")
716        pixSizeY = VCALC_getPixSizeY("ML")
717        nPix_X = VCALC_get_nPix_X("ML")
718        nPix_Y = VCALC_get_nPix_Y("ML")
719
720        if(kBCTR_CM)
721                xCtr = 0
722                yCtr = 0                        //values in cm
723        else   
724                xCtr = nPix_X+(M_L_sep/pixSizeX)                // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
725                yCtr = nPix_Y/2
726        endif           
727
728                //put these  beam center values into the local folder
729        V_putDet_beam_center_x("VCALC","ML",xCtr)
730        V_putDet_beam_center_y("VCALC","ML",yCtr)
731       
732//      VC_Detector_2Q(det_ML,qTot_ML,qx_ML,qy_ML,qz_ML,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
733        VC_Detector_2Q_NonLin(det_ML,qTot_ML,qx_ML,qy_ML,qz_ML,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,"ML")
734
735//      Print "xy for ML = ",xCtr,yCtr
736       
737        //set the wave scaling for the detector image so that it can be plotted in q-space
738        // TODO: this is only approximate - since the left "edge" is not the same from top to bottom, so I crudely
739        // take the middle value. At very small angles, OK, at 1m, this is a crummy approximation.
740        // since qTot is magnitude only, I need to put in the (-ve)
741        SetScale/I x WaveMin(qx_ML),WaveMax(qx_ML),"", det_ML           //this sets the left and right ends of the data scaling
742        SetScale/I y WaveMin(qy_ML),WaveMax(qy_ML),"", det_ML
743       
744//////////////////
745
746//Middle/RIGHT
747//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
748        detStr = "MR"
749        Wave qTot_MR = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
750        Wave qx_MR = $(folderPath+instPath+detStr+":qx_"+detStr)
751        Wave qy_MR = $(folderPath+instPath+detStr+":qy_"+detStr)       
752        Wave qz_MR = $(folderPath+instPath+detStr+":qz_"+detStr)
753       
754        qTot_MR = 0
755        qx_MR = 0
756        qy_MR = 0
757        qz_MR = 0
758
759// TODO - these are to be set from globals, not hard-wired
760// pixel sizes are in cm
761        pixSizeX = VCALC_getPixSizeX("MR")
762        pixSizeY = VCALC_getPixSizeY("MR")
763
764        nPix_X = VCALC_get_nPix_X("MR")
765        nPix_Y = VCALC_get_nPix_Y("MR")
766
767        if(kBCTR_CM)
768                xCtr = 0
769                yCtr = 0                        //values in cm
770        else   
771                xCtr = -(M_R_sep/pixSizeX)-1           
772                yCtr = nPix_Y/2
773        endif   
774               
775
776                //put these  beam center values into the local folder
777        V_putDet_beam_center_x("VCALC","MR",xCtr)
778        V_putDet_beam_center_y("VCALC","MR",yCtr)
779       
780//      VC_Detector_2Q(det_MR,qTot_MR,qx_MR,qy_MR,qz_MR,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
781        VC_Detector_2Q_NonLin(det_MR,qTot_MR,qx_MR,qy_MR,qz_MR,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,"MR")
782
783//      Print "xy for MR = ",xCtr,yCtr
784        SetScale/I x WaveMin(qx_MR),WaveMax(qx_MR),"", det_MR           //this sets the left and right ends of the data scaling
785        SetScale/I y WaveMin(qy_MR),WaveMax(qy_MR),"", det_MR
786/////////////////
787
788//Middle/TOP
789//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
790        detStr = "MT"
791        Wave qTot_MT = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
792        Wave qx_MT = $(folderPath+instPath+detStr+":qx_"+detStr)
793        Wave qy_MT = $(folderPath+instPath+detStr+":qy_"+detStr)       
794        Wave qz_MT = $(folderPath+instPath+detStr+":qz_"+detStr)
795
796        qTot_MT = 0
797        qx_MT = 0
798        qy_MT = 0
799        qz_MT = 0
800
801// TODO - these are to be set from globals, not hard-wired
802// pixel sizes are in cm
803        pixSizeX = VCALC_getPixSizeX("MT")
804        pixSizeY = VCALC_getPixSizeY("MT")
805        nPix_X = VCALC_get_nPix_X("MT")
806        nPix_Y = VCALC_get_nPix_Y("MT")
807
808        if(kBCTR_CM)
809                xCtr = 0
810                yCtr = 0                        //values in cm
811        else   
812                xCtr = nPix_X/2
813                yCtr = -(M_T_sep/pixSizeY)-1
814        endif
815               
816
817                //put these  beam center values into the local folder
818        V_putDet_beam_center_x("VCALC","MT",xCtr)
819        V_putDet_beam_center_y("VCALC","MT",yCtr)
820       
821        // global sdd_offset is in (mm), convert to meters here for the Q-calculation 
822//      VC_Detector_2Q(det_MT,qTot_MT,qx_MT,qy_MT,qz_MT,xCtr,yCtr,sdd+M_sdd_offset/1000,lam,pixSizeX,pixSizeY)
823        VC_Detector_2Q_NonLin(det_MT,qTot_MT,qx_MT,qy_MT,qz_MT,xCtr,yCtr,sdd+M_sdd_setback,lam,pixSizeX,pixSizeY,"MT")
824
825//      Print "xy for MT = ",xCtr,yCtr
826        SetScale/I x WaveMin(qx_MT),WaveMax(qx_MT),"", det_MT           //this sets the left and right ends of the data scaling
827        SetScale/I y WaveMin(qy_MT),WaveMax(qy_MT),"", det_MT
828//////////////////
829
830//Middle/BOTTOM
831//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
832        detStr = "MB"
833        Wave qTot_MB = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
834        Wave qx_MB = $(folderPath+instPath+detStr+":qx_"+detStr)
835        Wave qy_MB = $(folderPath+instPath+detStr+":qy_"+detStr)       
836        Wave qz_MB = $(folderPath+instPath+detStr+":qz_"+detStr)
837
838        qTot_MB = 0
839        qx_MB = 0
840        qy_MB = 0
841        qz_MB = 0
842
843// TODO - these are to be set from globals, not hard-wired
844// pixel sizes are in cm
845        pixSizeX = VCALC_getPixSizeX("MB")
846        pixSizeY = VCALC_getPixSizeY("MB")
847        nPix_X = VCALC_get_nPix_X("MB")
848        nPix_Y = VCALC_get_nPix_Y("MB")
849
850        if(kBCTR_CM)
851                xCtr = 0
852                yCtr = 0                        //values in cm
853        else   
854                xCtr = nPix_X/2
855                yCtr = nPix_Y+(M_B_sep/pixSizeY)                // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
856        endif           
857
858        //put these  beam center values into the local folder
859        V_putDet_beam_center_x("VCALC","MB",xCtr)
860        V_putDet_beam_center_y("VCALC","MB",yCtr)
861       
862                // global sdd_offset is in (mm), convert to meters here for the Q-calculation
863//      VC_Detector_2Q(det_MB,qTot_MB,qx_MB,qy_MB,qz_MB,xCtr,yCtr,sdd+M_sdd_offset/1000,lam,pixSizeX,pixSizeY)
864        VC_Detector_2Q_NonLin(det_MB,qTot_MB,qx_MB,qy_MB,qz_MB,xCtr,yCtr,sdd+M_sdd_setback,lam,pixSizeX,pixSizeY,"MB")
865
866//      Print "xy for MB = ",xCtr,yCtr
867        SetScale/I x WaveMin(qx_MB),WaveMax(qx_MB),"", det_MB           //this sets the left and right ends of the data scaling
868        SetScale/I y WaveMin(qy_MB),WaveMax(qy_MB),"", det_MB
869/////////////////
870
871        SetDataFolder root:
872               
873        return(0)
874End
875
876
877Function MiddlePanels_AsQ()
878//      DoWindow/F MiddlePanels_AsQ
879//      if(V_flag == 0)
880//      PauseUpdate; Silent 1           // building window...
881//      Display /W=(1477,44,1978,517)
882
883        String midStr = "root:Packages:NIST:VSANS:VCALC:entry:instrument:"
884//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
885        SetDataFolder $(midStr+"detector_MB")
886        Wave det_MB = det_MB
887        SetDataFolder $(midStr+"detector_MT")
888        Wave det_MT = det_MT
889        SetDataFolder $(midStr+"detector_ML")
890        Wave det_ML = det_ML
891        SetDataFolder $(midStr+"detector_MR")
892        Wave det_MR = det_MR
893
894        CheckDisplayed /W=VCALC#Panels_Q det_MB
895       
896        if(V_flag == 0)
897                AppendImage/W=VCALC#Panels_Q det_MB
898                ModifyImage/W=VCALC#Panels_Q det_MB ctab= {*,*,ColdWarm,0}
899                AppendImage/W=VCALC#Panels_Q det_MT
900                ModifyImage/W=VCALC#Panels_Q det_MT ctab= {*,*,ColdWarm,0}
901                AppendImage/W=VCALC#Panels_Q det_ML
902                ModifyImage/W=VCALC#Panels_Q det_ML ctab= {*,*,ColdWarm,0}
903                AppendImage/W=VCALC#Panels_Q det_MR
904                ModifyImage/W=VCALC#Panels_Q det_MR ctab= {*,*,ColdWarm,0}
905        endif
906
907        Variable dval
908        ControlInfo/W=VCALC setVar_b
909        dval = V_Value
910
911        SetAxis/W=VCALC#Panels_Q left -dval,dval
912        SetAxis/W=VCALC#Panels_Q bottom -dval,dval     
913
914        ControlInfo/W=VCALC check_0a
915// V_Value == 1 if checked
916        ModifyImage/W=VCALC#Panels_Q det_MB log=V_Value
917        ModifyImage/W=VCALC#Panels_Q det_MT log=V_Value
918        ModifyImage/W=VCALC#Panels_Q det_ML log=V_Value
919        ModifyImage/W=VCALC#Panels_Q det_MR log=V_Value
920
921
922        SetDataFolder root:
923       
924//      ModifyGraph width={Aspect,1},height={Aspect,1},gbRGB=(56797,56797,56797)
925//      ModifyGraph grid=2
926//      ModifyGraph mirror=2
927//      SetAxis left -0.2,0.2
928//      SetAxis bottom -0.2,0.2
929//      endif
930EndMacro
931
932//
933// these routines bin the 2D q data to 1D I(q). Currently the Qtot is magnitude only, no sign (since
934// it's being binned to I(Q), having a sign makes no sense. If you want the sign, work from qxqyqz
935//
936// first - the DeltaQ step is set as the smaller detector resolution (along tube)
937//       which is different for LR / TB geometry. This is not set in stone.
938//
939// second - each detector is binned separately
940//
941// -- like the routines in CircSectAve, start with 500 points, and trim after binning is done.
942//      you'l end up with < 200 points.
943//
944// the results are in iBin_qxqy, qBin_qxqy, and eBin_qxqy, in the folder passed
945//
946Function BinAllMiddlePanels()
947
948        SetDeltaQ("VCALC","ML")
949        SetDeltaQ("VCALC","MR")
950        SetDeltaQ("VCALC","MT")
951        SetDeltaQ("VCALC","MB")
952
953        Variable binType       
954        ControlInfo/W=VCALC popup_b
955        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
956
957        String folderStr = "VCALC"
958
959        switch(binType)
960                case 1:
961//                      VC_fDoBinning_QxQy2D(folderStr,"FL")
962//                      VC_fDoBinning_QxQy2D(folderStr,"FR")
963//                      VC_fDoBinning_QxQy2D(folderStr,"FT")
964//                      VC_fDoBinning_QxQy2D(folderStr,"FB")
965                        VC_fDoBinning_QxQy2D(folderStr,"ML")
966                        VC_fDoBinning_QxQy2D(folderStr,"MR")
967                        VC_fDoBinning_QxQy2D(folderStr,"MT")
968                        VC_fDoBinning_QxQy2D(folderStr,"MB")                   
969//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
970
971                        break
972                case 2:
973//                      VC_fDoBinning_QxQy2D(folderStr,"FLR")
974//                      VC_fDoBinning_QxQy2D(folderStr,"FTB")
975                        VC_fDoBinning_QxQy2D(folderStr,"MLR")
976                        VC_fDoBinning_QxQy2D(folderStr,"MTB")
977//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
978
979                        break
980                case 3:
981                        VC_fDoBinning_QxQy2D(folderStr,"MLRTB")
982//                      VC_fDoBinning_QxQy2D(folderStr,"FLRTB")
983//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
984                       
985                        break
986                case 4:                         /// this is for a tall, narrow slit mode       
987//                      VC_fBinDetector_byRows(folderStr,"FL")
988//                      VC_fBinDetector_byRows(folderStr,"FR")
989                        VC_fBinDetector_byRows(folderStr,"ML")
990                        VC_fBinDetector_byRows(folderStr,"MR")
991//                      VC_fBinDetector_byRows(folderStr,"B")
992
993                        break
994                case 5:
995//                      VC_fDoBinning_QxQy2D(folderStr,"FTB")
996//                      VC_fDoBinning_QxQy2D(folderStr,"FLR")
997                        VC_fDoBinning_QxQy2D(folderStr,"MLRTB")
998//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
999               
1000                        break
1001                case 6:
1002//                      VC_fDoBinning_QxQy2D(folderStr,"FLRTB")
1003                        VC_fDoBinning_QxQy2D(folderStr,"MLR")
1004//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
1005               
1006                        break
1007                case 7:
1008//                      VC_fDoBinning_QxQy2D(folderStr,"FTB")
1009//                      VC_fDoBinning_QxQy2D(folderStr,"FLR")
1010                        VC_fDoBinning_QxQy2D(folderStr,"MLR")
1011//                      VC_fDoBinning_QxQy2D(folderStr, "B")           
1012               
1013                        break
1014                       
1015                default:
1016                        Abort "Binning mode not found in BinAllFrontPanels "// when no case matches     
1017        endswitch
1018       
1019
1020
1021//      if(binType == 1)
1022//              VC_BinQxQy_to_1D("VCALC","ML")
1023//              VC_BinQxQy_to_1D("VCALC","MR")
1024//              VC_BinQxQy_to_1D("VCALC","MT")
1025//              VC_BinQxQy_to_1D("VCALC","MB")
1026//      endif
1027//     
1028//      if(binType == 2)       
1029//              VC_BinQxQy_to_1D("VCALC","MLR")
1030//              VC_BinQxQy_to_1D("VCALC","MTB")
1031//      endif
1032//
1033//      if(binType == 3)
1034//              VC_BinQxQy_to_1D("VCALC","MLRTB")
1035//      endif
1036//     
1037//      // TODO -- this is only a temporary fix for slit mode   
1038//      if(binType == 4)
1039//              /// this is for a tall, narrow slit mode       
1040//              VC_fBinDetector_byRows("VCALC","ML")
1041//              VC_fBinDetector_byRows("VCALC","MR")
1042//              VC_fBinDetector_byRows("VCALC","MT")
1043//              VC_fBinDetector_byRows("VCALC","MB")
1044//      endif
1045End
1046
1047////////////to plot the (4) 2D panels and to plot the I(Q) data on the same plot
1048Window Middle_IQ_Graph() : Graph
1049
1050        Variable binType
1051       
1052        ControlInfo/W=VCALC popup_b
1053        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1054
1055        SetDataFolder root:Packages:NIST:VSANS:VCALC
1056
1057        if(binType==1)
1058                ClearIQIfDisplayed("VCALC","MLRTB","")
1059                ClearIQIfDisplayed("VCALC","MLR","")
1060                ClearIQIfDisplayed("VCALC","MTB","")
1061               
1062                SetDataFolder root:Packages:NIST:VSANS:VCALC
1063                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_ML
1064               
1065                if(V_flag==0)
1066                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_ML vs qBin_qxqy_ML
1067                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MR vs qBin_qxqy_MR
1068                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MT vs qBin_qxqy_MT
1069                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MB vs qBin_qxqy_MB
1070                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1071                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1072                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_ML)=(65535,0,0),rgb(iBin_qxqy_MB)=(1,16019,65535),rgb(iBin_qxqy_MR)=(65535,0,0),rgb(iBin_qxqy_MT)=(1,16019,65535)
1073                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1074                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_ML)={0,4},muloffset(iBin_qxqy_MB)={0,2},muloffset(iBin_qxqy_MR)={0,8}
1075                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1076                        ModifyGraph/W=VCALC#Panels_IQ log=1
1077                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1078                endif           
1079        endif
1080       
1081        if(binType==2)
1082                ClearIQIfDisplayed("VCALC","MLRTB","")
1083                ClearIQIfDisplayed("VCALC","MT","")     
1084                ClearIQIfDisplayed("VCALC","ML","")     
1085                ClearIQIfDisplayed("VCALC","MR","")     
1086                ClearIQIfDisplayed("VCALC","MB","")
1087       
1088
1089                SetDataFolder root:Packages:NIST:VSANS:VCALC
1090                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_MLR
1091               
1092                if(V_flag==0)
1093                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_MLR vs qBin_qxqy_MLR
1094                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MTB vs qBin_qxqy_MTB
1095                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1096                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1097                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_MLR)=(65535,0,0),rgb(iBin_qxqy_MTB)=(1,16019,65535)
1098                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1099                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_MLR)={0,2}
1100                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1101                        ModifyGraph/W=VCALC#Panels_IQ log=1
1102                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1103                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1104                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1105                endif   
1106                       
1107        endif
1108       
1109        if(binType==3)
1110                ClearIQIfDisplayed("VCALC","MLR","")
1111                ClearIQIfDisplayed("VCALC","MTB","")   
1112                ClearIQIfDisplayed("VCALC","MT","")     
1113                ClearIQIfDisplayed("VCALC","ML","")     
1114                ClearIQIfDisplayed("VCALC","MR","")     
1115                ClearIQIfDisplayed("VCALC","MB","")     
1116       
1117                SetDataFolder root:Packages:NIST:VSANS:VCALC
1118                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_MLRTB
1119               
1120                if(V_flag==0)
1121                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_MLRTB vs qBin_qxqy_MLRTB
1122                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1123                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1124                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_MLRTB)=(65535,0,0)
1125                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1126                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1127                        ModifyGraph/W=VCALC#Panels_IQ log=1
1128                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1129                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1130                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1131                endif   
1132                       
1133        endif
1134
1135        if(binType==4)          // slit aperture binning - MT, ML, MR, MB are averaged
1136                ClearIQIfDisplayed("VCALC","MLRTB","")
1137                ClearIQIfDisplayed("VCALC","MLR","")
1138                ClearIQIfDisplayed("VCALC","MTB","")
1139               
1140                SetDataFolder root:Packages:NIST:VSANS:VCALC
1141                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_ML
1142               
1143                if(V_flag==0)
1144                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_ML vs qBin_qxqy_ML
1145                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MR vs qBin_qxqy_MR
1146                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MT vs qBin_qxqy_MT
1147                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MB vs qBin_qxqy_MB
1148                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1149                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1150                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_ML)=(65535,0,0),rgb(iBin_qxqy_MB)=(1,16019,65535),rgb(iBin_qxqy_MR)=(65535,0,0),rgb(iBin_qxqy_MT)=(1,16019,65535)
1151                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1152                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_ML)={0,4},muloffset(iBin_qxqy_MB)={0,2},muloffset(iBin_qxqy_MR)={0,8}
1153                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1154                        ModifyGraph/W=VCALC#Panels_IQ log=1
1155                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1156                endif           
1157                       
1158        endif
1159        SetDataFolder root:
1160EndMacro
1161
1162
1163////////// and for the BACK detector
1164Proc PlotBackPanels()
1165        fPlotBackPanels()
1166End
1167
1168// to plot I(q) for the Back panel
1169//
1170// *** Call this function when Back panel is adjusted, or wavelength, etc. changed
1171//
1172Function fPlotBackPanels()
1173
1174        // space is allocated for all of the detectors and Q's on initialization
1175        // calculate Qtot, qxqyqz arrays from geometry
1176        VC_CalculateQBackPanels()
1177       
1178        // fill the panels with fake sphere scattering data
1179        // TODO: am I in the right data folder??
1180        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B
1181
1182        WAVE det_B = det_B
1183        WAVE qTot_B = qTot_B
1184
1185        FillPanel_wModelData(det_B,qTot_B,"B")         
1186
1187        SetDataFolder root:
1188               
1189        // set any "shadowed" area of the T/B detectors to NaN to get a realitic
1190        // view of how much of the detectors are actually collecting data
1191        // -- I can get the separation L/R from the panel - only this "open" width is visible.
1192//      VC_SetShadow_TopBottom("","MT")         // TODO: -- be sure the data folder is properly set (within the function...)
1193//      VC_SetShadow_TopBottom("","MB")
1194       
1195        // do the q-binning for each of the panels to get I(Q)
1196        BinAllBackPanels()
1197
1198        // plot the results
1199        String type = "VCALC"
1200        String str,winStr="VCALC#Panels_IQ",workTypeStr,popStr
1201        workTypeStr = "root:Packages:NIST:VSANS:"+type
1202
1203        ControlInfo/W=VCALC popup_b
1204        popStr = S_Value                //
1205       
1206        sprintf str,"(\"%s\",%d,\"%s\")",workTypeStr,V_BinTypeStr2Num(popStr),winStr
1207
1208        Execute ("V_Back_IQ_Graph"+str)
1209               
1210               
1211        // plot the results
1212//      Execute "Back_IQ_Graph()"
1213
1214
1215
1216        Execute "BackPanels_AsQ()"
1217
1218        return(0)
1219
1220End
1221
1222// works for Left, works for Right... works for T/B too.
1223//
1224// - TODO: be sure that the Q's are calculated correctly even when the beam is off of the
1225//     detector, and on different sides of the detector (or T/B) - since it will be in a different
1226//     relative postion to 0,0 on the detector. If the postions are symmetric, then the Q's should be identical.
1227//     --- test this...
1228// TODO -- be sure I'm in the right data folder. nothing is set correctly right now
1229//
1230// TODO: make all detector parameters global, not hard-wired
1231//
1232//
1233// --- Panels are all allocated in the initialization. Here, only the q-values are calculated
1234//     when anything changes
1235//
1236Function VC_CalculateQBackPanels()
1237
1238        Variable xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY
1239        Variable B_offset
1240
1241        String folderPath = "root:Packages:NIST:VSANS:VCALC"
1242        String instPath = ":entry:instrument:detector_"
1243        String detStr = ""
1244       
1245        ControlInfo/W=VCALC VCALCCtrl_4a
1246        B_offset = V_Value
1247       
1248        SDD = VCALC_getSDD("B")         //nominal SDD - need offset for TB
1249        lam = VCALC_getWavelength()
1250
1251// TODO (make the N along the tube length a variable, since this can be reset @ acquisition)
1252//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Back
1253        WAVE det_B = $(folderPath+instPath+"B"+":det_B")                        // this is nominally (150,150)
1254
1255//Back detector
1256//root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B:qTot_B
1257        detStr = "B"
1258        Wave qTot_B = $(folderPath+instPath+detStr+":qTot_"+detStr)                     // 2D q-values
1259        Wave qx_B = $(folderPath+instPath+detStr+":qx_"+detStr)
1260        Wave qy_B = $(folderPath+instPath+detStr+":qy_"+detStr)
1261        Wave qz_B = $(folderPath+instPath+detStr+":qz_"+detStr)
1262
1263        qTot_B = 0
1264        qx_B = 0
1265        qy_B = 0
1266        qz_B = 0       
1267       
1268// TODO - these are to be set from globals, not hard-wired. N and pixelSixze will be known (or pre-measured)
1269// pixel sizes are in cm
1270        pixSizeX = VCALC_getPixSizeX("B")
1271        pixSizeY = VCALC_getPixSizeY("B")
1272       
1273        xCtr = trunc( DimSize(det_B,0)/2 )              //should be 150/2=75
1274        yCtr = trunc( DimSize(det_B,1)/2 )              //should be 150/2=75
1275                //put these  beam center values into the local folder
1276        V_putDet_beam_center_x("VCALC","B",xCtr)
1277        V_putDet_beam_center_y("VCALC","B",yCtr)
1278       
1279//      VC_Detector_2Q(det_B,qTot_B,qx_B,qy_B,qz_B,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
1280        // this will always do the linear calculation, since the real-space distance waves do not exist
1281        VC_Detector_2Q_NonLin(det_B,qTot_B,qx_B,qy_B,qz_B,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,"B")
1282
1283       
1284        //set the wave scaling for the detector image so that it can be plotted in q-space
1285        // TODO: this is only approximate - since the left "edge" is not the same from top to bottom, so I crudely
1286        // take the middle value. At very small angles, OK, at 1m, this is a crummy approximation.
1287        // since qTot is magnitude only, I need to put in the (-ve)
1288        SetScale/I x WaveMin(qx_B),WaveMax(qx_B),"", det_B              //this sets the left and right ends of the data scaling
1289        SetScale/I y WaveMin(qy_B),WaveMax(qy_B),"", det_B
1290
1291        SetDataFolder root:
1292               
1293        return(0)
1294End
1295
1296
1297Window BackPanels_AsQ() : Graph
1298//      DoWindow/F BackPanels_AsQ
1299//      if(V_flag == 0)
1300//      PauseUpdate; Silent 1           // building window...
1301//      Display /W=(1477,44,1978,517)
1302
1303        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B
1304
1305        CheckDisplayed /W=VCALC#Panels_Q det_B
1306        if(V_flag == 0)
1307                AppendImage/W=VCALC#Panels_Q det_B
1308                ModifyImage/W=VCALC#Panels_Q det_B ctab= {*,*,ColdWarm,0}
1309        endif
1310
1311        Variable dval
1312        ControlInfo/W=VCALC setVar_b
1313        dval = V_Value
1314
1315        SetAxis/W=VCALC#Panels_Q left -dval,dval
1316        SetAxis/W=VCALC#Panels_Q bottom -dval,dval     
1317
1318        ControlInfo/W=VCALC check_0a
1319// V_Value == 1 if checked
1320        ModifyImage/W=VCALC#Panels_Q det_B log=V_Value
1321
1322        SetDataFolder root:
1323       
1324//      ModifyGraph width={Aspect,1},height={Aspect,1},gbRGB=(56797,56797,56797)
1325//      ModifyGraph grid=2
1326//      ModifyGraph mirror=2
1327//      SetAxis left -0.2,0.2
1328//      SetAxis bottom -0.2,0.2
1329//      endif
1330EndMacro
1331
1332//
1333// these routines bin the 2D q data to 1D I(q). Currently the Qtot is magnitude only, no sign (since
1334// it's being binned to I(Q), having a sign makes no sense. If you want the sign, work from qxqyqz
1335//
1336// first - the DeltaQ step is set as the smaller detector resolution (along tube)
1337//       which is different for LR / TB geometry. This is not set in stone.
1338//
1339// second - each detector is binned separately
1340//
1341// -- like the routines in CircSectAve, start with 500 points, and trim after binning is done.
1342//      you'l end up with < 200 points.
1343//
1344// the results are in iBin_qxqy, qBin_qxqy, and eBin_qxqy, in the folder passed
1345//
1346Function BinAllBackPanels()
1347
1348        SetDeltaQ("VCALC","B")
1349
1350        Variable binType       
1351        ControlInfo/W=VCALC popup_b
1352        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1353
1354        String folderStr = "VCALC"
1355
1356        switch(binType)
1357                case 1:
1358//                      VC_fDoBinning_QxQy2D(folderStr,"FL")
1359//                      VC_fDoBinning_QxQy2D(folderStr,"FR")
1360//                      VC_fDoBinning_QxQy2D(folderStr,"FT")
1361//                      VC_fDoBinning_QxQy2D(folderStr,"FB")
1362//                      VC_fDoBinning_QxQy2D(folderStr,"ML")
1363//                      VC_fDoBinning_QxQy2D(folderStr,"MR")
1364//                      VC_fDoBinning_QxQy2D(folderStr,"MT")
1365//                      VC_fDoBinning_QxQy2D(folderStr,"MB")                   
1366                        VC_fDoBinning_QxQy2D(folderStr, "B")           
1367
1368                        break
1369                case 2:
1370//                      VC_fDoBinning_QxQy2D(folderStr,"FLR")
1371//                      VC_fDoBinning_QxQy2D(folderStr,"FTB")
1372//                      VC_fDoBinning_QxQy2D(folderStr,"MLR")
1373//                      VC_fDoBinning_QxQy2D(folderStr,"MTB")
1374                        VC_fDoBinning_QxQy2D(folderStr, "B")           
1375
1376                        break
1377                case 3:
1378//                      VC_fDoBinning_QxQy2D(folderStr,"MLRTB")
1379//                      VC_fDoBinning_QxQy2D(folderStr,"FLRTB")
1380                        VC_fDoBinning_QxQy2D(folderStr, "B")           
1381                       
1382                        break
1383                case 4:                         /// this is for a tall, narrow slit mode       
1384//                      VC_fBinDetector_byRows(folderStr,"FL")
1385//                      VC_fBinDetector_byRows(folderStr,"FR")
1386//                      VC_fBinDetector_byRows(folderStr,"ML")
1387//                      VC_fBinDetector_byRows(folderStr,"MR")
1388                        VC_fBinDetector_byRows(folderStr,"B")
1389
1390                        break
1391                case 5:
1392//                      VC_fDoBinning_QxQy2D(folderStr,"FTB")
1393//                      VC_fDoBinning_QxQy2D(folderStr,"FLR")
1394//                      VC_fDoBinning_QxQy2D(folderStr,"MLRTB")
1395                        VC_fDoBinning_QxQy2D(folderStr, "B")           
1396               
1397                        break
1398                case 6:
1399//                      VC_fDoBinning_QxQy2D(folderStr,"FLRTB")
1400//                      VC_fDoBinning_QxQy2D(folderStr,"MLR")
1401                        VC_fDoBinning_QxQy2D(folderStr, "B")           
1402               
1403                        break
1404                case 7:
1405//                      VC_fDoBinning_QxQy2D(folderStr,"FTB")
1406//                      VC_fDoBinning_QxQy2D(folderStr,"FLR")
1407//                      VC_fDoBinning_QxQy2D(folderStr,"MLR")
1408                        VC_fDoBinning_QxQy2D(folderStr, "B")           
1409               
1410                        break
1411                       
1412                default:
1413                        Abort "Binning mode not found in BinAllFrontPanels "// when no case matches     
1414        endswitch
1415               
1416//      VC_BinQxQy_to_1D("VCALC","B")
1417//
1418//// TODO -- this is only a temporary fix for slit mode
1419//      if(binType == 4)
1420//              /// this is for a tall, narrow slit mode       
1421//              VC_fBinDetector_byRows("VCALC","B")
1422//      endif   
1423       
1424End
1425
1426////////////to plot the back panel I(q)
1427Window Back_IQ_Graph() : Graph
1428
1429        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B
1430
1431        Variable binType
1432       
1433        ControlInfo/W=VCALC popup_b
1434        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1435       
1436
1437        if(binType==1 || binType==2 || binType==3)
1438               
1439                SetDataFolder root:Packages:NIST:VSANS:VCALC
1440                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_B
1441               
1442                if(V_flag==0)
1443                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_B vs qBin_qxqy_B
1444                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1445                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1446                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_B)=(1,52428,52428)
1447                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1448                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1449                        ModifyGraph/W=VCALC#Panels_IQ log=1
1450                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1451                endif
1452        endif
1453
1454        //nothing different here since there is ony a single detector to display, but for the future...
1455        if(binType==4)
1456               
1457                SetDataFolder root:Packages:NIST:VSANS:VCALC
1458                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_B
1459               
1460                if(V_flag==0)
1461                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_B vs qBin_qxqy_B
1462                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1463                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1464                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_B)=(1,52428,52428)
1465                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1466                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1467                        ModifyGraph/W=VCALC#Panels_IQ log=1
1468                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1469                endif
1470        endif
1471
1472       
1473        SetDataFolder root:
1474EndMacro
1475
1476
1477////////////to plot the (4) 2D panels and to plot the I(Q) data on the same plot
1478//
1479// ** but now I need to check and see if these waves exist before trying to append them
1480// since the panels may bave been combined when binned - rather than all separate.
1481//
1482// TODO
1483// -- so maybe I want to clear the traces from the graph?
1484// -- set a flag on the panel to know how the binning is applied?
1485//
1486Window Front_IQ_Graph() : Graph
1487
1488        Variable binType
1489        String fldr = "VCALC"
1490       
1491        ControlInfo/W=VCALC popup_b
1492        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1493
1494        SetDataFolder root:Packages:NIST:VSANS:VCALC
1495
1496        if(binType==1)
1497                ClearIQIfDisplayed("VCALC","FLRTB","")
1498                ClearIQIfDisplayed("VCALC","FLR","")
1499                ClearIQIfDisplayed("VCALC","FTB","")
1500               
1501                SetDataFolder root:Packages:NIST:VSANS:VCALC
1502                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FL
1503               
1504                if(V_flag==0)
1505                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FL vs qBin_qxqy_FL
1506                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FR vs qBin_qxqy_FR
1507                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FT vs qBin_qxqy_FT
1508                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FB vs qBin_qxqy_FB
1509                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1510                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1511                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FL)=(39321,26208,1),rgb(iBin_qxqy_FB)=(2,39321,1),rgb(iBin_qxqy_FR)=(39321,26208,1),rgb(iBin_qxqy_FT)=(2,39321,1)
1512                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1513                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FL)={0,4},muloffset(iBin_qxqy_FB)={0,2},muloffset(iBin_qxqy_FR)={0,8}
1514                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1515                        ModifyGraph/W=VCALC#Panels_IQ log=1
1516                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1517                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1518                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1519                endif   
1520                               
1521        endif
1522
1523        if(binType==2)
1524                ClearIQIfDisplayed("VCALC","FLRTB","")
1525                ClearIQIfDisplayed("VCALC","FT","")     
1526                ClearIQIfDisplayed("VCALC","FL","")     
1527                ClearIQIfDisplayed("VCALC","FR","")     
1528                ClearIQIfDisplayed("VCALC","FB","")
1529       
1530
1531                SetDataFolder root:Packages:NIST:VSANS:VCALC
1532                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FLR
1533               
1534                if(V_flag==0)
1535                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FLR vs qBin_qxqy_FLR
1536                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FTB vs qBin_qxqy_FTB
1537                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1538                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1539                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FLR)=(39321,26208,1),rgb(iBin_qxqy_FTB)=(2,39321,1)
1540                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1541                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FLR)={0,2}
1542                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1543                        ModifyGraph/W=VCALC#Panels_IQ log=1
1544                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1545                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1546                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1547                endif   
1548                       
1549        endif
1550       
1551        if(binType==3)
1552                ClearIQIfDisplayed("VCALC","FLR","")
1553                ClearIQIfDisplayed("VCALC","FTB","")   
1554                ClearIQIfDisplayed("VCALC","FT","")     
1555                ClearIQIfDisplayed("VCALC","FL","")     
1556                ClearIQIfDisplayed("VCALC","FR","")     
1557                ClearIQIfDisplayed("VCALC","FB","")     
1558       
1559                SetDataFolder root:Packages:NIST:VSANS:VCALC
1560                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FLRTB
1561               
1562                if(V_flag==0)
1563                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FLRTB vs qBin_qxqy_FLRTB
1564                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1565                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1566                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FLRTB)=(39321,26208,1)
1567                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1568                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1569                        ModifyGraph/W=VCALC#Panels_IQ log=1
1570                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1571                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1572                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1573                endif   
1574                       
1575        endif
1576
1577
1578        if(binType==4)          //slit mode
1579                ClearIQIfDisplayed("VCALC","FLRTB","")
1580                ClearIQIfDisplayed("VCALC","FLR","")
1581                ClearIQIfDisplayed("VCALC","FTB","")
1582               
1583                SetDataFolder root:Packages:NIST:VSANS:VCALC
1584                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FL
1585               
1586                if(V_flag==0)
1587                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FL vs qBin_qxqy_FL
1588                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FR vs qBin_qxqy_FR
1589                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FT vs qBin_qxqy_FT
1590                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FB vs qBin_qxqy_FB
1591                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1592                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1593                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FL)=(39321,26208,1),rgb(iBin_qxqy_FB)=(2,39321,1),rgb(iBin_qxqy_FR)=(39321,26208,1),rgb(iBin_qxqy_FT)=(2,39321,1)
1594                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1595                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FL)={0,4},muloffset(iBin_qxqy_FB)={0,2},muloffset(iBin_qxqy_FR)={0,8}
1596                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1597                        ModifyGraph/W=VCALC#Panels_IQ log=1
1598                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1599                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1600                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1601                endif   
1602                               
1603        endif
1604
1605       
1606        SetDataFolder root:
1607       
1608EndMacro
1609
1610
1611// for a given detector binning type ("B", "FLTB", "MTB" etc)
1612// all of the work folders will be checked to see if the data is on the graph
1613// and if it is, it will be removed
1614//
1615// VCALC panel can pass in "" for the winNameStr
1616//
1617Function ClearIQIfDisplayed_AllFldr(type,winNameStr)
1618        String type,winNameStr
1619
1620//      String folderList = ksWorkFolderListShort
1621        String fldr
1622        Variable ii
1623       
1624        String folderList_plus = ksWorkFolderListShort+";VCALC"
1625       
1626        for(ii=0;ii<ItemsInList(folderList_plus);ii+=1)
1627                fldr = StringFromList(ii, folderList_plus, ";")
1628                ClearIQIfDisplayed(fldr,type,winNameStr)
1629        endfor
1630        // just in case
1631        SetDataFolder root:
1632       
1633        return(0)
1634end
1635
1636
1637
1638// for a given data folder, all detector binning types
1639// ("B", "FLTB", "MTB" etc) will be checked to see if the data is on the graph
1640// and if it is, it will be removed
1641//
1642// VCALC panel can pass in "" for the winNameStr
1643//
1644Function ClearIQIfDisplayed_AllBin(fldr,winNameStr)
1645        String fldr,winNameStr
1646
1647//      String folderList = ksWorkFolderListShort
1648        String type
1649        Variable ii
1650       
1651        for(ii=0;ii<ItemsInList(ksPanelBinTypeList);ii+=1)
1652                type = StringFromList(ii, ksPanelBinTypeList, ";")
1653                ClearIQIfDisplayed(fldr,type,winNameStr)
1654        endfor
1655        // just in case
1656        SetDataFolder root:
1657       
1658        return(0)
1659end
1660
1661
1662
1663Function ClearIQIfDisplayed(fldr,type,winNameStr)
1664        String fldr,type,winNameStr
1665
1666        SetDataFolder $("root:Packages:NIST:VSANS:"+fldr)
1667
1668        if(cmpstr(fldr,"VCALC") == 0)
1669                CheckDisplayed/W=VCALC#Panels_IQ $("iBin_qxqy_"+type)
1670                if(V_flag==1)
1671                        RemoveFromGraph/W=VCALC#Panels_IQ $("iBin_qxqy_"+type)
1672                endif
1673        else
1674                CheckDisplayed/W=$winNameStr $("iBin_qxqy_"+type)
1675                if(V_flag==1)
1676                        RemoveFromGraph/W=$winNameStr $("iBin_qxqy_"+type)
1677                endif
1678        endif
1679
1680        SetDataFolder root:
1681       
1682        return(0)
1683end
1684
1685Window Table_of_QBins() : Table
1686        PauseUpdate; Silent 1           // building window...
1687        String fldrSav0= GetDataFolder(1)
1688        SetDataFolder root:Packages:NIST:VSANS:VCALC:
1689        Edit/W=(5,44,771,898) qBin_qxqy_FL,qBin_qxqy_FR,qBin_qxqy_FT,qBin_qxqy_FB,qBin_qxqy_FLR
1690        AppendToTable qBin_qxqy_FTB,qBin_qxqy_FLRTB
1691        ModifyTable format(Point)=1,width(qBin_qxqy_FLR)=136,width(qBin_qxqy_FLRTB)=120
1692        SetDataFolder fldrSav0
1693EndMacro
1694
1695
1696
1697
Note: See TracBrowser for help on using the repository browser.