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

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

more changes to VCALC functionality and bug fixes for VCALC

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