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

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

changes mostly to VCALC to add in what bits of information I have about the instrument dimensions. Added in stubs (based on NG3 SANS) for the beam intensity. Added in a preset condition for Front+Middle. Still need a more uniform way to do this.

File size: 54.5 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 realistic
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// (DONE) - these are set from globals, not hard-wired. N and pixelSize will be known (or pre-measured)
1271// pixel sizes are in cm
1272// beam center for the back detector is in PIXELS. always.
1273        pixSizeX = VCALC_getPixSizeX("B")
1274        pixSizeY = VCALC_getPixSizeY("B")
1275
1276        xCtr = V_getDet_beam_center_x("VCALC","B")
1277        yCtr = V_getDet_beam_center_y("VCALC","B")
1278
1279//      if(kBCTR_CM)
1280//              xCtr = trunc( DimSize(det_B,0)/2 ) *pixSizeX * 10
1281//              yCtr = trunc( DimSize(det_B,1)/2 ) *pixSizeY * 10       //values in mm -- beam is nominally at 0,0 in space
1282//      else   
1283//              xCtr = trunc( DimSize(det_B,0)/2 )              //
1284//              yCtr = trunc( DimSize(det_B,1)/2 )              //
1285//      endif
1286//     
1287//              //put these  beam center values into the local folder
1288//      V_putDet_beam_center_x("VCALC","B",xCtr)
1289//      V_putDet_beam_center_y("VCALC","B",yCtr)
1290       
1291//      VC_Detector_2Q(det_B,qTot_B,qx_B,qy_B,qz_B,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
1292        // this will always do the linear calculation, since the real-space distance waves do not exist
1293        VC_Detector_2Q_NonLin(det_B,qTot_B,qx_B,qy_B,qz_B,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,"B")
1294
1295       
1296        //set the wave scaling for the detector image so that it can be plotted in q-space
1297        // TODO: this is only approximate - since the left "edge" is not the same from top to bottom, so I crudely
1298        // take the middle value. At very small angles, OK, at 1m, this is a crummy approximation.
1299        // since qTot is magnitude only, I need to put in the (-ve)
1300        SetScale/I x WaveMin(qx_B),WaveMax(qx_B),"", det_B              //this sets the left and right ends of the data scaling
1301        SetScale/I y WaveMin(qy_B),WaveMax(qy_B),"", det_B
1302
1303        SetDataFolder root:
1304               
1305        return(0)
1306End
1307
1308
1309Window BackPanels_AsQ() : Graph
1310//      DoWindow/F BackPanels_AsQ
1311//      if(V_flag == 0)
1312//      PauseUpdate; Silent 1           // building window...
1313//      Display /W=(1477,44,1978,517)
1314
1315        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B
1316
1317        CheckDisplayed /W=VCALC#Panels_Q det_B
1318        if(V_flag == 0)
1319                AppendImage/W=VCALC#Panels_Q det_B
1320                ModifyImage/W=VCALC#Panels_Q det_B ctab= {*,*,ColdWarm,0}
1321        endif
1322
1323        Variable dval
1324        ControlInfo/W=VCALC setVar_b
1325        dval = V_Value
1326
1327        SetAxis/W=VCALC#Panels_Q left -dval,dval
1328        SetAxis/W=VCALC#Panels_Q bottom -dval,dval     
1329
1330        ControlInfo/W=VCALC check_0a
1331// V_Value == 1 if checked
1332        ModifyImage/W=VCALC#Panels_Q det_B log=V_Value
1333
1334        SetDataFolder root:
1335       
1336//      ModifyGraph width={Aspect,1},height={Aspect,1},gbRGB=(56797,56797,56797)
1337//      ModifyGraph grid=2
1338//      ModifyGraph mirror=2
1339//      SetAxis left -0.2,0.2
1340//      SetAxis bottom -0.2,0.2
1341//      endif
1342EndMacro
1343
1344//
1345// these routines bin the 2D q data to 1D I(q). Currently the Qtot is magnitude only, no sign (since
1346// it's being binned to I(Q), having a sign makes no sense. If you want the sign, work from qxqyqz
1347//
1348// first - the DeltaQ step is set as the smaller detector resolution (along tube)
1349//       which is different for LR / TB geometry. This is not set in stone.
1350//
1351// second - each detector is binned separately
1352//
1353// -- like the routines in CircSectAve, start with 500 points, and trim after binning is done.
1354//      you'l end up with < 200 points.
1355//
1356// the results are in iBin_qxqy, qBin_qxqy, and eBin_qxqy, in the folder passed
1357//
1358Function BinAllBackPanels()
1359
1360        V_SetDeltaQ("VCALC","B")
1361
1362        Variable binType       
1363        ControlInfo/W=VCALC popup_b
1364        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1365
1366        String folderStr = "VCALC"
1367        String collimationStr="pinhole"         // TODO: fill this in from the VCALC panel
1368        Print "collimationStr hard-wired to pinhole: update as VCALC is filled in"
1369
1370        switch(binType)
1371                case 1:
1372//                      VC_fDoBinning_QxQy2D(folderStr,"FL")
1373//                      VC_fDoBinning_QxQy2D(folderStr,"FR")
1374//                      VC_fDoBinning_QxQy2D(folderStr,"FT")
1375//                      VC_fDoBinning_QxQy2D(folderStr,"FB")
1376//                      VC_fDoBinning_QxQy2D(folderStr,"ML")
1377//                      VC_fDoBinning_QxQy2D(folderStr,"MR")
1378//                      VC_fDoBinning_QxQy2D(folderStr,"MT")
1379//                      VC_fDoBinning_QxQy2D(folderStr,"MB")                   
1380                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
1381
1382                        break
1383                case 2:
1384//                      VC_fDoBinning_QxQy2D(folderStr,"FLR")
1385//                      VC_fDoBinning_QxQy2D(folderStr,"FTB")
1386//                      VC_fDoBinning_QxQy2D(folderStr,"MLR")
1387//                      VC_fDoBinning_QxQy2D(folderStr,"MTB")
1388                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
1389
1390                        break
1391                case 3:
1392//                      VC_fDoBinning_QxQy2D(folderStr,"MLRTB")
1393//                      VC_fDoBinning_QxQy2D(folderStr,"FLRTB")
1394                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
1395                       
1396                        break
1397                case 4:                         /// this is for a tall, narrow slit mode       
1398//                      VC_fBinDetector_byRows(folderStr,"FL")
1399//                      VC_fBinDetector_byRows(folderStr,"FR")
1400//                      VC_fBinDetector_byRows(folderStr,"ML")
1401//                      VC_fBinDetector_byRows(folderStr,"MR")
1402                        VC_fBinDetector_byRows(folderStr,"B")
1403
1404                        break
1405                case 5:
1406//                      VC_fDoBinning_QxQy2D(folderStr,"FTB")
1407//                      VC_fDoBinning_QxQy2D(folderStr,"FLR")
1408//                      VC_fDoBinning_QxQy2D(folderStr,"MLRTB")
1409                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
1410               
1411                        break
1412                case 6:
1413//                      VC_fDoBinning_QxQy2D(folderStr,"FLRTB")
1414//                      VC_fDoBinning_QxQy2D(folderStr,"MLR")
1415                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
1416               
1417                        break
1418                case 7:
1419//                      VC_fDoBinning_QxQy2D(folderStr,"FTB")
1420//                      VC_fDoBinning_QxQy2D(folderStr,"FLR")
1421//                      VC_fDoBinning_QxQy2D(folderStr,"MLR")
1422                        VC_fDoBinning_QxQy2D(folderStr, "B",collimationStr)             
1423               
1424                        break
1425                       
1426                default:
1427                        Abort "Binning mode not found in BinAllFrontPanels "// when no case matches     
1428        endswitch
1429               
1430//      VC_BinQxQy_to_1D("VCALC","B")
1431//
1432//// TODO -- this is only a temporary fix for slit mode
1433//      if(binType == 4)
1434//              /// this is for a tall, narrow slit mode       
1435//              VC_fBinDetector_byRows("VCALC","B")
1436//      endif   
1437       
1438End
1439
1440////////////to plot the back panel I(q)
1441Window Back_IQ_Graph() : Graph
1442
1443        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B
1444
1445        Variable binType
1446       
1447        ControlInfo/W=VCALC popup_b
1448        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1449       
1450
1451        if(binType==1 || binType==2 || binType==3)
1452               
1453                SetDataFolder root:Packages:NIST:VSANS:VCALC
1454                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_B
1455               
1456                if(V_flag==0)
1457                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_B vs qBin_qxqy_B
1458                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1459                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1460                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_B)=(1,52428,52428)
1461                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1462                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1463                        ModifyGraph/W=VCALC#Panels_IQ log=1
1464                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1465                endif
1466        endif
1467
1468        //nothing different here since there is ony a single detector to display, but for the future...
1469        if(binType==4)
1470               
1471                SetDataFolder root:Packages:NIST:VSANS:VCALC
1472                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_B
1473               
1474                if(V_flag==0)
1475                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_B vs qBin_qxqy_B
1476                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1477                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1478                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_B)=(1,52428,52428)
1479                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1480                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1481                        ModifyGraph/W=VCALC#Panels_IQ log=1
1482                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1483                endif
1484        endif
1485
1486       
1487        SetDataFolder root:
1488EndMacro
1489
1490
1491////////////to plot the (4) 2D panels and to plot the I(Q) data on the same plot
1492//
1493// ** but now I need to check and see if these waves exist before trying to append them
1494// since the panels may bave been combined when binned - rather than all separate.
1495//
1496// TODO
1497// -- so maybe I want to clear the traces from the graph?
1498// -- set a flag on the panel to know how the binning is applied?
1499//
1500Window Front_IQ_Graph() : Graph
1501
1502        Variable binType
1503        String fldr = "VCALC"
1504       
1505        ControlInfo/W=VCALC popup_b
1506        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1507
1508        SetDataFolder root:Packages:NIST:VSANS:VCALC
1509
1510        if(binType==1)
1511                ClearIQIfDisplayed("VCALC","FLRTB","")
1512                ClearIQIfDisplayed("VCALC","FLR","")
1513                ClearIQIfDisplayed("VCALC","FTB","")
1514               
1515                SetDataFolder root:Packages:NIST:VSANS:VCALC
1516                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FL
1517               
1518                if(V_flag==0)
1519                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FL vs qBin_qxqy_FL
1520                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FR vs qBin_qxqy_FR
1521                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FT vs qBin_qxqy_FT
1522                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FB vs qBin_qxqy_FB
1523                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1524                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1525                        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)
1526                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1527                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FL)={0,4},muloffset(iBin_qxqy_FB)={0,2},muloffset(iBin_qxqy_FR)={0,8}
1528                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1529                        ModifyGraph/W=VCALC#Panels_IQ log=1
1530                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1531                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1532                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1533                endif   
1534                               
1535        endif
1536
1537        if(binType==2)
1538                ClearIQIfDisplayed("VCALC","FLRTB","")
1539                ClearIQIfDisplayed("VCALC","FT","")     
1540                ClearIQIfDisplayed("VCALC","FL","")     
1541                ClearIQIfDisplayed("VCALC","FR","")     
1542                ClearIQIfDisplayed("VCALC","FB","")
1543       
1544
1545                SetDataFolder root:Packages:NIST:VSANS:VCALC
1546                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FLR
1547               
1548                if(V_flag==0)
1549                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FLR vs qBin_qxqy_FLR
1550                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FTB vs qBin_qxqy_FTB
1551                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1552                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1553                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FLR)=(39321,26208,1),rgb(iBin_qxqy_FTB)=(2,39321,1)
1554                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1555                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FLR)={0,2}
1556                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1557                        ModifyGraph/W=VCALC#Panels_IQ log=1
1558                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1559                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1560                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1561                endif   
1562                       
1563        endif
1564       
1565        if(binType==3)
1566                ClearIQIfDisplayed("VCALC","FLR","")
1567                ClearIQIfDisplayed("VCALC","FTB","")   
1568                ClearIQIfDisplayed("VCALC","FT","")     
1569                ClearIQIfDisplayed("VCALC","FL","")     
1570                ClearIQIfDisplayed("VCALC","FR","")     
1571                ClearIQIfDisplayed("VCALC","FB","")     
1572       
1573                SetDataFolder root:Packages:NIST:VSANS:VCALC
1574                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FLRTB
1575               
1576                if(V_flag==0)
1577                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FLRTB vs qBin_qxqy_FLRTB
1578                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1579                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1580                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FLRTB)=(39321,26208,1)
1581                        ModifyGraph/W=VCALC#Panels_IQ msize=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
1592        if(binType==4)          //slit mode
1593                ClearIQIfDisplayed("VCALC","FLRTB","")
1594                ClearIQIfDisplayed("VCALC","FLR","")
1595                ClearIQIfDisplayed("VCALC","FTB","")
1596               
1597                SetDataFolder root:Packages:NIST:VSANS:VCALC
1598                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FL
1599               
1600                if(V_flag==0)
1601                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FL vs qBin_qxqy_FL
1602                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FR vs qBin_qxqy_FR
1603                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FT vs qBin_qxqy_FT
1604                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FB vs qBin_qxqy_FB
1605                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1606                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1607                        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)
1608                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1609                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FL)={0,4},muloffset(iBin_qxqy_FB)={0,2},muloffset(iBin_qxqy_FR)={0,8}
1610                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1611                        ModifyGraph/W=VCALC#Panels_IQ log=1
1612                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1613                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1614                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1615                endif   
1616                               
1617        endif
1618
1619       
1620        SetDataFolder root:
1621       
1622EndMacro
1623
1624
1625// for a given detector binning type ("B", "FLTB", "MTB" etc)
1626// all of the work folders will be checked to see if the data is on the graph
1627// and if it is, it will be removed
1628//
1629// VCALC panel can pass in "" for the winNameStr
1630//
1631Function ClearIQIfDisplayed_AllFldr(type,winNameStr)
1632        String type,winNameStr
1633
1634//      String folderList = ksWorkFolderListShort
1635        String fldr
1636        Variable ii
1637       
1638        String folderList = ksWorkFolderListShort
1639
1640// add in the check on the VCALC  folder only if called from that window       
1641        if(cmpstr(winNameStr[0,4],"VCALC") == 0)
1642                folderList = "VCALC;"
1643        endif
1644       
1645        for(ii=0;ii<ItemsInList(folderList);ii+=1)
1646                fldr = StringFromList(ii, folderList, ";")
1647                ClearIQIfDisplayed(fldr,type,winNameStr)
1648        endfor
1649        // just in case
1650        SetDataFolder root:
1651       
1652        return(0)
1653end
1654
1655
1656
1657// for a given data folder, all detector binning types
1658// ("B", "FLTB", "MTB" etc) will be checked to see if the data is on the graph
1659// and if it is, it will be removed
1660//
1661// VCALC panel can pass in "" for the winNameStr
1662//
1663Function ClearIQIfDisplayed_AllBin(fldr,winNameStr)
1664        String fldr,winNameStr
1665
1666//      String folderList = ksWorkFolderListShort
1667        String type
1668        Variable ii
1669       
1670        for(ii=0;ii<ItemsInList(ksPanelBinTypeList);ii+=1)
1671                type = StringFromList(ii, ksPanelBinTypeList, ";")
1672                ClearIQIfDisplayed(fldr,type,winNameStr)
1673        endfor
1674        // just in case
1675        SetDataFolder root:
1676       
1677        return(0)
1678end
1679
1680
1681
1682Function ClearIQIfDisplayed(fldr,type,winNameStr)
1683        String fldr,type,winNameStr
1684
1685        SetDataFolder $("root:Packages:NIST:VSANS:"+fldr)
1686
1687        if(cmpstr(fldr,"VCALC") == 0)
1688                CheckDisplayed/W=VCALC#Panels_IQ $("iBin_qxqy_"+type)
1689                if(V_flag==1)
1690                        RemoveFromGraph/W=VCALC#Panels_IQ $("iBin_qxqy_"+type)
1691                endif
1692        else
1693                CheckDisplayed/W=$winNameStr $("iBin_qxqy_"+type)
1694                if(V_flag==1)
1695                        RemoveFromGraph/W=$winNameStr $("iBin_qxqy_"+type)
1696                endif
1697        endif
1698
1699        SetDataFolder root:
1700       
1701        return(0)
1702end
1703
1704Window Table_of_QBins() : Table
1705        PauseUpdate; Silent 1           // building window...
1706        String fldrSav0= GetDataFolder(1)
1707        SetDataFolder root:Packages:NIST:VSANS:VCALC:
1708        Edit/W=(5,44,771,898) qBin_qxqy_FL,qBin_qxqy_FR,qBin_qxqy_FT,qBin_qxqy_FB,qBin_qxqy_FLR
1709        AppendToTable qBin_qxqy_FTB,qBin_qxqy_FLRTB
1710        ModifyTable format(Point)=1,width(qBin_qxqy_FLR)=136,width(qBin_qxqy_FLRTB)=120
1711        SetDataFolder fldrSav0
1712EndMacro
1713
1714
1715
1716
Note: See TracBrowser for help on using the repository browser.