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

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

many changes to the VCALC procedures to add in the hard/soft shadowing to the calculation, visualization of the shadowed regions, and the actual q-values. Added a separate panel to view the shadowed regions.

simpe fix to the real time routine to allow easy updating of both the raw 2D data and 1-D average

update to the USANS package to handle the new NICE generated data where the data is collected in terms of q-values rather than angle. On startup asks user which style of data they have. Sets a preference that can be un-checked if you have old-style ICP data. (there is nothing in the data file that I can key on).

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