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

Last change on this file since 1247 was 1247, checked in by srkline, 2 years ago

more changes to panel scaling so that they are viewed properly on a small-screen laptop

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