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

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

minor changes - can't find the diff command in TortoiseSVN...

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