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

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

more additions to VCALC functionality and bug fixes

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