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

Last change on this file since 1035 was 1035, checked in by srkline, 6 years ago

changes to streamline the data plotting of 1D data, in preparation for different modes of combining detector panels. Also will allow better integration with protocols to combine 1D data, which can now be part of the protocol.

Other changes, but I can't remember whtat they were...

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