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

Last change on this file since 982 was 982, checked in by srkline, 7 years ago

more changes and additons to display VSANS data

adding functions for IvsQ plotting

coverted much of VCALC to have similar folder structure as HDF to allow re-use of the Q-binning procedures from VCALC with real data in work files.

re-working the beam center finder to get it to work with work file data rather then only VCALC.

new plotting routines for the panels to rescale to the beam center (still in pixels, though)

File size: 42.6 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
30Proc PlotFrontPanels()
31        fPlotFrontPanels()
32End
33
34//
35// Plot the front panels in 2D and 1D
36//              calcualate Q
37//              fill w/model data
38//              "shadow" the T/B detectors
39//              bin the data to I(q)
40//              draw I(q) graph
41//              draw 2D panel graph
42//
43// *** Call this function when front panels are adjusted, or wavelength, etc. changed
44//
45Function fPlotFrontPanels()
46
47        // space is allocated for all of the detectors and Q's on initialization
48        // calculate Qtot, qxqyqz arrays from geometry
49        VC_CalculateQFrontPanels()
50       
51        // fill the panels with fake sphere scattering data
52        // TODO: am I in the right data folder??
53//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
54
55        String folderStr = "VCALC"
56        String detStr = ""
57
58        String folderPath = "root:Packages:NIST:VSANS:"+folderStr
59        String instPath = ":entry:entry:instrument:detector_"   
60
61        detStr = "FL"
62        WAVE det_FL = $(folderPath+instPath+detStr+":det_"+detStr)     
63        WAVE qTot_FL = $(folderPath+instPath+detStr+":qTot_"+detStr)
64       
65        detStr = "FR"
66        WAVE det_FR = $(folderPath+instPath+detStr+":det_"+detStr)     
67        WAVE qTot_FR = $(folderPath+instPath+detStr+":qTot_"+detStr)
68       
69        detStr = "FT"
70        WAVE det_FT = $(folderPath+instPath+detStr+":det_"+detStr)     
71        WAVE qTot_FT = $(folderPath+instPath+detStr+":qTot_"+detStr)
72       
73        detStr = "FB"
74        WAVE det_FB = $(folderPath+instPath+detStr+":det_"+detStr)     
75        WAVE qTot_FB = $(folderPath+instPath+detStr+":qTot_"+detStr)
76
77        FillPanel_wModelData(det_FL,qTot_FL,"FL")
78        FillPanel_wModelData(det_FR,qTot_FR,"FR")
79        FillPanel_wModelData(det_FT,qTot_FT,"FT")
80        FillPanel_wModelData(det_FB,qTot_FB,"FB")
81
82        SetDataFolder root:
83               
84        // set any "shadowed" area of the T/B detectors to NaN to get a realitic
85        // view of how much of the detectors are actually collecting data
86        // -- I can get the separation L/R from the panel - only this "open" width is visible.
87        //TODO - make this a proper shadow - TB extent of the LR panels matters too, not just the LR separation
88        VC_SetShadow_TopBottom("VCALC","FT")            // TODO: -- be sure the data folder is properly set (within the function...)
89        VC_SetShadow_TopBottom("VCALC","FB")
90       
91        // do the q-binning for each of the panels to get I(Q)
92        Execute "BinAllFrontPanels()"
93
94        // plot the results
95        Execute "Front_IQ_Graph()"
96        FrontPanels_AsQ()
97       
98        return(0)
99End
100
101
102// works for Left, works for Right... works for T/B too.
103//
104// - TODO: be sure that the Q's are calculated correctly even when the beam is off of the
105//     detector, and on different sides of the detector (or T/B) - since it will be in a different
106//     relative postion to 0,0 on the detector. If the postions are symmetric, then the Q's should be identical.
107//     --- test this...
108// TODO -- be sure I'm in the right data folder. nothing is set correctly right now
109//
110// TODO: make all detector parameters global, not hard-wired
111//
112//
113// --- Panels are all allocated in the initialization. Here, only the q-values are calculated
114//     when anything changes
115//
116// TODO
117// NOTE -- this is VCALC ONLY. data is not referenced for hdf here, and data is rescaled based on VCALC assumptions
118//
119Function VC_CalculateQFrontPanels()
120
121        Variable xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,nPix_X,nPix_Y
122        Variable F_LR_sep,F_TB_sep,F_offset,F_sdd_offset
123
124        String folderPath = "root:Packages:NIST:VSANS:VCALC"
125        String instPath = ":entry:entry:instrument:detector_"
126        String detStr=""
127
128// get the values from the panel + constants   
129        F_LR_sep = VCALC_getPanelSeparation("FLR")
130        F_TB_sep = VCALC_getPanelSeparation("FTB")
131        F_offset = VCALC_getLateralOffset("FL")
132       
133        SDD = VCALC_getSDD("FL")                //nominal SDD - need offset for TB
134        lam = VCALC_getWavelength()
135
136//separations are in mm -- need to watch the units, convert to cm
137        F_LR_sep /= 10
138        F_TB_sep /= 10
139// TODO - I'm treating the separation as the TOTAL width - so the difference
140//      from the "center" to the edge is 1/2 of the separation
141
142// TODO (make the N along the tube length a variable, since this can be reset @ acquisition)
143
144        F_sdd_offset = VCALC_getTopBottomSDDOffset("FT")        //T/B are 300 mm farther back  //TODO: make all detector parameters global, not hard-wired
145
146// detector data to bin
147//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
148        Wave det_FL = $(folderPath+instPath+"FL"+":det_FL")
149        Wave det_FR = $(folderPath+instPath+"FR"+":det_FR")             // these are (48,128)           (nominal, may change)
150
151        Wave det_FT = $(folderPath+instPath+"FT"+":det_FT")
152        Wave det_FB = $(folderPath+instPath+"FB"+":det_FB")             // these are (128,48)
153
154//FRONT/LEFT
155        detStr = "FL"
156        Wave qTot_FL = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
157        Wave qx_FL = $(folderPath+instPath+detStr+":qx_"+detStr)
158        Wave qy_FL = $(folderPath+instPath+detStr+":qy_"+detStr)       
159        Wave qz_FL = $(folderPath+instPath+detStr+":qz_"+detStr)       
160
161        qTot_FL = 0
162        qx_FL = 0
163        qy_FL = 0
164        qz_FL = 0       
165       
166// TODO - these are to be set from globals, not hard-wired. N and pixelSixze will be known (or pre-measured)
167// pixel sizes are in cm
168        pixSizeX = VCALC_getPixSizeX("FL")
169        pixSizeY = VCALC_getPixSizeY("FL")
170//      pixSizeX = 0.8                  // 0.8 cm/pixel along width
171//      pixSizeY = 0.4                  // approx 0.4 cm/pixel along length
172        nPix_X = VCALC_get_nPix_X("FL")
173        nPix_Y = VCALC_get_nPix_Y("FL")
174       
175        xCtr = nPix_X+(F_LR_sep/2/pixSizeX)             // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
176        yCtr = nPix_Y/2
177        VC_Detector_2Q(det_FL,qTot_FL,qx_FL,qy_FL,qz_FL,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
178//      Print "xy for FL = ",xCtr,yCtr
179       
180        //set the wave scaling for the detector image so that it can be plotted in q-space
181        // TODO: this is only approximate - since the left "edge" is not the same from top to bottom, so I crudely
182        // take the middle value. At very small angles, OK, at 1m, this is a crummy approximation.
183        // since qTot is magnitude only, I need to put in the (-ve)
184        SetScale/I x WaveMin(qx_FL),WaveMax(qx_FL),"", det_FL           //this sets the left and right ends of the data scaling
185        SetScale/I y WaveMin(qy_FL),WaveMax(qy_FL),"", det_FL
186//////////////////
187
188//FRONT/RIGHT
189//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
190        detStr = "FR"
191        Wave qTot_FR = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
192        Wave qx_FR = $(folderPath+instPath+detStr+":qx_"+detStr)
193        Wave qy_FR = $(folderPath+instPath+detStr+":qy_"+detStr)       
194        Wave qz_FR = $(folderPath+instPath+detStr+":qz_"+detStr)       
195       
196        qTot_FR = 0
197        qx_FR = 0
198        qy_FR = 0
199        qz_FR = 0
200
201// TODO - these are to be set from globals, not hard-wired
202// pixel sizes are in cm
203        pixSizeX = VCALC_getPixSizeX("FR")
204        pixSizeY = VCALC_getPixSizeY("FR")
205        nPix_X = VCALC_get_nPix_X("FR")
206        nPix_Y = VCALC_get_nPix_Y("FR")
207       
208        xCtr = -(F_LR_sep/2/pixSizeX)-1         
209        yCtr = nPix_Y/2
210        VC_Detector_2Q(det_FR,qTot_FR,qx_FR,qy_FR,qz_FR,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
211//      Print "xy for FR = ",xCtr,yCtr
212        SetScale/I x WaveMin(qx_FR),WaveMax(qx_FR),"", det_FR           //this sets the left and right ends of the data scaling
213        SetScale/I y WaveMin(qy_FR),WaveMax(qy_FR),"", det_FR
214/////////////////
215
216//FRONT/TOP
217//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
218        detStr = "FT"
219        Wave qTot_FT = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
220        Wave qx_FT = $(folderPath+instPath+detStr+":qx_"+detStr)
221        Wave qy_FT = $(folderPath+instPath+detStr+":qy_"+detStr)       
222        Wave qz_FT = $(folderPath+instPath+detStr+":qz_"+detStr)       
223
224        qTot_FT = 0
225        qx_FT = 0
226        qy_FT = 0
227        qz_FT = 0
228
229// TODO - these are to be set from globals, not hard-wired
230// pixel sizes are in cm
231        pixSizeX = VCALC_getPixSizeX("FT")
232        pixSizeY = VCALC_getPixSizeY("FT")
233        nPix_X = VCALC_get_nPix_X("FT")
234        nPix_Y = VCALC_get_nPix_Y("FT")
235       
236        xCtr = nPix_X/2
237        yCtr = -(F_TB_sep/2/pixSizeY)-1   
238        // global sdd_offset is in (mm), convert to meters here for the Q-calculation
239        VC_Detector_2Q(det_FT,qTot_FT,qx_FT,qy_FT,qz_FT,xCtr,yCtr,sdd+F_sdd_offset/1000,lam,pixSizeX,pixSizeY)
240//      Print "xy for FT = ",xCtr,yCtr
241        SetScale/I x WaveMin(qx_FT),WaveMax(qx_FT),"", det_FT           //this sets the left and right ends of the data scaling
242        SetScale/I y WaveMin(qy_FT),WaveMax(qy_FT),"", det_FT
243//////////////////
244
245//FRONT/BOTTOM
246//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
247        detStr = "FB"
248        Wave qTot_FB = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
249        Wave qx_FB = $(folderPath+instPath+detStr+":qx_"+detStr)
250        Wave qy_FB = $(folderPath+instPath+detStr+":qy_"+detStr)       
251        Wave qz_FB = $(folderPath+instPath+detStr+":qz_"+detStr)       
252
253        qTot_FB = 0
254        qx_FB = 0
255        qy_FB = 0
256        qz_FB = 0
257
258// TODO - these are to be set from globals, not hard-wired
259// pixel sizes are in cm
260        pixSizeX = VCALC_getPixSizeX("FB")
261        pixSizeY = VCALC_getPixSizeY("FB")
262        nPix_X = VCALC_get_nPix_X("FB")
263        nPix_Y = VCALC_get_nPix_Y("FB")
264               
265        xCtr = nPix_X/2
266        yCtr = nPix_Y+(F_TB_sep/2/pixSizeY)             // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
267        // global sdd_offset is in (mm), convert to meters here for the Q-calculation
268        VC_Detector_2Q(det_FB,qTot_FB,qx_FB,qy_FB,qz_FB,xCtr,yCtr,sdd+F_sdd_offset/1000,lam,pixSizeX,pixSizeY)
269//      Print "xy for FB = ",xCtr,yCtr
270        SetScale/I x WaveMin(qx_FB),WaveMax(qx_FB),"", det_FB           //this sets the left and right ends of the data scaling
271        SetScale/I y WaveMin(qy_FB),WaveMax(qy_FB),"", det_FB
272/////////////////
273
274        SetDataFolder root:
275               
276        return(0)
277End
278
279
280// TODO - this doesn't quite mask things out as they should be (too much is masked L/R of center)
281// and the outer edges of the detector are masked even if the TB panels extend past the TB of the LR panels.
282// ? skip the masking? but then I bin the detector data directly to get I(q), skipping the masked NaN values...
283//
284Function VC_SetShadow_TopBottom(folderStr,type)
285        String folderStr,type
286       
287        Variable LR_sep,nPix,xCtr,ii,jj,numCol,pixSizeX,pixSizeY,nPix_X,nPix_Y
288
289/// !! 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...
290        if(cmpstr(type[0],"F")==0)
291                //front
292                ControlInfo/W=VCALC VCALCCtrl_2a
293                LR_sep = V_Value       
294        else
295                //middle
296                ControlInfo/W=VCALC VCALCCtrl_3a
297                LR_sep = V_Value       
298        endif           
299//separations on panel are in mm -- need to watch the units, convert to cm
300        LR_sep /= 10
301
302//detector data
303        Wave det = $("root:Packages:NIST:VSANS:"+folderStr+":entry:entry:instrument:detector_"+type+":det_"+type)
304
305// TODO - these are to be set from globals, not hard-wired
306// pixel sizes are in cm for T/B detector
307// TODO - the "FT" check is hard wired for FRONT -- get rid of this...
308
309        pixSizeX = VCALC_getPixSizeX(type)
310        pixSizeY = VCALC_getPixSizeY(type)
311
312        nPix_X = VCALC_get_nPix_X(type)
313        nPix_Y = VCALC_get_nPix_Y(type)
314       
315        //TODO -- get this from a global
316        xCtr = nPix_X/2
317        nPix = trunc(LR_sep/2/pixSizeX)         // approx # of pixels Left/right of center that are not obscured by L/R panels
318       
319        numCol = DimSize(det,0)         // x dim (columns)
320        for(ii=0;ii<(xCtr-nPix-2);ii+=1)
321                det[ii][] = NaN
322        endfor
323        for(ii=(xCtr+nPix+2);ii<numCol;ii+=1)
324                det[ii][] = NaN
325        endfor
326       
327        return(0)
328end
329
330
331// After the panels have been calculated and rescaled in terms of Q, and filled with simulated data
332// they can be appended to the subwindow. If they are already there, the axes and coloring
333// are rescaled as needed
334//
335Function FrontPanels_AsQ()
336
337        String frontStr = "root:Packages:NIST:VSANS:VCALC:entry:entry:instrument:"
338//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Front
339        SetDataFolder $(frontStr+"detector_FB")
340        Wave det_FB = det_FB
341        SetDataFolder $(frontStr+"detector_FT")
342        Wave det_FT = det_FT
343        SetDataFolder $(frontStr+"detector_FL")
344        Wave det_FL = det_FL
345        SetDataFolder $(frontStr+"detector_FR")
346        Wave det_FR = det_FR
347       
348        CheckDisplayed /W=VCALC#Panels_Q det_FB
349        if(V_flag == 0)
350                AppendImage/W=VCALC#Panels_Q det_FB
351                ModifyImage/W=VCALC#Panels_Q det_FB ctab= {*,*,ColdWarm,0}
352                AppendImage/W=VCALC#Panels_Q det_FT
353                ModifyImage/W=VCALC#Panels_Q det_FT ctab= {*,*,ColdWarm,0}
354                AppendImage/W=VCALC#Panels_Q det_FL
355                ModifyImage/W=VCALC#Panels_Q det_FL ctab= {*,*,ColdWarm,0}
356                AppendImage/W=VCALC#Panels_Q det_FR
357                ModifyImage/W=VCALC#Panels_Q det_FR ctab= {*,*,ColdWarm,0}
358        endif
359
360        Variable dval
361        ControlInfo/W=VCALC setVar_b
362        dval = V_Value
363
364        SetAxis/W=VCALC#Panels_Q left -dval,dval
365        SetAxis/W=VCALC#Panels_Q bottom -dval,dval     
366
367        ControlInfo/W=VCALC check_0a
368// V_Value == 1 if checked
369        ModifyImage/W=VCALC#Panels_Q det_FB log=V_Value
370        ModifyImage/W=VCALC#Panels_Q det_FT log=V_Value
371        ModifyImage/W=VCALC#Panels_Q det_FL log=V_Value
372        ModifyImage/W=VCALC#Panels_Q det_FR log=V_Value
373
374
375        SetDataFolder root:
376       
377EndMacro
378
379
380
381
382
383
384//
385// these routines bin the 2D q data to 1D I(q). Currently the Qtot is magnitude only, no sign (since
386// it's being binned to I(Q), having a sign makes no sense. If you want the sign, work from qxqyqz
387//
388// first - the DeltaQ step is set as the smaller detector resolution (along tube)
389//       which is different for LR / TB geometry. This is not set in stone.
390//
391// second - each detector is binned separately
392//
393// -- like the routines in CircSectAve, start with 500 points, and trim after binning is done.
394//      you'l end up with < 200 points.
395//
396// the results are in iBin_qxqy, qBin_qxqy, and eBin_qxqy, in the folder passed
397//
398Proc BinAllFrontPanels()
399
400        SetDeltaQ("VCALC","FL")
401        SetDeltaQ("VCALC","FR")
402        SetDeltaQ("VCALC","FT")
403        SetDeltaQ("VCALC","FB")
404
405        Variable binType       
406        ControlInfo/W=VCALC popup_b
407        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
408
409        if(binType == 1)
410                VC_BinQxQy_to_1D("VCALC","FL")
411                VC_BinQxQy_to_1D("VCALC","FR")
412                VC_BinQxQy_to_1D("VCALC","FT")
413                VC_BinQxQy_to_1D("VCALC","FB")
414        endif
415       
416        if(binType == 2)       
417                VC_BinQxQy_to_1D("VCALC","FLR")
418                VC_BinQxQy_to_1D("VCALC","FTB")
419        endif
420
421        if(binType == 3)
422                VC_BinQxQy_to_1D("VCALC","FLRTB")
423        endif
424
425// TODO -- this is only a temporary fix for slit mode   
426        if(binType == 4)
427                /// this is for a tall, narrow slit mode       
428                VC_fBinDetector_byRows("VCALC","FL")
429                VC_fBinDetector_byRows("VCALC","FR")
430                VC_fBinDetector_byRows("VCALC","FT")
431                VC_fBinDetector_byRows("VCALC","FB")
432        endif
433               
434End
435
436
437
438
439
440
441
442Proc PlotMiddlePanels()
443        fPlotMiddlePanels()
444End
445
446// to plot I(q) for the 4 Middle panels
447//
448// *** Call this function when Middle panels are adjusted, or wavelength, etc. changed
449//
450Function fPlotMiddlePanels()
451
452        // space is allocated for all of the detectors and Q's on initialization
453        // calculate Qtot, qxqyqz arrays from geometry
454        VC_CalculateQMiddlePanels()
455       
456        // fill the panels with fake sphere scattering data
457        // TODO: am I in the right data folder??
458//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
459
460        String folderStr = "VCALC"
461        String detStr = ""
462
463        String folderPath = "root:Packages:NIST:VSANS:"+folderStr
464        String instPath = ":entry:entry:instrument:detector_"   
465
466        detStr = "ML"
467        WAVE det_ML = $(folderPath+instPath+detStr+":det_"+detStr)     
468        WAVE qTot_ML = $(folderPath+instPath+detStr+":qTot_"+detStr)
469
470        detStr = "MR"
471        WAVE det_MR = $(folderPath+instPath+detStr+":det_"+detStr)     
472        WAVE qTot_MR = $(folderPath+instPath+detStr+":qTot_"+detStr)
473
474        detStr = "MT"
475        WAVE det_MT = $(folderPath+instPath+detStr+":det_"+detStr)     
476        WAVE qTot_MT = $(folderPath+instPath+detStr+":qTot_"+detStr)
477
478        detStr = "MB"
479        WAVE det_MB = $(folderPath+instPath+detStr+":det_"+detStr)     
480        WAVE qTot_MB = $(folderPath+instPath+detStr+":qTot_"+detStr)
481
482        FillPanel_wModelData(det_ML,qTot_ML,"ML")
483        FillPanel_wModelData(det_MR,qTot_MR,"MR")
484        FillPanel_wModelData(det_MT,qTot_MT,"MT")
485        FillPanel_wModelData(det_MB,qTot_MB,"MB")                       
486
487        SetDataFolder root:
488               
489        // set any "shadowed" area of the T/B detectors to NaN to get a realitic
490        // view of how much of the detectors are actually collecting data
491        // -- I can get the separation L/R from the panel - only this "open" width is visible.
492        VC_SetShadow_TopBottom("VCALC","MT")            // TODO: -- be sure the data folder is properly set (within the function...)
493        VC_SetShadow_TopBottom("VCALC","MB")
494       
495        // do the q-binning for each of the panels to get I(Q)
496        Execute "BinAllMiddlePanels()"
497
498        // plot the results
499        Execute "Middle_IQ_Graph()"
500        MiddlePanels_AsQ()
501       
502        return(0)
503End
504
505// works for Left, works for Right... works for T/B too.
506//
507// - TODO: be sure that the Q's are calculated correctly even when the beam is off of the
508//     detector, and on different sides of the detector (or T/B) - since it will be in a different
509//     relative postion to 0,0 on the detector. If the postions are symmetric, then the Q's should be identical.
510//     --- test this...
511// TODO -- be sure I'm in the right data folder. nothing is set correctly right now
512//
513// TODO: make all detector parameters global, not hard-wired
514//
515//
516// --- Panels are all allocated in the initialization. Here, only the q-values are calculated
517//     when anything changes
518//
519Function VC_CalculateQMiddlePanels()
520
521        Variable xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY,nPix_X,nPix_Y
522        Variable M_LR_sep,M_TB_sep,M_offset, M_sdd_offset
523
524
525        String folderPath = "root:Packages:NIST:VSANS:VCALC"
526        String instPath = ":entry:entry:instrument:detector_"
527        String detStr=""
528       
529        M_LR_sep = VCALC_getPanelSeparation("MLR")
530        M_TB_sep = VCALC_getPanelSeparation("MTB")
531        M_offset = VCALC_getLateralOffset("ML")
532       
533        SDD = VCALC_getSDD("ML")                //nominal SDD - need offset for TB
534        lam = VCALC_getWavelength()
535
536//separations are in mm -- need to watch the units, convert to cm
537        M_LR_sep /= 10
538        M_TB_sep /= 10
539// TODO - I'm treating the separation as the TOTAL width - so the difference
540//      from the "center" to the edge is 1/2 of the separation
541
542// TODO (make the N along the tube length a variable, since this can be reset @ acquisition)
543        M_sdd_offset = VCALC_getTopBottomSDDOffset("MT")        //T/B are 30 cm farther back  //TODO: make all detector parameters global, not hard-wired
544
545
546//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
547        Wave det_ML = $(folderPath+instPath+"ML"+":det_ML")
548        Wave det_MR = $(folderPath+instPath+"MR"+":det_MR")             // these are (48,128)           (nominal, may change)
549
550        Wave det_MT = $(folderPath+instPath+"MT"+":det_MT")
551        Wave det_MB = $(folderPath+instPath+"MB"+":det_MB")             // these are (128,48)
552
553//Middle/LEFT
554        detStr = "ML"
555        Wave qTot_ML = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
556        Wave qx_ML = $(folderPath+instPath+detStr+":qx_"+detStr)
557        Wave qy_ML = $(folderPath+instPath+detStr+":qy_"+detStr)       
558        Wave qz_ML = $(folderPath+instPath+detStr+":qz_"+detStr)       
559       
560        qTot_ML = 0
561        qx_ML = 0
562        qy_ML = 0
563        qz_ML = 0       
564       
565// TODO - these are to be set from globals, not hard-wired. N and pixelSixze will be known (or pre-measured)
566// pixel sizes are in cm
567        pixSizeX = VCALC_getPixSizeX("ML")
568        pixSizeY = VCALC_getPixSizeY("ML")
569        nPix_X = VCALC_get_nPix_X("ML")
570        nPix_Y = VCALC_get_nPix_Y("ML")
571       
572        xCtr = nPix_X+(M_LR_sep/2/pixSizeX)             // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
573        yCtr = nPix_Y/2
574        VC_Detector_2Q(det_ML,qTot_ML,qx_ML,qy_ML,qz_ML,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
575//      Print "xy for ML = ",xCtr,yCtr
576       
577        //set the wave scaling for the detector image so that it can be plotted in q-space
578        // TODO: this is only approximate - since the left "edge" is not the same from top to bottom, so I crudely
579        // take the middle value. At very small angles, OK, at 1m, this is a crummy approximation.
580        // since qTot is magnitude only, I need to put in the (-ve)
581        SetScale/I x WaveMin(qx_ML),WaveMax(qx_ML),"", det_ML           //this sets the left and right ends of the data scaling
582        SetScale/I y WaveMin(qy_ML),WaveMax(qy_ML),"", det_ML
583       
584//////////////////
585
586//Middle/RIGHT
587//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
588        detStr = "MR"
589        Wave qTot_MR = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
590        Wave qx_MR = $(folderPath+instPath+detStr+":qx_"+detStr)
591        Wave qy_MR = $(folderPath+instPath+detStr+":qy_"+detStr)       
592        Wave qz_MR = $(folderPath+instPath+detStr+":qz_"+detStr)
593       
594        qTot_MR = 0
595        qx_MR = 0
596        qy_MR = 0
597        qz_MR = 0
598
599// TODO - these are to be set from globals, not hard-wired
600// pixel sizes are in cm
601        pixSizeX = VCALC_getPixSizeX("MR")
602        pixSizeY = VCALC_getPixSizeY("MR")
603
604        nPix_X = VCALC_get_nPix_X("MR")
605        nPix_Y = VCALC_get_nPix_Y("MR")
606       
607        xCtr = -(M_LR_sep/2/pixSizeX)-1         
608        yCtr = nPix_Y/2
609        VC_Detector_2Q(det_MR,qTot_MR,qx_MR,qy_MR,qz_MR,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
610//      Print "xy for MR = ",xCtr,yCtr
611        SetScale/I x WaveMin(qx_MR),WaveMax(qx_MR),"", det_MR           //this sets the left and right ends of the data scaling
612        SetScale/I y WaveMin(qy_MR),WaveMax(qy_MR),"", det_MR
613/////////////////
614
615//Middle/TOP
616//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
617        detStr = "MT"
618        Wave qTot_MT = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
619        Wave qx_MT = $(folderPath+instPath+detStr+":qx_"+detStr)
620        Wave qy_MT = $(folderPath+instPath+detStr+":qy_"+detStr)       
621        Wave qz_MT = $(folderPath+instPath+detStr+":qz_"+detStr)
622
623        qTot_MT = 0
624        qx_MT = 0
625        qy_MT = 0
626        qz_MT = 0
627
628// TODO - these are to be set from globals, not hard-wired
629// pixel sizes are in cm
630        pixSizeX = VCALC_getPixSizeX("MT")
631        pixSizeY = VCALC_getPixSizeY("MT")
632        nPix_X = VCALC_get_nPix_X("MT")
633        nPix_Y = VCALC_get_nPix_Y("MT")
634       
635        xCtr = nPix_X/2
636        yCtr = -(M_TB_sep/2/pixSizeY)-1
637        // global sdd_offset is in (mm), convert to meters here for the Q-calculation 
638        VC_Detector_2Q(det_MT,qTot_MT,qx_MT,qy_MT,qz_MT,xCtr,yCtr,sdd+M_sdd_offset/1000,lam,pixSizeX,pixSizeY)
639//      Print "xy for MT = ",xCtr,yCtr
640        SetScale/I x WaveMin(qx_MT),WaveMax(qx_MT),"", det_MT           //this sets the left and right ends of the data scaling
641        SetScale/I y WaveMin(qy_MT),WaveMax(qy_MT),"", det_MT
642//////////////////
643
644//Middle/BOTTOM
645//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
646        detStr = "MB"
647        Wave qTot_MB = $(folderPath+instPath+detStr+":qTot_"+detStr)                    // 2D q-values
648        Wave qx_MB = $(folderPath+instPath+detStr+":qx_"+detStr)
649        Wave qy_MB = $(folderPath+instPath+detStr+":qy_"+detStr)       
650        Wave qz_MB = $(folderPath+instPath+detStr+":qz_"+detStr)
651
652        qTot_MB = 0
653        qx_MB = 0
654        qy_MB = 0
655        qz_MB = 0
656
657// TODO - these are to be set from globals, not hard-wired
658// pixel sizes are in cm
659        pixSizeX = VCALC_getPixSizeX("MB")
660        pixSizeY = VCALC_getPixSizeY("MB")
661        nPix_X = VCALC_get_nPix_X("MB")
662        nPix_Y = VCALC_get_nPix_Y("MB")
663               
664        xCtr = nPix_X/2
665        yCtr = nPix_Y+(M_TB_sep/2/pixSizeY)             // TODO  -- check -- starting from 47 rather than 48 (but I'm in pixel units for centers)??
666                // global sdd_offset is in (mm), convert to meters here for the Q-calculation
667        VC_Detector_2Q(det_MB,qTot_MB,qx_MB,qy_MB,qz_MB,xCtr,yCtr,sdd+M_sdd_offset/1000,lam,pixSizeX,pixSizeY)
668//      Print "xy for MB = ",xCtr,yCtr
669        SetScale/I x WaveMin(qx_MB),WaveMax(qx_MB),"", det_MB           //this sets the left and right ends of the data scaling
670        SetScale/I y WaveMin(qy_MB),WaveMax(qy_MB),"", det_MB
671/////////////////
672
673        SetDataFolder root:
674               
675        return(0)
676End
677
678
679Function MiddlePanels_AsQ()
680//      DoWindow/F MiddlePanels_AsQ
681//      if(V_flag == 0)
682//      PauseUpdate; Silent 1           // building window...
683//      Display /W=(1477,44,1978,517)
684
685        String midStr = "root:Packages:NIST:VSANS:VCALC:entry:entry:instrument:"
686//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Middle
687        SetDataFolder $(midStr+"detector_MB")
688        Wave det_MB = det_MB
689        SetDataFolder $(midStr+"detector_MT")
690        Wave det_MT = det_MT
691        SetDataFolder $(midStr+"detector_ML")
692        Wave det_ML = det_ML
693        SetDataFolder $(midStr+"detector_MR")
694        Wave det_MR = det_MR
695
696        CheckDisplayed /W=VCALC#Panels_Q det_MB
697       
698        if(V_flag == 0)
699                AppendImage/W=VCALC#Panels_Q det_MB
700                ModifyImage/W=VCALC#Panels_Q det_MB ctab= {*,*,ColdWarm,0}
701                AppendImage/W=VCALC#Panels_Q det_MT
702                ModifyImage/W=VCALC#Panels_Q det_MT ctab= {*,*,ColdWarm,0}
703                AppendImage/W=VCALC#Panels_Q det_ML
704                ModifyImage/W=VCALC#Panels_Q det_ML ctab= {*,*,ColdWarm,0}
705                AppendImage/W=VCALC#Panels_Q det_MR
706                ModifyImage/W=VCALC#Panels_Q det_MR ctab= {*,*,ColdWarm,0}
707        endif
708
709        Variable dval
710        ControlInfo/W=VCALC setVar_b
711        dval = V_Value
712
713        SetAxis/W=VCALC#Panels_Q left -dval,dval
714        SetAxis/W=VCALC#Panels_Q bottom -dval,dval     
715
716        ControlInfo/W=VCALC check_0a
717// V_Value == 1 if checked
718        ModifyImage/W=VCALC#Panels_Q det_MB log=V_Value
719        ModifyImage/W=VCALC#Panels_Q det_MT log=V_Value
720        ModifyImage/W=VCALC#Panels_Q det_ML log=V_Value
721        ModifyImage/W=VCALC#Panels_Q det_MR log=V_Value
722
723
724        SetDataFolder root:
725       
726//      ModifyGraph width={Aspect,1},height={Aspect,1},gbRGB=(56797,56797,56797)
727//      ModifyGraph grid=2
728//      ModifyGraph mirror=2
729//      SetAxis left -0.2,0.2
730//      SetAxis bottom -0.2,0.2
731//      endif
732EndMacro
733
734//
735// these routines bin the 2D q data to 1D I(q). Currently the Qtot is magnitude only, no sign (since
736// it's being binned to I(Q), having a sign makes no sense. If you want the sign, work from qxqyqz
737//
738// first - the DeltaQ step is set as the smaller detector resolution (along tube)
739//       which is different for LR / TB geometry. This is not set in stone.
740//
741// second - each detector is binned separately
742//
743// -- like the routines in CircSectAve, start with 500 points, and trim after binning is done.
744//      you'l end up with < 200 points.
745//
746// the results are in iBin_qxqy, qBin_qxqy, and eBin_qxqy, in the folder passed
747//
748Proc BinAllMiddlePanels()
749
750        SetDeltaQ("VCALC","ML")
751        SetDeltaQ("VCALC","MR")
752        SetDeltaQ("VCALC","MT")
753        SetDeltaQ("VCALC","MB")
754
755        Variable binType       
756        ControlInfo/W=VCALC popup_b
757        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
758
759        if(binType == 1)
760                VC_BinQxQy_to_1D("VCALC","ML")
761                VC_BinQxQy_to_1D("VCALC","MR")
762                VC_BinQxQy_to_1D("VCALC","MT")
763                VC_BinQxQy_to_1D("VCALC","MB")
764        endif
765       
766        if(binType == 2)       
767                VC_BinQxQy_to_1D("VCALC","MLR")
768                VC_BinQxQy_to_1D("VCALC","MTB")
769        endif
770
771        if(binType == 3)
772                VC_BinQxQy_to_1D("VCALC","MLRTB")
773        endif
774       
775        // TODO -- this is only a temporary fix for slit mode   
776        if(binType == 4)
777                /// this is for a tall, narrow slit mode       
778                VC_fBinDetector_byRows("VCALC","ML")
779                VC_fBinDetector_byRows("VCALC","MR")
780                VC_fBinDetector_byRows("VCALC","MT")
781                VC_fBinDetector_byRows("VCALC","MB")
782        endif
783End
784
785////////////to plot the (4) 2D panels and to plot the I(Q) data on the same plot
786Window Middle_IQ_Graph() : Graph
787
788        Variable binType
789       
790        ControlInfo/W=VCALC popup_b
791        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
792
793        SetDataFolder root:Packages:NIST:VSANS:VCALC
794
795        if(binType==1)
796                ClearIQIfDisplayed("VCALC","MLRTB")
797                ClearIQIfDisplayed("VCALC","MLR")
798                ClearIQIfDisplayed("VCALC","MTB")
799               
800                SetDataFolder root:Packages:NIST:VSANS:VCALC
801                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_ML
802               
803                if(V_flag==0)
804                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_ML vs qBin_qxqy_ML
805                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MR vs qBin_qxqy_MR
806                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MT vs qBin_qxqy_MT
807                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MB vs qBin_qxqy_MB
808                        ModifyGraph/W=VCALC#Panels_IQ mode=4
809                        ModifyGraph/W=VCALC#Panels_IQ marker=19
810                        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)
811                        ModifyGraph/W=VCALC#Panels_IQ msize=2
812                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_ML)={0,4},muloffset(iBin_qxqy_MB)={0,2},muloffset(iBin_qxqy_MR)={0,8}
813                        ModifyGraph/W=VCALC#Panels_IQ grid=1
814                        ModifyGraph/W=VCALC#Panels_IQ log=1
815                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
816                endif           
817        endif
818       
819        if(binType==2)
820                ClearIQIfDisplayed("VCALC","MLRTB")
821                ClearIQIfDisplayed("VCALC","MT")       
822                ClearIQIfDisplayed("VCALC","ML")       
823                ClearIQIfDisplayed("VCALC","MR")       
824                ClearIQIfDisplayed("VCALC","MB")
825       
826
827                SetDataFolder root:Packages:NIST:VSANS:VCALC
828                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_MLR
829               
830                if(V_flag==0)
831                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_MLR vs qBin_qxqy_MLR
832                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MTB vs qBin_qxqy_MTB
833                        ModifyGraph/W=VCALC#Panels_IQ mode=4
834                        ModifyGraph/W=VCALC#Panels_IQ marker=19
835                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_MLR)=(65535,0,0),rgb(iBin_qxqy_MTB)=(1,16019,65535)
836                        ModifyGraph/W=VCALC#Panels_IQ msize=2
837                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_MLR)={0,2}
838                        ModifyGraph/W=VCALC#Panels_IQ grid=1
839                        ModifyGraph/W=VCALC#Panels_IQ log=1
840                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
841                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
842                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
843                endif   
844                       
845        endif
846       
847        if(binType==3)
848                ClearIQIfDisplayed("VCALC","MLR")
849                ClearIQIfDisplayed("VCALC","MTB")       
850                ClearIQIfDisplayed("VCALC","MT")       
851                ClearIQIfDisplayed("VCALC","ML")       
852                ClearIQIfDisplayed("VCALC","MR")       
853                ClearIQIfDisplayed("VCALC","MB")       
854       
855                SetDataFolder root:Packages:NIST:VSANS:VCALC
856                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_MLRTB
857               
858                if(V_flag==0)
859                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_MLRTB vs qBin_qxqy_MLRTB
860                        ModifyGraph/W=VCALC#Panels_IQ mode=4
861                        ModifyGraph/W=VCALC#Panels_IQ marker=19
862                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_MLRTB)=(65535,0,0)
863                        ModifyGraph/W=VCALC#Panels_IQ msize=2
864                        ModifyGraph/W=VCALC#Panels_IQ grid=1
865                        ModifyGraph/W=VCALC#Panels_IQ log=1
866                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
867                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
868                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
869                endif   
870                       
871        endif
872
873        if(binType==4)          // slit aperture binning - Mt, ML, MR, MB are averaged
874                ClearIQIfDisplayed("VCALC","MLRTB")
875                ClearIQIfDisplayed("VCALC","MLR")
876                ClearIQIfDisplayed("VCALC","MTB")
877               
878                SetDataFolder root:Packages:NIST:VSANS:VCALC
879                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_ML
880               
881                if(V_flag==0)
882                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_ML vs qBin_qxqy_ML
883                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MR vs qBin_qxqy_MR
884                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MT vs qBin_qxqy_MT
885                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_MB vs qBin_qxqy_MB
886                        ModifyGraph/W=VCALC#Panels_IQ mode=4
887                        ModifyGraph/W=VCALC#Panels_IQ marker=19
888                        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)
889                        ModifyGraph/W=VCALC#Panels_IQ msize=2
890                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_ML)={0,4},muloffset(iBin_qxqy_MB)={0,2},muloffset(iBin_qxqy_MR)={0,8}
891                        ModifyGraph/W=VCALC#Panels_IQ grid=1
892                        ModifyGraph/W=VCALC#Panels_IQ log=1
893                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
894                endif           
895                       
896        endif
897        SetDataFolder root:
898EndMacro
899
900
901////////// and for the BACK detector
902Proc PlotBackPanels()
903        fPlotBackPanels()
904End
905
906// to plot I(q) for the Back panel
907//
908// *** Call this function when Back panel is adjusted, or wavelength, etc. changed
909//
910Function fPlotBackPanels()
911
912        // space is allocated for all of the detectors and Q's on initialization
913        // calculate Qtot, qxqyqz arrays from geometry
914        VC_CalculateQBackPanels()
915       
916        // fill the panels with fake sphere scattering data
917        // TODO: am I in the right data folder??
918        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:entry:instrument:detector_B
919
920        WAVE det_B = det_B
921        WAVE qTot_B = qTot_B
922
923        FillPanel_wModelData(det_B,qTot_B,"B")         
924
925        SetDataFolder root:
926               
927        // set any "shadowed" area of the T/B detectors to NaN to get a realitic
928        // view of how much of the detectors are actually collecting data
929        // -- I can get the separation L/R from the panel - only this "open" width is visible.
930//      VC_SetShadow_TopBottom("","MT")         // TODO: -- be sure the data folder is properly set (within the function...)
931//      VC_SetShadow_TopBottom("","MB")
932       
933        // do the q-binning for each of the panels to get I(Q)
934        Execute "BinAllBackPanels()"
935
936        // plot the results
937        Execute "Back_IQ_Graph()"
938        Execute "BackPanels_AsQ()"
939
940        return(0)
941
942End
943
944// works for Left, works for Right... works for T/B too.
945//
946// - TODO: be sure that the Q's are calculated correctly even when the beam is off of the
947//     detector, and on different sides of the detector (or T/B) - since it will be in a different
948//     relative postion to 0,0 on the detector. If the postions are symmetric, then the Q's should be identical.
949//     --- test this...
950// TODO -- be sure I'm in the right data folder. nothing is set correctly right now
951//
952// TODO: make all detector parameters global, not hard-wired
953//
954//
955// --- Panels are all allocated in the initialization. Here, only the q-values are calculated
956//     when anything changes
957//
958Function VC_CalculateQBackPanels()
959
960        Variable xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY
961        Variable B_offset
962
963        String folderPath = "root:Packages:NIST:VSANS:VCALC"
964        String instPath = ":entry:entry:instrument:detector_"
965        String detStr = ""
966       
967        B_offset = VCALC_getLateralOffset("B")
968       
969        SDD = VCALC_getSDD("B")         //nominal SDD - need offset for TB
970        lam = VCALC_getWavelength()
971
972// TODO (make the N along the tube length a variable, since this can be reset @ acquisition)
973//      SetDataFolder root:Packages:NIST:VSANS:VCALC:Back
974        WAVE det_B = $(folderPath+instPath+"B"+":det_B")                        // this is nominally (320,320)
975
976//Back detector
977//root:Packages:NIST:VSANS:VCALC:entry:entry:instrument:detector_B:qTot_B
978        detStr = "B"
979        Wave qTot_B = $(folderPath+instPath+detStr+":qTot_"+detStr)                     // 2D q-values
980        Wave qx_B = $(folderPath+instPath+detStr+":qx_"+detStr)
981        Wave qy_B = $(folderPath+instPath+detStr+":qy_"+detStr)
982        Wave qz_B = $(folderPath+instPath+detStr+":qz_"+detStr)
983
984        qTot_B = 0
985        qx_B = 0
986        qy_B = 0
987        qz_B = 0       
988       
989// TODO - these are to be set from globals, not hard-wired. N and pixelSixze will be known (or pre-measured)
990// pixel sizes are in cm
991        pixSizeX = VCALC_getPixSizeX("B")
992        pixSizeY = VCALC_getPixSizeY("B")
993       
994        xCtr = trunc( DimSize(det_B,0)/2 )              //should be 160
995        yCtr = trunc( DimSize(det_B,1)/2 )              //should be 160
996        VC_Detector_2Q(det_B,qTot_B,qx_B,qy_B,qz_B,xCtr,yCtr,sdd,lam,pixSizeX,pixSizeY)
997       
998        //set the wave scaling for the detector image so that it can be plotted in q-space
999        // TODO: this is only approximate - since the left "edge" is not the same from top to bottom, so I crudely
1000        // take the middle value. At very small angles, OK, at 1m, this is a crummy approximation.
1001        // since qTot is magnitude only, I need to put in the (-ve)
1002        SetScale/I x WaveMin(qx_B),WaveMax(qx_B),"", det_B              //this sets the left and right ends of the data scaling
1003        SetScale/I y WaveMin(qy_B),WaveMax(qy_B),"", det_B
1004
1005        SetDataFolder root:
1006               
1007        return(0)
1008End
1009
1010
1011Window BackPanels_AsQ() : Graph
1012//      DoWindow/F BackPanels_AsQ
1013//      if(V_flag == 0)
1014//      PauseUpdate; Silent 1           // building window...
1015//      Display /W=(1477,44,1978,517)
1016
1017        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:entry:instrument:detector_B
1018
1019        CheckDisplayed /W=VCALC#Panels_Q det_B
1020        if(V_flag == 0)
1021                AppendImage/W=VCALC#Panels_Q det_B
1022                ModifyImage/W=VCALC#Panels_Q det_B ctab= {*,*,ColdWarm,0}
1023        endif
1024
1025        Variable dval
1026        ControlInfo/W=VCALC setVar_b
1027        dval = V_Value
1028
1029        SetAxis/W=VCALC#Panels_Q left -dval,dval
1030        SetAxis/W=VCALC#Panels_Q bottom -dval,dval     
1031
1032        ControlInfo/W=VCALC check_0a
1033// V_Value == 1 if checked
1034        ModifyImage/W=VCALC#Panels_Q det_B log=V_Value
1035
1036        SetDataFolder root:
1037       
1038//      ModifyGraph width={Aspect,1},height={Aspect,1},gbRGB=(56797,56797,56797)
1039//      ModifyGraph grid=2
1040//      ModifyGraph mirror=2
1041//      SetAxis left -0.2,0.2
1042//      SetAxis bottom -0.2,0.2
1043//      endif
1044EndMacro
1045
1046//
1047// these routines bin the 2D q data to 1D I(q). Currently the Qtot is magnitude only, no sign (since
1048// it's being binned to I(Q), having a sign makes no sense. If you want the sign, work from qxqyqz
1049//
1050// first - the DeltaQ step is set as the smaller detector resolution (along tube)
1051//       which is different for LR / TB geometry. This is not set in stone.
1052//
1053// second - each detector is binned separately
1054//
1055// -- like the routines in CircSectAve, start with 500 points, and trim after binning is done.
1056//      you'l end up with < 200 points.
1057//
1058// the results are in iBin_qxqy, qBin_qxqy, and eBin_qxqy, in the folder passed
1059//
1060Proc BinAllBackPanels()
1061
1062        SetDeltaQ("VCALC","B")
1063
1064        Variable binType       
1065        ControlInfo/W=VCALC popup_b
1066        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1067       
1068        VC_BinQxQy_to_1D("VCALC","B")
1069
1070// TODO -- this is only a temporary fix for slit mode   
1071        if(binType == 4)
1072                /// this is for a tall, narrow slit mode       
1073                VC_fBinDetector_byRows("VCALC","B")
1074        endif   
1075       
1076End
1077
1078////////////to plot the back panel I(q)
1079Window Back_IQ_Graph() : Graph
1080
1081        SetDataFolder root:Packages:NIST:VSANS:VCALC:entry:entry:instrument:detector_B
1082
1083        Variable binType
1084       
1085        ControlInfo/W=VCALC popup_b
1086        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1087       
1088
1089        if(binType==1 || binType==2 || binType==3)
1090               
1091                SetDataFolder root:Packages:NIST:VSANS:VCALC
1092                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_B
1093               
1094                if(V_flag==0)
1095                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_B vs qBin_qxqy_B
1096                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1097                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1098                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_B)=(1,52428,52428)
1099                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1100                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1101                        ModifyGraph/W=VCALC#Panels_IQ log=1
1102                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1103                endif
1104        endif
1105
1106        //nothing different here since there is ony a single detector to display, but for the future...
1107        if(binType==4)
1108               
1109                SetDataFolder root:Packages:NIST:VSANS:VCALC
1110                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_B
1111               
1112                if(V_flag==0)
1113                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_B vs qBin_qxqy_B
1114                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1115                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1116                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_B)=(1,52428,52428)
1117                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1118                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1119                        ModifyGraph/W=VCALC#Panels_IQ log=1
1120                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1121                endif
1122        endif
1123
1124       
1125        SetDataFolder root:
1126EndMacro
1127
1128
1129////////////to plot the (4) 2D panels and to plot the I(Q) data on the same plot
1130//
1131// ** but now I need to check and see if these waves exist before trying to append them
1132// since the panels may bave been combined when binned - rather than all separate.
1133//
1134// TODO
1135// -- so maybe I want to clear the traces from the graph?
1136// -- set a flag on the panel to know how the binning is applied?
1137//
1138Window Front_IQ_Graph() : Graph
1139
1140        Variable binType
1141        String fldr = "VCALC"
1142       
1143        ControlInfo/W=VCALC popup_b
1144        binType = V_Value               // V_value counts menu items from 1, so 1=1, 2=2, 3=4
1145
1146        SetDataFolder root:Packages:NIST:VSANS:VCALC
1147
1148        if(binType==1)
1149                ClearIQIfDisplayed("VCALC","FLRTB")
1150                ClearIQIfDisplayed("VCALC","FLR")
1151                ClearIQIfDisplayed("VCALC","FTB")
1152               
1153                SetDataFolder root:Packages:NIST:VSANS:VCALC
1154                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FL
1155               
1156                if(V_flag==0)
1157                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FL vs qBin_qxqy_FL
1158                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FR vs qBin_qxqy_FR
1159                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FT vs qBin_qxqy_FT
1160                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FB vs qBin_qxqy_FB
1161                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1162                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1163                        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)
1164                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1165                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FL)={0,4},muloffset(iBin_qxqy_FB)={0,2},muloffset(iBin_qxqy_FR)={0,8}
1166                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1167                        ModifyGraph/W=VCALC#Panels_IQ log=1
1168                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1169                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1170                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1171                endif   
1172                               
1173        endif
1174
1175        if(binType==2)
1176                ClearIQIfDisplayed("VCALC","FLRTB")
1177                ClearIQIfDisplayed("VCALC","FT")       
1178                ClearIQIfDisplayed("VCALC","FL")       
1179                ClearIQIfDisplayed("VCALC","FR")       
1180                ClearIQIfDisplayed("VCALC","FB")
1181       
1182
1183                SetDataFolder root:Packages:NIST:VSANS:VCALC
1184                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FLR
1185               
1186                if(V_flag==0)
1187                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FLR vs qBin_qxqy_FLR
1188                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FTB vs qBin_qxqy_FTB
1189                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1190                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1191                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FLR)=(39321,26208,1),rgb(iBin_qxqy_FTB)=(2,39321,1)
1192                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1193                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FLR)={0,2}
1194                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1195                        ModifyGraph/W=VCALC#Panels_IQ log=1
1196                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1197                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1198                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1199                endif   
1200                       
1201        endif
1202       
1203        if(binType==3)
1204                ClearIQIfDisplayed("VCALC","FLR")
1205                ClearIQIfDisplayed("VCALC","FTB")       
1206                ClearIQIfDisplayed("VCALC","FT")       
1207                ClearIQIfDisplayed("VCALC","FL")       
1208                ClearIQIfDisplayed("VCALC","FR")       
1209                ClearIQIfDisplayed("VCALC","FB")       
1210       
1211                SetDataFolder root:Packages:NIST:VSANS:VCALC
1212                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FLRTB
1213               
1214                if(V_flag==0)
1215                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FLRTB vs qBin_qxqy_FLRTB
1216                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1217                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1218                        ModifyGraph/W=VCALC#Panels_IQ rgb(iBin_qxqy_FLRTB)=(39321,26208,1)
1219                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1220                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1221                        ModifyGraph/W=VCALC#Panels_IQ log=1
1222                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1223                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1224                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1225                endif   
1226                       
1227        endif
1228
1229
1230        if(binType==4)          //slit mode
1231                ClearIQIfDisplayed("VCALC","FLRTB")
1232                ClearIQIfDisplayed("VCALC","FLR")
1233                ClearIQIfDisplayed("VCALC","FTB")
1234               
1235                SetDataFolder root:Packages:NIST:VSANS:VCALC
1236                CheckDisplayed/W=VCALC#Panels_IQ iBin_qxqy_FL
1237               
1238                if(V_flag==0)
1239                        AppendtoGraph/W=VCALC#Panels_IQ iBin_qxqy_FL vs qBin_qxqy_FL
1240                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FR vs qBin_qxqy_FR
1241                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FT vs qBin_qxqy_FT
1242                        AppendToGraph/W=VCALC#Panels_IQ iBin_qxqy_FB vs qBin_qxqy_FB
1243                        ModifyGraph/W=VCALC#Panels_IQ mode=4
1244                        ModifyGraph/W=VCALC#Panels_IQ marker=19
1245                        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)
1246                        ModifyGraph/W=VCALC#Panels_IQ msize=2
1247                        ModifyGraph/W=VCALC#Panels_IQ muloffset(iBin_qxqy_FL)={0,4},muloffset(iBin_qxqy_FB)={0,2},muloffset(iBin_qxqy_FR)={0,8}
1248                        ModifyGraph/W=VCALC#Panels_IQ grid=1
1249                        ModifyGraph/W=VCALC#Panels_IQ log=1
1250                        ModifyGraph/W=VCALC#Panels_IQ mirror=2
1251                        Label/W=VCALC#Panels_IQ left "Intensity (1/cm)"
1252                        Label/W=VCALC#Panels_IQ bottom "Q (1/A)"
1253                endif   
1254                               
1255        endif
1256
1257       
1258        SetDataFolder root:
1259       
1260EndMacro
1261
1262
1263Function ClearIQIfDisplayed(fldr,type)
1264        String fldr,type
1265
1266        SetDataFolder $("root:Packages:NIST:VSANS:"+fldr)
1267
1268        if(cmpstr(fldr,"VCALC") == 0)
1269                CheckDisplayed/W=VCALC#Panels_IQ $("iBin_qxqy_"+type)
1270                if(V_flag==1)
1271                        RemoveFromGraph/W=VCALC#Panels_IQ $("iBin_qxqy_"+type)
1272                endif
1273        else
1274                CheckDisplayed/W=V_1D_Data $("iBin_qxqy_"+type)
1275                if(V_flag==1)
1276                        RemoveFromGraph/W=V_1D_Data $("iBin_qxqy_"+type)
1277                endif
1278        endif
1279
1280        SetDataFolder root:
1281       
1282        return(0)
1283end
1284
1285Window Table_of_QBins() : Table
1286        PauseUpdate; Silent 1           // building window...
1287        String fldrSav0= GetDataFolder(1)
1288        SetDataFolder root:Packages:NIST:VSANS:VCALC:
1289        Edit/W=(5,44,771,898) qBin_qxqy_FL,qBin_qxqy_FR,qBin_qxqy_FT,qBin_qxqy_FB,qBin_qxqy_FLR
1290        AppendToTable qBin_qxqy_FTB,qBin_qxqy_FLRTB
1291        ModifyTable format(Point)=1,width(qBin_qxqy_FLR)=136,width(qBin_qxqy_FLRTB)=120
1292        SetDataFolder fldrSav0
1293EndMacro
1294
1295
1296
1297
Note: See TracBrowser for help on using the repository browser.