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

Last change on this file since 1098 was 1098, checked in by srkline, 5 years ago

renamed white beam smearing models so they would be grouped together on the file list.

Re-worked the logic and flow of the averaging/plotting/saving steps of the reduction protocol so that it would flow cleanly and leave room for changes for the multitude of different collimation conditions. The averaging routines are now aware of the collimation conditions so that the appropriate resolution can be calculated. The collimation string is also written out to the averaged data file as element[9] of the protocol. The hope is that one could key on this collimation string to decide how to proceed with the analysis.

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