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

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

multiple changes to improve the functionality of VCALC

more values are reported, and the IQ plot now accounts for a beam stop shadowing the low q region. Qmin and qmax values are reported for each panel. the beam intensity value is more realistic, with correct SSD values.

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